@financedistrict/medusa-plugin-prism-payment 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.
- package/.medusa/server/src/admin/index.js +22 -0
- package/.medusa/server/src/admin/index.mjs +23 -0
- package/.medusa/server/src/index.d.ts +57 -0
- package/.medusa/server/src/index.d.ts.map +1 -0
- package/.medusa/server/src/index.js +71 -0
- package/.medusa/server/src/index.js.map +1 -0
- package/.medusa/server/src/lib/prism-client.d.ts +85 -0
- package/.medusa/server/src/lib/prism-client.d.ts.map +1 -0
- package/.medusa/server/src/lib/prism-client.js +107 -0
- package/.medusa/server/src/lib/prism-client.js.map +1 -0
- package/.medusa/server/src/modules/prism-payment/index.d.ts +3 -0
- package/.medusa/server/src/modules/prism-payment/index.d.ts.map +1 -0
- package/.medusa/server/src/modules/prism-payment/index.js +11 -0
- package/.medusa/server/src/modules/prism-payment/index.js.map +1 -0
- package/.medusa/server/src/modules/prism-payment/service.d.ts +90 -0
- package/.medusa/server/src/modules/prism-payment/service.d.ts.map +1 -0
- package/.medusa/server/src/modules/prism-payment/service.js +344 -0
- package/.medusa/server/src/modules/prism-payment/service.js.map +1 -0
- package/.medusa/server/src/modules/prism-payment/types.d.ts +111 -0
- package/.medusa/server/src/modules/prism-payment/types.d.ts.map +1 -0
- package/.medusa/server/src/modules/prism-payment/types.js +39 -0
- package/.medusa/server/src/modules/prism-payment/types.js.map +1 -0
- package/.medusa/server/src/modules/prism-payment-handler/index.d.ts +7 -0
- package/.medusa/server/src/modules/prism-payment-handler/index.d.ts.map +1 -0
- package/.medusa/server/src/modules/prism-payment-handler/index.js +13 -0
- package/.medusa/server/src/modules/prism-payment-handler/index.js.map +1 -0
- package/.medusa/server/src/modules/prism-payment-handler/service.d.ts +40 -0
- package/.medusa/server/src/modules/prism-payment-handler/service.d.ts.map +1 -0
- package/.medusa/server/src/modules/prism-payment-handler/service.js +184 -0
- package/.medusa/server/src/modules/prism-payment-handler/service.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +262 -0
- package/package.json +58 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const widgetModule = { widgets: [] };
|
|
3
|
+
const routeModule = {
|
|
4
|
+
routes: []
|
|
5
|
+
};
|
|
6
|
+
const menuItemModule = {
|
|
7
|
+
menuItems: []
|
|
8
|
+
};
|
|
9
|
+
const formModule = { customFields: {} };
|
|
10
|
+
const displayModule = {
|
|
11
|
+
displays: {}
|
|
12
|
+
};
|
|
13
|
+
const i18nModule = { resources: {} };
|
|
14
|
+
const plugin = {
|
|
15
|
+
widgetModule,
|
|
16
|
+
routeModule,
|
|
17
|
+
menuItemModule,
|
|
18
|
+
formModule,
|
|
19
|
+
displayModule,
|
|
20
|
+
i18nModule
|
|
21
|
+
};
|
|
22
|
+
module.exports = plugin;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const widgetModule = { widgets: [] };
|
|
2
|
+
const routeModule = {
|
|
3
|
+
routes: []
|
|
4
|
+
};
|
|
5
|
+
const menuItemModule = {
|
|
6
|
+
menuItems: []
|
|
7
|
+
};
|
|
8
|
+
const formModule = { customFields: {} };
|
|
9
|
+
const displayModule = {
|
|
10
|
+
displays: {}
|
|
11
|
+
};
|
|
12
|
+
const i18nModule = { resources: {} };
|
|
13
|
+
const plugin = {
|
|
14
|
+
widgetModule,
|
|
15
|
+
routeModule,
|
|
16
|
+
menuItemModule,
|
|
17
|
+
formModule,
|
|
18
|
+
displayModule,
|
|
19
|
+
i18nModule
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
plugin as default
|
|
23
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @financedistrict/medusa-plugin-prism-payment
|
|
3
|
+
*
|
|
4
|
+
* Prism x402 stablecoin payment handler for Medusa agentic commerce.
|
|
5
|
+
*
|
|
6
|
+
* Provides two Medusa modules:
|
|
7
|
+
* 1. prismPaymentHandler — PaymentHandlerAdapter for UCP/ACP discovery + checkout preparation
|
|
8
|
+
* 2. prism (payment provider) — Medusa AbstractPaymentProvider for authorize/capture/settle
|
|
9
|
+
*
|
|
10
|
+
* Usage in medusa-config.ts:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* modules: [
|
|
15
|
+
* // The payment handler adapter (discovery + checkout-prepare)
|
|
16
|
+
* {
|
|
17
|
+
* resolve: "@financedistrict/medusa-plugin-prism-payment/modules/prism-payment-handler",
|
|
18
|
+
* options: {
|
|
19
|
+
* api_url: process.env.PRISM_API_URL || "https://prism-gw.fd.xyz",
|
|
20
|
+
* api_key: process.env.PRISM_API_KEY,
|
|
21
|
+
* },
|
|
22
|
+
* },
|
|
23
|
+
* // The Medusa payment provider (authorize/capture/settle)
|
|
24
|
+
* {
|
|
25
|
+
* resolve: "@medusajs/medusa/payment",
|
|
26
|
+
* options: {
|
|
27
|
+
* providers: [{
|
|
28
|
+
* resolve: "@financedistrict/medusa-plugin-prism-payment/modules/prism-payment",
|
|
29
|
+
* id: "prism",
|
|
30
|
+
* options: {
|
|
31
|
+
* api_url: process.env.PRISM_API_URL || "https://prism-gw.fd.xyz",
|
|
32
|
+
* api_key: process.env.PRISM_API_KEY,
|
|
33
|
+
* },
|
|
34
|
+
* }],
|
|
35
|
+
* },
|
|
36
|
+
* },
|
|
37
|
+
* // Reference in the agentic commerce plugin
|
|
38
|
+
* {
|
|
39
|
+
* resolve: "@financedistrict/medusa-plugin-agentic-commerce/modules/agentic-commerce",
|
|
40
|
+
* options: {
|
|
41
|
+
* payment_handler_adapters: ["prismPaymentHandler"],
|
|
42
|
+
* // ...other options
|
|
43
|
+
* },
|
|
44
|
+
* },
|
|
45
|
+
* ],
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export { default as PrismPaymentHandlerModule, PRISM_PAYMENT_HANDLER_MODULE } from "./modules/prism-payment-handler";
|
|
50
|
+
export { default as PrismPaymentHandlerAdapter, PRISM_CHECKOUT_CONFIG_KEY } from "./modules/prism-payment-handler/service";
|
|
51
|
+
export type { PrismPaymentHandlerOptions } from "./modules/prism-payment-handler/service";
|
|
52
|
+
export { default as PrismPaymentProvider } from "./modules/prism-payment";
|
|
53
|
+
export { PrismClient } from "./lib/prism-client";
|
|
54
|
+
export type { PrismClientOptions, CheckoutPrepareInput, CheckoutPrepareResult, X402AcceptEntry } from "./lib/prism-client";
|
|
55
|
+
export type { PrismPaymentConfig, X402PaymentAuthorization, Eip3009Authorization, PrismSettleResponse, PrismVerifyResponse, } from "./modules/prism-payment/types";
|
|
56
|
+
export { PRISM_HANDLER_ID, PRISM_INSTRUMENT_SCHEMA } from "./modules/prism-payment/types";
|
|
57
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAGH,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAA;AACpH,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAA;AAC1H,YAAY,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AAGzF,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAGzE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAG1H,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @financedistrict/medusa-plugin-prism-payment
|
|
4
|
+
*
|
|
5
|
+
* Prism x402 stablecoin payment handler for Medusa agentic commerce.
|
|
6
|
+
*
|
|
7
|
+
* Provides two Medusa modules:
|
|
8
|
+
* 1. prismPaymentHandler — PaymentHandlerAdapter for UCP/ACP discovery + checkout preparation
|
|
9
|
+
* 2. prism (payment provider) — Medusa AbstractPaymentProvider for authorize/capture/settle
|
|
10
|
+
*
|
|
11
|
+
* Usage in medusa-config.ts:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* modules: [
|
|
16
|
+
* // The payment handler adapter (discovery + checkout-prepare)
|
|
17
|
+
* {
|
|
18
|
+
* resolve: "@financedistrict/medusa-plugin-prism-payment/modules/prism-payment-handler",
|
|
19
|
+
* options: {
|
|
20
|
+
* api_url: process.env.PRISM_API_URL || "https://prism-gw.fd.xyz",
|
|
21
|
+
* api_key: process.env.PRISM_API_KEY,
|
|
22
|
+
* },
|
|
23
|
+
* },
|
|
24
|
+
* // The Medusa payment provider (authorize/capture/settle)
|
|
25
|
+
* {
|
|
26
|
+
* resolve: "@medusajs/medusa/payment",
|
|
27
|
+
* options: {
|
|
28
|
+
* providers: [{
|
|
29
|
+
* resolve: "@financedistrict/medusa-plugin-prism-payment/modules/prism-payment",
|
|
30
|
+
* id: "prism",
|
|
31
|
+
* options: {
|
|
32
|
+
* api_url: process.env.PRISM_API_URL || "https://prism-gw.fd.xyz",
|
|
33
|
+
* api_key: process.env.PRISM_API_KEY,
|
|
34
|
+
* },
|
|
35
|
+
* }],
|
|
36
|
+
* },
|
|
37
|
+
* },
|
|
38
|
+
* // Reference in the agentic commerce plugin
|
|
39
|
+
* {
|
|
40
|
+
* resolve: "@financedistrict/medusa-plugin-agentic-commerce/modules/agentic-commerce",
|
|
41
|
+
* options: {
|
|
42
|
+
* payment_handler_adapters: ["prismPaymentHandler"],
|
|
43
|
+
* // ...other options
|
|
44
|
+
* },
|
|
45
|
+
* },
|
|
46
|
+
* ],
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
51
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.PRISM_INSTRUMENT_SCHEMA = exports.PRISM_HANDLER_ID = exports.PrismClient = exports.PrismPaymentProvider = exports.PRISM_CHECKOUT_CONFIG_KEY = exports.PrismPaymentHandlerAdapter = exports.PRISM_PAYMENT_HANDLER_MODULE = exports.PrismPaymentHandlerModule = void 0;
|
|
55
|
+
// Payment Handler Adapter module
|
|
56
|
+
var prism_payment_handler_1 = require("./modules/prism-payment-handler");
|
|
57
|
+
Object.defineProperty(exports, "PrismPaymentHandlerModule", { enumerable: true, get: function () { return __importDefault(prism_payment_handler_1).default; } });
|
|
58
|
+
Object.defineProperty(exports, "PRISM_PAYMENT_HANDLER_MODULE", { enumerable: true, get: function () { return prism_payment_handler_1.PRISM_PAYMENT_HANDLER_MODULE; } });
|
|
59
|
+
var service_1 = require("./modules/prism-payment-handler/service");
|
|
60
|
+
Object.defineProperty(exports, "PrismPaymentHandlerAdapter", { enumerable: true, get: function () { return __importDefault(service_1).default; } });
|
|
61
|
+
Object.defineProperty(exports, "PRISM_CHECKOUT_CONFIG_KEY", { enumerable: true, get: function () { return service_1.PRISM_CHECKOUT_CONFIG_KEY; } });
|
|
62
|
+
// Payment Provider module
|
|
63
|
+
var prism_payment_1 = require("./modules/prism-payment");
|
|
64
|
+
Object.defineProperty(exports, "PrismPaymentProvider", { enumerable: true, get: function () { return __importDefault(prism_payment_1).default; } });
|
|
65
|
+
// Prism Client
|
|
66
|
+
var prism_client_1 = require("./lib/prism-client");
|
|
67
|
+
Object.defineProperty(exports, "PrismClient", { enumerable: true, get: function () { return prism_client_1.PrismClient; } });
|
|
68
|
+
var types_1 = require("./modules/prism-payment/types");
|
|
69
|
+
Object.defineProperty(exports, "PRISM_HANDLER_ID", { enumerable: true, get: function () { return types_1.PRISM_HANDLER_ID; } });
|
|
70
|
+
Object.defineProperty(exports, "PRISM_INSTRUMENT_SCHEMA", { enumerable: true, get: function () { return types_1.PRISM_INSTRUMENT_SCHEMA; } });
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;;;;;;AAEH,iCAAiC;AACjC,yEAAoH;AAA3G,mJAAA,OAAO,OAA6B;AAAE,qIAAA,4BAA4B,OAAA;AAC3E,mEAA0H;AAAjH,sIAAA,OAAO,OAA8B;AAAE,oHAAA,yBAAyB,OAAA;AAGzE,0BAA0B;AAC1B,yDAAyE;AAAhE,sIAAA,OAAO,OAAwB;AAExC,eAAe;AACf,mDAAgD;AAAvC,2GAAA,WAAW,OAAA;AAWpB,uDAAyF;AAAhF,yGAAA,gBAAgB,OAAA;AAAE,gHAAA,uBAAuB,OAAA"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prism Gateway API Client
|
|
3
|
+
*
|
|
4
|
+
* Handles the merchant-side Prism integration:
|
|
5
|
+
* - checkout-prepare: Get x402 payment requirements for a checkout session
|
|
6
|
+
* - payment-profile: Fetch the handler definition (for dynamic discovery)
|
|
7
|
+
*
|
|
8
|
+
* Settlement is handled by the Prism payment provider module directly.
|
|
9
|
+
*
|
|
10
|
+
* Configuration via plugin options:
|
|
11
|
+
* api_url — Prism Gateway base URL (default: https://prism-gw.fd.xyz)
|
|
12
|
+
* api_key — Merchant API key from Prism Console
|
|
13
|
+
*/
|
|
14
|
+
export type CheckoutPrepareInput = {
|
|
15
|
+
/** Amount in minor units (cents). Will be converted to string for Prism. */
|
|
16
|
+
amount: number;
|
|
17
|
+
/** ISO 4217 currency code (e.g., "USD", "EUR") */
|
|
18
|
+
currency: string;
|
|
19
|
+
/** Unique URL for this checkout session (used as x402 resource binding) */
|
|
20
|
+
resourceUrl: string;
|
|
21
|
+
/** Human-readable description of what's being purchased */
|
|
22
|
+
resourceDescription: string;
|
|
23
|
+
};
|
|
24
|
+
export type CheckoutPrepareResult = {
|
|
25
|
+
/** Handler instance config with resolved x402 requirements */
|
|
26
|
+
id: string;
|
|
27
|
+
version: string;
|
|
28
|
+
config: {
|
|
29
|
+
x402Version: number;
|
|
30
|
+
resource: {
|
|
31
|
+
url: string;
|
|
32
|
+
description: string;
|
|
33
|
+
};
|
|
34
|
+
accepts: X402AcceptEntry[];
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export type X402AcceptEntry = {
|
|
38
|
+
/** Payment scheme (e.g., "exact" for EIP-3009) */
|
|
39
|
+
scheme: string;
|
|
40
|
+
/** Chain identifier in CAIP-2 format (e.g., "eip155:8453" for Base) */
|
|
41
|
+
network: string;
|
|
42
|
+
/** Amount in token base units as string (e.g., "120000000" for 120 USDC) */
|
|
43
|
+
amount: string;
|
|
44
|
+
/** Token contract address */
|
|
45
|
+
asset: string;
|
|
46
|
+
/** Merchant settlement address */
|
|
47
|
+
payTo: string;
|
|
48
|
+
/** Maximum time for authorization validity */
|
|
49
|
+
maxTimeoutSeconds: number;
|
|
50
|
+
/** Additional metadata (token name, version, etc.) */
|
|
51
|
+
extra?: Record<string, unknown>;
|
|
52
|
+
};
|
|
53
|
+
export type PaymentProfileResult = {
|
|
54
|
+
/** The handler declaration to merge into .well-known/ucp */
|
|
55
|
+
[namespace: string]: unknown[];
|
|
56
|
+
};
|
|
57
|
+
export type PrismClientOptions = {
|
|
58
|
+
apiUrl?: string;
|
|
59
|
+
apiKey?: string;
|
|
60
|
+
};
|
|
61
|
+
export declare class PrismClient {
|
|
62
|
+
private apiUrl;
|
|
63
|
+
private apiKey;
|
|
64
|
+
constructor(options?: PrismClientOptions);
|
|
65
|
+
/**
|
|
66
|
+
* Prepare checkout via Prism.
|
|
67
|
+
*
|
|
68
|
+
* Called when a checkout session is created or updated (total changes).
|
|
69
|
+
* Returns the x402 payment requirements that the agent wallet needs
|
|
70
|
+
* to construct a valid EIP-3009 authorization.
|
|
71
|
+
*/
|
|
72
|
+
checkoutPrepare(input: CheckoutPrepareInput): Promise<CheckoutPrepareResult>;
|
|
73
|
+
/**
|
|
74
|
+
* Fetch handler definition from Prism.
|
|
75
|
+
*
|
|
76
|
+
* Called to get the current handler declaration for .well-known/ucp.
|
|
77
|
+
* Can be cached (handler definitions don't change per checkout).
|
|
78
|
+
*/
|
|
79
|
+
fetchPaymentProfile(): Promise<PaymentProfileResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Fallback config when Prism API key is not configured.
|
|
82
|
+
*/
|
|
83
|
+
private emptyConfig;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=prism-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prism-client.d.ts","sourceRoot":"","sources":["../../../../src/lib/prism-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,MAAM,MAAM,oBAAoB,GAAG;IACjC,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAA;IACd,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAA;IAChB,2EAA2E;IAC3E,WAAW,EAAE,MAAM,CAAA;IACnB,2DAA2D;IAC3D,mBAAmB,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,8DAA8D;IAC9D,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE;QACN,WAAW,EAAE,MAAM,C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checkout-prepare: Get x402 payment requirements for a checkout session
|
|
7
|
+
* - payment-profile: Fetch the handler definition (for dynamic discovery)
|
|
8
|
+
*
|
|
9
|
+
* Settlement is handled by the Prism payment provider module directly.
|
|
10
|
+
*
|
|
11
|
+
* Configuration via plugin options:
|
|
12
|
+
* api_url — Prism Gateway base URL (default: https://prism-gw.fd.xyz)
|
|
13
|
+
* api_key — Merchant API key from Prism Console
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.PrismClient = void 0;
|
|
17
|
+
class PrismClient {
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
this.apiUrl = options.apiUrl || process.env.PRISM_API_URL || "https://prism-gw.fd.xyz";
|
|
20
|
+
this.apiKey = options.apiKey || process.env.PRISM_API_KEY || "";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Prepare checkout via Prism.
|
|
24
|
+
*
|
|
25
|
+
* Called when a checkout session is created or updated (total changes).
|
|
26
|
+
* Returns the x402 payment requirements that the agent wallet needs
|
|
27
|
+
* to construct a valid EIP-3009 authorization.
|
|
28
|
+
*/
|
|
29
|
+
async checkoutPrepare(input) {
|
|
30
|
+
if (!this.apiKey) {
|
|
31
|
+
console.warn("[prism-client] No PRISM_API_KEY configured, returning empty payment config");
|
|
32
|
+
return this.emptyConfig(input);
|
|
33
|
+
}
|
|
34
|
+
const response = await fetch(`${this.apiUrl}/api/v2/merchant/checkout-prepare`, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
"X-API-Key": this.apiKey,
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
amount: String(input.amount),
|
|
42
|
+
currency: input.currency.toUpperCase(),
|
|
43
|
+
resource: {
|
|
44
|
+
url: input.resourceUrl,
|
|
45
|
+
description: input.resourceDescription,
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
});
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
51
|
+
console.error(`[prism-client] checkout-prepare failed (${response.status}): ${errorText}`);
|
|
52
|
+
throw new Error(`Prism checkout-prepare failed: ${response.status}`);
|
|
53
|
+
}
|
|
54
|
+
const data = await response.json();
|
|
55
|
+
// Prism returns a namespace-wrapped response: { "xyz.fd.prism_payment": [{ id, version, config }] }
|
|
56
|
+
const PRISM_NAMESPACE = "xyz.fd.prism_payment";
|
|
57
|
+
const handlers = (data[PRISM_NAMESPACE] ?? Object.values(data)[0]);
|
|
58
|
+
if (!handlers || !Array.isArray(handlers) || handlers.length === 0) {
|
|
59
|
+
console.warn(`[prism-client] checkout-prepare returned no handlers`);
|
|
60
|
+
return this.emptyConfig(input);
|
|
61
|
+
}
|
|
62
|
+
return handlers[0];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Fetch handler definition from Prism.
|
|
66
|
+
*
|
|
67
|
+
* Called to get the current handler declaration for .well-known/ucp.
|
|
68
|
+
* Can be cached (handler definitions don't change per checkout).
|
|
69
|
+
*/
|
|
70
|
+
async fetchPaymentProfile() {
|
|
71
|
+
if (!this.apiKey) {
|
|
72
|
+
console.warn("[prism-client] No PRISM_API_KEY configured, returning empty profile");
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
const response = await fetch(`${this.apiUrl}/api/v2/merchant/payment-profile`, {
|
|
76
|
+
method: "GET",
|
|
77
|
+
headers: {
|
|
78
|
+
"X-API-Key": this.apiKey,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
83
|
+
console.error(`[prism-client] payment-profile failed (${response.status}): ${errorText}`);
|
|
84
|
+
throw new Error(`Prism payment-profile failed: ${response.status}`);
|
|
85
|
+
}
|
|
86
|
+
return response.json();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Fallback config when Prism API key is not configured.
|
|
90
|
+
*/
|
|
91
|
+
emptyConfig(input) {
|
|
92
|
+
return {
|
|
93
|
+
id: "prism_default",
|
|
94
|
+
version: "2026-01-23",
|
|
95
|
+
config: {
|
|
96
|
+
x402Version: 2,
|
|
97
|
+
resource: {
|
|
98
|
+
url: input.resourceUrl,
|
|
99
|
+
description: input.resourceDescription,
|
|
100
|
+
},
|
|
101
|
+
accepts: [],
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.PrismClient = PrismClient;
|
|
107
|
+
//# sourceMappingURL=prism-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prism-client.js","sourceRoot":"","sources":["../../../../src/lib/prism-client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AA8DH,MAAa,WAAW;IAItB,YAAY,UAA8B,EAAE;QAC1C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,yBAAyB,CAAA;QACtF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAA;IACjE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CAAC,KAA2B;QAC/C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,4EAA4E,CAAC,CAAA;YAC1F,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QAChC,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,mCAAmC,EAAE;YAC9E,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,WAAW,EAAE,IAAI,CAAC,MAAM;aACzB;YACD,IAAI,EAAE,IAAI,CAAC,SAA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AAC,IAAI,CAAC,qEAAqE,CAAC,CAAA;YACnF,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,kCAAkC,EAAE;YAC7E,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,WAAW,EAAE,IAAI,CAAC,MAAM;aACzB;SACF,CAAC,CAAA;QAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,CAAA;YACpE,OAAO,CAAC,KAAK,CAAC,0CAA0C,QAAQ,CAAC,MAAM,MAAM,SAAS,EAAE,CAAC,CAAA;YACzF,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;QACrE,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAmC,CAAA;IACzD,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,KAA2B;QAC7C,OAAO;YACL,EAAE,EAAE,eAAe;YACnB,OAAO,EAAE,YAAY;YACrB,MAAM,EAAE;gBACN,WAAW,EAAE,CAAC;gBACd,QAAQ,EAAE;oBACR,GAAG,EAAE,KAAK,CAAC,WAAW;oBACtB,WAAW,EAAE,KAAK,CAAC,mBAAmB;iBACvC;gBACD,OAAO,EAAE,EAAE;aACZ;SACF,CAAA;IACH,CAAC;CACF;AAtGD,kCAsGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/prism-payment/index.ts"],"names":[],"mappings":";AAGA,wBAEE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 utils_1 = require("@medusajs/framework/utils");
|
|
7
|
+
const service_1 = __importDefault(require("./service"));
|
|
8
|
+
exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.PAYMENT, {
|
|
9
|
+
services: [service_1.default],
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/prism-payment/index.ts"],"names":[],"mappings":";;;;;AAAA,qDAAmE;AACnE,wDAAmD;AAEnD,kBAAe,IAAA,sBAAc,EAAC,eAAO,CAAC,OAAO,EAAE;IAC7C,QAAQ,EAAE,CAAC,iBAA2B,CAAC;CACxC,CAAC,CAAA"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { AbstractPaymentProvider } from "@medusajs/framework/utils";
|
|
2
|
+
import type { InitiatePaymentInput, InitiatePaymentOutput, AuthorizePaymentInput, AuthorizePaymentOutput, CapturePaymentInput, CapturePaymentOutput, CancelPaymentInput, CancelPaymentOutput, RefundPaymentInput, RefundPaymentOutput, DeletePaymentInput, DeletePaymentOutput, RetrievePaymentInput, RetrievePaymentOutput, UpdatePaymentInput, UpdatePaymentOutput, GetPaymentStatusInput, GetPaymentStatusOutput, WebhookActionResult } from "@medusajs/framework/types";
|
|
3
|
+
import type { PrismPaymentConfig } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Prism Payment Provider for Medusa v2
|
|
6
|
+
*
|
|
7
|
+
* Handles stablecoin payments via the x402 protocol:
|
|
8
|
+
* 1. Agent wallet signs EIP-3009 transferWithAuthorization (off-chain)
|
|
9
|
+
* 2. Authorization is passed through ACP/UCP checkout complete
|
|
10
|
+
* 3. This provider validates and forwards to Prism facilitator
|
|
11
|
+
* 4. Prism executes the on-chain transfer
|
|
12
|
+
*
|
|
13
|
+
* Settlement flow:
|
|
14
|
+
* initiatePayment -> stores amount/currency, returns session ID
|
|
15
|
+
* authorizePayment -> validates EIP-3009 authorization, optionally verifies with Prism
|
|
16
|
+
* capturePayment -> calls Prism /api/v2/payment/settle for on-chain execution
|
|
17
|
+
*/
|
|
18
|
+
declare class PrismPaymentProviderService extends AbstractPaymentProvider<PrismPaymentConfig> {
|
|
19
|
+
static identifier: string;
|
|
20
|
+
private apiUrl;
|
|
21
|
+
private apiKey;
|
|
22
|
+
private supportedChains;
|
|
23
|
+
private supportedAssets;
|
|
24
|
+
private autoCapture;
|
|
25
|
+
private verifyBeforeSettle;
|
|
26
|
+
constructor(cradle: Record<string, unknown>, config: PrismPaymentConfig);
|
|
27
|
+
static validateOptions(options: Record<string, unknown>): void;
|
|
28
|
+
/**
|
|
29
|
+
* Called when a payment session is created for the cart.
|
|
30
|
+
* Stores the payment amount and currency for later verification.
|
|
31
|
+
*/
|
|
32
|
+
initiatePayment(input: InitiatePaymentInput): Promise<InitiatePaymentOutput>;
|
|
33
|
+
/**
|
|
34
|
+
* Called during cart completion (order placement).
|
|
35
|
+
* Validates the EIP-3009 authorization and optionally verifies with Prism.
|
|
36
|
+
*
|
|
37
|
+
* If auto_capture is enabled, also settles the payment on-chain.
|
|
38
|
+
*/
|
|
39
|
+
authorizePayment(input: AuthorizePaymentInput): Promise<AuthorizePaymentOutput>;
|
|
40
|
+
/**
|
|
41
|
+
* Called when admin captures the payment.
|
|
42
|
+
* If auto_capture was used, this is a no-op (already settled).
|
|
43
|
+
* Otherwise, calls Prism to execute the on-chain transfer.
|
|
44
|
+
*/
|
|
45
|
+
capturePayment(input: CapturePaymentInput): Promise<CapturePaymentOutput>;
|
|
46
|
+
/**
|
|
47
|
+
* Cancel an authorized payment.
|
|
48
|
+
* For EIP-3009, the authorization simply expires (no on-chain action needed).
|
|
49
|
+
*/
|
|
50
|
+
cancelPayment(input: CancelPaymentInput): Promise<CancelPaymentOutput>;
|
|
51
|
+
/**
|
|
52
|
+
* Refund a captured payment.
|
|
53
|
+
* Requires a reverse transfer via Prism (out of scope for Phase 4).
|
|
54
|
+
*/
|
|
55
|
+
refundPayment(input: RefundPaymentInput): Promise<RefundPaymentOutput>;
|
|
56
|
+
/**
|
|
57
|
+
* Delete a payment session (customer switches payment method).
|
|
58
|
+
*/
|
|
59
|
+
deletePayment(_input: DeletePaymentInput): Promise<DeletePaymentOutput>;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieve payment data from the provider.
|
|
62
|
+
*/
|
|
63
|
+
retrievePayment(input: RetrievePaymentInput): Promise<RetrievePaymentOutput>;
|
|
64
|
+
/**
|
|
65
|
+
* Update a payment session (e.g., cart total changed).
|
|
66
|
+
*/
|
|
67
|
+
updatePayment(input: UpdatePaymentInput): Promise<UpdatePaymentOutput>;
|
|
68
|
+
/**
|
|
69
|
+
* Get current payment status from the provider.
|
|
70
|
+
*/
|
|
71
|
+
getPaymentStatus(input: GetPaymentStatusInput): Promise<GetPaymentStatusOutput>;
|
|
72
|
+
/**
|
|
73
|
+
* Handle incoming webhooks from Prism (settlement confirmations, etc.)
|
|
74
|
+
*/
|
|
75
|
+
getWebhookActionAndData(_data: {
|
|
76
|
+
data: Record<string, unknown>;
|
|
77
|
+
rawData: string | Buffer;
|
|
78
|
+
headers: Record<string, unknown>;
|
|
79
|
+
}): Promise<WebhookActionResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Verify an EIP-3009 authorization with Prism before settlement.
|
|
82
|
+
*/
|
|
83
|
+
private verifyWithPrism;
|
|
84
|
+
/**
|
|
85
|
+
* Settle (execute on-chain) an EIP-3009 authorization via Prism.
|
|
86
|
+
*/
|
|
87
|
+
private settleWithPrism;
|
|
88
|
+
}
|
|
89
|
+
export default PrismPaymentProviderService;
|
|
90
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../src/modules/prism-payment/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE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