@curless/agentbank-merchant-sdk 0.2.0 → 0.3.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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentbankMerchant } from '../client.js';
|
|
2
|
+
import type { X402PaymentRequirements } from '../types.js';
|
|
2
3
|
export type CheckoutLineItem = {
|
|
3
4
|
/** Your product id / SKU. */
|
|
4
5
|
sku: string;
|
|
@@ -26,5 +27,24 @@ export declare class CheckoutResource {
|
|
|
26
27
|
private readonly client;
|
|
27
28
|
constructor(client: AgentbankMerchant);
|
|
28
29
|
open(input: OpenCheckoutInput): Promise<Checkout>;
|
|
30
|
+
openX402(input: OpenX402CheckoutInput): Promise<X402Checkout>;
|
|
29
31
|
}
|
|
32
|
+
export type OpenX402CheckoutInput = {
|
|
33
|
+
items: CheckoutLineItem[];
|
|
34
|
+
/** Authoritative total in USDC base units (6 dp). YOU set this. */
|
|
35
|
+
amount: number;
|
|
36
|
+
/** Overrides the client's configured `merchantId` for this call. */
|
|
37
|
+
merchantId?: string;
|
|
38
|
+
};
|
|
39
|
+
export type X402Checkout = {
|
|
40
|
+
/** The session id the buyer pays with `{ sessionId }`. */
|
|
41
|
+
sessionId: string;
|
|
42
|
+
x402Version: number;
|
|
43
|
+
/** The x402 challenge the buyer signs against (payTo = your USDC address). */
|
|
44
|
+
accepts: X402PaymentRequirements[];
|
|
45
|
+
amount: number;
|
|
46
|
+
currency: string;
|
|
47
|
+
payTo: string;
|
|
48
|
+
network: string;
|
|
49
|
+
};
|
|
30
50
|
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/resources/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":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AM,CAAC;IACpB,8EAA8E;IAC9E,OAAO,EAAE,uBAAuB,EAAE,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
@@ -25,5 +25,27 @@ export class CheckoutResource {
|
|
|
25
25
|
const amount = session.totals?.find((t) => t.type === 'total')?.amount ?? 0;
|
|
26
26
|
return { id: session.id, status: session.status, amount, currency: session.currency };
|
|
27
27
|
}
|
|
28
|
+
// Merchant-quoted x402 (USDC) checkout — the stablecoin twin of `open`. YOU
|
|
29
|
+
// set the authoritative USDC amount (base units, 6 dp); the gateway freezes
|
|
30
|
+
// it and returns the x402 challenge. A buyer agent then pays it by signing an
|
|
31
|
+
// EIP-3009 authorization against `accepts[0]` and POSTing `{ sessionId }` to
|
|
32
|
+
// /x402/:merchantId/checkout — it can't change the amount. Settlement is
|
|
33
|
+
// on-chain via the x402 facilitator; the USDC lands at your address.
|
|
34
|
+
async openX402(input) {
|
|
35
|
+
const merchantId = input.merchantId ?? this.client.merchantId;
|
|
36
|
+
if (!merchantId) {
|
|
37
|
+
throw new Error('merchantId is required — set it on AgentbankMerchant({ merchantId }) or pass it to openX402()');
|
|
38
|
+
}
|
|
39
|
+
return this.client.request('POST', `/x402/${encodeURIComponent(merchantId)}/checkout_sessions`, {
|
|
40
|
+
body: {
|
|
41
|
+
amount: input.amount,
|
|
42
|
+
items: input.items.map((it) => ({
|
|
43
|
+
id: it.sku,
|
|
44
|
+
quantity: it.quantity,
|
|
45
|
+
name: it.name,
|
|
46
|
+
})),
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
28
50
|
}
|
|
29
51
|
//# sourceMappingURL=checkout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../src/resources/checkout.ts"],"names":[],"mappings":"
|
|
1
|
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IAC5E,4EAA4E;IAC5E,8EAA8E;IAC9E,6EAA6E;IAC7E,yEAAyE;IACzE,qEAAqE;IACrE,KAAK,CAAC,QAAQ,CAAC,KAA4B;QACzC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;QAC9D,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,+FAA+F,CAChG,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,MAAM,EACN,SAAS,kBAAkB,CAAC,UAAU,CAAC,oBAAoB,EAC3D;YACE,IAAI,EAAE;gBACJ,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC9B,EAAE,EAAE,EAAE,CAAC,GAAG;oBACV,QAAQ,EAAE,EAAE,CAAC,QAAQ;oBACrB,IAAI,EAAE,EAAE,CAAC,IAAI;iBACd,CAAC,CAAC;aACJ;SACF,CACF,CAAC;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curless/agentbank-merchant-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Merchant-side SDK for agentbank — accept agent payments: open a merchant-quoted checkout (you price it, an agent pays it), PaymentIntents, edge-safe webhook verification, x402 challenge helpers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|
|
41
41
|
"url": "git+https://gitlab.com/robin-ruan/agentbank.git",
|
|
42
|
-
"directory": "packages/merchant-sdk"
|
|
42
|
+
"directory": "packages/sdks/merchant-sdk"
|
|
43
43
|
},
|
|
44
44
|
"author": "robin",
|
|
45
45
|
"scripts": {
|