@paykit-sdk/paypal 1.0.6 → 1.0.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.
@@ -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 paykitPayee$InboundSchema = (payee) => {
6
- let customer = { email: "" };
7
- if (typeof payee === "string") customer = payee;
8
- else if (payee?.emailAddress) customer = { email: payee?.emailAddress };
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 paykitRefund$InboundSchema = (refund) => {
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(JSON.parse(refund.customId ?? "{}")),
15
+ metadata: omitInternalMetadata(
16
+ JSON.parse(refund.customId ?? "{}")
17
+ ),
17
18
  reason: refund.noteToPayer ?? null
18
19
  };
19
20
  };
20
- var paykitCheckout$InboundSchema = (order) => {
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(order.purchaseUnits?.[0]?.amount?.value || "0"),
25
+ amount: parseFloat(
26
+ order.purchaseUnits?.[0]?.amount?.value || "0"
27
+ ),
25
28
  currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
26
- customer: paykitPayee$InboundSchema(order.payer ?? {}),
29
+ customer: Payee$inboundSchema(order.payer ?? {}),
27
30
  session_type: "one_time",
28
- products: [{ id: order.purchaseUnits?.[0]?.items?.[0]?.sku || "", quantity: 1 }],
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 paykitPayment$InboundSchema = (order) => {
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: paykitPayee$InboundSchema(order.payer ?? {}),
55
- amount: parseFloat(order.purchaseUnits?.[0]?.amount?.value || "0"),
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 paykitSubscription$InboundSchema = (subscription) => {
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: subscription.subscriber?.email_address ?? "" },
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(JSON.parse(subscription?.customId ?? "{}")),
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 paykitInvoice$InboundSchema = (order) => {
137
+ var Invoice$inboundSchema = (order) => {
125
138
  return {
126
139
  id: order.id,
127
- amount_paid: parseFloat(order.purchaseUnits?.[0]?.amount?.value || "0"),
140
+ amount_paid: parseFloat(
141
+ order.purchaseUnits?.[0]?.amount?.value || "0"
142
+ ),
128
143
  currency: order.purchaseUnits?.[0]?.amount?.currencyCode || "USD",
129
- customer: paykitPayee$InboundSchema(order.payer ?? {}),
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: [{ id: order.purchaseUnits?.[0]?.items?.[0]?.sku || "", quantity: 1 }]
153
+ line_items: [
154
+ {
155
+ id: order.purchaseUnits?.[0]?.items?.[0]?.sku || "",
156
+ quantity: 1
157
+ }
158
+ ]
139
159
  };
140
160
  };
141
- var paykitPaymentWebhook$InboundSchema = (resource) => {
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 = { email: "" };
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 paykitPaymentCaptureWebhook$InboundSchema = (capture) => {
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: { email: "" },
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 paykitRefundWebhook$InboundSchema = (refund) => {
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 paykitSubscriptionWebhook$InboundSchema = (agreement) => {
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((def) => def.type === "REGULAR") ?? paymentDefinitions[0];
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 { paykitCheckout$InboundSchema, paykitInvoice$InboundSchema, paykitPayee$InboundSchema, paykitPayment$InboundSchema, paykitPaymentCaptureWebhook$InboundSchema, paykitPaymentWebhook$InboundSchema, paykitRefund$InboundSchema, paykitRefundWebhook$InboundSchema, paykitSubscription$InboundSchema, paykitSubscriptionWebhook$InboundSchema };
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.6",
3
+ "version": "1.0.7",
4
4
  "description": "PayPal provider for PayKit",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -8,6 +8,9 @@
8
8
  "files": [
9
9
  "dist"
10
10
  ],
11
+ "scripts": {
12
+ "build": "tsup"
13
+ },
11
14
  "keywords": [
12
15
  "paypal",
13
16
  "paykit",
@@ -17,17 +20,16 @@
17
20
  "author": "Emmanuel Odii",
18
21
  "license": "ISC",
19
22
  "devDependencies": {
23
+ "@paykit-sdk/core": "workspace:*",
20
24
  "tsup": "^8.5.0",
21
- "typescript": "^5.9.2",
22
- "zod": "^3.24.2",
23
- "@paykit-sdk/core": "1.1.102"
25
+ "typescript": "^5.9.2"
24
26
  },
25
27
  "dependencies": {
26
28
  "@paypal/paypal-server-sdk": "^1.1.0",
27
29
  "esbuild": "^0.25.11"
28
30
  },
29
31
  "peerDependencies": {
30
- "@paykit-sdk/core": ">=1.1.102"
32
+ "@paykit-sdk/core": ">=1.1.103"
31
33
  },
32
34
  "publishConfig": {
33
35
  "access": "public"
@@ -38,8 +40,5 @@
38
40
  },
39
41
  "bugs": {
40
42
  "url": "https://github.com/usepaykit/paykit-sdk/issues"
41
- },
42
- "scripts": {
43
- "build": "tsup"
44
43
  }
45
- }
44
+ }