stripe-paymentsGetting started with stripe-payments


This section provides an overview of what stripe-payments is, and why a developer might want to use it.

It should also mention any large subjects within stripe-payments, and link out to the related topics. Since the Documentation for stripe-payments is new, you may need to create initial versions of those related topics.

Embedded Stripe Payment Modal

Register a production/sandbox account at

Insert below code into your webpage where you want to have a checkout button.

<form action="/charge" method="POST">
    src="" class="stripe-button"
    data-description="2 widgets"

Result:enter image description here

Hello World in Python

An example how to run stripe out of the box with wsgi from a single file.

At first, please install the python stripe API, i.e. with pip:

pip install --user stripe

Create which creates a WSGI webserver at port 8000 out of the box

html = """

form = """
<form action="" method="POST">
        src="" class="stripe-button"
        data-description="Hello World"

def application(environ, start_response):
                request_body_size = int(environ.get('CONTENT_LENGTH', 0))
        except (ValueError):
                request_body_size = 0
        request_body = environ['wsgi.input'].read(request_body_size)
        post = parse_qs(request_body)
        out = ''
        if post:
                print post
                token = post.get('stripeToken', [''])[0]
                token = escape(token)
                if token:
                        import stripe
                        stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"
                                charge = stripe.Charge.create(
                                        description="Hello World",
                                out = '<pre>charge: %s</pre>' % (charge,)
                        except Exception as e:
                                print 'Exception %s' % (str(e),)
                        out = 'missing in post: token'
                out = form
        response_body = html % {
                'output': out,
        status = '200 OK'
        response_headers = [('content-type', 'text/html;charset=utf-8')]
        start_response(status, response_headers)        
        return [response_body]

from wsgiref.simple_server import make_server
from cgi import parse_qs, escape
httpd = make_server('', 8000, application)

Please note:

  • the frontend form contains the public key
  • the backend charge part contains the secret key.

Run the script


Navigate with your browser to


After clicking the Pay-Button and entering the credit card number (4242424242424242) the form is posted with the token. So the payment could be processed and finally the charge object will be printed into the browser, which contains:

"paid": true, 
"description": "Hello World", 
"status": "succeeded"

Resources and further reading:

Installation or Setup

Detailed instructions on getting stripe-payments set up or installed.

Introduction to Stripe's API

A typical payment flow with Stripe can be divided in two steps:

  1. Client-side, in your frontend (HTML + Javascript) code, you collect the customer's payment information using Stripe's prebuilt Checkout form or Elements form field(s). This will return a token that you then send to your server.

  2. Server-side, in your backend code (in PHP, Python, Ruby, or whichever server-side programming language you prefer), you use the token in a charge creation request to actually charge the card.

The point of this 2-step flow is that your server only works with card tokens and never with raw card information. This means you never have access to card numbers, which greatly eases the burden of PCI compliance.

Stripe's documentation is pretty extensive and includes many examples and tutorials -- make sure to check it out!