@financedistrict/medusa-plugin-agentic-commerce 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/api/acp/checkout_sessions/[id]/cancel/route.d.ts +3 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/cancel/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/cancel/route.js +39 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/cancel/route.js.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/complete/route.d.ts +3 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/complete/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/complete/route.js +73 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/complete/route.js.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/route.d.ts +4 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/route.js +107 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/route.d.ts +3 -0
- package/.medusa/server/src/api/acp/checkout_sessions/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/route.js +70 -0
- package/.medusa/server/src/api/acp/checkout_sessions/route.js.map +1 -0
- package/.medusa/server/src/api/acp/orders/[id]/route.d.ts +3 -0
- package/.medusa/server/src/api/acp/orders/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/orders/[id]/route.js +37 -0
- package/.medusa/server/src/api/acp/orders/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/acp/product-feed/route.d.ts +3 -0
- package/.medusa/server/src/api/acp/product-feed/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/product-feed/route.js +57 -0
- package/.medusa/server/src/api/acp/product-feed/route.js.map +1 -0
- package/.medusa/server/src/api/middleware/idempotency.d.ts +21 -0
- package/.medusa/server/src/api/middleware/idempotency.d.ts.map +1 -0
- package/.medusa/server/src/api/middleware/idempotency.js +184 -0
- package/.medusa/server/src/api/middleware/idempotency.js.map +1 -0
- package/.medusa/server/src/api/middlewares.d.ts +3 -0
- package/.medusa/server/src/api/middlewares.d.ts.map +1 -0
- package/.medusa/server/src/api/middlewares.js +309 -0
- package/.medusa/server/src/api/middlewares.js.map +1 -0
- package/.medusa/server/src/api/ucp/carts/[id]/cancel/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/carts/[id]/cancel/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/carts/[id]/cancel/route.js +39 -0
- package/.medusa/server/src/api/ucp/carts/[id]/cancel/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/carts/[id]/route.d.ts +4 -0
- package/.medusa/server/src/api/ucp/carts/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/carts/[id]/route.js +96 -0
- package/.medusa/server/src/api/ucp/carts/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/carts/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/carts/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/carts/route.js +52 -0
- package/.medusa/server/src/api/ucp/carts/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/catalog/lookup/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/catalog/lookup/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/catalog/lookup/route.js +66 -0
- package/.medusa/server/src/api/ucp/catalog/lookup/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/catalog/search/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/catalog/search/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/catalog/search/route.js +84 -0
- package/.medusa/server/src/api/ucp/catalog/search/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/cancel/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/cancel/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/cancel/route.js +40 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/cancel/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/complete/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/complete/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/complete/route.js +77 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/complete/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/route.d.ts +4 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/route.js +110 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/route.js +71 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/orders/[id]/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/orders/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/orders/[id]/route.js +38 -0
- package/.medusa/server/src/api/ucp/orders/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/validation-schemas.d.ts +992 -0
- package/.medusa/server/src/api/validation-schemas.d.ts.map +1 -0
- package/.medusa/server/src/api/validation-schemas.js +200 -0
- package/.medusa/server/src/api/validation-schemas.js.map +1 -0
- package/.medusa/server/src/api/well-known/acp.json/route.d.ts +3 -0
- package/.medusa/server/src/api/well-known/acp.json/route.d.ts.map +1 -0
- package/.medusa/server/src/api/well-known/acp.json/route.js +44 -0
- package/.medusa/server/src/api/well-known/acp.json/route.js.map +1 -0
- package/.medusa/server/src/api/well-known/ucp/route.d.ts +3 -0
- package/.medusa/server/src/api/well-known/ucp/route.d.ts.map +1 -0
- package/.medusa/server/src/api/well-known/ucp/route.js +34 -0
- package/.medusa/server/src/api/well-known/ucp/route.js.map +1 -0
- package/.medusa/server/src/index.d.ts +51 -0
- package/.medusa/server/src/index.d.ts.map +1 -0
- package/.medusa/server/src/index.js +81 -0
- package/.medusa/server/src/index.js.map +1 -0
- package/.medusa/server/src/jobs/sync-product-feed.d.ts +16 -0
- package/.medusa/server/src/jobs/sync-product-feed.d.ts.map +1 -0
- package/.medusa/server/src/jobs/sync-product-feed.js +78 -0
- package/.medusa/server/src/jobs/sync-product-feed.js.map +1 -0
- package/.medusa/server/src/lib/address-translator.d.ts +40 -0
- package/.medusa/server/src/lib/address-translator.d.ts.map +1 -0
- package/.medusa/server/src/lib/address-translator.js +79 -0
- package/.medusa/server/src/lib/address-translator.js.map +1 -0
- package/.medusa/server/src/lib/cart-fields.d.ts +10 -0
- package/.medusa/server/src/lib/cart-fields.d.ts.map +1 -0
- package/.medusa/server/src/lib/cart-fields.js +42 -0
- package/.medusa/server/src/lib/cart-fields.js.map +1 -0
- package/.medusa/server/src/lib/error-formatters.d.ts +38 -0
- package/.medusa/server/src/lib/error-formatters.d.ts.map +1 -0
- package/.medusa/server/src/lib/error-formatters.js +42 -0
- package/.medusa/server/src/lib/error-formatters.js.map +1 -0
- package/.medusa/server/src/lib/formatters/acp.d.ts +108 -0
- package/.medusa/server/src/lib/formatters/acp.d.ts.map +1 -0
- package/.medusa/server/src/lib/formatters/acp.js +158 -0
- package/.medusa/server/src/lib/formatters/acp.js.map +1 -0
- package/.medusa/server/src/lib/formatters/types.d.ts +19 -0
- package/.medusa/server/src/lib/formatters/types.d.ts.map +1 -0
- package/.medusa/server/src/lib/formatters/types.js +15 -0
- package/.medusa/server/src/lib/formatters/types.js.map +1 -0
- package/.medusa/server/src/lib/formatters/ucp.d.ts +123 -0
- package/.medusa/server/src/lib/formatters/ucp.d.ts.map +1 -0
- package/.medusa/server/src/lib/formatters/ucp.js +226 -0
- package/.medusa/server/src/lib/formatters/ucp.js.map +1 -0
- package/.medusa/server/src/lib/order-fields.d.ts +6 -0
- package/.medusa/server/src/lib/order-fields.d.ts.map +1 -0
- package/.medusa/server/src/lib/order-fields.js +29 -0
- package/.medusa/server/src/lib/order-fields.js.map +1 -0
- package/.medusa/server/src/lib/payment-handler-registry.d.ts +58 -0
- package/.medusa/server/src/lib/payment-handler-registry.d.ts.map +1 -0
- package/.medusa/server/src/lib/payment-handler-registry.js +150 -0
- package/.medusa/server/src/lib/payment-handler-registry.js.map +1 -0
- package/.medusa/server/src/lib/public-url.d.ts +12 -0
- package/.medusa/server/src/lib/public-url.d.ts.map +1 -0
- package/.medusa/server/src/lib/public-url.js +14 -0
- package/.medusa/server/src/lib/public-url.js.map +1 -0
- package/.medusa/server/src/lib/status-maps.d.ts +7 -0
- package/.medusa/server/src/lib/status-maps.d.ts.map +1 -0
- package/.medusa/server/src/lib/status-maps.js +43 -0
- package/.medusa/server/src/lib/status-maps.js.map +1 -0
- package/.medusa/server/src/modules/agentic-commerce/index.d.ts +7 -0
- package/.medusa/server/src/modules/agentic-commerce/index.d.ts.map +1 -0
- package/.medusa/server/src/modules/agentic-commerce/index.js +13 -0
- package/.medusa/server/src/modules/agentic-commerce/index.js.map +1 -0
- package/.medusa/server/src/modules/agentic-commerce/service.d.ts +294 -0
- package/.medusa/server/src/modules/agentic-commerce/service.d.ts.map +1 -0
- package/.medusa/server/src/modules/agentic-commerce/service.js +206 -0
- package/.medusa/server/src/modules/agentic-commerce/service.js.map +1 -0
- package/.medusa/server/src/subscribers/order-placed-webhook.d.ts +16 -0
- package/.medusa/server/src/subscribers/order-placed-webhook.d.ts.map +1 -0
- package/.medusa/server/src/subscribers/order-placed-webhook.js +83 -0
- package/.medusa/server/src/subscribers/order-placed-webhook.js.map +1 -0
- package/.medusa/server/src/types/payment-handler-adapter.d.ts +92 -0
- package/.medusa/server/src/types/payment-handler-adapter.d.ts.map +1 -0
- package/.medusa/server/src/types/payment-handler-adapter.js +34 -0
- package/.medusa/server/src/types/payment-handler-adapter.js.map +1 -0
- package/.medusa/server/src/workflows/cancel-checkout-session.d.ts +9 -0
- package/.medusa/server/src/workflows/cancel-checkout-session.d.ts.map +1 -0
- package/.medusa/server/src/workflows/cancel-checkout-session.js +53 -0
- package/.medusa/server/src/workflows/cancel-checkout-session.js.map +1 -0
- package/.medusa/server/src/workflows/complete-checkout-session.d.ts +23 -0
- package/.medusa/server/src/workflows/complete-checkout-session.d.ts.map +1 -0
- package/.medusa/server/src/workflows/complete-checkout-session.js +44 -0
- package/.medusa/server/src/workflows/complete-checkout-session.js.map +1 -0
- package/.medusa/server/src/workflows/create-checkout-session.d.ts +20 -0
- package/.medusa/server/src/workflows/create-checkout-session.d.ts.map +1 -0
- package/.medusa/server/src/workflows/create-checkout-session.js +65 -0
- package/.medusa/server/src/workflows/create-checkout-session.js.map +1 -0
- package/.medusa/server/src/workflows/index.d.ts +5 -0
- package/.medusa/server/src/workflows/index.d.ts.map +1 -0
- package/.medusa/server/src/workflows/index.js +15 -0
- package/.medusa/server/src/workflows/index.js.map +1 -0
- package/.medusa/server/src/workflows/steps/ensure-shipping-method.d.ts +10 -0
- package/.medusa/server/src/workflows/steps/ensure-shipping-method.d.ts.map +1 -0
- package/.medusa/server/src/workflows/steps/ensure-shipping-method.js +50 -0
- package/.medusa/server/src/workflows/steps/ensure-shipping-method.js.map +1 -0
- package/.medusa/server/src/workflows/steps/setup-payment.d.ts +21 -0
- package/.medusa/server/src/workflows/steps/setup-payment.d.ts.map +1 -0
- package/.medusa/server/src/workflows/steps/setup-payment.js +88 -0
- package/.medusa/server/src/workflows/steps/setup-payment.js.map +1 -0
- package/.medusa/server/src/workflows/steps/validate-checkout-prerequisites.d.ts +9 -0
- package/.medusa/server/src/workflows/steps/validate-checkout-prerequisites.d.ts.map +1 -0
- package/.medusa/server/src/workflows/steps/validate-checkout-prerequisites.js +34 -0
- package/.medusa/server/src/workflows/steps/validate-checkout-prerequisites.js.map +1 -0
- package/.medusa/server/src/workflows/update-checkout-session.d.ts +22 -0
- package/.medusa/server/src/workflows/update-checkout-session.d.ts.map +1 -0
- package/.medusa/server/src/workflows/update-checkout-session.js +103 -0
- package/.medusa/server/src/workflows/update-checkout-session.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +356 -0
- package/package.json +59 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupPaymentStep = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/framework/workflows-sdk");
|
|
5
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
6
|
+
const core_flows_1 = require("@medusajs/medusa/core-flows");
|
|
7
|
+
exports.setupPaymentStep = (0, workflows_sdk_1.createStep)("setup-payment", async (input, { container }) => {
|
|
8
|
+
const query = container.resolve(utils_1.ContainerRegistrationKeys.QUERY);
|
|
9
|
+
// Check if cart already has a payment collection
|
|
10
|
+
const { data: [cart] } = await query.graph({
|
|
11
|
+
entity: "cart",
|
|
12
|
+
fields: [
|
|
13
|
+
"id",
|
|
14
|
+
"payment_collection.id",
|
|
15
|
+
"payment_collection.payment_sessions.*",
|
|
16
|
+
],
|
|
17
|
+
filters: { id: input.cart_id },
|
|
18
|
+
});
|
|
19
|
+
let paymentCollectionId = cart?.payment_collection?.id;
|
|
20
|
+
// Create payment collection if none exists
|
|
21
|
+
if (!paymentCollectionId) {
|
|
22
|
+
await (0, core_flows_1.createPaymentCollectionForCartWorkflow)(container).run({
|
|
23
|
+
input: { cart_id: input.cart_id },
|
|
24
|
+
});
|
|
25
|
+
// Re-fetch to get the payment collection ID
|
|
26
|
+
const { data: [updatedCart] } = await query.graph({
|
|
27
|
+
entity: "cart",
|
|
28
|
+
fields: ["id", "payment_collection.id"],
|
|
29
|
+
filters: { id: input.cart_id },
|
|
30
|
+
});
|
|
31
|
+
paymentCollectionId = updatedCart?.payment_collection?.id;
|
|
32
|
+
if (!paymentCollectionId) {
|
|
33
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.UNEXPECTED_STATE, "Failed to create payment collection for cart");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Check if there's already an active payment session
|
|
37
|
+
const existingSessions = cart?.payment_collection?.payment_sessions || [];
|
|
38
|
+
const hasActiveSession = existingSessions.some((s) => s.status === "pending" || s.status === "authorized");
|
|
39
|
+
if (!hasActiveSession) {
|
|
40
|
+
// Create payment session with the configured provider
|
|
41
|
+
const sessionData = {};
|
|
42
|
+
// Pass EIP-3009 authorization to the payment provider
|
|
43
|
+
// The provider receives this in its initiatePayment() and stores it in session data,
|
|
44
|
+
// then receives it again in authorizePayment() during cart completion
|
|
45
|
+
if (input.payment_data?.eip3009_authorization) {
|
|
46
|
+
sessionData.eip3009_authorization = input.payment_data.eip3009_authorization;
|
|
47
|
+
if (input.payment_data.x402_version) {
|
|
48
|
+
sessionData.x402_version = input.payment_data.x402_version;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Legacy: pass flat token for backwards compatibility
|
|
52
|
+
if (input.payment_data?.token && !input.payment_data?.eip3009_authorization) {
|
|
53
|
+
sessionData.shared_payment_token = input.payment_data.token;
|
|
54
|
+
}
|
|
55
|
+
await (0, core_flows_1.createPaymentSessionsWorkflow)(container).run({
|
|
56
|
+
input: {
|
|
57
|
+
payment_collection_id: paymentCollectionId,
|
|
58
|
+
provider_id: input.payment_provider_id,
|
|
59
|
+
data: sessionData,
|
|
60
|
+
context: {},
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return new workflows_sdk_1.StepResponse({
|
|
65
|
+
cart_id: input.cart_id,
|
|
66
|
+
payment_collection_id: paymentCollectionId,
|
|
67
|
+
},
|
|
68
|
+
// Compensation data — used for cleanup on workflow failure
|
|
69
|
+
{
|
|
70
|
+
cart_id: input.cart_id,
|
|
71
|
+
payment_collection_id: paymentCollectionId,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
// Compensation: refresh payment collection on failure
|
|
75
|
+
async (compensationData, { container }) => {
|
|
76
|
+
if (!compensationData?.cart_id)
|
|
77
|
+
return;
|
|
78
|
+
try {
|
|
79
|
+
const { refreshPaymentCollectionForCartWorkflow } = await import("@medusajs/medusa/core-flows");
|
|
80
|
+
await refreshPaymentCollectionForCartWorkflow(container).run({
|
|
81
|
+
input: { cart_id: compensationData.cart_id },
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// Best effort cleanup — don't throw from compensation
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=setup-payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-payment.js","sourceRoot":"","sources":["../../../../../src/workflows/steps/setup-payment.ts"],"names":[],"mappings":";;;AAAA,qEAA4E;AAC5E,qDAAkF;AAClF,4DAGoC;AAkBvB,QAAA,gBAAgB,GAAG,IAAA,0BAAU,EACxC,eAAe,EACf,KAAK,EAAE,KAAwB,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;IAChD,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,iCAAyB,CAAC,KAAK,CAAC,CAAA;IAEhE,iDAAiD;IACjD,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC;QACzC,MAAM,EAAE,MAAM;QACd,MAAM,EAAE;YACN,IAAI;YACJ,uBAAuB;YACvB,uCAAuC;SACxC;QACD,OAAO,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE;KAC/B,CAAC,CAAA;IAEF,IAAI,mBAAmB,GAAG,IAAI,EAAE,kBAAk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
|
|
1
|
+
type ValidateInput = {
|
|
2
|
+
cart_id: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const validateCheckoutPrerequisitesStep: import("@medusajs/framework/workflows-sdk").StepFunction<ValidateInput, {
|
|
5
|
+
cart_id: string;
|
|
6
|
+
validated: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=validate-checkout-prerequisites.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-checkout-prerequisites.d.ts","sourceRoot":"","sources":["../../../../../src/workflows/steps/validate-checkout-prerequisites.ts"],"names":[],"mappings":"AAIA,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,iCAAiC;;;EAuD7C,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCheckoutPrerequisitesStep = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/framework/workflows-sdk");
|
|
5
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
6
|
+
const cart_fields_1 = require("../../lib/cart-fields");
|
|
7
|
+
exports.validateCheckoutPrerequisitesStep = (0, workflows_sdk_1.createStep)("validate-checkout-prerequisites", async ({ cart_id }, { container }) => {
|
|
8
|
+
const query = container.resolve(utils_1.ContainerRegistrationKeys.QUERY);
|
|
9
|
+
const { data: [cart] } = await query.graph({
|
|
10
|
+
entity: "cart",
|
|
11
|
+
fields: cart_fields_1.CART_VALIDATION_FIELDS,
|
|
12
|
+
filters: { id: cart_id },
|
|
13
|
+
});
|
|
14
|
+
if (!cart) {
|
|
15
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Cart ${cart_id} not found`);
|
|
16
|
+
}
|
|
17
|
+
if (cart.metadata?.checkout_session_canceled) {
|
|
18
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_ALLOWED, "Checkout session has been cancelled");
|
|
19
|
+
}
|
|
20
|
+
if (cart.completed_at) {
|
|
21
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.DUPLICATE_ERROR, "Checkout session has already been completed");
|
|
22
|
+
}
|
|
23
|
+
if (!cart.items || cart.items.length === 0) {
|
|
24
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Cart is empty — add items before completing checkout");
|
|
25
|
+
}
|
|
26
|
+
if (!cart.email) {
|
|
27
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Email is required to complete checkout");
|
|
28
|
+
}
|
|
29
|
+
if (!cart.shipping_address?.id) {
|
|
30
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Shipping address is required to complete checkout");
|
|
31
|
+
}
|
|
32
|
+
return new workflows_sdk_1.StepResponse({ cart_id, validated: true });
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=validate-checkout-prerequisites.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-checkout-prerequisites.js","sourceRoot":"","sources":["../../../../../src/workflows/steps/validate-checkout-prerequisites.ts"],"names":[],"mappings":";;;AAAA,qEAA4E;AAC5E,qDAAkF;AAClF,uDAA8D;AAMjD,QAAA,iCAAiC,GAAG,IAAA,0BAAU,EACzD,iCAAiC,EACjC,KAAK,EAAE,EAAE,OAAO,EAAiB,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;IAClD,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,iCAAyB,CAAC,KAAK,CAAC,CAAA;IAEhE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC;QACzC,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,oCAAsB;QAC9B,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE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type UpdateCheckoutSessionInput = {
|
|
7
|
+
cart_id: string;
|
|
8
|
+
items?: ItemUpdate[];
|
|
9
|
+
email?: string;
|
|
10
|
+
shipping_address?: Record<string, unknown>;
|
|
11
|
+
fulfillment_address?: Record<string, unknown>;
|
|
12
|
+
buyer?: {
|
|
13
|
+
email?: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
};
|
|
16
|
+
fulfillment_option_id?: string;
|
|
17
|
+
};
|
|
18
|
+
declare const updateCheckoutSessionWorkflow: import("@medusajs/framework/workflows-sdk").ReturnWorkflow<UpdateCheckoutSessionInput, {
|
|
19
|
+
cart_id: string;
|
|
20
|
+
}, []>;
|
|
21
|
+
export default updateCheckoutSessionWorkflow;
|
|
22
|
+
//# sourceMappingURL=update-checkout-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-checkout-session.d.ts","sourceRoot":"","sources":["../../../../src/workflows/update-checkout-session.ts"],"names":[],"mappings":"AAeA,KAAK,UAAU,GAAG;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,UAAU,EAAE,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC1C,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7C,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACzC,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B,CAAA;AAED,QAAA,MAAM,6BAA6B;;MAwHlC,CAAA;AAED,eAAe,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const workflows_sdk_1 = require("@medusajs/framework/workflows-sdk");
|
|
4
|
+
const core_flows_1 = require("@medusajs/medusa/core-flows");
|
|
5
|
+
const updateCheckoutSessionWorkflow = (0, workflows_sdk_1.createWorkflow)("update-checkout-session", (input) => {
|
|
6
|
+
// Step 1: Update cart properties (email, shipping address)
|
|
7
|
+
const hasCartUpdates = (0, workflows_sdk_1.transform)(input, (input) => {
|
|
8
|
+
const email = input.buyer?.email || input.email;
|
|
9
|
+
const address = input.fulfillment_address || input.shipping_address;
|
|
10
|
+
return !!(email || address);
|
|
11
|
+
});
|
|
12
|
+
(0, workflows_sdk_1.when)(hasCartUpdates, (v) => v).then(() => {
|
|
13
|
+
const updateData = (0, workflows_sdk_1.transform)(input, (input) => {
|
|
14
|
+
const data = { id: input.cart_id };
|
|
15
|
+
const email = input.buyer?.email || input.email;
|
|
16
|
+
const address = input.fulfillment_address || input.shipping_address;
|
|
17
|
+
if (email)
|
|
18
|
+
data.email = email;
|
|
19
|
+
if (address)
|
|
20
|
+
data.shipping_address = address;
|
|
21
|
+
return data;
|
|
22
|
+
});
|
|
23
|
+
core_flows_1.updateCartWorkflow.runAsStep({ input: updateData });
|
|
24
|
+
});
|
|
25
|
+
// Step 2a: Add new items (items with variant_id and no line_item_id)
|
|
26
|
+
const itemActions = (0, workflows_sdk_1.transform)(input, (input) => {
|
|
27
|
+
const items = input.items || [];
|
|
28
|
+
return {
|
|
29
|
+
toAdd: items.filter((i) => i.variant_id && !i.line_item_id && i.quantity > 0),
|
|
30
|
+
toUpdate: items.filter((i) => i.line_item_id && i.quantity > 0),
|
|
31
|
+
toRemove: items.filter((i) => i.line_item_id && i.quantity === 0),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
(0, workflows_sdk_1.when)(itemActions, (a) => a.toAdd.length > 0).then(() => {
|
|
35
|
+
core_flows_1.addToCartWorkflow.runAsStep({
|
|
36
|
+
input: (0, workflows_sdk_1.transform)({ input, itemActions }, ({ input, itemActions }) => ({
|
|
37
|
+
cart_id: input.cart_id,
|
|
38
|
+
items: itemActions.toAdd.map((i) => ({
|
|
39
|
+
variant_id: i.variant_id,
|
|
40
|
+
quantity: i.quantity,
|
|
41
|
+
})),
|
|
42
|
+
})),
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
// Step 2b: Update existing item quantities
|
|
46
|
+
(0, workflows_sdk_1.when)(itemActions, (a) => a.toUpdate.length > 0).then(() => {
|
|
47
|
+
// updateLineItemInCartWorkflow handles one item at a time
|
|
48
|
+
// For multiple updates, we process the first one here
|
|
49
|
+
// (Medusa v2 workflows don't support dynamic loops — for MVP this handles the common case)
|
|
50
|
+
const firstUpdate = (0, workflows_sdk_1.transform)({ input, itemActions }, ({ input, itemActions }) => ({
|
|
51
|
+
cart_id: input.cart_id,
|
|
52
|
+
item_id: itemActions.toUpdate[0].line_item_id,
|
|
53
|
+
update: { quantity: itemActions.toUpdate[0].quantity },
|
|
54
|
+
}));
|
|
55
|
+
core_flows_1.updateLineItemInCartWorkflow.runAsStep({ input: firstUpdate });
|
|
56
|
+
});
|
|
57
|
+
// Step 2c: Remove items (quantity = 0)
|
|
58
|
+
(0, workflows_sdk_1.when)(itemActions, (a) => a.toRemove.length > 0).then(() => {
|
|
59
|
+
core_flows_1.deleteLineItemsWorkflow.runAsStep({
|
|
60
|
+
input: (0, workflows_sdk_1.transform)({ input, itemActions }, ({ input, itemActions }) => ({
|
|
61
|
+
cart_id: input.cart_id,
|
|
62
|
+
ids: itemActions.toRemove.map((i) => i.line_item_id),
|
|
63
|
+
})),
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
// Step 3: If address was changed and no explicit fulfillment option, auto-select shipping
|
|
67
|
+
const shouldAutoSelectShipping = (0, workflows_sdk_1.transform)(input, (input) => {
|
|
68
|
+
const addressChanged = !!(input.fulfillment_address || input.shipping_address);
|
|
69
|
+
const noExplicitOption = !input.fulfillment_option_id;
|
|
70
|
+
return addressChanged && noExplicitOption;
|
|
71
|
+
});
|
|
72
|
+
const shippingOptions = (0, workflows_sdk_1.when)(shouldAutoSelectShipping, (v) => !!v).then(() => {
|
|
73
|
+
return core_flows_1.listShippingOptionsForCartWorkflow.runAsStep({
|
|
74
|
+
input: (0, workflows_sdk_1.transform)(input, (input) => ({
|
|
75
|
+
cart_id: input.cart_id,
|
|
76
|
+
is_return: false,
|
|
77
|
+
})),
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
const cheapestOptionId = (0, workflows_sdk_1.transform)({ shouldAutoSelectShipping, shippingOptions }, ({ shouldAutoSelectShipping, shippingOptions }) => {
|
|
81
|
+
if (!shouldAutoSelectShipping || !shippingOptions || !Array.isArray(shippingOptions) || shippingOptions.length === 0)
|
|
82
|
+
return null;
|
|
83
|
+
const sorted = [...shippingOptions].sort((a, b) => (a.amount ?? 0) - (b.amount ?? 0));
|
|
84
|
+
return sorted[0]?.id || null;
|
|
85
|
+
});
|
|
86
|
+
// Resolve the final shipping option: explicit choice wins, otherwise auto-select cheapest
|
|
87
|
+
const shippingOptionToApply = (0, workflows_sdk_1.transform)({ input, cheapestOptionId }, ({ input, cheapestOptionId }) => {
|
|
88
|
+
if (input.fulfillment_option_id)
|
|
89
|
+
return input.fulfillment_option_id;
|
|
90
|
+
return cheapestOptionId;
|
|
91
|
+
});
|
|
92
|
+
(0, workflows_sdk_1.when)(shippingOptionToApply, (id) => !!id).then(() => {
|
|
93
|
+
core_flows_1.addShippingMethodToCartWorkflow.runAsStep({
|
|
94
|
+
input: (0, workflows_sdk_1.transform)({ input, shippingOptionToApply }, ({ input, shippingOptionToApply }) => ({
|
|
95
|
+
cart_id: input.cart_id,
|
|
96
|
+
options: [{ id: shippingOptionToApply }],
|
|
97
|
+
})),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return new workflows_sdk_1.WorkflowResponse((0, workflows_sdk_1.transform)(input, (input) => ({ cart_id: input.cart_id })));
|
|
101
|
+
});
|
|
102
|
+
exports.default = updateCheckoutSessionWorkflow;
|
|
103
|
+
//# sourceMappingURL=update-checkout-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-checkout-session.js","sourceRoot":"","sources":["../../../../src/workflows/update-checkout-session.ts"],"names":[],"mappings":";;AAAA,qEAK0C;AAC1C,4DAOoC;AAkBpC,MAAM,6BAA6B,GAAG,IAAA,8BAAc,EAClD,yBAAyB,EACzB,CAAC,KAAiC,EAAE,EAAE;IACpC,2DAA2D;IAC3D,MAAM,cAAc,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAChD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,KAAK,IAAI,KAAK,CAAC,KAAK,CAAA;QAC/C,MAAM,OAAO,GAAG,KAAK,CAAC,mBAAmB,IAAI,KAAK,CAAC,gBAAgB,CAAA;QACnE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;IAEF,IAAA,oBAAI,EAAC,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QACvC,MAAM,UAAU,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;YAC5C,MAAM,IAAI,GAA4B,EAAE,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,CAAA;YAC3D,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,KAAK,IAAI,KAAK,CAAC,KAAK,CAAA;YAC/C,MAAM,OAAO,GAAG,KAAK,CAAC,mBAAmB,IAAI,KAAK,CAAC,gBAAgB,CAAA;YACnE,IAAI,KAAK;gBAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;YAC7B,IAAI,OAAO;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|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Finance District OÜ
|
|
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,356 @@
|
|
|
1
|
+
<h1 align="center">@financedistrict/medusa-plugin-agentic-commerce</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
Turn any Medusa v2 store into an AI-native storefront.<br />
|
|
5
|
+
Adds <strong>UCP</strong> and <strong>ACP</strong> protocol endpoints so AI agents can discover products, check out, pay, and track orders — all through standard HTTP APIs.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="#quick-start">Quick Start</a> ·
|
|
10
|
+
<a href="#protocols">Protocols</a> ·
|
|
11
|
+
<a href="#api-reference">API Reference</a> ·
|
|
12
|
+
<a href="#payment-handlers">Payment Handlers</a> ·
|
|
13
|
+
<a href="#configuration">Configuration</a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Why
|
|
19
|
+
|
|
20
|
+
AI agents are becoming a real commerce channel. They need machine-readable APIs to browse catalogs, fill carts, handle payments, and confirm orders — without scraping HTML or reverse-engineering checkout flows.
|
|
21
|
+
|
|
22
|
+
This plugin gives your Medusa store a **standards-compliant agent API** in minutes. No custom code, no frontend changes. And the **pluggable payment handler adapter system** means any payment method — stablecoins, cards, wallets — can be added without modifying the core plugin.
|
|
23
|
+
|
|
24
|
+
## What You Get
|
|
25
|
+
|
|
26
|
+
| Feature | Description |
|
|
27
|
+
|---------|-------------|
|
|
28
|
+
| **Dual protocol support** | Both UCP and ACP endpoints from a single plugin |
|
|
29
|
+
| **Product discovery** | Full-text search and direct lookup for agents to browse your catalog |
|
|
30
|
+
| **Checkout sessions** | Create, update, complete, and cancel — with idempotency built in |
|
|
31
|
+
| **Pluggable payments** | Bring your own payment handler via the adapter interface |
|
|
32
|
+
| **Order tracking** | Agents can retrieve order status and details |
|
|
33
|
+
| **Webhook notifications** | Automatic agent callbacks on order placement |
|
|
34
|
+
| **Protocol discovery** | `/.well-known/ucp` and `/.well-known/acp.json` for automatic capability detection |
|
|
35
|
+
| **Product feed sync** | Scheduled job to push your catalog to agent platforms |
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### 1. Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install @financedistrict/medusa-plugin-agentic-commerce
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Configure `medusa-config.ts`
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { defineConfig } from "@medusajs/framework/utils"
|
|
49
|
+
|
|
50
|
+
export default defineConfig({
|
|
51
|
+
// Register the plugin for route/workflow/subscriber auto-discovery
|
|
52
|
+
plugins: [
|
|
53
|
+
{
|
|
54
|
+
resolve: "@financedistrict/medusa-plugin-agentic-commerce",
|
|
55
|
+
options: {},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
modules: [
|
|
59
|
+
// Register the core service module with your configuration
|
|
60
|
+
{
|
|
61
|
+
key: "agenticCommerce",
|
|
62
|
+
resolve: "@financedistrict/medusa-plugin-agentic-commerce/modules/agentic-commerce",
|
|
63
|
+
options: {
|
|
64
|
+
api_key: process.env.AGENTIC_COMMERCE_API_KEY,
|
|
65
|
+
signatureKey: process.env.AGENTIC_COMMERCE_SIGNATURE_KEY,
|
|
66
|
+
storefront_url: process.env.STOREFRONT_URL || "https://your-store.com",
|
|
67
|
+
store_name: "Your Store Name",
|
|
68
|
+
store_description: "What your store sells",
|
|
69
|
+
// Reference payment handler adapter module keys (see Payment Handlers)
|
|
70
|
+
payment_handler_adapters: ["prismPaymentHandler"],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 3. Set Environment Variables
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Required
|
|
81
|
+
AGENTIC_COMMERCE_API_KEY=your-secret-api-key
|
|
82
|
+
|
|
83
|
+
# Optional
|
|
84
|
+
AGENTIC_COMMERCE_SIGNATURE_KEY=your-hmac-secret
|
|
85
|
+
STOREFRONT_URL=https://your-store.com
|
|
86
|
+
AGENTIC_STORE_NAME="Your Store"
|
|
87
|
+
AGENTIC_STORE_DESCRIPTION="Premium widgets for humans and agents"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 4. Start Your Store
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npx medusa develop
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Your agent APIs are now live:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Discovery
|
|
100
|
+
curl http://localhost:9000/.well-known/ucp
|
|
101
|
+
curl http://localhost:9000/.well-known/acp.json
|
|
102
|
+
|
|
103
|
+
# Search products (UCP)
|
|
104
|
+
curl -X POST http://localhost:9000/ucp/catalog/search \
|
|
105
|
+
-H "UCP-Agent: my-agent/1.0" \
|
|
106
|
+
-H "Request-Id: $(uuidgen)" \
|
|
107
|
+
-H "Content-Type: application/json" \
|
|
108
|
+
-d '{"query": "t-shirt", "limit": 10}'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Protocols
|
|
112
|
+
|
|
113
|
+
### UCP (Unified Commerce Protocol)
|
|
114
|
+
|
|
115
|
+
UCP is designed for **agent-to-merchant** interactions. It uses a shopping-cart model where agents manage carts directly.
|
|
116
|
+
|
|
117
|
+
| Endpoint | Method | Description |
|
|
118
|
+
|----------|--------|-------------|
|
|
119
|
+
| `/.well-known/ucp` | GET | Protocol discovery and capabilities |
|
|
120
|
+
| `/ucp/catalog/search` | POST | Full-text product search |
|
|
121
|
+
| `/ucp/catalog/lookup` | POST | Direct product lookup by ID or handle |
|
|
122
|
+
| `/ucp/carts` | POST | Create a new cart |
|
|
123
|
+
| `/ucp/carts/:id` | GET | Retrieve cart |
|
|
124
|
+
| `/ucp/carts/:id` | PUT | Update cart (add/remove items, set address) |
|
|
125
|
+
| `/ucp/checkout-sessions` | POST | Create checkout session from cart |
|
|
126
|
+
| `/ucp/checkout-sessions/:id` | GET | Retrieve checkout session |
|
|
127
|
+
| `/ucp/checkout-sessions/:id` | PUT | Update checkout session |
|
|
128
|
+
| `/ucp/checkout-sessions/:id/complete` | POST | Complete checkout and place order |
|
|
129
|
+
| `/ucp/checkout-sessions/:id/cancel` | POST | Cancel checkout session |
|
|
130
|
+
| `/ucp/orders/:id` | GET | Retrieve order details |
|
|
131
|
+
|
|
132
|
+
**Required headers:** `UCP-Agent`, `Request-Id`
|
|
133
|
+
|
|
134
|
+
### ACP (Agent Commerce Protocol)
|
|
135
|
+
|
|
136
|
+
ACP is designed for **platform-to-merchant** interactions. It uses a session-based model where the platform manages the checkout flow.
|
|
137
|
+
|
|
138
|
+
| Endpoint | Method | Description |
|
|
139
|
+
|----------|--------|-------------|
|
|
140
|
+
| `/.well-known/acp.json` | GET | Protocol discovery and capabilities |
|
|
141
|
+
| `/acp/checkout_sessions` | POST | Create checkout session |
|
|
142
|
+
| `/acp/checkout_sessions/:id` | GET | Retrieve checkout session |
|
|
143
|
+
| `/acp/checkout_sessions/:id` | POST | Update checkout session |
|
|
144
|
+
| `/acp/checkout_sessions/:id/complete` | POST | Complete checkout |
|
|
145
|
+
| `/acp/checkout_sessions/:id/cancel` | POST | Cancel checkout session |
|
|
146
|
+
| `/acp/orders/:id` | GET | Retrieve order |
|
|
147
|
+
| `/acp/product-feed` | GET | Retrieve product feed |
|
|
148
|
+
|
|
149
|
+
**Required headers:** `Authorization: Bearer <api_key>`, `API-Version`
|
|
150
|
+
|
|
151
|
+
## Payment Handlers
|
|
152
|
+
|
|
153
|
+
Payment is handled through a **pluggable adapter system**. Each adapter implements the `PaymentHandlerAdapter` interface and registers as a Medusa module.
|
|
154
|
+
|
|
155
|
+
### Using the Prism Payment Handler
|
|
156
|
+
|
|
157
|
+
For x402 stablecoin payments (USDC, FDUSD, etc.), use the companion package:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npm install @financedistrict/medusa-plugin-prism-payment
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
See [@financedistrict/medusa-plugin-prism-payment](../prism-payment/README.md) for setup instructions.
|
|
164
|
+
|
|
165
|
+
### Building a Custom Payment Handler
|
|
166
|
+
|
|
167
|
+
Implement the `PaymentHandlerAdapter` interface:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import type {
|
|
171
|
+
PaymentHandlerAdapter,
|
|
172
|
+
CheckoutPrepareInput,
|
|
173
|
+
} from "@financedistrict/medusa-plugin-agentic-commerce"
|
|
174
|
+
|
|
175
|
+
export default class MyPaymentAdapter implements PaymentHandlerAdapter {
|
|
176
|
+
readonly id = "my_payment_handler"
|
|
177
|
+
readonly name = "My Payment"
|
|
178
|
+
|
|
179
|
+
// Discovery — what to advertise in .well-known endpoints
|
|
180
|
+
async getUcpDiscoveryHandlers(): Promise<Record<string, unknown[]>> {
|
|
181
|
+
return {
|
|
182
|
+
"com.example.my_payment": [{
|
|
183
|
+
id: "my-handler",
|
|
184
|
+
version: "1.0.0",
|
|
185
|
+
}],
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async getAcpDiscoveryHandlers(): Promise<unknown[]> {
|
|
190
|
+
return [{
|
|
191
|
+
id: "com.example.my_payment",
|
|
192
|
+
name: "My Payment",
|
|
193
|
+
version: "1.0.0",
|
|
194
|
+
psp: "my-psp",
|
|
195
|
+
requires_delegate_payment: false,
|
|
196
|
+
instrument_schemas: [/* ... */],
|
|
197
|
+
}]
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Checkout preparation — called when a checkout session is created
|
|
201
|
+
async prepareCheckoutPayment(input: CheckoutPrepareInput) {
|
|
202
|
+
// Call your payment gateway, return config for the agent
|
|
203
|
+
return { id: "my-handler", version: "1.0.0", config: { /* ... */ } }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Response formatting — include payment config in checkout responses
|
|
207
|
+
getUcpCheckoutHandlers(cartMetadata?: Record<string, unknown>) {
|
|
208
|
+
return { /* ... */ }
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
getAcpCheckoutHandlers(cartMetadata?: Record<string, unknown>) {
|
|
212
|
+
return [/* ... */]
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Register it as a Medusa module and reference it in `payment_handler_adapters`:
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
// medusa-config.ts
|
|
221
|
+
modules: [
|
|
222
|
+
{
|
|
223
|
+
key: "myPaymentHandler",
|
|
224
|
+
resolve: "./src/modules/my-payment-handler",
|
|
225
|
+
options: { /* ... */ },
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
key: "agenticCommerce",
|
|
229
|
+
resolve: "@financedistrict/medusa-plugin-agentic-commerce/modules/agentic-commerce",
|
|
230
|
+
options: {
|
|
231
|
+
payment_handler_adapters: ["myPaymentHandler"],
|
|
232
|
+
// ...
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
]
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Architecture
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
medusa-config.ts
|
|
242
|
+
|
|
|
243
|
+
+-- plugins: [@financedistrict/medusa-plugin-agentic-commerce]
|
|
244
|
+
| Routes, workflows, subscribers, jobs auto-discovered
|
|
245
|
+
|
|
|
246
|
+
+-- modules:
|
|
247
|
+
+-- agenticCommerce (core service)
|
|
248
|
+
| Config, auth, formatting, payment registry
|
|
249
|
+
|
|
|
250
|
+
+-- prismPaymentHandler (optional adapter)
|
|
251
|
+
Discovery, checkout-prepare, response formatting
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### How Adapter Resolution Works
|
|
255
|
+
|
|
256
|
+
Medusa v2 modules have isolated DI containers. The plugin resolves payment handler adapters from the **request-scoped container** (`req.scope`) via middleware — not from the module's constructor. This ensures all modules are registered and accessible at request time.
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
Request → resolvePaymentAdapters middleware → route handler
|
|
260
|
+
|
|
|
261
|
+
+-- req.scope.resolve("prismPaymentHandler")
|
|
262
|
+
+-- agenticCommerceService.resolveAdapters(req.scope)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Workflows
|
|
266
|
+
|
|
267
|
+
The plugin provides four reusable workflows that orchestrate the checkout process:
|
|
268
|
+
|
|
269
|
+
| Workflow | Description |
|
|
270
|
+
|----------|-------------|
|
|
271
|
+
| `createCheckoutSessionWorkflow` | Validates cart, resolves region, prepares payment |
|
|
272
|
+
| `updateCheckoutSessionWorkflow` | Handles item/address changes, re-prepares payment |
|
|
273
|
+
| `completeCheckoutSessionWorkflow` | Completes payment, creates order |
|
|
274
|
+
| `cancelCheckoutSessionWorkflow` | Cancels session and releases resources |
|
|
275
|
+
|
|
276
|
+
Import them in your custom code:
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import {
|
|
280
|
+
createCheckoutSessionWorkflow,
|
|
281
|
+
completeCheckoutSessionWorkflow,
|
|
282
|
+
} from "@financedistrict/medusa-plugin-agentic-commerce/workflows"
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Configuration
|
|
286
|
+
|
|
287
|
+
### Plugin Options
|
|
288
|
+
|
|
289
|
+
| Option | Type | Default | Description |
|
|
290
|
+
|--------|------|---------|-------------|
|
|
291
|
+
| `api_key` | `string` | `""` | API key for ACP Bearer token authentication |
|
|
292
|
+
| `signatureKey` | `string` | `""` | HMAC-SHA256 key for request signing |
|
|
293
|
+
| `storefront_url` | `string` | `"http://localhost:8000"` | Public URL of your storefront |
|
|
294
|
+
| `store_name` | `string` | `"My Store"` | Store name in protocol responses |
|
|
295
|
+
| `store_description` | `string` | `""` | Store description for discovery |
|
|
296
|
+
| `payment_provider_id` | `string` | `"pp_system_default"` | Medusa payment provider ID |
|
|
297
|
+
| `payment_handler_adapters` | `string[]` | `[]` | Module keys of payment handler adapters |
|
|
298
|
+
| `ucp_version` | `string` | `"2026-01-11"` | UCP protocol version to advertise |
|
|
299
|
+
| `acp_version` | `string` | `"2026-01-30"` | ACP protocol version to advertise |
|
|
300
|
+
|
|
301
|
+
### Environment Variables
|
|
302
|
+
|
|
303
|
+
| Variable | Maps to |
|
|
304
|
+
|----------|---------|
|
|
305
|
+
| `AGENTIC_COMMERCE_API_KEY` | `api_key` |
|
|
306
|
+
| `AGENTIC_COMMERCE_SIGNATURE_KEY` | `signatureKey` |
|
|
307
|
+
| `STOREFRONT_URL` | `storefront_url` |
|
|
308
|
+
| `AGENTIC_STORE_NAME` | `store_name` |
|
|
309
|
+
| `AGENTIC_STORE_DESCRIPTION` | `store_description` |
|
|
310
|
+
| `AGENTIC_PAYMENT_PROVIDER` | `payment_provider_id` |
|
|
311
|
+
|
|
312
|
+
## Exported Utilities
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
import {
|
|
316
|
+
// Service & module
|
|
317
|
+
AgenticCommerceService,
|
|
318
|
+
AgenticCommerceModule,
|
|
319
|
+
AGENTIC_COMMERCE_MODULE,
|
|
320
|
+
|
|
321
|
+
// Payment adapter interface
|
|
322
|
+
PaymentHandlerAdapter, // type
|
|
323
|
+
CheckoutPrepareInput, // type
|
|
324
|
+
PaymentHandlerRegistry,
|
|
325
|
+
|
|
326
|
+
// Error formatting
|
|
327
|
+
formatAcpError,
|
|
328
|
+
formatUcpError,
|
|
329
|
+
|
|
330
|
+
// Address translation
|
|
331
|
+
medusaToAcpAddress,
|
|
332
|
+
acpAddressToMedusa,
|
|
333
|
+
medusaToUcpAddress,
|
|
334
|
+
ucpAddressToMedusa,
|
|
335
|
+
|
|
336
|
+
// Status mapping
|
|
337
|
+
resolveAcpStatus,
|
|
338
|
+
resolveUcpStatus,
|
|
339
|
+
} from "@financedistrict/medusa-plugin-agentic-commerce"
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Requirements
|
|
343
|
+
|
|
344
|
+
- **Medusa v2** (2.x)
|
|
345
|
+
- **Node.js** 20+
|
|
346
|
+
- **PostgreSQL** (standard Medusa requirement)
|
|
347
|
+
|
|
348
|
+
## License
|
|
349
|
+
|
|
350
|
+
MIT
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
<p align="center">
|
|
355
|
+
Built by <a href="https://fd.xyz">Finance District</a>
|
|
356
|
+
</p>
|