@superdurable/connector-adyen 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +21 -2
- package/dex-connector.json +597 -0
- package/dist/chunk-P6IMRLQ6.js +489 -0
- package/dist/connection-DqqfBp8C.d.ts +300 -0
- package/dist/index.d.ts +595 -0
- package/dist/index.js +952 -0
- package/dist/mock.d.ts +187 -0
- package/dist/mock.js +459 -0
- package/package.json +59 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,952 @@
|
|
|
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,
|
|
17
|
+
ConfigSchema,
|
|
18
|
+
Connection,
|
|
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,
|
|
39
|
+
GetPaymentLinkBranch,
|
|
40
|
+
GetPaymentLinkBranchDefect,
|
|
41
|
+
GetPaymentLinkBranchFound,
|
|
42
|
+
GetPaymentLinkBranchInvalidResponse,
|
|
43
|
+
GetPaymentLinkBranchNotFound,
|
|
44
|
+
GetPaymentLinkBranchProviderRejected,
|
|
45
|
+
GetPaymentLinkDefinition,
|
|
46
|
+
GetPaymentLinkInputSchema,
|
|
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,
|
|
64
|
+
PaymentLinkStatusSchema,
|
|
65
|
+
PaymentMethodPageSchema,
|
|
66
|
+
PaymentModificationInputSchema,
|
|
67
|
+
PaymentModificationReceiptSchema,
|
|
68
|
+
PaymentReferenceModificationInputSchema,
|
|
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,
|
|
88
|
+
decodeCredentials,
|
|
89
|
+
decodeSignedInteger,
|
|
90
|
+
exactIntegerJSONCodec,
|
|
91
|
+
isCredentialMaterialError,
|
|
92
|
+
newConnection,
|
|
93
|
+
newConnectionWithOperations,
|
|
94
|
+
newProjectConnection,
|
|
95
|
+
parseExactIntegerJSON,
|
|
96
|
+
parseJSONNumberTokens
|
|
97
|
+
} from "./chunk-P6IMRLQ6.js";
|
|
98
|
+
|
|
99
|
+
// src/generated/steps.ts
|
|
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
|
+
}
|
|
187
|
+
function newGetPaymentLinkStep(configuration) {
|
|
188
|
+
const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
189
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
190
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.getPaymentLink(), connection: connection.reference, branches: [
|
|
191
|
+
goToBranch("found", found),
|
|
192
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
193
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
194
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
195
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
196
|
+
] });
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/project.ts
|
|
200
|
+
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
201
|
+
import { z } from "zod";
|
|
202
|
+
|
|
203
|
+
// src/client.ts
|
|
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
|
|
626
|
+
var defaultBaseURL = "https://checkout-test.adyen.com/v72";
|
|
627
|
+
var emptyPaymentLink = () => ({ id: "", status: "", currencyCode: "" });
|
|
628
|
+
var AdyenClient = class {
|
|
629
|
+
/** Validate provider configuration without contacting Adyen. */
|
|
630
|
+
constructor(config, credentials, options = {}) {
|
|
631
|
+
this.credentials = credentials;
|
|
632
|
+
if (!config || !credentials) throw new TypeError("Adyen configuration and credentials are required");
|
|
633
|
+
this.baseURL = validateBaseURL(config.baseUrl || defaultBaseURL);
|
|
634
|
+
this.timeoutMs = config.timeoutMs || 15e3;
|
|
635
|
+
this.maxResponseBytes = config.maxResponseBytes || 1048576;
|
|
636
|
+
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0)
|
|
637
|
+
throw new TypeError("Adyen request limits must be positive integers");
|
|
638
|
+
this.send = options.send ?? sendProviderRequest;
|
|
639
|
+
}
|
|
640
|
+
credentials;
|
|
641
|
+
baseURL;
|
|
642
|
+
timeoutMs;
|
|
643
|
+
maxResponseBytes;
|
|
644
|
+
send;
|
|
645
|
+
/** Bind the getPaymentLink Query. */
|
|
646
|
+
getPaymentLink() {
|
|
647
|
+
return new GetPaymentLinkOperation(this);
|
|
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
|
+
}
|
|
685
|
+
/** Resolve the API key and send one bounded payment link lookup. */
|
|
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) {
|
|
691
|
+
let apiKey;
|
|
692
|
+
try {
|
|
693
|
+
const credentials = await this.credentials.resolve(call, call.context.cancellationSignal);
|
|
694
|
+
apiKey = credentials.apiKey instanceof SecretString ? credentials.apiKey.reveal() : "";
|
|
695
|
+
} catch {
|
|
696
|
+
return emptyExchange("credential");
|
|
697
|
+
}
|
|
698
|
+
if (!apiKey || !isHeaderSafeCredential(apiKey)) return emptyExchange("credential");
|
|
699
|
+
const request = {
|
|
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)) } : {},
|
|
709
|
+
maxResponseBytes: this.maxResponseBytes,
|
|
710
|
+
timeoutMs: this.timeoutMs,
|
|
711
|
+
addressPolicy: this.baseURL.startsWith("https://") ? "publicHTTPS" : "privateNetworkHTTP",
|
|
712
|
+
signal: call.context.cancellationSignal
|
|
713
|
+
};
|
|
714
|
+
let response;
|
|
715
|
+
let isTooLarge = false;
|
|
716
|
+
try {
|
|
717
|
+
response = await this.send(request);
|
|
718
|
+
} catch (error) {
|
|
719
|
+
if (error instanceof BodyTooLargeError && error.status !== void 0) {
|
|
720
|
+
response = { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() };
|
|
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
|
+
};
|
|
729
|
+
} else return emptyExchange("request");
|
|
730
|
+
}
|
|
731
|
+
const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"));
|
|
732
|
+
if (isTooLarge || response.body.length > this.maxResponseBytes)
|
|
733
|
+
return { status: response.status, body: new Uint8Array(), retryAfterMs, error: "tooLarge" };
|
|
734
|
+
return { status: response.status, body: response.body, retryAfterMs };
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
var GetPaymentLinkOperation = class {
|
|
738
|
+
/** Bind the provider client. */
|
|
739
|
+
constructor(client) {
|
|
740
|
+
this.client = client;
|
|
741
|
+
}
|
|
742
|
+
client;
|
|
743
|
+
/** Return the generated Query contract. */
|
|
744
|
+
definition() {
|
|
745
|
+
return GetPaymentLinkDefinition;
|
|
746
|
+
}
|
|
747
|
+
/** Classify provider outcomes consistently with the Go implementation. */
|
|
748
|
+
async invoke(call, input) {
|
|
749
|
+
if (!isValidPaymentLinkID(input?.paymentLinkId))
|
|
750
|
+
return terminal("defect", "VALIDATION", "payment link ID must contain 1\u2013128 URL-safe characters");
|
|
751
|
+
const exchange = await this.client.get(call, input.paymentLinkId);
|
|
752
|
+
if (exchange.error === "credential") return terminal("defect", "AUTHENTICATION", "Adyen credentials are unavailable or invalid");
|
|
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);
|
|
756
|
+
if (exchange.status === 404) return terminal("notFound", "NOT_FOUND", "Adyen did not expose the payment link");
|
|
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");
|
|
759
|
+
if (exchange.error === "tooLarge") return terminal("invalidResponse", "RESPONSE_TOO_LARGE", "Adyen response exceeded the configured limit");
|
|
760
|
+
const paymentLinkStatus = decodePaymentLink(exchange.body, input.paymentLinkId);
|
|
761
|
+
if (!paymentLinkStatus) return terminal("invalidResponse", "PROTOCOL", "Adyen returned invalid payment link JSON");
|
|
762
|
+
return newQueryBranch2("found", paymentLinkStatus);
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
function isValidPaymentLinkID(value) {
|
|
766
|
+
return typeof value === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(value);
|
|
767
|
+
}
|
|
768
|
+
function emptyExchange(error) {
|
|
769
|
+
return { status: 0, body: new Uint8Array(), retryAfterMs: 0, error };
|
|
770
|
+
}
|
|
771
|
+
function failure2(kind, message) {
|
|
772
|
+
return { provider: "adyen", operation: "getPaymentLink", kind, message };
|
|
773
|
+
}
|
|
774
|
+
function terminal(branch, kind, message) {
|
|
775
|
+
return newQueryBranch2(branch, emptyPaymentLink(), {}, failure2(kind, message));
|
|
776
|
+
}
|
|
777
|
+
function retry2(kind, message, delay = 0) {
|
|
778
|
+
return newQueryRetry2(failure2(kind, message), delay);
|
|
779
|
+
}
|
|
780
|
+
function header(headers, name) {
|
|
781
|
+
const entry = Object.entries(headers).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
|
|
782
|
+
return Array.isArray(entry) ? entry[0] ?? "" : entry ?? "";
|
|
783
|
+
}
|
|
784
|
+
function isObject(value) {
|
|
785
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
786
|
+
}
|
|
787
|
+
function decodePaymentLink(body, paymentLinkID) {
|
|
788
|
+
let raw;
|
|
789
|
+
try {
|
|
790
|
+
raw = JSON.parse(Buffer.from(body).toString("utf8"));
|
|
791
|
+
} catch {
|
|
792
|
+
return void 0;
|
|
793
|
+
}
|
|
794
|
+
if (!isObject(raw) || !isObject(raw.amount)) return void 0;
|
|
795
|
+
const amount = raw.amount;
|
|
796
|
+
if (raw.id !== paymentLinkID || typeof raw.status !== "string" || !raw.status.trim() || typeof amount.currency !== "string" || amount.currency.length !== 3) return void 0;
|
|
797
|
+
return { id: paymentLinkID, status: raw.status, currencyCode: amount.currency };
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// src/project.ts
|
|
801
|
+
function newProjectConnection2(project, connectionName) {
|
|
802
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
803
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "adyen" && entry.connectionName === name);
|
|
804
|
+
if (!selected) throw new TypeError("Adyen project connection is not configured");
|
|
805
|
+
const fields = z.strictObject({ baseUrl: z.string().optional(), timeout: z.union([z.string(), z.number().int()]).optional(), maxResponseBytes: z.number().int().optional() }).parse(selected.configuration);
|
|
806
|
+
const timeoutMs = typeof fields.timeout === "number" ? Math.ceil(fields.timeout / 1e6) : fields.timeout ? parseDurationMilliseconds(fields.timeout) : void 0;
|
|
807
|
+
const config = {
|
|
808
|
+
...fields.baseUrl ? { baseUrl: fields.baseUrl } : {},
|
|
809
|
+
...timeoutMs !== void 0 ? { timeoutMs } : {},
|
|
810
|
+
...fields.maxResponseBytes !== void 0 ? { maxResponseBytes: fields.maxResponseBytes } : {}
|
|
811
|
+
};
|
|
812
|
+
const credentials = {
|
|
813
|
+
async resolve(_call, signal) {
|
|
814
|
+
const privateFields = await loadedProject.resolveCredential("adyen", name, signal);
|
|
815
|
+
if (typeof privateFields.api_key !== "string") throw new TypeError("Adyen credentials are unavailable");
|
|
816
|
+
return { apiKey: new SecretString2(privateFields.api_key) };
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
return new AdyenClient(config, credentials);
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
function parseDurationMilliseconds(value) {
|
|
823
|
+
let remaining = value;
|
|
824
|
+
let milliseconds = 0;
|
|
825
|
+
const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
|
|
826
|
+
while (remaining) {
|
|
827
|
+
const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
|
|
828
|
+
if (!part) throw new TypeError("Adyen timeout must be a positive Go duration");
|
|
829
|
+
milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
|
|
830
|
+
remaining = remaining.slice(part[0].length);
|
|
831
|
+
}
|
|
832
|
+
if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("Adyen timeout must resolve to positive whole milliseconds");
|
|
833
|
+
return milliseconds;
|
|
834
|
+
}
|
|
835
|
+
export {
|
|
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,
|
|
854
|
+
ConfigSchema,
|
|
855
|
+
Connection,
|
|
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,
|
|
878
|
+
GetPaymentLinkBranch,
|
|
879
|
+
GetPaymentLinkBranchDefect,
|
|
880
|
+
GetPaymentLinkBranchFound,
|
|
881
|
+
GetPaymentLinkBranchInvalidResponse,
|
|
882
|
+
GetPaymentLinkBranchNotFound,
|
|
883
|
+
GetPaymentLinkBranchProviderRejected,
|
|
884
|
+
GetPaymentLinkDefinition,
|
|
885
|
+
GetPaymentLinkInputSchema,
|
|
886
|
+
GetPaymentLinkMetadata,
|
|
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,
|
|
906
|
+
PaymentLinkStatusSchema,
|
|
907
|
+
PaymentMethodPageSchema,
|
|
908
|
+
PaymentModificationInputSchema,
|
|
909
|
+
PaymentModificationReceiptSchema,
|
|
910
|
+
PaymentReferenceModificationInputSchema,
|
|
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,
|
|
933
|
+
decodeCredentials,
|
|
934
|
+
decodeSignedInteger,
|
|
935
|
+
exactIntegerJSONCodec,
|
|
936
|
+
isCredentialMaterialError,
|
|
937
|
+
newCancelPaymentStep,
|
|
938
|
+
newCapturePaymentStep,
|
|
939
|
+
newConnection,
|
|
940
|
+
newConnectionWithOperations,
|
|
941
|
+
newCreatePaymentLinkStep,
|
|
942
|
+
newExpirePaymentLinkStep,
|
|
943
|
+
newGetPaymentLinkStep,
|
|
944
|
+
newListPaymentMethodsStep,
|
|
945
|
+
newLookupCardBrandsByBINStep,
|
|
946
|
+
newProjectConnection2 as newProjectConnection,
|
|
947
|
+
newRefundPaymentStep,
|
|
948
|
+
newReversePaymentStep,
|
|
949
|
+
newUpdateAuthorisedAmountStep,
|
|
950
|
+
parseExactIntegerJSON,
|
|
951
|
+
parseJSONNumberTokens
|
|
952
|
+
};
|