@raideno/convex-stripe 0.2.0 → 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 CHANGED
@@ -1,17 +1,14 @@
1
1
  # Convex Stripe
2
2
 
3
- A demo project is available at [https://convex-stripe-demo.vercel.app/](https://convex-stripe-demo.vercel.app/).
4
-
5
3
  Stripe [syncing](./references/tables.md), subscriptions, [checkouts](#-checkout-action) and stripe connect for Convex apps. Implemented according to the best practices listed in [Theo's Stripe Recommendations](https://github.com/t3dotgg/stripe-recommendations).
6
4
 
7
-
8
5
  ## Installation
9
6
 
10
7
  ```sh [npm]
11
8
  npm install @raideno/convex-stripe stripe
12
9
  ```
13
10
 
14
- ## Configuration
11
+ ## Usage
15
12
 
16
13
  ### 1. Set up Stripe
17
14
  - Create a Stripe account.
@@ -45,7 +42,9 @@ export default defineSchema({
45
42
 
46
43
  ### 4. Initialize the library
47
44
 
48
- ```ts [convex/stripe.ts]
45
+ ```ts
46
+ // convex/stripe.ts
47
+
49
48
  import { internalConvexStripe } from "@raideno/convex-stripe/server";
50
49
 
51
50
  export const { stripe, store, sync } = internalConvexStripe({
@@ -70,12 +69,14 @@ export const createCustomer = internalAction({
70
69
 
71
70
  ```
72
71
 
73
- > **Note:** All exposed actions (store, sync, createEntity) are **internal**. Meaning they can only be called from other convex functions, you can wrap them in public actions when needed.
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.
74
73
  > **Important:** `store` must always be exported, as it is used internally.
75
74
 
76
75
  ### 5. Register HTTP routes
77
76
 
78
- ```ts [convex/http.ts]
77
+ ```ts
78
+ // convex/http.ts
79
+
79
80
  import { httpRouter } from "convex/server";
80
81
  import { stripe } from "./stripe";
81
82
 
@@ -92,7 +93,7 @@ export default http;
92
93
 
93
94
  Ideally you want to create a stripe customer the moment a new entity (user, organization, etc) is created.
94
95
 
95
- 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 [`createEntity` action](#createentity-action).
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).
96
97
 
97
98
  Below are with different auth providers examples where the user is the entity we are billing.
98
99
 
@@ -110,6 +111,7 @@ import { internal } from "./_generated/api";
110
111
  export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
111
112
  providers: [Password],
112
113
  callbacks: {
114
+ // NOTE: create a customer immediately after a user is created
113
115
  afterUserCreatedOrUpdated: async (context, args) => {
114
116
  await context.scheduler.runAfter(0, internal.stripe.createCustomer, {
115
117
  /*
@@ -151,17 +153,36 @@ It must be done in both your development and production deployments after instal
151
153
  This might not be necessary if you are starting with a fresh empty stripe project.
152
154
 
153
155
  ### 8. Start building
156
+
154
157
  Now you can use the provided functions to:
155
158
  - Generate a subscription or payment link [`stripe.subscribe`](#subscribe-function), [`stripe.pay`](#pay-function) for a given entity.
156
159
  - Generate a link to the entity's [`stripe.portal`](#portal-function) to manage their subscriptions.
157
160
  - Create stripe connect accounts and link them, [`stripe.accounts.create`](#), [`stripe.accounts.link`](#).
158
- - Consult the [synced tables](./references/tables.md).
161
+ - Consult the [synced tables](documentation/references/tables.md).
159
162
  - Etc.
160
163
 
164
+ ## Add Stripe Connect
161
165
 
162
- ## Usage
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).
163
167
 
164
- The library automatically syncs the [following tables](./references/tables.md).
168
+ ### 1. Create a connect webhook using `sync` method.
169
+ ...
170
+
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).
165
186
 
166
187
  You can query these tables at any time to:
167
188
 
@@ -171,7 +192,7 @@ You can query these tables at any time to:
171
192
  - Etc.
172
193
 
173
194
 
174
- ### `customers.create` Function
195
+ ### `stripe.customers.create` Function
175
196
 
176
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.
177
198
 
@@ -213,6 +234,15 @@ This action is typically manually called or setup to be automatically called in
213
234
 
214
235
  **Parameters:**
215
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
+
216
246
  - `data` (optional, default: `true`): Syncs all existing Stripe resources to Convex tables.
217
247
  - `data.withConnect` (option, default: `false`): Syncs all existing Stripe resources from linked accounts to Convex tables.
218
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`.
@@ -220,7 +250,7 @@ This action is typically manually called or setup to be automatically called in
220
250
  - `portal` (optional, default: `false`): Creates the default billing portal configuration if it doesn't exist.
221
251
  - `unstable_catalog` (optional, default: `false`): Creates the default provided products and prices passed in the configuration.
222
252
 
223
- ### `subscribe` Function
253
+ ### `stripe.subscribe` Function
224
254
 
225
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.
226
256
 
@@ -256,7 +286,7 @@ export const createCheckout = action({
256
286
  ```
257
287
 
258
288
 
259
- ### `portal` Function
289
+ ### `stripe.portal` Function
260
290
 
261
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.
262
292
 
@@ -288,7 +318,7 @@ export const portal = action({
288
318
  The provided entityId must have a customerId associated to it otherwise the action will throw an error.
289
319
 
290
320
 
291
- ### `pay` Function
321
+ ### `stripe.pay` Function
292
322
 
293
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.
294
324
 
@@ -327,7 +357,7 @@ export const pay = action({
327
357
 
328
358
  ## Best Practices
329
359
 
330
- - Always create a Stripe customer (`createEntity`) when a new entity is created.
360
+ - Always create a Stripe customer (`stripe.customers.create`) when a new entity is created.
331
361
  - Use `metadata` or `marketing_features` on products to store feature flags or limits.
332
362
  - Run `sync` when you first configure the extension to sync already existing stripe resources.
333
363
  - Never expose internal actions directly to clients, wrap them in public actions with proper authorization.
@@ -337,7 +367,6 @@ export const pay = action({
337
367
 
338
368
  - [Convex Documentation](https://docs.convex.dev)
339
369
  - [Stripe Documentation](https://stripe.com/docs)
340
- - [Demo App](https://convex-stripe-demo.vercel.app/)
341
370
  - [GitHub Repository](https://github.com/raideno/convex-stripe)
342
371
  - [Theo's Stripe Recommendations](https://github.com/t3dotgg/stripe-recommendations)
343
372