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(core): Refactor customer payment method list for v2 #4856

Merged
merged 44 commits into from
Aug 6, 2024

Conversation

Sarthak1799
Copy link
Contributor

@Sarthak1799 Sarthak1799 commented Jun 3, 2024

Type of Change

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

Description

Refactored customer's pml for v2

The customers Payment method list will be moved under two distinct endpoints:

For Client (with payment tokens) - /payments/:id:/saved_payment_methods
For Server (without payment token) - /customers/:cust_id:/saved_payment_methods

Payment tokens for the listed payment methods would be generated only in case of client calls in a payments context.

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?

  • Save a card
  • Create another payment
curl --location --request POST 'http://localhost:8080/v2/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_cHN6hMdCFUUrNWjYSxnwhiuMsg83rXTX9jBmtHmCL6sq9a43PswY304MSt3a9blR' \
--data-raw '{
    "amount": 200,
    "currency": "USD",
    "confirm": false,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "Some_cust2",
    "email": "[email protected]",
    "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": "US",
            "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": "US",
            "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_GNxoHRthb37nMZt6KLhv",
    "merchant_id": "sarthak1",
    "status": "requires_payment_method",
    "amount": 200,
    "net_amount": 200,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": null,
    "client_secret": "pay_GNxoHRthb37nMZt6KLhv_secret_G97qG0GJ85JeGks8NmnA",
    "created": "2024-07-02T09:56:52.153Z",
    "currency": "USD",
    "customer_id": "Some_cust2",
    "customer": {
        "id": "Some_cust2",
        "name": "John Doe",
        "email": "[email protected]",
        "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": "US",
            "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": "US",
            "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": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "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": {
        "customer_id": "Some_cust2",
        "created_at": 1719914212,
        "expires": 1719917812,
        "secret": "epk_7299286e8535424b957d32f6f5e44e99"
    },
    "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_1HgRzJgJf21X3s7FPrhP",
    "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-07-02T10:11:52.153Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-07-02T09:56:52.226Z",
    "charges": null,
    "frm_metadata": null
}
  • List saved payment method for v2
curl --location --request GET 'http://localhost:8080/v2/payments/pay_GNxoHRthb37nMZt6KLhv/saved_payment_methods?client_secret=pay_GNxoHRthb37nMZt6KLhv_secret_G97qG0GJ85JeGks8NmnA' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_16e38a16176e45298a70da6c56c5028d'

Response -

{
    "customer_payment_methods": [
        {
            "payment_token": "token_SBCX3r5nb9QaHNGtSbgK",
            "payment_method_id": "pm_R8n4IKXyEpAGcKaEQl0g",
            "customer_id": "Some_cust2",
            "payment_method": "card",
            "payment_method_type": null,
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": false,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "payment_method_data": {
                "Card": {
                    "scheme": null,
                    "issuer_country": null,
                    "last4_digits": "4242",
                    "expiry_month": "10",
                    "expiry_year": "2025",
                    "card_token": null,
                    "card_holder_name": "joseph Doe",
                    "card_fingerprint": null,
                    "nick_name": null,
                    "card_network": null,
                    "card_isin": "424242",
                    "card_issuer": null,
                    "card_type": null,
                    "saved_to_locker": true
                }
            },
            "bank": null,
            "metadata": null,
            "created": "2024-06-26T08:26:47.674Z",
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-06-26T10:39:30.552Z",
            "default_payment_method_set": false,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "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
            }
        },
        {
            "payment_token": "token_nvHY8mkVcPYA94KQefdx",
            "payment_method_id": "pm_xFF1OOhEMqVQhzEv3b06",
            "customer_id": "Some_cust2",
            "payment_method": "card",
            "payment_method_type": null,
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": false,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "payment_method_data": {
                "Card": {
                    "scheme": null,
                    "issuer_country": null,
                    "last4_digits": "4242",
                    "expiry_month": "10",
                    "expiry_year": "2025",
                    "card_token": null,
                    "card_holder_name": "joseph Doe",
                    "card_fingerprint": null,
                    "nick_name": null,
                    "card_network": null,
                    "card_isin": "424242",
                    "card_issuer": null,
                    "card_type": null,
                    "saved_to_locker": true
                }
            },
            "bank": null,
            "metadata": null,
            "created": "2024-06-13T11:55:47.828Z",
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-06-13T11:55:47.828Z",
            "default_payment_method_set": true,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "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
            }
        }
    ],
    "is_guest_customer": false
}
  • Use Merchant API for saved payment methods -
