@paytree/medusa-payment-paytree 0.1.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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +195 -0
  3. package/dist/index.d.ts +28 -0
  4. package/dist/index.js +55 -0
  5. package/dist/modules/paytree/index.d.ts +36 -0
  6. package/dist/modules/paytree/index.js +13 -0
  7. package/dist/modules/paytree/migrations/Migration20260617000000.d.ts +5 -0
  8. package/dist/modules/paytree/migrations/Migration20260617000000.js +54 -0
  9. package/dist/modules/paytree/migrations/Migration20260618000000.d.ts +5 -0
  10. package/dist/modules/paytree/migrations/Migration20260618000000.js +19 -0
  11. package/dist/modules/paytree/models/paytree-event-log.d.ts +25 -0
  12. package/dist/modules/paytree/models/paytree-event-log.js +29 -0
  13. package/dist/modules/paytree/models/paytree-setting.d.ts +23 -0
  14. package/dist/modules/paytree/models/paytree-setting.js +27 -0
  15. package/dist/modules/paytree/service.d.ts +60 -0
  16. package/dist/modules/paytree/service.js +47 -0
  17. package/dist/modules/paytree-payment/index.d.ts +8 -0
  18. package/dist/modules/paytree-payment/index.js +16 -0
  19. package/dist/modules/paytree-payment/lib/amount.d.ts +23 -0
  20. package/dist/modules/paytree-payment/lib/amount.js +40 -0
  21. package/dist/modules/paytree-payment/lib/audit.d.ts +26 -0
  22. package/dist/modules/paytree-payment/lib/audit.js +51 -0
  23. package/dist/modules/paytree-payment/lib/client.d.ts +28 -0
  24. package/dist/modules/paytree-payment/lib/client.js +81 -0
  25. package/dist/modules/paytree-payment/lib/constants.d.ts +54 -0
  26. package/dist/modules/paytree-payment/lib/constants.js +55 -0
  27. package/dist/modules/paytree-payment/lib/logger.d.ts +27 -0
  28. package/dist/modules/paytree-payment/lib/logger.js +73 -0
  29. package/dist/modules/paytree-payment/lib/methods.d.ts +69 -0
  30. package/dist/modules/paytree-payment/lib/methods.js +68 -0
  31. package/dist/modules/paytree-payment/lib/redact.d.ts +16 -0
  32. package/dist/modules/paytree-payment/lib/redact.js +60 -0
  33. package/dist/modules/paytree-payment/lib/settings-reader.d.ts +24 -0
  34. package/dist/modules/paytree-payment/lib/settings-reader.js +74 -0
  35. package/dist/modules/paytree-payment/lib/status-map.d.ts +26 -0
  36. package/dist/modules/paytree-payment/lib/status-map.js +66 -0
  37. package/dist/modules/paytree-payment/lib/types.d.ts +144 -0
  38. package/dist/modules/paytree-payment/lib/types.js +2 -0
  39. package/dist/modules/paytree-payment/service.d.ts +36 -0
  40. package/dist/modules/paytree-payment/service.js +369 -0
  41. package/docs/api-reference.md +121 -0
  42. package/docs/architecture.md +97 -0
  43. package/docs/configuration.md +62 -0
  44. package/docs/getting-started.md +111 -0
  45. package/docs/storefront-integration.md +85 -0
  46. package/integration/README.md +46 -0
  47. package/integration/admin/routes/paytree/api.ts +16 -0
  48. package/integration/admin/routes/paytree/method-icons.tsx +106 -0
  49. package/integration/admin/routes/paytree/page.tsx +18 -0
  50. package/integration/admin/routes/paytree/payments/page.tsx +240 -0
  51. package/integration/admin/routes/paytree/settings/page.tsx +214 -0
  52. package/integration/api/admin/paytree/events/route.ts +35 -0
  53. package/integration/api/admin/paytree/settings/route.ts +86 -0
  54. package/integration/api/hooks/paytree/route.ts +195 -0
  55. package/integration/api/store/paytree/methods/route.ts +28 -0
  56. package/package.json +57 -0
  57. package/storefront/README.md +25 -0
  58. package/storefront/components/payment-button.tsx +361 -0
  59. package/storefront/components/payment.tsx +356 -0
  60. package/storefront/components/paytree-method-icon.tsx +106 -0
  61. package/storefront/lib/paytree.ts +23 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Paytree
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/README.md ADDED
@@ -0,0 +1,195 @@
1
+ <h1 align="center">@paytree/medusa-payment-paytree</h1>
2
+
3
+ <p align="center">
4
+ Paytree hosted-payment provider for <a href="https://medusajs.com">Medusa 2.0</a>.
5
+ </p>
6
+
7
+ Adds Paytree as a payment provider in your Medusa store. Customers are handed off
8
+ to a Paytree hosted payment page, pay with the method they chose (card, PayPal,
9
+ Klarna, iDEAL, crypto, bank transfer, and more), and are redirected back to your
10
+ storefront. Status changes are reconciled server-side via a signed-by-lookup
11
+ callback, and every event is written to an auditable log.
12
+
13
+ Like `@medusajs/payment-stripe`, this is an installable package that does most
14
+ of the work; you register it and wire up a few Medusa-side pieces.
15
+
16
+ **Shipped compiled (installed from npm):**
17
+
18
+ - **Payment provider** (`paytree`) — the package's default export, registered
19
+ under Medusa's Payment module.
20
+ - **Data module** (`paytree`) — owns the settings + audit-log tables and their
21
+ migrations.
22
+
23
+ **Shipped as copy-in source (the "some work you still do"):**
24
+
25
+ - **API routes** under [`integration/api`](./integration/api) — the Paytree
26
+ callback (`/hooks/paytree`), the store methods endpoint
27
+ (`/store/paytree/methods`), and the admin settings/events APIs.
28
+ - **Admin UI** under [`integration/admin`](./integration/admin) — a "Paytree"
29
+ sidebar group (Payments log + Settings).
30
+ - **Storefront components** (Next.js) under [`storefront/`](./storefront).
31
+
32
+ These live outside the compiled module because Medusa discovers API routes and
33
+ admin extensions from *your app's* `src/` (and bundles admin with Vite), so they
34
+ are copied in rather than imported. See
35
+ [`integration/README.md`](./integration/README.md).
36
+
37
+ ---
38
+
39
+ ## Requirements
40
+
41
+ - Medusa `>= 2.13`
42
+ - Node `>= 20`
43
+ - A Paytree account and API key
44
+
45
+ ## Installation
46
+
47
+ ```bash
48
+ npm install @paytree/medusa-payment-paytree
49
+ # or
50
+ pnpm add @paytree/medusa-payment-paytree
51
+ # or
52
+ yarn add @paytree/medusa-payment-paytree
53
+ ```
54
+
55
+ ## Configuration
56
+
57
+ Add your credentials to the backend `.env`:
58
+
59
+ ```bash
60
+ PAYTREE_API_KEY=your_paytree_api_key
61
+ # Optional — defaults to https://api.paytree.tech, also editable in the admin UI
62
+ PAYTREE_BASE_URL=https://api.paytree.tech
63
+ # Public URL of THIS backend, used to build the callback URL Paytree calls back
64
+ BACKEND_URL=https://api.mystore.com
65
+ ```
66
+
67
+ Register the payment **provider** (the package's default export) inside the
68
+ Payment module's `providers` array, and register the **data module** so the
69
+ settings/audit tables and their migrations are picked up:
70
+
71
+ ```js
72
+ const { PAYTREE_API_KEY, PAYTREE_BASE_URL, BACKEND_URL } = process.env
73
+
74
+ module.exports = defineConfig({
75
+ // ...
76
+ modules: [
77
+ // Data module: settings + audit-log tables (owns the migrations).
78
+ {
79
+ resolve: "@paytree/medusa-payment-paytree/dist/modules/paytree",
80
+ },
81
+ // Payment module with the Paytree provider.
82
+ {
83
+ key: Modules.PAYMENT,
84
+ resolve: "@medusajs/payment",
85
+ options: {
86
+ providers: [
87
+ {
88
+ resolve: "@paytree/medusa-payment-paytree",
89
+ id: "paytree",
90
+ options: {
91
+ apiKey: PAYTREE_API_KEY,
92
+ backendUrl: BACKEND_URL,
93
+ baseUrl: PAYTREE_BASE_URL,
94
+ // defaultMethod: "card",
95
+ },
96
+ },
97
+ ],
98
+ },
99
+ },
100
+ ],
101
+ })
102
+ ```
103
+
104
+ Then copy the API routes and admin UI from
105
+ [`integration/`](./integration) into your backend's `src/` (see
106
+ [`integration/README.md`](./integration/README.md)), and run migrations.
107
+
108
+ > The API key is **only** ever read from the provider options (i.e. the
109
+ > `PAYTREE_API_KEY` env var). It is never written to the database and never
110
+ > returned by any API or shown in the admin UI.
111
+
112
+ Run migrations to create the `paytree_setting` and `paytree_event_log` tables:
113
+
114
+ ```bash
115
+ npx medusa db:migrate
116
+ ```
117
+
118
+ Finally, enable Paytree for the relevant regions in the Medusa admin
119
+ (**Settings → Regions → Payment providers**), the same as any other provider.
120
+
121
+ ## Provider options
122
+
123
+ | Option | Required | Description |
124
+ | --------------- | -------- | --------------------------------------------------------------------------- |
125
+ | `apiKey` | yes | Paytree API key. Sent as `Authorization: Token <apiKey>`. Source from env. |
126
+ | `backendUrl` | yes | Public URL of this Medusa backend; used to build the callback URL. |
127
+ | `baseUrl` | no | Paytree API origin. Falls back to the admin setting, then the default. |
128
+ | `defaultMethod` | no | Method requested when the storefront doesn't specify one. Defaults `card`. |
129
+
130
+ ## How it works
131
+
132
+ ```mermaid
133
+ sequenceDiagram
134
+ participant S as Storefront
135
+ participant M as Medusa (provider)
136
+ participant P as Paytree API
137
+ participant C as Customer
138
+
139
+ S->>M: initiatePaymentSession (customer, address, session, method)
140
+ M->>P: POST /v1/transaction/payment_intent/
141
+ P-->>M: { id, payment_link }
142
+ M-->>S: session.data.payment_link
143
+ S->>C: redirect to hosted payment page
144
+ C->>P: pays
145
+ P->>M: GET /hooks/paytree?payment_intent_id=..&transaction_id=..
146
+ M->>P: authoritative status lookup (by transaction_ref)
147
+ M->>M: processPaymentWorkflow / refundPaymentWorkflow
148
+ C->>S: redirected to return_url → order confirmed
149
+ ```
150
+
151
+ Key design points:
152
+
153
+ - **Auto-capture model.** Paytree captures on the hosted page, so a `success`
154
+ status maps to Medusa `CAPTURED`. There is no separate capture call.
155
+ - **Callback is trusted by lookup, not signature.** The `/hooks/paytree` GET
156
+ callback carries only ids; the handler re-fetches the authoritative status
157
+ from Paytree using the secret API key. It is idempotent and safe to retry.
158
+ - **Refunds are reflected, not initiated.** Refunds are performed in the Paytree
159
+ back office; the callback drives Medusa's refund workflow, and the provider
160
+ verifies the refund exists in Paytree before recording it.
161
+ - **Correlation.** The Medusa payment session id is used as Paytree's
162
+ `transaction_ref`, so a payment can be traced end-to-end by that single id.
163
+
164
+ See [`docs/architecture.md`](./docs/architecture.md) for the full breakdown.
165
+
166
+ ## Admin UI
167
+
168
+ Once installed, a **Paytree** group appears in the admin sidebar:
169
+
170
+ - **Payments** — the audit log of every event (initiate, capture, callback,
171
+ refund, errors), filterable by session/intent id and event type.
172
+ - **Settings** — the API endpoint, per-method enable/label overrides shown at
173
+ checkout, and opt-in request/response logging (always redacted).
174
+
175
+ ## Storefront
176
+
177
+ The backend exposes `GET /store/paytree/methods` returning the admin-enabled
178
+ methods. The [`storefront/`](./storefront) folder contains reference Next.js
179
+ components (method picker, hosted-page redirect button, data loader) you can drop
180
+ into a Medusa Next.js starter. See
181
+ [`docs/storefront-integration.md`](./docs/storefront-integration.md).
182
+
183
+ ## Documentation
184
+
185
+ | Doc | What's in it |
186
+ | --- | --- |
187
+ | [Getting started](./docs/getting-started.md) | Install, configure, first payment |
188
+ | [Configuration](./docs/configuration.md) | Env vars, options, admin settings |
189
+ | [Storefront integration](./docs/storefront-integration.md) | Wiring the checkout UI |
190
+ | [Architecture](./docs/architecture.md) | Modules, data flow, design decisions |
191
+ | [API reference](./docs/api-reference.md) | Store, admin, and callback routes |
192
+
193
+ ## License
194
+
195
+ [MIT](./LICENSE)
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Public entry point for the Paytree Medusa payment package.
3
+ *
4
+ * The compiled package ships two backend modules — the payment PROVIDER and a
5
+ * small DATA module that owns the settings + audit-log tables — plus the shared
6
+ * helpers used by the copy-in API routes and admin pages (see `integration/`).
7
+ */
8
+ /**
9
+ * Default export: registers the Paytree payment provider with the Payment
10
+ * module. Reference this from `medusa-config` under the payment module's
11
+ * `providers` array (see the README).
12
+ */
13
+ declare const _default: import("@medusajs/types").ModuleProviderExports;
14
+ export default _default;
15
+ export { default as PaytreePaymentProviderService, PaytreePaymentProviderService as PaytreeProvider, } from "./modules/paytree-payment/service";
16
+ export { default as PaytreeModule, PAYTREE_MODULE, PaytreeService, } from "./modules/paytree";
17
+ export { PAYTREE_PROVIDER_IDENTIFIER, PaytreeStatus, AuditEvent, DEFAULT_BASE_URL, } from "./modules/paytree-payment/lib/constants";
18
+ export type { PaytreeStatusValue, AuditEventType, } from "./modules/paytree-payment/lib/constants";
19
+ export { PAYTREE_METHOD_DEFS, resolveMethods, normalizeMethods, } from "./modules/paytree-payment/lib/methods";
20
+ export type { StoredMethodConfig, ResolvedMethodConfig, PaytreeMethodId, } from "./modules/paytree-payment/lib/methods";
21
+ export { PaytreeClient } from "./modules/paytree-payment/lib/client";
22
+ export type { PaytreeClientConfig } from "./modules/paytree-payment/lib/client";
23
+ export { PaytreeLogger } from "./modules/paytree-payment/lib/logger";
24
+ export type { Correlation } from "./modules/paytree-payment/lib/logger";
25
+ export { toSessionStatus, callbackOutcome, } from "./modules/paytree-payment/lib/status-map";
26
+ export type { CallbackOutcome } from "./modules/paytree-payment/lib/status-map";
27
+ export { toPaytreeAmount, fromPaytreeAmount, newlyRefundedAmount, } from "./modules/paytree-payment/lib/amount";
28
+ export type { PaytreeProviderOptions, PaytreeMethod, PaytreeSessionData, PaytreeOrderItem, PaytreePaymentIntent, } from "./modules/paytree-payment/lib/types";
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /**
3
+ * Public entry point for the Paytree Medusa payment package.
4
+ *
5
+ * The compiled package ships two backend modules — the payment PROVIDER and a
6
+ * small DATA module that owns the settings + audit-log tables — plus the shared
7
+ * helpers used by the copy-in API routes and admin pages (see `integration/`).
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.newlyRefundedAmount = exports.fromPaytreeAmount = exports.toPaytreeAmount = exports.callbackOutcome = exports.toSessionStatus = exports.PaytreeLogger = exports.PaytreeClient = exports.normalizeMethods = exports.resolveMethods = exports.PAYTREE_METHOD_DEFS = exports.DEFAULT_BASE_URL = exports.AuditEvent = exports.PaytreeStatus = exports.PAYTREE_PROVIDER_IDENTIFIER = exports.PaytreeService = exports.PAYTREE_MODULE = exports.PaytreeModule = exports.PaytreeProvider = exports.PaytreePaymentProviderService = void 0;
14
+ const utils_1 = require("@medusajs/framework/utils");
15
+ const service_1 = __importDefault(require("./modules/paytree-payment/service"));
16
+ /**
17
+ * Default export: registers the Paytree payment provider with the Payment
18
+ * module. Reference this from `medusa-config` under the payment module's
19
+ * `providers` array (see the README).
20
+ */
21
+ exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.PAYMENT, {
22
+ services: [service_1.default],
23
+ });
24
+ // Payment provider service.
25
+ var service_2 = require("./modules/paytree-payment/service");
26
+ Object.defineProperty(exports, "PaytreePaymentProviderService", { enumerable: true, get: function () { return __importDefault(service_2).default; } });
27
+ Object.defineProperty(exports, "PaytreeProvider", { enumerable: true, get: function () { return service_2.PaytreePaymentProviderService; } });
28
+ // Data module (settings + audit-log tables; resolvable from routes/subscribers).
29
+ var paytree_1 = require("./modules/paytree");
30
+ Object.defineProperty(exports, "PaytreeModule", { enumerable: true, get: function () { return __importDefault(paytree_1).default; } });
31
+ Object.defineProperty(exports, "PAYTREE_MODULE", { enumerable: true, get: function () { return paytree_1.PAYTREE_MODULE; } });
32
+ Object.defineProperty(exports, "PaytreeService", { enumerable: true, get: function () { return paytree_1.PaytreeService; } });
33
+ // Constants.
34
+ var constants_1 = require("./modules/paytree-payment/lib/constants");
35
+ Object.defineProperty(exports, "PAYTREE_PROVIDER_IDENTIFIER", { enumerable: true, get: function () { return constants_1.PAYTREE_PROVIDER_IDENTIFIER; } });
36
+ Object.defineProperty(exports, "PaytreeStatus", { enumerable: true, get: function () { return constants_1.PaytreeStatus; } });
37
+ Object.defineProperty(exports, "AuditEvent", { enumerable: true, get: function () { return constants_1.AuditEvent; } });
38
+ Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return constants_1.DEFAULT_BASE_URL; } });
39
+ // Method catalog + resolution helpers (used by the admin + store routes).
40
+ var methods_1 = require("./modules/paytree-payment/lib/methods");
41
+ Object.defineProperty(exports, "PAYTREE_METHOD_DEFS", { enumerable: true, get: function () { return methods_1.PAYTREE_METHOD_DEFS; } });
42
+ Object.defineProperty(exports, "resolveMethods", { enumerable: true, get: function () { return methods_1.resolveMethods; } });
43
+ Object.defineProperty(exports, "normalizeMethods", { enumerable: true, get: function () { return methods_1.normalizeMethods; } });
44
+ // REST client, logging, amount + status helpers (used by the callback route).
45
+ var client_1 = require("./modules/paytree-payment/lib/client");
46
+ Object.defineProperty(exports, "PaytreeClient", { enumerable: true, get: function () { return client_1.PaytreeClient; } });
47
+ var logger_1 = require("./modules/paytree-payment/lib/logger");
48
+ Object.defineProperty(exports, "PaytreeLogger", { enumerable: true, get: function () { return logger_1.PaytreeLogger; } });
49
+ var status_map_1 = require("./modules/paytree-payment/lib/status-map");
50
+ Object.defineProperty(exports, "toSessionStatus", { enumerable: true, get: function () { return status_map_1.toSessionStatus; } });
51
+ Object.defineProperty(exports, "callbackOutcome", { enumerable: true, get: function () { return status_map_1.callbackOutcome; } });
52
+ var amount_1 = require("./modules/paytree-payment/lib/amount");
53
+ Object.defineProperty(exports, "toPaytreeAmount", { enumerable: true, get: function () { return amount_1.toPaytreeAmount; } });
54
+ Object.defineProperty(exports, "fromPaytreeAmount", { enumerable: true, get: function () { return amount_1.fromPaytreeAmount; } });
55
+ Object.defineProperty(exports, "newlyRefundedAmount", { enumerable: true, get: function () { return amount_1.newlyRefundedAmount; } });
@@ -0,0 +1,36 @@
1
+ import PaytreeService from "./service";
2
+ export declare const PAYTREE_MODULE = "paytree";
3
+ declare const _default: import("@medusajs/types").ModuleExports<typeof PaytreeService> & {
4
+ linkable: {
5
+ readonly paytreeSetting: {
6
+ id: {
7
+ serviceName: "paytree";
8
+ field: "paytreeSetting";
9
+ linkable: "paytree_setting_id";
10
+ primaryKey: "id";
11
+ };
12
+ toJSON: () => {
13
+ serviceName: "paytree";
14
+ field: "paytreeSetting";
15
+ linkable: "paytree_setting_id";
16
+ primaryKey: "id";
17
+ };
18
+ };
19
+ readonly paytreeEventLog: {
20
+ id: {
21
+ serviceName: "paytree";
22
+ field: "paytreeEventLog";
23
+ linkable: "paytree_event_log_id";
24
+ primaryKey: "id";
25
+ };
26
+ toJSON: () => {
27
+ serviceName: "paytree";
28
+ field: "paytreeEventLog";
29
+ linkable: "paytree_event_log_id";
30
+ primaryKey: "id";
31
+ };
32
+ };
33
+ };
34
+ };
35
+ export default _default;
36
+ export { PaytreeService };
@@ -0,0 +1,13 @@
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.PaytreeService = exports.PAYTREE_MODULE = void 0;
7
+ const utils_1 = require("@medusajs/framework/utils");
8
+ const service_1 = __importDefault(require("./service"));
9
+ exports.PaytreeService = service_1.default;
10
+ exports.PAYTREE_MODULE = "paytree";
11
+ exports.default = (0, utils_1.Module)(exports.PAYTREE_MODULE, {
12
+ service: service_1.default,
13
+ });
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@mikro-orm/migrations";
2
+ export declare class Migration20260617000000 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20260617000000 = void 0;
4
+ const migrations_1 = require("@mikro-orm/migrations");
5
+ class Migration20260617000000 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`
8
+ CREATE TABLE IF NOT EXISTS "paytree_setting" (
9
+ "id" TEXT NOT NULL,
10
+ "base_url" TEXT NOT NULL,
11
+ "log_request" BOOLEAN NOT NULL DEFAULT FALSE,
12
+ "log_response" BOOLEAN NOT NULL DEFAULT FALSE,
13
+ "created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
14
+ "updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
15
+ "deleted_at" TIMESTAMPTZ NULL,
16
+ CONSTRAINT "paytree_setting_pkey" PRIMARY KEY ("id")
17
+ );
18
+ `);
19
+ this.addSql(`
20
+ CREATE TABLE IF NOT EXISTS "paytree_event_log" (
21
+ "id" TEXT NOT NULL,
22
+ "event" TEXT NOT NULL,
23
+ "session_id" TEXT NULL,
24
+ "paytree_id" TEXT NULL,
25
+ "status" TEXT NULL,
26
+ "amount" TEXT NULL,
27
+ "currency" TEXT NULL,
28
+ "detail" JSONB NULL,
29
+ "error" TEXT NULL,
30
+ "created_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
31
+ "updated_at" TIMESTAMPTZ NOT NULL DEFAULT NOW(),
32
+ "deleted_at" TIMESTAMPTZ NULL,
33
+ CONSTRAINT "paytree_event_log_pkey" PRIMARY KEY ("id")
34
+ );
35
+ `);
36
+ this.addSql(`
37
+ CREATE INDEX IF NOT EXISTS "IDX_paytree_event_log_session_id"
38
+ ON "paytree_event_log" ("session_id");
39
+ `);
40
+ this.addSql(`
41
+ CREATE INDEX IF NOT EXISTS "IDX_paytree_event_log_paytree_id"
42
+ ON "paytree_event_log" ("paytree_id");
43
+ `);
44
+ this.addSql(`
45
+ CREATE INDEX IF NOT EXISTS "IDX_paytree_event_log_created_at"
46
+ ON "paytree_event_log" ("created_at");
47
+ `);
48
+ }
49
+ async down() {
50
+ this.addSql(`DROP TABLE IF EXISTS "paytree_event_log" CASCADE;`);
51
+ this.addSql(`DROP TABLE IF EXISTS "paytree_setting" CASCADE;`);
52
+ }
53
+ }
54
+ exports.Migration20260617000000 = Migration20260617000000;
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@mikro-orm/migrations";
2
+ export declare class Migration20260618000000 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20260618000000 = void 0;
4
+ const migrations_1 = require("@mikro-orm/migrations");
5
+ class Migration20260618000000 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`
8
+ ALTER TABLE "paytree_setting"
9
+ ADD COLUMN IF NOT EXISTS "methods" JSONB NULL;
10
+ `);
11
+ }
12
+ async down() {
13
+ this.addSql(`
14
+ ALTER TABLE "paytree_setting"
15
+ DROP COLUMN IF EXISTS "methods";
16
+ `);
17
+ }
18
+ }
19
+ exports.Migration20260618000000 = Migration20260618000000;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Append-only audit trail of payment events, for traceability. Written by the
3
+ * provider, the callback route, and the subscriber; read by the admin UI.
4
+ *
5
+ * Every payload stored in `detail` is redacted before write, so this table
6
+ * never holds secrets or raw PII.
7
+ */
8
+ export declare const PaytreeEventLog: import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
9
+ id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
10
+ /** One of the AuditEvent values (initiate_payment, capture_payment, ...). */
11
+ event: import("@medusajs/framework/utils").TextProperty;
12
+ /** Medusa payment session id (our transaction_ref). */
13
+ session_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
14
+ /** Paytree payment intent id. */
15
+ paytree_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
16
+ /** Paytree status at the time of the event. */
17
+ status: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
18
+ amount: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
19
+ currency: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
20
+ /** Redacted JSON blob with event-specific detail. */
21
+ detail: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
22
+ /** Error message, when the event records a failure. */
23
+ error: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
24
+ }>, "paytree_event_log">;
25
+ export default PaytreeEventLog;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaytreeEventLog = void 0;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ /**
6
+ * Append-only audit trail of payment events, for traceability. Written by the
7
+ * provider, the callback route, and the subscriber; read by the admin UI.
8
+ *
9
+ * Every payload stored in `detail` is redacted before write, so this table
10
+ * never holds secrets or raw PII.
11
+ */
12
+ exports.PaytreeEventLog = utils_1.model.define("paytree_event_log", {
13
+ id: utils_1.model.id().primaryKey(),
14
+ /** One of the AuditEvent values (initiate_payment, capture_payment, ...). */
15
+ event: utils_1.model.text(),
16
+ /** Medusa payment session id (our transaction_ref). */
17
+ session_id: utils_1.model.text().nullable(),
18
+ /** Paytree payment intent id. */
19
+ paytree_id: utils_1.model.text().nullable(),
20
+ /** Paytree status at the time of the event. */
21
+ status: utils_1.model.text().nullable(),
22
+ amount: utils_1.model.text().nullable(),
23
+ currency: utils_1.model.text().nullable(),
24
+ /** Redacted JSON blob with event-specific detail. */
25
+ detail: utils_1.model.json().nullable(),
26
+ /** Error message, when the event records a failure. */
27
+ error: utils_1.model.text().nullable(),
28
+ });
29
+ exports.default = exports.PaytreeEventLog;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Global settings for the Paytree integration, editable from the admin UI.
3
+ * Only NON-secret operational config lives here. The API key is never stored
4
+ * in the database — it comes from the PAYTREE_API_KEY environment variable.
5
+ *
6
+ * We keep a single row (id = "paytree_settings").
7
+ */
8
+ export declare const PaytreeSetting: import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
9
+ id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
10
+ /** Paytree API origin requests are sent to. */
11
+ base_url: import("@medusajs/framework/utils").TextProperty;
12
+ /** When true, outbound request bodies are logged (always redacted). */
13
+ log_request: import("@medusajs/framework/utils").BooleanProperty;
14
+ /** When true, Paytree response bodies are logged (always redacted). */
15
+ log_response: import("@medusajs/framework/utils").BooleanProperty;
16
+ /**
17
+ * Per-method config the admin curates: which Paytree methods are offered at
18
+ * checkout and an optional label override. Shape: Array<{ method, enabled,
19
+ * label? }>. Null until the admin saves; resolved against canonical defaults.
20
+ */
21
+ methods: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
22
+ }>, "paytree_setting">;
23
+ export default PaytreeSetting;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaytreeSetting = void 0;
4
+ const utils_1 = require("@medusajs/framework/utils");
5
+ /**
6
+ * Global settings for the Paytree integration, editable from the admin UI.
7
+ * Only NON-secret operational config lives here. The API key is never stored
8
+ * in the database — it comes from the PAYTREE_API_KEY environment variable.
9
+ *
10
+ * We keep a single row (id = "paytree_settings").
11
+ */
12
+ exports.PaytreeSetting = utils_1.model.define("paytree_setting", {
13
+ id: utils_1.model.id().primaryKey(),
14
+ /** Paytree API origin requests are sent to. */
15
+ base_url: utils_1.model.text(),
16
+ /** When true, outbound request bodies are logged (always redacted). */
17
+ log_request: utils_1.model.boolean().default(false),
18
+ /** When true, Paytree response bodies are logged (always redacted). */
19
+ log_response: utils_1.model.boolean().default(false),
20
+ /**
21
+ * Per-method config the admin curates: which Paytree methods are offered at
22
+ * checkout and an optional label override. Shape: Array<{ method, enabled,
23
+ * label? }>. Null until the admin saves; resolved against canonical defaults.
24
+ */
25
+ methods: utils_1.model.json().nullable(),
26
+ });
27
+ exports.default = exports.PaytreeSetting;
@@ -0,0 +1,60 @@
1
+ declare const PaytreeService_base: import("@medusajs/framework/utils").MedusaServiceReturnType<import("@medusajs/framework/utils").ModelConfigurationsToConfigTemplate<{
2
+ readonly PaytreeSetting: import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
3
+ id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
4
+ base_url: import("@medusajs/framework/utils").TextProperty;
5
+ log_request: import("@medusajs/framework/utils").BooleanProperty;
6
+ log_response: import("@medusajs/framework/utils").BooleanProperty;
7
+ methods: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
8
+ }>, "paytree_setting">;
9
+ readonly PaytreeEventLog: import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
10
+ id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
11
+ event: import("@medusajs/framework/utils").TextProperty;
12
+ session_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
13
+ paytree_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
14
+ status: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
15
+ amount: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
16
+ currency: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
17
+ detail: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
18
+ error: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
19
+ }>, "paytree_event_log">;
20
+ }>>;
21
+ /**
22
+ * Service for the `paytree` module. Resolvable from app-level API routes and
23
+ * subscribers (not from the isolated payment provider — that path reads the
24
+ * table directly). Exposes settings get/upsert and audit-log queries used by
25
+ * the admin UI.
26
+ */
27
+ declare class PaytreeService extends PaytreeService_base {
28
+ /** Return the single settings row, creating defaults if absent. */
29
+ getSettings(defaults: {
30
+ base_url: string;
31
+ log_request?: boolean;
32
+ log_response?: boolean;
33
+ }): Promise<{
34
+ id: string;
35
+ base_url: string;
36
+ log_request: boolean;
37
+ log_response: boolean;
38
+ methods: Record<string, unknown> | null;
39
+ created_at: Date;
40
+ updated_at: Date;
41
+ deleted_at: Date | null;
42
+ }>;
43
+ /** Upsert the single settings row. */
44
+ upsertSettings(values: {
45
+ base_url: string;
46
+ log_request: boolean;
47
+ log_response: boolean;
48
+ methods?: unknown;
49
+ }): Promise<{
50
+ id: string;
51
+ base_url: string;
52
+ log_request: boolean;
53
+ log_response: boolean;
54
+ methods: Record<string, unknown> | null;
55
+ created_at: Date;
56
+ updated_at: Date;
57
+ deleted_at: Date | null;
58
+ }>;
59
+ }
60
+ export default PaytreeService;