Reputation: 391
I am using a PayPal button in my HTML Form. All works fine like PayPal ask for authentication and inject the payment_method_nonce in HTML form.
But, When i creating a subscription with this payment_method_nonce then its give me error that:- Message:- Payment method token is invalid 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 sale method using 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 its works fine.
Please let me know what is the problem with this?
Upvotes: 3
Views: 2363
Reputation: 176730
I work at Braintree. You can always get in touch with our support team if you need more help.
Payment methods need to be vaulted before they can be used to create a subscription.
In the case of a nonce that doesn't point to a vaulted payment method, you can use it to create one, and then use that to create the subscription. (We'll update the docs to make this more clear.)
$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',
));
Upvotes: 12