@medusajs/payment-adyen 0.0.0-stage → 2.22.1

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/AGENTS.md ADDED
@@ -0,0 +1,64 @@
1
+ # @medusajs/payment-adyen
2
+
3
+ Payment Module provider for Adyen, built on the Checkout API Advanced flow (`/paymentMethods`, `/payments`, `/payments/details`). Supports cards with 3D Secure.
4
+
5
+ ## Using this package
6
+
7
+ ```ts
8
+ module.exports = defineConfig({
9
+ modules: [
10
+ {
11
+ resolve: "@medusajs/medusa/payment",
12
+ options: {
13
+ providers: [
14
+ {
15
+ resolve: "@medusajs/medusa/payment-adyen",
16
+ id: "adyen",
17
+ options: {
18
+ apiKey: process.env.ADYEN_API_KEY,
19
+ merchantAccount: process.env.ADYEN_MERCHANT_ACCOUNT,
20
+ hmacKey: process.env.ADYEN_WEBHOOK_HMAC_KEY,
21
+ returnUrl: process.env.ADYEN_RETURN_URL,
22
+ },
23
+ },
24
+ ],
25
+ },
26
+ },
27
+ ],
28
+ })
29
+ ```
30
+
31
+ - Options (`AdyenOptions` in `src/types/index.ts`): `apiKey` and `merchantAccount` (required), `hmacKey`, `environment` (`TEST` or `LIVE`, default `TEST`), `liveEndpointUrlPrefix` (required in `LIVE`), `capture` (default `false` = manual capture), `returnUrl`.
32
+ - Provider ID is `pp_adyen_{id}`. Register one instance per merchant account, for example `id: "eu"` and `id: "us"`.
33
+ - Webhooks: point a standard Adyen webhook at `{server_url}/hooks/payment/adyen_{id}`.
34
+ - The storefront passes Drop-in's `paymentMethod`, `browserInfo`, and `details` through `sdk.store.payment.updatePaymentSession` as `client_data.payment_method`, `client_data.browser_info`, and `client_data.details`, then completes the cart. `client_data.origin` and `client_data.return_url` are optional.
35
+ - Docs: https://docs.medusajs.com/resources/commerce-modules/payment/payment-session.md
36
+ - Build a custom payment provider: https://docs.medusajs.com/resources/references/payment/provider.md
37
+
38
+ ## Architecture
39
+
40
+ - `src/services/adyen-provider.ts`: `AdyenProviderService` (identifier `adyen`) with all logic.
41
+ - `initiatePayment` calls `/paymentMethods` and stores the response in `data.payment_methods` for Drop-in.
42
+ - `authorizePayment` submits `data.client.details` to `/payments/details`, or `data.client.payment_method` to `/payments`, then nulls them in the session.
43
+ - Capture, refund, and cancel use the Modifications API with the idempotency key Medusa passes in `context`.
44
+ - Account holders use the customer ID as Adyen's `shopperReference`, with no Adyen call. `initiatePayment` stores it in `data.shopper_reference` and sends it to `/paymentMethods`, which returns the shopper's saved cards.
45
+ - Saved cards: `/payments` sends `storePaymentMethod` when `data.client.store_payment_method` is set, and `listPaymentMethods`, `savePaymentMethod`, and `deletePaymentMethod` use the Checkout `/storedPaymentMethods` endpoints.
46
+ - `src/utils/amounts.ts`: converts Medusa's major units with Adyen's currency exponents, which differ from ISO 4217 for some currencies.
47
+
48
+ ## Development
49
+
50
+ - `yarn build`, `yarn test` (unit tests in `src/services/__tests__` and `src/utils/__tests__`, with the Adyen client mocked).
51
+
52
+ ## Gotchas
53
+
54
+ - `data.client` is written by the storefront, so amounts, currency, references, and the payment state are read only from provider-owned keys. `initiatePayment` sets all of them explicitly so data passed when initializing the session can't take their place.
55
+ - Adyen has no API to retrieve a payment, so `getPaymentStatus` and `retrievePayment` return the last stored state.
56
+ - Captures, refunds, and cancellations are confirmed asynchronously by webhooks, but Medusa records them when it requests them. Failed captures and refunds (`CAPTURE_FAILED`, `REFUND_FAILED`) are only logged.
57
+ - `CAPTURE` and `REFUND` webhooks return `NOT_SUPPORTED`, so captures and refunds made in the Customer Area aren't synced to Medusa.
58
+ - With `capture: true`, an authorized payment returns `captured`, and `cancelPayment` reverses (refunds) it instead of canceling. Each `/payments` request sets `captureDelayHours: 0` or `manualCapture`, as the merchant account's capture delay can't be relied on.
59
+ - Medusa doesn't pass the capture amount to providers, so the first capture captures the full amount at Adyen. Later partial captures in Medusa only record the amount and don't call Adyen.
60
+ - `/payments` idempotency keys are derived from the session ID and the submitted payment method, so retries are safe and a new submission after a refusal is a new payment.
61
+ - Async payment methods that are only confirmed by the `AUTHORISATION` webhook aren't supported yet.
62
+ - Saved cards are only used and stored with the provider-set `data.shopper_reference`, never one from `data.client`, so shoppers can't reach each other's cards (Adyen rejects another shopper's token with `Contract not found`). Guests get no `shopperReference`, so `store_payment_method` is ignored for them.
63
+ - `savePaymentMethod` (`POST /storedPaymentMethods`) needs the "API tokenise payment details" credential role and a `holderName` in the payment method. Storing a card during a payment only needs the "Merchant Recurring" role.
64
+ - `/payments` and modification requests send a hard-coded `applicationInfo.externalPlatform` (`APPLICATION_INFO` in `src/services/adyen-provider.ts`) that Adyen uses to attribute payments to Medusa for partner revenue sharing. Adyen matches the exact name, so don't change it or make it configurable.
package/README.md CHANGED
@@ -1,3 +1,129 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <a href="https://www.medusajs.com">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
6
+ <img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
7
+ </picture>
8
+ </a>
9
+ </p>
10
+ <h1 align="center">
11
+ @medusajs/payment-adyen
12
+ </h1>
2
13
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
14
+ <h4 align="center">
15
+ <a href="https://docs.medusajs.com">Documentation</a> |
16
+ <a href="https://www.medusajs.com">Website</a>
17
+ </h4>
18
+
19
+ <p align="center">
20
+ Building blocks for digital commerce
21
+ </p>
22
+ <p align="center">
23
+ <a href="https://github.com/medusajs/medusa/blob/develop/LICENSE">
24
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Medusa is released under the MIT license." />
25
+ </a>
26
+ <a href="https://github.com/medusajs/medusa/blob/develop/CONTRIBUTING.md">
27
+ <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
28
+ </a>
29
+ <a href="https://discord.gg/xpCwq3Kfn8">
30
+ <img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
31
+ </a>
32
+ <a href="https://twitter.com/intent/follow?screen_name=medusajs">
33
+ <img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
34
+ </a>
35
+ </p>
36
+
37
+ Adyen Payment Module Provider for Medusa: processes card payments, including 3D Secure, with Adyen's Checkout API (Advanced flow). Use it with Adyen's Drop-in or Components in your storefront. It ships with `@medusajs/medusa` and is registered through the `@medusajs/medusa/payment-adyen` path.
38
+
39
+ ## At a glance
40
+
41
+ | | |
42
+ | --------------------- | --------------------------------------------- |
43
+ | Package | `@medusajs/payment-adyen` |
44
+ | Type | Module Provider (Payment Module) |
45
+ | Provider ID | `pp_adyen_{id}`, for example `pp_adyen_adyen` |
46
+ | Registered by default | No |
47
+ | Import from | `@medusajs/medusa/payment-adyen` |
48
+
49
+ ## Installation
50
+
51
+ No installation needed. The provider is a dependency of `@medusajs/medusa`.
52
+
53
+ ## Usage
54
+
55
+ Register the provider in the Payment Module's `providers` array in `medusa-config.ts`:
56
+
57
+ ```ts
58
+ import { defineConfig } from "@medusajs/framework/utils"
59
+
60
+ module.exports = defineConfig({
61
+ // ...
62
+ modules: [
63
+ {
64
+ resolve: "@medusajs/medusa/payment",
65
+ options: {
66
+ providers: [
67
+ {
68
+ resolve: "@medusajs/medusa/payment-adyen",
69
+ id: "adyen",
70
+ options: {
71
+ apiKey: process.env.ADYEN_API_KEY,
72
+ merchantAccount: process.env.ADYEN_MERCHANT_ACCOUNT,
73
+ hmacKey: process.env.ADYEN_WEBHOOK_HMAC_KEY,
74
+ returnUrl: process.env.ADYEN_RETURN_URL,
75
+ },
76
+ },
77
+ ],
78
+ },
79
+ },
80
+ ],
81
+ })
82
+ ```
83
+
84
+ Then enable the provider in a region, for example from the Medusa Admin.
85
+
86
+ In the Adyen Customer Area, create a standard webhook pointing to `{server_url}/hooks/payment/{provider_id}`, where `{provider_id}` is the registered ID without the `pp_` prefix, such as `adyen_adyen`. Generate its HMAC key and set it as `hmacKey`.
87
+
88
+ ### Storefront flow
89
+
90
+ 1. Initialize a payment session with the provider. The session's `data.payment_methods` holds the response of Adyen's `/paymentMethods`, which you pass to Drop-in.
91
+ 2. In Drop-in's `onSubmit`, pass `state.data.paymentMethod` and `state.data.browserInfo` to the session with `sdk.store.payment.updatePaymentSession`, as `client_data.payment_method` and `client_data.browser_info`. Optionally pass `origin` and `return_url`.
92
+ 3. Complete the cart. If the session's status is `requires_more`, pass its `data.action` to Drop-in.
93
+ 4. In Drop-in's `onAdditionalDetails`, pass `state.data.details` as `client_data.details`, then complete the cart again.
94
+
95
+ If a payment is refused, the session's status is `error`. Pass a new `client_data.payment_method` to the same session to retry.
96
+
97
+ ### Saved cards
98
+
99
+ For logged-in customers, the customer's account holder ID is sent to Adyen as the `shopperReference`:
100
+
101
+ - `data.payment_methods.storedPaymentMethods` lists the customer's saved cards, which Drop-in shows. Paying with one works like any other payment method.
102
+ - To save the card used in a payment, pass Drop-in's `state.data.storePaymentMethod` as `client_data.store_payment_method`. Enable Drop-in's `enableStoreDetails` option to show the checkbox.
103
+ - The Payment Module's `listPaymentMethods`, `createPaymentMethods`, and `deletePaymentMethods` methods list, save, and delete the customer's saved cards. Saving a card without a payment takes Drop-in's `state.data.paymentMethod`, including a `holderName`, as `data.payment_method`, and requires the "API tokenise payment details" role on your API credential.
104
+ - Deleting the account holder deletes the customer's saved cards.
105
+
106
+ ### Limitations
107
+
108
+ - Only cards, including 3D Secure, are supported. Payment methods that are confirmed asynchronously by webhook, such as iDEAL or bank transfers, aren't supported yet.
109
+ - Captures, refunds, and cancellations are recorded in Medusa when they're requested. Adyen confirms them asynchronously, and failures (for example, a refund rejected for insufficient funds) are only logged.
110
+ - Medusa doesn't pass capture amounts to providers, so the first capture captures the full authorized amount.
111
+ - Captures and refunds made in the Adyen Customer Area aren't synced to Medusa.
112
+
113
+ ## Configuration
114
+
115
+ | Option | Type | Description | Default |
116
+ | ----------------------- | ------------------ | ------------------------------------------------------------------------------------------ | -------- |
117
+ | `apiKey` | `string` | Required. The API key of your Adyen API credential. | - |
118
+ | `merchantAccount` | `string` | Required. The merchant account to process payments with. | - |
119
+ | `hmacKey` | `string` | The HMAC key of the standard webhook. Webhooks are rejected without it. | - |
120
+ | `environment` | `"TEST" \| "LIVE"` | The Adyen environment. | `"TEST"` |
121
+ | `liveEndpointUrlPrefix` | `string` | Required in `LIVE`. Find it in the Customer Area under Developers > API URLs. | - |
122
+ | `capture` | `boolean` | Capture payments immediately instead of only authorizing them. | `false` |
123
+ | `returnUrl` | `string` | The URL to return shoppers to after a redirect, unless the storefront passes `return_url`. | - |
124
+
125
+ ## Resources
126
+
127
+ - [Payment Module Provider](https://docs.medusajs.com/resources/commerce-modules/payment/payment-provider)
128
+ - [Payment Session](https://docs.medusajs.com/resources/commerce-modules/payment/payment-session)
129
+ - [Payment Module](https://docs.medusajs.com/resources/commerce-modules/payment)
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@medusajs/types").ModuleProviderExports;
2
+ export default _default;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAKA,wBAEE"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@medusajs/framework/utils");
4
+ const services_1 = require("./services");
5
+ const services = [services_1.AdyenProviderService];
6
+ exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.PAYMENT, {
7
+ services,
8
+ });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,qDAAmE;AACnE,yCAAiD;AAEjD,MAAM,QAAQ,GAAG,CAAC,+BAAoB,CAAC,CAAA;AAEvC,kBAAe,IAAA,sBAAc,EAAC,eAAO,CAAC,OAAO,EAAE;IAC7C,QAAQ;CACT,CAAC,CAAA"}
@@ -0,0 +1,50 @@
1
+ import { CheckoutAPI, hmacValidator, Types } from "@adyen/api-library";
2
+ import { AuthorizePaymentInput, AuthorizePaymentOutput, CancelPaymentInput, CancelPaymentOutput, CapturePaymentInput, CapturePaymentOutput, CreateAccountHolderInput, CreateAccountHolderOutput, DeleteAccountHolderInput, DeleteAccountHolderOutput, DeletePaymentInput, DeletePaymentOutput, GetPaymentStatusInput, GetPaymentStatusOutput, DeletePaymentMethodInput, DeletePaymentMethodOutput, InitiatePaymentInput, InitiatePaymentOutput, ListPaymentMethodsInput, ListPaymentMethodsOutput, Logger, ProviderWebhookPayload, RefundPaymentInput, RefundPaymentOutput, RetrieveAccountHolderInput, RetrieveAccountHolderOutput, RetrievePaymentInput, RetrievePaymentOutput, SavePaymentMethodInput, SavePaymentMethodOutput, UpdateAccountHolderInput, UpdateAccountHolderOutput, UpdatePaymentInput, UpdatePaymentOutput, WebhookActionResult } from "@medusajs/framework/types";
3
+ import { AbstractPaymentProvider, PaymentSessionStatus } from "@medusajs/framework/utils";
4
+ import { AdyenClientData, AdyenOptions, AdyenSessionData } from "../types";
5
+ type AccountHolderContext = {
6
+ account_holder?: {
7
+ data?: Record<string, unknown>;
8
+ };
9
+ };
10
+ type InjectedDependencies = {
11
+ logger: Logger;
12
+ };
13
+ declare class AdyenProviderService extends AbstractPaymentProvider<AdyenOptions> {
14
+ static identifier: string;
15
+ protected readonly options_: AdyenOptions;
16
+ protected readonly logger_: Logger;
17
+ protected readonly checkout_: CheckoutAPI;
18
+ protected readonly hmacValidator_: hmacValidator;
19
+ static validateOptions(options: Record<string, unknown>): void;
20
+ constructor(container: InjectedDependencies, options: AdyenOptions);
21
+ initiatePayment({ amount, currency_code, data, context, }: InitiatePaymentInput): Promise<InitiatePaymentOutput>;
22
+ updatePayment({ amount, currency_code, data, }: UpdatePaymentInput): Promise<UpdatePaymentOutput>;
23
+ authorizePayment({ data, }: AuthorizePaymentInput): Promise<AuthorizePaymentOutput>;
24
+ getPaymentStatus({ data, }: GetPaymentStatusInput): Promise<GetPaymentStatusOutput>;
25
+ retrievePayment({ data, }: RetrievePaymentInput): Promise<RetrievePaymentOutput>;
26
+ capturePayment({ data, context, }: CapturePaymentInput): Promise<CapturePaymentOutput>;
27
+ refundPayment({ amount, data, context, }: RefundPaymentInput): Promise<RefundPaymentOutput>;
28
+ cancelPayment({ data, context, }: CancelPaymentInput): Promise<CancelPaymentOutput>;
29
+ deletePayment({ data, context, }: DeletePaymentInput): Promise<DeletePaymentOutput>;
30
+ createAccountHolder({ context, }: CreateAccountHolderInput): Promise<CreateAccountHolderOutput>;
31
+ retrieveAccountHolder({ id, }: RetrieveAccountHolderInput): Promise<RetrieveAccountHolderOutput>;
32
+ updateAccountHolder(_: UpdateAccountHolderInput): Promise<UpdateAccountHolderOutput>;
33
+ deleteAccountHolder({ context, }: DeleteAccountHolderInput): Promise<DeleteAccountHolderOutput>;
34
+ listPaymentMethods({ context, }: ListPaymentMethodsInput): Promise<ListPaymentMethodsOutput>;
35
+ savePaymentMethod({ data, context, }: SavePaymentMethodInput): Promise<SavePaymentMethodOutput>;
36
+ deletePaymentMethod({ data, context, }: DeletePaymentMethodInput): Promise<DeletePaymentMethodOutput>;
37
+ protected listStoredPaymentMethods(shopperReference: string): Promise<Types.checkout.StoredPaymentMethodResource[]>;
38
+ protected deleteStoredPaymentMethod(id: string, shopperReference: string): Promise<void>;
39
+ getWebhookActionAndData({ data, }: ProviderWebhookPayload["payload"]): Promise<WebhookActionResult>;
40
+ protected isValidNotification(item?: Types.notification.NotificationRequestItem): boolean;
41
+ protected buildPaymentRequest(session: AdyenSessionData, client: AdyenClientData): Types.checkout.PaymentRequest;
42
+ protected getStatus(session: AdyenSessionData): PaymentSessionStatus;
43
+ protected getAuthorizedStatus(session: AdyenSessionData): PaymentSessionStatus.AUTHORIZED | PaymentSessionStatus.CAPTURED;
44
+ protected getShopperReference(context?: AccountHolderContext): string | undefined;
45
+ protected requireShopperReference(context?: AccountHolderContext): string;
46
+ protected getPspReference(session: AdyenSessionData): string;
47
+ protected request<T>(operation: string, fn: () => Promise<T>): Promise<T>;
48
+ }
49
+ export default AdyenProviderService;
50
+ //# sourceMappingURL=adyen-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adyen-provider.d.ts","sourceRoot":"","sources":["../../src/services/adyen-provider.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EAGX,aAAa,EACb,KAAK,EACN,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,MAAM,EACN,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,0BAA0B,EAC1B,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,uBAAuB,EAGvB,oBAAoB,EACrB,MAAM,2BAA2B,CAAA;AAElC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAG1E,KAAK,oBAAoB,GAAG;IAC1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,EACzB,MAAM,EAAE,eAAe,GACtB,KAAK,CAAC,QAAQ,CAAC,cAAc;IAkDhC,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,oBAAoB;IAmBpE,SAAS,CAAC,mBAAmB,CAAC,OAAO,EAAE,gBAAgB;IAMvD,SAAS,CAAC,mBAAmB,CAC3B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,MAAM,GAAG,SAAS;IAIrB,SAAS,CAAC,uBAAuB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM;IAYzE,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM;cAa5C,OAAO,CAAC,CAAC,EACvB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC;CAsCd;AAED,eAAe,oBAAoB,CAAA"}
@@ -0,0 +1,495 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const crypto_1 = __importDefault(require("crypto"));
7
+ const api_library_1 = require("@adyen/api-library");
8
+ const utils_1 = require("@medusajs/framework/utils");
9
+ const amounts_1 = require("../utils/amounts");
10
+ const ResultCode = api_library_1.Types.checkout.PaymentResponse.ResultCodeEnum;
11
+ const CARD_ON_FILE = api_library_1.Types.checkout.PaymentRequest.RecurringProcessingModelEnum.CardOnFile;
12
+ const EventCode = api_library_1.Types.notification.NotificationRequestItem.EventCodeEnum;
13
+ // Identifies payments processed through Medusa to Adyen, for partner revenue
14
+ // sharing. Adyen matches on the exact name, so it must not change.
15
+ const APPLICATION_INFO = {
16
+ externalPlatform: { name: "Medusa", integrator: "medusajs" },
17
+ };
18
+ const SESSION_ID_PREFIX = "payses_";
19
+ const MAX_IDEMPOTENCY_KEY_LENGTH = 64;
20
+ const hash = (value) => crypto_1.default.createHash("sha256").update(JSON.stringify(value)).digest("hex");
21
+ // Adyen limits idempotency keys to 64 characters.
22
+ const toIdempotencyKey = (key) => {
23
+ if (!key || key.length <= MAX_IDEMPOTENCY_KEY_LENGTH) {
24
+ return key;
25
+ }
26
+ return hash(key);
27
+ };
28
+ class AdyenProviderService extends utils_1.AbstractPaymentProvider {
29
+ static validateOptions(options) {
30
+ for (const key of ["apiKey", "merchantAccount"]) {
31
+ if (!options[key]) {
32
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Required option \`${key}\` is missing in the Adyen payment provider`);
33
+ }
34
+ }
35
+ if (options.environment === "LIVE" && !options.liveEndpointUrlPrefix) {
36
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Option `liveEndpointUrlPrefix` is required when `environment` is `LIVE` in the Adyen payment provider");
37
+ }
38
+ }
39
+ constructor(container, options) {
40
+ super(container, options);
41
+ this.hmacValidator_ = new api_library_1.hmacValidator();
42
+ this.options_ = options;
43
+ this.logger_ = container.logger;
44
+ this.checkout_ = new api_library_1.CheckoutAPI(new api_library_1.Client({
45
+ apiKey: options.apiKey,
46
+ environment: options.environment === "LIVE"
47
+ ? api_library_1.EnvironmentEnum.LIVE
48
+ : api_library_1.EnvironmentEnum.TEST,
49
+ liveEndpointUrlPrefix: options.liveEndpointUrlPrefix,
50
+ }));
51
+ }
52
+ async initiatePayment({ amount, currency_code, data, context, }) {
53
+ const sessionId = data?.session_id;
54
+ const currency = currency_code.toUpperCase();
55
+ const value = (0, amounts_1.toMinorUnits)(amount, currency);
56
+ const countryCode = data?.country_code ??
57
+ context?.customer?.billing_address?.country_code ??
58
+ undefined;
59
+ const shopperReference = this.getShopperReference(context);
60
+ // With a shopper reference, the response includes the shopper's saved
61
+ // cards in `storedPaymentMethods`, which Drop-in renders.
62
+ const paymentMethods = await this.request("initiatePayment", () => this.checkout_.PaymentsApi.paymentMethods({
63
+ merchantAccount: this.options_.merchantAccount,
64
+ amount: { currency, value },
65
+ countryCode: countryCode?.toUpperCase(),
66
+ channel: api_library_1.Types.checkout.PaymentMethodsRequest.ChannelEnum.Web,
67
+ shopperReference,
68
+ }));
69
+ // Every provider-owned key is set explicitly, so data that the storefront
70
+ // passed when initializing the session can't take their place.
71
+ const sessionData = {
72
+ session_id: sessionId,
73
+ amount: value,
74
+ currency,
75
+ capture: !!this.options_.capture,
76
+ shopper_email: context?.customer?.email ?? null,
77
+ shopper_reference: shopperReference ?? null,
78
+ payment_methods: paymentMethods,
79
+ psp_reference: null,
80
+ result_code: null,
81
+ action: null,
82
+ };
83
+ return {
84
+ id: sessionId,
85
+ status: utils_1.PaymentSessionStatus.PENDING,
86
+ data: sessionData,
87
+ };
88
+ }
89
+ async updatePayment({ amount, currency_code, data, }) {
90
+ const session = data;
91
+ const currency = currency_code.toUpperCase();
92
+ const updated = {
93
+ ...data,
94
+ amount: (0, amounts_1.toMinorUnits)(amount, currency),
95
+ currency,
96
+ };
97
+ // A new payment method after a refusal or an abandoned action starts a new
98
+ // attempt. Carts can't be completed with a session in the `error` status.
99
+ if (session.client?.payment_method &&
100
+ session.result_code !== ResultCode.Authorised) {
101
+ return {
102
+ status: utils_1.PaymentSessionStatus.PENDING,
103
+ data: {
104
+ ...updated,
105
+ psp_reference: null,
106
+ result_code: null,
107
+ action: null,
108
+ },
109
+ };
110
+ }
111
+ return { data: updated };
112
+ }
113
+ async authorizePayment({ data, }) {
114
+ const session = data;
115
+ const client = session.client ?? {};
116
+ if (session.result_code === ResultCode.Authorised) {
117
+ return { status: this.getAuthorizedStatus(session), data };
118
+ }
119
+ let response;
120
+ if (client.details) {
121
+ const request = {
122
+ details: client.details,
123
+ };
124
+ const paymentData = session.action
125
+ ?.paymentData;
126
+ if (paymentData) {
127
+ request.paymentData = paymentData;
128
+ }
129
+ response = await this.request("authorizePayment", () => this.checkout_.PaymentsApi.paymentsDetails(request, {
130
+ idempotencyKey: toIdempotencyKey(`${session.session_id}-${hash(client.details).slice(0, 16)}`),
131
+ }));
132
+ }
133
+ else if (client.payment_method) {
134
+ const request = this.buildPaymentRequest(session, client);
135
+ // Keyed on the submitted payment method, so retrying the same submission
136
+ // is safe while a new one (for example, after a refusal) is a new payment.
137
+ response = await this.request("authorizePayment", () => this.checkout_.PaymentsApi.payments(request, {
138
+ idempotencyKey: toIdempotencyKey(`${session.session_id}-${hash(client.payment_method).slice(0, 16)}`),
139
+ }));
140
+ }
141
+ else {
142
+ // TODO: async payment methods (for example, iDEAL or bank transfers) are only
143
+ // confirmed by the AUTHORISATION webhook. Supporting them needs the webhook
144
+ // result to be persisted on the session before it's authorized.
145
+ return { status: this.getStatus(session), data };
146
+ }
147
+ if (response.resultCode !== ResultCode.Authorised) {
148
+ this.logger_.info(`Adyen payment for session ${session.session_id} returned ${response.resultCode}${response.refusalReason ? `: ${response.refusalReason}` : ""}`);
149
+ }
150
+ const action = "action" in response && response.action ? response.action : null;
151
+ const updated = {
152
+ ...session,
153
+ psp_reference: response.pspReference ?? session.psp_reference,
154
+ result_code: response.resultCode ?? null,
155
+ action,
156
+ // Don't retain the shopper's payment details once they're submitted.
157
+ client: {
158
+ ...client,
159
+ payment_method: null,
160
+ browser_info: null,
161
+ details: null,
162
+ },
163
+ };
164
+ return {
165
+ status: this.getStatus(updated),
166
+ data: updated,
167
+ };
168
+ }
169
+ async getPaymentStatus({ data, }) {
170
+ return {
171
+ status: this.getStatus(data),
172
+ data,
173
+ };
174
+ }
175
+ async retrievePayment({ data, }) {
176
+ // Adyen has no API to retrieve a payment, so the stored data is the latest known state.
177
+ return { data };
178
+ }
179
+ async capturePayment({ data, context, }) {
180
+ const session = data;
181
+ // Medusa doesn't pass the capture amount to providers, so the first capture
182
+ // is always for the full amount and later partial captures only record it.
183
+ // TODO: capture the requested amount once Medusa passes it.
184
+ if (session.capture || session.capture_psp_reference) {
185
+ return { data };
186
+ }
187
+ const pspReference = this.getPspReference(session);
188
+ // Adyen confirms the capture asynchronously with a CAPTURE webhook.
189
+ // TODO: reflect captures that later fail (CAPTURE_FAILED) in Medusa.
190
+ const response = await this.request("capturePayment", () => this.checkout_.ModificationsApi.captureAuthorisedPayment(pspReference, {
191
+ merchantAccount: this.options_.merchantAccount,
192
+ amount: { currency: session.currency, value: session.amount },
193
+ reference: session.session_id,
194
+ applicationInfo: APPLICATION_INFO,
195
+ }, { idempotencyKey: toIdempotencyKey(context?.idempotency_key) }));
196
+ return {
197
+ data: { ...data, capture_psp_reference: response.pspReference },
198
+ };
199
+ }
200
+ async refundPayment({ amount, data, context, }) {
201
+ const session = data;
202
+ const pspReference = this.getPspReference(session);
203
+ // Adyen confirms the refund asynchronously with a REFUND webhook.
204
+ // TODO: reflect refunds that later fail (REFUND_FAILED) in Medusa.
205
+ await this.request("refundPayment", () => this.checkout_.ModificationsApi.refundCapturedPayment(pspReference, {
206
+ merchantAccount: this.options_.merchantAccount,
207
+ amount: {
208
+ currency: session.currency,
209
+ value: (0, amounts_1.toMinorUnits)(amount, session.currency),
210
+ },
211
+ reference: session.session_id,
212
+ applicationInfo: APPLICATION_INFO,
213
+ }, { idempotencyKey: toIdempotencyKey(context?.idempotency_key) }));
214
+ return { data };
215
+ }
216
+ async cancelPayment({ data, context, }) {
217
+ const session = data;
218
+ if (!session.psp_reference ||
219
+ session.result_code !== ResultCode.Authorised) {
220
+ return { data };
221
+ }
222
+ const request = {
223
+ merchantAccount: this.options_.merchantAccount,
224
+ reference: session.session_id,
225
+ applicationInfo: APPLICATION_INFO,
226
+ };
227
+ const options = {
228
+ idempotencyKey: toIdempotencyKey(context?.idempotency_key),
229
+ };
230
+ // Auto-captured payments can't be canceled, only reversed (refunded).
231
+ await this.request("cancelPayment", () => session.capture
232
+ ? this.checkout_.ModificationsApi.refundOrCancelPayment(session.psp_reference, request, options)
233
+ : this.checkout_.ModificationsApi.cancelAuthorisedPaymentByPspReference(session.psp_reference, request, options));
234
+ return { data };
235
+ }
236
+ async deletePayment({ data, context, }) {
237
+ const session = data;
238
+ // Release an authorization that will never be used. Auto-captured payments
239
+ // aren't refunded here, as deleting a session shouldn't move money.
240
+ if (!session?.capture) {
241
+ return await this.cancelPayment({ data, context });
242
+ }
243
+ return { data };
244
+ }
245
+ // Adyen has no shopper object: the `shopperReference` sent with payments is
246
+ // the account holder's ID.
247
+ async createAccountHolder({ context, }) {
248
+ const { account_holder, customer } = context;
249
+ if (account_holder?.data?.id) {
250
+ return { id: account_holder.data.id };
251
+ }
252
+ return { id: customer.id, data: { id: customer.id } };
253
+ }
254
+ async retrieveAccountHolder({ id, }) {
255
+ return { id, data: { id } };
256
+ }
257
+ async updateAccountHolder(_) {
258
+ return {};
259
+ }
260
+ // Deleting the account holder also deletes the shopper's saved cards, as
261
+ // nothing could use them afterwards.
262
+ async deleteAccountHolder({ context, }) {
263
+ const shopperReference = this.getShopperReference(context);
264
+ if (!shopperReference) {
265
+ return {};
266
+ }
267
+ const paymentMethods = await this.listStoredPaymentMethods(shopperReference);
268
+ for (const paymentMethod of paymentMethods) {
269
+ await this.deleteStoredPaymentMethod(paymentMethod.id, shopperReference);
270
+ }
271
+ return {};
272
+ }
273
+ async listPaymentMethods({ context, }) {
274
+ const shopperReference = this.getShopperReference(context);
275
+ if (!shopperReference) {
276
+ return [];
277
+ }
278
+ const paymentMethods = await this.listStoredPaymentMethods(shopperReference);
279
+ return paymentMethods.map((paymentMethod) => ({
280
+ id: paymentMethod.id,
281
+ data: paymentMethod,
282
+ }));
283
+ }
284
+ // Stores the card that Drop-in collected, passed as `data.payment_method`,
285
+ // without making a payment.
286
+ async savePaymentMethod({ data, context, }) {
287
+ const shopperReference = this.requireShopperReference(context);
288
+ const paymentMethod = await this.request("savePaymentMethod", () => this.checkout_.RecurringApi.storedPaymentMethods({
289
+ merchantAccount: this.options_.merchantAccount,
290
+ shopperReference,
291
+ paymentMethod: data?.payment_method,
292
+ recurringProcessingModel: api_library_1.Types.checkout.StoredPaymentMethodRequest
293
+ .RecurringProcessingModelEnum.CardOnFile,
294
+ shopperEmail: context?.customer?.email,
295
+ }, { idempotencyKey: toIdempotencyKey(context?.idempotency_key) }));
296
+ return {
297
+ id: paymentMethod.id,
298
+ data: paymentMethod,
299
+ };
300
+ }
301
+ async deletePaymentMethod({ data, context, }) {
302
+ await this.deleteStoredPaymentMethod(data.id, this.requireShopperReference(context));
303
+ return {};
304
+ }
305
+ async listStoredPaymentMethods(shopperReference) {
306
+ const response = await this.request("listPaymentMethods", () => this.checkout_.RecurringApi.getTokensForStoredPaymentDetails(shopperReference, this.options_.merchantAccount));
307
+ return response.storedPaymentMethods ?? [];
308
+ }
309
+ async deleteStoredPaymentMethod(id, shopperReference) {
310
+ await this.request("deletePaymentMethod", () => this.checkout_.RecurringApi.deleteTokenForStoredPaymentDetails(id, shopperReference, this.options_.merchantAccount));
311
+ }
312
+ async getWebhookActionAndData({ data, }) {
313
+ const notSupported = { action: utils_1.PaymentActions.NOT_SUPPORTED };
314
+ const items = (data?.notificationItems ?? [])
315
+ .map((item) => item.NotificationRequestItem)
316
+ .filter((item) => this.isValidNotification(item));
317
+ // Adyen sends a single item per JSON webhook, and the webhook route handles
318
+ // one action per request.
319
+ if (items.length > 1) {
320
+ this.logger_.warn(`Adyen webhook contained ${items.length} notifications, only the first is processed`);
321
+ }
322
+ const item = items[0];
323
+ if (!item) {
324
+ return notSupported;
325
+ }
326
+ const succeeded = item.success === "true";
327
+ const { value = 0, currency } = item.amount ?? {};
328
+ const result = {
329
+ session_id: item.merchantReference,
330
+ amount: currency ? (0, amounts_1.fromMinorUnits)(value, currency) : 0,
331
+ };
332
+ switch (item.eventCode) {
333
+ case EventCode.Authorisation:
334
+ if (!succeeded) {
335
+ return { action: utils_1.PaymentActions.FAILED, data: result };
336
+ }
337
+ return {
338
+ action: this.options_.capture
339
+ ? utils_1.PaymentActions.SUCCESSFUL
340
+ : utils_1.PaymentActions.AUTHORIZED,
341
+ data: result,
342
+ };
343
+ case EventCode.Cancellation:
344
+ return succeeded
345
+ ? { action: utils_1.PaymentActions.CANCELED, data: result }
346
+ : notSupported;
347
+ case EventCode.Capture:
348
+ case EventCode.Refund:
349
+ if (!succeeded) {
350
+ // TODO: reflect failed captures and refunds in Medusa.
351
+ this.logger_.error(`Adyen ${item.eventCode} for session ${item.merchantReference} failed: ${item.reason}`);
352
+ }
353
+ // Captures and refunds are already recorded when Medusa requests them.
354
+ // TODO: sync captures and refunds made outside of Medusa, such as in the Customer Area.
355
+ return notSupported;
356
+ case EventCode.CaptureFailed:
357
+ case EventCode.RefundFailed:
358
+ // TODO: reflect failed captures and refunds in Medusa.
359
+ this.logger_.error(`Adyen ${item.eventCode} for session ${item.merchantReference}: ${item.reason}`);
360
+ return notSupported;
361
+ default:
362
+ return notSupported;
363
+ }
364
+ }
365
+ isValidNotification(item) {
366
+ if (!item) {
367
+ return false;
368
+ }
369
+ if (!this.options_.hmacKey) {
370
+ this.logger_.warn("Adyen webhook rejected because the `hmacKey` option isn't set");
371
+ return false;
372
+ }
373
+ let isValid = false;
374
+ try {
375
+ isValid = this.hmacValidator_.validateHMAC(item, this.options_.hmacKey);
376
+ }
377
+ catch { }
378
+ if (!isValid) {
379
+ this.logger_.warn(`Adyen webhook for ${item.pspReference} rejected because of an invalid HMAC signature`);
380
+ return false;
381
+ }
382
+ // A webhook endpoint can be shared by merchant accounts and integrations,
383
+ // so only notifications for payment sessions of this account are handled.
384
+ return (item.merchantAccountCode === this.options_.merchantAccount &&
385
+ !!item.merchantReference?.startsWith(SESSION_ID_PREFIX));
386
+ }
387
+ buildPaymentRequest(session, client) {
388
+ const returnUrl = client.return_url ?? this.options_.returnUrl;
389
+ if (!returnUrl) {
390
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Adyen requires a return URL. Set the `returnUrl` option or pass `return_url` in the payment session's client data.");
391
+ }
392
+ const shopperReference = session.shopper_reference ?? undefined;
393
+ const isStoredPaymentMethod = !!client.payment_method.storedPaymentMethodId;
394
+ // Saved cards are tied to the shopper reference set by the provider, so a
395
+ // shopper can't pay with or save to another shopper's cards.
396
+ const storePaymentMethod = !!shopperReference && !!client.store_payment_method;
397
+ return {
398
+ merchantAccount: this.options_.merchantAccount,
399
+ amount: { currency: session.currency, value: session.amount },
400
+ reference: session.session_id,
401
+ shopperReference,
402
+ ...(storePaymentMethod ? { storePaymentMethod: true } : {}),
403
+ ...(storePaymentMethod || isStoredPaymentMethod
404
+ ? { recurringProcessingModel: CARD_ON_FILE }
405
+ : {}),
406
+ paymentMethod: client.payment_method,
407
+ browserInfo: client.browser_info ?? undefined,
408
+ origin: client.origin ?? undefined,
409
+ returnUrl,
410
+ shopperEmail: session.shopper_email ?? undefined,
411
+ channel: api_library_1.Types.checkout.PaymentRequest.ChannelEnum.Web,
412
+ shopperInteraction: api_library_1.Types.checkout.PaymentRequest.ShopperInteractionEnum.Ecommerce,
413
+ authenticationData: {
414
+ threeDSRequestData: {
415
+ nativeThreeDS: api_library_1.Types.checkout.ThreeDSRequestData.NativeThreeDSEnum.Preferred,
416
+ },
417
+ },
418
+ // Both override the merchant account's capture delay, which Medusa can't
419
+ // rely on: it records the payment as captured when `capture` is enabled.
420
+ ...(session.capture
421
+ ? { captureDelayHours: 0 }
422
+ : { additionalData: { manualCapture: "true" } }),
423
+ applicationInfo: APPLICATION_INFO,
424
+ };
425
+ }
426
+ getStatus(session) {
427
+ switch (session.result_code) {
428
+ case ResultCode.Authorised:
429
+ return this.getAuthorizedStatus(session);
430
+ case ResultCode.RedirectShopper:
431
+ case ResultCode.ChallengeShopper:
432
+ case ResultCode.IdentifyShopper:
433
+ return utils_1.PaymentSessionStatus.REQUIRES_MORE;
434
+ case ResultCode.Cancelled:
435
+ return utils_1.PaymentSessionStatus.CANCELED;
436
+ case ResultCode.Refused:
437
+ case ResultCode.Error:
438
+ case ResultCode.PartiallyAuthorised:
439
+ return utils_1.PaymentSessionStatus.ERROR;
440
+ default:
441
+ return utils_1.PaymentSessionStatus.PENDING;
442
+ }
443
+ }
444
+ getAuthorizedStatus(session) {
445
+ return session.capture
446
+ ? utils_1.PaymentSessionStatus.CAPTURED
447
+ : utils_1.PaymentSessionStatus.AUTHORIZED;
448
+ }
449
+ getShopperReference(context) {
450
+ return context?.account_holder?.data?.id;
451
+ }
452
+ requireShopperReference(context) {
453
+ const shopperReference = this.getShopperReference(context);
454
+ if (!shopperReference) {
455
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Adyen saved payment methods require an account holder");
456
+ }
457
+ return shopperReference;
458
+ }
459
+ getPspReference(session) {
460
+ if (!session.psp_reference) {
461
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Adyen payment for session ${session.session_id} has no PSP reference`);
462
+ }
463
+ return session.psp_reference;
464
+ }
465
+ // Adyen's error details are logged, not returned, as provider errors can
466
+ // reach the storefront.
467
+ async request(operation, fn) {
468
+ try {
469
+ return await fn();
470
+ }
471
+ catch (error) {
472
+ const { statusCode, errorCode, responseBody, message } = error;
473
+ this.logger_.error(`Adyen ${operation} failed: ${[
474
+ statusCode,
475
+ errorCode,
476
+ message,
477
+ responseBody,
478
+ ]
479
+ .filter(Boolean)
480
+ .join(" | ")}`);
481
+ // Validation errors (for example, invalid payment details) are the
482
+ // shopper's to fix, while authentication and server errors aren't.
483
+ const isValidationError = !!statusCode &&
484
+ statusCode >= 400 &&
485
+ statusCode < 500 &&
486
+ ![401, 403].includes(statusCode);
487
+ throw new utils_1.MedusaError(isValidationError
488
+ ? utils_1.MedusaError.Types.INVALID_DATA
489
+ : utils_1.MedusaError.Types.UNEXPECTED_STATE, `An error occurred in ${operation} with Adyen`);
490
+ }
491
+ }
492
+ }
493
+ AdyenProviderService.identifier = "adyen";
494
+ exports.default = AdyenProviderService;
495
+ //# sourceMappingURL=adyen-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adyen-provider.js","sourceRoot":"","sources":["../../src/services/adyen-provider.ts"],"names":[],"mappings":";;;;;AAAA,oDAA2B;AAE3B,oDAM2B;AAsC3B,qDAKkC;AAGlC,8CAA+D;AAa/D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BAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,6BAA6B,OAAO,CAAC,UAAU,uBAAuB,CACvE,CAAA;QACH,CAAC;QAED,OAAO,OAAO,CAAC,aAAa,CAAA;IAC9B,CAAC;IAED,yEAAyE;IACzE,wBAAwB;IACd,KAAK,CAAC,OAAO,CACrB,SAAiB,EACjB,EAAoB;QAEpB,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAA;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,KAKxD,CAAA;YAED,IAAI,CAAC,OAAO,CAAC,KAAK,CAChB,SAAS,SAAS,YAAY;gBAC5B,UAAU;gBACV,SAAS;gBACT,OAAO;gBACP,YAAY;aACb;iBACE,MAAM,CAAC,OAAO,CAAC;iBACf,IAAI,CAAC,KAAK,CAAC,EAAE,CACjB,CAAA;YAED,mEAAmE;YACnE,mEAAmE;YACnE,MAAM,iBAAiB,GACrB,CAAC,CAAC,UAAU;gBACZ,UAAU,IAAI,GAAG;gBACjB,UAAU,GAAG,GAAG;gBAChB,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;YAElC,MAAM,IAAI,mBAAW,CACnB,iBAAiB;gBACf,CAAC,CAAC,mBAAW,CAAC,KAAK,CAAC,YAAY;gBAChC,CAAC,CAAC,mBAAW,CAAC,KAAK,CAAC,gBAAgB,EACtC,wBAAwB,SAAS,aAAa,CAC/C,CAAA;QACH,CAAC;IACH,CAAC;;AAltBM,+BAAU,GAAG,OAAO,AAAV,CAAU;AAqtB7B,kBAAe,oBAAoB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { default as AdyenProviderService } from "./adyen-provider";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AdyenProviderService = void 0;
7
+ var adyen_provider_1 = require("./adyen-provider");
8
+ Object.defineProperty(exports, "AdyenProviderService", { enumerable: true, get: function () { return __importDefault(adyen_provider_1).default; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAkE;AAAzD,uIAAA,OAAO,OAAwB"}
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts","../src/services/adyen-provider.ts","../src/services/index.ts","../src/services/__tests__/adyen-provider.spec.ts","../src/types/index.ts","../src/utils/amounts.ts","../src/utils/__tests__/amounts.spec.ts"],"version":"5.9.3"}
@@ -0,0 +1,64 @@
1
+ import { Types } from "@adyen/api-library";
2
+ export type AdyenEnvironment = "TEST" | "LIVE";
3
+ export interface AdyenOptions {
4
+ apiKey: string;
5
+ merchantAccount: string;
6
+ /**
7
+ * The HMAC key of the standard webhook. Webhooks are rejected without it.
8
+ */
9
+ hmacKey?: string;
10
+ /**
11
+ * @defaultValue "TEST"
12
+ */
13
+ environment?: AdyenEnvironment;
14
+ /**
15
+ * Required when `environment` is `LIVE`. Find it in the Customer Area under Developers > API URLs.
16
+ */
17
+ liveEndpointUrlPrefix?: string;
18
+ /**
19
+ * Whether to capture payments immediately after authorization.
20
+ *
21
+ * @defaultValue false
22
+ */
23
+ capture?: boolean;
24
+ /**
25
+ * The URL to return the shopper to after a redirect, used when the
26
+ * storefront doesn't pass `return_url` in the session's `data.client`.
27
+ */
28
+ returnUrl?: string;
29
+ }
30
+ /**
31
+ * Data the storefront passes in the session's `data.client`. Treated as untrusted.
32
+ */
33
+ export interface AdyenClientData {
34
+ payment_method?: Types.checkout.PaymentRequest["paymentMethod"] | null;
35
+ browser_info?: Types.checkout.BrowserInfo | null;
36
+ details?: Types.checkout.PaymentCompletionDetails | null;
37
+ origin?: string | null;
38
+ return_url?: string | null;
39
+ /**
40
+ * Whether to save the card for future payments, from Drop-in's `state.data.storePaymentMethod`.
41
+ * Only applies to customers with an account holder.
42
+ */
43
+ store_payment_method?: boolean | null;
44
+ }
45
+ export interface AdyenSessionData {
46
+ session_id: string;
47
+ /**
48
+ * The amount in minor units.
49
+ */
50
+ amount: number;
51
+ currency: string;
52
+ capture: boolean;
53
+ shopper_email?: string | null;
54
+ /**
55
+ * The account holder's ID, which Adyen uses to store and look up saved cards.
56
+ */
57
+ shopper_reference?: string | null;
58
+ payment_methods?: Types.checkout.PaymentMethodsResponse | null;
59
+ psp_reference: string | null;
60
+ result_code: string | null;
61
+ action: Types.checkout.PaymentResponseAction | null;
62
+ client?: AdyenClientData;
63
+ }
64
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAA;AAE9C,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAA;IAC9B;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,eAAe,CAAC,GAAG,IAAI,CAAA;IACtE,YAAY,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,WAAW,GAAG,IAAI,CAAA;IAChD,OAAO,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,wBAAwB,GAAG,IAAI,CAAA;IACxD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;CACtC;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,eAAe,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,sBAAsB,GAAG,IAAI,CAAA;IAC9D,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,qBAAqB,GAAG,IAAI,CAAA;IACnD,MAAM,CAAC,EAAE,eAAe,CAAA;CACzB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { BigNumberInput } from "@medusajs/framework/types";
2
+ export declare function getCurrencyExponent(currency: string): number;
3
+ export declare function toMinorUnits(amount: BigNumberInput, currency: string): number;
4
+ export declare function fromMinorUnits(amount: number, currency: string): number;
5
+ //# sourceMappingURL=amounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amounts.d.ts","sourceRoot":"","sources":["../../src/utils/amounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAkC1D,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAY5D;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAI7E;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIvE"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCurrencyExponent = getCurrencyExponent;
4
+ exports.toMinorUnits = toMinorUnits;
5
+ exports.fromMinorUnits = fromMinorUnits;
6
+ const utils_1 = require("@medusajs/framework/utils");
7
+ // Adyen's own exponents, which differ from ISO 4217 for some currencies
8
+ // (for example, CLP and ISK have 2 decimals and IDR has 0).
9
+ // https://docs.adyen.com/development-resources/currency-codes
10
+ const ZERO_DECIMAL_CURRENCIES = new Set([
11
+ "CVE",
12
+ "DJF",
13
+ "GNF",
14
+ "IDR",
15
+ "JPY",
16
+ "KMF",
17
+ "KRW",
18
+ "PYG",
19
+ "RWF",
20
+ "UGX",
21
+ "VND",
22
+ "VUV",
23
+ "XAF",
24
+ "XOF",
25
+ "XPF",
26
+ ]);
27
+ const THREE_DECIMAL_CURRENCIES = new Set([
28
+ "BHD",
29
+ "IQD",
30
+ "JOD",
31
+ "KWD",
32
+ "LYD",
33
+ "OMR",
34
+ "TND",
35
+ ]);
36
+ function getCurrencyExponent(currency) {
37
+ const code = currency.toUpperCase();
38
+ if (ZERO_DECIMAL_CURRENCIES.has(code)) {
39
+ return 0;
40
+ }
41
+ if (THREE_DECIMAL_CURRENCIES.has(code)) {
42
+ return 3;
43
+ }
44
+ return 2;
45
+ }
46
+ function toMinorUnits(amount, currency) {
47
+ const multiplier = 10 ** getCurrencyExponent(currency);
48
+ return utils_1.MathBN.convert(utils_1.MathBN.mult(amount, multiplier), 0).toNumber();
49
+ }
50
+ function fromMinorUnits(amount, currency) {
51
+ const multiplier = 10 ** getCurrencyExponent(currency);
52
+ return utils_1.MathBN.div(amount, multiplier).toNumber();
53
+ }
54
+ //# sourceMappingURL=amounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amounts.js","sourceRoot":"","sources":["../../src/utils/amounts.ts"],"names":[],"mappings":";;AAkCA,kDAYC;AAED,oCAIC;AAED,wCAIC;AAzDD,qDAAkD;AAElD,wEAAwE;AACxE,4DAA4D;AAC5D,8DAA8D;AAC9D,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC;IACtC,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;CACN,CAAC,CAAA;AAEF,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IACvC,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;CACN,CAAC,CAAA;AAEF,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,MAAM,IAAI,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAA;IAEnC,IAAI,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,OAAO,CAAC,CAAA;IACV,CAAC;IAED,IAAI,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,OAAO,CAAC,CAAA;IACV,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC;AAED,SAAgB,YAAY,CAAC,MAAsB,EAAE,QAAgB;IACnE,MAAM,UAAU,GAAG,EAAE,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IAEtD,OAAO,cAAM,CAAC,OAAO,CAAC,cAAM,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;AACtE,CAAC;AAED,SAAgB,cAAc,CAAC,MAAc,EAAE,QAAgB;IAC7D,MAAM,UAAU,GAAG,EAAE,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IAEtD,OAAO,cAAM,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAA;AAClD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@medusajs/payment-adyen",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.22.1",
4
+ "description": "Adyen payment provider for Medusa",
5
+ "main": "dist/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/medusajs/medusa.git",
9
+ "directory": "packages/modules/providers/payment-adyen"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/medusajs/medusa/issues"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "AGENTS.md",
17
+ "!dist/**/__tests__",
18
+ "!dist/**/__mocks__",
19
+ "!dist/**/__fixtures__"
20
+ ],
21
+ "llms": "https://docs.medusajs.com/llms.txt",
22
+ "llmsFull": "https://docs.medusajs.com/llms-full.txt",
23
+ "mcpServer": "https://docs.medusajs.com/mcp",
24
+ "engines": {
25
+ "node": ">=22.22.0"
26
+ },
27
+ "author": "Medusa",
28
+ "license": "MIT",
29
+ "scripts": {
30
+ "test": "../../../../node_modules/.bin/jest --passWithNoTests src",
31
+ "build": "yarn run -T rimraf dist && yarn run -T tsc --build ./tsconfig.json",
32
+ "watch": "yarn run -T tsc --watch"
33
+ },
34
+ "devDependencies": {
35
+ "@medusajs/framework": "2.22.1"
36
+ },
37
+ "peerDependencies": {
38
+ "@medusajs/framework": "2.22.1"
39
+ },
40
+ "dependencies": {
41
+ "@adyen/api-library": "^32.2.0"
42
+ },
43
+ "keywords": [
44
+ "medusa-plugin",
45
+ "medusa-plugin-payment"
46
+ ]
47
+ }