For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Apply for AccessDashboard
Guides
Guides
  • Get Started
    • Introduction
    • Quickstart
  • Agent Identity
    • Overview
    • Create Auth Intent
    • Exchange for JWT
    • Sessions
    • JWKS
  • Agent Checkout
    • Overview
    • Create an Invoice
    • List Invoices
    • Get Invoice
    • Cancel Invoice
  • Integration Patterns
    • Overview
    • Shared SDK Client
    • Wallet Auth
    • JWT Verification
    • Subscription Checkout
    • Webhook Verification
  • Concepts
    • Two Invoice IDs
    • Wallet Identity
    • Session vs Token
    • Webhook-Driven State
  • Webhooks
    • Overview
    • Verify Signatures
  • Reliability
    • Errors
    • SDK Reference
Apply for AccessDashboard
On this page
  • Cancel an invoice
  • Response
  • Idempotent cancellation
  • Only OPEN invoices can be canceled
  • After cancellation
  • Next step
Agent Checkout

Cancel Invoice

Cancel an open invoice to prevent payment
||View as Markdown|
Was this page helpful?
Edit this page
Previous

Get Invoice

Next

Integration Patterns

Built with

Cancel an invoice

Cancel an open invoice. Only OPEN invoices can be canceled.

1import { Gwop } from "@gwop/sdk";
2
3const gwop = new Gwop({
4 merchantApiKey: process.env.GWOP_MERCHANT_API_KEY,
5});
6
7const { result } = await gwop.invoices.cancel({
8 id: "e136eabd-5185-4331-8aa4-b020c9bd9b57", // merchant-side UUID
9});
10
11console.log(result.status); // "CANCELED"
12console.log(result.canceledAt); // 2026-03-25T01:52:51.023Z

Cancel takes the merchant-side UUID (id), not the public inv_* identifier. This is the id you received from invoices.create().

Response

1{
2 "id": "e136eabd-5185-4331-8aa4-b020c9bd9b57",
3 "status": "CANCELED",
4 "canceledAt": "2026-03-25T01:52:51.023Z"
5}
FieldTypeDescription
idstringMerchant-side UUID
statusstringAlways "CANCELED"
canceledAtDateCancellation timestamp

Idempotent cancellation

Canceling an already-canceled invoice returns success — no error is thrown. This makes retries safe:

1// Both calls succeed
2await gwop.invoices.cancel({ id: invoiceId });
3await gwop.invoices.cancel({ id: invoiceId }); // same response

Only OPEN invoices can be canceled

Attempting to cancel a PAID, EXPIRED, or PAYING invoice throws an error:

1import { ErrorCode, isGwopError } from "@gwop/sdk/errors";
2
3try {
4 await gwop.invoices.cancel({ id: paidInvoiceId });
5} catch (err) {
6 if (isGwopError(err, ErrorCode.InvoiceCancelNotAllowed)) {
7 // Only OPEN invoices can be canceled
8 }
9}

After cancellation

Once canceled:

  • The invoice status becomes CANCELED
  • Payment methods are removed from the public view
  • The invoice.canceled webhook fires (if configured)
  • The invoice is no longer payable

Next step

List Invoices

Query all invoices with pagination and status filtering

Invoices Overview

How invoices work, lifecycle, and what you can sell