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(router): [V2] Introduce V2Auth and use it for payment_methods_list_enabled #7038

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AnuthaDev
Copy link
Contributor

@AnuthaDev AnuthaDev commented Jan 15, 2025

Type of Change

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

Description

Added an enum V2Auth (name subject to change) to encapsulate different authentication scenarios. Currently only works for Client Authentication using publishable_key and ephemeral_key in Authorization header

Additional Changes

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

Motivation and Context

Closes #7037

How did you test it?

1a. Payment method intent create request:

curl --location 'http://localhost:8080/v2/payment-methods/create-intent' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_5l4dA6ccfVZtudTnPD14' \
--header 'api-key: dev_7ZyumZK1jpifm1OiQQrxGHUkS3uW29bJYYpboYSB03EnMlx6c6pEAtSSkUImpwmD' \
--data '{
  "customer_id": "12345_cus_019468e131037383abb89cd72079135c"
}'

1b. Payment method intent create response:

{
    "id": "12345_pm_019468e155917241a1473a8c3c03d709",
    "merchant_id": "cloth_seller_6Q0HMgBXekiC3lEREr18",
    "customer_id": "12345_cus_019468e131037383abb89cd72079135c",
    "payment_method_type": null,
    "payment_method_subtype": null,
    "recurring_enabled": false,
    "created": "2025-01-15T07:33:05.560Z",
    "last_used_at": "2025-01-15T07:33:05.560Z",
    "ephemeral_key": "epk_019468e155917241a1473a93d1a39e3b",
    "payment_method_data": null
}

2a. List payment methods enabled request:

curl --location 'http://localhost:8080/v2/payment-methods/12345_pm_019468e155917241a1473a8c3c03d709/list-enabled-payment-methods' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_5l4dA6ccfVZtudTnPD14' \
--header 'Authorization: publishable-key=pk_dev_2aa97f9fecf54766ac82d062dcd4e0cd, ephemeral-key=epk_019468e155917241a1473a93d1a39e3b'

2b. List payment methods enabled response:

{
    "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": []
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "google_pay",
            "required_fields": []
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "apple_pay",
            "required_fields": []
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "we_chat_pay",
            "required_fields": []
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "ali_pay",
            "required_fields": []
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "paypal",
            "required_fields": []
        },
        {
            "payment_method_type": "wallet",
            "payment_method_subtype": "mb_way",
            "required_fields": []
        },
        {
            "payment_method_type": "pay_later",
            "payment_method_subtype": "klarna",
            "required_fields": []
        },
        {
            "payment_method_type": "pay_later",
            "payment_method_subtype": "affirm",
            "required_fields": []
        },
        {
            "payment_method_type": "pay_later",
            "payment_method_subtype": "afterpay_clearpay",
            "required_fields": []
        },
        {
            "payment_method_type": "pay_later",
            "payment_method_subtype": "walley",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "giropay",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "ideal",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "eps",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "bancontact_card",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "przelewy24",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "sofort",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "blik",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "trustly",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "online_banking_finland",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_redirect",
            "payment_method_subtype": "online_banking_poland",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_transfer",
            "payment_method_subtype": "ach",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_transfer",
            "payment_method_subtype": "sepa",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_transfer",
            "payment_method_subtype": "bacs",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_debit",
            "payment_method_subtype": "ach",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_debit",
            "payment_method_subtype": "sepa",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_debit",
            "payment_method_subtype": "bacs",
            "required_fields": []
        },
        {
            "payment_method_type": "bank_debit",
            "payment_method_subtype": "becs",
            "required_fields": []
        }
    ]
}

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

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jan 15, 2025
@@ -1,5 +1,7 @@
#[cfg(feature = "v1")]
pub use api_models::payments::PaymentsRequest;
#[cfg(feature = "v1")]
pub use api_models::payments::{PaymentListResponse, PaymentListResponseV2, PaymentsResponse};
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to re export this, ideally we should not have any re exports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to move these out of the existing re-exports to add the v1 feature gate. Removing re-exports can be taken up as a separate task

crates/router/src/types/storage/ephemeral_key.rs Outdated Show resolved Hide resolved
crates/diesel_models/src/ephemeral_key.rs Outdated Show resolved Hide resolved
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.

feat(router): Unify Auth in single layer (V2)
2 participants