0
votes

I have an issue with Braintree,

Suppose a customer logged in on my site, then I create client token for that customer (By passing customer id in Braintree\ClientToken::generate() function ), so that if he have any existing payment method then it will be loaded automatically at client side.

But if customer selects new payment method which already in vault:

for card same card number, for Paypal same email address,

then it automatically added in vault for that customer, either it exists or not,

So in my case, i don't want to store same payment method(either Paypal or Card) twice or more for same user,

How can i restrict so that same payment method should not store multiple times in vault?

1

1 Answers

0
votes

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.

There is actually a parameter you can set in the Client Token generate options called failOnDuplicatePaymentMethod. If this option is passed as True and the payment method has already been added to the Vault, the request will fail. This can only be passed if a customer_id is passed as well. If the check fails, this option will stop the Drop-in from returning a payment_method_nonce. Unfortunately, this will not work for Paypal Payment methods, and there are a few workarounds for that.

Not Storing in the Vault

You would first need to collect the customer's PayPal email account in the client-side callback. When the payment type is a PayPalAccount , you can then run a Braintree::Customer.search() request on the user's email. If this brings up any customers that have the PayPal email account you specified (which was retrieved from the client-side integration), you wouldn't need to vault the account, you can simply proceed with creating another transaction on the existing token.

Deleting Duplicate Accounts

The second workaround is similar to the first.You collect the customer's PayPal payment method as usual (collect the nonce and pass it to your server) and then use it in a Braintree::PaymentMethod.create or Braintree::Customer.create API request as usual. In the result object returned, you can then check the details of this PayPal transaction, paypal_details and inspect this to find the email address. If this email matches one for a PayPal account for that customer, you can choose to delete the new payment method immediately.

Don't hesitate to reach out to Braintree Support if you need more help.