juspay / hyperswitch

An open source payments switch written in Rust to make payments fast, reliable and affordable
https://hyperswitch.io/
Apache License 2.0
11.02k stars 1.19k forks source link

feat(router): skip apple pay session call if the browser is not Safari #5136

Closed ShankarSinghC closed 5 days ago

ShankarSinghC commented 6 days ago

Type of Change

Description

Currently, the Apple Pay session call is mandatory in all cases. This requirement also mandates configuring the initiative_context, which is the domain name where the Apple Pay payment is being processed. However, in the case of an iOS app, a domain is not required, so this field can be made optional. Additionally, in this case, the session call to Apple Pay can be skipped.

On the web, Apple Pay is supported only in Safari. Therefore, the session call should be skipped in web environments when the browser is not Safari.

Additional Changes

Motivation and Context

How did you test it?

-> Create merchant connector account with apple pay manual flow. Below is the metadata for the manual flow.

"session_token_data": {
                    "initiative": "web",
                    "certificate": "==",
                    "display_name": "applepay",
                    "certificate_keys": "",
                    "payment_processing_details_at": "Hyperswitch",
                    "payment_processing_certificate": "",
                    "payment_processing_certificate_key": "",
                    "initiative_context": "sdk-test-app.netlify.app",
                    "merchant_identifier": "",
                    "merchant_business_country": "US"
                }

-> Currently we make session call only if x_client_platform and browsername header None or if it is web and Safari respectively.

-> When mca is configured with write domain and header is not passed

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

-> When mca is configured with write domain and header is passed as

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'browsername: Safari' \
--header 'x_client_platform: web' \
--header 'api-key: pk_dev_7e0d9f48e20b430baa86eb956dc99142' \
--data '{
    "payment_id": "pay_7WAejcRN248R0Y7Kwsfh",
    "wallets": [],
    "client_secret": "pay_7WAejcRN248R0Y7Kwsfh_secret_CDL03LbGwQQnMPVA0Lq0"
}'
image

-> mac with write domain and wrong value in header

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'browsername: aa' \
--header 'x-client-platform: bb' \
--header 'api-key: pk_dev_7e0d9f48e20b430baa86eb956dc99142' \
--data '{
    "payment_id": "pay_oisWpJs0i1gXIpdYMqFp",
    "wallets": [],
    "client_secret": "pay_oisWpJs0i1gXIpdYMqFp_secret_fkzm5bW5WR5wssQxEo3f"
}'
image

-> If only one header is passed

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'x-client-platform: ios' \
--header 'api-key: pk_dev_7e0d9f48e20b430baa86eb956dc99142' \
--data '{
    "payment_id": "pay_oisWpJs0i1gXIpdYMqFp",
    "wallets": [],
    "client_secret": "pay_oisWpJs0i1gXIpdYMqFp_secret_fkzm5bW5WR5wssQxEo3f"
}'
image

Checklist