Skip to content

Conversation

@Sakilmostak
Copy link
Contributor

@Sakilmostak Sakilmostak commented Jan 6, 2025

Type of Change

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

Description

Decryption flow for google pays
Decrypts the token using public and private key of merchant
API contract change for MCA, includes credentials for decryption collection using connector_wallets_details
Note: This PR also bumps the msrv version from 1.78.0 to 1.80.0

Additional Changes

Motivation and Context

How did you test it?

Tested through Postman:

  • Create a MCA with google_pay keys (public, private and root_signing keys) for Cybersource:
{
    "connector_type": "payment_processor",
    "connector_name": "cybersource",
    "connector_label": "cybersource_AU_defa",
    "connector_account_details": {
        "key1": "key1",
        "api_key": "api_key",
        "api_secret": "api_secret",
        "auth_type": "SignatureKey"
    },
    "test_mode": false,
    "disabled": false,
    "payment_methods_enabled": [
        
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "google_pay",
                    "payment_experience": "redirect_to_url",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": false
                }
            ]
        }
    ],
    "connector_wallets_details": {
        "google_pay": {
            "provider_details": {
                "merchant_info": {
                    "merchant_name": "cybersource",
                    "tokenization_specification": {
                        "type": "DIRECT",
                        "parameters": {
                            "gateway": "cybersource",
                            "public_key": "public_key",
                            "private_key": "private_key",
                            "root_signing_keys": "root_signing_keys",
                            "recipient_id": "recipient_id"
                        }
                    }
                }
            },
            "cards": {
                "allowed_auth_methods": [
                    "PAN_ONLY",
                    "CRYPTOGRAM_3DS"
                ],
                "allowed_card_networks": [
                    "AMEX",
                    "DISCOVER",
                    "INTERAC",
                    "JCB",
                    "MASTERCARD",
                    "VISA"
                ],
            }
        }
    },
    "connector_webhook_details": {
        "merchant_secret": "ee148db14b97d503ab5958e7abb5c374",
        "additional_secret": null
    }
}
  • Create Google Pay Token with given parameters:
