๐ฐStripe Integration
Handling Stripe payments and webhooks.
Adding Stripe Payment
To get started, ensure you have a Stripe account and access the Developers section in the Stripe Dashboard.
1. Setting up Payment Integration with the Stripe Embeddable Pricing Table
Pricing Table is a no code solution from stripe and is specifically designed for first-time purchases. It simplifies the process by allowing you to integrate an iframe directly into your webpage. This iframe will display various pricing options available to your new customers.
2. Embedding Pricing Table over the UI
Prompt Databutton to create a new UI component and paste the pricing table code to embed it.
Alternatively, copy the template code given below and paste over a page/UI components. Make sure to replace with your actual pricing-table-id
and publishable-key
.
3. API for handling webhook
The stripe_webhook
endpoint gets triggered when Stripe sends a POST request to your webhook URL. This happens when specific events occur in your Stripe account, such as a successful payment through Stripe Checkout.
Generating Webhook API via prompting
Databutton can generate this API on prompting and guide through the entire process. Example prompt :
Generating stripe_webhook API manually
This step requires : STRIPE_SECRET_KEY
key and STRIPE_WEBHOOK_SECRET key and add it to Databutton secrets. For adding over to Databutton secrets hover to Config (โ๏ธ). Instruction given below on how to obtain the secret keys.
How to get the Stripe API Key and add over Databutton:
Go to the Stripe Dashboard.
Navigate to Developers.
Click on API keys.
Copy the secret key and paste it into Databutton/config/secrets.
How to configure the Webhook Endpoint and fetch the Webhook:
Go to the Stripe Dashboard.
Navigate to Developers.
Click on the Webhooks tab.
Click "Add endpoint"
In order to enter the endpoint URL, we need two things (a) Project ID of the current Databutton App and (b) Router name of the wehbhook API. Then, we need to replace them in the following URL ;
https://api.databutton.com/_projects/<ProjectID>/dbtn/prodx/app/routes/<RouterName>
(replace<projectID>
and<router_name>
with your specific information)Project ID can be found over the current browser url : https://databutton.com/projects/<projectID>/ui/App/build
router_name : In the template code given below, the router name used is
webhook
. Here's the ref line@router.post("/webhook")
. You can find the entire code for the API below.Copy the webhook secret ("whsec_xxxxxx") and paste it into Databutton/config/secrets
While selecting events to send, you can choose specific events, such as those related to the customer (e.g.,
checkout.session.completed
)
While adding the endpoint url, the Correct Project ID
and Router Name
is important.
API (stripe_webhook
)
Note: In the above example code, we use databutton
storage to monitor the event details with db.storage.json.put("stripe-webhook-event", event)
, which can be useful for verifying that the webhook integration is working correctly and can be extended for database storage, security checks, and automated processing.
Add stripe package, when adding the API code manually
Note : The app must be deployed for a successfull webhook call.
Last updated