@paykit-sdk/paypal 1.0.6 → 1.2.0
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 +31 -8
- package/dist/controllers/subscription.d.mts +1 -1
- package/dist/controllers/subscription.d.ts +1 -1
- package/dist/controllers/subscription.js +50 -13
- package/dist/controllers/subscription.mjs +50 -13
- package/dist/controllers/webhook.js +11 -3
- package/dist/controllers/webhook.mjs +11 -3
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +397 -4321
- package/dist/index.mjs +398 -4322
- package/dist/paypal-provider.d.mts +9 -14
- package/dist/paypal-provider.d.ts +9 -14
- package/dist/paypal-provider.js +394 -4319
- package/dist/paypal-provider.mjs +395 -4320
- package/dist/schema.js +7 -2
- package/dist/schema.mjs +7 -2
- package/dist/types.d.mts +77 -1
- package/dist/types.d.ts +77 -1
- package/dist/utils/mapper.d.mts +33 -15
- package/dist/utils/mapper.d.ts +33 -15
- package/dist/utils/mapper.js +63 -46
- package/dist/utils/mapper.mjs +54 -37
- package/package.json +11 -9
package/dist/utils/mapper.mjs
CHANGED
|
@@ -2,37 +2,45 @@ import { omitInternalMetadata } from '@paykit-sdk/core';
|
|
|
2
2
|
import { OrderStatus } from '@paypal/paypal-server-sdk';
|
|
3
3
|
|
|
4
4
|
// src/utils/mapper.ts
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
return customer;
|
|
5
|
+
var Payee$inboundSchema = (payee) => {
|
|
6
|
+
if (typeof payee === "string") return { id: payee };
|
|
7
|
+
if (payee?.emailAddress) return { email: payee.emailAddress };
|
|
8
|
+
return null;
|
|
10
9
|
};
|
|
11
|
-
var
|
|
10
|
+
var Refund$inboundSchema = (refund) => {
|
|
12
11
|
return {
|
|
13
12
|
id: refund.id,
|
|
14
13
|
amount: refund.amount?.value ? parseFloat(refund.amount.value) : 0,
|
|
15
14
|
currency: refund.amount?.currencyCode || "USD",
|
|
16
|
-
metadata: omitInternalMetadata(
|
|
15
|
+
metadata: omitInternalMetadata(
|
|
16
|
+
JSON.parse(refund.customId ?? "{}")
|
|
17
|
+
),
|
|
17
18
|
reason: refund.noteToPayer ?? null
|
|
18
19
|
};
|
|
19
20
|
};
|
|
20
|
-
var
|
|
21
|
+
var Checkout$inboundSchema = (order) => {
|
|
21
22
|
return {
|
|
22
23
|
id: order.id,
|
|
23
24
|
payment_url: order.links?.find((l) => l.rel === "approve")?.href || "",
|
|
24
|
-
amount: parseFloat(
|
|
25
|
+
amount: parseFloat(
|
|
26
|
+
order.purchaseUnits?.[0]?.amount?.value || "0"
|
|
27
|
+
),
|
|
25
28
|
currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
|
|
26
|
-
customer:
|
|
29
|
+
customer: Payee$inboundSchema(order.payer ?? {}),
|
|
27
30
|
session_type: "one_time",
|
|
28
|
-
products: [
|
|
31
|
+
products: [
|
|
32
|
+
{
|
|
33
|
+
id: order.purchaseUnits?.[0]?.items?.[0]?.sku || "",
|
|
34
|
+
quantity: 1
|
|
35
|
+
}
|
|
36
|
+
],
|
|
29
37
|
metadata: omitInternalMetadata(
|
|
30
38
|
JSON.parse(order.purchaseUnits?.[0]?.customId ?? "{}")
|
|
31
39
|
),
|
|
32
40
|
subscription: null
|
|
33
41
|
};
|
|
34
42
|
};
|
|
35
|
-
var
|
|
43
|
+
var Payment$inboundSchema = (order) => {
|
|
36
44
|
const statusMap = {
|
|
37
45
|
CREATED: "pending",
|
|
38
46
|
SAVED: "pending",
|
|
@@ -51,8 +59,10 @@ var paykitPayment$InboundSchema = (order) => {
|
|
|
51
59
|
return {
|
|
52
60
|
id: order.id,
|
|
53
61
|
status,
|
|
54
|
-
customer:
|
|
55
|
-
amount: parseFloat(
|
|
62
|
+
customer: Payee$inboundSchema(order.payer ?? {}),
|
|
63
|
+
amount: parseFloat(
|
|
64
|
+
order.purchaseUnits?.[0]?.amount?.value || "0"
|
|
65
|
+
),
|
|
56
66
|
currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
|
|
57
67
|
metadata: omitInternalMetadata(
|
|
58
68
|
JSON.parse(order.purchaseUnits?.[0]?.customId ?? "{}")
|
|
@@ -62,7 +72,7 @@ var paykitPayment$InboundSchema = (order) => {
|
|
|
62
72
|
payment_url: approveLink
|
|
63
73
|
};
|
|
64
74
|
};
|
|
65
|
-
var
|
|
75
|
+
var Subscription$inboundSchema = (subscription) => {
|
|
66
76
|
const statusMap = {
|
|
67
77
|
APPROVAL_PENDING: "pending",
|
|
68
78
|
APPROVED: "active",
|
|
@@ -105,14 +115,17 @@ var paykitSubscription$InboundSchema = (subscription) => {
|
|
|
105
115
|
}
|
|
106
116
|
return end;
|
|
107
117
|
})();
|
|
118
|
+
const email = subscription.subscriber?.email_address;
|
|
108
119
|
return {
|
|
109
120
|
id: subscription.id,
|
|
110
|
-
customer: { email
|
|
121
|
+
customer: email ? { email } : null,
|
|
111
122
|
status,
|
|
112
123
|
item_id: subscription.plan_id,
|
|
113
124
|
current_period_start: periodStart,
|
|
114
125
|
current_period_end: periodEnd,
|
|
115
|
-
metadata: omitInternalMetadata(
|
|
126
|
+
metadata: omitInternalMetadata(
|
|
127
|
+
JSON.parse(subscription?.customId ?? "{}")
|
|
128
|
+
),
|
|
116
129
|
billing_interval: billingInterval,
|
|
117
130
|
amount: 0,
|
|
118
131
|
currency: "USD",
|
|
@@ -121,12 +134,14 @@ var paykitSubscription$InboundSchema = (subscription) => {
|
|
|
121
134
|
payment_url: null
|
|
122
135
|
};
|
|
123
136
|
};
|
|
124
|
-
var
|
|
137
|
+
var Invoice$inboundSchema = (order) => {
|
|
125
138
|
return {
|
|
126
139
|
id: order.id,
|
|
127
|
-
amount_paid: parseFloat(
|
|
140
|
+
amount_paid: parseFloat(
|
|
141
|
+
order.purchaseUnits?.[0]?.amount?.value || "0"
|
|
142
|
+
),
|
|
128
143
|
currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
|
|
129
|
-
customer:
|
|
144
|
+
customer: Payee$inboundSchema(order.payer ?? {}),
|
|
130
145
|
status: "paid",
|
|
131
146
|
paid_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
132
147
|
metadata: omitInternalMetadata(
|
|
@@ -135,10 +150,15 @@ var paykitInvoice$InboundSchema = (order) => {
|
|
|
135
150
|
custom_fields: null,
|
|
136
151
|
subscription_id: null,
|
|
137
152
|
billing_mode: "one_time",
|
|
138
|
-
line_items: [
|
|
153
|
+
line_items: [
|
|
154
|
+
{
|
|
155
|
+
id: order.purchaseUnits?.[0]?.items?.[0]?.sku || "",
|
|
156
|
+
quantity: 1
|
|
157
|
+
}
|
|
158
|
+
]
|
|
139
159
|
};
|
|
140
160
|
};
|
|
141
|
-
var
|
|
161
|
+
var PaymentWebhook$inboundSchema = (resource) => {
|
|
142
162
|
const statusMap = {
|
|
143
163
|
CREATED: "pending",
|
|
144
164
|
SAVED: "pending",
|
|
@@ -149,9 +169,9 @@ var paykitPaymentWebhook$InboundSchema = (resource) => {
|
|
|
149
169
|
};
|
|
150
170
|
const status = statusMap[resource.status ?? "CREATED"] ?? "pending";
|
|
151
171
|
const payer = resource.payer;
|
|
152
|
-
let customer =
|
|
172
|
+
let customer = null;
|
|
153
173
|
if (payer?.payer_id) {
|
|
154
|
-
customer = payer.payer_id;
|
|
174
|
+
customer = { id: payer.payer_id };
|
|
155
175
|
} else if (payer?.email_address) {
|
|
156
176
|
customer = { email: payer.email_address };
|
|
157
177
|
}
|
|
@@ -180,12 +200,11 @@ var paykitPaymentWebhook$InboundSchema = (resource) => {
|
|
|
180
200
|
payment_url: null
|
|
181
201
|
};
|
|
182
202
|
};
|
|
183
|
-
var
|
|
203
|
+
var PaymentCaptureWebhook$inboundSchema = (capture) => {
|
|
184
204
|
const statusMap = {
|
|
185
205
|
COMPLETED: "succeeded",
|
|
186
206
|
PENDING: "pending",
|
|
187
207
|
REFUNDED: "succeeded",
|
|
188
|
-
// Refunded but was successful
|
|
189
208
|
PARTIALLY_REFUNDED: "succeeded"
|
|
190
209
|
};
|
|
191
210
|
const status = statusMap[capture.status ?? "PENDING"] ?? "pending";
|
|
@@ -204,18 +223,16 @@ var paykitPaymentCaptureWebhook$InboundSchema = (capture) => {
|
|
|
204
223
|
return {
|
|
205
224
|
id: orderId,
|
|
206
225
|
status,
|
|
207
|
-
customer:
|
|
208
|
-
// Not available in capture event
|
|
226
|
+
customer: null,
|
|
209
227
|
amount: parseFloat(amount?.value ?? "0"),
|
|
210
228
|
currency: amount?.currency_code ?? "USD",
|
|
211
229
|
metadata: omitInternalMetadata(metadata),
|
|
212
230
|
item_id: "",
|
|
213
|
-
// Not available in capture event
|
|
214
231
|
requires_action: false,
|
|
215
232
|
payment_url: null
|
|
216
233
|
};
|
|
217
234
|
};
|
|
218
|
-
var
|
|
235
|
+
var RefundWebhook$inboundSchema = (refund) => {
|
|
219
236
|
const amount = refund.amount;
|
|
220
237
|
const refundAmount = amount?.total ? Math.abs(parseFloat(amount.total)) : 0;
|
|
221
238
|
return {
|
|
@@ -223,12 +240,10 @@ var paykitRefundWebhook$InboundSchema = (refund) => {
|
|
|
223
240
|
amount: refundAmount,
|
|
224
241
|
currency: amount?.currency ?? "USD",
|
|
225
242
|
metadata: omitInternalMetadata({}),
|
|
226
|
-
// No metadata in webhook refund
|
|
227
243
|
reason: null
|
|
228
|
-
// No reason in webhook refund
|
|
229
244
|
};
|
|
230
245
|
};
|
|
231
|
-
var
|
|
246
|
+
var SubscriptionWebhook$inboundSchema = (agreement) => {
|
|
232
247
|
const state = agreement.state ?? "Pending";
|
|
233
248
|
const statusMap = {
|
|
234
249
|
Pending: "pending",
|
|
@@ -241,7 +256,9 @@ var paykitSubscriptionWebhook$InboundSchema = (agreement) => {
|
|
|
241
256
|
const status = statusMap[state] ?? "pending";
|
|
242
257
|
const plan = agreement.plan;
|
|
243
258
|
const paymentDefinitions = plan?.payment_definitions ?? [];
|
|
244
|
-
const regularDefinition = paymentDefinitions.find(
|
|
259
|
+
const regularDefinition = paymentDefinitions.find(
|
|
260
|
+
(def) => def.type === "REGULAR"
|
|
261
|
+
) ?? paymentDefinitions[0];
|
|
245
262
|
const frequency = regularDefinition?.frequency ?? "Month";
|
|
246
263
|
const billingIntervalMap = {
|
|
247
264
|
Day: "day",
|
|
@@ -278,7 +295,7 @@ var paykitSubscriptionWebhook$InboundSchema = (agreement) => {
|
|
|
278
295
|
})();
|
|
279
296
|
const payer = agreement.payer;
|
|
280
297
|
const payerInfo = payer?.payer_info;
|
|
281
|
-
const email = payerInfo?.email
|
|
298
|
+
const email = payerInfo?.email;
|
|
282
299
|
const planId = plan?.id ?? agreement.id;
|
|
283
300
|
const amount = regularDefinition?.amount;
|
|
284
301
|
const subscriptionAmount = amount?.value ? parseFloat(amount.value) : 0;
|
|
@@ -293,7 +310,7 @@ var paykitSubscriptionWebhook$InboundSchema = (agreement) => {
|
|
|
293
310
|
})();
|
|
294
311
|
return {
|
|
295
312
|
id: agreement.id,
|
|
296
|
-
customer: { email },
|
|
313
|
+
customer: email ? { email } : null,
|
|
297
314
|
status,
|
|
298
315
|
item_id: planId,
|
|
299
316
|
current_period_start: periodStart,
|
|
@@ -308,4 +325,4 @@ var paykitSubscriptionWebhook$InboundSchema = (agreement) => {
|
|
|
308
325
|
};
|
|
309
326
|
};
|
|
310
327
|
|
|
311
|
-
export {
|
|
328
|
+
export { Checkout$inboundSchema, Invoice$inboundSchema, Payee$inboundSchema, Payment$inboundSchema, PaymentCaptureWebhook$inboundSchema, PaymentWebhook$inboundSchema, Refund$inboundSchema, RefundWebhook$inboundSchema, Subscription$inboundSchema, SubscriptionWebhook$inboundSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/paypal",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "PayPal provider for PayKit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup"
|
|
13
|
+
},
|
|
14
|
+
"paykit": {
|
|
15
|
+
"type": "provider"
|
|
16
|
+
},
|
|
11
17
|
"keywords": [
|
|
12
18
|
"paypal",
|
|
13
19
|
"paykit",
|
|
@@ -17,17 +23,16 @@
|
|
|
17
23
|
"author": "Emmanuel Odii",
|
|
18
24
|
"license": "ISC",
|
|
19
25
|
"devDependencies": {
|
|
26
|
+
"@paykit-sdk/core": "workspace:*",
|
|
20
27
|
"tsup": "^8.5.0",
|
|
21
|
-
"typescript": "^5.9.2"
|
|
22
|
-
"zod": "^3.24.2",
|
|
23
|
-
"@paykit-sdk/core": "1.1.102"
|
|
28
|
+
"typescript": "^5.9.2"
|
|
24
29
|
},
|
|
25
30
|
"dependencies": {
|
|
26
31
|
"@paypal/paypal-server-sdk": "^1.1.0",
|
|
27
32
|
"esbuild": "^0.25.11"
|
|
28
33
|
},
|
|
29
34
|
"peerDependencies": {
|
|
30
|
-
"@paykit-sdk/core": ">=1.
|
|
35
|
+
"@paykit-sdk/core": ">=1.2.0"
|
|
31
36
|
},
|
|
32
37
|
"publishConfig": {
|
|
33
38
|
"access": "public"
|
|
@@ -38,8 +43,5 @@
|
|
|
38
43
|
},
|
|
39
44
|
"bugs": {
|
|
40
45
|
"url": "https://github.com/usepaykit/paykit-sdk/issues"
|
|
41
|
-
},
|
|
42
|
-
"scripts": {
|
|
43
|
-
"build": "tsup"
|
|
44
46
|
}
|
|
45
|
-
}
|
|
47
|
+
}
|