Laravel\Cashier\Billable::updateCard PHP Method

updateCard() public method

Update customer's credit card.
public updateCard ( string $token, array $options = [] ) : void
$token string
$options array
return void
    public function updateCard($token, array $options = [])
    {
        $customer = $this->asBraintreeCustomer();
        $response = PaymentMethod::create(array_replace_recursive(['customerId' => $customer->id, 'paymentMethodNonce' => $token, 'options' => ['makeDefault' => true, 'verifyCard' => true]], $options));
        if (!$response->success) {
            throw new Exception('Braintree was unable to create a payment method: ' . $response->message);
        }
        $paypalAccount = $response->paymentMethod instanceof PaypalAccount;
        $this->forceFill(['paypal_email' => $paypalAccount ? $response->paymentMethod->email : null, 'card_brand' => $paypalAccount ? null : $response->paymentMethod->cardType, 'card_last_four' => $paypalAccount ? null : $response->paymentMethod->last4])->save();
        $this->updateSubscriptionsToPaymentMethod($response->paymentMethod->token);
    }