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(connector): add support for external authentication for cybersource #4714

Merged
merged 11 commits into from
May 29, 2024

Conversation

hrithikesh026
Copy link
Contributor

@hrithikesh026 hrithikesh026 commented May 21, 2024

Type of Change

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

Description

add support for external authentication for cybersource.
After this change is merged, we'll be able to authenticate a payment through an external 3ds authentication(threedsecureio or netcetera) and authorise the same payment through cybersource.

Other changes:
Added ds_trans_id field to authentication table since it is required for authorization through cybersource.

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?

Ran cybersource postman collection to make sure existing 3ds flow is not affected.
Screenshot 2024-05-23 at 1 00 07 PM

curls:

  1. Create a cybersource connector and netcetera authentication connector.
curl --location 'http://localhost:8080/account/postman_merchant_GHAction_7360288d-b77e-4624-8a48-74c11c31d3a0/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "fiz_operations",
    "connector_name": "cybersource",
    "connector_account_details": {
        "auth_type": "SignatureKey",
        "api_key": "",
        "key1": "",
        "api_secret": ""
    },
    "test_mode": false,
    "disabled": false,
    "business_country": "US",
    "business_label": "default",
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "debit",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "apple_pay",
                    "payment_experience": "invoke_sdk_client",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "google_pay",
                    "payment_experience": "invoke_sdk_client",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }
    ],
    "metadata": {
        "acquirer_bin": "438309",
        "acquirer_merchant_id": "00002000000"
    }
}'
curl --location 'http://localhost:8080/account/postman_merchant_GHAction_7360288d-b77e-4624-8a48-74c11c31d3a0/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "authentication_processor",
    "business_country": "US",
    "business_label": "default",
    "connector_name": "netcetera",
    "connector_account_details": {
        "auth_type": "CertificateAuth",
        "certificate": "",
        "private_key": ""
    },
    "test_mode": true,
    "disabled": false,
    "metadata": {
        "mcc": "5411",
        "merchant_country_code": "840",
        "merchant_name": "Dummy Merchant",
        "endpoint_prefix": "flowbird",
        "three_ds_requestor_name": "juspay-prev",
        "three_ds_requestor_id": "juspay-prev",
        "pull_mechanism_for_external_3ds_enabled": false
    }
}'
  1. Create a payment with "request_external_three_ds_authentication": true, and "authentication_type": "three_ds",
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_Mv6wkxquIeO6WDvY49Mpd4hullQ4CW05hBRT7tlIX4EOS5NaG5fmDzuY5NqacvXT' \
--data-raw '{
    "amount": 6540,
    "currency": "USD",
    "confirm": false,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 6540,
    "customer_id": "StripeCustomer",
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    "authentication_type": "three_ds",
    "return_url": "https://duck.com",
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX"
        },
        "phone": {
            "number": "123456789",
            "country_code": "12"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX"
        },
        "phone": {
            "number": "123456789",
            "country_code": "12"
        }
    },
    "request_external_three_ds_authentication": true,
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
  1. Confirm the payment
curl --location 'http://localhost:8080/payments/pay_XPc0gwoIZLYpMBKI8Yng/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_d777ba4dfb764db2a6f851870a00a7e5' \
--data '{
    "browser_info": {
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "115.99.183.2"
    },
    "client_secret": "pay_XPc0gwoIZLYpMBKI8Yng_secret_vRjk6g87hvftbO9z18BO",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "4929251897047956", 
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
        }
    }
}'
  1. Authenticate the payment.
curl --location 'http://localhost:8080/payments/pay_XPc0gwoIZLYpMBKI8Yng/3ds/authentication' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_d777ba4dfb764db2a6f851870a00a7e5' \
--data '{
    "client_secret": "pay_XPc0gwoIZLYpMBKI8Yng_secret_vRjk6g87hvftbO9z18BO",
    "device_channel": "BRW",
    "threeds_method_comp_ind": "N"
}'
  1. Authorize the payment.
curl --location 'http://localhost:8080/payments/pay_XPc0gwoIZLYpMBKI8Yng/postman_merchant_GHAction_7360288d-b77e-4624-8a48-74c11c31d3a0/authorize/checkout' \
--header 'Content-Type: application/json' \
--data '{
    
}'
  1. Retrive the payment.
curl --location 'http://localhost:8080/payments/pay_XPc0gwoIZLYpMBKI8Yng?force_sync=true' \
--header 'Accept: application/json' \
--header 'api-key: dev_Mv6wkxquIeO6WDvY49Mpd4hullQ4CW05hBRT7tlIX4EOS5NaG5fmDzuY5NqacvXT'

Payment should succeed and below object should be returned in the payment response body.

"external_authentication_details": {
        "authentication_flow": "frictionless",
        "electronic_commerce_indicator": null,
        "status": "success",
        "ds_transaction_id": "3961a5b1-593f-4f94-851e-2793cd7f9e77",
        "version": "2.2.0",
        "error_code": null,
        "error_message": null
    }

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

@hrithikesh026 hrithikesh026 added S-waiting-on-review Status: This PR has been implemented and needs to be reviewed M-database-changes Metadata: This PR involves database schema changes labels May 21, 2024
@hrithikesh026 hrithikesh026 self-assigned this May 21, 2024
@hrithikesh026 hrithikesh026 requested review from a team as code owners May 21, 2024 11:09
@hrithikesh026 hrithikesh026 linked an issue May 22, 2024 that may be closed by this pull request
2 tasks
AkshayaFoiger
AkshayaFoiger previously approved these changes May 28, 2024
crates/router/src/connector/cybersource/transformers.rs Outdated Show resolved Hide resolved
pa_specification_version: Option<PaSpecificationVersion>,
/// Verification response enrollment status.
///
/// This field is supported only on Asia, Middle East, and Africa Gateway.
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the US gateway? Should we skip sending this value or external authentication itself is not available?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is a required field for Asia, Middle East, and Africa Gateway.

crates/router/src/connector/cybersource/transformers.rs Outdated Show resolved Hide resolved
cavv,
ucaf_authentication_data,
xid: Some(authn_data.threeds_server_transaction_id.clone()),
// xid: None,
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 remove this comment?

@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE authentication DROP COLUMN ds_trans_id;
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
ALTER TABLE authentication DROP COLUMN ds_trans_id;
ALTER TABLE authentication DROP COLUMN IF EXISTS ds_trans_id;

@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE authentication ADD COLUMN ds_trans_id VARCHAR;
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
ALTER TABLE authentication ADD COLUMN ds_trans_id VARCHAR;
ALTER TABLE authentication ADD COLUMN IF NOT EXISTS ds_trans_id VARCHAR;

@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE authentication ADD COLUMN ds_trans_id VARCHAR;
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 specify some length for the VARCHAR here?

.as_ref()
.and_then(|authn_data| {
authn_data.eci.as_ref().map(|eci| {
match eci.as_str() {
Copy link
Contributor

@sai-harsha-vardhan sai-harsha-vardhan May 29, 2024

Choose a reason for hiding this comment

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

Can we please move this match statement to a fn?

SamraatBansal
SamraatBansal previously approved these changes May 29, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue May 29, 2024
Merged via the queue into main with commit 97f2ff0 May 29, 2024
16 checks passed
@likhinbopanna likhinbopanna deleted the add-support-external-authentication-cybersource branch May 29, 2024 13:51
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add support for external 3ds authentication in cybersource.
6 participants