public function createAsBraintreeCustomer($token, array $options = []): Customer
    {
        $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);
        }

        $this->braintree_id = $response->customer->id;

        $paymentMethod = $this->paymentMethod();

        $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;
    }
public function createAsBraintreeCustomer($token, array $options = []): Customer
    {
        $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);
        }

        $this->braintree_id = $response->customer->id;

        $paymentMethod = $this->paymentMethod();

        $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;
    }
public function createAsBraintreeCustomer ( $ token , array $ options = [ ] ) : Customer { $ 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 ) ; } $ this -> braintree_id = $ response -> customer -> id ; $ paymentMethod = $ this -> paymentMethod ( ) ; $ 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 ; }
Create a Braintree customer for the given model.

@param  string  $token
@param  array  $options
@return \Braintree\Customer
@throws \Exception
Create a Braintree customer for the given model .