Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Braintree's Dropin UI, How to remove payment method

Tags:

braintree

We are using braintree's dropin UI to help save time in having to create custom payment entry pages. What is hard to understand is why you can only add new payment method and not remove. I understand being able to add, but if there was a problem with a given payment method (later on). It is there forever because the customer cannot remove a payment method. I guess the only way to remove a payment method, is for us write a custom UI (thus defeating the purpose of using the dropin UI to begin with). Is there no way for a customer to remove a payment method using the dropin UI?

like image 682
MacWise Avatar asked Jan 13 '15 19:01

MacWise


2 Answers

Braintree's DropIn UI doesn't allow users to remove or update saved payment method. But there's a way to do that. For example, if you have a customer profile page where they can manage their settings, you can simply add a menu that shows all the payment methods associated with the customer.

To do this, you can simply use some Braintree functions which are explained here: https://developers.braintreepayments.com/guides/payment-methods/php

The idea is to get all the payment method associated with the customer using something like:

$customer = Braintree_Customer::find('a_customer_id');
$customer->paymentMethods // array of Braintree_PaymentMethod instances

It will return an object for all the payment methods. Then you can check the response of that object from the same page by clicking the specific payment method type here (credit card, paypal...)

Once you have these values, you can display them in a table for example, and add a simply button or whatever you want to delete that payment method. To do this, you can use the following function passing the TOKEN as an argument

 $result = Braintree_PaymentMethod::delete('the_token');
 /*(token is a value of the object that comes from $customer->paymentMethods*/

Finally, you can check the response controlling the value of $result (true or false)

Hope this helps.

like image 185
Damian Dominella Avatar answered Sep 28 '22 04:09

Damian Dominella


The ability to delete vaulted payment methods using the Braintree drop-in UI has been added around August 7, 2018 and is available in braintree-web-drop-in 1.12.0+. This feature is now listed in their documentation:

Name: vaultManager

Type: boolean

Attributes: optional

Default: false

Description:

Whether or not to allow a customer to delete saved payment methods when used with a client token with a customer id. Note: Deleting a payment method from Drop-in will permanently delete the payment method, so this option is not recomended for merchants using Braintree's recurring billing system. This feature is not supported in Internet Explorer 9.

To enable the "Vault Manager" (the ability to delete vaulted payment methods), set vaultManager: true when creating the drop-in:

braintree.dropin.create({
  authorization: 'CLIENT_AUTHORIZATION',
  vaultManager: true,
  /* your other braintree options */
})
like image 39
AlbinoDrought Avatar answered Sep 28 '22 04:09

AlbinoDrought