Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Payment method token is invalid in Braintree

I want to test it on the side of the functionality of the subscription payment gateway Braintree - for my application using Django (python).

Your code I have only one py file. (without front-end). When I want to create a subscription I get an error:

<ErrorResult 'Payment method token is invalid.' at 7f101d301390>

How can I get token payment method?

Here is all my code:

import braintree

braintree.Configuration.configure(braintree.Environment.Sandbox,
                                  merchant_id="myMechrantId",
                                  public_key="myPublicKey",
                                  private_key="myPrivateKey")

client_token = braintree.ClientToken.generate()

client = braintree.Customer.create({
    "first_name": 'Mike',
    "last_name": "Smith",
    "company": "Braintree",
    "email": "[email protected]",
    "phone": "312.555.1234",
    "fax": "614.555.5678",
    "website": "www.example.com"
})

result = braintree.Subscription.create({
    "payment_method_token": "the_token",
    "plan_id": "Here is my plan ID"
})
like image 343
mark Avatar asked Mar 26 '15 09:03

mark


1 Answers

I work at Braintree. Please get in touch with our support team if you have more questions.

In general, one of the main benefits of a service like Braintree is that you never have to handle credit card numbers, so you're better off following the Braintree recurring billing guide instead, which will better match a real integration with Braintree.

That said, if you do want to test it without a front-end, you can test it like this:

result = braintree.Customer.create({
    "credit_card": {
        "number": "4111111111111111",
        "expiration_date": "12/16"
    }
})

result = braintree.Subscription.create({
    "payment_method_token": result.customer.credit_cards[0].token,
    "plan_id": "my_plan_id"
})
like image 83
agf Avatar answered Oct 19 '22 10:10

agf