-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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): Store necessary payment method data in payment_methods table #2073
Conversation
@@ -144,6 +144,17 @@ pub struct PaymentMethodResponse { | |||
pub created: Option<time::PrimitiveDateTime>, | |||
} | |||
|
|||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it required to derive Eq, PartialEq
trait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as the PMT derives these. It wasn't compiling before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of things missing here
- Storing bank details or other payment methods info in DB
- API calls will always be made for payment method type - BankTransfer - while listing the customer's saved PMs
let key_store = db | ||
.get_merchant_key_store_by_merchant_id( | ||
&merchant_account.merchant_id, | ||
&db.get_master_key().to_vec().into(), | ||
) | ||
.await | ||
.ok(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the key store already available in all caller contexts, so we can just pass it in as an argument to this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have done the corresponding changes
migrations/2023-09-01-072744_payment_methods_add_card_details/up.sql
Outdated
Show resolved
Hide resolved
migrations/2023-09-05-101938_payment_method_data_in_payment_methods/up.sql
Outdated
Show resolved
Hide resolved
}; | ||
|
||
let card: Option<api::CardDetailFromLocker> = | ||
if pm.payment_method == enums::PaymentMethod::Card { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write card related things as a separate function and call that here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have done
Type of Change
Description
Currently, The Customer Payment method List API resorts to a locker call to fetch card details. The latency induced from this is reduced by storing encrypted card details in payment_methods table. This PR does that.
Additional Changes
Motivation and Context
How did you test it?
Payments Create -
curl --location --request POST 'http://localhost:8080/payments' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'api-key: dev_Ia7M1EapArhTiWcTqmQMCLJ4O8lXRbSz8vrxd2nTAZMgOIkBttrLRXFY6owwhlL7' \ --data-raw '{ "amount": 6540, "currency": "USD", "confirm": true, "capture_method": "automatic", "capture_on": "2022-09-10T10:11:12Z", "amount_to_capture": 6540, "customer_id": "StripeCustomer3", "email": "guest@example.com", "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", "payment_method": "card", "payment_method_type": "credit", "setup_future_usage":"off_session", "payment_method_data": { "card": { "card_number": "4242424242424242", "card_exp_month": "10", "card_exp_year": "25", "card_holder_name": "joseph Doe", "card_cvc": "124", "card_network": "Visa" } }, "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" } }'
List Payment methods for customers -
curl --location --request GET 'http://localhost:8080/customers/StripeCustomer1/payment_methods' \ --header 'Accept: application/json' \ --header 'api-key: dev_Ia7M1EapArhTiWcTqmQMCLJ4O8lXRbSz8vrxd2nTAZMgOIkBttrLRXFY6owwhlL7'
Checklist
cargo +nightly fmt --all
cargo clippy