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

Merged
merged 73 commits into from
Jan 13, 2025

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.

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": "[email protected]",
    "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-enabled-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": []
        }
    ],
}

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
@Sarthak1799
Copy link
Contributor

There are conflicts @Narayanbhat166
Also I think the entire development.toml file has been formatted.

Comment on lines +41 to +45
#[cfg(feature = "v2")]
PaymentMethod {
payment_method_id: id_type::GlobalPaymentMethodId,
payment_method_type: Option<common_enums::PaymentMethod>,
payment_method_subtype: Option<common_enums::PaymentMethodType>,
Copy link
Member

Choose a reason for hiding this comment

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

This would also need corresponding ClickHouse migrations. Can we avoid renaming fields in analytics related stuff for the time being?

CC: @ShivanshMathurJuspay

crates/api_models/src/payment_methods.rs Outdated Show resolved Hide resolved
crates/common_utils/src/events.rs Show resolved Hide resolved
crates/openapi/src/routes/payment_method.rs Outdated Show resolved Hide resolved
crates/openapi/src/routes/payment_method.rs Outdated Show resolved Hide resolved
crates/openapi/src/routes/payment_method.rs Outdated Show resolved Hide resolved
crates/router/Cargo.toml Outdated Show resolved Hide resolved
Comment on lines +542 to 547
#[cfg_attr(feature = "v2", derive(Default))] // Configs are read from the config file in config/payout_required_fields.toml
pub struct PayoutRequiredFields(pub HashMap<enums::PaymentMethod, PaymentMethodType>);

#[derive(Debug, Deserialize, Clone)]
#[cfg_attr(feature = "v2", derive(Default))] // Configs are read from the config file in config/payment_required_fields.toml
pub struct RequiredFields(pub HashMap<enums::PaymentMethod, PaymentMethodType>);
Copy link
Member

Choose a reason for hiding this comment

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

Why is Default being derived here? Can we remove it if it's not needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Default is derived because it is mandated in Settings.

crates/router/src/configs/settings.rs Show resolved Hide resolved
crates/router/src/configs/settings.rs Outdated Show resolved Hide resolved
hrithikesh026
hrithikesh026 previously approved these changes Jan 9, 2025
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

Comment on lines +1131 to +1158
#[cfg(feature = "v2")]
trait PerformFilteringOnEnabledPaymentMethods {
fn perform_filtering(self) -> FilteredPaymentMethodsEnabled;
}

#[cfg(feature = "v2")]
impl PerformFilteringOnEnabledPaymentMethods
for hyperswitch_domain_models::merchant_connector_account::FlattenedPaymentMethodsEnabled
{
fn perform_filtering(self) -> FilteredPaymentMethodsEnabled {
FilteredPaymentMethodsEnabled(self.payment_methods_enabled)
}
}

#[cfg(feature = "v2")]
/// Container for the inputs required for the required fields
struct RequiredFieldsInput {
required_fields_config: settings::RequiredFields,
}

#[cfg(feature = "v2")]
impl RequiredFieldsInput {
fn new(required_fields_config: settings::RequiredFields) -> Self {
Self {
required_fields_config,
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These seem to be internal types, can we then move these to crates/router/src/types/payment_methods.rs instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Sarthak1799 these types are internal to this module and the types are based around the impls defined on them. These types are not reusable by any other modules. So it is better to be defined in this module

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 Jan 13, 2025
Merged via the queue into main with commit 6a1f5a8 Jan 13, 2025
17 of 19 checks passed
@likhinbopanna likhinbopanna deleted the payment_methods_list_for_payment_methods branch January 13, 2025 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-v2 M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants