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(payment_methods): pass required shipping details field for wallets session call based on business_profile config #4616

Merged
merged 50 commits into from
May 14, 2024

Conversation

ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented May 9, 2024

Type of Change

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

Description

This change is required as part of the one click checkout where in which we expect apple pay to collect the shipping details from the customer and pass it in the confirm call with the payment_data.
In order for apple pay to collect the shipping details from customer we need to pass "requiredShippingContactFields": ["postalAddress", "phone", "email"] in the /session call. Hence we need to have a validation in the backend that checks for the business profile config (collect_shipping_details_from_wallet_connector) fields and pass the required_shipping_contact_fields to sdk.

Similarly for google_pay we need to pass the below fields for shipping details.

"shipping_address_required": true,
            "email_required": true,
            "shipping_address_parameters": {
                "phone_number_required": true
            },

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

-> Create a MCA for cybersource enable google_pay and apple_pay
-> Update a field in business_profile

curl --location 'http://localhost:8080/account/merchant_1715276947/business_profile/pro_DnFkGi1RPLPSmJKy54Ib' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "collect_shipping_details_from_wallet_connector": true
}'

-> Apple pay payment create with confirm false

{
    "amount": 650,
    "currency": "USD",
    "confirm": false,
    "business_country": "US",
    "business_label": "default",
    "amount_to_capture": 650,
    "customer_id": "custhype1232",
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "three_ds",
    "return_url": "https://google.com",
    "email": "[email protected]",
    "name": "Joseph Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "payment_method": "wallet",
    "payment_method_type": "apple_pay",
    "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"
        }
    },
    "payment_method_data": {
        "wallet": {
            "apple_pay": {
                "payment_data":"eyJkYXRhIjoiQ1ZoTGd5RGU3TzZjdFlhWHFiVWFONFZvRjBCQjhTbDZsenlXYUdCKzhKcXlic2hYVGxoNEFEcTZYb0t6ZWVSVGwvcUp6NDIvUFMwcmMxMCtqSyt5Z1F5NnlkT25EcnVDeVpkaVU4SWFGOEtOS2hJMFFKOU9JTk9aWFlYR0VzZEczNXlVNzcrQ0k1dk5lUjJiK1gyUXZTVTMzSjlOczJuTFRXZHpwb1VUSHJKU1RiSmFmTTlxYjlZOHZuZS9vZUdHQkV1ZU9DQWQxcFhjRE54SEl2dlc5Z0x3WXRPVldKZUEvUnh5MEdsb0VISng3VEhqUEVQUGJwMkVVZjRMQXZQOGlJSEpmUjM0THdEUVBIdmNSeW9nalRJSzJqOXZjUGRqS2xBSG1LUm5wZlhvWkY4VE16ZUJ6eWhGb0dKY3ZRa3JMc216OEcxTXowZGxlV2VmU2V0TkYxT1NMaldCdExrUXpvWG5xdU1ZeExMenU2SkxPZ1E5ejN1OStFNGQ2NHRZS1NYYlZBWGRKNXRMNTdvbSIsInNpZ25hdHVyZSI6Ik1JQUdDU3FHU0liM0RRRUhBcUNBTUlBQ0FRRXhEVEFMQmdsZ2hrZ0JaUU1FQWdFd2dBWUpLb1pJaHZjTkFRY0JBQUNnZ0RDQ0ErTXdnZ09Jb0FNQ0FRSUNDRXd3UVVsUm5WUTJNQW9HQ0NxR1NNNDlCQU1DTUhveExqQXNCZ05WQkFNTUpVRndjR3hsSUVGd2NHeHBZMkYwYVc5dUlFbHVkR1ZuY21GMGFXOXVJRU5CSUMwZ1J6TXhKakFrQm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UnBabWxqWVhScGIyNGdRWFYwYUc5eWFYUjVNUk13RVFZRFZRUUtEQXBCY0hCc1pTQkpibU11TVFzd0NRWURWUVFHRXdKVlV3SUlUREJCU1ZHZFZEWXdDd1lKWUlaSUFXVURCQUlCb0lHVE1CZ0dDU3FHU0liM0RRRUpBekVMQmdrcWhraUc5dzBCQndFd0hBWUpLb1pJaHZjTkFRa0ZNUThYRFRJME1ETXhOREE1TkRNeU0xb3dLQVlKS29aSWh2Y05BUWswTVJzdNTdMRElUVUQwcVI3RHd5SGx1VG0xMjJCejA5c2FzMkJVWitFRTlVPSIsImVwaGVtZXJhbFB1YmxpY0tleSI6Ik1Ga3dFd1lIS29aSXpqMENBUVlJS29aSXpqMERBUWNEUWdBRXBoMkNUKytubXZpYjU3YWNJZmVKTjFCQmJyZUEveG84N2p1b0xETDFnS1IvYy9wRDZYK0xKSGRYUGJnMFBIT3pYYjJFYm5RR1ZWYmZIWHRkQzBYTTdBPT0iLCJ0cmFuc2FjdGlvbklkIjoiMjBlYzhlM2I2N2YyYmNmMDExMDVmODAwNmEwNWFmNTRiNjBkZDIwMzgyOTdlMmExMmI0Y2FlNDY0ODhjYjZhOSJ9LCJ2ZXJzaW9uIjoiRUNfdjEifQ==",
                "payment_method": {
                    "display_name": "Visa 0326",
                    "network": "Mastercard",
                    "type": "debit"
                },
                "transaction_identifier": "55CC32D7BF7890B9064433F15B9F23F849CF84AFD01E4E65DD8ADE306300E9D8"
            }
        }
    }
}

