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(core): add support for confirmation flow for click to pay #6982

Conversation

sahkal
Copy link
Contributor

@sahkal sahkal commented Jan 3, 2025

Type of Change

  • New feature

Description

Add support for confirmation flow for click to pay

currenlty in cick to pay we do authentication with mastercard and authorisation with adyen.

But to be prod certified mastercard needs a confirmation notification from hyperswitch after authorisation stating the state of the transaction.

So, in this Pr I have added confirmation flow for click to pay

How did you test it?

Add config to make the merchant eligible for authentication service

curl --location 'http://localhost:8080/configs/' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
    "key": "merchants_eligible_for_authentication_service",
    "value": "[\"sahkal\", \"cewqcewc\", \"dqwdwljildwduoqwhduwqcqwjd\"]"
}'

Create merchant connector account for Ctp_mastercard

curl --location 'http://localhost:8080/account/dqwdwljildwduoqwhduwqcqwjd/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '
{
    "connector_type": "authentication_processor",
    "connector_name": "ctp_mastercard",
    "connector_account_details": {
        "auth_type": "HeaderKey",
        "api_key": "API-KEY"
    },
    "test_mode": true,
    "disabled": false,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }
    ],
    "business_country": "US",
    "business_label": "default",
     "metadata": {
    "dpa_id": "b6e06cc6-3018-4c4c-bbf5-9fb232615090",
    "dpa_name": "TestMerchant",
    "locale": "en_AU",
    "card_brands": ["mastercard", "visa"],
    "acquirer_bin": "545301",
    "acquirer_merchant_id": "SRC3DS",
    "merchant_category_code": "0001",
    "merchant_country_code": "US"
  }
}
'

Adyen

curl --location 'http://localhost:8080/account/dqwdwljildwduoqwhduwqcqwjd/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '
{
    "connector_type": "payment_processor",
    "connector_name": "adyen",
    "connector_account_details": {
        "auth_type": "SignatureKey",
        "api_key": "API-KEY",
        "key1": "KEY-1",
        "api_secret": "API-SECRET"
    },
    "test_mode": true,
    "disabled": false,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }
    ],
    "metadata": {
        "city": "NY",
        "unit": "245",
        "live_endpoint_prefix": "vsfbjh"
    },
    "connector_webhook_details": {
        "merchant_secret": "MERCHANT SECRET"
    },
    "business_country": "US",
    "business_label": "default"
}
'

update business profile with ctp_mastercard mca_id

curl --location 'http://localhost:8080/account/dqwdwljildwduoqwhduwqcqwjd/business_profile/pro_KCTRv8sFQfC0r65CZxrn' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
    "is_click_to_pay_enabled": true,
    "authentication_product_ids": {"click_to_pay": "mca_XAXUpel8ABbpoGNF8lGz"}
}'

do payments create

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_fQsdc9JbERQ7CWvmguo84XDROuXOD1oK9sdfCJXOko3SossoI4zdxpJkOIPmojwn' \
--data '{
    "amount": 1130,
    "currency": "USD",
    "confirm": false,
    "return_url": "https://hyperswitch.io"
    }   
'

do payments confirm

curl --location 'http://localhost:8080/payments/pay_Ft9Ke5Lun924OCJa7yll/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_1f712ac5fd7f4d8c91da6a627862a4f0' \
--data '
{
    
      "payment_method": "card",
    "payment_method_type": "debit",
    "client_secret": "pay_Ft9Ke5Lun924OCJa7yll_secret_po1FVW5adQWFolWJUhMb",
    "ctp_service_details" : {
        "merchant_transaction_id": "0a4e0d3.34f4a04b.803eb38b0a56f082296538d4a70c064a6b320639",
        "correlation_id": "34f4a04b.bcd1ac39-e0f3-479e-b3ee-703ade0c66dc",
        "x_src_flow_id" : "34f4a04b.bcd1ac39-e0f3-479e-b3ee-703ade0c66dc.1727438793"
    },
    "browser_info": {
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "color_depth": 24,
        "java_enabled":true,
        "java_script_enabled": true,
        "language": "en-GB",
        "screen_height":  1440,
        "screen_width": 2560,
        "time_zone": -330,
        "user_agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36"
    }
}'

