@superdurable/connector-adyen 0.1.0 → 0.2.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.
package/dist/index.js CHANGED
@@ -1,7 +1,41 @@
1
1
  import {
2
+ AvailablePaymentMethodSchema,
3
+ CancelPaymentBranch,
4
+ CancelPaymentBranchDefect,
5
+ CancelPaymentBranchProviderRejected,
6
+ CancelPaymentBranchReceived,
7
+ CancelPaymentDefinition,
8
+ CancelPaymentMetadata,
9
+ CapturePaymentBranch,
10
+ CapturePaymentBranchDefect,
11
+ CapturePaymentBranchProviderRejected,
12
+ CapturePaymentBranchReceived,
13
+ CapturePaymentDefinition,
14
+ CapturePaymentMetadata,
15
+ CardBrandSchema,
16
+ CardBrandsSchema,
2
17
  ConfigSchema,
3
18
  Connection,
4
19
  ConnectorID,
20
+ CreatePaymentLinkBranch,
21
+ CreatePaymentLinkBranchCreated,
22
+ CreatePaymentLinkBranchDefect,
23
+ CreatePaymentLinkBranchInvalidResponse,
24
+ CreatePaymentLinkBranchProviderRejected,
25
+ CreatePaymentLinkDefinition,
26
+ CreatePaymentLinkInputSchema,
27
+ CreatePaymentLinkMetadata,
28
+ CreatedPaymentLinkSchema,
29
+ CredentialMaterialError,
30
+ ExpirePaymentLinkBranch,
31
+ ExpirePaymentLinkBranchDefect,
32
+ ExpirePaymentLinkBranchExpired,
33
+ ExpirePaymentLinkBranchInvalidResponse,
34
+ ExpirePaymentLinkBranchNotFound,
35
+ ExpirePaymentLinkBranchProviderRejected,
36
+ ExpirePaymentLinkDefinition,
37
+ ExpirePaymentLinkInputSchema,
38
+ ExpirePaymentLinkMetadata,
5
39
  GetPaymentLinkBranch,
6
40
  GetPaymentLinkBranchDefect,
7
41
  GetPaymentLinkBranchFound,
@@ -11,16 +45,145 @@ import {
11
45
  GetPaymentLinkDefinition,
12
46
  GetPaymentLinkInputSchema,
13
47
  GetPaymentLinkMetadata,
48
+ ListPaymentMethodsBranch,
49
+ ListPaymentMethodsBranchDefect,
50
+ ListPaymentMethodsBranchInvalidResponse,
51
+ ListPaymentMethodsBranchListed,
52
+ ListPaymentMethodsBranchProviderRejected,
53
+ ListPaymentMethodsDefinition,
54
+ ListPaymentMethodsInputSchema,
55
+ ListPaymentMethodsMetadata,
56
+ LookupCardBrandsByBINBranch,
57
+ LookupCardBrandsByBINBranchDefect,
58
+ LookupCardBrandsByBINBranchFound,
59
+ LookupCardBrandsByBINBranchInvalidResponse,
60
+ LookupCardBrandsByBINBranchProviderRejected,
61
+ LookupCardBrandsByBINDefinition,
62
+ LookupCardBrandsByBINInputSchema,
63
+ LookupCardBrandsByBINMetadata,
14
64
  PaymentLinkStatusSchema,
65
+ PaymentMethodPageSchema,
66
+ PaymentModificationInputSchema,
67
+ PaymentModificationReceiptSchema,
68
+ PaymentReferenceModificationInputSchema,
15
69
  ProviderID,
70
+ RefundPaymentBranch,
71
+ RefundPaymentBranchDefect,
72
+ RefundPaymentBranchProviderRejected,
73
+ RefundPaymentBranchReceived,
74
+ RefundPaymentDefinition,
75
+ RefundPaymentMetadata,
76
+ ReversePaymentBranch,
77
+ ReversePaymentBranchDefect,
78
+ ReversePaymentBranchProviderRejected,
79
+ ReversePaymentBranchReceived,
80
+ ReversePaymentDefinition,
81
+ ReversePaymentMetadata,
82
+ UpdateAuthorisedAmountBranch,
83
+ UpdateAuthorisedAmountBranchDefect,
84
+ UpdateAuthorisedAmountBranchProviderRejected,
85
+ UpdateAuthorisedAmountBranchReceived,
86
+ UpdateAuthorisedAmountDefinition,
87
+ UpdateAuthorisedAmountMetadata,
16
88
  decodeCredentials,
89
+ decodeSignedInteger,
90
+ exactIntegerJSONCodec,
91
+ isCredentialMaterialError,
17
92
  newConnection,
18
93
  newConnectionWithOperations,
19
- newProjectConnection
20
- } from "./chunk-CHGEL2F6.js";
94
+ newProjectConnection,
95
+ parseExactIntegerJSON,
96
+ parseJSONNumberTokens
97
+ } from "./chunk-P6IMRLQ6.js";
21
98
 
22
99
  // src/generated/steps.ts
