I know that when I create a payment method I can use failOnDuplicatePaymentMethod
to block duplicate cards. But when I use the storeInVaultOnSuccess
option with Braintree_Transaction::sale
, what is the best way to not save the card if it is already saved?
Edit:
Let me clarify my situation to make sure. On my checkout page I am currently using this JavaScript:
braintree.setup(
myToken,
'custom',
{
id: 'my-form-id',
hostedFields: {
...
},
onPaymentMethodReceived: function(obj) {
...
},
onError: function(obj) {
...
}
}
);
The customer fills in their CC number, CVV and expiration date and clicks submit and then that onPaymentMethodReceived
callback fires. In that JS callback I make an AJAX call to my back-end and pass the nonce. On the back-end I call Braintree_Transaction::sale
in order to charge the customer.
I always need Braintree_Transaction::sale
to successfully complete so that the sale goes through. And then in addition so this sale, I want the card to be saved if the customer has checked "save my card" and the card isn't already saved.
On this checkout page, the customer does have the option to select a saved card instead of inputting all their card info again, but they may type all the card info in again(for an already saved card) instead of selecting the saved card.
How would you do it given this setup? Does your below setup still apply? If so how exactly would I integrate the below with my above setup? Or do I need to rearrange my UI/UX for this(I think this is a pretty standard checkout flow)?