@puzzle-ui/payment-providers 0.0.0-stage → 0.17.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/README.md +28 -2
- package/ai/instructions.md +10 -0
- package/ai/manifest.json +8 -0
- package/dist/LICENSE +21 -0
- package/dist/adyen.cjs +226 -0
- package/dist/adyen.cjs.map +1 -0
- package/dist/adyen.d.cts +10 -0
- package/dist/adyen.d.ts +10 -0
- package/dist/adyen.js +225 -0
- package/dist/adyen.js.map +1 -0
- package/dist/http-BJTHkHOr.d.cts +10 -0
- package/dist/http-BJTHkHOr.d.ts +10 -0
- package/dist/http-DxPMQ2xk.cjs +113 -0
- package/dist/http-DxPMQ2xk.cjs.map +1 -0
- package/dist/http-Pinf6Gsa.js +66 -0
- package/dist/http-Pinf6Gsa.js.map +1 -0
- package/dist/index.cjs +15 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +7 -0
- package/dist/mollie.cjs +194 -0
- package/dist/mollie.cjs.map +1 -0
- package/dist/mollie.d.cts +9 -0
- package/dist/mollie.d.ts +9 -0
- package/dist/mollie.js +193 -0
- package/dist/mollie.js.map +1 -0
- package/dist/paypal.cjs +207 -0
- package/dist/paypal.cjs.map +1 -0
- package/dist/paypal.d.cts +10 -0
- package/dist/paypal.d.ts +10 -0
- package/dist/paypal.js +206 -0
- package/dist/paypal.js.map +1 -0
- package/dist/signatures-AHsLlFRl.js +35 -0
- package/dist/signatures-AHsLlFRl.js.map +1 -0
- package/dist/signatures-F-65qEDl.cjs +46 -0
- package/dist/signatures-F-65qEDl.cjs.map +1 -0
- package/dist/stripe.cjs +191 -0
- package/dist/stripe.cjs.map +1 -0
- package/dist/stripe.d.cts +10 -0
- package/dist/stripe.d.ts +10 -0
- package/dist/stripe.js +190 -0
- package/dist/stripe.js.map +1 -0
- package/package.json +97 -4
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @puzzle-ui/payment-providers
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Server-only, fetch-based adapters for the provider-independent contracts in
|
|
4
|
+
`@puzzle-ui/commerce`.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { createStripeAdapter } from "@puzzle-ui/payment-providers/stripe";
|
|
8
|
+
|
|
9
|
+
const stripe = createStripeAdapter({
|
|
10
|
+
secretKey: process.env.STRIPE_SECRET_KEY!,
|
|
11
|
+
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET,
|
|
12
|
+
});
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Available adapters:
|
|
16
|
+
|
|
17
|
+
- `@puzzle-ui/payment-providers/stripe`
|
|
18
|
+
- `@puzzle-ui/payment-providers/mollie`
|
|
19
|
+
- `@puzzle-ui/payment-providers/paypal`
|
|
20
|
+
- `@puzzle-ui/payment-providers/adyen`
|
|
21
|
+
|
|
22
|
+
The package never exposes credentials through client-safe exports. Applications
|
|
23
|
+
must calculate totals from trusted server-side order data, use idempotency keys
|
|
24
|
+
for mutations, verify webhooks before processing them, and persist provider
|
|
25
|
+
references separately from internal payment IDs.
|
|
26
|
+
|
|
27
|
+
The adapters use the platform `fetch` API rather than bundling provider SDKs.
|
|
28
|
+
Provider sandbox and production credentials remain the responsibility of the
|
|
29
|
+
host application.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @puzzle-ui/payment-providers
|
|
2
|
+
|
|
3
|
+
Use this package only from server code. It provides optional Stripe, Mollie,
|
|
4
|
+
PayPal, and Adyen adapters for `@puzzle-ui/commerce`; it must not be imported by
|
|
5
|
+
UI, Pieces, browser, or shared client modules.
|
|
6
|
+
|
|
7
|
+
Every payment mutation requires a caller-owned idempotency key and trusted
|
|
8
|
+
server-side amounts. Webhook payloads must be verified before parsing and
|
|
9
|
+
processed through the commerce webhook deduplication contract. Provider
|
|
10
|
+
credentials and webhook secrets must remain in server-side secret storage.
|
package/ai/manifest.json
ADDED
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sjoerd van Den Berg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/adyen.cjs
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_http = require("./http-DxPMQ2xk.cjs");
|
|
3
|
+
const require_signatures = require("./signatures-F-65qEDl.cjs");
|
|
4
|
+
let _puzzle_ui_commerce = require("@puzzle-ui/commerce");
|
|
5
|
+
// src/adyen.ts
|
|
6
|
+
const provider = "adyen";
|
|
7
|
+
const paymentFromAdyen = (value, fallback) => {
|
|
8
|
+
const resultCode = String(value.resultCode ?? value.status ?? "Received");
|
|
9
|
+
const normalized = resultCode === "Authorised" || resultCode === "Captured" ? "authorized" : resultCode === "PresentToShopper" || resultCode === "IdentifyShopper" || resultCode === "ChallengeShopper" ? "requires_action" : resultCode === "Refused" || resultCode === "Error" ? "failed" : resultCode === "Cancelled" ? "cancelled" : "processing";
|
|
10
|
+
const amountValue = value.amount?.value;
|
|
11
|
+
const currency = String(value.amount?.currency ?? fallback.amount.currency).toUpperCase();
|
|
12
|
+
const amount = (0, _puzzle_ui_commerce.createMoney)(typeof amountValue === "number" && Number.isSafeInteger(amountValue) ? amountValue : fallback.amount.amount, currency);
|
|
13
|
+
const pspReference = require_http.asString(value.pspReference) ?? require_http.asString(value.id);
|
|
14
|
+
return {
|
|
15
|
+
id: fallback.id,
|
|
16
|
+
orderId: fallback.orderId,
|
|
17
|
+
amount,
|
|
18
|
+
status: normalized,
|
|
19
|
+
provider,
|
|
20
|
+
providerPaymentId: pspReference,
|
|
21
|
+
capturedAmount: resultCode === "Captured" ? amount : void 0,
|
|
22
|
+
failure: normalized === "failed" ? {
|
|
23
|
+
code: "declined",
|
|
24
|
+
message: String(value.refusalReason ?? "Adyen payment was refused."),
|
|
25
|
+
providerCode: require_http.asString(value.refusalReasonCode),
|
|
26
|
+
retryable: false,
|
|
27
|
+
decline: true
|
|
28
|
+
} : void 0,
|
|
29
|
+
createdAt: require_http.now(),
|
|
30
|
+
updatedAt: require_http.now()
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const notificationItem = (payload) => {
|
|
34
|
+
const root = payload;
|
|
35
|
+
return (Array.isArray(root.notificationItems) ? root.notificationItems : [])[0]?.NotificationRequestItem;
|
|
36
|
+
};
|
|
37
|
+
const createAdyenAdapter = (options) => {
|
|
38
|
+
if (!options.apiKey.trim() || !options.merchantAccount.trim()) throw new TypeError("Adyen API key and merchant account are required.");
|
|
39
|
+
const fetcher = options.fetcher ?? fetch;
|
|
40
|
+
const baseUrl = options.apiBaseUrl ?? "https://checkout-live.adyen.com";
|
|
41
|
+
const version = options.apiVersion ?? "v71";
|
|
42
|
+
const request = async (path, init = {}) => {
|
|
43
|
+
try {
|
|
44
|
+
return await require_http.requestJson(fetcher, `${baseUrl}/${version}${path}`, {
|
|
45
|
+
...init,
|
|
46
|
+
headers: {
|
|
47
|
+
...require_http.jsonHeaders({ "X-API-Key": options.apiKey }),
|
|
48
|
+
...init.headers
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw require_http.createProviderError(error);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
id: provider,
|
|
57
|
+
name: "Adyen",
|
|
58
|
+
capabilities: {
|
|
59
|
+
payments: true,
|
|
60
|
+
refunds: true,
|
|
61
|
+
capture: true,
|
|
62
|
+
cancel: true,
|
|
63
|
+
partialCapture: true,
|
|
64
|
+
partialRefund: true,
|
|
65
|
+
hostedCheckout: true,
|
|
66
|
+
embeddedCheckout: true,
|
|
67
|
+
wallets: true,
|
|
68
|
+
delayedPaymentMethods: true,
|
|
69
|
+
webhooks: true,
|
|
70
|
+
idempotency: true
|
|
71
|
+
},
|
|
72
|
+
createPayment: async (input, context) => {
|
|
73
|
+
const result = await request("/payments", {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers: context?.idempotencyKey ? { "Idempotency-Key": context.idempotencyKey } : void 0,
|
|
76
|
+
body: JSON.stringify({
|
|
77
|
+
merchantAccount: options.merchantAccount,
|
|
78
|
+
reference: input.orderId,
|
|
79
|
+
amount: {
|
|
80
|
+
currency: input.amount.currency,
|
|
81
|
+
value: input.amount.amount
|
|
82
|
+
},
|
|
83
|
+
returnUrl: input.returnUrl,
|
|
84
|
+
channel: "Web",
|
|
85
|
+
shopperInteraction: "Ecommerce",
|
|
86
|
+
metadata: input.metadata
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
return paymentFromAdyen(result, {
|
|
90
|
+
id: input.paymentId,
|
|
91
|
+
orderId: input.orderId,
|
|
92
|
+
amount: input.amount
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
getPayment: async (providerPaymentId) => {
|
|
96
|
+
const result = await request(`/payments/${encodeURIComponent(providerPaymentId)}`);
|
|
97
|
+
return paymentFromAdyen(result, {
|
|
98
|
+
id: providerPaymentId,
|
|
99
|
+
orderId: String(result.reference ?? ""),
|
|
100
|
+
amount: (0, _puzzle_ui_commerce.createMoney)(Number(result.amount?.value ?? 0), String(result.amount?.currency ?? "EUR"))
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
capture: async ({ payment, amount, context }) => {
|
|
104
|
+
const result = await request(`/payments/${encodeURIComponent(require_http.requireString(payment.providerPaymentId, "provider payment ID"))}/captures`, {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: context?.idempotencyKey ? { "Idempotency-Key": context.idempotencyKey } : void 0,
|
|
107
|
+
body: JSON.stringify({
|
|
108
|
+
merchantAccount: options.merchantAccount,
|
|
109
|
+
reference: payment.id,
|
|
110
|
+
...amount ? { amount: {
|
|
111
|
+
currency: amount.currency,
|
|
112
|
+
value: amount.amount
|
|
113
|
+
} } : {}
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
return paymentFromAdyen({
|
|
117
|
+
...result,
|
|
118
|
+
resultCode: "Captured"
|
|
119
|
+
}, payment);
|
|
120
|
+
},
|
|
121
|
+
cancel: async ({ payment, context }) => {
|
|
122
|
+
const result = await request(`/payments/${encodeURIComponent(require_http.requireString(payment.providerPaymentId, "provider payment ID"))}/cancels`, {
|
|
123
|
+
method: "POST",
|
|
124
|
+
headers: context?.idempotencyKey ? { "Idempotency-Key": context.idempotencyKey } : void 0,
|
|
125
|
+
body: JSON.stringify({ merchantAccount: options.merchantAccount })
|
|
126
|
+
});
|
|
127
|
+
return paymentFromAdyen({
|
|
128
|
+
...result,
|
|
129
|
+
resultCode: "Cancelled"
|
|
130
|
+
}, payment);
|
|
131
|
+
},
|
|
132
|
+
refund: async ({ payment, refund, context }) => {
|
|
133
|
+
const result = await request(`/payments/${encodeURIComponent(require_http.requireString(payment.providerPaymentId, "provider payment ID"))}/refunds`, {
|
|
134
|
+
method: "POST",
|
|
135
|
+
headers: context?.idempotencyKey ? { "Idempotency-Key": context.idempotencyKey } : void 0,
|
|
136
|
+
body: JSON.stringify({
|
|
137
|
+
merchantAccount: options.merchantAccount,
|
|
138
|
+
reference: refund.id,
|
|
139
|
+
amount: {
|
|
140
|
+
currency: refund.amount.currency,
|
|
141
|
+
value: refund.amount.amount
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
...refund,
|
|
147
|
+
providerRefundId: require_http.asString(result.pspReference),
|
|
148
|
+
status: "pending",
|
|
149
|
+
updatedAt: require_http.now()
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
createCheckoutSession: async (input, context) => {
|
|
153
|
+
const result = await request("/sessions", {
|
|
154
|
+
method: "POST",
|
|
155
|
+
headers: context?.idempotencyKey ? { "Idempotency-Key": context.idempotencyKey } : void 0,
|
|
156
|
+
body: JSON.stringify({
|
|
157
|
+
merchantAccount: options.merchantAccount,
|
|
158
|
+
reference: input.orderId,
|
|
159
|
+
amount: {
|
|
160
|
+
currency: input.amount.currency,
|
|
161
|
+
value: input.amount.amount
|
|
162
|
+
},
|
|
163
|
+
returnUrl: input.returnUrl,
|
|
164
|
+
mode: "embedded"
|
|
165
|
+
})
|
|
166
|
+
});
|
|
167
|
+
return {
|
|
168
|
+
id: require_http.requireString(result.id, "checkout session ID"),
|
|
169
|
+
provider,
|
|
170
|
+
paymentId: input.paymentId,
|
|
171
|
+
clientSecret: require_http.asString(result.sessionData)
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
getSupportedPaymentMethods: async () => [{
|
|
175
|
+
id: "scheme",
|
|
176
|
+
type: "card",
|
|
177
|
+
label: "Card",
|
|
178
|
+
provider
|
|
179
|
+
}, {
|
|
180
|
+
id: "paypal",
|
|
181
|
+
type: "wallet",
|
|
182
|
+
label: "PayPal",
|
|
183
|
+
provider
|
|
184
|
+
}],
|
|
185
|
+
verifyWebhook: async (payload, _signature, secret) => {
|
|
186
|
+
const item = notificationItem(JSON.parse(typeof payload === "string" ? payload : new TextDecoder().decode(payload)));
|
|
187
|
+
const additionalData = item?.additionalData;
|
|
188
|
+
const signature = require_http.asString(additionalData?.hmacSignature);
|
|
189
|
+
if (!item || !signature || !secret) return false;
|
|
190
|
+
const amount = item.amount;
|
|
191
|
+
const canonical = [
|
|
192
|
+
item.pspReference,
|
|
193
|
+
item.originalReference,
|
|
194
|
+
item.merchantAccountCode,
|
|
195
|
+
amount?.value,
|
|
196
|
+
amount?.currency,
|
|
197
|
+
item.eventCode,
|
|
198
|
+
item.success
|
|
199
|
+
].map((value) => String(value ?? "")).join(":");
|
|
200
|
+
return require_signatures.verifyHmacSha256({
|
|
201
|
+
payload: canonical,
|
|
202
|
+
signature,
|
|
203
|
+
secret,
|
|
204
|
+
encoding: "base64"
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
parseWebhook: (payload) => {
|
|
208
|
+
const item = notificationItem(payload);
|
|
209
|
+
if (!item) throw new Error("Adyen webhook did not contain a notification item.");
|
|
210
|
+
return {
|
|
211
|
+
id: [
|
|
212
|
+
require_http.requireString(item.pspReference, "webhook PSP reference"),
|
|
213
|
+
require_http.requireString(item.eventCode, "webhook event code"),
|
|
214
|
+
String(item.eventDate ?? "")
|
|
215
|
+
].join(":"),
|
|
216
|
+
type: `payment.${String(item.eventCode).toLowerCase()}`,
|
|
217
|
+
paymentId: require_http.asString(item.pspReference),
|
|
218
|
+
data: item,
|
|
219
|
+
occurredAt: item.eventDate ? new Date(String(item.eventDate)) : require_http.now()
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
exports.createAdyenAdapter = createAdyenAdapter;
|
|
225
|
+
|
|
226
|
+
//# sourceMappingURL=adyen.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adyen.cjs","names":["createMoney","asString","now","requestJson","jsonHeaders","createProviderError","requireString","verifyHmacSha256"],"sources":["../src/adyen.ts"],"sourcesContent":["import {\n createMoney,\n type CreateCheckoutSessionRequest,\n type PaymentProviderAdapter,\n type PaymentAttempt,\n type ProviderWebhookEvent,\n type RefundPaymentRequest,\n} from \"@puzzle-ui/commerce\";\nimport {\n asString,\n createProviderError,\n jsonHeaders,\n now,\n requestJson,\n requireString,\n type ProviderFetcher,\n} from \"./http\";\nimport { verifyHmacSha256 } from \"./signatures\";\n\nexport type AdyenAdapterOptions = {\n readonly apiKey: string;\n readonly merchantAccount: string;\n readonly apiBaseUrl?: string;\n readonly apiVersion?: string;\n readonly fetcher?: ProviderFetcher;\n};\n\nconst provider = \"adyen\";\n\nconst paymentFromAdyen = (\n value: Record<string, unknown>,\n fallback: Pick<PaymentAttempt, \"id\" | \"orderId\" | \"amount\">,\n): PaymentAttempt => {\n const resultCode = String(value.resultCode ?? value.status ?? \"Received\");\n const normalized: PaymentAttempt[\"status\"] =\n resultCode === \"Authorised\" || resultCode === \"Captured\"\n ? \"authorized\"\n : resultCode === \"PresentToShopper\" ||\n resultCode === \"IdentifyShopper\" ||\n resultCode === \"ChallengeShopper\"\n ? \"requires_action\"\n : resultCode === \"Refused\" || resultCode === \"Error\"\n ? \"failed\"\n : resultCode === \"Cancelled\"\n ? \"cancelled\"\n : \"processing\";\n const amountValue = (value.amount as Record<string, unknown> | undefined)?.value;\n const currency = String(\n (value.amount as Record<string, unknown> | undefined)?.currency ??\n fallback.amount.currency,\n ).toUpperCase();\n const amount = createMoney(\n typeof amountValue === \"number\" && Number.isSafeInteger(amountValue)\n ? amountValue\n : fallback.amount.amount,\n currency,\n );\n const pspReference = asString(value.pspReference) ?? asString(value.id);\n return {\n id: fallback.id,\n orderId: fallback.orderId,\n amount,\n status: normalized,\n provider,\n providerPaymentId: pspReference,\n capturedAmount: resultCode === \"Captured\" ? amount : undefined,\n failure:\n normalized === \"failed\"\n ? {\n code: \"declined\",\n message: String(value.refusalReason ?? \"Adyen payment was refused.\"),\n providerCode: asString(value.refusalReasonCode),\n retryable: false,\n decline: true,\n }\n : undefined,\n createdAt: now(),\n updatedAt: now(),\n };\n};\n\nconst notificationItem = (payload: unknown) => {\n const root = payload as Record<string, unknown>;\n const items = Array.isArray(root.notificationItems) ? root.notificationItems : [];\n return (items[0] as Record<string, unknown> | undefined)?.NotificationRequestItem as\n | Record<string, unknown>\n | undefined;\n};\n\nexport const createAdyenAdapter = (\n options: AdyenAdapterOptions,\n): PaymentProviderAdapter => {\n if (!options.apiKey.trim() || !options.merchantAccount.trim()) {\n throw new TypeError(\"Adyen API key and merchant account are required.\");\n }\n const fetcher = options.fetcher ?? fetch;\n const baseUrl = options.apiBaseUrl ?? \"https://checkout-live.adyen.com\";\n const version = options.apiVersion ?? \"v71\";\n const request = async (path: string, init: RequestInit = {}) => {\n try {\n return await requestJson(fetcher, `${baseUrl}/${version}${path}`, {\n ...init,\n headers: {\n ...jsonHeaders({ \"X-API-Key\": options.apiKey }),\n ...init.headers,\n },\n });\n } catch (error) {\n throw createProviderError(error);\n }\n };\n\n return {\n id: provider,\n name: \"Adyen\",\n capabilities: {\n payments: true,\n refunds: true,\n capture: true,\n cancel: true,\n partialCapture: true,\n partialRefund: true,\n hostedCheckout: true,\n embeddedCheckout: true,\n wallets: true,\n delayedPaymentMethods: true,\n webhooks: true,\n idempotency: true,\n },\n createPayment: async (input, context) => {\n const result = await request(\n \"/payments\",\n {\n method: \"POST\",\n headers: context?.idempotencyKey\n ? { \"Idempotency-Key\": context.idempotencyKey }\n : undefined,\n body: JSON.stringify({\n merchantAccount: options.merchantAccount,\n reference: input.orderId,\n amount: {\n currency: input.amount.currency,\n value: input.amount.amount,\n },\n returnUrl: input.returnUrl,\n channel: \"Web\",\n shopperInteraction: \"Ecommerce\",\n metadata: input.metadata,\n }),\n },\n );\n return paymentFromAdyen(result, {\n id: input.paymentId,\n orderId: input.orderId,\n amount: input.amount,\n });\n },\n getPayment: async (providerPaymentId) => {\n const result = await request(`/payments/${encodeURIComponent(providerPaymentId)}`);\n return paymentFromAdyen(result, {\n id: providerPaymentId,\n orderId: String(result.reference ?? \"\"),\n amount: createMoney(\n Number((result.amount as Record<string, unknown> | undefined)?.value ?? 0),\n String((result.amount as Record<string, unknown> | undefined)?.currency ?? \"EUR\"),\n ),\n });\n },\n capture: async ({ payment, amount, context }) => {\n const result = await request(\n `/payments/${encodeURIComponent(requireString(payment.providerPaymentId, \"provider payment ID\"))}/captures`,\n {\n method: \"POST\",\n headers: context?.idempotencyKey\n ? { \"Idempotency-Key\": context.idempotencyKey }\n : undefined,\n body: JSON.stringify({\n merchantAccount: options.merchantAccount,\n reference: payment.id,\n ...(amount\n ? { amount: { currency: amount.currency, value: amount.amount } }\n : {}),\n }),\n },\n );\n return paymentFromAdyen({ ...result, resultCode: \"Captured\" }, payment);\n },\n cancel: async ({ payment, context }) => {\n const result = await request(\n `/payments/${encodeURIComponent(requireString(payment.providerPaymentId, \"provider payment ID\"))}/cancels`,\n {\n method: \"POST\",\n headers: context?.idempotencyKey\n ? { \"Idempotency-Key\": context.idempotencyKey }\n : undefined,\n body: JSON.stringify({ merchantAccount: options.merchantAccount }),\n },\n );\n return paymentFromAdyen({ ...result, resultCode: \"Cancelled\" }, payment);\n },\n refund: async ({ payment, refund, context }: RefundPaymentRequest) => {\n const result = await request(\n `/payments/${encodeURIComponent(requireString(payment.providerPaymentId, \"provider payment ID\"))}/refunds`,\n {\n method: \"POST\",\n headers: context?.idempotencyKey\n ? { \"Idempotency-Key\": context.idempotencyKey }\n : undefined,\n body: JSON.stringify({\n merchantAccount: options.merchantAccount,\n reference: refund.id,\n amount: { currency: refund.amount.currency, value: refund.amount.amount },\n }),\n },\n );\n return {\n ...refund,\n providerRefundId: asString(result.pspReference),\n status: \"pending\",\n updatedAt: now(),\n };\n },\n createCheckoutSession: async (input: CreateCheckoutSessionRequest, context) => {\n const result = await request(\n \"/sessions\",\n {\n method: \"POST\",\n headers: context?.idempotencyKey\n ? { \"Idempotency-Key\": context.idempotencyKey }\n : undefined,\n body: JSON.stringify({\n merchantAccount: options.merchantAccount,\n reference: input.orderId,\n amount: { currency: input.amount.currency, value: input.amount.amount },\n returnUrl: input.returnUrl,\n mode: \"embedded\",\n }),\n },\n );\n return {\n id: requireString(result.id, \"checkout session ID\"),\n provider,\n paymentId: input.paymentId,\n clientSecret: asString(result.sessionData),\n };\n },\n getSupportedPaymentMethods: async () => [\n { id: \"scheme\", type: \"card\", label: \"Card\", provider },\n { id: \"paypal\", type: \"wallet\", label: \"PayPal\", provider },\n ],\n verifyWebhook: async (payload, _signature, secret) => {\n const item = notificationItem(\n JSON.parse(typeof payload === \"string\" ? payload : new TextDecoder().decode(payload)),\n );\n const additionalData = item?.additionalData as Record<string, unknown> | undefined;\n const signature = asString(additionalData?.hmacSignature);\n if (!item || !signature || !secret) return false;\n const amount = item.amount as Record<string, unknown> | undefined;\n const canonical = [\n item.pspReference,\n item.originalReference,\n item.merchantAccountCode,\n amount?.value,\n amount?.currency,\n item.eventCode,\n item.success,\n ].map((value) => String(value ?? \"\")).join(\":\");\n return verifyHmacSha256({\n payload: canonical,\n signature,\n secret,\n encoding: \"base64\",\n });\n },\n parseWebhook: (payload): ProviderWebhookEvent => {\n const item = notificationItem(payload);\n if (!item) {\n throw new Error(\"Adyen webhook did not contain a notification item.\");\n }\n const id = [\n requireString(item.pspReference, \"webhook PSP reference\"),\n requireString(item.eventCode, \"webhook event code\"),\n String(item.eventDate ?? \"\"),\n ].join(\":\");\n return {\n id,\n type: `payment.${String(item.eventCode).toLowerCase()}`,\n paymentId: asString(item.pspReference),\n data: item,\n occurredAt: item.eventDate ? new Date(String(item.eventDate)) : now(),\n };\n },\n };\n};\n"],"mappings":";;;;;AA2BA,MAAM,WAAW;AAEjB,MAAM,oBACJ,OACA,aACmB;CACnB,M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iBAAiB,OAAO;GACrC,IAAI,CAAC,MACH,MAAM,IAAI,MAAM,oDAAoD;GAOtE,OAAO;IACL,IANS;KACTD,aAAAA,cAAc,KAAK,cAAc,uBAAuB;KACxDA,aAAAA,cAAc,KAAK,WAAW,oBAAoB;KAClD,OAAO,KAAK,aAAa,EAAE;IAC7B,CAAC,CAAC,KAAK,GAEJ;IACD,MAAM,WAAW,OAAO,KAAK,SAAS,CAAC,CAAC,YAAY;IACpD,WAAWL,aAAAA,SAAS,KAAK,YAAY;IACrC,MAAM;IACN,YAAY,KAAK,YAAY,IAAI,KAAK,OAAO,KAAK,SAAS,CAAC,IAAIC,aAAAA,IAAI;GACtE;EACF;CACF;AACF"}
|
package/dist/adyen.d.cts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as ProviderFetcher } from "./http-BJTHkHOr.cjs";
|
|
2
|
+
import { PaymentProviderAdapter } from "@puzzle-ui/commerce";
|
|
3
|
+
export type AdyenAdapterOptions = {
|
|
4
|
+
readonly apiKey: string;
|
|
5
|
+
readonly merchantAccount: string;
|
|
6
|
+
readonly apiBaseUrl?: string;
|
|
7
|
+
readonly apiVersion?: string;
|
|
8
|
+
readonly fetcher?: ProviderFetcher;
|
|
9
|
+
};
|
|
10
|
+
export declare const createAdyenAdapter: (options: AdyenAdapterOptions) => PaymentProviderAdapter;
|
package/dist/adyen.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as ProviderFetcher } from "./http-BJTHkHOr.js";
|
|
2
|
+
import { PaymentProviderAdapter } from "@puzzle-ui/commerce";
|
|
3
|
+
export type AdyenAdapterOptions = {
|
|
4
|
+
readonly apiKey: string;
|
|
5
|
+
readonly merchantAccount: string;
|
|
6
|
+
readonly apiBaseUrl?: string;
|
|
7
|
+
readonly apiVersion?: string;
|
|
8
|
+
readonly fetcher?: ProviderFetcher;
|
|
9
|
+
};
|
|
10
|
+
export declare const createAdyenAdapter: (options: AdyenAdapterOptions) => PaymentProviderAdapter;
|
package/dist/adyen.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { a as jsonHeaders, c as requireString, n as asString, o as now, r as createProviderError, s as requestJson } from "./http-Pinf6Gsa.js";
|
|
2
|
+
import { t as verifyHmacSha256 } from "./signatures-AHsLlFRl.js";
|
|
3
|
+
import { createMoney } from "@puzzle-ui/commerce";
|
|
4
|
+
// src/adyen.ts
|
|
5
|
+
const provider = "adyen";
|
|
6
|
+
const paymentFromAdyen = (value, fallback) => {
|
|
7
|
+
const resultCode = String(value.resultCode ?? value.status ?? "Received");
|
|
8
|
+
const normalized = resultCode === "Authorised" || resultCode === "Captured" ? "authorized" : resultCode === "PresentToShopper" || resultCode === "IdentifyShopper" || resultCode === "ChallengeShopper" ? "requires_action" : resultCode === "Refused" || resultCode === "Error" ? "failed" : resultCode === "Cancelled" ? "cancelled" : "processing";
|
|
9
|
+
const amountValue = value.amount?.value;
|
|
10
|
+
const currency = String(value.amount?.currency ?? fallback.amount.currency).toUpperCase();
|
|
11
|
+
const amount = createMoney(typeof amountValue === "number" && Number.isSafeInteger(amountValue) ? amountValue : fallback.amount.amount, currency);
|
|
12
|
+
const pspReference = asString(value.pspReference) ?? asString(value.id);
|
|
13
|
+
return {
|
|
14
|
+
id: fallback.id,
|
|
15
|
+
orderId: fallback.orderId,
|
|
16
|
+
amount,
|
|
17
|
+
status: normalized,
|
|
18
|
+
provider,
|
|
19
|
+
providerPaymentId: pspReference,
|
|
20
|
+
capturedAmount: resultCode === "Captured" ? amount : void 0,
|
|
21
|
+
failure: normalized === "failed" ? {
|
|
22
|
+
code: "declined",
|
|
23
|
+
message: String(value.refusalReason ?? "Adyen payment was refused."),
|
|
24
|
+
providerCode: asString(value.refusalReasonCode),
|
|
25
|
+
retryable: false,
|
|
26
|
+
decline: true
|
|
27
|
+
} : void 0,
|
|
28
|
+
createdAt: now(),
|
|
29
|
+
updatedAt: now()
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const notificationItem = (payload) => {
|
|
33
|
+
const root = payload;
|
|
34
|
+
return (Array.isArray(root.notificationItems) ? root.notificationItems : [])[0]?.NotificationRequestItem;
|
|
35
|
+
};
|
|
36
|
+
const createAdyenAdapter = (options) => {
|
|
37
|
+
if (!options.apiKey.trim() || !options.merchantAccount.trim()) throw new TypeError("Adyen API key and merchant account are required.");
|
|
38
|
+
const fetcher = options.fetcher ?? fetch;
|
|
39
|
+
const baseUrl = options.apiBaseUrl ?? "https://checkout-live.adyen.com";
|
|
40
|
+
const version = options.apiVersion ?? "v71";
|
|
41
|
+
const request = async (path, init = {}) => {
|
|
42
|
+
try {
|
|
43
|
+
return await requestJson(fetcher, `${baseUrl}/${version}${path}`, {
|
|
44
|
+
...init,
|
|
45
|
+
headers: {
|
|
46
|
+
...jsonHeaders({ "X-API-Key": options.apiKey }),
|
|
47
|
+
...init.headers
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw createProviderError(error);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
id: provider,
|
|
56
|
+
name: "Adyen",
|
|
57
|
+
capabilities: {
|
|
58
|
+
payments: true,
|
|
59
|
+
refunds: true,
|
|
60
|
+
capture: true,
|
|
61
|
+
cancel: true,
|
|
62
|
+
partialCapture: true,
|
|
63
|
+
partialRefund: true,
|
|
64
|
+
hostedCheckout: true,
|
|
65
|
+
embeddedCheckout: true,
|
|
66
|
+
wallets: true,
|
|
67
|
+
delayedPaymentMethods: true,
|
|
68
|
+
webhooks: true,
|
|
69
|
+
idempotency: true
|
|
70
|
+
},
|
|
71
|
+
createPayment: async (input, context) => {
|
|
72
|
+
const result = await request("/payments", {
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: context?.idempotencyKey ? { "Idempotency-Key": context.idempotencyKey } : void 0,
|
|
75
|
+
body: JSON.stringify({
|
|
76
|
+
merchantAccount: options.merchantAccount,
|
|
77
|
+
reference: input.orderId,
|
|
78
|
+
amount: {
|
|
79
|
+
currency: input.amount.currency,
|
|
80
|
+
value: input.amount.amount
|
|
81
|
+
},
|
|
82
|
+
returnUrl: input.returnUrl,
|
|
83
|
+
channel: "Web",
|
|
84
|
+
shopperInteraction: "Ecommerce",
|
|
85
|
+
metadata: input.metadata
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
return paymentFromAdyen(result, {
|
|
89
|
+
id: input.paymentId,
|
|
90
|
+
orderId: input.orderId,
|
|
91
|
+
amount: input.amount
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
getPayment: async (providerPaymentId) => {
|
|
95
|
+
const result = await request(`/payments/${encodeURIComponent(providerPaymentId)}`);
|
|
96
|
+
return paymentFromAdyen(result, {
|
|
97
|
+
id: providerPaymentId,
|
|
98
|
+
orderId: String(result.reference ?? ""),
|
|
99
|
+
amount: createMoney(Number(result.amount?.value ?? 0), String(result.amount?.currency ?? "EUR"))
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
capture: async ({ payment, amount, context }) => {
|
|
103
|
+
const result = await request(`/payments/${encodeURIComponent(requireString(payment.providerPaymentId, "provider payment ID"))}/captures`, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers: context?.idempotencyKey ? { "Idempotency-Key": context.idempotencyKey } : void 0,
|
|
106
|
+
body: JSON.stringify({
|
|
107
|
+
merchantAccount: options.merchantAccount,
|
|
108
|
+
reference: payment.id,
|
|
109
|
+
...amount ? { amount: {
|
|
110
|
+
currency: amount.currency,
|
|
111
|
+
value: amount.amount
|
|
112
|
+
} } : {}
|
|
113
|
+
})
|
|
114
|
+
});
|
|
115
|
+
return paymentFromAdyen({
|
|
116
|
+
...result,
|
|
117
|
+
resultCode: "Captured"
|
|
118
|
+
}, payment);
|
|
119
|
+
},
|
|
120
|
+
cancel: async ({ payment, context }) => {
|
|
121
|
+
const result = await request(`/payments/${encodeURIComponent(requireString(payment.providerPaymentId, "provider payment ID"))}/cancels`, {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: context?.idempotencyKey ? { "Idempotency-Key": context.idempotencyKey } : void 0,
|
|
124
|
+
body: JSON.stringify({ merchantAccount: options.merchantAccount })
|
|
125
|
+
});
|
|
126
|
+
return paymentFromAdyen({
|
|
127
|
+
...result,
|
|
128
|
+
resultCode: "Cancelled"
|
|
129
|
+
}, payment);
|
|
130
|
+
},
|
|
131
|
+
refund: async ({ payment, refund, context }) => {
|
|
132
|
+
const result = await request(`/payments/${encodeURIComponent(requireString(payment.providerPaymentId, "provider payment ID"))}/refunds`, {
|
|
133
|
+
method: "POST",
|
|
134
|
+
headers: context?.idempotencyKey ? { "Idempotency-Key": context.idempotencyKey } : void 0,
|
|
135
|
+
body: JSON.stringify({
|
|
136
|
+
merchantAccount: options.merchantAccount,
|
|
137
|
+
reference: refund.id,
|
|
138
|
+
amount: {
|
|
139
|
+
currency: refund.amount.currency,
|
|
140
|
+
value: refund.amount.amount
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
...refund,
|
|
146
|
+
providerRefundId: asString(result.pspReference),
|
|
147
|
+
status: "pending",
|
|
148
|
+
updatedAt: now()
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
createCheckoutSession: async (input, context) => {
|
|
152
|
+
const result = await request("/sessions", {
|
|
153
|
+
method: "POST",
|
|
154
|
+
headers: context?.idempotencyKey ? { "Idempotency-Key": context.idempotencyKey } : void 0,
|
|
155
|
+
body: JSON.stringify({
|
|
156
|
+
merchantAccount: options.merchantAccount,
|
|
157
|
+
reference: input.orderId,
|
|
158
|
+
amount: {
|
|
159
|
+
currency: input.amount.currency,
|
|
160
|
+
value: input.amount.amount
|
|
161
|
+
},
|
|
162
|
+
returnUrl: input.returnUrl,
|
|
163
|
+
mode: "embedded"
|
|
164
|
+
})
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
id: requireString(result.id, "checkout session ID"),
|
|
168
|
+
provider,
|
|
169
|
+
paymentId: input.paymentId,
|
|
170
|
+
clientSecret: asString(result.sessionData)
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
getSupportedPaymentMethods: async () => [{
|
|
174
|
+
id: "scheme",
|
|
175
|
+
type: "card",
|
|
176
|
+
label: "Card",
|
|
177
|
+
provider
|
|
178
|
+
}, {
|
|
179
|
+
id: "paypal",
|
|
180
|
+
type: "wallet",
|
|
181
|
+
label: "PayPal",
|
|
182
|
+
provider
|
|
183
|
+
}],
|
|
184
|
+
verifyWebhook: async (payload, _signature, secret) => {
|
|
185
|
+
const item = notificationItem(JSON.parse(typeof payload === "string" ? payload : new TextDecoder().decode(payload)));
|
|
186
|
+
const additionalData = item?.additionalData;
|
|
187
|
+
const signature = asString(additionalData?.hmacSignature);
|
|
188
|
+
if (!item || !signature || !secret) return false;
|
|
189
|
+
const amount = item.amount;
|
|
190
|
+
const canonical = [
|
|
191
|
+
item.pspReference,
|
|
192
|
+
item.originalReference,
|
|
193
|
+
item.merchantAccountCode,
|
|
194
|
+
amount?.value,
|
|
195
|
+
amount?.currency,
|
|
196
|
+
item.eventCode,
|
|
197
|
+
item.success
|
|
198
|
+
].map((value) => String(value ?? "")).join(":");
|
|
199
|
+
return verifyHmacSha256({
|
|
200
|
+
payload: canonical,
|
|
201
|
+
signature,
|
|
202
|
+
secret,
|
|
203
|
+
encoding: "base64"
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
parseWebhook: (payload) => {
|
|
207
|
+
const item = notificationItem(payload);
|
|
208
|
+
if (!item) throw new Error("Adyen webhook did not contain a notification item.");
|
|
209
|
+
return {
|
|
210
|
+
id: [
|
|
211
|
+
requireString(item.pspReference, "webhook PSP reference"),
|
|
212
|
+
requireString(item.eventCode, "webhook event code"),
|
|
213
|
+
String(item.eventDate ?? "")
|
|
214
|
+
].join(":"),
|
|
215
|
+
type: `payment.${String(item.eventCode).toLowerCase()}`,
|
|
216
|
+
paymentId: asString(item.pspReference),
|
|
217
|
+
data: item,
|
|
218
|
+
occurredAt: item.eventDate ? new Date(String(item.eventDate)) : now()
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
export { createAdyenAdapter };
|
|
224
|
+
|
|
225
|
+
//# sourceMappingURL=adyen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adyen.js","names":[],"sources":["../src/adyen.ts"],"sourcesContent":["import {\n createMoney,\n type CreateCheckoutSessionRequest,\n type PaymentProviderAdapter,\n type PaymentAttempt,\n type ProviderWebhookEvent,\n type RefundPaymentRequest,\n} from \"@puzzle-ui/commerce\";\nimport {\n asString,\n createProviderError,\n jsonHeaders,\n now,\n requestJson,\n requireString,\n type ProviderFetcher,\n} from \"./http\";\nimport { verifyHmacSha256 } from \"./signatures\";\n\nexport type AdyenAdapterOptions = {\n readonly apiKey: string;\n readonly merchantAccount: string;\n readonly apiBaseUrl?: string;\n readonly apiVersion?: string;\n readonly fetcher?: ProviderFetcher;\n};\n\nconst provider = \"adyen\";\n\nconst paymentFromAdyen = (\n value: Record<string, unknown>,\n fallback: Pick<PaymentAttempt, \"id\" | \"orderId\" | \"amount\">,\n): PaymentAttempt => {\n const resultCode = String(value.resultCode ?? value.status ?? \"Received\");\n const normalized: PaymentAttempt[\"status\"] =\n resultCode === \"Authorised\" || resultCode === \"Captured\"\n ? \"authorized\"\n : resultCode === \"PresentToShopper\" ||\n resultCode === \"IdentifyShopper\" ||\n resultCode === \"ChallengeShopper\"\n ? \"requires_action\"\n : resultCode === \"Refused\" || resultCode === \"Error\"\n ? \"failed\"\n : resultCode === \"Cancelled\"\n ? \"cancelled\"\n : \"processing\";\n const amountValue = (value.amount as Record<string, unknown> | undefined)?.value;\n const currency = String(\n (value.amount as Record<string, unknown> | undefined)?.currency ??\n fallback.amount.currency,\n ).toUpperCase();\n const amount = createMoney(\n typeof amountValue === \"number\" && Number.isSafeInteger(amountValue)\n ? amountValue\n : fallback.amount.amount,\n currency,\n );\n const pspReference = asString(value.pspReference) ?? asString(value.id);\n return {\n id: fallback.id,\n orderId: fallback.orderId,\n amount,\n status: normalized,\n provider,\n providerPaymentId: pspReference,\n capturedAmount: resultCode === \"Captured\" ? amount : undefined,\n failure:\n normalized === \"failed\"\n ? {\n code: \"declined\",\n message: String(value.refusalReason ?? \"Adyen payment was refused.\"),\n providerCode: asString(value.refusalReasonCode),\n retryable: false,\n decline: true,\n }\n : undefined,\n createdAt: now(),\n updatedAt: now(),\n };\n};\n\nconst notificationItem = (payload: unknown) => {\n const root = payload as Record<string, unknown>;\n const items = Array.isArray(root.notificationItems) ? root.notificationItems : [];\n return (items[0] as Record<string, unknown> | undefined)?.NotificationRequestItem as\n | Record<string, unknown>\n | undefined;\n};\n\nexport const createAdyenAdapter = (\n options: AdyenAdapterOptions,\n): PaymentProviderAdapter => {\n if (!options.apiKey.trim() || !options.merchantAccount.trim()) {\n throw new TypeError(\"Adyen API key and merchant account are required.\");\n }\n const fetcher = options.fetcher ?? fetch;\n const baseUrl = options.apiBaseUrl ?? \"https://checkout-live.adyen.com\";\n const version = options.apiVersion ?? \"v71\";\n const request = async (path: string, init: RequestInit = {}) => {\n try {\n return await requestJson(fetcher, `${baseUrl}/${version}${path}`, {\n ...init,\n headers: {\n ...jsonHeaders({ \"X-API-Key\": options.apiKey }),\n ...init.headers,\n },\n });\n } catch (error) {\n throw createProviderError(error);\n }\n };\n\n return {\n id: provider,\n name: \"Adyen\",\n capabilities: {\n payments: true,\n refunds: true,\n capture: true,\n cancel: true,\n partialCapture: true,\n partialRefund: true,\n hostedCheckout: true,\n embeddedCheckout: true,\n wallets: true,\n delayedPaymentMethods: true,\n webhooks: true,\n idempotency: true,\n },\n createPayment: async (input, context) => {\n const result = await request(\n \"/payments\",\n {\n method: \"POST\",\n headers: context?.idempotencyKey\n ? { \"Idempotency-Key\": context.idempotencyKey }\n : undefined,\n body: JSON.stringify({\n merchantAccount: options.merchantAccount,\n reference: input.orderId,\n amount: {\n currency: input.amount.currency,\n value: input.amount.amount,\n },\n returnUrl: input.returnUrl,\n channel: \"Web\",\n shopperInteraction: \"Ecommerce\",\n metadata: input.metadata,\n }),\n },\n );\n return paymentFromAdyen(result, {\n id: input.paymentId,\n orderId: input.orderId,\n amount: input.amount,\n });\n },\n getPayment: async (providerPaymentId) => {\n const result = await request(`/payments/${encodeURIComponent(providerPaymentId)}`);\n return paymentFromAdyen(result, {\n id: providerPaymentId,\n orderId: String(result.reference ?? \"\"),\n amount: createMoney(\n Number((result.amount as Record<string, unknown> | undefined)?.value ?? 0),\n String((result.amount as Record<string, unknown> | undefined)?.currency ?? \"EUR\"),\n ),\n });\n },\n capture: async ({ payment, amount, context }) => {\n const result = await request(\n `/payments/${encodeURIComponent(requireString(payment.providerPaymentId, \"provider payment ID\"))}/captures`,\n {\n method: \"POST\",\n headers: context?.idempotencyKey\n ? { \"Idempotency-Key\": context.idempotencyKey }\n : undefined,\n body: JSON.stringify({\n merchantAccount: options.merchantAccount,\n reference: payment.id,\n ...(amount\n ? { amount: { currency: amount.currency, value: amount.amount } }\n : {}),\n }),\n },\n );\n return paymentFromAdyen({ ...result, resultCode: \"Captured\" }, payment);\n },\n cancel: async ({ payment, context }) => {\n const result = await request(\n `/payments/${encodeURIComponent(requireString(payment.providerPaymentId, \"provider payment ID\"))}/cancels`,\n {\n method: \"POST\",\n headers: context?.idempotencyKey\n ? { \"Idempotency-Key\": context.idempotencyKey }\n : undefined,\n body: JSON.stringify({ merchantAccount: options.merchantAccount }),\n },\n );\n return paymentFromAdyen({ ...result, resultCode: \"Cancelled\" }, payment);\n },\n refund: async ({ payment, refund, context }: RefundPaymentRequest) => {\n const result = await request(\n `/payments/${encodeURIComponent(requireString(payment.providerPaymentId, \"provider payment ID\"))}/refunds`,\n {\n method: \"POST\",\n headers: context?.idempotencyKey\n ? { \"Idempotency-Key\": context.idempotencyKey }\n : undefined,\n body: JSON.stringify({\n merchantAccount: options.merchantAccount,\n reference: refund.id,\n amount: { currency: refund.amount.currency, value: refund.amount.amount },\n }),\n },\n );\n return {\n ...refund,\n providerRefundId: asString(result.pspReference),\n status: \"pending\",\n updatedAt: now(),\n };\n },\n createCheckoutSession: async (input: CreateCheckoutSessionRequest, context) => {\n const result = await request(\n \"/sessions\",\n {\n method: \"POST\",\n headers: context?.idempotencyKey\n ? { \"Idempotency-Key\": context.idempotencyKey }\n : undefined,\n body: JSON.stringify({\n merchantAccount: options.merchantAccount,\n reference: input.orderId,\n amount: { currency: input.amount.currency, value: input.amount.amount },\n returnUrl: input.returnUrl,\n mode: \"embedded\",\n }),\n },\n );\n return {\n id: requireString(result.id, \"checkout session ID\"),\n provider,\n paymentId: input.paymentId,\n clientSecret: asString(result.sessionData),\n };\n },\n getSupportedPaymentMethods: async () => [\n { id: \"scheme\", type: \"card\", label: \"Card\", provider },\n { id: \"paypal\", type: \"wallet\", label: \"PayPal\", provider },\n ],\n verifyWebhook: async (payload, _signature, secret) => {\n const item = notificationItem(\n JSON.parse(typeof payload === \"string\" ? payload : new TextDecoder().decode(payload)),\n );\n const additionalData = item?.additionalData as Record<string, unknown> | undefined;\n const signature = asString(additionalData?.hmacSignature);\n if (!item || !signature || !secret) return false;\n const amount = item.amount as Record<string, unknown> | undefined;\n const canonical = [\n item.pspReference,\n item.originalReference,\n item.merchantAccountCode,\n amount?.value,\n amount?.currency,\n item.eventCode,\n item.success,\n ].map((value) => String(value ?? \"\")).join(\":\");\n return verifyHmacSha256({\n payload: canonical,\n signature,\n secret,\n encoding: \"base64\",\n });\n },\n parseWebhook: (payload): ProviderWebhookEvent => {\n const item = notificationItem(payload);\n if (!item) {\n throw new Error(\"Adyen webhook did not contain a notification item.\");\n }\n const id = [\n requireString(item.pspReference, \"webhook PSP reference\"),\n requireString(item.eventCode, \"webhook event code\"),\n String(item.eventDate ?? \"\"),\n ].join(\":\");\n return {\n id,\n type: `payment.${String(item.eventCode).toLowerCase()}`,\n paymentId: asString(item.pspReference),\n data: item,\n occurredAt: item.eventDate ? new Date(String(item.event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T,cAAc,KAAK,cAAc,uBAAuB;KACxD,cAAc,KAAK,WAAW,oBAAoB;KAClD,OAAO,KAAK,aAAa,EAAE;IAC7B,CAAC,CAAC,KAAK,GAEJ;IACD,MAAM,WAAW,OAAO,KAAK,SAAS,CAAC,CAAC,YAAY;IACpD,WAAW,SAAS,KAAK,YAAY;IACrC,MAAM;IACN,YAAY,KAAK,YAAY,IAAI,KAAK,OAAO,KAAK,SAAS,CAAC,IAAI,IAAI;GACtE;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NormalizedPaymentError, PaymentError } from "@puzzle-ui/commerce";
|
|
2
|
+
type ProviderFetcher = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
3
|
+
declare class ProviderHttpError extends Error {
|
|
4
|
+
readonly status: number;
|
|
5
|
+
readonly providerCode?: string;
|
|
6
|
+
readonly details?: Readonly<Record<string, string>>;
|
|
7
|
+
constructor(status: number, message: string, providerCode?: string, details?: Readonly<Record<string, string>>);
|
|
8
|
+
}
|
|
9
|
+
declare const createProviderError: (error: unknown, fallback?: NormalizedPaymentError["code"]) => PaymentError;
|
|
10
|
+
export { ProviderHttpError as n, createProviderError as r, ProviderFetcher as t };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NormalizedPaymentError, PaymentError } from "@puzzle-ui/commerce";
|
|
2
|
+
type ProviderFetcher = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
3
|
+
declare class ProviderHttpError extends Error {
|
|
4
|
+
readonly status: number;
|
|
5
|
+
readonly providerCode?: string;
|
|
6
|
+
readonly details?: Readonly<Record<string, string>>;
|
|
7
|
+
constructor(status: number, message: string, providerCode?: string, details?: Readonly<Record<string, string>>);
|
|
8
|
+
}
|
|
9
|
+
declare const createProviderError: (error: unknown, fallback?: NormalizedPaymentError["code"]) => PaymentError;
|
|
10
|
+
export { ProviderHttpError as n, createProviderError as r, ProviderFetcher as t };
|