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 49 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.

Uploading Screenshot 2024-12-25 at 5.12.16 PM.png…

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-payment-methods' \
--header 'api-key: dev_6BoCe4RXBXF6bxdXSvDilRNJzAyC44zmEzxrQrBAswLtV2wc91CNOGUTZ2ys5Ff0' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_Jl8KY80C28z1mRdXcDBT'

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
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Dec 25, 2024
@@ -776,6 +765,10 @@ pub struct PaymentMethodResponse {
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema, Clone)]
pub struct PaymentMethodResponse {
/// The unique identifier of the Payment method
#[schema(value_type = String, example = "card_rGK4Vi5iSW70MY7J2mIg")]
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could you update the example here?

Comment on lines +1038 to +1045
/// The list of payment methods that are enabled for the business profile
#[schema(value_type = Vec<ResponsePaymentMethodTypes>)]
pub payment_methods_enabled: Vec<ResponsePaymentMethodTypes>,

/// The list of payment methods that are saved by the given customer
/// This field is only returned if the customer_id is provided in the request
#[schema(value_type = Option<Vec<CustomerPaymentMethod>>)]
pub customer_payment_methods: Option<Vec<CustomerPaymentMethod>>,
Copy link
Member

@SanchithHegde SanchithHegde Dec 25, 2024

Choose a reason for hiding this comment

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

I don't think the value_type necessarily needs to be specified for both the fields.

ttl_for_storage_in_secs = 220752000
host = "http://127.0.0.1:3000"
host_rs = "http://127.0.0.1:3000"
mock_locker = false
Copy link
Member

Choose a reason for hiding this comment

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

Specifying mock_locker = false would force everyone running the application locally to set up the card vault. Is that the intended behavior?

@@ -1758,9 +1758,11 @@ pub struct PaymentMethodDeleteResponse {
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct PaymentMethodDeleteResponse {
/// The unique identifier of the Payment method
#[schema(example = "card_rGK4Vi5iSW70MY7J2mIg")]
pub payment_method_id: String,
#[schema(value_type = String, example = "card_rGK4Vi5iSW70MY7J2mIg")]
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Can you update the example here?

Comment on lines 6561 to +6562
#[schema(value_type = Vec<ResponsePaymentMethodTypes>)]
pub payment_methods_enabled: Vec<payment_methods::ResponsePaymentMethodTypes>,
pub payment_methods_enabled: Vec<ResponsePaymentMethodTypesForPayments>,
Copy link
Member

Choose a reason for hiding this comment

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

Should we update the value_type here?

Comment on lines +6574 to +6575
#[schema(example = "klarna", value_type = PaymentMethodType)]
pub payment_method_type: common_enums::PaymentMethod,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[schema(example = "klarna", value_type = PaymentMethodType)]
pub payment_method_type: common_enums::PaymentMethod,
#[schema(example = "klarna", value_type = PaymentMethod)]
pub payment_method_type: common_enums::PaymentMethod,

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?

)
.service(
web::resource("/update-saved-payment-method")
.route(web::patch().to(payment_methods::payment_method_update_api)),
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to be put(), to keep things consistent with the other v2 APIs?

Copy link
Member Author

Choose a reason for hiding this comment

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

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