@paykit-sdk/xendit 1.0.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.
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Xendit's error envelope, returned on any non-2xx response, e.g.
3
+ * `{ error_code: "INVALID_REQUEST", message: "..." }`
4
+ */
5
+ interface XenditErrorResponse {
6
+ error_code: string;
7
+ message: string;
8
+ }
9
+ interface XenditInvoiceItem {
10
+ name: string;
11
+ quantity: number;
12
+ price: number;
13
+ category?: string;
14
+ }
15
+ interface XenditInvoiceCustomer {
16
+ given_names?: string;
17
+ surname?: string;
18
+ email?: string;
19
+ mobile_number?: string;
20
+ }
21
+ /**
22
+ * The shape returned by `POST /v2/invoices/` and `GET /v2/invoices/:id`
23
+ * (Xendit's hosted checkout page).
24
+ */
25
+ interface XenditInvoice {
26
+ id: string;
27
+ external_id: string;
28
+ user_id: string;
29
+ status: 'PENDING' | 'PAID' | 'SETTLED' | 'EXPIRED';
30
+ merchant_name?: string;
31
+ amount: number;
32
+ payer_email?: string;
33
+ description?: string;
34
+ paid_amount?: number;
35
+ created: string;
36
+ updated: string;
37
+ currency: string;
38
+ expiry_date: string;
39
+ invoice_url: string;
40
+ paid_at?: string;
41
+ payment_method?: string;
42
+ payment_channel?: string;
43
+ payment_id?: string;
44
+ success_redirect_url?: string;
45
+ failure_redirect_url?: string;
46
+ items?: XenditInvoiceItem[];
47
+ customer?: XenditInvoiceCustomer;
48
+ metadata?: Record<string, unknown> | null;
49
+ recurring_payment_id?: string;
50
+ }
51
+ /**
52
+ * The shape returned by `POST /customers`, `GET /customers/:id`, and
53
+ * `PATCH /customers/:id`.
54
+ */
55
+ interface XenditCustomer {
56
+ id: string;
57
+ reference_id: string;
58
+ type?: 'INDIVIDUAL' | 'BUSINESS';
59
+ individual_detail?: {
60
+ given_names?: string;
61
+ surname?: string | null;
62
+ } | null;
63
+ email: string | null;
64
+ mobile_number: string | null;
65
+ phone_number?: string | null;
66
+ description?: string | null;
67
+ metadata: Record<string, unknown> | null;
68
+ created: string;
69
+ updated: string;
70
+ }
71
+ /**
72
+ * Interval unit accepted by the Recurring Plans API - `YEAR` is not
73
+ * supported natively and is translated to `MONTH` with `interval_count: 12`.
74
+ */
75
+ type XenditRecurringInterval = 'DAY' | 'WEEK' | 'MONTH';
76
+ interface XenditRecurringSchedule {
77
+ interval: XenditRecurringInterval;
78
+ interval_count: number;
79
+ total_recurrence?: number | null;
80
+ anchor_date?: string;
81
+ retry_interval?: string;
82
+ retry_interval_count?: number;
83
+ total_retry?: number;
84
+ created?: string;
85
+ updated?: string;
86
+ }
87
+ interface XenditPaymentToken {
88
+ payment_token_id: string;
89
+ rank: number;
90
+ }
91
+ /**
92
+ * The shape returned by `POST /recurring/plans`, `GET /recurring/plans/:id`,
93
+ * and `POST /recurring/plans/:id/deactivate`.
94
+ */
95
+ interface XenditRecurringPlan {
96
+ id: string;
97
+ reference_id: string;
98
+ customer_id: string;
99
+ currency: string;
100
+ amount: number;
101
+ status: 'ACTIVE' | 'INACTIVE' | 'PENDING' | 'REQUIRES_ACTION';
102
+ country?: string;
103
+ recurring_cycle_count?: number;
104
+ schedule: XenditRecurringSchedule;
105
+ payment_tokens: XenditPaymentToken[];
106
+ immediate_payment?: boolean;
107
+ failed_cycle_action?: 'RESUME' | 'STOP';
108
+ metadata?: Record<string, unknown> | null;
109
+ description?: string | null;
110
+ created: string;
111
+ updated: string;
112
+ actions?: Array<{
113
+ action: string;
114
+ url_type: string;
115
+ url: string;
116
+ method: string;
117
+ }>;
118
+ }
119
+ /**
120
+ * The shape returned by `POST /refunds` and `GET /refunds/:id`.
121
+ */
122
+ interface XenditRefund {
123
+ id: string;
124
+ payment_id?: string;
125
+ payment_request_id?: string;
126
+ invoice_id?: string;
127
+ amount: number;
128
+ currency: string;
129
+ channel_code?: string;
130
+ status: 'PENDING' | 'SUCCEEDED' | 'FAILED' | 'CANCELLED';
131
+ reason?: string;
132
+ reference_id?: string | null;
133
+ failure_code?: string | null;
134
+ metadata?: Record<string, unknown> | null;
135
+ created: string;
136
+ updated: string;
137
+ }
138
+ /**
139
+ * The Invoice Callback body is the invoice resource itself, sent
140
+ * unwrapped at the top level - there is no separate `event`/`data`
141
+ * envelope for invoice webhooks (unlike Recurring webhooks below).
142
+ */
143
+ type XenditInvoiceCallback = XenditInvoice;
144
+ /**
145
+ * Recurring webhooks (unlike invoice callbacks) use a wrapping
146
+ * `{ event, business_id, created, data }` envelope, reflecting a newer
147
+ * generation of Xendit's API.
148
+ */
149
+ interface XenditRecurringCycle {
150
+ id: string;
151
+ reference_id?: string;
152
+ plan_id?: string;
153
+ customer_id?: string;
154
+ cycle_number?: number;
155
+ attempt_count?: number;
156
+ status: 'SCHEDULED' | 'SUCCEEDED' | 'RETRYING' | 'FAILED';
157
+ scheduled_timestamp?: string;
158
+ currency: string;
159
+ amount: number;
160
+ created?: string;
161
+ updated?: string;
162
+ metadata?: Record<string, unknown> | null;
163
+ }
164
+ interface XenditRecurringPlanWebhookEvent {
165
+ event: 'recurring.plan.activated' | 'recurring.plan.inactivated';
166
+ business_id: string;
167
+ created: string;
168
+ data: XenditRecurringPlan;
169
+ }
170
+ interface XenditRecurringCycleWebhookEvent {
171
+ event: 'recurring.cycle.created' | 'recurring.cycle.succeeded' | 'recurring.cycle.retrying' | 'recurring.cycle.failed';
172
+ business_id: string;
173
+ created: string;
174
+ data: XenditRecurringCycle;
175
+ }
176
+ type XenditRecurringWebhookEvent = XenditRecurringPlanWebhookEvent | XenditRecurringCycleWebhookEvent;
177
+ type XenditWebhookEvent = XenditInvoiceCallback | XenditRecurringWebhookEvent;
178
+ declare const isXenditRecurringWebhookEvent: (event: XenditWebhookEvent) => event is XenditRecurringWebhookEvent;
179
+ type XenditRawEvents = {
180
+ 'xendit.invoice.pending': XenditInvoiceCallback;
181
+ 'xendit.invoice.paid': XenditInvoiceCallback;
182
+ 'xendit.invoice.settled': XenditInvoiceCallback;
183
+ 'xendit.invoice.expired': XenditInvoiceCallback;
184
+ 'xendit.recurring.plan.activated': XenditRecurringPlanWebhookEvent;
185
+ 'xendit.recurring.plan.inactivated': XenditRecurringPlanWebhookEvent;
186
+ 'xendit.recurring.cycle.created': XenditRecurringCycleWebhookEvent;
187
+ 'xendit.recurring.cycle.succeeded': XenditRecurringCycleWebhookEvent;
188
+ 'xendit.recurring.cycle.retrying': XenditRecurringCycleWebhookEvent;
189
+ 'xendit.recurring.cycle.failed': XenditRecurringCycleWebhookEvent;
190
+ };
191
+
192
+ export { type XenditCustomer, type XenditErrorResponse, type XenditInvoice, type XenditInvoiceCallback, type XenditInvoiceCustomer, type XenditInvoiceItem, type XenditPaymentToken, type XenditRawEvents, type XenditRecurringCycle, type XenditRecurringCycleWebhookEvent, type XenditRecurringInterval, type XenditRecurringPlan, type XenditRecurringPlanWebhookEvent, type XenditRecurringSchedule, type XenditRecurringWebhookEvent, type XenditRefund, type XenditWebhookEvent, isXenditRecurringWebhookEvent };
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Xendit's error envelope, returned on any non-2xx response, e.g.
3
+ * `{ error_code: "INVALID_REQUEST", message: "..." }`
4
+ */
5
+ interface XenditErrorResponse {
6
+ error_code: string;
7
+ message: string;
8
+ }
9
+ interface XenditInvoiceItem {
10
+ name: string;
11
+ quantity: number;
12
+ price: number;
13
+ category?: string;
14
+ }
15
+ interface XenditInvoiceCustomer {
16
+ given_names?: string;
17
+ surname?: string;
18
+ email?: string;
19
+ mobile_number?: string;
20
+ }
21
+ /**
22
+ * The shape returned by `POST /v2/invoices/` and `GET /v2/invoices/:id`
23
+ * (Xendit's hosted checkout page).
24
+ */
25
+ interface XenditInvoice {
26
+ id: string;
27
+ external_id: string;
28
+ user_id: string;
29
+ status: 'PENDING' | 'PAID' | 'SETTLED' | 'EXPIRED';
30
+ merchant_name?: string;
31
+ amount: number;
32
+ payer_email?: string;
33
+ description?: string;
34
+ paid_amount?: number;
35
+ created: string;
36
+ updated: string;
37
+ currency: string;
38
+ expiry_date: string;
39
+ invoice_url: string;
40
+ paid_at?: string;
41
+ payment_method?: string;
42
+ payment_channel?: string;
43
+ payment_id?: string;
44
+ success_redirect_url?: string;
45
+ failure_redirect_url?: string;
46
+ items?: XenditInvoiceItem[];
47
+ customer?: XenditInvoiceCustomer;
48
+ metadata?: Record<string, unknown> | null;
49
+ recurring_payment_id?: string;
50
+ }
51
+ /**
52
+ * The shape returned by `POST /customers`, `GET /customers/:id`, and
53
+ * `PATCH /customers/:id`.
54
+ */
55
+ interface XenditCustomer {
56
+ id: string;
57
+ reference_id: string;
58
+ type?: 'INDIVIDUAL' | 'BUSINESS';
59
+ individual_detail?: {
60
+ given_names?: string;
61
+ surname?: string | null;
62
+ } | null;
63
+ email: string | null;
64
+ mobile_number: string | null;
65
+ phone_number?: string | null;
66
+ description?: string | null;
67
+ metadata: Record<string, unknown> | null;
68
+ created: string;
69
+ updated: string;
70
+ }
71
+ /**
72
+ * Interval unit accepted by the Recurring Plans API - `YEAR` is not
73
+ * supported natively and is translated to `MONTH` with `interval_count: 12`.
74
+ */
75
+ type XenditRecurringInterval = 'DAY' | 'WEEK' | 'MONTH';
76
+ interface XenditRecurringSchedule {
77
+ interval: XenditRecurringInterval;
78
+ interval_count: number;
79
+ total_recurrence?: number | null;
80
+ anchor_date?: string;
81
+ retry_interval?: string;
82
+ retry_interval_count?: number;
83
+ total_retry?: number;
84
+ created?: string;
85
+ updated?: string;
86
+ }
87
+ interface XenditPaymentToken {
88
+ payment_token_id: string;
89
+ rank: number;
90
+ }
91
+ /**
92
+ * The shape returned by `POST /recurring/plans`, `GET /recurring/plans/:id`,
93
+ * and `POST /recurring/plans/:id/deactivate`.
94
+ */
95
+ interface XenditRecurringPlan {
96
+ id: string;
97
+ reference_id: string;
98
+ customer_id: string;
99
+ currency: string;
100
+ amount: number;
101
+ status: 'ACTIVE' | 'INACTIVE' | 'PENDING' | 'REQUIRES_ACTION';
102
+ country?: string;
103
+ recurring_cycle_count?: number;
104
+ schedule: XenditRecurringSchedule;
105
+ payment_tokens: XenditPaymentToken[];
106
+ immediate_payment?: boolean;
107
+ failed_cycle_action?: 'RESUME' | 'STOP';
108
+ metadata?: Record<string, unknown> | null;
109
+ description?: string | null;
110
+ created: string;
111
+ updated: string;
112
+ actions?: Array<{
113
+ action: string;
114
+ url_type: string;
115
+ url: string;
116
+ method: string;
117
+ }>;
118
+ }
119
+ /**
120
+ * The shape returned by `POST /refunds` and `GET /refunds/:id`.
121
+ */
122
+ interface XenditRefund {
123
+ id: string;
124
+ payment_id?: string;
125
+ payment_request_id?: string;
126
+ invoice_id?: string;
127
+ amount: number;
128
+ currency: string;
129
+ channel_code?: string;
130
+ status: 'PENDING' | 'SUCCEEDED' | 'FAILED' | 'CANCELLED';
131
+ reason?: string;
132
+ reference_id?: string | null;
133
+ failure_code?: string | null;
134
+ metadata?: Record<string, unknown> | null;
135
+ created: string;
136
+ updated: string;
137
+ }
138
+ /**
139
+ * The Invoice Callback body is the invoice resource itself, sent
140
+ * unwrapped at the top level - there is no separate `event`/`data`
141
+ * envelope for invoice webhooks (unlike Recurring webhooks below).
142
+ */
143
+ type XenditInvoiceCallback = XenditInvoice;
144
+ /**
145
+ * Recurring webhooks (unlike invoice callbacks) use a wrapping
146
+ * `{ event, business_id, created, data }` envelope, reflecting a newer
147
+ * generation of Xendit's API.
148
+ */
149
+ interface XenditRecurringCycle {
150
+ id: string;
151
+ reference_id?: string;
152
+ plan_id?: string;
153
+ customer_id?: string;
154
+ cycle_number?: number;
155
+ attempt_count?: number;
156
+ status: 'SCHEDULED' | 'SUCCEEDED' | 'RETRYING' | 'FAILED';
157
+ scheduled_timestamp?: string;
158
+ currency: string;
159
+ amount: number;
160
+ created?: string;
161
+ updated?: string;
162
+ metadata?: Record<string, unknown> | null;
163
+ }
164
+ interface XenditRecurringPlanWebhookEvent {
165
+ event: 'recurring.plan.activated' | 'recurring.plan.inactivated';
166
+ business_id: string;
167
+ created: string;
168
+ data: XenditRecurringPlan;
169
+ }
170
+ interface XenditRecurringCycleWebhookEvent {
171
+ event: 'recurring.cycle.created' | 'recurring.cycle.succeeded' | 'recurring.cycle.retrying' | 'recurring.cycle.failed';
172
+ business_id: string;
173
+ created: string;
174
+ data: XenditRecurringCycle;
175
+ }
176
+ type XenditRecurringWebhookEvent = XenditRecurringPlanWebhookEvent | XenditRecurringCycleWebhookEvent;
177
+ type XenditWebhookEvent = XenditInvoiceCallback | XenditRecurringWebhookEvent;
178
+ declare const isXenditRecurringWebhookEvent: (event: XenditWebhookEvent) => event is XenditRecurringWebhookEvent;
179
+ type XenditRawEvents = {
180
+ 'xendit.invoice.pending': XenditInvoiceCallback;
181
+ 'xendit.invoice.paid': XenditInvoiceCallback;
182
+ 'xendit.invoice.settled': XenditInvoiceCallback;
183
+ 'xendit.invoice.expired': XenditInvoiceCallback;
184
+ 'xendit.recurring.plan.activated': XenditRecurringPlanWebhookEvent;
185
+ 'xendit.recurring.plan.inactivated': XenditRecurringPlanWebhookEvent;
186
+ 'xendit.recurring.cycle.created': XenditRecurringCycleWebhookEvent;
187
+ 'xendit.recurring.cycle.succeeded': XenditRecurringCycleWebhookEvent;
188
+ 'xendit.recurring.cycle.retrying': XenditRecurringCycleWebhookEvent;
189
+ 'xendit.recurring.cycle.failed': XenditRecurringCycleWebhookEvent;
190
+ };
191
+
192
+ export { type XenditCustomer, type XenditErrorResponse, type XenditInvoice, type XenditInvoiceCallback, type XenditInvoiceCustomer, type XenditInvoiceItem, type XenditPaymentToken, type XenditRawEvents, type XenditRecurringCycle, type XenditRecurringCycleWebhookEvent, type XenditRecurringInterval, type XenditRecurringPlan, type XenditRecurringPlanWebhookEvent, type XenditRecurringSchedule, type XenditRecurringWebhookEvent, type XenditRefund, type XenditWebhookEvent, isXenditRecurringWebhookEvent };
package/dist/schema.js ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ // src/schema.ts
4
+ var isXenditRecurringWebhookEvent = (event) => typeof event.event === "string" && event.event.startsWith(
5
+ "recurring."
6
+ );
7
+
8
+ exports.isXenditRecurringWebhookEvent = isXenditRecurringWebhookEvent;
@@ -0,0 +1,6 @@
1
+ // src/schema.ts
2
+ var isXenditRecurringWebhookEvent = (event) => typeof event.event === "string" && event.event.startsWith(
3
+ "recurring."
4
+ );
5
+
6
+ export { isXenditRecurringWebhookEvent };
@@ -0,0 +1,34 @@
1
+ import { Payment, Checkout, Customer, Subscription, Refund, Invoice } from '@paykit-sdk/core';
2
+ import { XenditInvoice, XenditCustomer, XenditRecurringPlan, XenditRefund } from '../schema.mjs';
3
+
4
+ /**
5
+ * @internal
6
+ */
7
+ declare const Payment$inboundSchema: (data: XenditInvoice, overridePaymentUrl?: string | null) => Payment;
8
+ /**
9
+ * @internal
10
+ */
11
+ declare const Checkout$inboundSchema: (data: XenditInvoice) => Checkout;
12
+ /**
13
+ * @internal
14
+ */
15
+ declare const Customer$inboundSchema: (data: XenditCustomer) => Customer;
16
+ /**
17
+ * Xendit's Recurring Plans API has no separate reusable plan template to
18
+ * reference - the "plan" created here already carries the amount/currency
19
+ * for one specific subscription, so `item_id` is round-tripped through
20
+ * `description` instead of pointing at an external resource.
21
+ *
22
+ * @internal
23
+ */
24
+ declare const Subscription$inboundSchema: (data: XenditRecurringPlan) => Subscription;
25
+ /**
26
+ * @internal
27
+ */
28
+ declare const Refund$inboundSchema: (data: XenditRefund) => Refund;
29
+ /**
30
+ * @internal
31
+ */
32
+ declare const Invoice$inboundSchema: (data: XenditInvoice) => Invoice;
33
+
34
+ export { Checkout$inboundSchema, Customer$inboundSchema, Invoice$inboundSchema, Payment$inboundSchema, Refund$inboundSchema, Subscription$inboundSchema };
@@ -0,0 +1,34 @@
1
+ import { Payment, Checkout, Customer, Subscription, Refund, Invoice } from '@paykit-sdk/core';
2
+ import { XenditInvoice, XenditCustomer, XenditRecurringPlan, XenditRefund } from '../schema.js';
3
+
4
+ /**
5
+ * @internal
6
+ */
7
+ declare const Payment$inboundSchema: (data: XenditInvoice, overridePaymentUrl?: string | null) => Payment;
8
+ /**
9
+ * @internal
10
+ */
11
+ declare const Checkout$inboundSchema: (data: XenditInvoice) => Checkout;
12
+ /**
13
+ * @internal
14
+ */
15
+ declare const Customer$inboundSchema: (data: XenditCustomer) => Customer;
16
+ /**
17
+ * Xendit's Recurring Plans API has no separate reusable plan template to
18
+ * reference - the "plan" created here already carries the amount/currency
19
+ * for one specific subscription, so `item_id` is round-tripped through
20
+ * `description` instead of pointing at an external resource.
21
+ *
22
+ * @internal
23
+ */
24
+ declare const Subscription$inboundSchema: (data: XenditRecurringPlan) => Subscription;
25
+ /**
26
+ * @internal
27
+ */
28
+ declare const Refund$inboundSchema: (data: XenditRefund) => Refund;
29
+ /**
30
+ * @internal
31
+ */
32
+ declare const Invoice$inboundSchema: (data: XenditInvoice) => Invoice;
33
+
34
+ export { Checkout$inboundSchema, Customer$inboundSchema, Invoice$inboundSchema, Payment$inboundSchema, Refund$inboundSchema, Subscription$inboundSchema };
@@ -0,0 +1,169 @@
1
+ 'use strict';
2
+
3
+ var core = require('@paykit-sdk/core');
4
+
5
+ // src/utils/mapper.ts
6
+ var paymentStatusMap = {
7
+ PENDING: "pending",
8
+ PAID: "succeeded",
9
+ SETTLED: "succeeded",
10
+ EXPIRED: "canceled"
11
+ };
12
+ var subscriptionStatusMap = {
13
+ ACTIVE: "active",
14
+ INACTIVE: "canceled",
15
+ PENDING: "pending",
16
+ REQUIRES_ACTION: "pending"
17
+ };
18
+ var resolveCustomerFromEmail = (email) => email ? { email } : null;
19
+ var Payment$inboundSchema = (data, overridePaymentUrl) => {
20
+ const rawMeta = data.metadata ?? {};
21
+ const metadata = core.omitInternalMetadata(rawMeta);
22
+ let itemId = null;
23
+ const paykitMeta = core.parseJSON(
24
+ rawMeta[core.PAYKIT_METADATA_KEY],
25
+ core.Schema.object({ item_id: core.Schema.string().optional() })
26
+ );
27
+ if (paykitMeta) itemId = paykitMeta.item_id ?? null;
28
+ const status = paymentStatusMap[data.status] ?? "pending";
29
+ return {
30
+ id: data.id,
31
+ amount: data.amount,
32
+ currency: data.currency,
33
+ customer: resolveCustomerFromEmail(
34
+ data.payer_email ?? data.customer?.email
35
+ ),
36
+ status,
37
+ metadata,
38
+ item_id: itemId,
39
+ requires_action: status === "pending",
40
+ payment_url: overridePaymentUrl ?? null
41
+ };
42
+ };
43
+ var Checkout$inboundSchema = (data) => {
44
+ const rawMeta = data.metadata ?? {};
45
+ const metadata = core.omitInternalMetadata(rawMeta);
46
+ let itemId = "";
47
+ let quantity = 1;
48
+ let type = null;
49
+ const paykitMeta = core.parseJSON(
50
+ rawMeta[core.PAYKIT_METADATA_KEY],
51
+ core.Schema.object({
52
+ item_id: core.Schema.string().optional(),
53
+ quantity: core.Schema.number().optional(),
54
+ type: core.billingModeSchema.optional()
55
+ })
56
+ );
57
+ if (paykitMeta) {
58
+ itemId = paykitMeta.item_id ?? "";
59
+ quantity = paykitMeta.quantity ?? 1;
60
+ type = paykitMeta.type ?? null;
61
+ }
62
+ return {
63
+ id: data.id,
64
+ customer: resolveCustomerFromEmail(
65
+ data.payer_email ?? data.customer?.email
66
+ ),
67
+ payment_url: data.invoice_url,
68
+ metadata: Object.keys(metadata).length > 0 ? metadata : null,
69
+ session_type: type ?? "one_time",
70
+ products: [{ id: itemId, quantity }],
71
+ currency: data.currency,
72
+ amount: data.amount
73
+ };
74
+ };
75
+ var Customer$inboundSchema = (data) => {
76
+ const rawMeta = data.metadata ?? {};
77
+ const metadata = core.omitInternalMetadata(rawMeta);
78
+ const name = [
79
+ data.individual_detail?.given_names,
80
+ data.individual_detail?.surname
81
+ ].filter(Boolean).join(" ");
82
+ return {
83
+ id: data.id,
84
+ email: data.email ?? "",
85
+ name,
86
+ phone: data.mobile_number ?? data.phone_number ?? null,
87
+ metadata,
88
+ created_at: new Date(data.created),
89
+ updated_at: new Date(data.updated),
90
+ // Xendit-native fields with no PayKit core equivalent.
91
+ custom_fields: { type: data.type ?? null }
92
+ };
93
+ };
94
+ var recurringIntervalUnitMap = {
95
+ DAY: "day",
96
+ WEEK: "week",
97
+ MONTH: "month"
98
+ };
99
+ var Subscription$inboundSchema = (data) => {
100
+ const rawMeta = data.metadata ?? {};
101
+ const metadata = core.omitInternalMetadata(rawMeta);
102
+ const status = subscriptionStatusMap[data.status] ?? "pending";
103
+ const periodAnchor = data.schedule.anchor_date ? new Date(data.schedule.anchor_date) : /* @__PURE__ */ new Date(0);
104
+ const authAction = data.actions?.find(
105
+ (action) => action.action === "AUTH"
106
+ );
107
+ return {
108
+ id: data.id,
109
+ customer: { id: data.customer_id },
110
+ amount: data.amount,
111
+ currency: data.currency,
112
+ status,
113
+ current_period_start: periodAnchor,
114
+ current_period_end: periodAnchor,
115
+ item_id: data.description ?? data.reference_id,
116
+ billing_interval: recurringIntervalUnitMap[data.schedule.interval] ?? "month",
117
+ metadata: Object.keys(metadata).length > 0 ? metadata : null,
118
+ custom_fields: {
119
+ payment_tokens: data.payment_tokens,
120
+ recurring_cycle_count: data.recurring_cycle_count ?? null,
121
+ failed_cycle_action: data.failed_cycle_action ?? null
122
+ },
123
+ requires_action: status === "pending" || data.status === "REQUIRES_ACTION",
124
+ payment_url: authAction?.url ?? null
125
+ };
126
+ };
127
+ var Refund$inboundSchema = (data) => {
128
+ const rawMeta = data.metadata ?? {};
129
+ const metadata = core.omitInternalMetadata(rawMeta);
130
+ return {
131
+ id: data.id,
132
+ amount: data.amount,
133
+ currency: data.currency,
134
+ reason: data.reason ?? null,
135
+ metadata: Object.keys(metadata).length > 0 ? metadata : null
136
+ };
137
+ };
138
+ var Invoice$inboundSchema = (data) => {
139
+ const rawMeta = data.metadata ?? {};
140
+ const metadata = core.omitInternalMetadata(rawMeta);
141
+ return {
142
+ id: data.id,
143
+ customer: resolveCustomerFromEmail(
144
+ data.payer_email ?? data.customer?.email
145
+ ),
146
+ subscription_id: data.recurring_payment_id ?? null,
147
+ billing_mode: data.recurring_payment_id ? "recurring" : "one_time",
148
+ amount_paid: data.paid_amount ?? data.amount,
149
+ currency: data.currency,
150
+ status: "paid",
151
+ paid_at: data.paid_at ?? data.updated,
152
+ line_items: data.items?.map((item) => ({
153
+ id: item.name,
154
+ quantity: item.quantity
155
+ })) ?? null,
156
+ metadata: Object.keys(metadata).length > 0 ? metadata : null,
157
+ custom_fields: {
158
+ payment_method: data.payment_method ?? null,
159
+ payment_channel: data.payment_channel ?? null
160
+ }
161
+ };
162
+ };
163
+
164
+ exports.Checkout$inboundSchema = Checkout$inboundSchema;
165
+ exports.Customer$inboundSchema = Customer$inboundSchema;
166
+ exports.Invoice$inboundSchema = Invoice$inboundSchema;
167
+ exports.Payment$inboundSchema = Payment$inboundSchema;
168
+ exports.Refund$inboundSchema = Refund$inboundSchema;
169
+ exports.Subscription$inboundSchema = Subscription$inboundSchema;