Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a valid sample token with stripe?

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.

like image 585
Opal Avatar asked Mar 06 '15 12:03

Opal


1 Answers

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.

like image 117
rnevius Avatar answered Sep 28 '22 03:09

rnevius