Recurring payment not working with PayPal button in braintree

I am using PayPal button in my HTML form. Everything works fine as PayPal asks for authentication and enters payment_method_nonce in the HTML form.

But, when I create a subscription with this payment_method_nonce, then it gives me an error: - Message: - The payment method token is not valid. Code: - 91903

I am using PHP library and here is my code snippet: -

$subscription = Braintree_Subscription::create(array(
    'paymentMethodToken' => payment_method_nonce that PayPal button inject in my form,
    'planId' => planId that created in Braintree,   
));

      

or if i use the sale method using the same payment_method_nonce like this: -

$subscription = Braintree_Transaction::sale(array(
    'amount' => $amount,
    'paymentMethodToken' => payment_method_nonce that PayPal button inject in my form
));

      

than his work.

Please let me know what is the problem with this?

+3


source to share


1 answer


I work at Braintree. You can always contact our support team if you need further assistance.

Payment methods must be vaulted before they can be used to create a subscription .



In the case of a nonce that does not indicate a billable payment method, you can use it to create one and then use it to create a subscription. (We will update the docs to make this clearer.)

$result = Braintree_Customer::create(array(
    'paymentMethodNonce' => $payment_method_nonce,
));

$token = $result->customer->paypalAccounts[0]->token;

$result = Braintree_Subscription::create(array(
  'paymentMethodToken' => $token,
  'planId' => 'planId that created in Braintree',
));

      

+11


source







All Articles