If a customer has more than one payment method the Billable->charge() method is not working as expected. It charges the first payment method, not the default one.
$customer->paymentMethods[0]->token
I have fixed it by creating a method: (I hope correctly...)
$this->defaultPaymentMethod()->token,
/**
* Choose the default payment method.
*
* @return \Braintree\PaymentMethod
*/
private function defaultPaymentMethod()
{
$customer = $this->asBraintreeCustomer();
foreach ($customer->paymentMethods as $paymentMethod) {
if($paymentMethod->default) { return $paymentMethod;}
}
}
If a customer has more than one payment method the Billable->charge() method is not working as expected. It charges the first payment method, not the default one.
$customer->paymentMethods[0]->token
I have fixed it by creating a method: (I hope correctly...)
$this->defaultPaymentMethod()->token,