Search code examples
phpbraintree

Braintree PHP How To Get Nonce Without DropIn for Vaulting


For our use case, we have an existing form that captures the customer's credit card information. To smooth out the transition from one payment processor to the next since we're not sure when that will happen, we would like to vault the payment method in Braintree without charging the card but keep our existing form.

I see how to vault the nonce that we receive from the Drop-In UI, and I was able to find an answer on SO that described how to pass the payment information directly to Braintree and charging it, however, I have had no luck in finding a way to just pass the card information to braintree for the purposes of vaulting the payment method (with or without the intermediate step of receiving a nonce).

EDIT: I've discovered the $gateway->customer()->create() and $gateway->creditCard()->create() functions, however, of the various 'unique identifiers' returned from the credit card create call, none of them appear to be vaultable.


Solution

  • It was buried a bit in the documentation, but I was able to do this with an intermediate step:

    1. create customer $gateway->customer()->create(...)
    2. create credit card $gateway->creditCard()->create(...)
    3. take the token from the previous call and pass it to $gateway->paymentMethodNonce()->create(..)
    4. then take the customer id and the newly created nonce and passed them to $gateway->paymentMethod()->create(...)
    5. the necessary vault token was stored in the results object $result->paymentMethod->graphQLId