Full disclosure: I work at Braintree. If you have further questions, feel free to contact support .
You and Evan are true: this is the only pre-created way to fail duplication, created independently of the creation of the client. However, you can achieve what you are trying to do with your own automation.
To do this, simply collect the unique credit card identifiers that already exist from the customerโs object . Then, when you create a new payment method , compare it with 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 can remove the new payment method or whatever you need.
source share