Cancel Invoice

Cancel an open invoice to prevent payment
View as Markdown

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 * as errors from "@gwop/sdk/models/errors";
2
3try {
4 await gwop.invoices.cancel({ id: paidInvoiceId });
5} catch (err) {
6 if (err instanceof errors.ErrorResponse) {
7 err.data$.error.code;
8 // "INVOICE_CANCEL_NOT_ALLOWED"
9 err.data$.error.message;
10 // "Cannot cancel invoice with status PAID. Only OPEN invoices can be canceled."
11 }
12}

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