You are currently viewing the new Anvil Editor Docs.
Switch to the Classic Editor Docs
You are currently viewing the Classic Editor Docs.
Switch to the new Anvil Editor Docs

Quickstart: Stripe integration

Take payments using Stripe

Create an app

Log in to Anvil and click ‘New Blank App’. Choose the Material Design theme.

Location of the Create App button

Location of the Create App button

Enable the Stripe Service

In the App Browser, click the + next to Services.

App Browser showing the plus next to Services

You’ll see a list of available services and integrations. Click on Stripe.

List of available services with Stripe highlighted

In the Sidebar Menu, click the blue plus button +. You’ll see a list of available services and integrations. Click on Stripe

Services list with Stripe highlighted

Log in to a Stripe account

You must now connect Anvil to a Stripe account. You have two options.

The Stripe Service with options to log in or create a Stripe account.

The Stripe Service with options to log in or create a Stripe account.

If you already have a Stripe account, you can log in to it from Anvil to connect your app to Stripe.

Click ‘Yes - connect my existing account’. You’ll get a Stripe log in window - log in to your account.

The Stripe login window

If you do not already have a Stripe account, you’ll need one in order to take payments. Click ‘No - I need to create an account’. You’ll get a Stripe sign-up window, where you can enter a few details. Once you’ve signed up, you’ll be back in the Anvil Editor.

Add a payment form to your app

Click on Form1 in the App Browser.

Form1 in the App Browser

Form1 in the App Browser

Go to the Code view to see the code for Form1.

Form1 in the App Browser

Form1 in the App Browser

In the __init__ method, add these lines:

    c = stripe.checkout.charge(currency="GBP", amount=100)
    print(c)

Run your app and get paid

Now click the ‘Run’ button at the top of the screen.

Run app button at the top of the Anvil Editor

Run app button at the top of the Anvil Editor

Your app will run and display a payment form. The Stripe Service is running in test mode, so no money will actually change hands.

A Stripe Payment form with a label indicating that it's in test mode

For the card number, enter 4242424242424242 (This is a Visa test card number). Put anything in the other fields (the expiry date must be in the future).

Hit the ‘Pay’ button. The Stripe payment form will disappear and your main app will finish loading. Your transaction details have been printed on the Output Panel:

The Output Panel showing a Python dictionary containing details of the test transaction that has just been made.

Hit the ‘Pay’ button. The Stripe payment form will disappear and your main app will finish loading. Your transaction details have been printed on the App Console:

The App Console showing a Python dictionary containing details of the test transaction that has just been made.

The transaction details contain 'result': 'succeeded' - so Stripe has registered the transaction!

Running in Live mode

To take payments for real, hit the ‘Switch to Live mode’ button in the Stripe Service:

The Stripe Service in Test mode, with a button to switch to Live mode.

The warning goes away and your transactions will now be enacted for real.

Copy the example app

Click on the button below to clone a finished version of this app into your account.

Of course, you’ll need to log in to your own Stripe account - the cloned app does not retain the connection to Stripe, for obvious security reasons.

Next Up

Want more depth on this subject?

As well as presenting a pre-made payment form, Anvil has Python methods for making Stripe payments programmatically. This uses Stripe’s token system that allows transmitting card details while complying with financial regulations.

The Python API allows you to:

  • Make a payment programmatically using a card details token,
  • associate transactions with a customer record,
  • store the card details token against a customer record,
  • and set up recurring subscriptions.

You can also use the raw Stripe Python API if you prefer.

Want another quickstart?

Every quickstart is on the Quickstarts page.


Do you still have questions?

Our Community Forum is full of helpful information and Anvil experts.