@paykit-sdk/gopay 1.0.4 → 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/schema.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ interface GoPayTokenResponse {
|
|
|
2
2
|
/**
|
|
3
3
|
* The type of the token
|
|
4
4
|
*/
|
|
5
|
-
token_type:
|
|
5
|
+
token_type: 'bearer';
|
|
6
6
|
/**
|
|
7
7
|
* The access token
|
|
8
8
|
*/
|
|
@@ -12,7 +12,7 @@ interface GoPayTokenResponse {
|
|
|
12
12
|
*/
|
|
13
13
|
expires_in: number;
|
|
14
14
|
}
|
|
15
|
-
interface
|
|
15
|
+
interface GoPayPaymentBaseResponse {
|
|
16
16
|
/**
|
|
17
17
|
* The ID of the payment
|
|
18
18
|
*/
|
|
@@ -25,10 +25,6 @@ interface GoPayPaymentResponse {
|
|
|
25
25
|
* The state of the payment
|
|
26
26
|
*/
|
|
27
27
|
state: 'CREATED' | 'PAYMENT_METHOD_CHOSEN' | 'PAID' | 'AUTHORIZED' | 'CANCELED' | 'TIMEOUTED' | 'REFUNDED' | 'PARTIALLY_REFUNDED';
|
|
28
|
-
/**
|
|
29
|
-
* The sub state of the payment
|
|
30
|
-
*/
|
|
31
|
-
sub_state?: string;
|
|
32
28
|
/**
|
|
33
29
|
* The amount of the payment
|
|
34
30
|
*/
|
|
@@ -37,64 +33,86 @@ interface GoPayPaymentResponse {
|
|
|
37
33
|
* The currency of the payment
|
|
38
34
|
*/
|
|
39
35
|
currency: string;
|
|
40
|
-
/**
|
|
41
|
-
* The payment instrument of the payment
|
|
42
|
-
*/
|
|
43
|
-
payment_instrument?: string;
|
|
44
36
|
/**
|
|
45
37
|
* The payer of the payment
|
|
46
38
|
*/
|
|
47
|
-
payer
|
|
39
|
+
payer: {
|
|
40
|
+
/**
|
|
41
|
+
* The allowed payment instruments of the payer
|
|
42
|
+
*/
|
|
43
|
+
allowed_payment_instruments: string[];
|
|
44
|
+
/**
|
|
45
|
+
* The default payment instrument of the payer
|
|
46
|
+
*/
|
|
47
|
+
default_payment_instrument: string;
|
|
48
|
+
/**
|
|
49
|
+
* The contact of the payer
|
|
50
|
+
*/
|
|
51
|
+
contact: {
|
|
52
|
+
email: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
48
55
|
/**
|
|
49
56
|
* The target of the payment
|
|
50
57
|
*/
|
|
51
|
-
target
|
|
52
|
-
/**
|
|
53
|
-
* The recurrence of the payment
|
|
54
|
-
*/
|
|
55
|
-
recurrence?: {
|
|
58
|
+
target: {
|
|
56
59
|
/**
|
|
57
|
-
* The
|
|
60
|
+
* The type of the target
|
|
58
61
|
*/
|
|
59
|
-
|
|
62
|
+
type: 'ACCOUNT';
|
|
60
63
|
/**
|
|
61
|
-
* The
|
|
64
|
+
* The GoID of the target
|
|
62
65
|
*/
|
|
63
|
-
|
|
66
|
+
goid: number;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* The additional parameters of the payment
|
|
70
|
+
*/
|
|
71
|
+
additional_params?: Array<{
|
|
64
72
|
/**
|
|
65
|
-
* The
|
|
73
|
+
* The name of the additional parameter
|
|
66
74
|
*/
|
|
67
|
-
|
|
75
|
+
name: string;
|
|
68
76
|
/**
|
|
69
|
-
* The
|
|
77
|
+
* The value of the additional parameter
|
|
70
78
|
*/
|
|
71
|
-
|
|
72
|
-
}
|
|
79
|
+
value: string;
|
|
80
|
+
}>;
|
|
73
81
|
/**
|
|
74
|
-
* The
|
|
82
|
+
* The language of the payment
|
|
75
83
|
*/
|
|
76
|
-
|
|
84
|
+
lang?: string;
|
|
77
85
|
/**
|
|
78
86
|
* The GW URL of the payment
|
|
79
87
|
*/
|
|
80
88
|
gw_url?: string;
|
|
89
|
+
}
|
|
90
|
+
interface GoPaySubscriptionResponse extends GoPayPaymentBaseResponse {
|
|
81
91
|
/**
|
|
82
|
-
* The
|
|
92
|
+
* The payment instrument of the payment
|
|
83
93
|
*/
|
|
84
|
-
|
|
94
|
+
payment_instrument?: string;
|
|
85
95
|
/**
|
|
86
|
-
* The
|
|
96
|
+
* The recurrence of the payment
|
|
87
97
|
*/
|
|
88
|
-
|
|
98
|
+
recurrence: {
|
|
89
99
|
/**
|
|
90
|
-
* The
|
|
100
|
+
* The recurrence cycle of the payment
|
|
91
101
|
*/
|
|
92
|
-
|
|
102
|
+
recurrence_cycle: string;
|
|
93
103
|
/**
|
|
94
|
-
* The
|
|
104
|
+
* The period of the recurrence, e.g `1`
|
|
95
105
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
recurrence_period: number;
|
|
107
|
+
/**
|
|
108
|
+
* The recurrence date to of the payment
|
|
109
|
+
*/
|
|
110
|
+
recurrence_date_to: string;
|
|
111
|
+
/**
|
|
112
|
+
* The state of the recurrence
|
|
113
|
+
*/
|
|
114
|
+
recurrence_state: 'REQUESTED' | 'STOPPED';
|
|
115
|
+
};
|
|
98
116
|
}
|
|
99
117
|
interface GoPayPaymentItem {
|
|
100
118
|
/**
|
|
@@ -211,7 +229,7 @@ interface GoPayPaymentRequest {
|
|
|
211
229
|
*/
|
|
212
230
|
items?: Array<{
|
|
213
231
|
/**
|
|
214
|
-
* The name of the item
|
|
232
|
+
* The name of the item, this resolves to the item_id in PayKit
|
|
215
233
|
*/
|
|
216
234
|
name: string;
|
|
217
235
|
/**
|
|
@@ -292,4 +310,4 @@ interface GoPayPaymentRequest {
|
|
|
292
310
|
preauthorization?: boolean;
|
|
293
311
|
}
|
|
294
312
|
|
|
295
|
-
export type { GoPayPaymentItem, GoPayPaymentRequest,
|
|
313
|
+
export type { GoPayPaymentBaseResponse, GoPayPaymentItem, GoPayPaymentRequest, GoPaySubscriptionResponse, GoPayTokenResponse };
|
package/dist/schema.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ interface GoPayTokenResponse {
|
|
|
2
2
|
/**
|
|
3
3
|
* The type of the token
|
|
4
4
|
*/
|
|
5
|
-
token_type:
|
|
5
|
+
token_type: 'bearer';
|
|
6
6
|
/**
|
|
7
7
|
* The access token
|
|
8
8
|
*/
|
|
@@ -12,7 +12,7 @@ interface GoPayTokenResponse {
|
|
|
12
12
|
*/
|
|
13
13
|
expires_in: number;
|
|
14
14
|
}
|
|
15
|
-
interface
|
|
15
|
+
interface GoPayPaymentBaseResponse {
|
|
16
16
|
/**
|
|
17
17
|
* The ID of the payment
|
|
18
18
|
*/
|
|
@@ -25,10 +25,6 @@ interface GoPayPaymentResponse {
|
|
|
25
25
|
* The state of the payment
|
|
26
26
|
*/
|
|
27
27
|
state: 'CREATED' | 'PAYMENT_METHOD_CHOSEN' | 'PAID' | 'AUTHORIZED' | 'CANCELED' | 'TIMEOUTED' | 'REFUNDED' | 'PARTIALLY_REFUNDED';
|
|
28
|
-
/**
|
|
29
|
-
* The sub state of the payment
|
|
30
|
-
*/
|
|
31
|
-
sub_state?: string;
|
|
32
28
|
/**
|
|
33
29
|
* The amount of the payment
|
|
34
30
|
*/
|
|
@@ -37,64 +33,86 @@ interface GoPayPaymentResponse {
|
|
|
37
33
|
* The currency of the payment
|
|
38
34
|
*/
|
|
39
35
|
currency: string;
|
|
40
|
-
/**
|
|
41
|
-
* The payment instrument of the payment
|
|
42
|
-
*/
|
|
43
|
-
payment_instrument?: string;
|
|
44
36
|
/**
|
|
45
37
|
* The payer of the payment
|
|
46
38
|
*/
|
|
47
|
-
payer
|
|
39
|
+
payer: {
|
|
40
|
+
/**
|
|
41
|
+
* The allowed payment instruments of the payer
|
|
42
|
+
*/
|
|
43
|
+
allowed_payment_instruments: string[];
|
|
44
|
+
/**
|
|
45
|
+
* The default payment instrument of the payer
|
|
46
|
+
*/
|
|
47
|
+
default_payment_instrument: string;
|
|
48
|
+
/**
|
|
49
|
+
* The contact of the payer
|
|
50
|
+
*/
|
|
51
|
+
contact: {
|
|
52
|
+
email: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
48
55
|
/**
|
|
49
56
|
* The target of the payment
|
|
50
57
|
*/
|
|
51
|
-
target
|
|
52
|
-
/**
|
|
53
|
-
* The recurrence of the payment
|
|
54
|
-
*/
|
|
55
|
-
recurrence?: {
|
|
58
|
+
target: {
|
|
56
59
|
/**
|
|
57
|
-
* The
|
|
60
|
+
* The type of the target
|
|
58
61
|
*/
|
|
59
|
-
|
|
62
|
+
type: 'ACCOUNT';
|
|
60
63
|
/**
|
|
61
|
-
* The
|
|
64
|
+
* The GoID of the target
|
|
62
65
|
*/
|
|
63
|
-
|
|
66
|
+
goid: number;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* The additional parameters of the payment
|
|
70
|
+
*/
|
|
71
|
+
additional_params?: Array<{
|
|
64
72
|
/**
|
|
65
|
-
* The
|
|
73
|
+
* The name of the additional parameter
|
|
66
74
|
*/
|
|
67
|
-
|
|
75
|
+
name: string;
|
|
68
76
|
/**
|
|
69
|
-
* The
|
|
77
|
+
* The value of the additional parameter
|
|
70
78
|
*/
|
|
71
|
-
|
|
72
|
-
}
|
|
79
|
+
value: string;
|
|
80
|
+
}>;
|
|
73
81
|
/**
|
|
74
|
-
* The
|
|
82
|
+
* The language of the payment
|
|
75
83
|
*/
|
|
76
|
-
|
|
84
|
+
lang?: string;
|
|
77
85
|
/**
|
|
78
86
|
* The GW URL of the payment
|
|
79
87
|
*/
|
|
80
88
|
gw_url?: string;
|
|
89
|
+
}
|
|
90
|
+
interface GoPaySubscriptionResponse extends GoPayPaymentBaseResponse {
|
|
81
91
|
/**
|
|
82
|
-
* The
|
|
92
|
+
* The payment instrument of the payment
|
|
83
93
|
*/
|
|
84
|
-
|
|
94
|
+
payment_instrument?: string;
|
|
85
95
|
/**
|
|
86
|
-
* The
|
|
96
|
+
* The recurrence of the payment
|
|
87
97
|
*/
|
|
88
|
-
|
|
98
|
+
recurrence: {
|
|
89
99
|
/**
|
|
90
|
-
* The
|
|
100
|
+
* The recurrence cycle of the payment
|
|
91
101
|
*/
|
|
92
|
-
|
|
102
|
+
recurrence_cycle: string;
|
|
93
103
|
/**
|
|
94
|
-
* The
|
|
104
|
+
* The period of the recurrence, e.g `1`
|
|
95
105
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
recurrence_period: number;
|
|
107
|
+
/**
|
|
108
|
+
* The recurrence date to of the payment
|
|
109
|
+
*/
|
|
110
|
+
recurrence_date_to: string;
|
|
111
|
+
/**
|
|
112
|
+
* The state of the recurrence
|
|
113
|
+
*/
|
|
114
|
+
recurrence_state: 'REQUESTED' | 'STOPPED';
|
|
115
|
+
};
|
|
98
116
|
}
|
|
99
117
|
interface GoPayPaymentItem {
|
|
100
118
|
/**
|
|
@@ -211,7 +229,7 @@ interface GoPayPaymentRequest {
|
|
|
211
229
|
*/
|
|
212
230
|
items?: Array<{
|
|
213
231
|
/**
|
|
214
|
-
* The name of the item
|
|
232
|
+
* The name of the item, this resolves to the item_id in PayKit
|
|
215
233
|
*/
|
|
216
234
|
name: string;
|
|
217
235
|
/**
|
|
@@ -292,4 +310,4 @@ interface GoPayPaymentRequest {
|
|
|
292
310
|
preauthorization?: boolean;
|
|
293
311
|
}
|
|
294
312
|
|
|
295
|
-
export type { GoPayPaymentItem, GoPayPaymentRequest,
|
|
313
|
+
export type { GoPayPaymentBaseResponse, GoPayPaymentItem, GoPayPaymentRequest, GoPaySubscriptionResponse, GoPayTokenResponse };
|
package/dist/utils/mapper.d.mts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { Payment, Invoice, Subscription, Refund } from '@paykit-sdk/core';
|
|
2
|
-
import {
|
|
1
|
+
import { Payment, Checkout, Invoice, Subscription, Refund } from '@paykit-sdk/core';
|
|
2
|
+
import { GoPayPaymentBaseResponse, GoPaySubscriptionResponse } from '../schema.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Decodes HTML entities that GoPay returns for JSON strings
|
|
6
|
+
* GoPay HTML-encodes values containing special characters (quotes, etc.)
|
|
7
|
+
*/
|
|
8
|
+
declare const decodeHtmlEntities: (str: string) => string;
|
|
9
|
+
declare const paykitPayment$InboundSchema: (data: GoPayPaymentBaseResponse) => Payment;
|
|
10
|
+
declare const paykitCheckout$InboundSchema: (data: GoPayPaymentBaseResponse) => Checkout;
|
|
11
|
+
declare const paykitInvoice$InboundSchema: <T extends "payment" | "subscription">(data: T extends "payment" ? GoPayPaymentBaseResponse : GoPaySubscriptionResponse, isSubscription: boolean) => Invoice;
|
|
12
|
+
declare const paykitSubscription$InboundSchema: (data: GoPaySubscriptionResponse) => Subscription;
|
|
7
13
|
/**
|
|
8
14
|
* Refund
|
|
9
15
|
*/
|
|
10
|
-
declare const paykitRefund$InboundSchema: (data:
|
|
16
|
+
declare const paykitRefund$InboundSchema: (data: GoPayPaymentBaseResponse) => Refund;
|
|
11
17
|
|
|
12
|
-
export { paykitInvoice$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
|
|
18
|
+
export { decodeHtmlEntities, paykitCheckout$InboundSchema, paykitInvoice$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
|
package/dist/utils/mapper.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { Payment, Invoice, Subscription, Refund } from '@paykit-sdk/core';
|
|
2
|
-
import {
|
|
1
|
+
import { Payment, Checkout, Invoice, Subscription, Refund } from '@paykit-sdk/core';
|
|
2
|
+
import { GoPayPaymentBaseResponse, GoPaySubscriptionResponse } from '../schema.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Decodes HTML entities that GoPay returns for JSON strings
|
|
6
|
+
* GoPay HTML-encodes values containing special characters (quotes, etc.)
|
|
7
|
+
*/
|
|
8
|
+
declare const decodeHtmlEntities: (str: string) => string;
|
|
9
|
+
declare const paykitPayment$InboundSchema: (data: GoPayPaymentBaseResponse) => Payment;
|
|
10
|
+
declare const paykitCheckout$InboundSchema: (data: GoPayPaymentBaseResponse) => Checkout;
|
|
11
|
+
declare const paykitInvoice$InboundSchema: <T extends "payment" | "subscription">(data: T extends "payment" ? GoPayPaymentBaseResponse : GoPaySubscriptionResponse, isSubscription: boolean) => Invoice;
|
|
12
|
+
declare const paykitSubscription$InboundSchema: (data: GoPaySubscriptionResponse) => Subscription;
|
|
7
13
|
/**
|
|
8
14
|
* Refund
|
|
9
15
|
*/
|
|
10
|
-
declare const paykitRefund$InboundSchema: (data:
|
|
16
|
+
declare const paykitRefund$InboundSchema: (data: GoPayPaymentBaseResponse) => Refund;
|
|
11
17
|
|
|
12
|
-
export { paykitInvoice$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
|
|
18
|
+
export { decodeHtmlEntities, paykitCheckout$InboundSchema, paykitInvoice$InboundSchema, paykitPayment$InboundSchema, paykitRefund$InboundSchema, paykitSubscription$InboundSchema };
|
package/dist/utils/mapper.js
CHANGED
|
@@ -3,10 +3,53 @@
|
|
|
3
3
|
var core = require('@paykit-sdk/core');
|
|
4
4
|
|
|
5
5
|
// src/utils/mapper.ts
|
|
6
|
+
var decodeHtmlEntities = (str) => {
|
|
7
|
+
return str.replace(/"/g, '"').replace(/'/g, "'").replace(/"/g, '"').replace(/'/g, "'");
|
|
8
|
+
};
|
|
6
9
|
var paykitPayment$InboundSchema = (data) => {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
const { item } = JSON.parse(
|
|
11
|
+
decodeHtmlEntities(
|
|
12
|
+
data.additional_params?.find((param) => param.name === core.PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
const metadata = core.omitInternalMetadata(
|
|
16
|
+
data.additional_params?.reduce(
|
|
17
|
+
(acc, param) => {
|
|
18
|
+
acc[param.name] = String(param.value);
|
|
19
|
+
return acc;
|
|
20
|
+
},
|
|
21
|
+
{}
|
|
22
|
+
) ?? {}
|
|
23
|
+
);
|
|
24
|
+
const statusMap = {
|
|
25
|
+
CREATED: "pending",
|
|
26
|
+
PAYMENT_METHOD_CHOSEN: "processing",
|
|
27
|
+
PAID: "succeeded",
|
|
28
|
+
AUTHORIZED: "requires_capture",
|
|
29
|
+
CANCELED: "canceled",
|
|
30
|
+
TIMEOUTED: "canceled",
|
|
31
|
+
REFUNDED: "canceled",
|
|
32
|
+
PARTIALLY_REFUNDED: "canceled"
|
|
33
|
+
};
|
|
34
|
+
const requiresAction = data.state === "CREATED" || data.state === "AUTHORIZED" ? true : false;
|
|
35
|
+
return {
|
|
36
|
+
id: data.id.toString(),
|
|
37
|
+
amount: data.amount,
|
|
38
|
+
currency: data.currency,
|
|
39
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : "",
|
|
40
|
+
status: statusMap[data.state],
|
|
41
|
+
item_id: item,
|
|
42
|
+
metadata,
|
|
43
|
+
requires_action: requiresAction,
|
|
44
|
+
payment_url: data.gw_url ?? null
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
var paykitCheckout$InboundSchema = (data) => {
|
|
48
|
+
const { item, qty, type } = JSON.parse(
|
|
49
|
+
decodeHtmlEntities(
|
|
50
|
+
data.additional_params?.find((param) => param.name === core.PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
51
|
+
)
|
|
52
|
+
);
|
|
10
53
|
const metadata = core.omitInternalMetadata(
|
|
11
54
|
data.additional_params?.reduce(
|
|
12
55
|
(acc, param) => {
|
|
@@ -20,24 +63,24 @@ var paykitPayment$InboundSchema = (data) => {
|
|
|
20
63
|
id: data.id.toString(),
|
|
21
64
|
amount: data.amount,
|
|
22
65
|
currency: data.currency,
|
|
23
|
-
customer: data.payer
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
66
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : "",
|
|
67
|
+
payment_url: data.gw_url ?? "",
|
|
68
|
+
metadata,
|
|
69
|
+
session_type: type,
|
|
70
|
+
products: [{ id: item, quantity: parseInt(qty) }]
|
|
27
71
|
};
|
|
28
72
|
};
|
|
29
73
|
var paykitInvoice$InboundSchema = (data, isSubscription) => {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
).itemId;
|
|
74
|
+
const { item, qty } = JSON.parse(
|
|
75
|
+
decodeHtmlEntities(
|
|
76
|
+
data.additional_params?.find((param) => param.name === core.PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
77
|
+
)
|
|
78
|
+
);
|
|
36
79
|
const status = (() => {
|
|
37
80
|
if (data.state === "PAID") return "paid";
|
|
38
81
|
return "open";
|
|
39
82
|
})();
|
|
40
|
-
const paidAt = isSubscription ? new Date(data.recurrence?.
|
|
83
|
+
const paidAt = isSubscription ? new Date(data.recurrence?.recurrence_date_to ?? "") : /* @__PURE__ */ new Date();
|
|
41
84
|
const metadata = core.omitInternalMetadata(
|
|
42
85
|
data.additional_params?.reduce(
|
|
43
86
|
(acc, param) => {
|
|
@@ -51,20 +94,22 @@ var paykitInvoice$InboundSchema = (data, isSubscription) => {
|
|
|
51
94
|
id: data.id.toString(),
|
|
52
95
|
amount_paid: data.amount,
|
|
53
96
|
currency: data.currency,
|
|
54
|
-
customer: data.payer
|
|
97
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : "",
|
|
55
98
|
status,
|
|
56
99
|
paid_at: paidAt.toISOString(),
|
|
57
100
|
metadata: metadata ?? {},
|
|
58
101
|
custom_fields: null,
|
|
59
102
|
subscription_id: isSubscription ? data.id.toString() : null,
|
|
60
103
|
billing_mode: isSubscription ? "recurring" : "one_time",
|
|
61
|
-
line_items: [{ id:
|
|
104
|
+
line_items: [{ id: item, quantity: parseInt(qty) }]
|
|
62
105
|
};
|
|
63
106
|
};
|
|
64
107
|
var paykitSubscription$InboundSchema = (data) => {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
108
|
+
const { item } = JSON.parse(
|
|
109
|
+
decodeHtmlEntities(
|
|
110
|
+
data.additional_params?.find((param) => param.name === core.PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
111
|
+
)
|
|
112
|
+
);
|
|
68
113
|
const billingIntervalMap = {
|
|
69
114
|
DAY: "day",
|
|
70
115
|
WEEK: "week",
|
|
@@ -72,8 +117,28 @@ var paykitSubscription$InboundSchema = (data) => {
|
|
|
72
117
|
ON_DEMAND: "month"
|
|
73
118
|
};
|
|
74
119
|
const billingInterval = billingIntervalMap[data.recurrence?.recurrence_cycle ?? "ON_DEMAND"];
|
|
75
|
-
const
|
|
120
|
+
const recurrencePeriod = data.recurrence?.recurrence_period ?? 1;
|
|
121
|
+
const recurrenceCycle = data.recurrence?.recurrence_cycle;
|
|
76
122
|
const currentPeriodEnd = new Date(data.recurrence?.recurrence_date_to ?? "");
|
|
123
|
+
const currentPeriodStart = (() => {
|
|
124
|
+
if (!currentPeriodEnd) return /* @__PURE__ */ new Date();
|
|
125
|
+
const endDate = new Date(currentPeriodEnd);
|
|
126
|
+
const startDate = new Date(endDate);
|
|
127
|
+
switch (recurrenceCycle) {
|
|
128
|
+
case "DAY":
|
|
129
|
+
startDate.setDate(startDate.getDate() - recurrencePeriod);
|
|
130
|
+
break;
|
|
131
|
+
case "WEEK":
|
|
132
|
+
startDate.setDate(startDate.getDate() - recurrencePeriod * 7);
|
|
133
|
+
break;
|
|
134
|
+
case "MONTH":
|
|
135
|
+
startDate.setMonth(startDate.getMonth() - recurrencePeriod);
|
|
136
|
+
break;
|
|
137
|
+
default:
|
|
138
|
+
startDate.setDate(startDate.getDate() - recurrencePeriod);
|
|
139
|
+
}
|
|
140
|
+
return startDate;
|
|
141
|
+
})();
|
|
77
142
|
const metadata = core.omitInternalMetadata(
|
|
78
143
|
data.additional_params?.reduce(
|
|
79
144
|
(acc, param) => {
|
|
@@ -83,18 +148,32 @@ var paykitSubscription$InboundSchema = (data) => {
|
|
|
83
148
|
{}
|
|
84
149
|
) ?? {}
|
|
85
150
|
);
|
|
151
|
+
const requiresAction = data.state === "CREATED" ? true : false;
|
|
152
|
+
const status = (() => {
|
|
153
|
+
if (data.state === "CREATED") return "pending";
|
|
154
|
+
if (data.state === "PAID") return "active";
|
|
155
|
+
if (data.state === "CANCELED") return "canceled";
|
|
156
|
+
if (data.state === "TIMEOUTED") return "canceled";
|
|
157
|
+
if (data.state === "REFUNDED") return "canceled";
|
|
158
|
+
if (data.state === "PARTIALLY_REFUNDED") return "canceled";
|
|
159
|
+
if (data.state === "AUTHORIZED") return "active";
|
|
160
|
+
if (data.state === "PAYMENT_METHOD_CHOSEN") return "active";
|
|
161
|
+
return "pending";
|
|
162
|
+
})();
|
|
86
163
|
return {
|
|
87
164
|
id: data.id.toString(),
|
|
88
|
-
status
|
|
89
|
-
customer: data.payer
|
|
90
|
-
item_id:
|
|
165
|
+
status,
|
|
166
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : "",
|
|
167
|
+
item_id: item,
|
|
91
168
|
billing_interval: billingInterval,
|
|
92
169
|
currency: data.currency,
|
|
93
170
|
amount: data.amount,
|
|
94
|
-
metadata
|
|
171
|
+
metadata,
|
|
95
172
|
custom_fields: null,
|
|
96
173
|
current_period_start: currentPeriodStart,
|
|
97
|
-
current_period_end: currentPeriodEnd
|
|
174
|
+
current_period_end: currentPeriodEnd,
|
|
175
|
+
requires_action: requiresAction,
|
|
176
|
+
payment_url: requiresAction ? data.gw_url ?? null : null
|
|
98
177
|
};
|
|
99
178
|
};
|
|
100
179
|
var paykitRefund$InboundSchema = (data) => {
|
|
@@ -107,6 +186,8 @@ var paykitRefund$InboundSchema = (data) => {
|
|
|
107
186
|
};
|
|
108
187
|
};
|
|
109
188
|
|
|
189
|
+
exports.decodeHtmlEntities = decodeHtmlEntities;
|
|
190
|
+
exports.paykitCheckout$InboundSchema = paykitCheckout$InboundSchema;
|
|
110
191
|
exports.paykitInvoice$InboundSchema = paykitInvoice$InboundSchema;
|
|
111
192
|
exports.paykitPayment$InboundSchema = paykitPayment$InboundSchema;
|
|
112
193
|
exports.paykitRefund$InboundSchema = paykitRefund$InboundSchema;
|