Get LaunchBase

Stripe Payments Page!

Integrating Stripe into your Django application allows you to process payments securely and efficiently. This guide will help you set up your Stripe account, store your API keys, configure webhooks, and create a product with Stripe.


Setting Up a Stripe Account

To begin, you'll need to create a Stripe account if you don't already have one. Visit Stripe's website and sign up for an account. Once your account is set up and you have verified your email, you can start configuring your payment environment.


Retrieve API Keys

Navigate to the Developers section, then to API keys. You will find two keys here: the Publishable Key and the Secret Key. There are two sets of keys: one for testing (starts with pk_test and sk_test) and one for live payments (starts with pk_live and sk_live). Save the relevant keys to your secrets.json file.


Configure Webhooks

Stripe uses webhooks to notify your application when an event happens in your account, such as successful payments, failed charges, or recurring subscription events.

Go to the Webhooks page on your Stripe Dashboard:

  • Click on “Add endpoint” and enter your webhook URL for your domain https://yourdomain.com/stripe/webhook/.

  • Select the events you want to listen to, or choose to receive all events.

  • Once created, Stripe will generate a signing secret.

  • Add the STRIPE_WEBHOOK_SECRET to your secrets.json file.


Create a Product and Pricing

Next, you'll need to create a product and its associated pricing plans in Stripe:

  • Navigate to the Products section of the Stripe Dashboard and create a new product.
  • Add a pricing plan to this product. This can be a one-time charge or a recurring subscription.
  • After setting up the pricing plan, you will receive a Price ID (starts with price_).
  • Update your secrets.json file with the STRIPE_PRICE_ID:

Conclusion

By following these steps, you've configured your Django application to handle Stripe payments. When logged in and navigating to /autoshop/ you should now be redirected to the stripe payment portal. Once checkout is complete a new django user association will be made linking the stripe customer profile to the django user. tip: use coupons codes to test production setup.