Expected Response

{
    "payment_id": "pay_Ft9Ke5Lun924OCJa7yll",
    "merchant_id": "dqwdwljildwduoqwhduwqcqwjd",
    "status": "failed",
    "amount": 1130,
    "net_amount": 1130,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": "adyen",
    "client_secret": "pay_Ft9Ke5Lun924OCJa7yll_secret_po1FVW5adQWFolWJUhMb",
    "created": "2024-12-18T13:00:47.663Z",
    "currency": "USD",
    "customer_id": null,
    "customer": null,
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": null,
    "payment_method": "card",
    "payment_method_data": null,
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": null,
    "name": null,
    "phone": null,
    "return_url": "https://hyperswitch.io/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "next_action": null,
    "cancellation_reason": null,
    "error_code": "2",
    "error_message": "Refused",
    "unified_code": "UE_9000",
    "unified_message": "Something went wrong",
    "payment_experience": null,
    "payment_method_type": "debit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": null,
    "manual_retry_allowed": true,
    "connector_transaction_id": "KN8X64SH6PRRVS65",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": null,
    "payment_link": null,
    "profile_id": "pro_KCTRv8sFQfC0r65CZxrn",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_L6N77PiH3BI2BTPwkZPL",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-12-18T13:15:47.663Z",
    "fingerprint": null,
    "browser_info": {
        "language": "en-GB",
        "time_zone": -330,
        "ip_address": "::1",
        "user_agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36",
        "color_depth": 24,
        "java_enabled": true,
        "screen_width": 2560,
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "screen_height": 1440,
        "java_script_enabled": true
    },
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-12-18T13:04:08.461Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}

Reason for it being failed is ayden doesn't support click to pay in sandbox, but does support in production

Look for confirmation call in logs

Screenshot 2025-01-06 at 12 37 23 PM

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

@sahkal sahkal 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 Jan 3, 2025
@sahkal sahkal added this to the December 2024 Release milestone Jan 3, 2025
@sahkal sahkal self-assigned this Jan 3, 2025
@sahkal sahkal requested review from a team as code owners January 3, 2025 10:19
Copy link

semanticdiff-com bot commented Jan 3, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/types.rs  88% smaller
  crates/hyperswitch_connectors/src/connectors/datatrans/transformers.rs  83% smaller
  crates/router/src/connector/checkout/transformers.rs  83% smaller
  crates/router/src/core/payments/operations/payment_confirm.rs  82% smaller
  crates/hyperswitch_domain_models/src/types.rs  67% smaller
  crates/router/src/connector/nmi/transformers.rs  65% smaller
  crates/router/src/core/payments/types.rs  60% smaller
  crates/hyperswitch_interfaces/src/types.rs  49% smaller
  crates/hyperswitch_domain_models/src/router_request_types.rs  48% smaller
  crates/hyperswitch_interfaces/src/api.rs  39% smaller
  crates/router/src/core/payments/helpers.rs  18% smaller
  crates/router/src/core/payments/connector_integration_v2_impls.rs  10% smaller
  crates/router/src/core/payments/flows.rs  9% smaller
  crates/router/src/core/unified_authentication_service.rs  8% smaller
  crates/hyperswitch_connectors/src/connectors/unified_authentication_service.rs  8% smaller
  crates/hyperswitch_connectors/src/default_implementations.rs  6% smaller
  crates/hyperswitch_connectors/src/connectors/unified_authentication_service/transformers.rs  5% smaller
  crates/router/src/core/payments.rs  4% smaller
  crates/router/src/core/unified_authentication_service/types.rs  2% smaller
  crates/hyperswitch_connectors/src/connectors/cybersource/transformers.rs  0% smaller
  crates/hyperswitch_connectors/src/connectors/wellsfargo/transformers.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_flow_types/unified_authentication_service.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_request_types/unified_authentication_service.rs  0% smaller
  crates/router/src/core/payments/operations.rs  0% smaller
  crates/router/src/core/unified_authentication_service/utils.rs Unsupported file format