-> Make a /session call

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'api-key: api_key' \
--data '{
    "payment_id": "pay_oit9SUYrdsYlI0WvCh1L",
    "wallets": [],
    "client_secret": "pay_oit9SUYrdsYlI0WvCh1L_secret_N61PV7OLGKa7PI0dv2Wo"
}'

Required shipping details set for apple_pay in the session call
image

Required shipping details set for google_pay in the session call
image

List payment method list for merchant

curl --location 'http://localhost:8080/account/payment_methods?client_secret=pay_vJbV82f2bSFHZyTTex4X_secret_sSognYwAhzqMANozUw34' \
--header 'Accept: application/json' \
--header 'api-key: api_key'
image

Motivation and Context

How did you test it?

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

@ShankarSinghC ShankarSinghC changed the title feat(payment_methods): pass field in apple pay session call based on business_profile config feat(payment_methods): pass required shipping details field for wallets session call based on business_profile config May 10, 2024
Base automatically changed from apple_pay/billing-dynamic-fields to main May 13, 2024 14:16
Comment on lines +2240 to +2256
// Remove shipping fields from required fields based on business profile configuration
if should_send_shipping_details != Some(true) {
let shipping_variants =
api_enums::FieldType::get_shipping_variants();

let keys_to_be_removed = required_fields_hs
.iter()
.filter(|(_key, value)| {
shipping_variants.contains(&value.field_type)
})
.map(|(key, _value)| key.to_string())
.collect::<Vec<_>>();

keys_to_be_removed.iter().for_each(|key_to_be_removed| {
required_fields_hs.remove(key_to_be_removed);
});
}
Copy link
Member

Choose a reason for hiding this comment

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

instead of removing the fields, we can extend the required fields based on the config

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, I will take this up in next pr.

@likhinbopanna likhinbopanna added this pull request to the merge queue May 14, 2024
Merged via the queue into main with commit 650f3fa May 14, 2024
9 of 12 checks passed
@likhinbopanna likhinbopanna deleted the apple_pay/shipping-dynamic-fields branch May 14, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-payment-methods Area: Payment Methods
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pass required_shipping_contact_fields field in apple pay session call based on business_profile config
5 participants