23
- import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
100
+ import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
101
+ function newLookupCardBrandsByBINStep(configuration) {
102
+ const { connection, connectionName, found, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
103
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
104
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.lookupCardBrandsByBIN(), connection: connection.reference, branches: [
105
+ goToBranch("found", found),
106
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
107
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
108
+ ...defect ? [goToBranch("defect", defect)] : []
109
+ ] });
110
+ }
111
+ function newCapturePaymentStep(configuration) {
112
+ const { connection, connectionName, received, providerRejected, defect, maxSends, ...stepConfiguration } = configuration;
113
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
114
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.capturePayment(), connection: connection.reference, branches: [
115
+ goToBranch("received", received),
116
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
117
+ ...defect ? [goToBranch("defect", defect)] : []
118
+ ] });
119
+ }
120
+ function newCancelPaymentStep(configuration) {
121
+ const { connection, connectionName, received, providerRejected, defect, maxSends, ...stepConfiguration } = configuration;
122
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
123
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.cancelPayment(), connection: connection.reference, branches: [
124
+ goToBranch("received", received),
125
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
126
+ ...defect ? [goToBranch("defect", defect)] : []
127
+ ] });
128
+ }
129
+ function newRefundPaymentStep(configuration) {
130
+ const { connection, connectionName, received, providerRejected, defect, maxSends, ...stepConfiguration } = configuration;
131
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
132
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.refundPayment(), connection: connection.reference, branches: [
133
+ goToBranch("received", received),
134
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
135
+ ...defect ? [goToBranch("defect", defect)] : []
136
+ ] });
137
+ }
138
+ function newReversePaymentStep(configuration) {
139
+ const { connection, connectionName, received, providerRejected, defect, maxSends, ...stepConfiguration } = configuration;
140
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
141
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.reversePayment(), connection: connection.reference, branches: [
142
+ goToBranch("received", received),
143
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
144
+ ...defect ? [goToBranch("defect", defect)] : []
145
+ ] });
146
+ }
147
+ function newUpdateAuthorisedAmountStep(configuration) {
148
+ const { connection, connectionName, received, providerRejected, defect, maxSends, ...stepConfiguration } = configuration;
149
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
150
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateAuthorisedAmount(), connection: connection.reference, branches: [
151
+ goToBranch("received", received),
152
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
153
+ ...defect ? [goToBranch("defect", defect)] : []
154
+ ] });
155
+ }
156
+ function newListPaymentMethodsStep(configuration) {
157
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
158
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
159
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listPaymentMethods(), connection: connection.reference, branches: [
160
+ goToBranch("listed", listed),
161
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
162
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
163
+ ...defect ? [goToBranch("defect", defect)] : []
164
+ ] });
165
+ }
166
+ function newCreatePaymentLinkStep(configuration) {
167
+ const { connection, connectionName, created, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
168
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
169
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.createPaymentLink(), connection: connection.reference, branches: [
170
+ goToBranch("created", created),
171
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
172
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
173
+ ...defect ? [goToBranch("defect", defect)] : []
174
+ ] });
175
+ }
176
+ function newExpirePaymentLinkStep(configuration) {
177
+ const { connection, connectionName, expired, notFound, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
178
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
179
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.expirePaymentLink(), connection: connection.reference, branches: [
180
+ goToBranch("expired", expired),
181
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
182
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
183
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
184
+ ...defect ? [goToBranch("defect", defect)] : []
185
+ ] });
186
+ }
24
187
  function newGetPaymentLinkStep(configuration) {
25
188
  const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
26
189
  if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
@@ -38,8 +201,428 @@ import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
38
201
  import { z } from "zod";
39
202
 
40
203
  // src/client.ts
41
- import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
42
- import { BodyTooLargeError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
204
+ import { SecretString, newQueryBranch as newQueryBranch2, newQueryRetry as newQueryRetry2 } from "@superdurable/connectors-sdk";
205
+ import { BodyTooLargeError, ProviderTransportError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
206
+
207
+ // src/resources.ts
208
+ import {
209
+ newMutationBranch,
210
+ newMutationRetry,
211
+ newQueryBranch,
212
+ newQueryRetry
213
+ } from "@superdurable/connectors-sdk";
214
+ var LookupCardBrandsByBINOperation = class {
215
+ /** Bind the authenticated client. */
216
+ constructor(client) {
217
+ this.client = client;
218
+ }
219
+ client;
220
+ /** Return the generated operation contract. */
221
+ definition() {
222
+ return LookupCardBrandsByBINDefinition;
223
+ }
224
+ /** Look up the supported schemes for a six-digit issuer BIN. */
225
+ invoke(call, input) {
226
+ return lookupCardBrandsByBIN(this.client, call, input);
227
+ }
228
+ };
229
+ var CapturePaymentOperation = class {
230
+ /** Bind the authenticated client. */
231
+ constructor(client) {
232
+ this.client = client;
233
+ }
234
+ client;
235
+ /** Return the generated operation contract. */
236
+ definition() {
237
+ return CapturePaymentDefinition;
238
+ }
239
+ /** Use the Dex call ID across attempts. */
240
+ idempotencyKey(callId) {
241
+ return callId;
242
+ }
243
+ /** Request capture of an authorized payment. */
244
+ invoke(call, input) {
245
+ return capturePayment(this.client, call, input);
246
+ }
247
+ };
248
+ var CancelPaymentOperation = class {
249
+ /** Bind the authenticated client. */
250
+ constructor(client) {
251
+ this.client = client;
252
+ }
253
+ client;
254
+ /** Return the generated operation contract. */
255
+ definition() {
256
+ return CancelPaymentDefinition;
257
+ }
258
+ /** Use the Dex call ID across attempts. */
259
+ idempotencyKey(callId) {
260
+ return callId;
261
+ }
262
+ /** Request cancellation of an authorized payment. */
263
+ invoke(call, input) {
264
+ return cancelPayment(this.client, call, input);
265
+ }
266
+ };
267
+ var RefundPaymentOperation = class {
268
+ /** Bind the authenticated client. */
269
+ constructor(client) {
270
+ this.client = client;
271
+ }
272
+ client;
273
+ /** Return the generated operation contract. */
274
+ definition() {
275
+ return RefundPaymentDefinition;
276
+ }
277
+ /** Use the Dex call ID across attempts. */
278
+ idempotencyKey(callId) {
279
+ return callId;
280
+ }
281
+ /** Request a refund for a captured payment. */
282
+ invoke(call, input) {
283
+ return refundPayment(this.client, call, input);
284
+ }
285
+ };
286
+ var ReversePaymentOperation = class {
287
+ /** Bind the authenticated client. */
288
+ constructor(client) {
289
+ this.client = client;
290
+ }
291
+ client;
292
+ /** Return the generated operation contract. */
293
+ definition() {
294
+ return ReversePaymentDefinition;
295
+ }
296
+ /** Use the Dex call ID across attempts. */
297
+ idempotencyKey(callId) {
298
+ return callId;
299
+ }
300
+ /** Request reversal of a payment. */
301
+ invoke(call, input) {
302
+ return reversePayment(this.client, call, input);
303
+ }
304
+ };
305
+ var UpdateAuthorisedAmountOperation = class {
306
+ /** Bind the authenticated client. */
307
+ constructor(client) {
308
+ this.client = client;
309
+ }
310
+ client;
311
+ /** Return the generated operation contract. */
312
+ definition() {
313
+ return UpdateAuthorisedAmountDefinition;
314
+ }
315
+ /** Use the Dex call ID across attempts. */
316
+ idempotencyKey(callId) {
317
+ return callId;
318
+ }
319
+ /** Set the new amount of an authorized payment. */
320
+ invoke(call, input) {
321
+ return updateAuthorisedAmount(this.client, call, input);
322
+ }
323
+ };
324
+ var ListPaymentMethodsOperation = class {
325
+ /** Bind the authenticated client. */
326
+ constructor(client) {
327
+ this.client = client;
328
+ }
329
+ client;
330
+ /** Return the generated operation contract. */
331
+ definition() {
332
+ return ListPaymentMethodsDefinition;
333
+ }
334
+ /** List the methods available for a proposed payment. */
335
+ invoke(call, input) {
336
+ return listPaymentMethods(this.client, call, input);
337
+ }
338
+ };
339
+ var CreatePaymentLinkOperation = class {
340
+ /** Bind the authenticated client. */
341
+ constructor(client) {
342
+ this.client = client;
343
+ }
344
+ client;
345
+ /** Return the generated operation contract. */
346
+ definition() {
347
+ return CreatePaymentLinkDefinition;
348
+ }
349
+ /** Use the Dex call ID across attempts. */
350
+ idempotencyKey(callId) {
351
+ return callId;
352
+ }
353
+ /** Create a hosted Adyen payment link. */
354
+ invoke(call, input) {
355
+ return createPaymentLink(this.client, call, input);
356
+ }
357
+ };
358
+ var ExpirePaymentLinkOperation = class {
359
+ /** Bind the authenticated client. */
360
+ constructor(client) {
361
+ this.client = client;
362
+ }
363
+ client;
364
+ /** Return the generated operation contract. */
365
+ definition() {
366
+ return ExpirePaymentLinkDefinition;
367
+ }
368
+ /** Use the Dex call ID across attempts. */
369
+ idempotencyKey(callId) {
370
+ return callId;
371
+ }
372
+ /** Set an existing payment link to expired. */
373
+ invoke(call, input) {
374
+ return expirePaymentLink(this.client, call, input);
375
+ }
376
+ };
377
+ var pspReference = /^[A-Za-z0-9]{16,64}$/;
378
+ var refusalStatuses = /* @__PURE__ */ new Set([400, 401, 403, 404, 411, 413, 414, 415, 422]);
379
+ var emptyLink = () => ({ id: "", status: "", currencyCode: "" });
380
+ var emptyModification = () => ({
381
+ paymentPspReference: "",
382
+ modificationPspReference: "",
383
+ status: ""
384
+ });
385
+ async function lookupCardBrandsByBIN(client, call, input) {
386
+ const operation = "lookupCardBrandsByBIN";
387
+ const empty = { brands: [] };
388
+ if (!merchant(input.merchantAccount) || !/^[0-9]{6}$/.test(input.issuerBin) || !country(input.countryCode)) {
389
+ return queryBranch(operation, "defect", empty, "VALIDATION");
390
+ }
391
+ return query(client, call, operation, "/cardDetails", {
392
+ merchantAccount: input.merchantAccount,
393
+ cardNumber: input.issuerBin,
394
+ ...input.countryCode ? { countryCode: input.countryCode } : {}
395
+ }, "found", empty, cardBrands);
396
+ }
397
+ async function listPaymentMethods(client, call, input) {
398
+ const operation = "listPaymentMethods";
399
+ const empty = { methods: [] };
400
+ const amount = money(input.currencyCode, input.amountMinorUnits);
401
+ if (!merchant(input.merchantAccount) || !amount || !country(input.countryCode)) {
402
+ return queryBranch(operation, "defect", empty, "VALIDATION");
403
+ }
404
+ return query(
405
+ client,
406
+ call,
407
+ operation,
408
+ "/paymentMethods",
409
+ checkoutPayload(input.merchantAccount, amount, input.countryCode),
410
+ "listed",
411
+ empty,
412
+ paymentMethods
413
+ );
414
+ }
415
+ async function query(client, call, operation, path, payload, branch, empty, decode) {
416
+ const response = await client.exchange(call, "POST", path, payload);
417
+ if (response.error === "credential") return queryBranch(operation, "defect", empty, "AUTHENTICATION");
418
+ const kind = temporaryFailure(response);
419
+ if (kind) return newQueryRetry(failure(operation, kind), response.retryAfterMs);
420
+ if (response.status !== 200) return queryBranch(operation, "providerRejected", empty, "PROVIDER_REJECTION");
421
+ if (response.error === "tooLarge") return queryBranch(operation, "invalidResponse", empty, "RESPONSE_TOO_LARGE");
422
+ if (response.error) return newQueryRetry(failure(operation, "TRANSPORT"));
423
+ const output = decode(response.body);
424
+ return output ? newQueryBranch(branch, output) : queryBranch(operation, "invalidResponse", empty, "PROTOCOL");
425
+ }
426
+ async function createPaymentLink(client, call, input) {
427
+ const operation = "createPaymentLink";
428
+ const empty = { ...emptyLink(), amountMinorUnits: 0, url: "" };
429
+ const amount = money(input.currencyCode, input.amountMinorUnits);
430
+ if (!merchant(input.merchantAccount) || !input.reference || !boundedText(input.reference, 80) || !amount || !country(input.countryCode) || !validIdempotencyKey(call)) {
431
+ return mutationBranch(operation, "defect", empty, "VALIDATION");
432
+ }
433
+ const response = await client.exchange(call, "POST", "/paymentLinks", {
434
+ ...checkoutPayload(input.merchantAccount, amount, input.countryCode),
435
+ reference: input.reference
436
+ }, true);
437
+ return write(call, operation, response, 201, "created", empty, (body) => {
438
+ const document = preciseDocument(body);
439
+ if (!document || !isObject(document.amount) || !isValidPaymentLinkID(document.id) || document.status !== "active" || document.amount.currency !== amount.currency || !hostedURL(document.url)) return void 0;
440
+ const confirmedAmount = money(document.amount.currency, document.amount.value);
441
+ if (!confirmedAmount || integerValue(confirmedAmount.value) !== integerValue(amount.value)) return void 0;
442
+ return {
443
+ value: {
444
+ id: document.id,
445
+ status: "active",
446
+ currencyCode: amount.currency,
447
+ amountMinorUnits: confirmedAmount.value,
448
+ url: document.url
449
+ },
450
+ providerId: document.id
451
+ };
452
+ }, { classifiesSize: true });
453
+ }
454
+ async function expirePaymentLink(client, call, input) {
455
+ const operation = "expirePaymentLink";
456
+ const id = input.paymentLinkId;
457
+ if (!isValidPaymentLinkID(id)) return mutationBranch(operation, "defect", emptyLink(), "VALIDATION");
458
+ const response = await client.exchange(call, "PATCH", "/paymentLinks/" + id, { status: "expired" });
459
+ return write(call, operation, response, 200, "expired", emptyLink(), (body) => {
460
+ const value = decodePaymentLink(body, id);
461
+ return value?.status === "expired" ? { value, providerId: id } : void 0;
462
+ }, { handlesNotFound: true, classifiesSize: true });
463
+ }
464
+ async function capturePayment(client, call, input) {
465
+ return modify(client, call, "capturePayment", "captures", input, true);
466
+ }
467
+ async function cancelPayment(client, call, input) {
468
+ return modify(client, call, "cancelPayment", "cancels", input, false);
469
+ }
470
+ async function refundPayment(client, call, input) {
471
+ return modify(client, call, "refundPayment", "refunds", input, true);
472
+ }
473
+ async function reversePayment(client, call, input) {
474
+ return modify(client, call, "reversePayment", "reversals", input, false);
475
+ }
476
+ async function updateAuthorisedAmount(client, call, input) {
477
+ return modify(client, call, "updateAuthorisedAmount", "amountUpdates", input, true);
478
+ }
479
+ async function modify(client, call, operation, route, input, requiresAmount) {
480
+ const empty = emptyModification();
481
+ const amount = "currencyCode" in input && "amountMinorUnits" in input ? money(input.currencyCode, input.amountMinorUnits) : void 0;
482
+ if (!merchant(input.merchantAccount) || !pspReference.test(input.paymentPspReference) || !boundedText(input.reference ?? "", 80) || !validIdempotencyKey(call) || requiresAmount && !amount) {
483
+ return mutationBranch(operation, "defect", empty, "VALIDATION");
484
+ }
485
+ const response = await client.exchange(call, "POST", `/payments/${input.paymentPspReference}/${route}`, {
486
+ merchantAccount: input.merchantAccount,
487
+ ...input.reference ? { reference: input.reference } : {},
488
+ ...requiresAmount ? { amount } : {}
489
+ }, true);
490
+ return write(call, operation, response, 201, "received", empty, (body) => {
491
+ const result = parseJSON(body);
492
+ if (!isObject(result) || result.merchantAccount !== input.merchantAccount || result.paymentPspReference !== input.paymentPspReference || typeof result.pspReference !== "string" || !pspReference.test(result.pspReference) || result.status !== "received") return void 0;
493
+ return {
494
+ value: {
495
+ paymentPspReference: result.paymentPspReference,
496
+ modificationPspReference: result.pspReference,
497
+ status: "received"
498
+ },
499
+ providerId: result.pspReference
500
+ };
501
+ });
502
+ }
503
+ function write(call, operation, response, successStatus, branch, empty, decode, policy = {}) {
504
+ const isFirstAttempt = (call.context?.attempt ?? 1) === 1;
505
+ if (response.error === "credential") {
506
+ return isFirstAttempt ? mutationBranch(operation, "defect", empty, "AUTHENTICATION") : retry(operation, "AUTHENTICATION");
507
+ }
508
+ const kind = temporaryFailure(response);
509
+ if (kind) return retry(operation, kind, response.retryAfterMs);
510
+ if (response.status !== successStatus) {
511
+ if (isFirstAttempt && definiteRefusal(response)) {
512
+ return response.status === 404 && policy.handlesNotFound ? mutationBranch(operation, "notFound", empty, "NOT_FOUND") : mutationBranch(operation, "providerRejected", empty, "PROVIDER_REJECTION");
513
+ }
514
+ return retry(operation, "TRANSPORT");
515
+ }
516
+ if (response.error === "tooLarge" && policy.classifiesSize) return retry(operation, "RESPONSE_TOO_LARGE");
517
+ if (response.error) return retry(operation, "TRANSPORT");
518
+ const result = decode(response.body);
519
+ if (!result) return retry(operation, "PROTOCOL");
520
+ return newMutationBranch(branch, result.value, {
521
+ callId: call.id,
522
+ provider: "adyen",
523
+ providerObjectId: result.providerId,
524
+ observedAt: (/* @__PURE__ */ new Date()).toISOString(),
525
+ ...call.idempotencyKey ? { idempotencyKey: call.idempotencyKey } : {}
526
+ });
527
+ }
528
+ function definiteRefusal(response) {
529
+ if (response.error || !refusalStatuses.has(response.status)) return false;
530
+ const doc = parseJSON(response.body);
531
+ return isObject(doc) && doc.status === response.status && typeof doc.errorCode === "string" && Boolean(doc.errorCode) && (doc.id == null || doc.id === "") && (doc.pspReference == null || doc.pspReference === "");
532
+ }
533
+ function cardBrands(body) {
534
+ const doc = parseJSON(body);
535
+ if (!isObject(doc) || !Array.isArray(doc.brands)) return void 0;
536
+ const brands = [];
537
+ for (const entry of doc.brands) {
538
+ if (!isObject(entry) || typeof entry.type !== "string" || !entry.type || Buffer.byteLength(entry.type) > 64 || /[\r\n]/.test(entry.type)) return void 0;
539
+ const supported = entry.supported ?? false;
540
+ if (typeof supported !== "boolean") return void 0;
541
+ brands.push({ type: entry.type, supported });
542
+ }
543
+ return { brands };
544
+ }
545
+ function paymentMethods(body) {
546
+ const doc = parseJSON(body);
547
+ if (!isObject(doc) || !Array.isArray(doc.paymentMethods) || doc.paymentMethods.length > 500) return void 0;
548
+ const methods = [];
549
+ for (const entry of doc.paymentMethods) {
550
+ if (!isObject(entry) || typeof entry.type !== "string" || !entry.type || typeof entry.name !== "string" || !entry.name) return void 0;
551
+ methods.push({ type: entry.type, name: entry.name });
552
+ }
553
+ return { methods };
554
+ }
555
+ function preciseDocument(body) {
556
+ try {
557
+ const document = parseJSONNumberTokens(Buffer.from(body).toString("utf8"));
558
+ return isObject(document) ? document : void 0;
559
+ } catch {
560
+ return void 0;
561
+ }
562
+ }
563
+ function parseJSON(body) {
564
+ try {
565
+ return JSON.parse(Buffer.from(body).toString("utf8"));
566
+ } catch {
567
+ return void 0;
568
+ }
569
+ }
570
+ function money(currency, value) {
571
+ if (typeof currency !== "string" || !/^[A-Z]{3}$/.test(currency)) return void 0;
572
+ try {
573
+ const amount = decodeSignedInteger(value);
574
+ return integerValue(amount) > 0n ? { currency, value: amount } : void 0;
575
+ } catch {
576
+ return void 0;
577
+ }
578
+ }
579
+ function integerValue(value) {
580
+ return BigInt(typeof value === "number" ? value : value.rawJSON);
581
+ }
582
+ function checkoutPayload(merchantAccount, amount, countryCode) {
583
+ return { merchantAccount, amount, ...countryCode ? { countryCode } : {} };
584
+ }
585
+ function hostedURL(value) {
586
+ if (typeof value !== "string" || !/^https:\/\//i.test(value) || /[\p{Cc}\s]/u.test(value)) return false;
587
+ try {
588
+ const url = new URL(value);
589
+ return url.protocol === "https:" && Boolean(url.hostname) && !url.username && !url.password && !url.hash;
590
+ } catch {
591
+ return false;
592
+ }
593
+ }
594
+ function merchant(value) {
595
+ return Boolean(value) && boundedText(value, 128);
596
+ }
597
+ function boundedText(value, limit) {
598
+ return value.trim() === value && Buffer.byteLength(value) <= limit && !/[\r\n\p{Surrogate}]/u.test(value);
599
+ }
600
+ function country(value) {
601
+ return !value || /^[A-Z]{2}$/.test(value);
602
+ }
603
+ function validIdempotencyKey(call) {
604
+ return Boolean(call.idempotencyKey) && Buffer.byteLength(call.idempotencyKey ?? "") <= 64;
605
+ }
606
+ function temporaryFailure(response) {
607
+ if (response.error === "request") return "TRANSPORT";
608
+ if (response.status === 429) return "RATE_LIMIT";
609
+ if (response.status === 408 || response.status >= 500) return "AVAILABILITY";
610
+ return void 0;
611
+ }
612
+ function failure(operation, kind) {
613
+ return { provider: "adyen", operation, kind, message: `Adyen ${operation}: ${kind.toLowerCase().replaceAll("_", " ")}` };
614
+ }
615
+ function queryBranch(operation, branch, empty, kind) {
616
+ return newQueryBranch(branch, empty, {}, failure(operation, kind));
617
+ }
618
+ function mutationBranch(operation, branch, empty, kind) {
619
+ return newMutationBranch(branch, empty, {}, failure(operation, kind));
620
+ }
621
+ function retry(operation, kind, delay = 0) {
622
+ return newMutationRetry(failure(operation, kind), delay);
623
+ }
624
+
625
+ // src/client.ts
43
626
  var defaultBaseURL = "https://checkout-test.adyen.com/v72";
44
627
  var emptyPaymentLink = () => ({ id: "", status: "", currencyCode: "" });
45
628
  var AdyenClient = class {
@@ -63,8 +646,48 @@ var AdyenClient = class {
63
646
  getPaymentLink() {
64
647
  return new GetPaymentLinkOperation(this);
65
648
  }
649
+ /** Look up the supported schemes for a six-digit issuer BIN. */
650
+ lookupCardBrandsByBIN() {
651
+ return new LookupCardBrandsByBINOperation(this);
652
+ }
653
+ /** Request capture of an authorized payment. */
654
+ capturePayment() {
655
+ return new CapturePaymentOperation(this);
656
+ }
657
+ /** Request cancellation of an authorized payment. */
658
+ cancelPayment() {
659
+ return new CancelPaymentOperation(this);
660
+ }
661
+ /** Request a refund for a captured payment. */
662
+ refundPayment() {
663
+ return new RefundPaymentOperation(this);
664
+ }
665
+ /** Request reversal of a payment. */
666
+ reversePayment() {
667
+ return new ReversePaymentOperation(this);
668
+ }
669
+ /** Set the new amount of an authorized payment. */
670
+ updateAuthorisedAmount() {
671
+ return new UpdateAuthorisedAmountOperation(this);
672
+ }
673
+ /** List the methods available for a proposed payment. */
674
+ listPaymentMethods() {
675
+ return new ListPaymentMethodsOperation(this);
676
+ }
677
+ /** Create a hosted Adyen payment link. */
678
+ createPaymentLink() {
679
+ return new CreatePaymentLinkOperation(this);
680
+ }
681
+ /** Set an existing payment link to expired. */
682
+ expirePaymentLink() {
683
+ return new ExpirePaymentLinkOperation(this);
684
+ }
66
685
  /** Resolve the API key and send one bounded payment link lookup. */
67
686
  async get(call, paymentLinkID) {
687
+ return this.exchange(call, "GET", "/paymentLinks/" + encodeURIComponent(paymentLinkID));
688
+ }
689
+ /** Make a bounded request using the current Adyen credentials. */
690
+ async exchange(call, method, path, payload, usesIdempotencyKey = false) {
68
691
  let apiKey;
69
692
  try {
70
693
  const credentials = await this.credentials.resolve(call, call.context.cancellationSignal);
@@ -74,9 +697,15 @@ var AdyenClient = class {
74
697
  }
75
698
  if (!apiKey || !isHeaderSafeCredential(apiKey)) return emptyExchange("credential");
76
699
  const request = {
77
- url: `${this.baseURL}/paymentLinks/${encodeURIComponent(paymentLinkID)}`,
78
- method: "GET",
79
- headers: { Accept: "application/json", "X-API-Key": apiKey },
700
+ url: this.baseURL + path,
701
+ method,
702
+ headers: {
703
+ Accept: "application/json",
704
+ "X-API-Key": apiKey,
705
+ ...payload ? { "Content-Type": "application/json" } : {},
706
+ ...usesIdempotencyKey && call.idempotencyKey ? { "Idempotency-Key": call.idempotencyKey } : {}
707
+ },
708
+ ...payload ? { body: Buffer.from(JSON.stringify(payload)) } : {},
80
709
  maxResponseBytes: this.maxResponseBytes,
81
710
  timeoutMs: this.timeoutMs,
82
711
  addressPolicy: this.baseURL.startsWith("https://") ? "publicHTTPS" : "privateNetworkHTTP",
@@ -90,6 +719,13 @@ var AdyenClient = class {
90
719
  if (error instanceof BodyTooLargeError && error.status !== void 0) {
91
720
  response = { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() };
92
721
  isTooLarge = true;
722
+ } else if (error instanceof ProviderTransportError && error.status !== void 0) {
723
+ return {
724
+ status: error.status,
725
+ body: new Uint8Array(),
726
+ retryAfterMs: parseRetryAfter(header(error.headers ?? {}, "retry-after")),
727
+ error: "interrupted"
728
+ };
93
729
  } else return emptyExchange("request");
94
730
  }
95
731
  const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"));
@@ -114,15 +750,16 @@ var GetPaymentLinkOperation = class {
114
750
  return terminal("defect", "VALIDATION", "payment link ID must contain 1\u2013128 URL-safe characters");
115
751
  const exchange = await this.client.get(call, input.paymentLinkId);
116
752
  if (exchange.error === "credential") return terminal("defect", "AUTHENTICATION", "Adyen credentials are unavailable or invalid");
117
- if (exchange.error === "request") return retry("TRANSPORT", "Adyen request failed");
118
- if (exchange.status === 429) return retry("RATE_LIMIT", "Adyen rate limited the request", exchange.retryAfterMs);
119
- if (exchange.status === 408 || exchange.status >= 500) return retry("AVAILABILITY", "Adyen is temporarily unavailable", exchange.retryAfterMs);
753
+ if (exchange.error === "request") return retry2("TRANSPORT", "Adyen request failed");
754
+ if (exchange.status === 429) return retry2("RATE_LIMIT", "Adyen rate limited the request", exchange.retryAfterMs);
755
+ if (exchange.status === 408 || exchange.status >= 500) return retry2("AVAILABILITY", "Adyen is temporarily unavailable", exchange.retryAfterMs);
120
756
  if (exchange.status === 404) return terminal("notFound", "NOT_FOUND", "Adyen did not expose the payment link");
121
757
  if (exchange.status !== 200) return terminal("providerRejected", "PROVIDER_REJECTION", `Adyen rejected HTTP ${exchange.status}`);
758
+ if (exchange.error === "interrupted") return retry2("TRANSPORT", "Adyen response was interrupted");
122
759
  if (exchange.error === "tooLarge") return terminal("invalidResponse", "RESPONSE_TOO_LARGE", "Adyen response exceeded the configured limit");
123
760
  const paymentLinkStatus = decodePaymentLink(exchange.body, input.paymentLinkId);
124
761
  if (!paymentLinkStatus) return terminal("invalidResponse", "PROTOCOL", "Adyen returned invalid payment link JSON");
125
- return newQueryBranch("found", paymentLinkStatus);
762
+ return newQueryBranch2("found", paymentLinkStatus);
126
763
  }
127
764
  };
128
765
  function isValidPaymentLinkID(value) {
@@ -131,14 +768,14 @@ function isValidPaymentLinkID(value) {
131
768
  function emptyExchange(error) {
132
769
  return { status: 0, body: new Uint8Array(), retryAfterMs: 0, error };
133
770
  }
134
- function failure(kind, message) {
771
+ function failure2(kind, message) {
135
772
  return { provider: "adyen", operation: "getPaymentLink", kind, message };
136
773
  }
137
774
  function terminal(branch, kind, message) {
138
- return newQueryBranch(branch, emptyPaymentLink(), {}, failure(kind, message));
775
+ return newQueryBranch2(branch, emptyPaymentLink(), {}, failure2(kind, message));
139
776
  }
140
- function retry(kind, message, delay = 0) {
141
- return newQueryRetry(failure(kind, message), delay);
777
+ function retry2(kind, message, delay = 0) {
778
+ return newQueryRetry2(failure2(kind, message), delay);
142
779
  }
143
780
  function header(headers, name) {
144
781
  const entry = Object.entries(headers).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
@@ -197,9 +834,47 @@ function parseDurationMilliseconds(value) {
197
834
  }
198
835
  export {
199
836
  AdyenClient,
837
+ AvailablePaymentMethodSchema,
838
+ CancelPaymentBranch,
839
+ CancelPaymentBranchDefect,
840
+ CancelPaymentBranchProviderRejected,
841
+ CancelPaymentBranchReceived,
842
+ CancelPaymentDefinition,
843
+ CancelPaymentMetadata,
844
+ CancelPaymentOperation,
845
+ CapturePaymentBranch,
846
+ CapturePaymentBranchDefect,
847
+ CapturePaymentBranchProviderRejected,
848
+ CapturePaymentBranchReceived,
849
+ CapturePaymentDefinition,
850
+ CapturePaymentMetadata,
851
+ CapturePaymentOperation,
852
+ CardBrandSchema,
853
+ CardBrandsSchema,
200
854
  ConfigSchema,
201
855
  Connection,
202
856
  ConnectorID,
857
+ CreatePaymentLinkBranch,
858
+ CreatePaymentLinkBranchCreated,
859
+ CreatePaymentLinkBranchDefect,
860
+ CreatePaymentLinkBranchInvalidResponse,
861
+ CreatePaymentLinkBranchProviderRejected,
862
+ CreatePaymentLinkDefinition,
863
+ CreatePaymentLinkInputSchema,
864
+ CreatePaymentLinkMetadata,
865
+ CreatePaymentLinkOperation,
866
+ CreatedPaymentLinkSchema,
867
+ CredentialMaterialError,
868
+ ExpirePaymentLinkBranch,
869
+ ExpirePaymentLinkBranchDefect,
870
+ ExpirePaymentLinkBranchExpired,
871
+ ExpirePaymentLinkBranchInvalidResponse,
872
+ ExpirePaymentLinkBranchNotFound,
873
+ ExpirePaymentLinkBranchProviderRejected,
874
+ ExpirePaymentLinkDefinition,
875
+ ExpirePaymentLinkInputSchema,
876
+ ExpirePaymentLinkMetadata,
877
+ ExpirePaymentLinkOperation,
203
878
  GetPaymentLinkBranch,
204
879
  GetPaymentLinkBranchDefect,
205
880
  GetPaymentLinkBranchFound,
@@ -210,11 +885,68 @@ export {
210
885
  GetPaymentLinkInputSchema,
211
886
  GetPaymentLinkMetadata,
212
887
  GetPaymentLinkOperation,
888
+ ListPaymentMethodsBranch,
889
+ ListPaymentMethodsBranchDefect,
890
+ ListPaymentMethodsBranchInvalidResponse,
891
+ ListPaymentMethodsBranchListed,
892
+ ListPaymentMethodsBranchProviderRejected,
893
+ ListPaymentMethodsDefinition,
894
+ ListPaymentMethodsInputSchema,
895
+ ListPaymentMethodsMetadata,
896
+ ListPaymentMethodsOperation,
897
+ LookupCardBrandsByBINBranch,
898
+ LookupCardBrandsByBINBranchDefect,
899
+ LookupCardBrandsByBINBranchFound,
900
+ LookupCardBrandsByBINBranchInvalidResponse,
901
+ LookupCardBrandsByBINBranchProviderRejected,
902
+ LookupCardBrandsByBINDefinition,
903
+ LookupCardBrandsByBINInputSchema,
904
+ LookupCardBrandsByBINMetadata,
905
+ LookupCardBrandsByBINOperation,
213
906
  PaymentLinkStatusSchema,
907
+ PaymentMethodPageSchema,
908
+ PaymentModificationInputSchema,
909
+ PaymentModificationReceiptSchema,
910
+ PaymentReferenceModificationInputSchema,
214
911
  ProviderID,
912
+ RefundPaymentBranch,
913
+ RefundPaymentBranchDefect,
914
+ RefundPaymentBranchProviderRejected,
915
+ RefundPaymentBranchReceived,
916
+ RefundPaymentDefinition,
917
+ RefundPaymentMetadata,
918
+ RefundPaymentOperation,
919
+ ReversePaymentBranch,
920
+ ReversePaymentBranchDefect,
921
+ ReversePaymentBranchProviderRejected,
922
+ ReversePaymentBranchReceived,
923
+ ReversePaymentDefinition,
924
+ ReversePaymentMetadata,
925
+ ReversePaymentOperation,
926
+ UpdateAuthorisedAmountBranch,
927
+ UpdateAuthorisedAmountBranchDefect,
928
+ UpdateAuthorisedAmountBranchProviderRejected,
929
+ UpdateAuthorisedAmountBranchReceived,
930
+ UpdateAuthorisedAmountDefinition,
931
+ UpdateAuthorisedAmountMetadata,
932
+ UpdateAuthorisedAmountOperation,
215
933
  decodeCredentials,
934
+ decodeSignedInteger,
935
+ exactIntegerJSONCodec,
936
+ isCredentialMaterialError,
937
+ newCancelPaymentStep,
938
+ newCapturePaymentStep,
216
939
  newConnection,
217
940
  newConnectionWithOperations,
941
+ newCreatePaymentLinkStep,
942
+ newExpirePaymentLinkStep,
218
943
  newGetPaymentLinkStep,
219
- newProjectConnection2 as newProjectConnection
944
+ newListPaymentMethodsStep,
945
+ newLookupCardBrandsByBINStep,
946
+ newProjectConnection2 as newProjectConnection,
947
+ newRefundPaymentStep,
948
+ newReversePaymentStep,
949
+ newUpdateAuthorisedAmountStep,
950
+ parseExactIntegerJSON,
951
+ parseJSONNumberTokens
220
952
  };