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): [Paypal] Add session_token flow for Paypal sdk #4697

Merged
merged 24 commits into from
May 27, 2024

Conversation

SamraatBansal
Copy link
Contributor

@SamraatBansal SamraatBansal commented May 19, 2024

Type of Change

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

Description

Add session_token flow to enable Paypal via Paypal SDK

  • Accept data in metadata field of the MCA - create call
  • Return that data in the sessions call
  • Change payment_experience for paypal via paypal to sdk

Additional Changes

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

Motivation and Context

#4698

How did you test it?

Create Paypal MCA with payment_experience as invoke_sdk_client for Paypal Wallet

curl --location 'http://localhost:8080/account/merchant_1716757295/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "fiz_operations",
    "business_country": "US",
    
    "connector_name": "paypal",
    "connector_account_details": {
        "auth_type": "BodyKey",
        "api_key": "********************************",
        "key1": "ASK*****************************_2"
    },
    "test_mode": true,
    "disabled": false,
"payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "payment_experience": null,
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 0,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "payment_experience": null,
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "paypal",
                    "payment_experience": "invoke_sdk_client",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }
    ],
    "metadata": {
        "paypal_sdk": {
            "client_id": "ASK****************************_2"
        }
    }
}'

Payments Create

curl --location 'http://localhost:8080/payments' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_33Ad6faEcusLrqrqSeeFWyGRyTfOkKMoPMTSirAhCg0qqwkxQ25t7K1ucBEoq26M' \
--data-raw '{
    "amount": 6100,
    "currency": "USD",
    "confirm": false,
    "business_country": "US",
    "business_label": "default",
    "amount_to_capture": 6100,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "return_url": "https://google.com",
    "email": "something@gmail.com",
    "name": "Joseph Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "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"
        }
    }
}'

Session Token

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

Response

{
    "payment_id": "pay_msQQCSrBSCeNAZjBgwj9",
    "client_secret": "pay_msQQCSrBSCeNAZjBgwj9_secret_JdfpEbRZl5KTYwtNCURW",
    "session_token": [
        {
            "wallet_name": "paypal",
            "connector": "paypal",
            "session_token": "ASK************************_2",
            "sdk_next_action": {
                "next_action": "confirm"
            }
        }
    ]
}

Payments - Confirm

curl --location 'http://localhost:8080/payments/pay_msQQCSrBSCeNAZjBgwj9/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_33Ad6faEcusLrqrqSeeFWyGRyTfOkKMoPMTSirAhCg0qqwkxQ25t7K1ucBEoq26M' \
--data '{
    "confirm": true,
    "payment_method": "wallet",
    "payment_method_type": "paypal",
    "payment_method_data": {
        "wallet": {
            "paypal_sdk": {
            "token":""
            }
        }
    }  
}'

Response:

{
    "payment_id": "pay_msQQCSrBSCeNAZjBgwj9",
    "merchant_id": "merchant_1716757295",
    "status": "requires_customer_action",
    "amount": 6100,
    "net_amount": 6100,
    "amount_capturable": 6100,
    "amount_received": null,
    "connector": "paypal",
    "client_secret": "pay_msQQCSrBSCeNAZjBgwj9_secret_JdfpEbRZl5KTYwtNCURW",
    "created": "2024-05-26T21:03:19.068Z",
    "currency": "USD",
    "customer_id": null,
    "customer": null,
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "wallet",
    "payment_method_data": {
        "wallet": {},
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "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
    },
    "order_details": null,
    "email": null,
    "name": null,
    "phone": null,
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "next_action": {
        "type": "invoke_sdk_client",
        "next_action_data": {
            "next_action": "complete_authorize"
        }
    },
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "paypal",
    "connector_label": "paypal_US_default",
    "business_country": "US",
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": null,
    "manual_retry_allowed": null,
    "connector_transaction_id": "39X68391D53803705",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": {
        "apple_pay": null,
        "airwallex": null,
        "noon": {
            "order_category": "pay"
        }
    },
    "feature_metadata": null,
    "reference_id": "pay_msQQCSrBSCeNAZjBgwj9_1",
    "payment_link": null,
    "profile_id": "pro_L6gjuuDhzdKR9wlyV8yA",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_ziKihOYd8bxdqpoLhP3u",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-05-26T21:18:19.068Z",
    "fingerprint": null,
    "browser_info": {
        "language": null,
        "time_zone": null,
        "ip_address": "::1",
        "user_agent": null,
        "color_depth": null,
        "java_enabled": null,
        "screen_width": null,
        "accept_header": null,
        "screen_height": null,
        "java_script_enabled": null
    },
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-05-26T21:06:09.286Z",
    "charges": null,
    "frm_metadata": null
}

