@agorio/sdkDocs


Class: Ap2Client

Constructors

new Ap2Client()

new Ap2Client(options): Ap2Client

Parameters

options: Ap2ClientOptions

Returns

Ap2Client

Defined in

src/client/ap2-client.ts:249

Methods

attachCart()

attachCart(intent, lineItems): CartMandate

Attach line items to an IntentMandate, producing a CartMandate. Validates that the sum of line items matches the declared amount.

Parameters

intent: IntentMandate

lineItems: CartLineItem[]

Returns

CartMandate

Defined in

src/client/ap2-client.ts:350


attachX402Payment()

attachX402Payment<T>(mandate, instrument): T & object

Attach an x402 stablecoin payment instrument to a mandate. (v0.10)

Produces an X402Mandate — the receiver routes to on-chain settlement and returns an X402SettlementProof. Works on any IntentMandate variant.

Type Parameters

T extends IntentMandate

Parameters

mandate: T

instrument: X402PaymentInstrument

Returns

T & object

Defined in

src/client/ap2-client.ts:339


createDelegatedMandate()

createDelegatedMandate(params): DelegatedMandate

Create a DelegatedMandate authorizing payment on behalf of a principal. (v0.10)

The delegate (whoever this client signs as) is authorized by principal through chain. Sign + submit like any other mandate; receivers verify the delegate’s signature, then walk delegation.chain back to the principal.

Parameters

params

params.amount: string

params.chain: DelegationLink[]

params.currency: string

params.delegate: string

params.principal: string

Returns

DelegatedMandate

Defined in

src/client/ap2-client.ts:310


createIntentMandate()

createIntentMandate(params): IntentMandate

Create an IntentMandate — the first step in the AP2 flow. The mandate declares the intended payment before cart contents are known.

Parameters

params

params.amount: string

params.currency: string

Returns

IntentMandate

Defined in

src/client/ap2-client.ts:262


createRefundMandate()

createRefundMandate(params): RefundMandate

Create a RefundMandate that refunds an existing IntentMandate. (v0.9)

Sign + submit the result with the same sign() / submitPayment() flow you use for IntentMandates — receivers can distinguish via mandate.originalMandateId.

Parameters

params

params.amount: string

params.currency: string

params.originalMandateId: string

params.reason?: string

Returns

RefundMandate

Defined in

src/client/ap2-client.ts:284


isExpired()

isExpired(mandate): boolean

Check whether a mandate has expired.

Parameters

mandate: IntentMandate

Returns

boolean

Defined in

src/client/ap2-client.ts:425


pay()

pay(params): Promise<Ap2PaymentResult>

Full flow: create intent → attach cart → sign → submit. Convenience method for single-call usage.

Parameters

params

params.amount: string

params.currency: string

params.lineItems: CartLineItem[]

params.paymentEndpoint: string

Returns

Promise<Ap2PaymentResult>

Defined in

src/client/ap2-client.ts:433


sign()

sign<T>(mandate): Promise<SignedMandate<T>>

Sign a mandate (IntentMandate or CartMandate). Returns a SignedMandate ready for submission.

Type Parameters

T extends IntentMandate

Parameters

mandate: T

Returns

Promise<SignedMandate<T>>

Defined in

src/client/ap2-client.ts:369


submitPayment()

submitPayment(signed, paymentEndpoint): Promise<Ap2PaymentResult>

Submit a signed mandate to a payment endpoint. In production this would call the merchant’s AP2-compliant payment gateway.

Parameters

signed: SignedMandate<CartMandate>

paymentEndpoint: string

Returns

Promise<Ap2PaymentResult>

Defined in

src/client/ap2-client.ts:387