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"
})
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"
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With