@paykit-sdk/polar 1.1.5 → 1.1.7
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.js +66 -20
- package/dist/index.mjs +66 -20
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -61,7 +61,7 @@ var toPaykitSubscription = (subscription) => {
|
|
|
61
61
|
status: toPaykitSubscriptionStatus(subscription.status),
|
|
62
62
|
current_period_start: new Date(subscription.currentPeriodStart),
|
|
63
63
|
current_period_end: new Date(subscription.currentPeriodEnd),
|
|
64
|
-
metadata: (0, import_core.stringifyObjectValues)({ ...subscription.metadata ?? {}, customFieldData: subscription.customFieldData })
|
|
64
|
+
metadata: (0, import_core.stringifyObjectValues)({ ...subscription.metadata ?? {}, $customFieldData: subscription.customFieldData })
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
67
|
var toPaykitInvoice = (invoice) => {
|
|
@@ -69,7 +69,7 @@ var toPaykitInvoice = (invoice) => {
|
|
|
69
69
|
id: invoice.id,
|
|
70
70
|
amount: invoice.totalAmount,
|
|
71
71
|
currency: invoice.currency,
|
|
72
|
-
metadata: (0, import_core.stringifyObjectValues)(invoice.metadata ?? {}),
|
|
72
|
+
metadata: (0, import_core.stringifyObjectValues)({ ...invoice.metadata ?? {}, $customFieldData: invoice.customFieldData }),
|
|
73
73
|
customer_id: invoice.customerId
|
|
74
74
|
};
|
|
75
75
|
};
|
|
@@ -142,24 +142,70 @@ var PolarProvider = class {
|
|
|
142
142
|
const { data, type } = (0, import_webhooks.validateEvent)(body, webhookHeaders, webhookSecret);
|
|
143
143
|
const id = webhookHeaders["webhook-id"];
|
|
144
144
|
const timestamp = webhookHeaders["webhook-timestamp"];
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
145
|
+
const webhookHandlers = {
|
|
146
|
+
/**
|
|
147
|
+
* Invoice
|
|
148
|
+
*/
|
|
149
|
+
"order.paid": (data2) => {
|
|
150
|
+
const { status, metadata } = data2;
|
|
151
|
+
if (status !== "paid") return null;
|
|
152
|
+
return (0, import_core2.toPaykitEvent)({
|
|
153
|
+
type: "$invoicePaid",
|
|
154
|
+
created: parseInt(timestamp),
|
|
155
|
+
id,
|
|
156
|
+
data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "payment" } })
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
"order.created": (data2) => {
|
|
160
|
+
const { billingReason, metadata, status } = data2;
|
|
161
|
+
if (billingReason == "subscription_create") {
|
|
162
|
+
return (0, import_core2.toPaykitEvent)({
|
|
163
|
+
type: "$invoicePaid",
|
|
164
|
+
created: parseInt(timestamp),
|
|
165
|
+
id,
|
|
166
|
+
data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (billingReason == "subscription_cycle") {
|
|
170
|
+
return (0, import_core2.toPaykitEvent)({
|
|
171
|
+
type: "$invoicePaid",
|
|
172
|
+
created: parseInt(timestamp),
|
|
173
|
+
id,
|
|
174
|
+
data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Customer
|
|
181
|
+
*/
|
|
182
|
+
"customer.created": (data2) => {
|
|
183
|
+
return (0, import_core2.toPaykitEvent)({ type: "$customerCreated", created: parseInt(timestamp), id, data: toPaykitCustomer(data2) });
|
|
184
|
+
},
|
|
185
|
+
"customer.updated": (data2) => {
|
|
186
|
+
return (0, import_core2.toPaykitEvent)({ type: "$customerUpdated", created: parseInt(timestamp), id, data: toPaykitCustomer(data2) });
|
|
187
|
+
},
|
|
188
|
+
"customer.deleted": () => {
|
|
189
|
+
return (0, import_core2.toPaykitEvent)({ type: "$customerDeleted", created: parseInt(timestamp), id, data: null });
|
|
190
|
+
},
|
|
191
|
+
/**
|
|
192
|
+
* Subscription
|
|
193
|
+
*/
|
|
194
|
+
"subscription.updated": (data2) => {
|
|
195
|
+
return (0, import_core2.toPaykitEvent)({ type: "$subscriptionUpdated", created: parseInt(timestamp), id, data: toPaykitSubscription(data2) });
|
|
196
|
+
},
|
|
197
|
+
"subscription.created": (data2) => {
|
|
198
|
+
return (0, import_core2.toPaykitEvent)({ type: "$subscriptionCreated", created: parseInt(timestamp), id, data: toPaykitSubscription(data2) });
|
|
199
|
+
},
|
|
200
|
+
"subscription.revoked": (data2) => {
|
|
201
|
+
return (0, import_core2.toPaykitEvent)({ type: "$subscriptionCancelled", created: parseInt(timestamp), id, data: toPaykitSubscription(data2) });
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const handler = webhookHandlers[type];
|
|
205
|
+
if (!handler) throw new Error(`Unhandled event type: ${type}`);
|
|
206
|
+
const result = handler(data);
|
|
207
|
+
if (!result) throw new Error(`Unhandled event type: ${type}`);
|
|
208
|
+
return result;
|
|
163
209
|
};
|
|
164
210
|
const { accessToken, server, ...rest } = config;
|
|
165
211
|
this.polar = new import_sdk.Polar({ accessToken, serverURL: server === "sandbox" ? this.sandboxURL : this.productionURL, ...rest });
|
package/dist/index.mjs
CHANGED
|
@@ -39,7 +39,7 @@ var toPaykitSubscription = (subscription) => {
|
|
|
39
39
|
status: toPaykitSubscriptionStatus(subscription.status),
|
|
40
40
|
current_period_start: new Date(subscription.currentPeriodStart),
|
|
41
41
|
current_period_end: new Date(subscription.currentPeriodEnd),
|
|
42
|
-
metadata: stringifyObjectValues({ ...subscription.metadata ?? {}, customFieldData: subscription.customFieldData })
|
|
42
|
+
metadata: stringifyObjectValues({ ...subscription.metadata ?? {}, $customFieldData: subscription.customFieldData })
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
var toPaykitInvoice = (invoice) => {
|
|
@@ -47,7 +47,7 @@ var toPaykitInvoice = (invoice) => {
|
|
|
47
47
|
id: invoice.id,
|
|
48
48
|
amount: invoice.totalAmount,
|
|
49
49
|
currency: invoice.currency,
|
|
50
|
-
metadata: stringifyObjectValues(invoice.metadata ?? {}),
|
|
50
|
+
metadata: stringifyObjectValues({ ...invoice.metadata ?? {}, $customFieldData: invoice.customFieldData }),
|
|
51
51
|
customer_id: invoice.customerId
|
|
52
52
|
};
|
|
53
53
|
};
|
|
@@ -120,24 +120,70 @@ var PolarProvider = class {
|
|
|
120
120
|
const { data, type } = validateEvent(body, webhookHeaders, webhookSecret);
|
|
121
121
|
const id = webhookHeaders["webhook-id"];
|
|
122
122
|
const timestamp = webhookHeaders["webhook-timestamp"];
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
123
|
+
const webhookHandlers = {
|
|
124
|
+
/**
|
|
125
|
+
* Invoice
|
|
126
|
+
*/
|
|
127
|
+
"order.paid": (data2) => {
|
|
128
|
+
const { status, metadata } = data2;
|
|
129
|
+
if (status !== "paid") return null;
|
|
130
|
+
return toPaykitEvent({
|
|
131
|
+
type: "$invoicePaid",
|
|
132
|
+
created: parseInt(timestamp),
|
|
133
|
+
id,
|
|
134
|
+
data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "payment" } })
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
"order.created": (data2) => {
|
|
138
|
+
const { billingReason, metadata, status } = data2;
|
|
139
|
+
if (billingReason == "subscription_create") {
|
|
140
|
+
return toPaykitEvent({
|
|
141
|
+
type: "$invoicePaid",
|
|
142
|
+
created: parseInt(timestamp),
|
|
143
|
+
id,
|
|
144
|
+
data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (billingReason == "subscription_cycle") {
|
|
148
|
+
return toPaykitEvent({
|
|
149
|
+
type: "$invoicePaid",
|
|
150
|
+
created: parseInt(timestamp),
|
|
151
|
+
id,
|
|
152
|
+
data: toPaykitInvoice({ ...data2, metadata: { ...metadata ?? {}, $mode: "subscription" } })
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* Customer
|
|
159
|
+
*/
|
|
160
|
+
"customer.created": (data2) => {
|
|
161
|
+
return toPaykitEvent({ type: "$customerCreated", created: parseInt(timestamp), id, data: toPaykitCustomer(data2) });
|
|
162
|
+
},
|
|
163
|
+
"customer.updated": (data2) => {
|
|
164
|
+
return toPaykitEvent({ type: "$customerUpdated", created: parseInt(timestamp), id, data: toPaykitCustomer(data2) });
|
|
165
|
+
},
|
|
166
|
+
"customer.deleted": () => {
|
|
167
|
+
return toPaykitEvent({ type: "$customerDeleted", created: parseInt(timestamp), id, data: null });
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* Subscription
|
|
171
|
+
*/
|
|
172
|
+
"subscription.updated": (data2) => {
|
|
173
|
+
return toPaykitEvent({ type: "$subscriptionUpdated", created: parseInt(timestamp), id, data: toPaykitSubscription(data2) });
|
|
174
|
+
},
|
|
175
|
+
"subscription.created": (data2) => {
|
|
176
|
+
return toPaykitEvent({ type: "$subscriptionCreated", created: parseInt(timestamp), id, data: toPaykitSubscription(data2) });
|
|
177
|
+
},
|
|
178
|
+
"subscription.revoked": (data2) => {
|
|
179
|
+
return toPaykitEvent({ type: "$subscriptionCancelled", created: parseInt(timestamp), id, data: toPaykitSubscription(data2) });
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const handler = webhookHandlers[type];
|
|
183
|
+
if (!handler) throw new Error(`Unhandled event type: ${type}`);
|
|
184
|
+
const result = handler(data);
|
|
185
|
+
if (!result) throw new Error(`Unhandled event type: ${type}`);
|
|
186
|
+
return result;
|
|
141
187
|
};
|
|
142
188
|
const { accessToken, server, ...rest } = config;
|
|
143
189
|
this.polar = new Polar({ accessToken, serverURL: server === "sandbox" ? this.sandboxURL : this.productionURL, ...rest });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/polar",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Polar provider for PayKit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@polar-sh/sdk": "^0.33.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@paykit-sdk/core": "^1.1.
|
|
27
|
+
"@paykit-sdk/core": "^1.1.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@paykit-sdk/core": "workspace:*",
|