Currently I'm integrating stripe payments into may django-based backed app - here is how it can be done with python. I've some integration tests done with APIClient
and after payments were introduced I need to generate a sample token (normally received from client and generated with stripe.js) to make a successful payment.
Since these are integration tests I can't mock any part of my code.
You can just create the token with stripe.Token.create():
import stripe
stripe.api_key = "sk_test_asdfkljasblahblah123"
token = stripe.Token.create(
card={
"number": '4242424242424242',
"exp_month": 12,
"exp_year": 2016,
"cvc": '123'
},
)
To make a charge, only the id
is required. This can be obtained with token.id
, after the token has been generated.
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