curl --location --request GET 'http://localhost:8080/v2/customers/Some_cust2/saved_payment_methods' \
--header 'Accept: application/json' \
--header 'api-key: dev_cHN6hMdCFUUrNWjYSxnwhiuMsg83rXTX9jBmtHmCL6sq9a43PswY304MSt3a9blR'

Response -

{
    "customer_payment_methods": [
        {
            "payment_token": null,
            "payment_method_id": "pm_R8n4IKXyEpAGcKaEQl0g",
            "customer_id": "Some_cust2",
            "payment_method": "card",
            "payment_method_type": null,
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": false,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "payment_method_data": {
                "Card": {
                    "scheme": null,
                    "issuer_country": null,
                    "last4_digits": "4242",
                    "expiry_month": "10",
                    "expiry_year": "2025",
                    "card_token": null,
                    "card_holder_name": "joseph Doe",
                    "card_fingerprint": null,
                    "nick_name": null,
                    "card_network": null,
                    "card_isin": "424242",
                    "card_issuer": null,
                    "card_type": null,
                    "saved_to_locker": true
                }
            },
            "bank": null,
            "metadata": null,
            "created": "2024-06-26T08:26:47.674Z",
            "surcharge_details": null,
            "requires_cvv": false,
            "last_used_at": "2024-06-26T10:39:30.552Z",
            "default_payment_method_set": false,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "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
            }
        },
        {
            "payment_token": null,
            "payment_method_id": "pm_xFF1OOhEMqVQhzEv3b06",
            "customer_id": "Some_cust2",
            "payment_method": "card",
            "payment_method_type": null,
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": false,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "payment_method_data": {
                "Card": {
                    "scheme": null,
                    "issuer_country": null,
                    "last4_digits": "4242",
                    "expiry_month": "10",
                    "expiry_year": "2025",
                    "card_token": null,
                    "card_holder_name": "joseph Doe",
                    "card_fingerprint": null,
                    "nick_name": null,
                    "card_network": null,
                    "card_isin": "424242",
                    "card_issuer": null,
                    "card_type": null,
                    "saved_to_locker": true
                }
            },
            "bank": null,
            "metadata": null,
            "created": "2024-06-13T11:55:47.828Z",
            "surcharge_details": null,
            "requires_cvv": false,
            "last_used_at": "2024-06-13T11:55:47.828Z",
            "default_payment_method_set": true,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "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
            }
        }
    ],
    "is_guest_customer": 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 added A-core Area: Core flows A-payment-methods Area: Payment Methods C-refactor Category: Refactor labels Jun 3, 2024
@Sarthak1799 Sarthak1799 self-assigned this Jun 3, 2024
@Sarthak1799 Sarthak1799 requested review from a team as code owners June 3, 2024 13:32
crates/router/src/compatibility/stripe/customers/types.rs Outdated Show resolved Hide resolved
crates/router/src/types/storage/payment_method.rs Outdated Show resolved Hide resolved
crates/router/src/core/payment_methods/cards.rs Outdated Show resolved Hide resolved
crates/router/src/core/payment_methods/cards.rs Outdated Show resolved Hide resolved
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jun 20, 2024
hrithikesh026
hrithikesh026 previously approved these changes Jun 26, 2024
Copy link
Contributor

@hrithikesh026 hrithikesh026 left a comment

Choose a reason for hiding this comment

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

LGTM

@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Jul 1, 2024
@Sarthak1799 Sarthak1799 requested a review from a team as a code owner July 23, 2024 12:17
@Sarthak1799 Sarthak1799 requested a review from a team as a code owner July 27, 2024 15:50
jarnura
jarnura previously approved these changes Jul 28, 2024
@Sarthak1799 Sarthak1799 requested review from vspecky and removed request for vspecky August 5, 2024 12:42
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Aug 6, 2024
Merged via the queue into main with commit 8302272 Aug 6, 2024
14 checks passed
@Gnanasundari24 Gnanasundari24 deleted the refactor-customer-pm-list branch August 6, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows A-payment-methods Area: Payment Methods C-refactor Category: Refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Customers Payment Method List to support Client as well as S2S calls
6 participants