@strav/stripe 0.1.0 → 0.1.1
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 +8 -8
- package/package.json +1 -1
- package/src/billable.ts +6 -6
- package/src/checkout_builder.ts +1 -1
- package/src/customer.ts +1 -1
- package/src/errors.ts +1 -1
- package/src/helpers.ts +1 -1
- package/src/receipt.ts +1 -1
- package/src/stripe_manager.ts +2 -2
- package/src/stripe_provider.ts +2 -2
- package/src/subscription.ts +1 -1
- package/src/subscription_builder.ts +1 -1
- package/src/webhook.ts +3 -3
- package/stubs/config/stripe.ts +1 -1
- package/stubs/schemas/customer.ts +1 -1
- package/stubs/schemas/receipt.ts +1 -1
- package/stubs/schemas/subscription.ts +1 -1
- package/stubs/schemas/subscription_item.ts +1 -1
package/README.md
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @strav/stripe
|
|
2
2
|
|
|
3
|
-
Stripe billing for the [Strav](https://www.npmjs.com/package/@
|
|
3
|
+
Stripe billing for the [Strav](https://www.npmjs.com/package/@strav/core) framework. Subscriptions, one-time charges, checkout sessions, invoices, payment methods, and webhooks.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
bun add @
|
|
8
|
+
bun add @strav/stripe
|
|
9
9
|
bun strav install stripe
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
Requires `@
|
|
12
|
+
Requires `@strav/core` as a peer dependency.
|
|
13
13
|
|
|
14
14
|
## Setup
|
|
15
15
|
|
|
16
16
|
```ts
|
|
17
|
-
import { StripeProvider } from '@
|
|
17
|
+
import { StripeProvider } from '@strav/stripe'
|
|
18
18
|
|
|
19
19
|
app.use(new StripeProvider())
|
|
20
20
|
```
|
|
@@ -22,7 +22,7 @@ app.use(new StripeProvider())
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
|
-
import { stripe } from '@
|
|
25
|
+
import { stripe } from '@strav/stripe'
|
|
26
26
|
|
|
27
27
|
// Create a customer
|
|
28
28
|
const customer = await stripe.createOrGetCustomer(user)
|
|
@@ -44,7 +44,7 @@ const checkout = await stripe
|
|
|
44
44
|
## Billable Mixin
|
|
45
45
|
|
|
46
46
|
```ts
|
|
47
|
-
import { billable } from '@
|
|
47
|
+
import { billable } from '@strav/stripe'
|
|
48
48
|
|
|
49
49
|
class User extends billable(BaseModel) {
|
|
50
50
|
// adds subscription, invoice, and payment helpers
|
|
@@ -54,7 +54,7 @@ class User extends billable(BaseModel) {
|
|
|
54
54
|
## Webhooks
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
|
-
import { stripeWebhook, onWebhookEvent } from '@
|
|
57
|
+
import { stripeWebhook, onWebhookEvent } from '@strav/stripe'
|
|
58
58
|
|
|
59
59
|
onWebhookEvent('customer.subscription.updated', async (event) => {
|
|
60
60
|
// handle subscription changes
|
package/package.json
CHANGED
package/src/billable.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type Stripe from 'stripe'
|
|
2
|
-
import type { BaseModel } from '@
|
|
3
|
-
import type { NormalizeConstructor } from '@
|
|
4
|
-
import { extractUserId } from '@
|
|
2
|
+
import type { BaseModel } from '@strav/database'
|
|
3
|
+
import type { NormalizeConstructor } from '@strav/kernel'
|
|
4
|
+
import { extractUserId } from '@strav/database'
|
|
5
5
|
import Customer from './customer.ts'
|
|
6
6
|
import Subscription from './subscription.ts'
|
|
7
7
|
import SubscriptionBuilder from './subscription_builder.ts'
|
|
@@ -49,8 +49,8 @@ class BoundCheckoutBuilder extends CheckoutBuilder {
|
|
|
49
49
|
* Mixin that adds billing methods to a BaseModel subclass.
|
|
50
50
|
*
|
|
51
51
|
* @example
|
|
52
|
-
* import { BaseModel } from '@
|
|
53
|
-
* import { billable } from '@
|
|
52
|
+
* import { BaseModel } from '@strav/database'
|
|
53
|
+
* import { billable } from '@strav/stripe'
|
|
54
54
|
*
|
|
55
55
|
* class User extends billable(BaseModel) {
|
|
56
56
|
* declare id: number
|
|
@@ -58,7 +58,7 @@ class BoundCheckoutBuilder extends CheckoutBuilder {
|
|
|
58
58
|
* }
|
|
59
59
|
*
|
|
60
60
|
* // Composable with other mixins:
|
|
61
|
-
* import { compose } from '@
|
|
61
|
+
* import { compose } from '@strav/kernel'
|
|
62
62
|
* class User extends compose(BaseModel, softDeletes, billable) { }
|
|
63
63
|
*
|
|
64
64
|
* const user = await User.find(1)
|
package/src/checkout_builder.ts
CHANGED
package/src/customer.ts
CHANGED
package/src/errors.ts
CHANGED
package/src/helpers.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { CustomerData, SubscriptionData, ReceiptData } from './types.ts'
|
|
|
13
13
|
* Stripe helper object — the primary convenience API.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
|
-
* import { stripe } from '@
|
|
16
|
+
* import { stripe } from '@strav/stripe'
|
|
17
17
|
*
|
|
18
18
|
* // Direct Stripe instance access
|
|
19
19
|
* stripe.stripe.customers.list()
|
package/src/receipt.ts
CHANGED
package/src/stripe_manager.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Stripe from 'stripe'
|
|
2
|
-
import { inject, Configuration, ConfigurationError } from '@
|
|
3
|
-
import { Database, toSnakeCase } from '@
|
|
2
|
+
import { inject, Configuration, ConfigurationError } from '@strav/kernel'
|
|
3
|
+
import { Database, toSnakeCase } from '@strav/database'
|
|
4
4
|
import type { StripeConfig } from './types.ts'
|
|
5
5
|
|
|
6
6
|
@inject
|
package/src/stripe_provider.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ServiceProvider } from '@
|
|
2
|
-
import type { Application } from '@
|
|
1
|
+
import { ServiceProvider } from '@strav/kernel'
|
|
2
|
+
import type { Application } from '@strav/kernel'
|
|
3
3
|
import StripeManager from './stripe_manager.ts'
|
|
4
4
|
|
|
5
5
|
export default class StripeProvider extends ServiceProvider {
|
package/src/subscription.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type Stripe from 'stripe'
|
|
2
|
-
import { extractUserId } from '@
|
|
2
|
+
import { extractUserId } from '@strav/database'
|
|
3
3
|
import StripeManager from './stripe_manager.ts'
|
|
4
4
|
import Customer from './customer.ts'
|
|
5
5
|
import Subscription from './subscription.ts'
|
package/src/webhook.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type Stripe from 'stripe'
|
|
2
|
-
import type { Context, Handler } from '@
|
|
2
|
+
import type { Context, Handler } from '@strav/http'
|
|
3
3
|
import StripeManager from './stripe_manager.ts'
|
|
4
4
|
import Customer from './customer.ts'
|
|
5
5
|
import Subscription from './subscription.ts'
|
|
@@ -14,7 +14,7 @@ const customHandlers = new Map<string, WebhookEventHandler[]>()
|
|
|
14
14
|
* Register a custom handler for a Stripe webhook event type.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
|
-
* import { onWebhookEvent } from '@
|
|
17
|
+
* import { onWebhookEvent } from '@strav/stripe/webhook'
|
|
18
18
|
*
|
|
19
19
|
* onWebhookEvent('invoice.payment_failed', async (event) => {
|
|
20
20
|
* const invoice = event.data.object as Stripe.Invoice
|
|
@@ -35,7 +35,7 @@ export function onWebhookEvent(eventType: string, handler: WebhookEventHandler):
|
|
|
35
35
|
* `onWebhookEvent()`.
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
|
-
* import { stripeWebhook } from '@
|
|
38
|
+
* import { stripeWebhook } from '@strav/stripe/webhook'
|
|
39
39
|
* router.post('/stripe/webhook', stripeWebhook())
|
|
40
40
|
*/
|
|
41
41
|
export function stripeWebhook(): Handler {
|
package/stubs/config/stripe.ts
CHANGED
package/stubs/schemas/receipt.ts
CHANGED