Skip to content

Commit 3639244

Browse files
committed
Merge remote-tracking branch 'origin/main' into bwilmoth/macros-plugin
2 parents 0a9d34f + 8e36487 commit 3639244

4 files changed

Lines changed: 441 additions & 1 deletion

File tree

plugins/stripe/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Stripe Subscriptions Plugin
2+
3+
The Stripe Subscriptions Plugin for Starbase provides a quick and simple way for applications to begin accepting product subscription payments.
4+
5+
## Usage
6+
7+
Add the StripeSubscriptionPlugin plugin to your Starbase configuration:
8+
9+
```typescript
10+
import { StripeSubscriptionPlugin } from './plugins/stripe'
11+
const plugins = [
12+
// ... other plugins
13+
new StripeSubscriptionPlugin({
14+
stripeSecretKey: 'sk_test_**********',
15+
stripeWebhookSecret: 'whsec_**********',
16+
}),
17+
] satisfies StarbasePlugin[]
18+
```
19+
20+
## Configuration Options
21+
22+
| Option | Type | Default | Description |
23+
| --------------------- | ------ | ------- | ----------------------------------------------------------------------- |
24+
| `stripeSecretKey` | string | `null` | Access your secret key from (https://dashboard.stripe.com/apikeys) |
25+
| `stripeWebhookSecret` | string | `null` | Access your signing secret from (https://dashboard.stripe.com/webhooks) |
26+
27+
## How To Use
28+
29+
### Webhook Setup
30+
31+
For our Starbase instance to receive webhook events when subscription events change, we need to add our plugin endpoint to Stripe.
32+
33+
1. Visit the Developer Webhooks page: https://dashboard.stripe.com/webhooks
34+
2. Click "+ Add Endpoint"
35+
3. Set "Endpoint URL" to `https://starbasedb.YOUR-IDENTIFIER.dev/stripe/webhook`
36+
4. Add two events to listen to:
37+
- `customer.subscription.deleted`
38+
- `checkout.session.completed`
39+
5. Save by clicking "Add Endpoint"
40+
41+
### Product Subscription Setup
42+
43+
After you create a subscription product inside of Stripe you can get the hosted link by following these steps:
44+
45+
1. Click on the "Product catalog" section
46+
2. Click on the product you want
47+
3. Click the "..." menu next to the Pricing item you want a link for
48+
4. Click "Create new payment link"
49+
50+
Now you will have a new payment URL for you to direct your users to in order for them to checkout a new subscription of your product. We will take that URL and insert it
51+
into our frontend application similar to the example below.
52+
53+
_IMPORTANT:_ You must append the `client_reference_id={userId}` at the end so we can attribute the correct user for the purchase.
54+
55+
```html
56+
<body>
57+
<a
58+
href="https://buy.stripe.com/INSERT-SUBSCRIPTION-ID?client_reference_id=INSERT-USER-ID"
59+
class="subscribe-button"
60+
>
61+
Subscribe
62+
</a>
63+
</body>
64+
```
65+
66+
Assuming all of the correct values were set in your installation phases, when a customer successfully subscribes via the Stripe Payment Link you should see a new entry automatically populate inside your SQLite table named `subscription`. At any point if this subscription is cancelled, even from the Stripe interface, the webhook will be handled via this plugin and automatically mark the `deleted_at` column with the date time it became inactive.

0 commit comments

Comments
 (0)