@paykit-sdk/gopay 1.0.5 → 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 +105 -68
- package/dist/controllers/auth.js +12 -8
- package/dist/controllers/auth.mjs +12 -8
- package/dist/gopay-provider.js +249 -118
- package/dist/gopay-provider.mjs +249 -118
- package/dist/index.js +251 -119
- package/dist/index.mjs +251 -119
- package/dist/schema.d.mts +56 -38
- package/dist/schema.d.ts +56 -38
- package/dist/utils/mapper.d.mts +13 -7
- package/dist/utils/mapper.d.ts +13 -7
- package/dist/utils/mapper.js +106 -25
- package/dist/utils/mapper.mjs +105 -26
- package/package.json +3 -3
package/dist/utils/mapper.mjs
CHANGED
|
@@ -1,10 +1,53 @@
|
|
|
1
1
|
import { PAYKIT_METADATA_KEY, omitInternalMetadata } from '@paykit-sdk/core';
|
|
2
2
|
|
|
3
3
|
// src/utils/mapper.ts
|
|
4
|
+
var decodeHtmlEntities = (str) => {
|
|
5
|
+
return str.replace(/"/g, '"').replace(/'/g, "'").replace(/"/g, '"').replace(/'/g, "'");
|
|
6
|
+
};
|
|
4
7
|
var paykitPayment$InboundSchema = (data) => {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
const { item } = JSON.parse(
|
|
9
|
+
decodeHtmlEntities(
|
|
10
|
+
data.additional_params?.find((param) => param.name === PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
const metadata = omitInternalMetadata(
|
|
14
|
+
data.additional_params?.reduce(
|
|
15
|
+
(acc, param) => {
|
|
16
|
+
acc[param.name] = String(param.value);
|
|
17
|
+
return acc;
|
|
18
|
+
},
|
|
19
|
+
{}
|
|
20
|
+
) ?? {}
|
|
21
|
+
);
|
|
22
|
+
const statusMap = {
|
|
23
|
+
CREATED: "pending",
|
|
24
|
+
PAYMENT_METHOD_CHOSEN: "processing",
|
|
25
|
+
PAID: "succeeded",
|
|
26
|
+
AUTHORIZED: "requires_capture",
|
|
27
|
+
CANCELED: "canceled",
|
|
28
|
+
TIMEOUTED: "canceled",
|
|
29
|
+
REFUNDED: "canceled",
|
|
30
|
+
PARTIALLY_REFUNDED: "canceled"
|
|
31
|
+
};
|
|
32
|
+
const requiresAction = data.state === "CREATED" || data.state === "AUTHORIZED" ? true : false;
|
|
33
|
+
return {
|
|
34
|
+
id: data.id.toString(),
|
|
35
|
+
amount: data.amount,
|
|
36
|
+
currency: data.currency,
|
|
37
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : "",
|
|
38
|
+
status: statusMap[data.state],
|
|
39
|
+
item_id: item,
|
|
40
|
+
metadata,
|
|
41
|
+
requires_action: requiresAction,
|
|
42
|
+
payment_url: data.gw_url ?? null
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
var paykitCheckout$InboundSchema = (data) => {
|
|
46
|
+
const { item, qty, type } = JSON.parse(
|
|
47
|
+
decodeHtmlEntities(
|
|
48
|
+
data.additional_params?.find((param) => param.name === PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
49
|
+
)
|
|
50
|
+
);
|
|
8
51
|
const metadata = omitInternalMetadata(
|
|
9
52
|
data.additional_params?.reduce(
|
|
10
53
|
(acc, param) => {
|
|
@@ -18,24 +61,24 @@ var paykitPayment$InboundSchema = (data) => {
|
|
|
18
61
|
id: data.id.toString(),
|
|
19
62
|
amount: data.amount,
|
|
20
63
|
currency: data.currency,
|
|
21
|
-
customer: data.payer
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
64
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : "",
|
|
65
|
+
payment_url: data.gw_url ?? "",
|
|
66
|
+
metadata,
|
|
67
|
+
session_type: type,
|
|
68
|
+
products: [{ id: item, quantity: parseInt(qty) }]
|
|
25
69
|
};
|
|
26
70
|
};
|
|
27
71
|
var paykitInvoice$InboundSchema = (data, isSubscription) => {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
).itemId;
|
|
72
|
+
const { item, qty } = JSON.parse(
|
|
73
|
+
decodeHtmlEntities(
|
|
74
|
+
data.additional_params?.find((param) => param.name === PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
75
|
+
)
|
|
76
|
+
);
|
|
34
77
|
const status = (() => {
|
|
35
78
|
if (data.state === "PAID") return "paid";
|
|
36
79
|
return "open";
|
|
37
80
|
})();
|
|
38
|
-
const paidAt = isSubscription ? new Date(data.recurrence?.
|
|
81
|
+
const paidAt = isSubscription ? new Date(data.recurrence?.recurrence_date_to ?? "") : /* @__PURE__ */ new Date();
|
|
39
82
|
const metadata = omitInternalMetadata(
|
|
40
83
|
data.additional_params?.reduce(
|
|
41
84
|
(acc, param) => {
|
|
@@ -49,20 +92,22 @@ var paykitInvoice$InboundSchema = (data, isSubscription) => {
|
|
|
49
92
|
id: data.id.toString(),
|
|
50
93
|
amount_paid: data.amount,
|
|
51
94
|
currency: data.currency,
|
|
52
|
-
customer: data.payer
|
|
95
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : "",
|
|
53
96
|
status,
|
|
54
97
|
paid_at: paidAt.toISOString(),
|
|
55
98
|
metadata: metadata ?? {},
|
|
56
99
|
custom_fields: null,
|
|
57
100
|
subscription_id: isSubscription ? data.id.toString() : null,
|
|
58
101
|
billing_mode: isSubscription ? "recurring" : "one_time",
|
|
59
|
-
line_items: [{ id:
|
|
102
|
+
line_items: [{ id: item, quantity: parseInt(qty) }]
|
|
60
103
|
};
|
|
61
104
|
};
|
|
62
105
|
var paykitSubscription$InboundSchema = (data) => {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
106
|
+
const { item } = JSON.parse(
|
|
107
|
+
decodeHtmlEntities(
|
|
108
|
+
data.additional_params?.find((param) => param.name === PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
109
|
+
)
|
|
110
|
+
);
|
|
66
111
|
const billingIntervalMap = {
|
|
67
112
|
DAY: "day",
|
|
68
113
|
WEEK: "week",
|
|
@@ -70,8 +115,28 @@ var paykitSubscription$InboundSchema = (data) => {
|
|
|
70
115
|
ON_DEMAND: "month"
|
|
71
116
|
};
|
|
72
117
|
const billingInterval = billingIntervalMap[data.recurrence?.recurrence_cycle ?? "ON_DEMAND"];
|
|
73
|
-
const
|
|
118
|
+
const recurrencePeriod = data.recurrence?.recurrence_period ?? 1;
|
|
119
|
+
const recurrenceCycle = data.recurrence?.recurrence_cycle;
|
|
74
120
|
const currentPeriodEnd = new Date(data.recurrence?.recurrence_date_to ?? "");
|
|
121
|
+
const currentPeriodStart = (() => {
|
|
122
|
+
if (!currentPeriodEnd) return /* @__PURE__ */ new Date();
|
|
123
|
+
const endDate = new Date(currentPeriodEnd);
|
|
124
|
+
const startDate = new Date(endDate);
|
|
125
|
+
switch (recurrenceCycle) {
|
|
126
|
+
case "DAY":
|
|
127
|
+
startDate.setDate(startDate.getDate() - recurrencePeriod);
|
|
128
|
+
break;
|
|
129
|
+
case "WEEK":
|
|
130
|
+
startDate.setDate(startDate.getDate() - recurrencePeriod * 7);
|
|
131
|
+
break;
|
|
132
|
+
case "MONTH":
|
|
133
|
+
startDate.setMonth(startDate.getMonth() - recurrencePeriod);
|
|
134
|
+
break;
|
|
135
|
+
default:
|
|
136
|
+
startDate.setDate(startDate.getDate() - recurrencePeriod);
|
|
137
|
+
}
|
|
138
|
+
return startDate;
|
|
139
|
+
})();
|
|
75
140
|
const metadata = omitInternalMetadata(
|
|
76
141
|
data.additional_params?.reduce(
|
|
77
142
|
(acc, param) => {
|
|
@@ -81,18 +146,32 @@ var paykitSubscription$InboundSchema = (data) => {
|
|
|
81
146
|
{}
|
|
82
147
|
) ?? {}
|
|
83
148
|
);
|
|
149
|
+
const requiresAction = data.state === "CREATED" ? true : false;
|
|
150
|
+
const status = (() => {
|
|
151
|
+
if (data.state === "CREATED") return "pending";
|
|
152
|
+
if (data.state === "PAID") return "active";
|
|
153
|
+
if (data.state === "CANCELED") return "canceled";
|
|
154
|
+
if (data.state === "TIMEOUTED") return "canceled";
|
|
155
|
+
if (data.state === "REFUNDED") return "canceled";
|
|
156
|
+
if (data.state === "PARTIALLY_REFUNDED") return "canceled";
|
|
157
|
+
if (data.state === "AUTHORIZED") return "active";
|
|
158
|
+
if (data.state === "PAYMENT_METHOD_CHOSEN") return "active";
|
|
159
|
+
return "pending";
|
|
160
|
+
})();
|
|
84
161
|
return {
|
|
85
162
|
id: data.id.toString(),
|
|
86
|
-
status
|
|
87
|
-
customer: data.payer
|
|
88
|
-
item_id:
|
|
163
|
+
status,
|
|
164
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : "",
|
|
165
|
+
item_id: item,
|
|
89
166
|
billing_interval: billingInterval,
|
|
90
167
|
currency: data.currency,
|
|
91
168
|
amount: data.amount,
|
|
92
|
-
metadata
|
|
169
|
+
metadata,
|
|
93
170
|
custom_fields: null,
|
|
94
171
|
current_period_start: currentPeriodStart,
|
|
95
|
-
current_period_end: currentPeriodEnd
|
|
172
|
+
current_period_end: currentPeriodEnd,
|
|
173
|
+
requires_action: requiresAction,
|
|
174
|
+
payment_url: requiresAction ? data.gw_url ?? null : null
|
|
96
175
|
};
|
|
97
176
|
};
|
|
98
177
|
var paykitRefund$InboundSchema = (data) => {
|
|
@@ -105,4 +184,4 @@ var paykitRefund$InboundSchema = (data) => {
|
|
|
105
184
|
};
|
|
106
185
|
};
|
|
107
186
|
|
|
108
|
-
export { paykitInvoice$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
|
|
187
|
+
export { decodeHtmlEntities, paykitCheckout$InboundSchema, paykitInvoice$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/gopay",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "GoPay provider for PayKit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"author": "Emmanuel Odii",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@paykit-sdk/core": ">=1.1.
|
|
25
|
+
"@paykit-sdk/core": ">=1.1.102"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"tsup": "^8.5.0",
|
|
29
29
|
"typescript": "^5.9.2",
|
|
30
30
|
"zod": "^3.24.2",
|
|
31
|
-
"@paykit-sdk/core": "1.1.
|
|
31
|
+
"@paykit-sdk/core": "1.1.102"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|