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

refactor(open_banking): Refactored to consume and use headers from SDK #5884

Merged
merged 11 commits into from
Sep 20, 2024

Conversation

Sarthak1799
Copy link
Contributor

@Sarthak1799 Sarthak1799 commented Sep 13, 2024

Type of Change

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

Description

  • Refactored RouterData to use HeaderPayload for Android/IOS Platform specific flows.
  • Refactored Open banking flows to consume and process the header information to take decisions based on client platform.

Additional Changes

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

Motivation and Context

How did you test it?

  1. Payments create -
curl --location --request POST 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_uFcNSTN14N27NiyGdgkK8eN2fBmPWHHhbPZh6RMkBUxoByMfAdPlBItplwGctI6P' \
--data-raw '{
    "amount": 6500,
    "currency": "EUR",
    "confirm": false,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "email": "guest@example.com",
    "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",
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "GB",
            "first_name": "john",
            "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": "GB",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594430",
            "country_code": "+91"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'

Response

{
    "payment_id": "pay_qrNjDvodTni9SiSVeukh",
    "merchant_id": "merchant_1726386502",
    "status": "requires_payment_method",
    "amount": 6500,
    "net_amount": 6500,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": null,
    "client_secret": "pay_qrNjDvodTni9SiSVeukh_secret_Y14Mk7PkltuhrpuVCqAI",
    "created": "2024-09-15T07:50:42.333Z",
    "currency": "EUR",
    "customer_id": null,
    "customer": {
        "id": null,
        "name": "John Doe",
        "email": "guest@example.com",
        "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": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": null,
    "payment_method_data": null,
    "payment_token": null,
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "GB",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594430",
            "country_code": "+91"
        },
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "GB",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "john",
            "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": "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": null,
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": null,
    "manual_retry_allowed": null,
    "connector_transaction_id": null,
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": null,
    "payment_link": null,
    "profile_id": "pro_72r0N5WGBqazqsPQluK8",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": null,
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-09-15T08:05:42.333Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-09-15T07:50:42.348Z",
    "charges": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null
}
  1. PML -
curl --location --request GET 'http://localhost:8080/account/payment_methods?client_secret=pay_qrNjDvodTni9SiSVeukh_secret_Y14Mk7PkltuhrpuVCqAI' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_18865dbf242d48158d05eb8b49a55251'

Response -

{
    "redirect_url": "https://google.com/success",
    "currency": "EUR",
    "payment_methods": [
        {
            "payment_method": "open_banking",
            "payment_method_types": [
                {
                    "payment_method_type": "open_banking_pis",
                    "payment_experience": [
                        {
                            "payment_experience_type": "redirect_to_url",
                            "eligible_connectors": [
                                "plaid"
                            ]
                        }
                    ],
                    "card_networks": null,
                    "bank_names": null,
                    "bank_debits": null,
                    "bank_transfers": null,
                    "required_fields": null,
                    "surcharge_details": null,
                    "pm_auth_connector": null
                }
            ]
        }
    ],
    "mandate_payment": null,
    "merchant_name": "Sarthak1",
    "show_surcharge_breakup_screen": false,
    "payment_type": "normal",
    "request_external_three_ds_authentication": false,
    "collect_shipping_details_from_wallets": false,
    "collect_billing_details_from_wallets": false,
    "is_tax_calculation_enabled": false
}
  1. Payments confirm -
curl --location --request POST 'http://localhost:8080/payments/pay_qrNjDvodTni9SiSVeukh/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-client-platform: android' \
--header 'x-app-id: io.hyperswitch' \
--header 'api-key: pk_dev_18865dbf242d48158d05eb8b49a55251' \
--data-raw '{
    "client_secret": "pay_qrNjDvodTni9SiSVeukh_secret_Y14Mk7PkltuhrpuVCqAI",
    "payment_method": "open_banking",
    "payment_method_type": "open_banking_pis",
    "payment_method_data": {
        "open_banking": {
            "open_banking_pis": {}
        }
    }
}'

Response -

