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

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

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

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
}

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/connector/checkout/transformers.rs  83% smaller
  crates/router/src/connector/nmi/transformers.rs  65% smaller
  crates/router/src/core/payments/types.rs  60% smaller
  crates/hyperswitch_domain_models/src/router_request_types.rs  48% smaller
  crates/router/src/types.rs  46% smaller
  crates/hyperswitch_interfaces/src/types.rs  37% smaller
  crates/router/src/core/payments/connector_integration_v2_impls.rs  34% smaller
  crates/hyperswitch_domain_models/src/types.rs  22% smaller
  crates/router/src/core/unified_authentication_service.rs  16% smaller
  crates/hyperswitch_interfaces/src/api.rs  6% smaller
  crates/router/src/core/unified_authentication_service/transformers.rs  6% smaller
  crates/hyperswitch_connectors/src/connectors/unified_authentication_service/transformers.rs  5% smaller
  crates/hyperswitch_connectors/src/connectors/unified_authentication_service.rs  5% smaller
  crates/router/src/core/payments/flows.rs  5% smaller
  crates/router/src/core/payments.rs  5% smaller
  crates/hyperswitch_connectors/src/default_implementations.rs  4% smaller
  crates/router/src/core/unified_authentication_service/types.rs  2% smaller
  crates/router/src/core/payments/operations/payment_confirm.rs  1% 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

@sahkal sahkal requested review from a team as code owners January 6, 2025 07:08
@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Jan 6, 2025
@sahkal sahkal changed the base branch from 7862-refactor-refactor-ctp-flow-to-fetch-mca_id-and-get-the-connector-creds-instead-of-connector_name to main January 6, 2025 07:09
@hyperswitch-bot hyperswitch-bot bot removed the M-database-changes Metadata: This PR involves database schema changes label Jan 6, 2025
@sahkal sahkal removed request for a team January 6, 2025 07:09
@sahkal sahkal changed the base branch from main to 7862-refactor-refactor-ctp-flow-to-fetch-mca_id-and-get-the-connector-creds-instead-of-connector_name January 6, 2025 09:18
sahkal and others added 3 commits January 6, 2025 14:49
…_id-and-get-the-connector-creds-instead-of-connector_name
…-the-connector-creds-instead-of-connector_name' of https://github.com/juspay/hyperswitch into 7925-feature-add-support-for-confirmation-flow-for-click-to-pay
@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 6, 2025
Base automatically changed from 7862-refactor-refactor-ctp-flow-to-fetch-mca_id-and-get-the-connector-creds-instead-of-connector_name to main January 20, 2025 12:02
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 20, 2025
@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 21, 2025
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

Attention: Patch coverage is 0% with 179 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@cf82861). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...s/src/connectors/unified_authentication_service.rs 0.00% 82 Missing ⚠️
...ors/unified_authentication_service/transformers.rs 0.00% 48 Missing ⚠️
...ore/unified_authentication_service/transformers.rs 0.00% 13 Missing ⚠️
crates/router/src/connector/nmi/transformers.rs 0.00% 8 Missing ⚠️
...ates/router/src/connector/checkout/transformers.rs 0.00% 7 Missing ⚠️
...nectors/src/connectors/cybersource/transformers.rs 0.00% 6 Missing ⚠️
.../router/src/core/unified_authentication_service.rs 0.00% 5 Missing ⚠️
...r/src/core/unified_authentication_service/utils.rs 0.00% 4 Missing ⚠️
crates/router/src/core/payments/types.rs 0.00% 3 Missing ⚠️
...nnectors/src/connectors/wellsfargo/transformers.rs 0.00% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6982   +/-   ##
=======================================
  Coverage        ?    4.11%           
=======================================
  Files           ?     1011           
  Lines           ?   207554           
  Branches        ?        0           
=======================================
  Hits            ?     8548           
  Misses          ?   199006           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 S-waiting-on-review Status: This PR has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants