@thavguard/arc-pay 0.1.4 → 0.1.6

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.
@@ -1,269 +1,5 @@
1
- type Currency = "RUB" | "KZT" | "UZS";
2
- type PaymentMethod = "bank_card" | "sbp" | "sberpay" | "tpay" | "alfapay" | "dolyami" | "mirpay" | "applepay" | "googlepay" | "bnpl";
3
- type CaptureMode = "one_stage" | "two_stage";
4
- type PaymentFlowMode = "h2h" | "redirect";
5
- type Locale = "ru" | "en";
6
- type PaymentStatus = "created" | "pending" | "pending_3ds" | "authorized" | "captured" | "settled" | "voided" | "expired" | "refunded" | "chargeback" | "declined" | "failed" | "timeout";
7
- interface Payment {
8
- id: string;
9
- amount: number;
10
- authorized_amount?: number;
11
- captured_amount?: number;
12
- refunded_amount?: number;
13
- currency: Currency;
14
- payment_method: PaymentMethod;
15
- status: PaymentStatus;
16
- external_id?: string;
17
- description?: string;
18
- bank_payment_id?: string;
19
- bank_code?: string;
20
- bank_order_id?: string;
21
- bank_terminal_id?: string;
22
- bank_rrn?: string;
23
- bank_internal_ref?: string;
24
- bank_auth_code?: string;
25
- card_token_id?: string;
26
- decline_code?: string;
27
- card_mask?: string;
28
- card_scheme?: string;
29
- redirect_url?: string;
30
- payment_mode?: PaymentFlowMode;
31
- capture_mode?: CaptureMode;
32
- created_at: string;
33
- updated_at: string;
34
- metadata?: Record<string, string>;
35
- }
36
- interface PaymentList {
37
- payments: Payment[];
38
- total: number;
39
- page: number;
40
- page_size: number;
41
- }
42
- interface CreatePaymentRequest {
43
- amount: number;
44
- currency: Currency;
45
- payment_method: PaymentMethod;
46
- external_id: string;
47
- capture_mode: CaptureMode;
48
- save_card?: boolean;
49
- customer_id?: string;
50
- description?: string;
51
- success_url?: string;
52
- fail_url?: string;
53
- callback_url?: string;
54
- customer_email?: string;
55
- customer_phone?: string;
56
- metadata?: Record<string, string>;
57
- }
58
- interface CaptureRequest {
59
- amount?: number;
60
- }
61
- interface VoidRequest {
62
- reason?: string;
63
- }
64
- interface CreateRefundRequest {
65
- amount: number;
66
- reason?: string;
67
- }
68
- interface Refund {
69
- id: string;
70
- payment_id: string;
71
- amount: number;
72
- currency: Currency;
73
- status: "pending" | "completed" | "failed";
74
- reason?: string;
75
- created_at: string;
76
- }
77
- interface ExecutePaymentRequest {
78
- card_token_id: string;
79
- payment_mode: "h2h";
80
- browser_info: {
81
- accept_header: string;
82
- language: string;
83
- screen_width: number;
84
- screen_height: number;
85
- color_depth: 1 | 4 | 8 | 15 | 16 | 24 | 32 | 48;
86
- timezone_offset_minutes: number;
87
- java_enabled?: boolean;
88
- user_agent: string;
89
- window_size?: "01" | "02" | "03" | "04" | "05";
90
- };
91
- }
92
- interface ExecutePaymentResponse {
93
- payment_id: string;
94
- status: "authorized" | "captured" | "pending" | "pending_3ds" | "failed" | "declined";
95
- authorized_amount?: number;
96
- payment_mode?: PaymentFlowMode;
97
- redirect_url?: string;
98
- qr_url?: string;
99
- qr_image_base64?: string;
100
- qr_content_type?: "image/png" | "image/svg+xml" | string;
101
- qr_expires_at?: string;
102
- liability_shifted?: boolean;
103
- requires_3ds?: boolean;
104
- acs_url?: string;
105
- c_req?: string;
106
- pa_req?: string;
107
- md?: string;
108
- term_url?: string;
109
- three_ds_method_url?: string;
110
- three_ds_method_data?: string;
111
- three_ds_server_trans_id?: string;
112
- decline_code?: string;
113
- decline_message?: string;
114
- }
115
- interface ChargeSavedCardRequest {
116
- amount: number;
117
- currency: Currency;
118
- card_token_id: string;
119
- customer_id: string;
120
- external_id?: string;
121
- description?: string;
122
- metadata?: Record<string, string>;
123
- fiscal_items?: {
124
- name: string;
125
- quantity: number;
126
- unit_price: number;
127
- vat_rate: "no_vat" | "vat0" | "vat10" | "vat20";
128
- }[];
129
- }
130
- interface CompleteThreeDSMethodRequest {
131
- completion_indicator: "Y" | "N" | "U";
132
- three_ds_server_trans_id: string;
133
- }
134
- interface AvailablePaymentMethod {
135
- method: PaymentMethod;
136
- payment_mode: PaymentFlowMode;
137
- display_name: string;
138
- is_active: boolean;
139
- unavailable_reason?: string;
140
- icon_url?: string;
141
- supported_currencies?: Currency[];
142
- supported_countries?: string[];
143
- min_amount?: number;
144
- max_amount?: number;
145
- sandbox_requirements?: string;
146
- }
147
- interface CreateLinkRequest {
148
- link_type: "one_time" | "reusable" | "invoice" | "recurring";
149
- amount: number;
150
- currency: Currency;
151
- description?: string;
152
- environment?: "live" | "sandbox";
153
- max_uses?: number;
154
- expires_at?: string;
155
- customer_name?: string;
156
- customer_id?: string;
157
- customer_email?: string;
158
- due_date?: string;
159
- redirect_url?: string;
160
- webhook_url?: string;
161
- external_order_id?: string;
162
- metadata?: Record<string, string>;
163
- capture_mode: CaptureMode;
164
- autocompletion_date?: string;
165
- locale?: Locale;
166
- payment_methods: {
167
- method: PaymentMethod;
168
- payment_mode: PaymentFlowMode;
169
- }[];
170
- items?: {
171
- name: string;
172
- quantity: string;
173
- unit_price: number;
174
- vat_rate?: number;
175
- }[];
176
- billing_config?: {
177
- interval_type?: "day" | "week" | "month" | "year";
178
- interval_count?: number;
179
- trial_days?: number;
180
- trial_price?: number;
181
- };
182
- }
183
- interface Link {
184
- id: string;
185
- tenant_id?: string;
186
- organization_id?: string;
187
- short_code: string;
188
- link_type: "one_time" | "reusable" | "invoice" | "recurring";
189
- status: "active" | "paid" | "expired" | "canceled";
190
- environment: "live" | "sandbox";
191
- amount: number;
192
- currency: Currency;
193
- created_at?: string;
194
- updated_at?: string;
195
- description?: string;
196
- url: string;
197
- max_uses?: number;
198
- uses_count?: number;
199
- expires_at?: string;
200
- customer_name?: string;
201
- customer_id?: string;
202
- customer_email?: string;
203
- due_date?: string;
204
- external_order_id?: string;
205
- payment_methods: {
206
- method: PaymentMethod;
207
- payment_mode: PaymentFlowMode;
208
- display_name?: string;
209
- }[];
210
- redirect_url?: string;
211
- webhook_url?: string;
212
- items?: {
213
- name?: string;
214
- quantity?: string;
215
- unit_price?: number;
216
- vat_rate?: number;
217
- }[];
218
- billing_config?: {
219
- interval_type?: string;
220
- interval_count?: number;
221
- trial_days?: number;
222
- trial_price?: number;
223
- };
224
- metadata?: Record<string, string>;
225
- capture_mode: CaptureMode;
226
- autocompletion_date?: string;
227
- locale?: Locale;
228
- }
229
- interface CreateCheckoutSessionRequest {
230
- amount: number;
231
- currency: Currency;
232
- description?: string;
233
- payment_methods: {
234
- method: PaymentMethod;
235
- payment_mode: PaymentFlowMode;
236
- }[];
237
- capture_mode: CaptureMode;
238
- success_url?: string;
239
- fail_url?: string;
240
- cancel_url?: string;
241
- customer_email?: string;
242
- customer_id?: string;
243
- external_id?: string;
244
- metadata?: Record<string, string>;
245
- autocompletion_date?: string;
246
- locale?: Locale;
247
- }
248
- interface CheckoutSession {
249
- id: string;
250
- url: string;
251
- }
252
- interface ListPaymentsQuery {
253
- page?: number;
254
- page_size?: number;
255
- status?: PaymentStatus;
256
- payment_method?: PaymentMethod;
257
- bank_code?: string;
258
- decline_code?: string;
259
- payment_flow_id?: string;
260
- search?: string;
261
- date_from?: string;
262
- date_to?: string;
263
- }
264
- interface ListAvailablePaymentMethodsQuery {
265
- environment: "live" | "sandbox";
266
- }
1
+ import { k as ListPaymentsQuery, m as PaymentList, g as CreatePaymentRequest, P as Payment, C as CaptureRequest, V as VoidRequest, h as CreateRefundRequest, R as Refund, b as ChargeSavedCardRequest, i as ExecutePaymentResponse, E as ExecutePaymentRequest, d as CompleteThreeDSMethodRequest, j as ListAvailablePaymentMethodsQuery, A as AvailablePaymentMethod, f as CreateLinkRequest, L as Link, e as CreateCheckoutSessionRequest, c as CheckoutSession } from '../actions-D0CoBTF4.js';
2
+ export { B as BrowserFormField, a as BrowserPostForm, l as PaymentFlowMode, n as PaymentMethod, o as PaymentNextAction, T as ThreeDSAction, p as buildThreeDSBrowserForm, q as getThreeDSAction } from '../actions-D0CoBTF4.js';
267
3
 
268
4
  interface ArcPayClientOptions {
269
5
  secretKey: string;
@@ -300,4 +36,4 @@ declare class ArcPayClient {
300
36
  }
301
37
  declare const createArcPayClient: (options: ArcPayClientOptions) => ArcPayClient;
302
38
 
303
- export { ArcPayClient, type ArcPayClientOptions, type AvailablePaymentMethod, type CaptureRequest, type ChargeSavedCardRequest, type CheckoutSession, type CompleteThreeDSMethodRequest, type CreateCheckoutSessionRequest, type CreateLinkRequest, type CreatePaymentRequest, type CreateRefundRequest, type ExecutePaymentRequest, type ExecutePaymentResponse, type IdempotencyOptions, type Link, type ListAvailablePaymentMethodsQuery, type ListPaymentsQuery, type Payment, type PaymentFlowMode, type PaymentList, type PaymentMethod, type Refund, type RequestOptions, type VoidRequest, createArcPayClient };
39
+ export { ArcPayClient, type ArcPayClientOptions, AvailablePaymentMethod, CaptureRequest, ChargeSavedCardRequest, CheckoutSession, CompleteThreeDSMethodRequest, CreateCheckoutSessionRequest, CreateLinkRequest, CreatePaymentRequest, CreateRefundRequest, ExecutePaymentRequest, ExecutePaymentResponse, type IdempotencyOptions, Link, ListAvailablePaymentMethodsQuery, ListPaymentsQuery, Payment, PaymentList, Refund, type RequestOptions, VoidRequest, createArcPayClient };
@@ -53,6 +53,27 @@ var requireIdempotencyKey = (opts) => {
53
53
  }
54
54
  return opts.idempotencyKey;
55
55
  };
56
+ var normalizeExecutePaymentRequest = (body) => {
57
+ var _a;
58
+ if (!body || !body.card_token_id) {
59
+ throw new ArcPayError({
60
+ type: "validation_error",
61
+ code: "missing_card_token_id",
62
+ message: "card_token_id is required",
63
+ retryable: false
64
+ });
65
+ }
66
+ const paymentMode = (_a = body.payment_mode) != null ? _a : "h2h";
67
+ if (paymentMode !== "h2h") {
68
+ throw new ArcPayError({
69
+ type: "validation_error",
70
+ code: "invalid_payment_mode",
71
+ message: "payment_mode must be h2h for executePayment",
72
+ retryable: false
73
+ });
74
+ }
75
+ return { ...body, payment_mode: paymentMode };
76
+ };
56
77
  var appendQuery = (path, query) => {
57
78
  if (!query) return path;
58
79
  const params = new URLSearchParams();
@@ -150,10 +171,11 @@ var ArcPayClient = class {
150
171
  return this.request("POST", "/payments/saved-card", body, opts, true);
151
172
  }
152
173
  async executePayment(paymentId, body, opts) {
174
+ const requestBody = normalizeExecutePaymentRequest(body);
153
175
  return this.request(
154
176
  "POST",
155
177
  `/payments/${encodeURIComponent(paymentId)}/execute`,
156
- body,
178
+ requestBody,
157
179
  opts,
158
180
  true
159
181
  );
@@ -219,6 +241,17 @@ var ArcPayClient = class {
219
241
  };
220
242
  var createArcPayClient = (options) => new ArcPayClient(options);
221
243
 
222
- export { ArcPayClient, createArcPayClient };
244
+ // src/three-ds/actions.ts
245
+ var getThreeDSAction = (nextAction) => {
246
+ return nextAction != null ? nextAction : null;
247
+ };
248
+ var buildThreeDSBrowserForm = (nextAction) => ({
249
+ action: nextAction.three_ds.submit.url,
250
+ method: nextAction.three_ds.submit.method,
251
+ target: nextAction.three_ds.submit.target,
252
+ fields: nextAction.three_ds.submit.fields
253
+ });
254
+
255
+ export { ArcPayClient, buildThreeDSBrowserForm, createArcPayClient, getThreeDSAction };
223
256
  //# sourceMappingURL=index.mjs.map
224
257
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/errors.ts","../../src/server/client.ts"],"names":[],"mappings":";AAqBO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EASrC,YAAY,IAAA,EAAuB;AACjC,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,QAAQ,IAAA,CAAK,KAAA;AAClB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,cAAc,IAAA,CAAK,WAAA;AACxB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,YAAY,IAA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AAA,CAAQ,iBAAiB,CAAA,GAAI,qBAAA,CAAsB,WAAW,CAAA;AAAA,IAChE,CAAA,MAAA,IAAW,WAAA,CAAY,cAAA,KAAmB,MAAA,EAAW;AACnD,MAAA,OAAA,CAAQ,iBAAiB,CAAA,GAAI,qBAAA,CAAsB,WAAW,CAAA;AAAA,IAChE;AAEA,IAAA,IAAI,GAAA;AACJ,IAAA,IAAI;AACF,MAAA,GAAA,GAAM,MAAM,KAAK,SAAA,CAAU,CAAA,EAAG,KAAK,OAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI;AAAA,QACnD,MAAA;AAAA,QACA,OAAA;AAAA,QACA,MAAM,IAAA,KAAS,KAAA,CAAA,GAAY,KAAA,CAAA,GAAY,IAAA,CAAK,UAAU,IAAI,CAAA;AAAA,QAC1D,QAAQ,WAAA,CAAY;AAAA,OACrB,CAAA;AAAA,IACH,SAAS,GAAA,EAAK;AACZ,MAAA,MAAM,IAAI,WAAA,CAAY;AAAA,QACpB,IAAA,EAAM,eAAA;AAAA,QACN,OAAA,EAAS,GAAA,YAAe,KAAA,GAAQ,GAAA,CAAI,OAAA,GAAU,wBAAA;AAAA,QAC9C,SAAA,EAAW;AAAA,OACZ,CAAA;AAAA,IACH;AACA,IAAA,IAAI,CAAC,GAAA,CAAI,EAAA,EAAI,MAAM,MAAM,mBAAmB,GAAG,CAAA;AAC/C,IAAA,OAAQ,MAAM,IAAI,IAAA,EAAK;AAAA,EACzB;AACF;AAEO,IAAM,kBAAA,GAAqB,CAAC,OAAA,KACjC,IAAI,aAAa,OAAO","file":"index.mjs","sourcesContent":["export type ArcPayErrorType =\n | \"validation_error\"\n | \"authentication_error\"\n | \"authorization_error\"\n | \"state_error\"\n | \"rate_limit_error\"\n | \"api_error\"\n | \"network_error\"\n | \"challenge_aborted\";\n\nexport interface ArcPayErrorInit {\n type: ArcPayErrorType;\n message: string;\n code?: string;\n param?: string;\n paymentId?: string;\n declineCode?: string;\n retryable: boolean;\n requestId?: string;\n}\n\nexport class ArcPayError extends Error {\n readonly type: ArcPayErrorType;\n readonly code?: string;\n readonly param?: string;\n readonly paymentId?: string;\n readonly declineCode?: string;\n readonly retryable: boolean;\n readonly requestId?: string;\n\n constructor(init: ArcPayErrorInit) {\n super(init.message);\n this.name = \"ArcPayError\";\n this.type = init.type;\n this.code = init.code;\n this.param = init.param;\n this.paymentId = init.paymentId;\n this.declineCode = init.declineCode;\n this.retryable = init.retryable;\n this.requestId = init.requestId;\n }\n}\n\nexport const isValidationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"validation_error\";\nexport const isAuthenticationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authentication_error\";\nexport const isAuthorizationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authorization_error\";\nexport const isStateError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"state_error\";\nexport const isRateLimitError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"rate_limit_error\";\nexport const isApiError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"api_error\";\nexport const isNetworkError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"network_error\";\nexport const isChallengeAborted = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"challenge_aborted\";\n","import { ArcPayError, type ArcPayErrorType } from \"../core/errors\";\nimport type {\n AvailablePaymentMethod,\n CaptureRequest,\n ChargeSavedCardRequest,\n CheckoutSession,\n CompleteThreeDSMethodRequest,\n CreateCheckoutSessionRequest,\n CreateLinkRequest,\n CreatePaymentRequest,\n CreateRefundRequest,\n ExecutePaymentRequest,\n ExecutePaymentResponse,\n Link,\n ListAvailablePaymentMethodsQuery,\n ListPaymentsQuery,\n Payment,\n PaymentList,\n Refund,\n VoidRequest,\n} from \"./types\";\n\nexport type {\n AvailablePaymentMethod,\n CaptureMode,\n CaptureRequest,\n ChargeSavedCardRequest,\n CheckoutSession,\n CompleteThreeDSMethodRequest,\n CreateCheckoutSessionRequest,\n CreateLinkRequest,\n CreatePaymentRequest,\n CreateRefundRequest,\n Currency,\n ExecutePaymentRequest,\n ExecutePaymentResponse,\n Link,\n ListAvailablePaymentMethodsQuery,\n ListPaymentsQuery,\n Payment,\n PaymentFlowMode,\n PaymentList,\n PaymentMethod,\n PaymentStatus,\n Refund,\n VoidRequest,\n} from \"./types\";\n\nexport interface ArcPayClientOptions {\n secretKey: string;\n apiBase?: string;\n fetch?: typeof fetch;\n}\n\nexport interface IdempotencyOptions {\n idempotencyKey: string;\n signal?: AbortSignal;\n}\n\ntype RequestOptionsInput = RequestOptions | IdempotencyOptions | null | undefined;\n\nexport interface RequestOptions {\n signal?: AbortSignal;\n}\n\nconst DEFAULT_API_BASE = \"https://api.arcpay.space/v1\";\nconst API_VERSION = \"2026-05-06\";\n\nfunction validateSecretKey(key: unknown): asserts key is string {\n if (typeof key !== \"string\" || key.length === 0) {\n throw new ArcPayError({\n type: \"authentication_error\",\n code: \"invalid_secret_key\",\n message: \"Secret key must be a non-empty string\",\n retryable: false,\n });\n }\n if (!key.startsWith(\"sk_test_\") && !key.startsWith(\"sk_live_\")) {\n throw new ArcPayError({\n type: \"authentication_error\",\n code: \"invalid_secret_key\",\n message:\n \"Secret key must start with sk_test_ or sk_live_. Publishable keys cannot call server APIs.\",\n retryable: false,\n });\n }\n}\n\nconst normalizeBase = (base: string): string => {\n let end = base.length;\n while (end > 0 && base.charCodeAt(end - 1) === 47) {\n end -= 1;\n }\n return base.slice(0, end);\n};\n\ninterface RequestOptionsWithOptionalIdempotency extends RequestOptions {\n idempotencyKey?: string;\n}\n\nconst normalizeRequestOptions = (\n opts: RequestOptionsInput,\n): RequestOptionsWithOptionalIdempotency => opts ?? {};\n\nconst requireIdempotencyKey = (opts: RequestOptionsWithOptionalIdempotency): string => {\n if (!opts.idempotencyKey) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"missing_idempotency_key\",\n message: \"idempotencyKey is required for this operation\",\n retryable: false,\n });\n }\n return opts.idempotencyKey;\n};\n\nconst appendQuery = (path: string, query?: object): string => {\n if (!query) return path;\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null || value === \"\") continue;\n params.set(key, String(value));\n }\n const encoded = params.toString();\n return encoded ? `${path}?${encoded}` : path;\n};\n\ninterface APIErrorBody {\n error?: {\n type?: string;\n code?: string;\n message?: string;\n param?: string;\n request_id?: string;\n decline_code?: string;\n };\n}\n\nconst isPublicErrorType = (value: unknown): value is ArcPayErrorType =>\n value === \"validation_error\" ||\n value === \"authentication_error\" ||\n value === \"authorization_error\" ||\n value === \"state_error\" ||\n value === \"rate_limit_error\" ||\n value === \"api_error\";\n\nconst isRetryableError = (type: ArcPayErrorType, status: number, code?: string): boolean => {\n if (type === \"rate_limit_error\") return true;\n if (code === \"timeout\") return false;\n return type === \"api_error\" && status >= 500;\n};\n\nconst parseErrorResponse = async (res: Response): Promise<ArcPayError> => {\n let body: APIErrorBody = {};\n try {\n body = (await res.json()) as APIErrorBody;\n } catch {\n /* keep default error below */\n }\n const detail = body.error ?? {};\n const type = isPublicErrorType(detail.type)\n ? detail.type\n : res.status >= 500\n ? \"api_error\"\n : \"validation_error\";\n return new ArcPayError({\n type,\n code: detail.code,\n message: detail.message ?? `Request failed with status ${res.status}`,\n param: detail.param,\n requestId: detail.request_id,\n declineCode: detail.decline_code,\n retryable: isRetryableError(type, res.status, detail.code),\n });\n};\n\nexport class ArcPayClient {\n private readonly secretKey: string;\n private readonly apiBase: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: ArcPayClientOptions) {\n const secretKey: unknown = options.secretKey;\n validateSecretKey(secretKey);\n if (!options.fetch && typeof fetch === \"undefined\") {\n throw new ArcPayError({\n type: \"api_error\",\n code: \"fetch_unavailable\",\n message: \"A fetch implementation is required in this runtime\",\n retryable: false,\n });\n }\n this.secretKey = secretKey;\n this.apiBase = normalizeBase(options.apiBase ?? DEFAULT_API_BASE);\n this.fetchImpl = options.fetch ?? fetch;\n }\n\n async listPayments(\n query: ListPaymentsQuery = {},\n opts: RequestOptions = {},\n ): Promise<PaymentList> {\n return this.request<PaymentList>(\"GET\", appendQuery(\"/payments\", query), undefined, opts);\n }\n\n async createPayment(body: CreatePaymentRequest, opts: IdempotencyOptions): Promise<Payment>;\n async createPayment(body: CreatePaymentRequest, opts: RequestOptionsInput): Promise<Payment> {\n return this.request<Payment>(\"POST\", \"/payments\", body, opts, true);\n }\n\n async getPayment(paymentId: string, opts: RequestOptions = {}): Promise<Payment> {\n return this.request<Payment>(\n \"GET\",\n `/payments/${encodeURIComponent(paymentId)}`,\n undefined,\n opts,\n );\n }\n\n async capturePayment(\n paymentId: string,\n body: CaptureRequest,\n opts: IdempotencyOptions,\n ): Promise<Payment>;\n async capturePayment(\n paymentId: string,\n body: CaptureRequest,\n opts: RequestOptionsInput,\n ): Promise<Payment> {\n return this.request<Payment>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/capture`,\n body,\n opts,\n true,\n );\n }\n\n async voidPayment(\n paymentId: string,\n body: VoidRequest,\n opts: IdempotencyOptions,\n ): Promise<Payment>;\n async voidPayment(\n paymentId: string,\n body: VoidRequest,\n opts: RequestOptionsInput,\n ): Promise<Payment> {\n return this.request<Payment>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/void`,\n body,\n opts,\n true,\n );\n }\n\n async createRefund(\n paymentId: string,\n body: CreateRefundRequest,\n opts: IdempotencyOptions,\n ): Promise<Refund>;\n async createRefund(\n paymentId: string,\n body: CreateRefundRequest,\n opts: RequestOptionsInput,\n ): Promise<Refund> {\n return this.request<Refund>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/refunds`,\n body,\n opts,\n true,\n );\n }\n\n async chargeSavedCard(\n body: ChargeSavedCardRequest,\n opts: IdempotencyOptions,\n ): Promise<ExecutePaymentResponse>;\n async chargeSavedCard(\n body: ChargeSavedCardRequest,\n opts: RequestOptionsInput,\n ): Promise<ExecutePaymentResponse> {\n return this.request<ExecutePaymentResponse>(\"POST\", \"/payments/saved-card\", body, opts, true);\n }\n\n async executePayment(\n paymentId: string,\n body: ExecutePaymentRequest,\n opts: IdempotencyOptions,\n ): Promise<ExecutePaymentResponse>;\n async executePayment(\n paymentId: string,\n body: ExecutePaymentRequest,\n opts: RequestOptionsInput,\n ): Promise<ExecutePaymentResponse> {\n return this.request<ExecutePaymentResponse>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/execute`,\n body,\n opts,\n true,\n );\n }\n\n async completeThreeDSMethod(\n paymentId: string,\n body: CompleteThreeDSMethodRequest,\n opts: RequestOptions = {},\n ): Promise<ExecutePaymentResponse> {\n return this.request<ExecutePaymentResponse>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/complete-3ds-method`,\n body,\n opts,\n );\n }\n\n async listAvailablePaymentMethods(\n query: ListAvailablePaymentMethodsQuery,\n opts: RequestOptions = {},\n ): Promise<AvailablePaymentMethod[]> {\n return this.request<AvailablePaymentMethod[]>(\n \"GET\",\n appendQuery(\"/payment-methods/available\", query),\n undefined,\n opts,\n );\n }\n\n async createLink(body: CreateLinkRequest, opts: IdempotencyOptions): Promise<Link>;\n async createLink(body: CreateLinkRequest, opts: RequestOptionsInput): Promise<Link> {\n return this.request<Link>(\"POST\", \"/links\", body, opts, true);\n }\n\n async getLink(linkId: string, opts: RequestOptions = {}): Promise<Link> {\n return this.request<Link>(\"GET\", `/links/${encodeURIComponent(linkId)}`, undefined, opts);\n }\n\n async cancelLink(linkId: string, opts: RequestOptions = {}): Promise<Link> {\n return this.request<Link>(\"DELETE\", `/links/${encodeURIComponent(linkId)}`, undefined, opts);\n }\n\n async createCheckoutSession(\n body: CreateCheckoutSessionRequest,\n opts: IdempotencyOptions,\n ): Promise<CheckoutSession>;\n async createCheckoutSession(\n body: CreateCheckoutSessionRequest,\n opts: RequestOptionsInput,\n ): Promise<CheckoutSession> {\n return this.request<CheckoutSession>(\"POST\", \"/checkout/sessions\", body, opts, true);\n }\n\n private async request<T>(\n method: \"GET\" | \"POST\" | \"DELETE\",\n path: string,\n body: unknown,\n opts: RequestOptionsInput = undefined,\n requireIdempotency = false,\n ): Promise<T> {\n const requestOpts = normalizeRequestOptions(opts);\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.secretKey}`,\n \"X-Arc-Pay-API-Version\": API_VERSION,\n \"Content-Type\": \"application/json\",\n };\n if (requireIdempotency) {\n headers[\"Idempotency-Key\"] = requireIdempotencyKey(requestOpts);\n } else if (requestOpts.idempotencyKey !== undefined) {\n headers[\"Idempotency-Key\"] = requireIdempotencyKey(requestOpts);\n }\n\n let res: Response;\n try {\n res = await this.fetchImpl(`${this.apiBase}${path}`, {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: requestOpts.signal,\n });\n } catch (err) {\n throw new ArcPayError({\n type: \"network_error\",\n message: err instanceof Error ? err.message : \"Network request failed\",\n retryable: true,\n });\n }\n if (!res.ok) throw await parseErrorResponse(res);\n return (await res.json()) as T;\n }\n}\n\nexport const createArcPayClient = (options: ArcPayClientOptions): ArcPayClient =>\n new ArcPayClient(options);\n"]}
1
+ {"version":3,"sources":["../../src/core/errors.ts","../../src/server/client.ts","../../src/three-ds/actions.ts"],"names":[],"mappings":";AAqBO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EASrC,YAAY,IAAA,EAAuB;AACjC,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AACZ,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,QAAQ,IAAA,CAAK,KAAA;AAClB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,cAAc,IAAA,CAAK,WAAA;AACxB,IAAA,IAAA,CA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ACA,MAAM,IAAA,KAAS,KAAA,CAAA,GAAY,KAAA,CAAA,GAAY,IAAA,CAAK,UAAU,IAAI,CAAA;AAAA,QAC1D,QAAQ,WAAA,CAAY;AAAA,OACrB,CAAA;AAAA,IACH,SAAS,GAAA,EAAK;AACZ,MAAA,MAAM,IAAI,WAAA,CAAY;AAAA,QACpB,IAAA,EAAM,eAAA;AAAA,QACN,OAAA,EAAS,GAAA,YAAe,KAAA,GAAQ,GAAA,CAAI,OAAA,GAAU,wBAAA;AAAA,QAC9C,SAAA,EAAW;AAAA,OACZ,CAAA;AAAA,IACH;AACA,IAAA,IAAI,CAAC,GAAA,CAAI,EAAA,EAAI,MAAM,MAAM,mBAAmB,GAAG,CAAA;AAC/C,IAAA,OAAQ,MAAM,IAAI,IAAA,EAAK;AAAA,EACzB;AACF;AAEO,IAAM,kBAAA,GAAqB,CAAC,OAAA,KACjC,IAAI,aAAa,OAAO;;;AClZnB,IAAM,gBAAA,GAAmB,CAAC,UAAA,KAA6D;AAC5F,EAAA,OAAO,UAAA,IAAA,IAAA,GAAA,UAAA,GAAc,IAAA;AACvB;AAEO,IAAM,uBAAA,GAA0B,CAAC,UAAA,MAAoD;AAAA,EAC1F,MAAA,EAAQ,UAAA,CAAW,QAAA,CAAS,MAAA,CAAO,GAAA;AAAA,EACnC,MAAA,EAAQ,UAAA,CAAW,QAAA,CAAS,MAAA,CAAO,MAAA;AAAA,EACnC,MAAA,EAAQ,UAAA,CAAW,QAAA,CAAS,MAAA,CAAO,MAAA;AAAA,EACnC,MAAA,EAAQ,UAAA,CAAW,QAAA,CAAS,MAAA,CAAO;AACrC,CAAA","file":"index.mjs","sourcesContent":["export type ArcPayErrorType =\n | \"validation_error\"\n | \"authentication_error\"\n | \"authorization_error\"\n | \"state_error\"\n | \"rate_limit_error\"\n | \"api_error\"\n | \"network_error\"\n | \"challenge_aborted\";\n\nexport interface ArcPayErrorInit {\n type: ArcPayErrorType;\n message: string;\n code?: string;\n param?: string;\n paymentId?: string;\n declineCode?: string;\n retryable: boolean;\n requestId?: string;\n}\n\nexport class ArcPayError extends Error {\n readonly type: ArcPayErrorType;\n readonly code?: string;\n readonly param?: string;\n readonly paymentId?: string;\n readonly declineCode?: string;\n readonly retryable: boolean;\n readonly requestId?: string;\n\n constructor(init: ArcPayErrorInit) {\n super(init.message);\n this.name = \"ArcPayError\";\n this.type = init.type;\n this.code = init.code;\n this.param = init.param;\n this.paymentId = init.paymentId;\n this.declineCode = init.declineCode;\n this.retryable = init.retryable;\n this.requestId = init.requestId;\n }\n}\n\nexport const isValidationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"validation_error\";\nexport const isAuthenticationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authentication_error\";\nexport const isAuthorizationError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"authorization_error\";\nexport const isStateError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"state_error\";\nexport const isRateLimitError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"rate_limit_error\";\nexport const isApiError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"api_error\";\nexport const isNetworkError = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"network_error\";\nexport const isChallengeAborted = (e: unknown): e is ArcPayError =>\n e instanceof ArcPayError && e.type === \"challenge_aborted\";\n","import { ArcPayError, type ArcPayErrorType } from \"../core/errors\";\nimport type {\n AvailablePaymentMethod,\n CaptureRequest,\n ChargeSavedCardRequest,\n CheckoutSession,\n CompleteThreeDSMethodRequest,\n CreateCheckoutSessionRequest,\n CreateLinkRequest,\n CreatePaymentRequest,\n CreateRefundRequest,\n ExecutePaymentRequest,\n ExecutePaymentResponse,\n Link,\n ListAvailablePaymentMethodsQuery,\n ListPaymentsQuery,\n Payment,\n PaymentList,\n PaymentNextAction,\n Refund,\n VoidRequest,\n} from \"./types\";\n\nexport type {\n AvailablePaymentMethod,\n CaptureMode,\n CaptureRequest,\n ChargeSavedCardRequest,\n CheckoutSession,\n CompleteThreeDSMethodRequest,\n CreateCheckoutSessionRequest,\n CreateLinkRequest,\n CreatePaymentRequest,\n CreateRefundRequest,\n Currency,\n ExecutePaymentRequest,\n ExecutePaymentResponse,\n PaymentNextAction,\n Link,\n ListAvailablePaymentMethodsQuery,\n ListPaymentsQuery,\n Payment,\n PaymentFlowMode,\n PaymentList,\n PaymentMethod,\n PaymentStatus,\n Refund,\n VoidRequest,\n} from \"./types\";\n\nexport interface ArcPayClientOptions {\n secretKey: string;\n apiBase?: string;\n fetch?: typeof fetch;\n}\n\nexport interface IdempotencyOptions {\n idempotencyKey: string;\n signal?: AbortSignal;\n}\n\ntype RequestOptionsInput = RequestOptions | IdempotencyOptions | null | undefined;\n\nexport interface RequestOptions {\n signal?: AbortSignal;\n}\n\nconst DEFAULT_API_BASE = \"https://api.arcpay.space/v1\";\nconst API_VERSION = \"2026-05-06\";\n\nfunction validateSecretKey(key: unknown): asserts key is string {\n if (typeof key !== \"string\" || key.length === 0) {\n throw new ArcPayError({\n type: \"authentication_error\",\n code: \"invalid_secret_key\",\n message: \"Secret key must be a non-empty string\",\n retryable: false,\n });\n }\n if (!key.startsWith(\"sk_test_\") && !key.startsWith(\"sk_live_\")) {\n throw new ArcPayError({\n type: \"authentication_error\",\n code: \"invalid_secret_key\",\n message:\n \"Secret key must start with sk_test_ or sk_live_. Publishable keys cannot call server APIs.\",\n retryable: false,\n });\n }\n}\n\nconst normalizeBase = (base: string): string => {\n let end = base.length;\n while (end > 0 && base.charCodeAt(end - 1) === 47) {\n end -= 1;\n }\n return base.slice(0, end);\n};\n\ninterface RequestOptionsWithOptionalIdempotency extends RequestOptions {\n idempotencyKey?: string;\n}\n\nconst normalizeRequestOptions = (\n opts: RequestOptionsInput,\n): RequestOptionsWithOptionalIdempotency => opts ?? {};\n\nconst requireIdempotencyKey = (opts: RequestOptionsWithOptionalIdempotency): string => {\n if (!opts.idempotencyKey) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"missing_idempotency_key\",\n message: \"idempotencyKey is required for this operation\",\n retryable: false,\n });\n }\n return opts.idempotencyKey;\n};\n\nconst normalizeExecutePaymentRequest = (body: ExecutePaymentRequest): ExecutePaymentRequest => {\n if (!body || !body.card_token_id) {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"missing_card_token_id\",\n message: \"card_token_id is required\",\n retryable: false,\n });\n }\n const paymentMode = body.payment_mode ?? \"h2h\";\n if (paymentMode !== \"h2h\") {\n throw new ArcPayError({\n type: \"validation_error\",\n code: \"invalid_payment_mode\",\n message: \"payment_mode must be h2h for executePayment\",\n retryable: false,\n });\n }\n return { ...body, payment_mode: paymentMode };\n};\n\nconst appendQuery = (path: string, query?: object): string => {\n if (!query) return path;\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null || value === \"\") continue;\n params.set(key, String(value));\n }\n const encoded = params.toString();\n return encoded ? `${path}?${encoded}` : path;\n};\n\ninterface APIErrorBody {\n error?: {\n type?: string;\n code?: string;\n message?: string;\n param?: string;\n request_id?: string;\n decline_code?: string;\n };\n}\n\nconst isPublicErrorType = (value: unknown): value is ArcPayErrorType =>\n value === \"validation_error\" ||\n value === \"authentication_error\" ||\n value === \"authorization_error\" ||\n value === \"state_error\" ||\n value === \"rate_limit_error\" ||\n value === \"api_error\";\n\nconst isRetryableError = (type: ArcPayErrorType, status: number, code?: string): boolean => {\n if (type === \"rate_limit_error\") return true;\n if (code === \"timeout\") return false;\n return type === \"api_error\" && status >= 500;\n};\n\nconst parseErrorResponse = async (res: Response): Promise<ArcPayError> => {\n let body: APIErrorBody = {};\n try {\n body = (await res.json()) as APIErrorBody;\n } catch {\n /* keep default error below */\n }\n const detail = body.error ?? {};\n const type = isPublicErrorType(detail.type)\n ? detail.type\n : res.status >= 500\n ? \"api_error\"\n : \"validation_error\";\n return new ArcPayError({\n type,\n code: detail.code,\n message: detail.message ?? `Request failed with status ${res.status}`,\n param: detail.param,\n requestId: detail.request_id,\n declineCode: detail.decline_code,\n retryable: isRetryableError(type, res.status, detail.code),\n });\n};\n\nexport class ArcPayClient {\n private readonly secretKey: string;\n private readonly apiBase: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(options: ArcPayClientOptions) {\n const secretKey: unknown = options.secretKey;\n validateSecretKey(secretKey);\n if (!options.fetch && typeof fetch === \"undefined\") {\n throw new ArcPayError({\n type: \"api_error\",\n code: \"fetch_unavailable\",\n message: \"A fetch implementation is required in this runtime\",\n retryable: false,\n });\n }\n this.secretKey = secretKey;\n this.apiBase = normalizeBase(options.apiBase ?? DEFAULT_API_BASE);\n this.fetchImpl = options.fetch ?? fetch;\n }\n\n async listPayments(\n query: ListPaymentsQuery = {},\n opts: RequestOptions = {},\n ): Promise<PaymentList> {\n return this.request<PaymentList>(\"GET\", appendQuery(\"/payments\", query), undefined, opts);\n }\n\n async createPayment(body: CreatePaymentRequest, opts: IdempotencyOptions): Promise<Payment>;\n async createPayment(body: CreatePaymentRequest, opts: RequestOptionsInput): Promise<Payment> {\n return this.request<Payment>(\"POST\", \"/payments\", body, opts, true);\n }\n\n async getPayment(paymentId: string, opts: RequestOptions = {}): Promise<Payment> {\n return this.request<Payment>(\n \"GET\",\n `/payments/${encodeURIComponent(paymentId)}`,\n undefined,\n opts,\n );\n }\n\n async capturePayment(\n paymentId: string,\n body: CaptureRequest,\n opts: IdempotencyOptions,\n ): Promise<Payment>;\n async capturePayment(\n paymentId: string,\n body: CaptureRequest,\n opts: RequestOptionsInput,\n ): Promise<Payment> {\n return this.request<Payment>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/capture`,\n body,\n opts,\n true,\n );\n }\n\n async voidPayment(\n paymentId: string,\n body: VoidRequest,\n opts: IdempotencyOptions,\n ): Promise<Payment>;\n async voidPayment(\n paymentId: string,\n body: VoidRequest,\n opts: RequestOptionsInput,\n ): Promise<Payment> {\n return this.request<Payment>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/void`,\n body,\n opts,\n true,\n );\n }\n\n async createRefund(\n paymentId: string,\n body: CreateRefundRequest,\n opts: IdempotencyOptions,\n ): Promise<Refund>;\n async createRefund(\n paymentId: string,\n body: CreateRefundRequest,\n opts: RequestOptionsInput,\n ): Promise<Refund> {\n return this.request<Refund>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/refunds`,\n body,\n opts,\n true,\n );\n }\n\n async chargeSavedCard(\n body: ChargeSavedCardRequest,\n opts: IdempotencyOptions,\n ): Promise<ExecutePaymentResponse>;\n async chargeSavedCard(\n body: ChargeSavedCardRequest,\n opts: RequestOptionsInput,\n ): Promise<ExecutePaymentResponse> {\n return this.request<ExecutePaymentResponse>(\"POST\", \"/payments/saved-card\", body, opts, true);\n }\n\n async executePayment(\n paymentId: string,\n body: ExecutePaymentRequest,\n opts: IdempotencyOptions,\n ): Promise<ExecutePaymentResponse>;\n async executePayment(\n paymentId: string,\n body: ExecutePaymentRequest,\n opts: RequestOptionsInput,\n ): Promise<ExecutePaymentResponse> {\n const requestBody = normalizeExecutePaymentRequest(body);\n return this.request<ExecutePaymentResponse>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/execute`,\n requestBody,\n opts,\n true,\n );\n }\n\n async completeThreeDSMethod(\n paymentId: string,\n body: CompleteThreeDSMethodRequest,\n opts: RequestOptions = {},\n ): Promise<ExecutePaymentResponse> {\n return this.request<ExecutePaymentResponse>(\n \"POST\",\n `/payments/${encodeURIComponent(paymentId)}/complete-3ds-method`,\n body,\n opts,\n );\n }\n\n async listAvailablePaymentMethods(\n query: ListAvailablePaymentMethodsQuery,\n opts: RequestOptions = {},\n ): Promise<AvailablePaymentMethod[]> {\n return this.request<AvailablePaymentMethod[]>(\n \"GET\",\n appendQuery(\"/payment-methods/available\", query),\n undefined,\n opts,\n );\n }\n\n async createLink(body: CreateLinkRequest, opts: IdempotencyOptions): Promise<Link>;\n async createLink(body: CreateLinkRequest, opts: RequestOptionsInput): Promise<Link> {\n return this.request<Link>(\"POST\", \"/links\", body, opts, true);\n }\n\n async getLink(linkId: string, opts: RequestOptions = {}): Promise<Link> {\n return this.request<Link>(\"GET\", `/links/${encodeURIComponent(linkId)}`, undefined, opts);\n }\n\n async cancelLink(linkId: string, opts: RequestOptions = {}): Promise<Link> {\n return this.request<Link>(\"DELETE\", `/links/${encodeURIComponent(linkId)}`, undefined, opts);\n }\n\n async createCheckoutSession(\n body: CreateCheckoutSessionRequest,\n opts: IdempotencyOptions,\n ): Promise<CheckoutSession>;\n async createCheckoutSession(\n body: CreateCheckoutSessionRequest,\n opts: RequestOptionsInput,\n ): Promise<CheckoutSession> {\n return this.request<CheckoutSession>(\"POST\", \"/checkout/sessions\", body, opts, true);\n }\n\n private async request<T>(\n method: \"GET\" | \"POST\" | \"DELETE\",\n path: string,\n body: unknown,\n opts: RequestOptionsInput = undefined,\n requireIdempotency = false,\n ): Promise<T> {\n const requestOpts = normalizeRequestOptions(opts);\n const headers: Record<string, string> = {\n Authorization: `Bearer ${this.secretKey}`,\n \"X-Arc-Pay-API-Version\": API_VERSION,\n \"Content-Type\": \"application/json\",\n };\n if (requireIdempotency) {\n headers[\"Idempotency-Key\"] = requireIdempotencyKey(requestOpts);\n } else if (requestOpts.idempotencyKey !== undefined) {\n headers[\"Idempotency-Key\"] = requireIdempotencyKey(requestOpts);\n }\n\n let res: Response;\n try {\n res = await this.fetchImpl(`${this.apiBase}${path}`, {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: requestOpts.signal,\n });\n } catch (err) {\n throw new ArcPayError({\n type: \"network_error\",\n message: err instanceof Error ? err.message : \"Network request failed\",\n retryable: true,\n });\n }\n if (!res.ok) throw await parseErrorResponse(res);\n return (await res.json()) as T;\n }\n}\n\nexport const createArcPayClient = (options: ArcPayClientOptions): ArcPayClient =>\n new ArcPayClient(options);\n","import type { PaymentNextAction } from \"../server/types\";\n\nexport type ThreeDSAction = PaymentNextAction;\n\nexport interface BrowserFormField {\n name: string;\n value: string;\n}\n\nexport interface BrowserPostForm {\n action: string;\n method: \"POST\";\n target: \"hidden_iframe\" | \"browser\";\n fields: BrowserFormField[];\n}\n\nexport const getThreeDSAction = (nextAction?: PaymentNextAction): PaymentNextAction | null => {\n return nextAction ?? null;\n};\n\nexport const buildThreeDSBrowserForm = (nextAction: PaymentNextAction): BrowserPostForm => ({\n action: nextAction.three_ds.submit.url,\n method: nextAction.three_ds.submit.method,\n target: nextAction.three_ds.submit.target,\n fields: nextAction.three_ds.submit.fields,\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thavguard/arc-pay",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Arc Pay browser SDK — publishable-key tokenization, Hosted Fields, and React bindings",
5
5
  "private": false,
6
6
  "license": "MIT",