@paykit-sdk/gopay 1.0.5 → 1.1.2
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/gopay-provider.d.mts +1 -5
- package/dist/gopay-provider.d.ts +1 -5
- package/dist/gopay-provider.js +290 -179
- package/dist/gopay-provider.mjs +291 -180
- package/dist/index.js +296 -182
- package/dist/index.mjs +297 -183
- package/dist/schema.d.mts +55 -51
- package/dist/schema.d.ts +55 -51
- 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 +8 -8
- package/dist/controllers/auth.d.mts +0 -19
- package/dist/controllers/auth.d.ts +0 -19
- package/dist/controllers/auth.js +0 -57
- package/dist/controllers/auth.mjs +0 -55
package/dist/schema.d.mts
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
interface
|
|
2
|
-
/**
|
|
3
|
-
* The type of the token
|
|
4
|
-
*/
|
|
5
|
-
token_type: string;
|
|
6
|
-
/**
|
|
7
|
-
* The access token
|
|
8
|
-
*/
|
|
9
|
-
access_token: string;
|
|
10
|
-
/**
|
|
11
|
-
* The expiry time of the token
|
|
12
|
-
*/
|
|
13
|
-
expires_in: number;
|
|
14
|
-
}
|
|
15
|
-
interface GoPayPaymentResponse {
|
|
1
|
+
interface GoPayPaymentBaseResponse {
|
|
16
2
|
/**
|
|
17
3
|
* The ID of the payment
|
|
18
4
|
*/
|
|
@@ -25,10 +11,6 @@ interface GoPayPaymentResponse {
|
|
|
25
11
|
* The state of the payment
|
|
26
12
|
*/
|
|
27
13
|
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
14
|
/**
|
|
33
15
|
* The amount of the payment
|
|
34
16
|
*/
|
|
@@ -37,64 +19,86 @@ interface GoPayPaymentResponse {
|
|
|
37
19
|
* The currency of the payment
|
|
38
20
|
*/
|
|
39
21
|
currency: string;
|
|
40
|
-
/**
|
|
41
|
-
* The payment instrument of the payment
|
|
42
|
-
*/
|
|
43
|
-
payment_instrument?: string;
|
|
44
22
|
/**
|
|
45
23
|
* The payer of the payment
|
|
46
24
|
*/
|
|
47
|
-
payer
|
|
25
|
+
payer: {
|
|
26
|
+
/**
|
|
27
|
+
* The allowed payment instruments of the payer
|
|
28
|
+
*/
|
|
29
|
+
allowed_payment_instruments: string[];
|
|
30
|
+
/**
|
|
31
|
+
* The default payment instrument of the payer
|
|
32
|
+
*/
|
|
33
|
+
default_payment_instrument: string;
|
|
34
|
+
/**
|
|
35
|
+
* The contact of the payer
|
|
36
|
+
*/
|
|
37
|
+
contact: {
|
|
38
|
+
email: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
48
41
|
/**
|
|
49
42
|
* The target of the payment
|
|
50
43
|
*/
|
|
51
|
-
target
|
|
52
|
-
/**
|
|
53
|
-
* The recurrence of the payment
|
|
54
|
-
*/
|
|
55
|
-
recurrence?: {
|
|
44
|
+
target: {
|
|
56
45
|
/**
|
|
57
|
-
* The
|
|
46
|
+
* The type of the target
|
|
58
47
|
*/
|
|
59
|
-
|
|
48
|
+
type: 'ACCOUNT';
|
|
60
49
|
/**
|
|
61
|
-
* The
|
|
50
|
+
* The GoID of the target
|
|
62
51
|
*/
|
|
63
|
-
|
|
52
|
+
goid: number;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The additional parameters of the payment
|
|
56
|
+
*/
|
|
57
|
+
additional_params?: Array<{
|
|
64
58
|
/**
|
|
65
|
-
* The
|
|
59
|
+
* The name of the additional parameter
|
|
66
60
|
*/
|
|
67
|
-
|
|
61
|
+
name: string;
|
|
68
62
|
/**
|
|
69
|
-
* The
|
|
63
|
+
* The value of the additional parameter
|
|
70
64
|
*/
|
|
71
|
-
|
|
72
|
-
}
|
|
65
|
+
value: string;
|
|
66
|
+
}>;
|
|
73
67
|
/**
|
|
74
|
-
* The
|
|
68
|
+
* The language of the payment
|
|
75
69
|
*/
|
|
76
|
-
|
|
70
|
+
lang?: string;
|
|
77
71
|
/**
|
|
78
72
|
* The GW URL of the payment
|
|
79
73
|
*/
|
|
80
74
|
gw_url?: string;
|
|
75
|
+
}
|
|
76
|
+
interface GoPaySubscriptionResponse extends GoPayPaymentBaseResponse {
|
|
81
77
|
/**
|
|
82
|
-
* The
|
|
78
|
+
* The payment instrument of the payment
|
|
83
79
|
*/
|
|
84
|
-
|
|
80
|
+
payment_instrument?: string;
|
|
85
81
|
/**
|
|
86
|
-
* The
|
|
82
|
+
* The recurrence of the payment
|
|
87
83
|
*/
|
|
88
|
-
|
|
84
|
+
recurrence: {
|
|
89
85
|
/**
|
|
90
|
-
* The
|
|
86
|
+
* The recurrence cycle of the payment
|
|
91
87
|
*/
|
|
92
|
-
|
|
88
|
+
recurrence_cycle: string;
|
|
93
89
|
/**
|
|
94
|
-
* The
|
|
90
|
+
* The period of the recurrence, e.g `1`
|
|
95
91
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
recurrence_period: number;
|
|
93
|
+
/**
|
|
94
|
+
* The recurrence date to of the payment
|
|
95
|
+
*/
|
|
96
|
+
recurrence_date_to: string;
|
|
97
|
+
/**
|
|
98
|
+
* The state of the recurrence
|
|
99
|
+
*/
|
|
100
|
+
recurrence_state: 'REQUESTED' | 'STOPPED';
|
|
101
|
+
};
|
|
98
102
|
}
|
|
99
103
|
interface GoPayPaymentItem {
|
|
100
104
|
/**
|
|
@@ -211,7 +215,7 @@ interface GoPayPaymentRequest {
|
|
|
211
215
|
*/
|
|
212
216
|
items?: Array<{
|
|
213
217
|
/**
|
|
214
|
-
* The name of the item
|
|
218
|
+
* The name of the item, this resolves to the item_id in PayKit
|
|
215
219
|
*/
|
|
216
220
|
name: string;
|
|
217
221
|
/**
|
|
@@ -292,4 +296,4 @@ interface GoPayPaymentRequest {
|
|
|
292
296
|
preauthorization?: boolean;
|
|
293
297
|
}
|
|
294
298
|
|
|
295
|
-
export type { GoPayPaymentItem, GoPayPaymentRequest,
|
|
299
|
+
export type { GoPayPaymentBaseResponse, GoPayPaymentItem, GoPayPaymentRequest, GoPaySubscriptionResponse };
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
interface
|
|
2
|
-
/**
|
|
3
|
-
* The type of the token
|
|
4
|
-
*/
|
|
5
|
-
token_type: string;
|
|
6
|
-
/**
|
|
7
|
-
* The access token
|
|
8
|
-
*/
|
|
9
|
-
access_token: string;
|
|
10
|
-
/**
|
|
11
|
-
* The expiry time of the token
|
|
12
|
-
*/
|
|
13
|
-
expires_in: number;
|
|
14
|
-
}
|
|
15
|
-
interface GoPayPaymentResponse {
|
|
1
|
+
interface GoPayPaymentBaseResponse {
|
|
16
2
|
/**
|
|
17
3
|
* The ID of the payment
|
|
18
4
|
*/
|
|
@@ -25,10 +11,6 @@ interface GoPayPaymentResponse {
|
|
|
25
11
|
* The state of the payment
|
|
26
12
|
*/
|
|
27
13
|
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
14
|
/**
|
|
33
15
|
* The amount of the payment
|
|
34
16
|
*/
|
|
@@ -37,64 +19,86 @@ interface GoPayPaymentResponse {
|
|
|
37
19
|
* The currency of the payment
|
|
38
20
|
*/
|
|
39
21
|
currency: string;
|
|
40
|
-
/**
|
|
41
|
-
* The payment instrument of the payment
|
|
42
|
-
*/
|
|
43
|
-
payment_instrument?: string;
|
|
44
22
|
/**
|
|
45
23
|
* The payer of the payment
|
|
46
24
|
*/
|
|
47
|
-
payer
|
|
25
|
+
payer: {
|
|
26
|
+
/**
|
|
27
|
+
* The allowed payment instruments of the payer
|
|
28
|
+
*/
|
|
29
|
+
allowed_payment_instruments: string[];
|
|
30
|
+
/**
|
|
31
|
+
* The default payment instrument of the payer
|
|
32
|
+
*/
|
|
33
|
+
default_payment_instrument: string;
|
|
34
|
+
/**
|
|
35
|
+
* The contact of the payer
|
|
36
|
+
*/
|
|
37
|
+
contact: {
|
|
38
|
+
email: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
48
41
|
/**
|
|
49
42
|
* The target of the payment
|
|
50
43
|
*/
|
|
51
|
-
target
|
|
52
|
-
/**
|
|
53
|
-
* The recurrence of the payment
|
|
54
|
-
*/
|
|
55
|
-
recurrence?: {
|
|
44
|
+
target: {
|
|
56
45
|
/**
|
|
57
|
-
* The
|
|
46
|
+
* The type of the target
|
|
58
47
|
*/
|
|
59
|
-
|
|
48
|
+
type: 'ACCOUNT';
|
|
60
49
|
/**
|
|
61
|
-
* The
|
|
50
|
+
* The GoID of the target
|
|
62
51
|
*/
|
|
63
|
-
|
|
52
|
+
goid: number;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* The additional parameters of the payment
|
|
56
|
+
*/
|
|
57
|
+
additional_params?: Array<{
|
|
64
58
|
/**
|
|
65
|
-
* The
|
|
59
|
+
* The name of the additional parameter
|
|
66
60
|
*/
|
|
67
|
-
|
|
61
|
+
name: string;
|
|
68
62
|
/**
|
|
69
|
-
* The
|
|
63
|
+
* The value of the additional parameter
|
|
70
64
|
*/
|
|
71
|
-
|
|
72
|
-
}
|
|
65
|
+
value: string;
|
|
66
|
+
}>;
|
|
73
67
|
/**
|
|
74
|
-
* The
|
|
68
|
+
* The language of the payment
|
|
75
69
|
*/
|
|
76
|
-
|
|
70
|
+
lang?: string;
|
|
77
71
|
/**
|
|
78
72
|
* The GW URL of the payment
|
|
79
73
|
*/
|
|
80
74
|
gw_url?: string;
|
|
75
|
+
}
|
|
76
|
+
interface GoPaySubscriptionResponse extends GoPayPaymentBaseResponse {
|
|
81
77
|
/**
|
|
82
|
-
* The
|
|
78
|
+
* The payment instrument of the payment
|
|
83
79
|
*/
|
|
84
|
-
|
|
80
|
+
payment_instrument?: string;
|
|
85
81
|
/**
|
|
86
|
-
* The
|
|
82
|
+
* The recurrence of the payment
|
|
87
83
|
*/
|
|
88
|
-
|
|
84
|
+
recurrence: {
|
|
89
85
|
/**
|
|
90
|
-
* The
|
|
86
|
+
* The recurrence cycle of the payment
|
|
91
87
|
*/
|
|
92
|
-
|
|
88
|
+
recurrence_cycle: string;
|
|
93
89
|
/**
|
|
94
|
-
* The
|
|
90
|
+
* The period of the recurrence, e.g `1`
|
|
95
91
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
recurrence_period: number;
|
|
93
|
+
/**
|
|
94
|
+
* The recurrence date to of the payment
|
|
95
|
+
*/
|
|
96
|
+
recurrence_date_to: string;
|
|
97
|
+
/**
|
|
98
|
+
* The state of the recurrence
|
|
99
|
+
*/
|
|
100
|
+
recurrence_state: 'REQUESTED' | 'STOPPED';
|
|
101
|
+
};
|
|
98
102
|
}
|
|
99
103
|
interface GoPayPaymentItem {
|
|
100
104
|
/**
|
|
@@ -211,7 +215,7 @@ interface GoPayPaymentRequest {
|
|
|
211
215
|
*/
|
|
212
216
|
items?: Array<{
|
|
213
217
|
/**
|
|
214
|
-
* The name of the item
|
|
218
|
+
* The name of the item, this resolves to the item_id in PayKit
|
|
215
219
|
*/
|
|
216
220
|
name: string;
|
|
217
221
|
/**
|
|
@@ -292,4 +296,4 @@ interface GoPayPaymentRequest {
|
|
|
292
296
|
preauthorization?: boolean;
|
|
293
297
|
}
|
|
294
298
|
|
|
295
|
-
export type { GoPayPaymentItem, GoPayPaymentRequest,
|
|
299
|
+
export type { GoPayPaymentBaseResponse, GoPayPaymentItem, GoPayPaymentRequest, GoPaySubscriptionResponse };
|
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;
|