@paykit-sdk/stripe 1.0.1 → 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 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,10 +1,8 @@
1
- import { PayKitProvider } from '@paykit-sdk/core/src/paykit-provider';
2
- import { CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, WebhookEventPayload } from '@paykit-sdk/core/src/resources';
3
- import { WithPaymentProviderConfig } from '@paykit-sdk/core/src/types';
1
+ import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, UpdateSubscriptionParams, Subscription, $ExtWebhookHandlerConfig, WebhookEventPayload } from '@paykit-sdk/core';
4
2
  import Stripe from 'stripe';
5
3
 
6
- interface StripeConfig extends WithPaymentProviderConfig<Stripe.StripeConfig> {
7
- apiVersion?: Stripe.LatestApiVersion;
4
+ interface StripeConfig extends PaykitProviderOptions<Stripe.StripeConfig> {
5
+ apiKey: string;
8
6
  }
9
7
  declare class StripeProvider implements PayKitProvider {
10
8
  private stripe;
@@ -19,18 +17,18 @@ declare class StripeProvider implements PayKitProvider {
19
17
  */
20
18
  createCustomer: (params: CreateCustomerParams) => Promise<Customer>;
21
19
  updateCustomer: (id: string, params: UpdateCustomerParams) => Promise<Customer>;
22
- deleteCustomer: (id: string) => Promise<void>;
20
+ deleteCustomer: (id: string) => Promise<null>;
23
21
  retrieveCustomer: (id: string) => Promise<Customer | null>;
24
22
  /**
25
23
  * Subscription management
26
24
  */
27
- cancelSubscription: (id: string) => Promise<Subscription>;
25
+ cancelSubscription: (id: string) => Promise<null>;
28
26
  updateSubscription: (id: string, params: UpdateSubscriptionParams) => Promise<Subscription>;
29
27
  retrieveSubscription: (id: string) => Promise<Subscription>;
30
28
  /**
31
29
  * Webhook management
32
30
  */
33
- handleWebhook: (payload: string, signature: string, secret: string) => Promise<WebhookEventPayload>;
31
+ handleWebhook: (params: $ExtWebhookHandlerConfig) => Promise<WebhookEventPayload>;
34
32
  }
35
33
 
36
34
  declare const createStripe: (config: StripeConfig) => StripeProvider;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import { PayKitProvider } from '@paykit-sdk/core/src/paykit-provider';
2
- import { CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, WebhookEventPayload } from '@paykit-sdk/core/src/resources';
3
- import { WithPaymentProviderConfig } from '@paykit-sdk/core/src/types';
1
+ import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, UpdateSubscriptionParams, Subscription, $ExtWebhookHandlerConfig, WebhookEventPayload } from '@paykit-sdk/core';
4
2
  import Stripe from 'stripe';
5
3
 
6
- interface StripeConfig extends WithPaymentProviderConfig<Stripe.StripeConfig> {
7
- apiVersion?: Stripe.LatestApiVersion;
4
+ interface StripeConfig extends PaykitProviderOptions<Stripe.StripeConfig> {
5
+ apiKey: string;
8
6
  }
9
7
  declare class StripeProvider implements PayKitProvider {
10
8
  private stripe;
@@ -19,18 +17,18 @@ declare class StripeProvider implements PayKitProvider {
19
17
  */
20
18
  createCustomer: (params: CreateCustomerParams) => Promise<Customer>;
21
19
  updateCustomer: (id: string, params: UpdateCustomerParams) => Promise<Customer>;
22
- deleteCustomer: (id: string) => Promise<void>;
20
+ deleteCustomer: (id: string) => Promise<null>;
23
21
  retrieveCustomer: (id: string) => Promise<Customer | null>;
24
22
  /**
25
23
  * Subscription management
26
24
  */
27
- cancelSubscription: (id: string) => Promise<Subscription>;
25
+ cancelSubscription: (id: string) => Promise<null>;
28
26
  updateSubscription: (id: string, params: UpdateSubscriptionParams) => Promise<Subscription>;
29
27
  retrieveSubscription: (id: string) => Promise<Subscription>;
30
28
  /**
31
29
  * Webhook management
32
30
  */
33
- handleWebhook: (payload: string, signature: string, secret: string) => Promise<WebhookEventPayload>;
31
+ handleWebhook: (params: $ExtWebhookHandlerConfig) => Promise<WebhookEventPayload>;
34
32
  }
35
33
 
36
34
  declare const createStripe: (config: StripeConfig) => StripeProvider;
package/dist/index.js CHANGED
@@ -36,33 +36,56 @@ __export(index_exports, {
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
38
38
  // src/stripe-provider.ts
39
- var import_resources2 = require("@paykit-sdk/core/src/resources");
39
+ var import_core2 = require("@paykit-sdk/core");
40
40
  var import_stripe = __toESM(require("stripe"));
41
41
 
42
42
  // lib/mapper.ts
43
- var import_resources = require("@paykit-sdk/core/src/resources");
43
+ var import_core = require("@paykit-sdk/core");
44
44
  var toPaykitCheckout = (checkout) => {
45
45
  return {
46
46
  id: checkout.id,
47
47
  customer_id: checkout.customer,
48
- mode: checkout.mode,
49
- success_url: checkout.success_url,
50
- cancel_url: checkout.cancel_url,
48
+ session_type: checkout.mode === "subscription" ? "recurring" : "one_time",
49
+ // todo: handle `setup` mode
50
+ payment_url: checkout.url,
51
51
  products: checkout.line_items.data.map((item) => ({ id: item.price.id, quantity: item.quantity })),
52
- url: checkout.url,
53
- ...checkout.metadata && { metadata: checkout.metadata }
52
+ currency: checkout.currency,
53
+ amount: checkout.amount_total,
54
+ metadata: checkout.metadata
54
55
  };
55
56
  };
56
57
  var toPaykitCustomer = (customer) => {
57
- return { id: customer.id, email: customer.email ?? void 0, name: customer.name ?? void 0 };
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}`);
58
71
  };
59
72
  var toPaykitSubscription = (subscription) => {
60
73
  return {
61
74
  id: subscription.id,
62
- customer_id: subscription.customer,
63
- status: (0, import_resources.toPaykitSubscriptionStatus)(subscription.status),
75
+ customer_id: subscription.customer?.toString(),
76
+ status: toPaykitSubscriptionStatus(subscription.status),
64
77
  current_period_start: new Date(subscription.start_date),
65
- 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() ?? ""
66
89
  };
67
90
  };
68
91
 
@@ -73,8 +96,14 @@ var StripeProvider = class {
73
96
  * Checkout management
74
97
  */
75
98
  this.createCheckout = async (params) => {
76
- const { customer_id, price_id, quantity, ...rest } = params;
77
- const checkout = await this.stripe.checkout.sessions.create({ customer: customer_id, line_items: [{ price: price_id, quantity }], ...rest });
99
+ const { customer_id, item_id, metadata, session_type, provider_metadata } = params;
100
+ const checkout = await this.stripe.checkout.sessions.create({
101
+ customer: customer_id,
102
+ metadata,
103
+ line_items: [{ price: item_id }],
104
+ mode: session_type === "one_time" ? "payment" : "subscription",
105
+ ...provider_metadata
106
+ });
78
107
  return toPaykitCheckout(checkout);
79
108
  };
80
109
  this.retrieveCheckout = async (id) => {
@@ -94,6 +123,7 @@ var StripeProvider = class {
94
123
  };
95
124
  this.deleteCustomer = async (id) => {
96
125
  await this.stripe.customers.del(id);
126
+ return null;
97
127
  };
98
128
  this.retrieveCustomer = async (id) => {
99
129
  const customer = await this.stripe.customers.retrieve(id);
@@ -104,8 +134,8 @@ var StripeProvider = class {
104
134
  * Subscription management
105
135
  */
106
136
  this.cancelSubscription = async (id) => {
107
- const subscription = await this.stripe.subscriptions.cancel(id);
108
- return toPaykitSubscription(subscription);
137
+ await this.stripe.subscriptions.cancel(id);
138
+ return null;
109
139
  };
110
140
  this.updateSubscription = async (id, params) => {
111
141
  const subscription = await this.stripe.subscriptions.update(id, { metadata: params.metadata });
@@ -118,35 +148,74 @@ var StripeProvider = class {
118
148
  /**
119
149
  * Webhook management
120
150
  */
121
- this.handleWebhook = async (payload, signature, secret) => {
122
- const event = this.stripe.webhooks.constructEvent(payload, signature, secret);
151
+ this.handleWebhook = async (params) => {
152
+ const { body, headers, webhookSecret } = params;
153
+ const stripeHeaders = (0, import_core2.headersExtractor)(headers, ["x-stripe-signature"]);
154
+ const signature = stripeHeaders[0].value;
155
+ const event = this.stripe.webhooks.constructEvent(body, signature, webhookSecret);
123
156
  if (event.type === "checkout.session.completed") {
124
- const checkout = await this.retrieveCheckout(event.data.object.id);
125
- return (0, import_resources2.toPaykitEvent)({ type: "checkout.created", created: event.created, id: event.id, data: checkout });
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
+ });
126
170
  } else if (event.type === "customer.created") {
127
- const customer = await this.retrieveCustomer(event.data.object.id);
128
- return (0, import_resources2.toPaykitEvent)({ type: "customer.created", created: event.created, id: event.id, data: customer });
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
+ });
129
178
  } else if (event.type === "customer.updated") {
130
- const customer = await this.retrieveCustomer(event.data.object.id);
131
- return (0, import_resources2.toPaykitEvent)({ type: "customer.updated", created: event.created, id: event.id, data: customer });
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
+ });
132
186
  } else if (event.type === "customer.deleted") {
133
- return (0, import_resources2.toPaykitEvent)({ type: "customer.deleted", created: event.created, id: event.id, data: null });
187
+ return (0, import_core2.toPaykitEvent)({ type: "$customerDeleted", created: event.created, id: event.id, data: null });
134
188
  } else if (event.type === "customer.subscription.created") {
135
- const subscription = await this.retrieveSubscription(event.data.object.id);
136
- return (0, import_resources2.toPaykitEvent)({ type: "subscription.created", created: event.created, id: event.id, data: subscription });
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
+ });
137
196
  } else if (event.type === "customer.subscription.updated") {
138
- const subscription = await this.retrieveSubscription(event.data.object.id);
139
- return (0, import_resources2.toPaykitEvent)({ type: "subscription.updated", created: event.created, id: event.id, data: subscription });
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
+ });
140
204
  } else if (event.type === "customer.subscription.deleted") {
141
- const subscription = await this.retrieveSubscription(event.data.object.id);
142
- return (0, import_resources2.toPaykitEvent)({ type: "subscription.canceled", created: event.created, id: event.id, data: subscription });
143
- } else if (event.type === "customer.subscription.paused") {
144
- const subscription = await this.retrieveSubscription(event.data.object.id);
145
- return (0, import_resources2.toPaykitEvent)({ type: "subscription.updated", created: event.created, id: event.id, data: subscription });
205
+ const subscription = event.data.object;
206
+ return (0, import_core2.toPaykitEvent)({
207
+ type: "$subscriptionCancelled",
208
+ created: event.created,
209
+ id: event.id,
210
+ data: toPaykitSubscription(subscription)
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) });
146
215
  }
147
- throw new Error(`Unknown event type: ${event.type}`);
216
+ throw new Error(`Unhandled event type: ${event.type}`);
148
217
  };
149
- const { apiKey, ...rest } = config;
218
+ const { debug, apiKey, ...rest } = config;
150
219
  this.stripe = new import_stripe.default(apiKey, rest);
151
220
  }
152
221
  };
@@ -161,7 +230,7 @@ var stripe = () => {
161
230
  if (!apiKey) {
162
231
  throw new Error("STRIPE_API_KEY is not set");
163
232
  }
164
- return createStripe({ apiKey, apiVersion: "2025-05-28.basil", environment: isDev ? "test" : "live" });
233
+ return createStripe({ apiKey, debug: isDev, apiVersion: "2025-07-30.basil" });
165
234
  };
166
235
  // Annotate the CommonJS export names for ESM import in node:
167
236
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -1,33 +1,58 @@
1
1
  // src/stripe-provider.ts
2
2
  import {
3
- toPaykitEvent
4
- } from "@paykit-sdk/core/src/resources";
3
+ toPaykitEvent,
4
+ headersExtractor,
5
+ stringifyObjectValues as stringifyObjectValues2
6
+ } from "@paykit-sdk/core";
5
7
  import Stripe from "stripe";
6
8
 
7
9
  // lib/mapper.ts
8
- import { toPaykitSubscriptionStatus } from "@paykit-sdk/core/src/resources";
10
+ import { stringifyObjectValues } from "@paykit-sdk/core";
9
11
  var toPaykitCheckout = (checkout) => {
10
12
  return {
11
13
  id: checkout.id,
12
14
  customer_id: checkout.customer,
13
- mode: checkout.mode,
14
- success_url: checkout.success_url,
15
- cancel_url: checkout.cancel_url,
15
+ session_type: checkout.mode === "subscription" ? "recurring" : "one_time",
16
+ // todo: handle `setup` mode
17
+ payment_url: checkout.url,
16
18
  products: checkout.line_items.data.map((item) => ({ id: item.price.id, quantity: item.quantity })),
17
- url: checkout.url,
18
- ...checkout.metadata && { metadata: checkout.metadata }
19
+ currency: checkout.currency,
20
+ amount: checkout.amount_total,
21
+ metadata: checkout.metadata
19
22
  };
20
23
  };
21
24
  var toPaykitCustomer = (customer) => {
22
- return { id: customer.id, email: customer.email ?? void 0, name: customer.name ?? void 0 };
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}`);
23
38
  };
24
39
  var toPaykitSubscription = (subscription) => {
25
40
  return {
26
41
  id: subscription.id,
27
- customer_id: subscription.customer,
42
+ customer_id: subscription.customer?.toString(),
28
43
  status: toPaykitSubscriptionStatus(subscription.status),
29
44
  current_period_start: new Date(subscription.start_date),
30
- 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() ?? ""
31
56
  };
32
57
  };
33
58
 
@@ -38,8 +63,14 @@ var StripeProvider = class {
38
63
  * Checkout management
39
64
  */
40
65
  this.createCheckout = async (params) => {
41
- const { customer_id, price_id, quantity, ...rest } = params;
42
- const checkout = await this.stripe.checkout.sessions.create({ customer: customer_id, line_items: [{ price: price_id, quantity }], ...rest });
66
+ const { customer_id, item_id, metadata, session_type, provider_metadata } = params;
67
+ const checkout = await this.stripe.checkout.sessions.create({
68
+ customer: customer_id,
69
+ metadata,
70
+ line_items: [{ price: item_id }],
71
+ mode: session_type === "one_time" ? "payment" : "subscription",
72
+ ...provider_metadata
73
+ });
43
74
  return toPaykitCheckout(checkout);
44
75
  };
45
76
  this.retrieveCheckout = async (id) => {
@@ -59,6 +90,7 @@ var StripeProvider = class {
59
90
  };
60
91
  this.deleteCustomer = async (id) => {
61
92
  await this.stripe.customers.del(id);
93
+ return null;
62
94
  };
63
95
  this.retrieveCustomer = async (id) => {
64
96
  const customer = await this.stripe.customers.retrieve(id);
@@ -69,8 +101,8 @@ var StripeProvider = class {
69
101
  * Subscription management
70
102
  */
71
103
  this.cancelSubscription = async (id) => {
72
- const subscription = await this.stripe.subscriptions.cancel(id);
73
- return toPaykitSubscription(subscription);
104
+ await this.stripe.subscriptions.cancel(id);
105
+ return null;
74
106
  };
75
107
  this.updateSubscription = async (id, params) => {
76
108
  const subscription = await this.stripe.subscriptions.update(id, { metadata: params.metadata });
@@ -83,35 +115,74 @@ var StripeProvider = class {
83
115
  /**
84
116
  * Webhook management
85
117
  */
86
- this.handleWebhook = async (payload, signature, secret) => {
87
- const event = this.stripe.webhooks.constructEvent(payload, signature, secret);
118
+ this.handleWebhook = async (params) => {
119
+ const { body, headers, webhookSecret } = params;
120
+ const stripeHeaders = headersExtractor(headers, ["x-stripe-signature"]);
121
+ const signature = stripeHeaders[0].value;
122
+ const event = this.stripe.webhooks.constructEvent(body, signature, webhookSecret);
88
123
  if (event.type === "checkout.session.completed") {
89
- const checkout = await this.retrieveCheckout(event.data.object.id);
90
- return toPaykitEvent({ type: "checkout.created", created: event.created, id: event.id, data: checkout });
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
+ });
91
137
  } else if (event.type === "customer.created") {
92
- const customer = await this.retrieveCustomer(event.data.object.id);
93
- return toPaykitEvent({ type: "customer.created", created: event.created, id: event.id, data: customer });
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
+ });
94
145
  } else if (event.type === "customer.updated") {
95
- const customer = await this.retrieveCustomer(event.data.object.id);
96
- return toPaykitEvent({ type: "customer.updated", created: event.created, id: event.id, data: customer });
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
+ });
97
153
  } else if (event.type === "customer.deleted") {
98
- return toPaykitEvent({ type: "customer.deleted", created: event.created, id: event.id, data: null });
154
+ return toPaykitEvent({ type: "$customerDeleted", created: event.created, id: event.id, data: null });
99
155
  } else if (event.type === "customer.subscription.created") {
100
- const subscription = await this.retrieveSubscription(event.data.object.id);
101
- return toPaykitEvent({ type: "subscription.created", created: event.created, id: event.id, data: subscription });
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
+ });
102
163
  } else if (event.type === "customer.subscription.updated") {
103
- const subscription = await this.retrieveSubscription(event.data.object.id);
104
- return toPaykitEvent({ type: "subscription.updated", created: event.created, id: event.id, data: subscription });
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
+ });
105
171
  } else if (event.type === "customer.subscription.deleted") {
106
- const subscription = await this.retrieveSubscription(event.data.object.id);
107
- return toPaykitEvent({ type: "subscription.canceled", created: event.created, id: event.id, data: subscription });
108
- } else if (event.type === "customer.subscription.paused") {
109
- const subscription = await this.retrieveSubscription(event.data.object.id);
110
- return toPaykitEvent({ type: "subscription.updated", created: event.created, id: event.id, data: subscription });
172
+ const subscription = event.data.object;
173
+ return toPaykitEvent({
174
+ type: "$subscriptionCancelled",
175
+ created: event.created,
176
+ id: event.id,
177
+ data: toPaykitSubscription(subscription)
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) });
111
182
  }
