Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webhooks): add support for custom outgoing webhook http headers #5275

Merged
merged 26 commits into from
Jul 16, 2024

Conversation

srujanchikke
Copy link
Contributor

@srujanchikke srujanchikke commented Jul 10, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This pr adds support for custom outgoing webhook http headers. If we pass custom_outgoing_webhook_http_headers to business profile these headers will be forwaded to all outgoing webhooks request headers.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

Test case 1 :
Create or Update the business profile with custom http headers

curl --location 'http://localhost:8080/account/merchant_1720605139/business_profile/pro_vGz02PKyssUnujEpTwee' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
  "profile_name": "food",
  "outgoing_webhook_custom_http_headers": {
    "authentication" : "this is test key header",
    "client_id" : "askdjfhaksjhdf",
    "client_key" : "asdkfjhakdjh"
  }

}'

Create payment you should should be able to see custom headers in the configure test webhook site.

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_WYTknsPs0yvmcht1il3zk5bwvieOxmpk43I1O17xUrGDMgFoKYqUErBeafZw43Tg' \
--data-raw '{
    "amount":1000,
    "currency": "EUR",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2029-09-10T10:11:12Z",
    "amount_to_capture": 1000,
    "customer_id": "AdyenCustomer",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://google.com",
    "payment_method_data": {
        "card": {
            "card_number": "4111111145551142",
            "card_exp_month": "03",
            "card_exp_year": "30",
            "card_holder_name": "[email protected]",
            "card_cvc": "737",
            "card_network": "Visa",
            "card_type": null,
            "card_issuing_country": null,
            "bank_code": null
        },
        "billing": {
            "address": {
                "line1": "1467",
                "line2": "CA",
                "line3": "CA",
                "city": "San Fransico",
                "state": "California",
                "zip": "94122",
                "country": "NL",
                "first_name": "joseph",
                "last_name": "Doe"
            },
            "phone": {
                "number": "8056594427",
                "country_code": "+91"
            }
        }
    },
    "payment_method": "card",
    "payment_method_type" :"credit",
    "customer_acceptance": {
        "acceptance_type": "online",
        "accepted_at": "2026-07-04T10:59:42.232Z",
        "online": {
            "ip_address": null,
            "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0"
        }
    },
    "browser_info": {
        "color_depth": 24,
        "java_enabled": true,
        "java_script_enabled": true,
        "language": "en-GB",
        "screen_height": 720,
        "screen_width": 1280,
        "time_zone": -330,
        "ip_address": "208.127.127.193",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "CA",
            "line3": "CA",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
Screenshot 2024-07-10 at 5 45 10 PM

Test case 2 : Pass random string to the field custom_outgoing_webhook_http_headers , this should not trigger custom headers to outgoing webhook, but this will show warning in the logs
Screenshot 2024-07-10 at 5 55 12 PM

Testcase 3 : Check how data is stored in db, outgoing_webhook_custom_http_headers should be encrypted in db.

Screenshot 2024-07-15 at 7 34 43 PM

Test case 4: check whether retry for outgoing webhooks have custom headers . You can verify it by passing invalid return url to create 4xx webhook.

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@srujanchikke srujanchikke self-assigned this Jul 10, 2024
@srujanchikke srujanchikke requested review from a team as code owners July 10, 2024 12:07
@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Jul 10, 2024
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jul 10, 2024
@srujanchikke srujanchikke added A-core Area: Core flows C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Jul 10, 2024
@srujanchikke srujanchikke requested review from a team as code owners July 10, 2024 13:24
@srujanchikke srujanchikke force-pushed the custom_outgoint_webhook_http_headers branch from 6aef41c to 1f255e1 Compare July 10, 2024 13:26
@@ -6991,6 +6991,11 @@
}
],
"nullable": true
},
"custom_outgoing_webhook_http_headers": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"custom_outgoing_webhook_http_headers": {
"outgoing_webhook_custom_http_headers": {


/// These key-value pairs are sent as additional custom headers in the outgoing webhook request. It is recommended not to use more than four key-value pairs.
#[schema(value_type = Option<Object>, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
pub custom_outgoing_webhook_http_headers: Option<pii::SecretSerdeValue>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should accept it as an Hashmap here right?

let custom_outgoing_webhook_http_headers = business_profile
.custom_outgoing_webhook_http_headers
.clone();
let hashset = utils::convert_serde_json_to_hashset(custom_outgoing_webhook_http_headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use serde_json::from_value here instead?

@srujanchikke srujanchikke removed request for a team July 11, 2024 17:59
crates/router/src/core/admin.rs Show resolved Hide resolved
crates/router/src/core/admin.rs Show resolved Hide resolved
crates/router/src/core/admin.rs Show resolved Hide resolved
.change_context(errors::ApiErrorResponse::WebhookProcessingFailure)
.attach_printable("Failed to construct outgoing webhook request content")?;
.attach_printable("Failed to construct outgoing webhook custom HTTP headers")?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert this change?

Comment on lines +573 to +578
let custom_headers = decrypt::<serde_json::Value, masking::WithType>(
business_profile
.outgoing_webhook_custom_http_headers
.clone(),
key_store.key.get_inner().peek(),
)
Copy link
Member

@SanchithHegde SanchithHegde Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd preferably want to have this implementation as part of domain type implementation rather than encrypting/decrypting it individually in separate locations. We can take up the domain type implementation in a separate PR.

Copy link
Contributor Author

@srujanchikke srujanchikke Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will take this in separate pr .

Comment on lines +216 to +219
routing_algorithm: Some(serde_json::json!({
"algorithm_id": null,
"timestamp": 0
})),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this hardcoded value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SanchithHegde this was hardcoded for backward compatibility.
cc: @Aprabhat19

SanchithHegde
SanchithHegde previously approved these changes Jul 16, 2024
Aprabhat19
Aprabhat19 previously approved these changes Jul 16, 2024
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jul 16, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 16, 2024
Aprabhat19
Aprabhat19 previously approved these changes Jul 16, 2024
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jul 16, 2024
Merged via the queue into main with commit 101b21f Jul 16, 2024
17 checks passed
@Gnanasundari24 Gnanasundari24 deleted the custom_outgoint_webhook_http_headers branch July 16, 2024 16:37
@pixincreate pixincreate removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Jul 16, 2024
pixincreate added a commit that referenced this pull request Jul 16, 2024
* 'main' of github.com:juspay/hyperswitch: (25 commits)
  fix(logs): ignore request headers while logging (#5273)
  feat(webhooks): add support for custom outgoing webhook http headers (#5275)
  fix(payment_methods): set `requires_cvv` to false when either `connector_mandate_details` or `network_transaction_id` is present during MITs (#5331)
  chore: create justfile for running commands for v1 and v2 migrations (#5325)
  fix(routing): do not update `perform_session_flow_routing` output if the `SessionRoutingChoice` is none (#5336)
  fix(database): modified_at updated for every state change for Payment Attempts (#5312)
  feat(mca): Added recipient connector call for open banking connectors (#3758)
  chore(version): 2024.07.16.0
  refactor(connector): [Mifinity] add a field language_preference in payment request for mifinity payment method data (#5326)
  fix(router): store `customer_acceptance` in payment_attempt, use it in confirm flow for delayed authorizations like external 3ds flow (#5308)
  feat(proxy): add support to pass proxy bypass urls from configs (#5322)
  Docs: Updating Error codes in API-ref (#5296)
  feat(core): [Payouts] Add retrieve flow for payouts (#4936)
  fix(connector): [AUTHORIZEDOTNET] Populate error reason for failure transactions (#5319)
  chore(version): 2024.07.15.0
  feat(logging): Emit a setup error when a restricted keys are used for logging default keys (#5185)
  feat(payment_methods): add support to migrate existing customer PMs from processor to hyperswitch (#5306)
  feat(connector): [DATATRANS] Implement card payments (#5028)
  chore: making of function create_encrypted_data (#5251)
  fix(payments): populate merchant order ref id in list (#5310)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows C-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants