Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Braintree is it possible to verify duplicate payment method for just one customer instead of entire vault?

Tags:

php

braintree

For the Braintree_PaymentMethod::create() function, one of the options is:

'failOnDuplicatePaymentMethod', bool

If this option is passed and the payment method has already been added to the Vault, the request will fail. This option will not work with PayPal payment methods.

This appears to be a global compare. i.e. if the credit card information exists in the vault regardless of customer id this will fail.

Is there a way to check for duplicates on a particular customer?

like image 560
Revent Avatar asked Dec 23 '15 01:12

Revent


People also ask

How do I vault a payment method Braintree?

Once you have a single-use payment method ID from your client, you can vault the underlying payment method. To do so, use the vaultPaymentMethod mutation. This mutation will automatically run a verification against payment methods that support them before storing them in the vault.

What is vaulted payment method?

Vault as a payment method provides store customers with ability to use the previously saved credit card information for checkout. This information is stored safely on the side of trusted payments gateways (Braintree, PayPal). Not storing the sensitive credit card information is one of the PCI compliance requirements.

Does Braintree save credit card details?

Our Braintree Vault securely stores customer information – including payment method information – so you can safely keep customers on file.

What is a payment method nonce?

A payment method nonce is a secure, one-time-use reference to payment information. It's the key element that allows your server to communicate sensitive payment information to Braintree without ever touching the raw data.


2 Answers

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

You and Evan are correct: this is the only pre-built way of failing on duplicate creates regardless of customer create. You could achieve what you are trying to do with your own automation, however.

To do this, simply collect the credit card unique ids that already exist from the customer object. Then when you create the new payment method, compare it with the existing cards:

function extractUniqueId($creditCard){ 
    return $creditCard->uniqueNumberIdentifier;
}

$customer = Braintree_Customer::find('your_customer');
$unique_ids = array_map(extractUniqueId,$customer->creditCards);

$result = Braintree_PaymentMethod::create(array(
    'customerId' => 'your_customer',
    'paymentMethodNonce' => 'fake-valid-discover-nonce',
));

if ($result->success) {
    if(in_array(extractUniqueId($result->paymentMethod), $unique_ids)) {
        echo "Do your duplicate logic";
    } else {
        echo "Continue with your unique logic";
    }
} 

Depending on what you want to do, you could delete the new payment method or whatever else you need.

like image 174
Raymond Berg Avatar answered Sep 25 '22 13:09

Raymond Berg


Checked with Braintree support--still not available out of the box:

If you use failOnDuplicatePaymentMethod any request to add duplicate payment method information into the Vault will fail.

We currently don’t have the functionality to prevent a customer from adding a duplicate card to their profile, while allowing duplicate cards to still be added under multiple profiles. If this is something you are interested in you will have to build out your own logic.

like image 33
Evan Avatar answered Sep 23 '22 13:09

Evan