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_v2): add payment methods list endpoint #6938

Open
wants to merge 60 commits into
base: main
Choose a base branch
from

Conversation

Narayanbhat166
Copy link
Member

@Narayanbhat166 Narayanbhat166 commented Dec 25, 2024

Type of Change

  • New feature

Description

This PR adds payment methods list endpoint for payment methods endpoint for payment methods. This will be used to display the list of payment methods that are enabled by the merchant, and also the saved payment methods by the customer.

Screenshot 2025-01-03 at 11 59 48 PM

Motivation and Context

How did you test it?

  • Create a customer
curl --location 'http://localhost:8080/v2/customers' \
--header 'x-profile-id: pro_Jl8KY80C28z1mRdXcDBT' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_6BoCe4RXBXF6bxdXSvDilRNJzAyC44zmEzxrQrBAswLtV2wc91CNOGUTZ2ys5Ff0' \
--data-raw '{   
    "merchant_reference_id": "customer_1735122196",
    "name": "John Doe",
    "email": "guest@example.com",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "First customer",
    "default_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"
    },
    "default_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"
    },
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
  • Create a payment method intent
curl --location 'http://localhost:8080/v2/payment-methods/create-intent' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_Jl8KY80C28z1mRdXcDBT' \
--header 'api-key: dev_6BoCe4RXBXF6bxdXSvDilRNJzAyC44zmEzxrQrBAswLtV2wc91CNOGUTZ2ys5Ff0' \
--data '{
  "customer_id": "12345_cus_0193f9043aae775099131fb81108488f"
}'
  • List the payment methods
curl --location 'http://localhost:8080/v2/payment-methods/12345_pm_0193f99973757b30a97807211a19d8fc/list-payment-methods' \
--header 'api-key: dev_6BoCe4RXBXF6bxdXSvDilRNJzAyC44zmEzxrQrBAswLtV2wc91CNOGUTZ2ys5Ff0' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_Jl8KY80C28z1mRdXcDBT'
  • Response ( given that stripe connector is created )
{
    "payment_methods_enabled": [
        {
            "payment_method_type": "card_redirect",
            "payment_method_subtype": "card_redirect",
            "required_fields": []
        },
        {
            "payment_method_type": "card",
            "payment_method_subtype": "credit",
            "required_fields": [
                {
                    "required_field": "payment_method_data.card.card_number",
                    "display_name": "card_number",
                    "field_type": "user_card_number",
                    "value": null
                },
                {
                    "required_field": "payment_method_data.card.card_exp_year",
                    "display_name": "card_exp_year",
                    "field_type": "user_card_expiry_year",
                    "value": null
                },
                {
                    "required_field": "payment_method_data.card.card_cvc",
                    "display_name": "card_cvc",
                    "field_type": "user_card_cvc",
                    "value": null
                },
                {
                    "required_field": "payment_method_data.card.card_exp_month",
                    "display_name": "card_exp_month",
                    "field_type": "user_card_expiry_month",
                    "value": null
                }
            ]
        },
        {
            "payment_method_type": "card",
            "payment_method_subtype": "debit",
            "required_fields": []
        }
    ],
    "customer_payment_methods": null
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code

SanchithHegde and others added 30 commits December 6, 2024 15:13
@Narayanbhat166 Narayanbhat166 self-assigned this Dec 25, 2024
@Narayanbhat166 Narayanbhat166 requested review from a team as code owners December 25, 2024 10:24
Copy link

semanticdiff-com bot commented Dec 25, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/webhooks/incoming_v2.rs  96% smaller
  crates/router/src/routes/app.rs  70% smaller
  crates/router/src/core/admin.rs  50% smaller
  crates/hyperswitch_domain_models/src/merchant_connector_account.rs  47% smaller
  crates/router/src/core/routing/helpers.rs  46% smaller
  crates/router/src/core/payment_methods/transformers.rs  36% smaller
  crates/router/src/core/payment_methods/cards.rs  36% smaller
  api-reference-v2/mint.json  36% smaller
  crates/openapi/src/openapi_v2.rs  26% smaller
  crates/router/src/configs/defaults/payment_connector_required_fields.rs  25% smaller
  api-reference-v2/openapi_spec.json  24% smaller
  crates/common_utils/src/events.rs  23% smaller
  crates/api_models/src/payment_methods.rs  15% smaller
  api-reference/openapi_spec.json  10% smaller
  crates/api_models/src/payments.rs  7% smaller
  crates/openapi/src/routes/payment_method.rs  6% smaller
  crates/router/src/core/payment_methods.rs  2% smaller
  crates/api_models/src/connector_enums.rs  1% smaller
  crates/common_utils/src/id_type/global_id/payment_methods.rs  1% smaller
  Cargo.lock Unsupported file format
  api-reference-v2/api-reference/payment-methods/payment-method--payment-methods-list.mdx Unsupported file format
  config/development.toml Unsupported file format
  config/payment_required_fields.toml Unsupported file format
  crates/api_models/src/admin.rs  0% smaller
  crates/api_models/src/events.rs  0% smaller
  crates/api_models/src/events/payment.rs  0% smaller
  crates/common_enums/src/connector_enums.rs  0% smaller
  crates/diesel_models/src/merchant_connector_account.rs  0% smaller
  crates/openapi/src/openapi.rs  0% smaller
  crates/openapi/src/routes.rs  0% smaller
  crates/router/Cargo.toml Unsupported file format
  crates/router/src/configs/defaults/payout_required_fields.rs  0% smaller
  crates/router/src/configs/settings.rs  0% smaller
  crates/router/src/core/apple_pay_certificates_migration.rs  0% smaller
  crates/router/src/core/disputes.rs  0% smaller
  crates/router/src/core/payments/flows/session_flow.rs  0% smaller
  crates/router/src/core/payments/helpers.rs  0% smaller
  crates/router/src/core/payments/payment_methods.rs  0% smaller
  crates/router/src/core/payouts/transformers.rs  0% smaller
  crates/router/src/core/relay.rs  0% smaller
  crates/router/src/core/relay/utils.rs  0% smaller
  crates/router/src/core/user/dashboard_metadata.rs  0% smaller
  crates/router/src/db/merchant_connector_account.rs  0% smaller
  crates/router/src/routes/disputes.rs  0% smaller
  crates/router/src/routes/payment_methods.rs  0% smaller
  crates/router/src/routes/user.rs  0% smaller

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Dec 25, 2024
crates/api_models/src/payment_methods.rs Outdated Show resolved Hide resolved
crates/api_models/src/payment_methods.rs Outdated Show resolved Hide resolved
config/development.toml Outdated Show resolved Hide resolved
crates/api_models/src/payment_methods.rs Outdated Show resolved Hide resolved
crates/api_models/src/payments.rs Outdated Show resolved Hide resolved
crates/api_models/src/payments.rs Outdated Show resolved Hide resolved
Comment on lines +70 to +73
#[cfg(feature = "v2")]
PaymentMethodListForPaymentMethods {
payment_method_id: id_type::GlobalPaymentMethodId,
},
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this enum variant, is this being used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is being used when we receive only global_payment_method_id in the request

crates/router/src/routes/app.rs Outdated Show resolved Hide resolved
@Narayanbhat166 Narayanbhat166 requested review from a team as code owners January 3, 2025 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants