Get paid using Anvil.

Learn how to take online payments using Anvil and Stripe.

Note: This guide includes screenshots of the Classic Editor. Since we created this guide, we've released the new Anvil Editor, which is more powerful and easier to use.

All the code in this guide will work, but the Anvil Editor will look a little different to the screenshots you see here!

Find out more about accepting payments online - check out the Stripe section of the Anvil reference manual.

Topics Covered

The Stripe Service | 0:20 - 0:42

We enable the Stripe Service:

We then log in to an existing Stripe account. If you don’t have an account, don’t worry - Stripe accounts are free and signup takes a few minutes.

The Stripe Service is in Test Mode when you start it up, which means the service doesn’t actually charge anybody’s account.

Write some code | 0:42 - 1:06

Our user interface is just a single Button saying ‘Pay me’. We write an event handler to charge the user when the Button is clicked:

  def button_1_click(self, **event_args):
    """This method is called when the button is clicked."""
    c = stripe.checkout.charge(currency="GBP", amount=100)

Get paid | 1:06 - 1:49

Let’s try it out - when the user clicks on the Button, they are presented with a payment dialog.

We make a payment from card number 4242 4242 4242 4242. This is a test card that only works in test mode.

The Output Console shows the return value of the charge function - it contains all available information about the transaction. You could use this to audit your transactions and run analytics. It includes a URL that allows you to look up the transaction in the Stripe dashboard later.

Try it for yourself

Build this app for yourself - Log in and follow along, or try more tutorials to learn more about Anvil.

Next up

See the Stripe Service used in a production-scale app. We built an app to take online parking meter payments in just 90 minutes. You can read about how it works and clone the app into your own Anvil account.

If you’d like to learn the basics of Anvil, start with the Hello, World! tutorial.