@curless/agentbank-merchant-sdk 0.1.5 → 0.2.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/README.md +30 -1
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +7 -1
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/resources/checkout.d.ts +30 -0
- package/dist/resources/checkout.d.ts.map +1 -0
- package/dist/resources/checkout.js +29 -0
- package/dist/resources/checkout.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,7 +5,8 @@ Drop into a merchant's backend (Shopify storefront, ClubMed booking flow,
|
|
|
5
5
|
TikTok Shop seller service, anything that wants to **accept agent payments**)
|
|
6
6
|
and you get:
|
|
7
7
|
|
|
8
|
-
- **`
|
|
8
|
+
- **`checkout.open`** — the fast path. **You** price an order from your own catalog and open a checkout; an agent pays it; the money lands in your account. agentbank never stores your catalog — the price you pass is authoritative. You accept every agent-payment protocol (ACP, x402, A2A, UCP, AP2, …) with zero protocol code.
|
|
9
|
+
- **`AgentbankMerchant`** — typed client; also exposes `PaymentIntents` (create/get/capture/list/ledger-entries across ACP / x402 / AP2 / UCP / A2A), `PaymentLinks`, `Customers`, `BalanceTransactions`, and `WebhookEndpoints`. No refund method — refunds are Curless-originated (see below).
|
|
9
10
|
- **`verifyWebhook` / `parseVerifiedWebhook`** — HMAC-SHA256 signature verification (Stripe-style `t=…,v1=…`), constant-time, **edge-safe** (Web Crypto, runs on Vercel Edge / Cloudflare Workers). Async — `await` them.
|
|
10
11
|
- **`x402`** — `buildChallenge()` to emit your own canonical 402 from your route, `decodeXPaymentHeader()` to parse what the agent paid with.
|
|
11
12
|
|
|
@@ -16,6 +17,34 @@ One runtime dependency (`@curless/agentbank-core`, for portable crypto + the HTT
|
|
|
16
17
|
> forwards the event, which advances the PI to `refunded` / `partially_refunded`.
|
|
17
18
|
> Read the resulting state via `paymentIntents.get()` / `.list()`.
|
|
18
19
|
|
|
20
|
+
### Fast path — open a merchant-quoted checkout
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { AgentbankMerchant } from '@curless/agentbank-merchant-sdk';
|
|
24
|
+
|
|
25
|
+
const agentbank = new AgentbankMerchant({
|
|
26
|
+
baseUrl: 'https://mcp.curless.ai',
|
|
27
|
+
apiKey: process.env.AGENTBANK_MERCHANT_TOKEN!, // merchant:write
|
|
28
|
+
merchantId: process.env.AGENTBANK_MERCHANT_ID!,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// In your "an agent wants to buy" handler: YOU set the price.
|
|
32
|
+
const checkout = await agentbank.checkout.open({
|
|
33
|
+
currency: 'EUR',
|
|
34
|
+
items: [
|
|
35
|
+
{ sku: 'resort-bali', name: 'Club Med Bali — 7 nights', quantity: 1, unitPrice: 192000 },
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Hand checkout.id back to the buyer agent; it pays, money lands in your account.
|
|
40
|
+
return { checkoutId: checkout.id, amount: checkout.amount, currency: checkout.currency };
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
That's the whole integration: install, set three env vars, call `checkout.open`.
|
|
44
|
+
You stay the source of truth for your catalog and prices — nothing to sync.
|
|
45
|
+
|
|
46
|
+
### Lower-level — PaymentIntents, webhooks, x402
|
|
47
|
+
|
|
19
48
|
```ts
|
|
20
49
|
import { AgentbankMerchant, parseVerifiedWebhook, x402 } from '@curless/agentbank-merchant-sdk';
|
|
21
50
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FetchLike, type RequestOptions } from '@curless/agentbank-core';
|
|
2
2
|
import { BalanceTransactionsResource } from './resources/balance-transactions.js';
|
|
3
|
+
import { CheckoutResource } from './resources/checkout.js';
|
|
3
4
|
import { CustomersResource } from './resources/customers.js';
|
|
4
5
|
import { PaymentIntentsResource } from './resources/payment-intents.js';
|
|
5
6
|
import { PaymentLinksResource } from './resources/payment-links.js';
|
|
@@ -8,14 +9,17 @@ export type { FetchLike, RequestOptions } from '@curless/agentbank-core';
|
|
|
8
9
|
export type AgentbankMerchantOptions = {
|
|
9
10
|
baseUrl: string;
|
|
10
11
|
apiKey: string;
|
|
12
|
+
merchantId?: string;
|
|
11
13
|
fetch?: FetchLike;
|
|
12
14
|
timeoutMs?: number;
|
|
13
15
|
};
|
|
14
16
|
export declare class AgentbankMerchant {
|
|
15
17
|
readonly baseUrl: string;
|
|
18
|
+
readonly merchantId: string | undefined;
|
|
16
19
|
private readonly fetchImpl;
|
|
17
20
|
private readonly apiKey;
|
|
18
21
|
private readonly timeoutMs;
|
|
22
|
+
readonly checkout: CheckoutResource;
|
|
19
23
|
readonly paymentIntents: PaymentIntentsResource;
|
|
20
24
|
readonly paymentLinks: PaymentLinksResource;
|
|
21
25
|
readonly webhookEndpoints: WebhookEndpointsResource;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAsB,MAAM,yBAAyB,CAAC;AAClG,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAE5E,YAAY,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzE,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAEhB,MAAM,EAAE,MAAM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BAAiB,CAAC;IACtC,QAAQ,CAAC,mBAAmB,EAAE,2BAA2B,CAAC;gBAE9C,IAAI,EAAE,wBAAwB;IAc1C,gBAAgB;IACV,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;CAetF"}
|
package/dist/client.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { buildUrl, sendJson } from '@curless/agentbank-core';
|
|
2
2
|
import { BalanceTransactionsResource } from './resources/balance-transactions.js';
|
|
3
|
+
import { CheckoutResource } from './resources/checkout.js';
|
|
3
4
|
import { CustomersResource } from './resources/customers.js';
|
|
4
5
|
import { PaymentIntentsResource } from './resources/payment-intents.js';
|
|
5
6
|
import { PaymentLinksResource } from './resources/payment-links.js';
|
|
6
7
|
import { WebhookEndpointsResource } from './resources/webhook-endpoints.js';
|
|
7
8
|
// Merchant-side client for agentbank. Wraps the HTTP surface a merchant
|
|
8
|
-
// integrates against:
|
|
9
|
+
// integrates against: open a merchant-quoted checkout (you price it, an agent
|
|
10
|
+
// pays it — checkout.open), create + capture PaymentIntents (any protocol),
|
|
9
11
|
// manage webhook subscriptions, query PI status. Webhook verification
|
|
10
12
|
// + x402 challenge helpers live in ./webhooks and ./x402 as pure
|
|
11
13
|
// functions (no client needed).
|
|
12
14
|
export class AgentbankMerchant {
|
|
13
15
|
baseUrl;
|
|
16
|
+
merchantId;
|
|
14
17
|
fetchImpl;
|
|
15
18
|
apiKey;
|
|
16
19
|
timeoutMs;
|
|
20
|
+
checkout;
|
|
17
21
|
paymentIntents;
|
|
18
22
|
paymentLinks;
|
|
19
23
|
webhookEndpoints;
|
|
@@ -21,9 +25,11 @@ export class AgentbankMerchant {
|
|
|
21
25
|
balanceTransactions;
|
|
22
26
|
constructor(opts) {
|
|
23
27
|
this.baseUrl = opts.baseUrl.replace(/\/+$/, '');
|
|
28
|
+
this.merchantId = opts.merchantId;
|
|
24
29
|
this.apiKey = opts.apiKey;
|
|
25
30
|
this.fetchImpl = opts.fetch ?? fetch;
|
|
26
31
|
this.timeoutMs = opts.timeoutMs;
|
|
32
|
+
this.checkout = new CheckoutResource(this);
|
|
27
33
|
this.paymentIntents = new PaymentIntentsResource(this);
|
|
28
34
|
this.paymentLinks = new PaymentLinksResource(this);
|
|
29
35
|
this.webhookEndpoints = new WebhookEndpointsResource(this);
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAClG,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAClG,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAkB5E,wEAAwE;AACxE,8EAA8E;AAC9E,4EAA4E;AAC5E,sEA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EAAE;SACvC,CAAC;QACF,IAAI,IAAI,CAAC,cAAc;YAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1E,OAAO,QAAQ,CACb,IAAI,CAAC,SAAS,EACd,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EACxC,MAAM,EACN,OAAO,EACP,IAAI,CAAC,IAAI,EACT,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,EAAE,CACrE,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { AgentbankMerchant } from './client.js';
|
|
|
2
2
|
export type { AgentbankMerchantOptions, FetchLike, RequestOptions, } from './client.js';
|
|
3
3
|
export { AgentbankError } from '@curless/agentbank-core';
|
|
4
4
|
export type { BalanceTransaction, Customer, CustomerStatus, LedgerEntryView, Paginated, PaymentIntent, PaymentIntentLedger, PaymentIntentStatus, PaymentLink, PaymentLinkItem, PaymentLinkStatus, PaymentProtocol, WebhookEndpoint, WebhookEndpointWithSecret, X402PaymentRequirements, } from './types.js';
|
|
5
|
+
export type { Checkout, CheckoutLineItem, OpenCheckoutInput, } from './resources/checkout.js';
|
|
5
6
|
export type { CreateCustomerInput, UpdateCustomerInput } from './resources/customers.js';
|
|
6
7
|
export type { CreatePaymentIntentInput } from './resources/payment-intents.js';
|
|
7
8
|
export type { CreatePaymentLinkInput } from './resources/payment-links.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,YAAY,EACV,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,eAAe,EACf,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACzF,YAAY,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,YAAY,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAC3E,YAAY,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,CAAC;AAChB,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,YAAY,EACV,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,eAAe,EACf,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACzF,YAAY,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,YAAY,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAC3E,YAAY,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,CAAC;AAChB,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMhD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMhD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AA2BzD,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC;AAEvB,qEAAqE;AACrE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AgentbankMerchant } from '../client.js';
|
|
2
|
+
export type CheckoutLineItem = {
|
|
3
|
+
/** Your product id / SKU. */
|
|
4
|
+
sku: string;
|
|
5
|
+
quantity: number;
|
|
6
|
+
/** Minor units (e.g. cents). YOU set this from your own catalog. */
|
|
7
|
+
unitPrice: number;
|
|
8
|
+
name?: string;
|
|
9
|
+
};
|
|
10
|
+
export type OpenCheckoutInput = {
|
|
11
|
+
items: CheckoutLineItem[];
|
|
12
|
+
/** Must match your merchant account's currency (USD/EUR/USDT/USDC). */
|
|
13
|
+
currency: string;
|
|
14
|
+
/** Overrides the client's configured `merchantId` for this call. */
|
|
15
|
+
merchantId?: string;
|
|
16
|
+
};
|
|
17
|
+
export type Checkout = {
|
|
18
|
+
/** The checkout id the buyer agent completes to pay. */
|
|
19
|
+
id: string;
|
|
20
|
+
status: string;
|
|
21
|
+
/** Total in minor units. */
|
|
22
|
+
amount: number;
|
|
23
|
+
currency: string;
|
|
24
|
+
};
|
|
25
|
+
export declare class CheckoutResource {
|
|
26
|
+
private readonly client;
|
|
27
|
+
constructor(client: AgentbankMerchant);
|
|
28
|
+
open(input: OpenCheckoutInput): Promise<Checkout>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -0,0 +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;AAEtD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,wDAAwD;IACxD,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAKF,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,iBAAiB;IAEhD,IAAI,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC;CA0BxD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Merchant-quoted checkout: YOU price the order from your own catalog and open
|
|
2
|
+
// a checkout; an agent pays it; the money lands in your account. agentbank
|
|
3
|
+
// never stores your catalog — the price you pass here is authoritative.
|
|
4
|
+
export class CheckoutResource {
|
|
5
|
+
client;
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
async open(input) {
|
|
10
|
+
const merchantId = input.merchantId ?? this.client.merchantId;
|
|
11
|
+
if (!merchantId) {
|
|
12
|
+
throw new Error('merchantId is required — set it on AgentbankMerchant({ merchantId }) or pass it to open()');
|
|
13
|
+
}
|
|
14
|
+
const session = await this.client.request('POST', `/acp/${encodeURIComponent(merchantId)}/checkout_sessions`, {
|
|
15
|
+
body: {
|
|
16
|
+
currency: input.currency,
|
|
17
|
+
items: input.items.map((it) => ({
|
|
18
|
+
id: it.sku,
|
|
19
|
+
quantity: it.quantity,
|
|
20
|
+
unitPrice: it.unitPrice,
|
|
21
|
+
name: it.name,
|
|
22
|
+
})),
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const amount = session.totals?.find((t) => t.type === 'total')?.amount ?? 0;
|
|
26
|
+
return { id: session.id, status: session.status, amount, currency: session.currency };
|
|
27
|
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EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;IACxF,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curless/agentbank-merchant-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Merchant-side SDK for agentbank — accept agent payments: PaymentIntents, edge-safe webhook verification, x402 challenge helpers.",
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
7
7
|
"main": "dist/index.js",
|