Reputation:
I'm building a simple payment system using Braintree payments, PHP and JavaScript. I'm using Braintree's Drop-in UI, and would like to create subscriptions (i.e. recurring billing).
For this, I'm using:
// $_customer is a Braintree_Customer object; a customer stored in the Vault
$subscription_create = Braintree_Subscription::create([
'id' => $_customer->id,
'planId' => 'some_package',
'paymentMethodToken' => $_customer->defaultPaymentMethod()->token
]);
This works fine, and creates a subscription using the customer's 'default payment method'. However, I don't see any way for the customer to change his default payment method. There does not seem to be an option for this in the drop-in UI.
Does this mean I cannot use the drop-in UI for recurring billing? Should I write my own UI to allow customers to change their default payment method?
There is a way to make a payment method the default one. I could use that one, however, I only receive a paymentMethodNonce from the client. How do I find the paymentMethod linked to that nonce?
Upvotes: 3
Views: 2067
Reputation: 176730
I work at Braintree. If you have more questions, you can always get in touch with our support team.
You don't need a special method for this, you can pass the nonce directly to Braintree_PaymentMethod::create
:
$result = Braintree_PaymentMethod::create(array(
'customerId' => '12345',
'paymentMethodNonce' => 'nonce-from-the-client'
));
Upvotes: 3