Authenticate Payment via SDK

Payments - Complete Authorize

curl --location 'http://localhost:8080/payments/pay_msQQCSrBSCeNAZjBgwj9/complete_authorize' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_77ee3a2eb65741a0a4a3f1f6f3f0aa94' \
--data-raw '{
  "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Kormangala",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "guest@example.com"
    },
    "client_secret": "pay_msQQCSrBSCeNAZjBgwj9_secret_JdfpEbRZl5KTYwtNCURW"
}'

Test Scenarios

  • Test all the payments flow: Authorize, Manual Capture, Auto Capture, Refunds and webhooks
  • Test for backwards compatibility: i.e use an older account where redirect_to_url is configured as payment_experience none of the flow should get affected by new code
  • Update the connector account to SDK experience and then sync older payments and try new payments as well

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

@SamraatBansal SamraatBansal self-assigned this May 19, 2024
@SamraatBansal SamraatBansal requested review from a team as code owners May 19, 2024 17:37
@SamraatBansal SamraatBansal linked an issue May 19, 2024 that may be closed by this pull request
2 tasks
@SamraatBansal SamraatBansal added A-core Area: Core flows C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed M-api-contract-changes Metadata: This PR involves API contract changes labels May 19, 2024
Base automatically changed from complete-authorize to main May 20, 2024 16:17
@SamraatBansal SamraatBansal requested a review from a team as a code owner May 20, 2024 16:17
@SamraatBansal SamraatBansal requested a review from a team as a code owner May 22, 2024 12:04
@Narayanbhat166
Copy link
Member

Can you add api contracts foe each of the api calls?

prasunna09
prasunna09 previously approved these changes May 27, 2024
Narayanbhat166
Narayanbhat166 previously approved these changes May 27, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue May 27, 2024
Merged via the queue into main with commit b3d4d13 May 27, 2024
10 checks passed
@likhinbopanna likhinbopanna deleted the paypal-sdk-session branch May 27, 2024 11:19
ghost pushed a commit that referenced this pull request May 29, 2024
…actor

* 'main' of github.com:juspay/hyperswitch: (39 commits)
  Fix(Cypress): Fixing 3DS payment failure in headless mode (#4807)
  feat(users): Add redis in Begin and Verify TOTP and create a new API that updates TOTP (#4765)
  refactor(connector): [Klarna] Refactor Authorize call and configs for prod (#4750)
  fix: implement StrongEq for Vec<u8> (#4795)
  refactor(core): move router data response and request models to hyperswitch domain models crate (#4789)
  chore(version): 2024.05.29.0
  refactor: retrieve extended card info config during business profile get call (#4784)
  refactor(payment_methods): add support for passing ttl to locker entries (#4690)
  feat(connector): [CRYPTOPAY] Pass network details in payment request (#4779)
  fix: include client columns in payment attempts response struct (#4761)
  fix(docker-compose): fix docker compose syntax (#4782)
  feat(connector): [Iatapay] add upi qr support (#4728)
  docs(analytics): Add documentation for setting up data services and enabling data features in control center (#4741)
  chore(version): 2024.05.28.0
  feat(connector): [AUTHORIZEDOTNET] Implement non-zero mandates (#4758)
  feat(core): [Paypal] Add session_token flow for Paypal sdk (#4697)
  chore(version): 2024.05.27.0
  chore: add missing migrations for recently added currencies (#4760)
  Refactor(core): Inclusion of constraint graph for merchant Payment Method list (#4626)
  chore(version): 2024.05.24.1
  ...
@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
A-core Area: Core flows C-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add Session token flow for Paypal Sdk
6 participants