@paykit-sdk/stripe 1.0.1-alpha.2 → 1.0.1-alpha.4
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/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +12 -13
- package/dist/index.mjs +4 -4
- package/package.json +7 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { PayKitProvider } from '@paykit-sdk/core
|
|
2
|
-
import { CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, WebhookProviderPayload, WebhookEventPayload } from '@paykit-sdk/core/src/resources';
|
|
3
|
-
import { PaykitProviderOptions } from '@paykit-sdk/core/src/types';
|
|
1
|
+
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, WebhookProviderPayload, WebhookEventPayload } from '@paykit-sdk/core';
|
|
4
2
|
import Stripe from 'stripe';
|
|
5
3
|
|
|
6
4
|
interface StripeConfig extends PaykitProviderOptions<Stripe.StripeConfig> {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { PayKitProvider } from '@paykit-sdk/core
|
|
2
|
-
import { CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, WebhookProviderPayload, WebhookEventPayload } from '@paykit-sdk/core/src/resources';
|
|
3
|
-
import { PaykitProviderOptions } from '@paykit-sdk/core/src/types';
|
|
1
|
+
import { PaykitProviderOptions, PayKitProvider, CreateCheckoutParams, Checkout, CreateCustomerParams, Customer, UpdateCustomerParams, Subscription, UpdateSubscriptionParams, WebhookProviderPayload, WebhookEventPayload } from '@paykit-sdk/core';
|
|
4
2
|
import Stripe from 'stripe';
|
|
5
3
|
|
|
6
4
|
interface StripeConfig extends PaykitProviderOptions<Stripe.StripeConfig> {
|
package/dist/index.js
CHANGED
|
@@ -36,12 +36,11 @@ __export(index_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
38
38
|
// src/stripe-provider.ts
|
|
39
|
-
var
|
|
40
|
-
var import_webhook = require("@paykit-sdk/core/src/tools/webhook");
|
|
39
|
+
var import_core2 = require("@paykit-sdk/core");
|
|
41
40
|
var import_stripe = __toESM(require("stripe"));
|
|
42
41
|
|
|
43
42
|
// lib/mapper.ts
|
|
44
|
-
var
|
|
43
|
+
var import_core = require("@paykit-sdk/core");
|
|
45
44
|
var toPaykitCheckout = (checkout) => {
|
|
46
45
|
return {
|
|
47
46
|
id: checkout.id,
|
|
@@ -62,7 +61,7 @@ var toPaykitSubscription = (subscription) => {
|
|
|
62
61
|
return {
|
|
63
62
|
id: subscription.id,
|
|
64
63
|
customer_id: subscription.customer,
|
|
65
|
-
status: (0,
|
|
64
|
+
status: (0, import_core.toPaykitSubscriptionStatus)(subscription.status),
|
|
66
65
|
current_period_start: new Date(subscription.start_date),
|
|
67
66
|
current_period_end: new Date(subscription.cancel_at)
|
|
68
67
|
};
|
|
@@ -128,36 +127,36 @@ var StripeProvider = class {
|
|
|
128
127
|
*/
|
|
129
128
|
this.handleWebhook = async (params) => {
|
|
130
129
|
const { body, headers, webhookSecret } = params;
|
|
131
|
-
const stripeHeaders = (0,
|
|
130
|
+
const stripeHeaders = (0, import_core2.headersExtractor)(headers, ["x-stripe-signature"]);
|
|
132
131
|
const signature = stripeHeaders[0].value;
|
|
133
132
|
const event = this.stripe.webhooks.constructEvent(body, signature, webhookSecret);
|
|
134
133
|
if (event.type === "checkout.session.completed") {
|
|
135
134
|
const checkout = await this.retrieveCheckout(event.data.object.id);
|
|
136
|
-
return (0,
|
|
135
|
+
return (0, import_core2.toPaykitEvent)({ type: "checkout.created", created: event.created, id: event.id, data: checkout });
|
|
137
136
|
} else if (event.type === "customer.created") {
|
|
138
137
|
const customer = await this.createCustomer({ email: event.data.object.email, name: event.data.object.name ?? void 0 });
|
|
139
|
-
return (0,
|
|
138
|
+
return (0, import_core2.toPaykitEvent)({ type: "customer.created", created: event.created, id: event.id, data: customer });
|
|
140
139
|
} else if (event.type === "customer.updated") {
|
|
141
140
|
const customer = await this.updateCustomer(event.data.object.id, {
|
|
142
141
|
email: event.data.object.email,
|
|
143
142
|
name: event.data.object.name ?? void 0
|
|
144
143
|
});
|
|
145
|
-
return (0,
|
|
144
|
+
return (0, import_core2.toPaykitEvent)({ type: "customer.updated", created: event.created, id: event.id, data: customer });
|
|
146
145
|
} else if (event.type === "customer.deleted") {
|
|
147
146
|
await this.deleteCustomer(event.data.object.id);
|
|
148
|
-
return (0,
|
|
147
|
+
return (0, import_core2.toPaykitEvent)({ type: "customer.deleted", created: event.created, id: event.id, data: null });
|
|
149
148
|
} else if (event.type === "customer.subscription.created") {
|
|
150
149
|
const subscription = await this.retrieveSubscription(event.data.object.id);
|
|
151
|
-
return (0,
|
|
150
|
+
return (0, import_core2.toPaykitEvent)({ type: "subscription.created", created: event.created, id: event.id, data: subscription });
|
|
152
151
|
} else if (event.type === "customer.subscription.updated") {
|
|
153
152
|
const subscription = await this.retrieveSubscription(event.data.object.id);
|
|
154
|
-
return (0,
|
|
153
|
+
return (0, import_core2.toPaykitEvent)({ type: "subscription.updated", created: event.created, id: event.id, data: subscription });
|
|
155
154
|
} else if (event.type === "customer.subscription.deleted") {
|
|
156
155
|
const subscription = await this.retrieveSubscription(event.data.object.id);
|
|
157
|
-
return (0,
|
|
156
|
+
return (0, import_core2.toPaykitEvent)({ type: "subscription.canceled", created: event.created, id: event.id, data: subscription });
|
|
158
157
|
} else if (event.type === "customer.subscription.paused") {
|
|
159
158
|
const subscription = await this.retrieveSubscription(event.data.object.id);
|
|
160
|
-
return (0,
|
|
159
|
+
return (0, import_core2.toPaykitEvent)({ type: "subscription.updated", created: event.created, id: event.id, data: subscription });
|
|
161
160
|
}
|
|
162
161
|
throw new Error(`Unknown event type: ${event.type}`);
|
|
163
162
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/stripe-provider.ts
|
|
2
2
|
import {
|
|
3
|
-
toPaykitEvent
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
toPaykitEvent,
|
|
4
|
+
headersExtractor
|
|
5
|
+
} from "@paykit-sdk/core";
|
|
6
6
|
import Stripe from "stripe";
|
|
7
7
|
|
|
8
8
|
// lib/mapper.ts
|
|
9
|
-
import { toPaykitSubscriptionStatus } from "@paykit-sdk/core
|
|
9
|
+
import { toPaykitSubscriptionStatus } from "@paykit-sdk/core";
|
|
10
10
|
var toPaykitCheckout = (checkout) => {
|
|
11
11
|
return {
|
|
12
12
|
id: checkout.id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/stripe",
|
|
3
|
-
"version": "1.0.1-alpha.
|
|
3
|
+
"version": "1.0.1-alpha.4",
|
|
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": "npm run build"
|
|
14
|
+
},
|
|
11
15
|
"keywords": [
|
|
12
16
|
"stripe",
|
|
13
17
|
"paykit",
|
|
@@ -25,7 +29,7 @@
|
|
|
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
|
+
}
|