parameters: {
      "protocolVersion": "ECv2",
  		"publicKey": "publicKey"
  }
  • Create a Payment with the generated token:
{
    "amount": 6540,
    "currency": "EUR",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 6540,
    "customer_id": "{{customer_id}}",
    "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": "wallet",
    "payment_method_type": "google_pay",
    "payment_method_data": {
        "wallet": {
            "google_pay": {
                "type": "CARD",
                "description": "SuccessfulAuth: Visa •••• 1000",
                "info": {
                    "card_network": "VISA",
                    "card_details": "1000",
                    "assurance_details": {
                        "card_holder_authenticated": false,
                        "account_verified": true
                    }
                },
                "tokenization_data": {
                    "type": "DIRECT",
                    "token": "{{put_generated_token}}"
                }
            }
        },
        "billing": {
            "address": {
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "city": "San Fransico",
                "state": "California",
                "zip": "94122",
                "country": "US",
                "first_name": "joseph",
                "last_name": "Doe"
            },
            "phone": {
                "number": "8056594427",
                "country_code": "+91"
            }
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
  • The response should have succeed status
{
    "payment_id": "pay_UC3XsEwe26nx70RbwwLT",
    "merchant_id": "merchant_1737919085",
    "status": "succeeded",
    "amount": 6540,
    "net_amount": 6540,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 6540,
    "connector": "cybersource",
    "client_secret": "pay_UC3XsEwe26nx70RbwwLT_secret_Ay0XCgzSSc5DDDhAevvw",
    "created": "2025-01-26T19:18:31.927Z",
    "currency": "EUR",
    "customer_id": "cus_oRTeJ7WknRcwKjLdf3Ao",
    "customer": {
        "id": "cus_oRTeJ7WknRcwKjLdf3Ao",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "wallet",
    "payment_method_data": {
        "wallet": {
            "google_pay": {
                "last4": "1000",
                "card_network": "VISA",
                "type": "CARD"
            }
        },
        "billing": {
            "address": {
                "city": "San Fransico",
                "country": "US",
                "line1": "1467",
                "line2": "Harrison Street",
                "line3": "Harrison Street",
                "zip": "94122",
                "state": "California",
                "first_name": "joseph",
                "last_name": "Doe"
            },
            "phone": {
                "number": "8056594427",
                "country_code": "+91"
            },
            "email": null
        }
    },
    "payment_token": null,
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "billing": null,
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "google_pay",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cus_oRTeJ7WknRcwKjLdf3Ao",
        "created_at": 1737919111,
        "expires": 1737922711,
        "secret": "epk_fb46c2777fe74011afeedc26ded6b5c8"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "7379191134856729404807",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_UC3XsEwe26nx70RbwwLT_1",
    "payment_link": null,
    "profile_id": "pro_h9SNYPWcW7Imw5n2AG0x",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_GiYH6JhoTv4WZQdrlgz2",
    "incremental_authorization_allowed": false,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-01-26T19:33:31.927Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-01-26T19:18:33.874Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": 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

@Sakilmostak Sakilmostak added A-connector-integration Area: Connector integration A-core Area: Core flows labels Jan 6, 2025
@Sakilmostak Sakilmostak self-assigned this Jan 6, 2025
@Sakilmostak Sakilmostak requested review from a team as code owners January 6, 2025 07:02
@semanticdiff-com
Copy link

semanticdiff-com bot commented Jan 6, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/hyperswitch_connectors/src/connectors/gocardless/transformers.rs  83% smaller
  crates/router/src/types.rs  79% smaller
  crates/common_utils/src/custom_serde.rs  32% smaller
  crates/hyperswitch_connectors/src/connectors/cybersource/transformers.rs  14% smaller
  crates/cards/src/lib.rs  8% smaller
  crates/router/src/core/payments.rs  2% smaller
  .deepsource.toml Unsupported file format
  Cargo.lock Unsupported file format
  Cargo.toml Unsupported file format
  INSTALL_dependencies.sh Unsupported file format
  api-reference-v2/openapi_spec.json  0% smaller
  api-reference/openapi_spec.json  0% smaller
  config/config.example.toml Unsupported file format
  config/deployments/env_specific.toml Unsupported file format
  config/development.toml Unsupported file format
  crates/api_models/src/admin.rs  0% smaller
  crates/api_models/src/payments.rs  0% smaller
  crates/common_enums/src/enums.rs  0% smaller
  crates/common_utils/Cargo.toml Unsupported file format
  crates/common_utils/src/lib.rs  0% smaller
  crates/hyperswitch_connectors/src/connectors/bankofamerica/transformers.rs  0% smaller
  crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs  0% smaller
  crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs  0% smaller
  crates/hyperswitch_connectors/src/connectors/square/transformers.rs  0% smaller
  crates/hyperswitch_connectors/src/connectors/stax/transformers.rs  0% smaller
  crates/hyperswitch_connectors/src/connectors/wellsfargo/transformers.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_data.rs  0% smaller
  crates/masking/src/secret.rs  0% smaller
  crates/router/Cargo.toml Unsupported file format
  crates/router/src/configs/secrets_transformers.rs  0% smaller
  crates/router/src/configs/settings.rs  0% smaller
  crates/router/src/configs/validations.rs  0% smaller
  crates/router/src/connector/braintree/transformers.rs  0% smaller
  crates/router/src/connector/checkout/transformers.rs  0% smaller
  crates/router/src/connector/payme/transformers.rs  0% smaller
  crates/router/src/connector/stripe/transformers.rs  0% smaller
  crates/router/src/core/errors.rs  0% smaller
  crates/router/src/core/payments/helpers.rs  0% smaller
  crates/router/src/core/payments/tokenization.rs  0% smaller

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 6, 2025
@Sakilmostak Sakilmostak force-pushed the google_pay_decrypt_flow branch from 0106c38 to bdc45bc Compare January 29, 2025 12:09
Copy link
Contributor

@ShankarSinghC ShankarSinghC left a comment

Choose a reason for hiding this comment

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

Add some debug logs in the google decryption flow.

Copy link
Contributor

@ShankarSinghC ShankarSinghC left a comment

Choose a reason for hiding this comment

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

LGTM
Add some debug logs in the google decryption flow.

Copy link
Contributor

@ShankarSinghC ShankarSinghC left a comment

Choose a reason for hiding this comment

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

LGTM
Add some debug logs in the google decryption flow.

@Sakilmostak Sakilmostak requested a review from a team as a code owner February 3, 2025 10:23
SanchithHegde
SanchithHegde previously approved these changes Feb 3, 2025
ShankarSinghC
ShankarSinghC previously approved these changes Feb 4, 2025
deepanshu-iiitu
deepanshu-iiitu previously approved these changes Feb 4, 2025
pub struct GooglePayDecryptedData {
pub message_expiration: String,
pub message_id: String,
pub payment_method: String,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub payment_method: String,
pub payment_method_type: String,

.attach_printable("failed to decrypt google pay token")?,
)
}
_ => None,
Copy link
Member

Choose a reason for hiding this comment

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

Add logs, add context about the variants.

google_pay_predecrypt,
))))
}
_ => Ok(None),
Copy link
Member

Choose a reason for hiding this comment

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

Add logs, add context about the variants.


// derive 64 bytes for the output key (symmetric encryption + MAC key)
let mut output_key = vec![0u8; 64];
hkdf.expand(SENDER_ID, &mut output_key).map_err(|_| {
Copy link
Member

Choose a reason for hiding this comment

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

Lift the error or log the error here

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Feb 5, 2025
Merged via the queue into main with commit e0ec27d Feb 5, 2025
17 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the google_pay_decrypt_flow branch February 5, 2025 11:07
Narayanbhat166 pushed a commit that referenced this pull request Feb 6, 2025
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Gnanasundari24 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-connector-integration Area: Connector integration A-core Area: Core flows M-api-contract-changes Metadata: This PR involves API contract changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants