Stripe Addon
Stripe allows to add pre-paid payments to the Platform so users can buy Credits and consume them.
Stripe Configuration
- Create a product with name e.g.
Datalayer Credits
.- Copy the product ID and set that value (starting with
prod_
) as theDATALAYER_STRIPE_PRODUCT_ID
environment variable.
- Copy the product ID and set that value (starting with
- Create one or more pricing for that product, each pricing is for a package of credits.
- Pricing policy: Select
one-off
(it will charge a one-time fee). - Pricing model: Select
Package pricing
.- Amount: e.g. $5.00 per 50 units (one unit equals one credits on the platform, and we recommend 0.1$ per unit/credit).
- Choose a VAT policy,
Auto
,Yes
orNo
based on your country policy.
- Set a price description that will be fetched and displayed in the payment form.
- Pricing policy: Select
- Create a Webhook endpoint.
- Set the target endpoint URL, e.g.
https://test.datalayer.run/api/iam/stripe/v1/webhook
. - Select the events to be sent, we only use
checkout.session.completed
. - Copy the Webhook signing secret and set that value (starting with
whsec_
) as theDATALAYER_STRIPE_WEBHOOK_SECRET
environment variable.
- Set the target endpoint URL, e.g.
- Get additional Keys present in the
Developers > API keys
section of the Stripe portal.- Copy the Stripe Publishable API Key (starting with
pk_
) and set that value as theDATALAYER_STRIPE_JS_API_KEY
environment variable. - Copy the Stripe Secret API Key (starting with
sk_
) and set that value as theDATALAYER_STRIPE_API_KEY
environment variable.
- Copy the Stripe Publishable API Key (starting with
Datalayer Services
The Datlayer services need to respond to the calls to the Webhook.
- Add feature to create a Stripe customer for each platform users.
- Add handler to fetch the prices to display possible credit packages to the user.
- Add handler to create a Stripe checkout session (read more on the Stripe documentation website).
- Add a Webhook handler to update user credits balance (read more on the Stripe documentation website).
- Check the payload signature.
- Filter by event type - although we should only get one type here.
- Get the checkout session purchases from the event metadata.
- Update user credits balance with the retrieved purchases.
warning
- Stripe will retry sending event if the webhook fails (with exponential backoff delay).
- Stripe may send multiple times the same events.
User Interface
The User Interface needs to implement the following functionality.
- Fetch the prices for the Remote Kernel credits, requesting the Datalayer Services (that will interrogate back Stripe).
- Display a form for the user to pick a credits package.
- Fetch a
checkout session id
, requesting the Datalayer Services (that will interrogate Stripe). - Display the embedded Strip checkout session using the secret of the checkout session.
Read more on the Stripe documentation website.
That is it as we don't trust the customer Web Application to validate a checkout session, we are using the Webhook events.