@raideno/convex-stripe 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -13
- package/dist/index.d.ts +52 -52
- package/dist/server.js +286 -69
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Stripe [syncing](./references/tables.md), subscriptions, [checkouts](#-checkout-
|
|
|
8
8
|
npm install @raideno/convex-stripe stripe
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Usage
|
|
12
12
|
|
|
13
13
|
### 1. Set up Stripe
|
|
14
14
|
- Create a Stripe account.
|
|
@@ -42,7 +42,9 @@ export default defineSchema({
|
|
|
42
42
|
|
|
43
43
|
### 4. Initialize the library
|
|
44
44
|
|
|
45
|
-
```ts
|
|
45
|
+
```ts
|
|
46
|
+
// convex/stripe.ts
|
|
47
|
+
|
|
46
48
|
import { internalConvexStripe } from "@raideno/convex-stripe/server";
|
|
47
49
|
|
|
48
50
|
export const { stripe, store, sync } = internalConvexStripe({
|
|
@@ -67,12 +69,14 @@ export const createCustomer = internalAction({
|
|
|
67
69
|
|
|
68
70
|
```
|
|
69
71
|
|
|
70
|
-
> **Note:** All exposed actions (store
|
|
72
|
+
> **Note:** All exposed actions (`store`, `sync`) are **internal**. Meaning they can only be called from other convex functions, you can wrap them in public actions when needed.
|
|
71
73
|
> **Important:** `store` must always be exported, as it is used internally.
|
|
72
74
|
|
|
73
75
|
### 5. Register HTTP routes
|
|
74
76
|
|
|
75
|
-
```ts
|
|
77
|
+
```ts
|
|
78
|
+
// convex/http.ts
|
|
79
|
+
|
|
76
80
|
import { httpRouter } from "convex/server";
|
|
77
81
|
import { stripe } from "./stripe";
|
|
78
82
|
|
|
@@ -89,7 +93,7 @@ export default http;
|
|
|
89
93
|
|
|
90
94
|
Ideally you want to create a stripe customer the moment a new entity (user, organization, etc) is created.
|
|
91
95
|
|
|
92
|
-
An `entityId` refers to something you are billing. It can be a user, organization or any other thing. With each entity must be associated a stripe customer and the stripe customer can be created using the [`
|
|
96
|
+
An `entityId` refers to something you are billing. It can be a user, organization or any other thing. With each entity must be associated a stripe customer and the stripe customer can be created using the [`stripe.customers.create` function](#stripecustomerscreate-function).
|
|
93
97
|
|
|
94
98
|
Below are with different auth providers examples where the user is the entity we are billing.
|
|
95
99
|
|
|
@@ -107,6 +111,7 @@ import { internal } from "./_generated/api";
|
|
|
107
111
|
export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
|
|
108
112
|
providers: [Password],
|
|
109
113
|
callbacks: {
|
|
114
|
+
// NOTE: create a customer immediately after a user is created
|
|
110
115
|
afterUserCreatedOrUpdated: async (context, args) => {
|
|
111
116
|
await context.scheduler.runAfter(0, internal.stripe.createCustomer, {
|
|
112
117
|
/*
|
|
@@ -148,17 +153,36 @@ It must be done in both your development and production deployments after instal
|
|
|
148
153
|
This might not be necessary if you are starting with a fresh empty stripe project.
|
|
149
154
|
|
|
150
155
|
### 8. Start building
|
|
156
|
+
|
|
151
157
|
Now you can use the provided functions to:
|
|
152
158
|
- Generate a subscription or payment link [`stripe.subscribe`](#subscribe-function), [`stripe.pay`](#pay-function) for a given entity.
|
|
153
159
|
- Generate a link to the entity's [`stripe.portal`](#portal-function) to manage their subscriptions.
|
|
154
160
|
- Create stripe connect accounts and link them, [`stripe.accounts.create`](#), [`stripe.accounts.link`](#).
|
|
155
|
-
- Consult the [synced tables](
|
|
161
|
+
- Consult the [synced tables](documentation/references/tables.md).
|
|
156
162
|
- Etc.
|
|
157
163
|
|
|
164
|
+
## Add Stripe Connect
|
|
158
165
|
|
|
159
|
-
|
|
166
|
+
If you wish to also add stripe connect, below is a guide on how to do it. You can find a full example in [`examples/marketplaces/README.md`](examples/marketplace/README.md).
|
|
167
|
+
|
|
168
|
+
### 1. Create a connect webhook using `sync` method.
|
|
169
|
+
...
|
|
160
170
|
|
|
161
|
-
|
|
171
|
+
### 2. Add the new webhook secret to the dashboard and configuration.
|
|
172
|
+
...
|
|
173
|
+
|
|
174
|
+
### 3. Create Stripe Accounts for Sellers & Onboard them
|
|
175
|
+
...
|
|
176
|
+
|
|
177
|
+
### 4. Create Products for Sellers
|
|
178
|
+
...
|
|
179
|
+
|
|
180
|
+
### 5. Send payouts
|
|
181
|
+
...
|
|
182
|
+
|
|
183
|
+
## References
|
|
184
|
+
|
|
185
|
+
The library automatically syncs the [following tables](documentation/references/tables.md).
|
|
162
186
|
|
|
163
187
|
You can query these tables at any time to:
|
|
164
188
|
|
|
@@ -168,7 +192,7 @@ You can query these tables at any time to:
|
|
|
168
192
|
- Etc.
|
|
169
193
|
|
|
170
194
|
|
|
171
|
-
### `customers.create` Function
|
|
195
|
+
### `stripe.customers.create` Function
|
|
172
196
|
|
|
173
197
|
Creates or updates a Stripe customer for a given entity (user or organization). Will call [`stripe.customers.create`](https://docs.stripe.com/api/customers/create) under the hood.
|
|
174
198
|
|
|
@@ -210,6 +234,15 @@ This action is typically manually called or setup to be automatically called in
|
|
|
210
234
|
|
|
211
235
|
**Parameters:**
|
|
212
236
|
|
|
237
|
+
```ts
|
|
238
|
+
{
|
|
239
|
+
data?: boolean | { withConnect: boolean };
|
|
240
|
+
webhook?: { account?: boolean; connect?: boolean };
|
|
241
|
+
portal?: boolean;
|
|
242
|
+
unstable_catalog?: boolean;
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
213
246
|
- `data` (optional, default: `true`): Syncs all existing Stripe resources to Convex tables.
|
|
214
247
|
- `data.withConnect` (option, default: `false`): Syncs all existing Stripe resources from linked accounts to Convex tables.
|
|
215
248
|
- `webhook.account` (optional, default: `false`): Creates/updates the account webhook endpoint. Returns the webhook secret if a new endpoint is created. You must set it in your convex environment variables as `STRIPE_ACCOUNT_WEBHOOK_SECRET`.
|
|
@@ -217,7 +250,7 @@ This action is typically manually called or setup to be automatically called in
|
|
|
217
250
|
- `portal` (optional, default: `false`): Creates the default billing portal configuration if it doesn't exist.
|
|
218
251
|
- `unstable_catalog` (optional, default: `false`): Creates the default provided products and prices passed in the configuration.
|
|
219
252
|
|
|
220
|
-
### `subscribe` Function
|
|
253
|
+
### `stripe.subscribe` Function
|
|
221
254
|
|
|
222
255
|
Creates a Stripe Subscription Checkout session for a given entity. Will call [`stripe.checkout.sessions.create`](https://docs.stripe.com/api/checkout/sessions/create) under the hood, the same parameters can be passed.
|
|
223
256
|
|
|
@@ -253,7 +286,7 @@ export const createCheckout = action({
|
|
|
253
286
|
```
|
|
254
287
|
|
|
255
288
|
|
|
256
|
-
### `portal` Function
|
|
289
|
+
### `stripe.portal` Function
|
|
257
290
|
|
|
258
291
|
Allows an entity to manage their subscription via the Stripe Portal. Will call [`stripe.billingPortal.sessions.create`](https://docs.stripe.com/api/customer_portal/sessions/create) under the hood, the same parameters can be passed.
|
|
259
292
|
|
|
@@ -285,7 +318,7 @@ export const portal = action({
|
|
|
285
318
|
The provided entityId must have a customerId associated to it otherwise the action will throw an error.
|
|
286
319
|
|
|
287
320
|
|
|
288
|
-
### `pay` Function
|
|
321
|
+
### `stripe.pay` Function
|
|
289
322
|
|
|
290
323
|
Creates a Stripe One Time Payment Checkout session for a given entity. Will call [`stripe.checkout.sessions.create`](https://docs.stripe.com/api/checkout/sessions/create) under the hood, the same parameters can be passed.
|
|
291
324
|
|
|
@@ -324,7 +357,7 @@ export const pay = action({
|
|
|
324
357
|
|
|
325
358
|
## Best Practices
|
|
326
359
|
|
|
327
|
-
- Always create a Stripe customer (`
|
|
360
|
+
- Always create a Stripe customer (`stripe.customers.create`) when a new entity is created.
|
|
328
361
|
- Use `metadata` or `marketing_features` on products to store feature flags or limits.
|
|
329
362
|
- Run `sync` when you first configure the extension to sync already existing stripe resources.
|
|
330
363
|
- Never expose internal actions directly to clients, wrap them in public actions with proper authorization.
|