Search code examples
braintree

braintree how to vault a payment method ready for subscription


I'd like to create a customer with a payment method then store the payment method in the vault

and then to create a subscription for the user

so far I have this:

    $rs = \Braintree_Customer::create([
            'id'                 =>$m_id,
            'firstName'          =>$username,
            'paymentMethodNonce' =>$nonce
            ]);

but this doesn't appear to be storing payment methods in the vault, is the above code correct for storing payment methods in the vault?


Solution

  • You need to send the customer_id and paymentmethodnonce to BT. Follow the ways

    $result = Braintree_PaymentMethod::create([
        'customerId' => '12345',
        'paymentMethodNonce' => nonceFromTheClient
    ]);
    

    From the result you can get the braintree token (token = result.payment_method.token) store in the database. You can use this token for the subscription.