112
- throw new Error(`Unknown event type: ${event.type}`);
183
+ throw new Error(`Unhandled event type: ${event.type}`);
113
184
  };
114
- const { apiKey, ...rest } = config;
185
+ const { debug, apiKey, ...rest } = config;
115
186
  this.stripe = new Stripe(apiKey, rest);
116
187
  }
117
188
  };
@@ -126,7 +197,7 @@ var stripe = () => {
126
197
  if (!apiKey) {
127
198
  throw new Error("STRIPE_API_KEY is not set");
128
199
  }
129
- return createStripe({ apiKey, apiVersion: "2025-05-28.basil", environment: isDev ? "test" : "live" });
200
+ return createStripe({ apiKey, debug: isDev, apiVersion: "2025-07-30.basil" });
130
201
  };
131
202
  export {
132
203
  createStripe,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paykit-sdk/stripe",
3
- "version": "1.0.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",
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "scripts": {
12
12
  "build": "tsup src/index.ts --format cjs,esm --dts",
13
- "prepublishOnly": "npm run build"
13
+ "prepublishOnly": "rm -rf dist && npm run build"
14
14
  },
15
15
  "keywords": [
16
16
  "stripe",
@@ -24,7 +24,7 @@
24
24
  "stripe": "^18.2.1"
25
25
  },
26
26
  "peerDependencies": {
27
- "@paykit-sdk/core": "^1.0.0"
27
+ "@paykit-sdk/core": "^1.1.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "tsup": "^8.0.0",