-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
refactor(payment_methods): handle card duplication #3146
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Chethan-rao
added
A-core
Area: Core flows
S-waiting-on-review
Status: This PR has been implemented and needs to be reviewed
A-payment-methods
Area: Payment Methods
C-refactor
Category: Refactor
A-payments
Area: payments
labels
Dec 15, 2023
2 tasks
NishantJoshi00
previously approved these changes
Feb 5, 2024
NishantJoshi00
previously approved these changes
Feb 7, 2024
vspecky
previously approved these changes
Feb 8, 2024
Chethan-rao
dismissed stale reviews from vspecky and NishantJoshi00
via
February 8, 2024 09:59
c431000
vspecky
approved these changes
Feb 8, 2024
NishantJoshi00
approved these changes
Feb 8, 2024
SanchithHegde
removed
the
S-waiting-on-review
Status: This PR has been implemented and needs to be reviewed
label
Feb 11, 2024
This was referenced Feb 16, 2024
refactor(payment_methods): update payment method db operations to include multi-key validation
#3679
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-core
Area: Core flows
A-payment-methods
Area: Payment Methods
A-payments
Area: payments
C-refactor
Category: Refactor
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of Change
Description
Currently card duplication and card metadata (card_holder_name, expiry year, expiry month, etc) changes are not being handled in Hyperswitch.
Rust locker has the following changes made -
a new field
duplication_check
has been added in stored card response. This field can have three values (duplicated, meta_data_changed and null).duplicated
: indicates that the entire card details in the card request is already present in the locker.meta_data_changed
: indicates that there is already a saved card with same card number but with different card details (like expiry or card holder name).null
: indicates that card is not present in the locker.This PR handles above response from locker in two different flows.
/payments
api call withsetup_future_usage = on_session
/payment_methods
api call to add card directlyBelow are the ways in which Hyperswitch will behave based on above 3 values of
duplication_check
duplicated
: Since card already exist on locker, just ensure corresponding payment method entry is present inpayment_methods
table. If not we create it with thepayment_method_id
(locker_id) returned by locker.meta_data_changed
: Send a delete request to locker. Send a add card request to locker with the updated card details but samepayment_method_id
(This ensures that we don't re-create payment method entry on Hyperswitch side). Next update thepayment_method_data
field inpayment_methods
table to contain the new card details.null
: New payment method entry is created as this is a new card.Additional Changes
Motivation and Context
How did you test it?
Create a merchant account, api key and stripe mca.
This PR has to be tested in below 2 flows as these are the two ways in which we can send add card request to locker.
i) Directly adding card using
/payment_methods
apiii) Using
/payments
api withsetup_future_usage = on_session
i) Directly adding card using
/payment_methods
api -Customer
customer_id
from above request (Try some new test card which shouldn't exist in locker)Below is the locker response I logged for testing purpose -
duplication_check
says None.Also make sure payment method entry is created in hyperswitch side in using
list_customer_payment_method
apiLocker response -
duplication_check
saysDuplicated
which means whole card is found in locker without any change in card metadata (expiry year, expiry month, card holder name, etc)Make sure no new entry is created in
payment_methods
table as this was a duplicate card. Check this by again doinglist_customer_payment_method
and this should still have 1 card.Locker response -
duplication_check
saysMetaDataChanged
which means card was found but some of its metadata was changed. At this point the card details (metadata) must be updated as per request sent.Do
list_customer_payment_method
and this response should have the metadata changes you have done.ii) Using
/payments
api withsetup_future_usage = on_session
Customer
/payments
api withsetup_future_usage = on_session
with card thats not present in locker. Make sure to use abovecustomer_id
This time card has to be saved in locker and
payment_methods
entry has to be created in hyperswitch. Verify by hittinglist_customer_payment_method
.payment_methods
table. Verify by hittinglist_customer_payment_method
and this should still have 1 card.list_customer_payment_method
and this response should have the metadata changes you have done.Checklist
cargo +nightly fmt --all
cargo clippy