{
    "payment_id": "pay_qrNjDvodTni9SiSVeukh",
    "merchant_id": "merchant_1726386502",
    "status": "requires_customer_action",
    "amount": 6500,
    "net_amount": 6500,
    "amount_capturable": 6500,
    "amount_received": null,
    "connector": "plaid",
    "client_secret": "pay_qrNjDvodTni9SiSVeukh_secret_Y14Mk7PkltuhrpuVCqAI",
    "created": "2024-09-15T07:50:42.333Z",
    "currency": "EUR",
    "customer_id": null,
    "customer": {
        "id": null,
        "name": "John Doe",
        "email": "guest@example.com",
        "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": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "open_banking",
    "payment_method_data": {
        "open_banking": {
            "open_banking_pis": {}
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "GB",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594430",
            "country_code": "+91"
        },
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "GB",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "john",
            "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": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": {
        "type": "third_party_sdk_session_token",
        "session_token": {
            "wallet_name": "open_banking",
            "open_banking_session_token": "link-sandbox-9e376cad-8ab2-40f7-b0a0-4744d06a003b"
        }
    },
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "open_banking_pis",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": null,
    "manual_retry_allowed": null,
    "connector_transaction_id": "payment-id-sandbox-adcf53a4-c1ff-46d9-81c2-8e8bfa0d6db2",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "payment-id-sandbox-adcf53a4-c1ff-46d9-81c2-8e8bfa0d6db2",
    "payment_link": null,
    "profile_id": "pro_72r0N5WGBqazqsPQluK8",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_jp7RozkyIQV4e9zTXjyf",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-09-15T08:05:42.333Z",
    "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-09-15T07:51:02.510Z",
    "charges": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": 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

@Sarthak1799 Sarthak1799 self-assigned this Sep 13, 2024
@Sarthak1799 Sarthak1799 requested review from a team as code owners September 13, 2024 13:40
Copy link

semanticdiff-com bot commented Sep 13, 2024

Review changes with SemanticDiff.

Analyzed 44 of 44 files.

Overall, the semantic diff is 25% smaller than the GitHub diff.

File Information
Filename Status
✔️ crates/router/tests/connectors/aci.rs Analyzed
✔️ crates/router/tests/connectors/utils.rs Analyzed
✔️ crates/router/src/lib.rs Analyzed
✔️ crates/router/src/types.rs Analyzed
✔️ crates/router/src/types/transformers.rs 6.39% smaller
✔️ crates/router/src/types/api/verify_connector.rs Analyzed
✔️ crates/router/src/services/conversion_impls.rs Analyzed
✔️ crates/router/src/core/authentication.rs 95.98% smaller
✔️ crates/router/src/core/fraud_check.rs Analyzed
✔️ crates/router/src/core/payments.rs Analyzed
✔️ crates/router/src/core/payouts.rs Analyzed
✔️ crates/router/src/core/pm_auth.rs Analyzed
✔️ crates/router/src/core/refunds.rs Analyzed
✔️ crates/router/src/core/utils.rs Analyzed
✔️ crates/router/src/core/webhooks/utils.rs Analyzed
✔️ crates/router/src/core/payments/flows.rs Analyzed
✔️ crates/router/src/core/payments/helpers.rs Analyzed
✔️ crates/router/src/core/payments/transformers.rs 17.33% smaller
✔️ crates/router/src/core/payments/flows/approve_flow.rs Analyzed
✔️ crates/router/src/core/payments/flows/authorize_flow.rs Analyzed
✔️ crates/router/src/core/payments/flows/cancel_flow.rs Analyzed
✔️ crates/router/src/core/payments/flows/capture_flow.rs Analyzed
✔️ crates/router/src/core/payments/flows/complete_authorize_flow.rs Analyzed
✔️ crates/router/src/core/payments/flows/incremental_authorization_flow.rs Analyzed
✔️ crates/router/src/core/payments/flows/psync_flow.rs Analyzed
✔️ crates/router/src/core/payments/flows/reject_flow.rs Analyzed
✔️ crates/router/src/core/payments/flows/session_flow.rs Analyzed
✔️ crates/router/src/core/payments/flows/session_update_flow.rs Analyzed
✔️ crates/router/src/core/payments/flows/setup_mandate_flow.rs Analyzed
✔️ crates/router/src/core/mandate/utils.rs Analyzed
✔️ crates/router/src/core/fraud_check/flows/checkout_flow.rs Analyzed
✔️ crates/router/src/core/fraud_check/flows/fulfillment_flow.rs Analyzed
✔️ crates/router/src/core/fraud_check/flows/record_return.rs Analyzed
✔️ crates/router/src/core/fraud_check/flows/sale_flow.rs Analyzed
✔️ crates/router/src/core/fraud_check/flows/transaction_flow.rs Analyzed
✔️ crates/router/src/core/authentication/transformers.rs Analyzed
✔️ crates/router/src/connector/plaid/transformers.rs 54.04% smaller
✔️ crates/pm_auth/src/types.rs Analyzed
✔️ crates/pm_auth/src/connector/plaid/transformers.rs Analyzed
✔️ crates/hyperswitch_domain_models/src/router_data.rs Analyzed
✔️ crates/hyperswitch_domain_models/src/router_request_types.rs Analyzed
✔️ crates/common_enums/src/enums.rs Analyzed
✔️ crates/api_models/src/payments.rs Analyzed
✔️ crates/api_models/src/pm_auth.rs Analyzed

@Sarthak1799 Sarthak1799 linked an issue Sep 16, 2024 that may be closed by this pull request
2 tasks
@Sarthak1799 Sarthak1799 added the A-core Area: Core flows label Sep 16, 2024
crates/api_models/src/pm_auth.rs Outdated Show resolved Hide resolved
crates/pm_auth/src/connector/plaid/transformers.rs Outdated Show resolved Hide resolved
crates/pm_auth/src/connector/plaid/transformers.rs Outdated Show resolved Hide resolved
crates/router/src/core/pm_auth.rs Outdated Show resolved Hide resolved
crates/router/src/connector/plaid/transformers.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ThisIsMani ThisIsMani left a comment

Choose a reason for hiding this comment

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

Dashboard specific changes looks fine.

@likhinbopanna likhinbopanna added this pull request to the merge queue Sep 20, 2024
Merged via the queue into main with commit d9270ac Sep 20, 2024
17 of 18 checks passed
@likhinbopanna likhinbopanna deleted the open-banking-fixes branch September 20, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Open banking SDK fixes
6 participants