@paykit-sdk/stripe 1.1.0 → 1.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 +71 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +78 -32
- package/dist/index.mjs +80 -33
- package/package.json +8 -7
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @paykit-sdk/stripe
|
|
2
|
+
|
|
3
|
+
Stripe provider for PayKit
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { PayKit } from '@paykit-sdk/core';
|
|
9
|
+
import { stripe, createStripe } from '@paykit-sdk/stripe';
|
|
10
|
+
|
|
11
|
+
// Method 1: Using environment variables
|
|
12
|
+
const provider = stripe(); // Ensure STRIPE_API_KEY environment variable is set
|
|
13
|
+
|
|
14
|
+
// Method 2: Direct configuration
|
|
15
|
+
const provider = createStripe({
|
|
16
|
+
apiKey: process.env.STRIPE_API_KEY,
|
|
17
|
+
apiVersion: '2024-12-18.acacia',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const paykit = new PayKit(provider);
|
|
21
|
+
|
|
22
|
+
// Create checkout
|
|
23
|
+
const checkout = await paykit.checkouts.create({
|
|
24
|
+
customer_id: 'cus_123',
|
|
25
|
+
item_id: 'price_123',
|
|
26
|
+
session_type: 'one_time',
|
|
27
|
+
metadata: { plan: 'pro' },
|
|
28
|
+
provider_metadata: {
|
|
29
|
+
ui_mode: 'hosted',
|
|
30
|
+
success_url: 'https://your-app.com/success',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Handle webhooks
|
|
35
|
+
paykit.webhooks
|
|
36
|
+
.setup({ webhookSecret: process.env.STRIPE_WEBHOOK_SECRET })
|
|
37
|
+
.on('$checkoutCreated', async event => {
|
|
38
|
+
console.log('Checkout created:', event.data);
|
|
39
|
+
})
|
|
40
|
+
.on('$invoicePaid', async event => {
|
|
41
|
+
console.log('Payment received:', event.data);
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Subscription Management
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// Update subscription
|
|
49
|
+
await paykit.subscriptions.update('sub_123', {
|
|
50
|
+
metadata: { plan: 'enterprise' },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Cancel subscription
|
|
54
|
+
await paykit.subscriptions.cancel('sub_123');
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Environment Variables
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
STRIPE_SECRET_KEY=sk_test_...
|
|
61
|
+
STRIPE_WEBHOOK_SECRET=whsec_...
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Support
|
|
65
|
+
|
|
66
|
+
- [Stripe Documentation](https://stripe.com/docs)
|
|
67
|
+
- [PayKit Issues](https://github.com/devodii/paykit/issues)
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
ISC
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams,
|
|
1
|
+
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, UpdateSubscriptionParams, Subscription, $ExtWebhookHandlerConfig, WebhookEventPayload } from '@paykit-sdk/core';
|
|
2
2
|
import Stripe from 'stripe';
|
|
3
3
|
|
|
4
4
|
interface StripeConfig extends PaykitProviderOptions<Stripe.StripeConfig> {
|
|
@@ -17,12 +17,12 @@ declare class StripeProvider implements PayKitProvider {
|
|
|
17
17
|
*/
|
|
18
18
|
createCustomer: (params: CreateCustomerParams) => Promise<Customer>;
|
|
19
19
|
updateCustomer: (id: string, params: UpdateCustomerParams) => Promise<Customer>;
|
|
20
|
-
deleteCustomer: (id: string) => Promise<
|
|
20
|
+
deleteCustomer: (id: string) => Promise<null>;
|
|
21
21
|
retrieveCustomer: (id: string) => Promise<Customer | null>;
|
|
22
22
|
/**
|
|
23
23
|
* Subscription management
|
|
24
24
|
*/
|
|
25
|
-
cancelSubscription: (id: string) => Promise<
|
|
25
|
+
cancelSubscription: (id: string) => Promise<null>;
|
|
26
26
|
updateSubscription: (id: string, params: UpdateSubscriptionParams) => Promise<Subscription>;
|
|
27
27
|
retrieveSubscription: (id: string) => Promise<Subscription>;
|
|
28
28
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams,
|
|
1
|
+
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, UpdateSubscriptionParams, Subscription, $ExtWebhookHandlerConfig, WebhookEventPayload } from '@paykit-sdk/core';
|
|
2
2
|
import Stripe from 'stripe';
|
|
3
3
|
|
|
4
4
|
interface StripeConfig extends PaykitProviderOptions<Stripe.StripeConfig> {
|
|
@@ -17,12 +17,12 @@ declare class StripeProvider implements PayKitProvider {
|
|
|
17
17
|
*/
|
|
18
18
|
createCustomer: (params: CreateCustomerParams) => Promise<Customer>;
|
|
19
19
|
updateCustomer: (id: string, params: UpdateCustomerParams) => Promise<Customer>;
|
|
20
|
-
deleteCustomer: (id: string) => Promise<
|
|
20
|
+
deleteCustomer: (id: string) => Promise<null>;
|
|
21
21
|
retrieveCustomer: (id: string) => Promise<Customer | null>;
|
|
22
22
|
/**
|
|
23
23
|
* Subscription management
|
|
24
24
|
*/
|
|
25
|
-
cancelSubscription: (id: string) => Promise<
|
|
25
|
+
cancelSubscription: (id: string) => Promise<null>;
|
|
26
26
|
updateSubscription: (id: string, params: UpdateSubscriptionParams) => Promise<Subscription>;
|
|
27
27
|
retrieveSubscription: (id: string) => Promise<Subscription>;
|
|
28
28
|
/**
|
package/dist/index.js
CHANGED
|
@@ -55,15 +55,37 @@ var toPaykitCheckout = (checkout) => {
|
|
|
55
55
|
};
|
|
56
56
|
};
|
|
57
57
|
var toPaykitCustomer = (customer) => {
|
|
58
|
-
return {
|
|
58
|
+
return {
|
|
59
|
+
id: customer.id,
|
|
60
|
+
email: customer.email ?? void 0,
|
|
61
|
+
name: customer.name ?? void 0,
|
|
62
|
+
metadata: (0, import_core.stringifyObjectValues)(customer.metadata ?? {})
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
var toPaykitSubscriptionStatus = (status) => {
|
|
66
|
+
if (["active", "trialing"].includes(status)) return "active";
|
|
67
|
+
if (["incomplete_expired", "incomplete", "past_due"].includes(status)) return "past_due";
|
|
68
|
+
if (["canceled"].includes(status)) return "canceled";
|
|
69
|
+
if (["expired"].includes(status)) return "expired";
|
|
70
|
+
throw new Error(`Unknown status: ${status}`);
|
|
59
71
|
};
|
|
60
72
|
var toPaykitSubscription = (subscription) => {
|
|
61
73
|
return {
|
|
62
74
|
id: subscription.id,
|
|
63
|
-
customer_id: subscription.customer,
|
|
64
|
-
status:
|
|
75
|
+
customer_id: subscription.customer?.toString(),
|
|
76
|
+
status: toPaykitSubscriptionStatus(subscription.status),
|
|
65
77
|
current_period_start: new Date(subscription.start_date),
|
|
66
|
-
current_period_end: new Date(subscription.cancel_at)
|
|
78
|
+
current_period_end: new Date(subscription.cancel_at),
|
|
79
|
+
metadata: (0, import_core.stringifyObjectValues)(subscription.metadata ?? {})
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var toPaykitInvoice = (invoice) => {
|
|
83
|
+
return {
|
|
84
|
+
id: invoice.id,
|
|
85
|
+
amount: invoice.amount_paid,
|
|
86
|
+
currency: invoice.currency,
|
|
87
|
+
metadata: (0, import_core.stringifyObjectValues)(invoice.metadata ?? {}),
|
|
88
|
+
customer_id: invoice.customer?.toString() ?? ""
|
|
67
89
|
};
|
|
68
90
|
};
|
|
69
91
|
|
|
@@ -101,6 +123,7 @@ var StripeProvider = class {
|
|
|
101
123
|
};
|
|
102
124
|
this.deleteCustomer = async (id) => {
|
|
103
125
|
await this.stripe.customers.del(id);
|
|
126
|
+
return null;
|
|
104
127
|
};
|
|
105
128
|
this.retrieveCustomer = async (id) => {
|
|
106
129
|
const customer = await this.stripe.customers.retrieve(id);
|
|
@@ -111,8 +134,8 @@ var StripeProvider = class {
|
|
|
111
134
|
* Subscription management
|
|
112
135
|
*/
|
|
113
136
|
this.cancelSubscription = async (id) => {
|
|
114
|
-
|
|
115
|
-
return
|
|
137
|
+
await this.stripe.subscriptions.cancel(id);
|
|
138
|
+
return null;
|
|
116
139
|
};
|
|
117
140
|
this.updateSubscription = async (id, params) => {
|
|
118
141
|
const subscription = await this.stripe.subscriptions.update(id, { metadata: params.metadata });
|
|
@@ -131,43 +154,66 @@ var StripeProvider = class {
|
|
|
131
154
|
const signature = stripeHeaders[0].value;
|
|
132
155
|
const event = this.stripe.webhooks.constructEvent(body, signature, webhookSecret);
|
|
133
156
|
if (event.type === "checkout.session.completed") {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
157
|
+
const data = event.data.object;
|
|
158
|
+
return (0, import_core2.toPaykitEvent)({
|
|
159
|
+
type: "$invoicePaid",
|
|
160
|
+
created: event.created,
|
|
161
|
+
id: event.id,
|
|
162
|
+
data: {
|
|
163
|
+
id: data.id,
|
|
164
|
+
amount: data.amount_total ?? 0,
|
|
165
|
+
currency: data.currency ?? "",
|
|
166
|
+
metadata: (0, import_core2.stringifyObjectValues)(data.metadata ?? {}),
|
|
167
|
+
customer_id: data.customer?.toString() ?? ""
|
|
168
|
+
}
|
|
169
|
+
});
|
|
137
170
|
} else if (event.type === "customer.created") {
|
|
138
|
-
const customer =
|
|
139
|
-
return (0, import_core2.toPaykitEvent)({
|
|
171
|
+
const customer = event.data.object;
|
|
172
|
+
return (0, import_core2.toPaykitEvent)({
|
|
173
|
+
type: "$customerCreated",
|
|
174
|
+
created: event.created,
|
|
175
|
+
id: event.id,
|
|
176
|
+
data: toPaykitCustomer(customer)
|
|
177
|
+
});
|
|
140
178
|
} else if (event.type === "customer.updated") {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
179
|
+
const customer = event.data.object;
|
|
180
|
+
return (0, import_core2.toPaykitEvent)({
|
|
181
|
+
type: "$customerUpdated",
|
|
182
|
+
created: event.created,
|
|
183
|
+
id: event.id,
|
|
184
|
+
data: toPaykitCustomer(customer)
|
|
185
|
+
});
|
|
144
186
|
} else if (event.type === "customer.deleted") {
|
|
145
|
-
await this.deleteCustomer(event.data.object.id);
|
|
146
187
|
return (0, import_core2.toPaykitEvent)({ type: "$customerDeleted", created: event.created, id: event.id, data: null });
|
|
147
188
|
} else if (event.type === "customer.subscription.created") {
|
|
148
|
-
const subscription =
|
|
149
|
-
return (0, import_core2.toPaykitEvent)({
|
|
189
|
+
const subscription = event.data.object;
|
|
190
|
+
return (0, import_core2.toPaykitEvent)({
|
|
191
|
+
type: "$subscriptionCreated",
|
|
192
|
+
created: event.created,
|
|
193
|
+
id: event.id,
|
|
194
|
+
data: toPaykitSubscription(subscription)
|
|
195
|
+
});
|
|
150
196
|
} else if (event.type === "customer.subscription.updated") {
|
|
151
|
-
const subscription =
|
|
152
|
-
return (0, import_core2.toPaykitEvent)({
|
|
197
|
+
const subscription = event.data.object;
|
|
198
|
+
return (0, import_core2.toPaykitEvent)({
|
|
199
|
+
type: "$subscriptionUpdated",
|
|
200
|
+
created: event.created,
|
|
201
|
+
id: event.id,
|
|
202
|
+
data: toPaykitSubscription(subscription)
|
|
203
|
+
});
|
|
153
204
|
} else if (event.type === "customer.subscription.deleted") {
|
|
154
|
-
const subscription =
|
|
155
|
-
return (0, import_core2.toPaykitEvent)({ type: "$subscriptionCanceled", created: event.created, id: event.id, data: subscription });
|
|
156
|
-
} else if (event.type === "customer.subscription.paused") {
|
|
157
|
-
const subscription = await this.retrieveSubscription(event.data.object.id);
|
|
158
|
-
return (0, import_core2.toPaykitEvent)({ type: "$subscriptionUpdated", created: event.created, id: event.id, data: subscription });
|
|
159
|
-
} else if (event.type == "invoice.payment_succeeded") {
|
|
160
|
-
const checkoutId = event.data.object.metadata?.checkoutId;
|
|
161
|
-
if (!checkoutId) throw new Error("Checkout ID not found in invoice metadata");
|
|
162
|
-
const checkout = await this.retrieveCheckout(checkoutId);
|
|
205
|
+
const subscription = event.data.object;
|
|
163
206
|
return (0, import_core2.toPaykitEvent)({
|
|
164
|
-
type: "$
|
|
207
|
+
type: "$subscriptionCancelled",
|
|
165
208
|
created: event.created,
|
|
166
209
|
id: event.id,
|
|
167
|
-
data:
|
|
210
|
+
data: toPaykitSubscription(subscription)
|
|
168
211
|
});
|
|
212
|
+
} else if (event.type == "invoice.paid") {
|
|
213
|
+
const invoice = event.data.object;
|
|
214
|
+
return (0, import_core2.toPaykitEvent)({ type: "$invoicePaid", created: event.created, id: event.id, data: toPaykitInvoice(invoice) });
|
|
169
215
|
}
|
|
170
|
-
throw new Error(`
|
|
216
|
+
throw new Error(`Unhandled event type: ${event.type}`);
|
|
171
217
|
};
|
|
172
218
|
const { debug, apiKey, ...rest } = config;
|
|
173
219
|
this.stripe = new import_stripe.default(apiKey, rest);
|
|
@@ -184,7 +230,7 @@ var stripe = () => {
|
|
|
184
230
|
if (!apiKey) {
|
|
185
231
|
throw new Error("STRIPE_API_KEY is not set");
|
|
186
232
|
}
|
|
187
|
-
return createStripe({ apiKey, debug: isDev, apiVersion: "2025-
|
|
233
|
+
return createStripe({ apiKey, debug: isDev, apiVersion: "2025-07-30.basil" });
|
|
188
234
|
};
|
|
189
235
|
// Annotate the CommonJS export names for ESM import in node:
|
|
190
236
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// src/stripe-provider.ts
|
|
2
2
|
import {
|
|
3
3
|
toPaykitEvent,
|
|
4
|
-
headersExtractor
|
|
4
|
+
headersExtractor,
|
|
5
|
+
stringifyObjectValues as stringifyObjectValues2
|
|
5
6
|
} from "@paykit-sdk/core";
|
|
6
7
|
import Stripe from "stripe";
|
|
7
8
|
|
|
8
9
|
// lib/mapper.ts
|
|
9
|
-
import {
|
|
10
|
+
import { stringifyObjectValues } from "@paykit-sdk/core";
|
|
10
11
|
var toPaykitCheckout = (checkout) => {
|
|
11
12
|
return {
|
|
12
13
|
id: checkout.id,
|
|
@@ -21,15 +22,37 @@ var toPaykitCheckout = (checkout) => {
|
|
|
21
22
|
};
|
|
22
23
|
};
|
|
23
24
|
var toPaykitCustomer = (customer) => {
|
|
24
|
-
return {
|
|
25
|
+
return {
|
|
26
|
+
id: customer.id,
|
|
27
|
+
email: customer.email ?? void 0,
|
|
28
|
+
name: customer.name ?? void 0,
|
|
29
|
+
metadata: stringifyObjectValues(customer.metadata ?? {})
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
var toPaykitSubscriptionStatus = (status) => {
|
|
33
|
+
if (["active", "trialing"].includes(status)) return "active";
|
|
34
|
+
if (["incomplete_expired", "incomplete", "past_due"].includes(status)) return "past_due";
|
|
35
|
+
if (["canceled"].includes(status)) return "canceled";
|
|
36
|
+
if (["expired"].includes(status)) return "expired";
|
|
37
|
+
throw new Error(`Unknown status: ${status}`);
|
|
25
38
|
};
|
|
26
39
|
var toPaykitSubscription = (subscription) => {
|
|
27
40
|
return {
|
|
28
41
|
id: subscription.id,
|
|
29
|
-
customer_id: subscription.customer,
|
|
42
|
+
customer_id: subscription.customer?.toString(),
|
|
30
43
|
status: toPaykitSubscriptionStatus(subscription.status),
|
|
31
44
|
current_period_start: new Date(subscription.start_date),
|
|
32
|
-
current_period_end: new Date(subscription.cancel_at)
|
|
45
|
+
current_period_end: new Date(subscription.cancel_at),
|
|
46
|
+
metadata: stringifyObjectValues(subscription.metadata ?? {})
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
var toPaykitInvoice = (invoice) => {
|
|
50
|
+
return {
|
|
51
|
+
id: invoice.id,
|
|
52
|
+
amount: invoice.amount_paid,
|
|
53
|
+
currency: invoice.currency,
|
|
54
|
+
metadata: stringifyObjectValues(invoice.metadata ?? {}),
|
|
55
|
+
customer_id: invoice.customer?.toString() ?? ""
|
|
33
56
|
};
|
|
34
57
|
};
|
|
35
58
|
|
|
@@ -67,6 +90,7 @@ var StripeProvider = class {
|
|
|
67
90
|
};
|
|
68
91
|
this.deleteCustomer = async (id) => {
|
|
69
92
|
await this.stripe.customers.del(id);
|
|
93
|
+
return null;
|
|
70
94
|
};
|
|
71
95
|
this.retrieveCustomer = async (id) => {
|
|
72
96
|
const customer = await this.stripe.customers.retrieve(id);
|
|
@@ -77,8 +101,8 @@ var StripeProvider = class {
|
|
|
77
101
|
* Subscription management
|
|
78
102
|
*/
|
|
79
103
|
this.cancelSubscription = async (id) => {
|
|
80
|
-
|
|
81
|
-
return
|
|
104
|
+
await this.stripe.subscriptions.cancel(id);
|
|
105
|
+
return null;
|
|
82
106
|
};
|
|
83
107
|
this.updateSubscription = async (id, params) => {
|
|
84
108
|
const subscription = await this.stripe.subscriptions.update(id, { metadata: params.metadata });
|
|
@@ -97,43 +121,66 @@ var StripeProvider = class {
|
|
|
97
121
|
const signature = stripeHeaders[0].value;
|
|
98
122
|
const event = this.stripe.webhooks.constructEvent(body, signature, webhookSecret);
|
|
99
123
|
if (event.type === "checkout.session.completed") {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
124
|
+
const data = event.data.object;
|
|
125
|
+
return toPaykitEvent({
|
|
126
|
+
type: "$invoicePaid",
|
|
127
|
+
created: event.created,
|
|
128
|
+
id: event.id,
|
|
129
|
+
data: {
|
|
130
|
+
id: data.id,
|
|
131
|
+
amount: data.amount_total ?? 0,
|
|
132
|
+
currency: data.currency ?? "",
|
|
133
|
+
metadata: stringifyObjectValues2(data.metadata ?? {}),
|
|
134
|
+
customer_id: data.customer?.toString() ?? ""
|
|
135
|
+
}
|
|
136
|
+
});
|
|
103
137
|
} else if (event.type === "customer.created") {
|
|
104
|
-
const customer =
|
|
105
|
-
return toPaykitEvent({
|
|
138
|
+
const customer = event.data.object;
|
|
139
|
+
return toPaykitEvent({
|
|
140
|
+
type: "$customerCreated",
|
|
141
|
+
created: event.created,
|
|
142
|
+
id: event.id,
|
|
143
|
+
data: toPaykitCustomer(customer)
|
|
144
|
+
});
|
|
106
145
|
} else if (event.type === "customer.updated") {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
146
|
+
const customer = event.data.object;
|
|
147
|
+
return toPaykitEvent({
|
|
148
|
+
type: "$customerUpdated",
|
|
149
|
+
created: event.created,
|
|
150
|
+
id: event.id,
|
|
151
|
+
data: toPaykitCustomer(customer)
|
|
152
|
+
});
|
|
110
153
|
} else if (event.type === "customer.deleted") {
|
|
111
|
-
await this.deleteCustomer(event.data.object.id);
|
|
112
154
|
return toPaykitEvent({ type: "$customerDeleted", created: event.created, id: event.id, data: null });
|
|
113
155
|
} else if (event.type === "customer.subscription.created") {
|
|
114
|
-
const subscription =
|
|
115
|
-
return toPaykitEvent({
|
|
156
|
+
const subscription = event.data.object;
|
|
157
|
+
return toPaykitEvent({
|
|
158
|
+
type: "$subscriptionCreated",
|
|
159
|
+
created: event.created,
|
|
160
|
+
id: event.id,
|
|
161
|
+
data: toPaykitSubscription(subscription)
|
|
162
|
+
});
|
|
116
163
|
} else if (event.type === "customer.subscription.updated") {
|
|
117
|
-
const subscription =
|
|
118
|
-
return toPaykitEvent({
|
|
164
|
+
const subscription = event.data.object;
|
|
165
|
+
return toPaykitEvent({
|
|
166
|
+
type: "$subscriptionUpdated",
|
|
167
|
+
created: event.created,
|
|
168
|
+
id: event.id,
|
|
169
|
+
data: toPaykitSubscription(subscription)
|
|
170
|
+
});
|
|
119
171
|
} else if (event.type === "customer.subscription.deleted") {
|
|
120
|
-
const subscription =
|
|
121
|
-
return toPaykitEvent({ type: "$subscriptionCanceled", created: event.created, id: event.id, data: subscription });
|
|
122
|
-
} else if (event.type === "customer.subscription.paused") {
|
|
123
|
-
const subscription = await this.retrieveSubscription(event.data.object.id);
|
|
124
|
-
return toPaykitEvent({ type: "$subscriptionUpdated", created: event.created, id: event.id, data: subscription });
|
|
125
|
-
} else if (event.type == "invoice.payment_succeeded") {
|
|
126
|
-
const checkoutId = event.data.object.metadata?.checkoutId;
|
|
127
|
-
if (!checkoutId) throw new Error("Checkout ID not found in invoice metadata");
|
|
128
|
-
const checkout = await this.retrieveCheckout(checkoutId);
|
|
172
|
+
const subscription = event.data.object;
|
|
129
173
|
return toPaykitEvent({
|
|
130
|
-
type: "$
|
|
174
|
+
type: "$subscriptionCancelled",
|
|
131
175
|
created: event.created,
|
|
132
176
|
id: event.id,
|
|
133
|
-
data:
|
|
177
|
+
data: toPaykitSubscription(subscription)
|
|
134
178
|
});
|
|
179
|
+
} else if (event.type == "invoice.paid") {
|
|
180
|
+
const invoice = event.data.object;
|
|
181
|
+
return toPaykitEvent({ type: "$invoicePaid", created: event.created, id: event.id, data: toPaykitInvoice(invoice) });
|
|
135
182
|
}
|
|
136
|
-
throw new Error(`
|
|
183
|
+
throw new Error(`Unhandled event type: ${event.type}`);
|
|
137
184
|
};
|
|
138
185
|
const { debug, apiKey, ...rest } = config;
|
|
139
186
|
this.stripe = new Stripe(apiKey, rest);
|
|
@@ -150,7 +197,7 @@ var stripe = () => {
|
|
|
150
197
|
if (!apiKey) {
|
|
151
198
|
throw new Error("STRIPE_API_KEY is not set");
|
|
152
199
|
}
|
|
153
|
-
return createStripe({ apiKey, debug: isDev, apiVersion: "2025-
|
|
200
|
+
return createStripe({ apiKey, debug: isDev, apiVersion: "2025-07-30.basil" });
|
|
154
201
|
};
|
|
155
202
|
export {
|
|
156
203
|
createStripe,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/stripe",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Stripe provider for PayKit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
13
|
+
"prepublishOnly": "rm -rf dist && npm run build"
|
|
14
|
+
},
|
|
11
15
|
"keywords": [
|
|
12
16
|
"stripe",
|
|
13
17
|
"paykit",
|
|
@@ -20,12 +24,12 @@
|
|
|
20
24
|
"stripe": "^18.2.1"
|
|
21
25
|
},
|
|
22
26
|
"peerDependencies": {
|
|
23
|
-
"@paykit-sdk/core": "^1.1.
|
|
27
|
+
"@paykit-sdk/core": "^1.1.1"
|
|
24
28
|
},
|
|
25
29
|
"devDependencies": {
|
|
26
30
|
"tsup": "^8.0.0",
|
|
27
31
|
"typescript": "^5.0.0",
|
|
28
|
-
"@paykit-sdk/core": "
|
|
32
|
+
"@paykit-sdk/core": "workspace:*"
|
|
29
33
|
},
|
|
30
34
|
"publishConfig": {
|
|
31
35
|
"access": "public"
|
|
@@ -36,8 +40,5 @@
|
|
|
36
40
|
},
|
|
37
41
|
"bugs": {
|
|
38
42
|
"url": "https://github.com/devodii/paykit/issues"
|
|
39
|
-
},
|
|
40
|
-
"scripts": {
|
|
41
|
-
"build": "tsup src/index.ts --format cjs,esm --dts"
|
|
42
43
|
}
|
|
43
|
-
}
|
|
44
|
+
}
|