Laravel\Cashier\Billable::createAsBraintreeCustomer PHP Method

createAsBraintreeCustomer() public method

Create a Braintree customer for the given user.
public createAsBraintreeCustomer ( string $token, array $options = [] ) : Customer
$token string
$options array
return Braintree\Customer
    public function createAsBraintreeCustomer($token, array $options = [])
    {
        $response = BraintreeCustomer::create(array_replace_recursive(['firstName' => Arr::get(explode(' ', $this->name), 0), 'lastName' => Arr::get(explode(' ', $this->name), 1), 'email' => $this->email, 'paymentMethodNonce' => $token, 'creditCard' => ['options' => ['verifyCard' => true]]], $options));
        if (!$response->success) {
            throw new Exception('Unable to create Braintree customer: ' . $response->message);
        }
        $paymentMethod = $response->customer->paymentMethods[0];
        $paypalAccount = $paymentMethod instanceof PaypalAccount;
        $this->forceFill(['braintree_id' => $response->customer->id, 'paypal_email' => $paypalAccount ? $paymentMethod->email : null, 'card_brand' => !$paypalAccount ? $paymentMethod->cardType : null, 'card_last_four' => !$paypalAccount ? $paymentMethod->last4 : null])->save();
        return $response->customer;
    }