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): added customer phone_number and email to session token response for click to pay #6863

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

Conversation

sahkal
Copy link
Contributor

@sahkal sahkal commented Dec 17, 2024

Type of Change

  • Enhancement

Description

Add customer phone_number and email to session token response for click to pay

How did you test it?

Add Ctp_mastercard as a connector and send relevant details to ctp in connector metadata

curl --location 'http://localhost:8080/account/dqwdwljildqwjd/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"
  }
}
'

update business profile with

"is_click_to_pay_enabled": true,
"authentication_product_ids": {"click_to_pay": "mca_id"}

Do payments create with customer details

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_myZVgK2frn2tWuTghpqBw4YmFcVOKoQ0etjGKyZCdegwHvKiGQgZOvhGsu7ShkaU' \
--data-raw '{
    "amount": 1130,
    "currency": "USD",
    "confirm": false,
    "return_url": "https://hyperswitch.io",
    "customer": {
        "email": "[email protected]",
        "id": "cus_abcdccqjciefgh",
        "name": "John Dough",
        "phone": "9123456789"
  } 
}'

Look for customer details in click to pay session response

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'x-feature: integ-custom' \
--header 'api-key: pk_dev_a82510aa11054218bfbae152586fb16d' \
--data '{
    "payment_id": "pay_gEidbQrgy29Hu2JfUWto",
    "client_secret": "pay_gEidbQrgy29Hu2JfUWto_secret_PfoMiqnCRZL3uCKrNDmv",
    "wallets": []
}
'

Response

{
    "payment_id": "pay_gEidbQrgy29Hu2JfUWto",
    "client_secret": "pay_gEidbQrgy29Hu2JfUWto_secret_PfoMiqnCRZL3uCKrNDmv",
    "session_token": [
        {
            "wallet_name": "click_to_pay",
            "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",
            "transaction_amount": "11.30",
            "transaction_currency_code": "USD",
            "phone_number": "9123456789",
            "email": "[email protected]"
        }
    ]
}

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 S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Dec 17, 2024
@sahkal sahkal added this to the December 2024 Release milestone Dec 17, 2024
@sahkal sahkal self-assigned this Dec 17, 2024
@sahkal sahkal requested review from a team as code owners December 17, 2024 12:10
Copy link

semanticdiff-com bot commented Dec 17, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments.rs  2% smaller
  api-reference-v2/openapi_spec.json  0% smaller
  api-reference/openapi_spec.json  0% smaller
  crates/api_models/src/payments.rs  0% smaller

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Dec 18, 2024
customer_details.phone_country_code.as_ref(),
) {
(Some(_), Some(_)) => Ok(()),
(None, None) => Err(errors::ApiErrorResponse::MissingRequiredFields {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we should be mentioning in the error that, either email or phone number is required for ctp flow. So, that merchant would do the integration accordingly right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, will add another level of error check

@@ -6997,6 +6997,10 @@ pub struct ClickToPaySessionResponse {
pub transaction_amount: StringMajorUnit,
#[schema(value_type = Currency)]
pub transaction_currency_code: common_enums::Currency,
pub phone_number: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

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

Can we wrap this within a Secret?

.customer_details
.as_ref()
.map(|details| {
serde_json::from_value::<CustomerData>(details.clone().into_inner().expose())
Copy link
Member

Choose a reason for hiding this comment

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

Nit: We can call parse_value() 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 M-api-contract-changes Metadata: This PR involves API contract changes 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.

3 participants