Braintree VaultManager using react-native-braintree-dropin-ui

407 Views Asked by At

I want to let user to delete his saved payment cards I am using this package

"react-native-braintree-payments-drop-in": "^1.2.0"`

Code:

BraintreeDropIn.show({
  clientToken: this.state.clientToken,
  // I also add this but it is not showing me edit option in dropin
  vaultManager: true 
}).then(result => { ...

Is there something I am missing?

1

There are 1 best solutions below

0
On

You have to create a "braintree customer" then store braintree.customer.id to your user object.

Then if you have a braintree customer id, you can generate a custom client token like me. Call this on your backend to generate one then use that in your Drop-in show({clientToken}) option field

if(!req.user.brainTreeCustomerId){
    gateway.customer.create({
        firstName: req.user.name.first,
        lastName: req.user.name.last,
        email: req.user.email
    }, function (err, result) {
        if(err) return error(res, 500, "Something went wrong while creating customer payment profile");

        if(result.success){
            req.user.brainTreeCustomerId = result.customer.id;
            req.user.save();
        }
    });
}

return gateway.clientToken.generate({
    customerId: req.user.brainTreeCustomerId
})
    .then(response => {
        console.log(response);
        return result(res, 200, response.clientToken);
    }).catch(error(res));