coinbase / coinbase-commerce-node

Coinbase Commerce Node
MIT License
144 stars 54 forks source link

coinbase.resources.Charge.cancel #38

Closed wallopthecat closed 3 years ago

wallopthecat commented 4 years ago

Any plans to support this?

BALTO245 commented 3 years ago

why would you need to cancel the charge if it will automatically expire?

hippolyte42 commented 2 years ago

wrote this small function that does the trick, let me know

import fetch from "node-fetch";

const cancelCharge = async (chargeCode: string, apiKey: string): Promise<void> => {
  try {
    await fetch(
      `https://api.commerce.coinbase.com/charges/${chargeCode}/cancel`,
      {
        method: "POST",
        headers: {
          "X-CC-Api-Key": apiKey,
          "X-CC-Version": "2018-03-22",
        },
      }
    );
  } catch (error) {
    console.log("cancelCharge error:", error);
  }
};