ShankarSinghC
ShankarSinghC previously approved these changes Feb 12, 2025
@@ -394,6 +396,7 @@ where
&business_profile,
&key_store,
mandate_type,
&false,
Copy link
Contributor

Choose a reason for hiding this comment

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

As this does not provide the information about what is this field, can we make this as enum for better readability ?

Some("Approval Code received".to_string()),
),
_ => (
Some("03".to_string()),
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 please give code comments for this hardcoding

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for the code is provided, which states based in transaction we need to send 02 to mastercard stating approval code received and same for code 03

@sahkal sahkal removed the request for review from jarnura February 17, 2025 10:41
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Feb 20, 2025
Merged via the queue into main with commit 74bbf4b Feb 20, 2025
17 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the 7925-feature-add-support-for-confirmation-flow-for-click-to-pay branch February 20, 2025 08:04
aniketburman014 pushed a commit that referenced this pull request Feb 21, 2025
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: sai-harsha-vardhan <[email protected]>
Co-authored-by: Sai Harsha Vardhan <[email protected]>
pixincreate added a commit that referenced this pull request Feb 21, 2025
* 'main' of github.com:juspay/hyperswitch:
  fix(connector): [DATATRANS] Fix Force Sync Flow (#7331)
  chore(version): 2025.02.21.0
  fix(connector): [DATATRANS] Add new payment status (#7327)
  feat(router): [Xendit] add support for split payments (#7143)
  fix(payment_methods_v2): update fingerprint implementation in v2 (#7270)
  feat(router): Add Payments - List endpoint for v2 (#7191)
  feat(core): add support for confirmation flow for click to pay (#6982)
  chore(version): 2025.02.20.0
  fix(connector): [SCRIPT] Update template generating script and updated connector doc (#7301)
  ci(cypress): add assertions for `requires_cvv` (#7296)
  refactor(utils): match string for state with SDK's naming convention (#7300)
  feat(core): add hypersense integration api  (#7218)
  chore(version): 2025.02.19.0
  feat(connector): [Moneris] Add payments flow (#7249)
  feat(core): api ,domain and diesel model changes for extended authorization (#6607)
  feat(payments): [Payment links]  Add configs for payment link (#7288)
pixincreate added a commit that referenced this pull request Feb 22, 2025
…tusedPM

* 'main' of github.com:juspay/hyperswitch: (22 commits)
  feat(connector): add Samsung pay mandate support for Cybersource (#7298)
  chore(masking): add peek_mut to PeekInterface (#7281)
  feat(samsung_pay): collect customer address details form Samsung Pay based on business profile config and connector required fields (#7320)
  ci: update creds (#7345)
  feat(router): add `merchant_configuration_id` in netcetera metadata and make other merchant configurations optional (#7347)
  fix(routing): Fixed 5xx error logs in dynamic routing metrics (#7335)
  fix(connector): [DATATRANS] Fix Force Sync Flow (#7331)
  chore(version): 2025.02.21.0
  fix(connector): [DATATRANS] Add new payment status (#7327)
  feat(router): [Xendit] add support for split payments (#7143)
  fix(payment_methods_v2): update fingerprint implementation in v2 (#7270)
  feat(router): Add Payments - List endpoint for v2 (#7191)
  feat(core): add support for confirmation flow for click to pay (#6982)
  chore(version): 2025.02.20.0
  fix(connector): [SCRIPT] Update template generating script and updated connector doc (#7301)
  ci(cypress): add assertions for `requires_cvv` (#7296)
  refactor(utils): match string for state with SDK's naming convention (#7300)
  feat(core): add hypersense integration api  (#7218)
  chore(version): 2025.02.19.0
  feat(connector): [Moneris] Add payments flow (#7249)
  ...
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Feb 23, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants