@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,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.config = void 0;
|
|
4
|
+
exports.default = orderPlacedWebhookHandler;
|
|
5
|
+
/**
|
|
6
|
+
* Subscriber that fires when an order is placed.
|
|
7
|
+
* If the originating cart had an `agent_webhook_url` in metadata
|
|
8
|
+
* (set during checkout session creation), we notify the agent.
|
|
9
|
+
*
|
|
10
|
+
* ACP webhook format:
|
|
11
|
+
* - Event type: order_create / order_update
|
|
12
|
+
* - Data: { checkout_session_id, permalink_url, status, refunds[] }
|
|
13
|
+
* - Timestamp in header, not body
|
|
14
|
+
*/
|
|
15
|
+
async function orderPlacedWebhookHandler({ event, container, }) {
|
|
16
|
+
const orderId = event.data.id;
|
|
17
|
+
if (!orderId)
|
|
18
|
+
return;
|
|
19
|
+
const query = container.resolve("query");
|
|
20
|
+
// Fetch the order
|
|
21
|
+
let order;
|
|
22
|
+
try {
|
|
23
|
+
const { data: [result] } = await query.graph({
|
|
24
|
+
entity: "order",
|
|
25
|
+
fields: ["id", "display_id", "status", "cart_id"],
|
|
26
|
+
filters: { id: orderId },
|
|
27
|
+
});
|
|
28
|
+
order = result;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error(`[order-placed-webhook] Failed to fetch order ${orderId}:`, error.message);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!order) {
|
|
35
|
+
console.warn(`[order-placed-webhook] Order ${orderId} not found`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
// Look up the original cart to get the webhook URL from metadata
|
|
39
|
+
const cartId = order.cart_id;
|
|
40
|
+
if (!cartId)
|
|
41
|
+
return;
|
|
42
|
+
let cart;
|
|
43
|
+
try {
|
|
44
|
+
const { data: [result] } = await query.graph({
|
|
45
|
+
entity: "cart",
|
|
46
|
+
fields: ["id", "metadata"],
|
|
47
|
+
filters: { id: cartId },
|
|
48
|
+
});
|
|
49
|
+
cart = result;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.warn(`[order-placed-webhook] Failed to fetch cart ${cartId}:`, error.message);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const webhookUrl = cart?.metadata?.agent_webhook_url;
|
|
56
|
+
if (!webhookUrl) {
|
|
57
|
+
// No webhook URL — not an agent order, or no webhook registered
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const agenticCommerceService = container.resolve("agenticCommerce");
|
|
61
|
+
const storefrontUrl = agenticCommerceService.getStorefrontUrl();
|
|
62
|
+
try {
|
|
63
|
+
await agenticCommerceService.sendWebhookEvent({
|
|
64
|
+
url: webhookUrl,
|
|
65
|
+
event_type: "order_create",
|
|
66
|
+
payload: {
|
|
67
|
+
type: "order",
|
|
68
|
+
checkout_session_id: cartId,
|
|
69
|
+
permalink_url: `${storefrontUrl}/orders/${order.id}`,
|
|
70
|
+
status: order.status || "created",
|
|
71
|
+
refunds: [],
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
console.log(`[order-placed-webhook] Notified agent at ${webhookUrl} for order ${orderId}`);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error(`[order-placed-webhook] Failed to notify ${webhookUrl}:`, error.message);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.config = {
|
|
81
|
+
event: "order.placed",
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=order-placed-webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-placed-webhook.js","sourceRoot":"","sources":["../../../../src/subscribers/order-placed-webhook.ts"],"names":[],"mappings":";;;AAYA,4CAsEC;AAhFD;;;;;;;;;GASG;AACY,KAAK,UAAU,yBAAyB,CAAC,EACtD,KAAK,EACL,SAAS,GACsB;IAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAA;IAC7B,IAAI,CAAC,OAAO;QAAE,OAAM;IAEpB,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAQ,CAAA;IAE/C,kBAAkB;IAClB,IAAI,KAAU,CAAA;IACd,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC;YAC3C,MAAM,EAAE,OAAO;YACf,MAAM,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,CAAC;YACjD,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE;SACzB,CAAC,CAAA;QACF,KAAK,GAAG,MAAM,CAAA;IAChB,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,gDAAgD,OAAO,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;QACxF,OAAM;IACR,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,gCAAgC,OAAO,YAAY,CAAC,CAAA;QACjE,OAAM;IACR,CAAC;IAED,iEAAiE;IACjE,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAA;IAC5B,IAAI,CAAC,MAAM;QAAE,OAAM;IAEnB,IAAI,IAAS,CAAA;IACb,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,CAAC,MAA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AAK,EAAE,cAAc;CACtB,CAAA"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment Handler Adapter Interface
|
|
3
|
+
*
|
|
4
|
+
* Implement this interface to add a new payment handler to the agentic commerce plugin.
|
|
5
|
+
* Each adapter provides discovery, checkout preparation, and response formatting
|
|
6
|
+
* for a specific payment provider (e.g., Prism x402, Stripe, Coinbase, etc.)
|
|
7
|
+
*
|
|
8
|
+
* Example implementation:
|
|
9
|
+
* ```ts
|
|
10
|
+
* import type { PaymentHandlerAdapter } from "@financedistrict/medusa-plugin-agentic-commerce"
|
|
11
|
+
*
|
|
12
|
+
* class StripePaymentHandlerAdapter implements PaymentHandlerAdapter {
|
|
13
|
+
* readonly id = "com.stripe.payment"
|
|
14
|
+
* readonly name = "Stripe"
|
|
15
|
+
* // ... implement all methods
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Register your adapter as a Medusa module, then reference it by container name
|
|
20
|
+
* in the agentic commerce plugin options:
|
|
21
|
+
* ```ts
|
|
22
|
+
* // medusa-config.ts
|
|
23
|
+
* modules: [
|
|
24
|
+
* { resolve: "your-adapter-plugin/modules/your-adapter", options: { ... } },
|
|
25
|
+
* {
|
|
26
|
+
* resolve: "@financedistrict/medusa-plugin-agentic-commerce/modules/agentic-commerce",
|
|
27
|
+
* options: { payment_handler_adapters: ["yourAdapterServiceName"] },
|
|
28
|
+
* },
|
|
29
|
+
* ]
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface PaymentHandlerAdapter {
|
|
33
|
+
/** Unique identifier for this adapter (e.g., "xyz.fd.prism_payment") */
|
|
34
|
+
readonly id: string;
|
|
35
|
+
/** Human-readable name (e.g., "Finance District Prism") */
|
|
36
|
+
readonly name: string;
|
|
37
|
+
/**
|
|
38
|
+
* Return UCP discovery handler entries for .well-known/ucp.
|
|
39
|
+
* Keyed by handler namespace (e.g., "xyz.fd.prism_payment").
|
|
40
|
+
* Return empty object if nothing to advertise.
|
|
41
|
+
*/
|
|
42
|
+
getUcpDiscoveryHandlers(): Promise<Record<string, unknown[]>>;
|
|
43
|
+
/**
|
|
44
|
+
* Return ACP discovery handler entries for .well-known/acp.json.
|
|
45
|
+
* Flat array of handler objects for capabilities.payment.handlers.
|
|
46
|
+
* Return empty array if nothing to advertise.
|
|
47
|
+
*/
|
|
48
|
+
getAcpDiscoveryHandlers(): Promise<unknown[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Prepare payment requirements for a checkout session.
|
|
51
|
+
*
|
|
52
|
+
* Called when a checkout session is created or updated (total changes).
|
|
53
|
+
* The adapter should:
|
|
54
|
+
* 1. Call its payment gateway to get payment requirements
|
|
55
|
+
* 2. Store the result on cart metadata under a key it owns
|
|
56
|
+
* 3. Return the result (or null on failure)
|
|
57
|
+
*
|
|
58
|
+
* The adapter is responsible for idempotency — skip the API call
|
|
59
|
+
* if already prepared for the same cart total.
|
|
60
|
+
*/
|
|
61
|
+
prepareCheckoutPayment(input: CheckoutPrepareInput): Promise<unknown | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Return UCP payment_handlers block for a checkout session response.
|
|
64
|
+
* Reads its own stored data from cart metadata.
|
|
65
|
+
* Return empty object if no data available.
|
|
66
|
+
*/
|
|
67
|
+
getUcpCheckoutHandlers(cartMetadata?: Record<string, unknown>): Record<string, unknown[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Return ACP payment handlers array for a checkout session response.
|
|
70
|
+
* Reads its own stored data from cart metadata.
|
|
71
|
+
* Return empty array if no data available.
|
|
72
|
+
*/
|
|
73
|
+
getAcpCheckoutHandlers(cartMetadata?: Record<string, unknown>): unknown[];
|
|
74
|
+
}
|
|
75
|
+
export type CheckoutPrepareInput = {
|
|
76
|
+
cart: {
|
|
77
|
+
id: string;
|
|
78
|
+
total?: number;
|
|
79
|
+
raw_total?: {
|
|
80
|
+
value: number;
|
|
81
|
+
};
|
|
82
|
+
currency_code?: string;
|
|
83
|
+
metadata?: Record<string, unknown>;
|
|
84
|
+
};
|
|
85
|
+
/** Base URL for checkout session resources (e.g., "https://store.example.com/ucp/checkout-sessions") */
|
|
86
|
+
checkoutBaseUrl: string;
|
|
87
|
+
/** Human-readable store name for payment descriptions */
|
|
88
|
+
storeName: string;
|
|
89
|
+
/** Medusa DI container for resolving services (e.g., cart module for metadata updates) */
|
|
90
|
+
container: any;
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=payment-handler-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-handler-adapter.d.ts","sourceRoot":"","sources":["../../../../src/types/payment-handler-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAMH,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IAEnB,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAA;IAE7D;;;;OAIG;IACH,uBAAuB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;IAE7C;;;;;;;;;;;OAWG;IACH,sBAAsB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAE5E;;;;OAIG;IACH,sBAAsB,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;IAEzF;;;;OAIG;IACH,sBAAsB,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAAE,CAAA;CAC1E;AAMD,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAA;QACV,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,SAAS,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;QAC7B,aAAa,CAAC,EAAE,MAAM,CAAA;QACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KACnC,CAAA;IACD,wGAAwG;IACxG,eAAe,EAAE,MAAM,CAAA;IACvB,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAA;IACjB,0FAA0F;IAC1F,SAAS,EAAE,GAAG,CAAA;CACf,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Payment Handler Adapter Interface
|
|
4
|
+
*
|
|
5
|
+
* Implement this interface to add a new payment handler to the agentic commerce plugin.
|
|
6
|
+
* Each adapter provides discovery, checkout preparation, and response formatting
|
|
7
|
+
* for a specific payment provider (e.g., Prism x402, Stripe, Coinbase, etc.)
|
|
8
|
+
*
|
|
9
|
+
* Example implementation:
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { PaymentHandlerAdapter } from "@financedistrict/medusa-plugin-agentic-commerce"
|
|
12
|
+
*
|
|
13
|
+
* class StripePaymentHandlerAdapter implements PaymentHandlerAdapter {
|
|
14
|
+
* readonly id = "com.stripe.payment"
|
|
15
|
+
* readonly name = "Stripe"
|
|
16
|
+
* // ... implement all methods
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Register your adapter as a Medusa module, then reference it by container name
|
|
21
|
+
* in the agentic commerce plugin options:
|
|
22
|
+
* ```ts
|
|
23
|
+
* // medusa-config.ts
|
|
24
|
+
* modules: [
|
|
25
|
+
* { resolve: "your-adapter-plugin/modules/your-adapter", options: { ... } },
|
|
26
|
+
* {
|
|
27
|
+
* resolve: "@financedistrict/medusa-plugin-agentic-commerce/modules/agentic-commerce",
|
|
28
|
+
* options: { payment_handler_adapters: ["yourAdapterServiceName"] },
|
|
29
|
+
* },
|
|
30
|
+
* ]
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
//# sourceMappingURL=payment-handler-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-handler-adapter.js","sourceRoot":"","sources":["../../../../src/types/payment-handler-adapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type CancelCheckoutSessionInput = {
|
|
2
|
+
cart_id: string;
|
|
3
|
+
};
|
|
4
|
+
declare const cancelCheckoutSessionWorkflow: import("@medusajs/framework/workflows-sdk").ReturnWorkflow<CancelCheckoutSessionInput, {
|
|
5
|
+
cart_id: string;
|
|
6
|
+
status: string;
|
|
7
|
+
}, []>;
|
|
8
|
+
export default cancelCheckoutSessionWorkflow;
|
|
9
|
+
//# sourceMappingURL=cancel-checkout-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancel-checkout-session.d.ts","sourceRoot":"","sources":["../../../../src/workflows/cancel-checkout-session.ts"],"names":[],"mappings":"AAYA,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,QAAA,MAAM,6BAA6B;;;MA0DlC,CAAA;AAED,eAAe,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 core_flows_2 = require("@medusajs/medusa/core-flows");
|
|
6
|
+
const cancelCheckoutSessionWorkflow = (0, workflows_sdk_1.createWorkflow)("cancel-checkout-session", (input) => {
|
|
7
|
+
// Step 1: Fetch current cart to check status
|
|
8
|
+
const cartData = (0, core_flows_2.useQueryGraphStep)({
|
|
9
|
+
entity: "cart",
|
|
10
|
+
fields: ["id", "completed_at", "metadata", "payment_collection.id"],
|
|
11
|
+
filters: { id: input.cart_id },
|
|
12
|
+
}).config({ name: "fetch-cart-for-cancel" });
|
|
13
|
+
// Step 2: Validate and prepare update
|
|
14
|
+
const updateInput = (0, workflows_sdk_1.transform)({ input, cartData }, ({ input, cartData }) => {
|
|
15
|
+
const cart = cartData.data?.[0];
|
|
16
|
+
if (!cart) {
|
|
17
|
+
throw new Error(`Cart ${input.cart_id} not found`);
|
|
18
|
+
}
|
|
19
|
+
if (cart.completed_at) {
|
|
20
|
+
throw new Error("Cannot cancel a completed checkout session");
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
id: input.cart_id,
|
|
24
|
+
metadata: {
|
|
25
|
+
...(cart.metadata || {}),
|
|
26
|
+
checkout_session_canceled: true,
|
|
27
|
+
canceled_at: new Date().toISOString(),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
// Step 3: Update cart metadata to mark as cancelled
|
|
32
|
+
core_flows_1.updateCartWorkflow.runAsStep({
|
|
33
|
+
input: updateInput,
|
|
34
|
+
});
|
|
35
|
+
// Step 4: Clean up payment state if a payment collection exists
|
|
36
|
+
const hasPaymentCollection = (0, workflows_sdk_1.transform)(cartData, (cartData) => {
|
|
37
|
+
const cart = cartData.data?.[0];
|
|
38
|
+
return !!(cart?.payment_collection?.id);
|
|
39
|
+
});
|
|
40
|
+
(0, workflows_sdk_1.when)(hasPaymentCollection, (v) => v).then(() => {
|
|
41
|
+
core_flows_1.refreshPaymentCollectionForCartWorkflow.runAsStep({
|
|
42
|
+
input: (0, workflows_sdk_1.transform)(input, (input) => ({
|
|
43
|
+
cart_id: input.cart_id,
|
|
44
|
+
})),
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return new workflows_sdk_1.WorkflowResponse((0, workflows_sdk_1.transform)(input, (input) => ({
|
|
48
|
+
cart_id: input.cart_id,
|
|
49
|
+
status: "canceled",
|
|
50
|
+
})));
|
|
51
|
+
});
|
|
52
|
+
exports.default = cancelCheckoutSessionWorkflow;
|
|
53
|
+
//# sourceMappingURL=cancel-checkout-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancel-checkout-session.js","sourceRoot":"","sources":["../../../../src/workflows/cancel-checkout-session.ts"],"names":[],"mappings":";;AAAA,qEAK0C;AAC1C,4DAGoC;AACpC,4DAA+D;AAM/D,MAAM,6BAA6B,GAAG,IAAA,8BAAc,EAClD,yBAAyB,EACzB,CAAC,KAAiC,EAAE,EAAE;IACpC,6CAA6C;IAC7C,MAAM,QAAQ,GAAG,IAAA,8BAAiB,EAAC;QACjC,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,uBAAuB,CAAC;QACnE,OAAO,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE;KAC/B,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC,CAAA;IAE5C,sCAAsC;IACtC,MAAM,WAAW,GAAG,IAAA,yBAAS,EAC3B,EAAE,KAAK,EAAE,QAAQ,EAAE,EACnB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;QACtB,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;QAC/B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,QAAQ,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;QACpD,CAAC;QACD,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;QAC/D,CAAC;QACD,OAAO;YACL,EAAE,EA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string;
|
|
3
|
+
payment_provider_id: string;
|
|
4
|
+
payment_data?: {
|
|
5
|
+
/** Base64-encoded x402 PaymentAuthorizationResult */
|
|
6
|
+
eip3009_authorization?: string;
|
|
7
|
+
/** x402 protocol version */
|
|
8
|
+
x402_version?: number;
|
|
9
|
+
/** Payment handler ID (e.g., "xyz.fd.prism_payment") */
|
|
10
|
+
handler_id?: string;
|
|
11
|
+
/** @deprecated Legacy fields */
|
|
12
|
+
provider?: string;
|
|
13
|
+
token?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
billing_address?: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
declare const completeCheckoutSessionWorkflow: import("@medusajs/framework/workflows-sdk").ReturnWorkflow<CompleteCheckoutSessionInput, {
|
|
19
|
+
cart_id: string;
|
|
20
|
+
order_id: any;
|
|
21
|
+
}, []>;
|
|
22
|
+
export default completeCheckoutSessionWorkflow;
|
|
23
|
+
//# sourceMappingURL=complete-checkout-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete-checkout-session.d.ts","sourceRoot":"","sources":["../../../../src/workflows/complete-checkout-session.ts"],"names":[],"mappings":"AAUA,KAAK,4BAA4B,GAAG;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,mBAAmB,EAAE,MAAM,CAAA;IAC3B,YAAY,CAAC,EAAE;QACb,qDAAqD;QACrD,qBAAqB,CAAC,EAAE,MAAM,CAAA;QAC9B,4BAA4B;QAC5B,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,wDAAwD;QACxD,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,gCAAgC;QAChC,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,CAAA;IACD,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC1C,CAAA;AAED,QAAA,MAAM,+BAA+B;;;MA+CpC,CAAA;AAED,eAAe,+BAA+B,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 validate_checkout_prerequisites_1 = require("./steps/validate-checkout-prerequisites");
|
|
6
|
+
const ensure_shipping_method_1 = require("./steps/ensure-shipping-method");
|
|
7
|
+
const setup_payment_1 = require("./steps/setup-payment");
|
|
8
|
+
const completeCheckoutSessionWorkflow = (0, workflows_sdk_1.createWorkflow)("complete-checkout-session", (input) => {
|
|
9
|
+
// Step 1: Validate all prerequisites
|
|
10
|
+
(0, validate_checkout_prerequisites_1.validateCheckoutPrerequisitesStep)({ cart_id: input.cart_id });
|
|
11
|
+
// Step 2: Ensure shipping method is set
|
|
12
|
+
(0, ensure_shipping_method_1.ensureShippingMethodStep)({ cart_id: input.cart_id });
|
|
13
|
+
// Step 3: Setup payment collection + session
|
|
14
|
+
const paymentData = (0, workflows_sdk_1.transform)(input, (input) => {
|
|
15
|
+
// Pass EIP-3009 authorization or legacy token to the payment session
|
|
16
|
+
const authorization = input.payment_data?.eip3009_authorization;
|
|
17
|
+
const legacyToken = input.payment_data?.token;
|
|
18
|
+
const hasPaymentData = authorization || legacyToken;
|
|
19
|
+
return {
|
|
20
|
+
cart_id: input.cart_id,
|
|
21
|
+
payment_provider_id: input.payment_provider_id,
|
|
22
|
+
payment_data: hasPaymentData
|
|
23
|
+
? {
|
|
24
|
+
eip3009_authorization: authorization || legacyToken,
|
|
25
|
+
x402_version: input.payment_data?.x402_version,
|
|
26
|
+
handler_id: input.payment_data?.handler_id,
|
|
27
|
+
}
|
|
28
|
+
: undefined,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
(0, setup_payment_1.setupPaymentStep)(paymentData);
|
|
32
|
+
// Step 4: Complete the cart → creates the order
|
|
33
|
+
const completionResult = core_flows_1.completeCartWorkflow.runAsStep({
|
|
34
|
+
input: (0, workflows_sdk_1.transform)(input, (input) => ({ id: input.cart_id })),
|
|
35
|
+
});
|
|
36
|
+
// Step 5: Extract order info from result
|
|
37
|
+
const result = (0, workflows_sdk_1.transform)({ completionResult, input }, ({ completionResult, input }) => ({
|
|
38
|
+
cart_id: input.cart_id,
|
|
39
|
+
order_id: completionResult?.id || null,
|
|
40
|
+
}));
|
|
41
|
+
return new workflows_sdk_1.WorkflowResponse(result);
|
|
42
|
+
});
|
|
43
|
+
exports.default = completeCheckoutSessionWorkflow;
|
|
44
|
+
//# sourceMappingURL=complete-checkout-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete-checkout-session.js","sourceRoot":"","sources":["../../../../src/workflows/complete-checkout-session.ts"],"names":[],"mappings":";;AAAA,qEAI0C;AAC1C,4DAAkE;AAClE,6FAA2F;AAC3F,2EAAyE;AACzE,yDAAwD;AAoBxD,MAAM,+BAA+B,GAAG,IAAA,8BAAc,EACpD,2BAA2B,EAC3B,CAAC,KAAmC,EAAE,EAAE;IACtC,qCAAqC;IACrC,IAAA,mEAAiC,EAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IAE7D,wCAAwC;IACxC,IAAA,iDAAwB,EAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IAEpD,6CAA6C;IAC7C,MAAM,WAAW,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAC7C,qEAAqE;QACrE,MAAM,aAAa,GAAG,KAAK,CAAC,YAAY,EAAE,qBAAqB,CAAA;QAC/D,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,EAAE,KAAK,CAAA;QAC7C,MAAM,cAAc,GAAG,aAAa,IAAI,WAAW,CAAA;QAEnD,OAAO;YACL,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,mBAAmB,EAAE,KAAK,CAAC,mBAAmB;YAC9C,YAAY,EAAE,cAAc;gBAC1B,CAAC,CAAC;oBACE,qBAAqB,EAAE,aAAa,IAAI,WAAW;oBACnD,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,YAAY;oBAC9C,UAAU,EAAE,KAAK,CAAC,YAAY,EAAE,UAAU;iBAC3C;gBACH,CAAC,CAAC,SAAS;SACd,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,IAAA,gCAAgB,EAAC,WAAW,CAAC,CAAA;IAE7B,gDAAgD;IAChD,MAAM,gBAAgB,GAAG,iCAAoB,CAAC,SAAS,CAAC;QACtD,KAAK,EAAE,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;KAC5D,CAAC,CAAA;IAEF,yCAAyC;IACzC,MAAM,MAAM,GAAG,IAAA,yBAAS,EACtB,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAC3B,CAAC,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QAChC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,QAAQ,EAAG,gBAAwB,EAAE,EAAE,IAAI,IAAI;KAChD,CAAC,CACH,CAAA;IAED,OAAO,IAAI,gCAAgB,CAAC,MAAM,CAAC,CAAA;AACrC,CAAC,CACF,CAAA;AAED,kBAAe,+BAA+B,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type CreateCheckoutSessionInput = {
|
|
2
|
+
items: {
|
|
3
|
+
variant_id: string;
|
|
4
|
+
quantity: number;
|
|
5
|
+
}[];
|
|
6
|
+
region_id?: string;
|
|
7
|
+
email?: string;
|
|
8
|
+
currency_code?: string;
|
|
9
|
+
shipping_address?: Record<string, unknown>;
|
|
10
|
+
fulfillment_address?: Record<string, unknown>;
|
|
11
|
+
buyer?: {
|
|
12
|
+
email?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
};
|
|
15
|
+
webhook_url?: string;
|
|
16
|
+
protocol: "acp" | "ucp";
|
|
17
|
+
};
|
|
18
|
+
declare const createCheckoutSessionWorkflow: import("@medusajs/framework/workflows-sdk").ReturnWorkflow<CreateCheckoutSessionInput, import("@medusajs/types").CartDTO, []>;
|
|
19
|
+
export default createCheckoutSessionWorkflow;
|
|
20
|
+
//# sourceMappingURL=create-checkout-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-checkout-session.d.ts","sourceRoot":"","sources":["../../../../src/workflows/create-checkout-session.ts"],"names":[],"mappings":"AAcA,KAAK,0BAA0B,GAAG;IAChC,KAAK,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACjD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,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,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAA;CACxB,CAAA;AAED,QAAA,MAAM,6BAA6B,+HA8ElC,CAAA;AAED,eAAe,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 core_flows_2 = require("@medusajs/medusa/core-flows");
|
|
6
|
+
const createCheckoutSessionWorkflow = (0, workflows_sdk_1.createWorkflow)("create-checkout-session", (input) => {
|
|
7
|
+
// Step 1: Resolve region if not provided
|
|
8
|
+
const regions = (0, core_flows_2.useQueryGraphStep)({
|
|
9
|
+
entity: "region",
|
|
10
|
+
fields: ["id", "currency_code"],
|
|
11
|
+
pagination: { take: 1 },
|
|
12
|
+
}).config({ name: "fetch-default-region" });
|
|
13
|
+
const cartInput = (0, workflows_sdk_1.transform)({ input, regions }, ({ input, regions }) => {
|
|
14
|
+
const regionId = input.region_id || regions.data?.[0]?.id;
|
|
15
|
+
if (!regionId) {
|
|
16
|
+
throw new Error("No regions configured in the store");
|
|
17
|
+
}
|
|
18
|
+
const email = input.buyer?.email || input.email;
|
|
19
|
+
const address = input.fulfillment_address || input.shipping_address;
|
|
20
|
+
return {
|
|
21
|
+
region_id: regionId,
|
|
22
|
+
email: email || undefined,
|
|
23
|
+
currency_code: input.currency_code || "eur",
|
|
24
|
+
items: input.items.map((i) => ({
|
|
25
|
+
variant_id: i.variant_id,
|
|
26
|
+
quantity: i.quantity,
|
|
27
|
+
})),
|
|
28
|
+
metadata: {
|
|
29
|
+
is_checkout_session: true,
|
|
30
|
+
protocol: input.protocol,
|
|
31
|
+
...(input.webhook_url ? { agent_webhook_url: input.webhook_url } : {}),
|
|
32
|
+
},
|
|
33
|
+
...(address ? { shipping_address: address } : {}),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
// Step 2: Create the cart
|
|
37
|
+
const cart = core_flows_1.createCartWorkflow.runAsStep({
|
|
38
|
+
input: cartInput,
|
|
39
|
+
});
|
|
40
|
+
// Step 3: If shipping address was provided, auto-select cheapest shipping
|
|
41
|
+
const cartId = (0, workflows_sdk_1.transform)(cart, (cart) => cart.id);
|
|
42
|
+
const hasAddress = (0, workflows_sdk_1.transform)(input, (input) => !!(input.fulfillment_address || input.shipping_address));
|
|
43
|
+
const shippingOptions = (0, workflows_sdk_1.when)(hasAddress, (has) => !!has).then(() => {
|
|
44
|
+
return core_flows_1.listShippingOptionsForCartWorkflow.runAsStep({
|
|
45
|
+
input: (0, workflows_sdk_1.transform)(cartId, (id) => ({ cart_id: id, is_return: false })),
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const shouldAddShipping = (0, workflows_sdk_1.transform)({ hasAddress, shippingOptions }, ({ hasAddress, shippingOptions }) => {
|
|
49
|
+
if (!hasAddress || !shippingOptions || !Array.isArray(shippingOptions) || shippingOptions.length === 0)
|
|
50
|
+
return null;
|
|
51
|
+
const sorted = [...shippingOptions].sort((a, b) => (a.amount ?? 0) - (b.amount ?? 0));
|
|
52
|
+
return sorted[0]?.id || null;
|
|
53
|
+
});
|
|
54
|
+
(0, workflows_sdk_1.when)(shouldAddShipping, (id) => !!id).then(() => {
|
|
55
|
+
core_flows_1.addShippingMethodToCartWorkflow.runAsStep({
|
|
56
|
+
input: (0, workflows_sdk_1.transform)({ cartId, shouldAddShipping }, ({ cartId, shouldAddShipping }) => ({
|
|
57
|
+
cart_id: cartId,
|
|
58
|
+
options: [{ id: shouldAddShipping }],
|
|
59
|
+
})),
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return new workflows_sdk_1.WorkflowResponse(cart);
|
|
63
|
+
});
|
|
64
|
+
exports.default = createCheckoutSessionWorkflow;
|
|
65
|
+
//# sourceMappingURL=create-checkout-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-checkout-session.js","sourceRoot":"","sources":["../../../../src/workflows/create-checkout-session.ts"],"names":[],"mappings":";;AAAA,qEAK0C;AAC1C,4DAKoC;AACpC,4DAA+D;AAc/D,MAAM,6BAA6B,GAAG,IAAA,8BAAc,EAClD,yBAAyB,EACzB,CAAC,KAAiC,EAAE,EAAE;IACpC,yCAAyC;IACzC,MAAM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MAAM,MAAM,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAA;QAC/F,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,IAAI,CAAA;IAC9B,CAAC,CACF,CAAA;IAED,IAAA,oBAAI,EAAC,iBAAiB,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QAC9C,4CAA+B,CAAC,SAAS,CAAC;YACxC,KAAK,EAAE,IAAA,yBAAS,EACd,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAC7B,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAC;gBAClC,OAAO,EAAE,MAAM;gBACf,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,iBAAiB,EAAE,CAAC;aACrC,CAAC,CACH;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,IAAI,gCAAgB,CAAC,IAAI,CAAC,CAAA;AACnC,CAAC,CACF,CAAA;AAED,kBAAe,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as createCheckoutSessionWorkflow } from "./create-checkout-session";
|
|
2
|
+
export { default as completeCheckoutSessionWorkflow } from "./complete-checkout-session";
|
|
3
|
+
export { default as cancelCheckoutSessionWorkflow } from "./cancel-checkout-session";
|
|
4
|
+
export { default as updateCheckoutSessionWorkflow } from "./update-checkout-session";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/workflows/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,6BAA6B,EAAE,MAAM,2BAA2B,CAAA;AACpF,OAAO,EAAE,OAAO,IAAI,+BAA+B,EAAE,MAAM,6BAA6B,CAAA;AACxF,OAAO,EAAE,OAAO,IAAI,6BAA6B,EAAE,MAAM,2BAA2B,CAAA;AACpF,OAAO,EAAE,OAAO,IAAI,6BAA6B,EAAE,MAAM,2BAA2B,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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.updateCheckoutSessionWorkflow = exports.cancelCheckoutSessionWorkflow = exports.completeCheckoutSessionWorkflow = exports.createCheckoutSessionWorkflow = void 0;
|
|
7
|
+
var create_checkout_session_1 = require("./create-checkout-session");
|
|
8
|
+
Object.defineProperty(exports, "createCheckoutSessionWorkflow", { enumerable: true, get: function () { return __importDefault(create_checkout_session_1).default; } });
|
|
9
|
+
var complete_checkout_session_1 = require("./complete-checkout-session");
|
|
10
|
+
Object.defineProperty(exports, "completeCheckoutSessionWorkflow", { enumerable: true, get: function () { return __importDefault(complete_checkout_session_1).default; } });
|
|
11
|
+
var cancel_checkout_session_1 = require("./cancel-checkout-session");
|
|
12
|
+
Object.defineProperty(exports, "cancelCheckoutSessionWorkflow", { enumerable: true, get: function () { return __importDefault(cancel_checkout_session_1).default; } });
|
|
13
|
+
var update_checkout_session_1 = require("./update-checkout-session");
|
|
14
|
+
Object.defineProperty(exports, "updateCheckoutSessionWorkflow", { enumerable: true, get: function () { return __importDefault(update_checkout_session_1).default; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/workflows/index.ts"],"names":[],"mappings":";;;;;;AAAA,qEAAoF;AAA3E,yJAAA,OAAO,OAAiC;AACjD,yEAAwF;AAA/E,6JAAA,OAAO,OAAmC;AACnD,qEAAoF;AAA3E,yJAAA,OAAO,OAAiC;AACjD,qEAAoF;AAA3E,yJAAA,OAAO,OAAiC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type EnsureShippingInput = {
|
|
2
|
+
cart_id: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const ensureShippingMethodStep: import("@medusajs/framework/workflows-sdk").StepFunction<EnsureShippingInput, {
|
|
5
|
+
cart_id: string;
|
|
6
|
+
shipping_option_id: any;
|
|
7
|
+
already_set: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=ensure-shipping-method.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure-shipping-method.d.ts","sourceRoot":"","sources":["../../../../../src/workflows/steps/ensure-shipping-method.ts"],"names":[],"mappings":"AAOA,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,wBAAwB;;;;EAwDpC,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureShippingMethodStep = 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.ensureShippingMethodStep = (0, workflows_sdk_1.createStep)("ensure-shipping-method", async ({ cart_id }, { container }) => {
|
|
8
|
+
const query = container.resolve(utils_1.ContainerRegistrationKeys.QUERY);
|
|
9
|
+
// Check if cart already has shipping methods
|
|
10
|
+
const { data: [cart] } = await query.graph({
|
|
11
|
+
entity: "cart",
|
|
12
|
+
fields: ["id", "shipping_methods.id"],
|
|
13
|
+
filters: { id: cart_id },
|
|
14
|
+
});
|
|
15
|
+
if (cart?.shipping_methods && cart.shipping_methods.length > 0) {
|
|
16
|
+
return new workflows_sdk_1.StepResponse({
|
|
17
|
+
cart_id,
|
|
18
|
+
shipping_option_id: null,
|
|
19
|
+
already_set: true,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
// List available shipping options for this cart
|
|
23
|
+
const { result: shippingOptions } = await (0, core_flows_1.listShippingOptionsForCartWorkflow)(container).run({
|
|
24
|
+
input: { cart_id, is_return: false },
|
|
25
|
+
});
|
|
26
|
+
if (!shippingOptions || shippingOptions.length === 0) {
|
|
27
|
+
// No shipping options available — this is OK for digital goods
|
|
28
|
+
// but will block checkout for physical goods
|
|
29
|
+
return new workflows_sdk_1.StepResponse({
|
|
30
|
+
cart_id,
|
|
31
|
+
shipping_option_id: null,
|
|
32
|
+
already_set: false,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
// Pick the cheapest option
|
|
36
|
+
const cheapest = shippingOptions.sort((a, b) => (a.amount ?? 0) - (b.amount ?? 0))[0];
|
|
37
|
+
// Add shipping method to cart
|
|
38
|
+
await (0, core_flows_1.addShippingMethodToCartWorkflow)(container).run({
|
|
39
|
+
input: {
|
|
40
|
+
cart_id,
|
|
41
|
+
options: [{ id: cheapest.id }],
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return new workflows_sdk_1.StepResponse({
|
|
45
|
+
cart_id,
|
|
46
|
+
shipping_option_id: cheapest.id,
|
|
47
|
+
already_set: false,
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=ensure-shipping-method.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensure-shipping-method.js","sourceRoot":"","sources":["../../../../../src/workflows/steps/ensure-shipping-method.ts"],"names":[],"mappings":";;;AAAA,qEAA4E;AAC5E,qDAAqE;AACrE,4DAGoC;AAMvB,QAAA,wBAAwB,GAAG,IAAA,0BAAU,EA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IAAI,CAAC,CAAC,CACtD,CAAC,CAAC,CAAC,CAAA;IAEJ,8BAA8B;IAC9B,MAAM,IAAA,4CAA+B,EAAC,SAAS,CAAC,CAAC,GAAG,CAAC;QACnD,KAAK,EAAE;YACL,OAAO;YACP,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC;SAC/B;KACF,CAAC,CAAA;IAEF,OAAO,IAAI,4BAAY,CAAC;QACtB,OAAO;QACP,kBAAkB,EAAE,QAAQ,CAAC,EAAE;QAC/B,WAAW,EAAE,KAAK;KACnB,CAAC,CAAA;AACJ,CAAC,CACF,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type SetupPaymentInput = {
|
|
2
|
+
cart_id: string;
|
|
3
|
+
payment_provider_id: string;
|
|
4
|
+
payment_data?: {
|
|
5
|
+
/** Base64-encoded x402 PaymentAuthorizationResult */
|
|
6
|
+
eip3009_authorization?: string;
|
|
7
|
+
/** x402 protocol version */
|
|
8
|
+
x402_version?: number;
|
|
9
|
+
/** Payment handler ID */
|
|
10
|
+
handler_id?: string;
|
|
11
|
+
/** @deprecated Legacy token field */
|
|
12
|
+
token?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare const setupPaymentStep: import("@medusajs/framework/workflows-sdk").StepFunction<SetupPaymentInput, {
|
|
17
|
+
cart_id: string;
|
|
18
|
+
payment_collection_id: any;
|
|
19
|
+
}>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=setup-payment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-payment.d.ts","sourceRoot":"","sources":["../../../../../src/workflows/steps/setup-payment.ts"],"names":[],"mappings":"AAOA,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,mBAAmB,EAAE,MAAM,CAAA;IAC3B,YAAY,CAAC,EAAE;QACb,qDAAqD;QACrD,qBAAqB,CAAC,EAAE,MAAM,CAAA;QAC9B,4BAA4B;QAC5B,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,yBAAyB;QACzB,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,qCAAqC;QACrC,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,CAAA;CACF,CAAA;AAED,eAAO,MAAM,gBAAgB;;;EAuG5B,CAAA"}
|