coinbase / coinbase-commerce-node

Coinbase Commerce Node
MIT License
148 stars 54 forks source link

cancel a charge #64

Closed hippolyte42 closed 2 years ago

hippolyte42 commented 2 years ago

Is their a way to cancel a charge currently implemented with this package or plans to integrate such a feature in the near future? thank you

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);
  }
};
hippolyte42 commented 2 years ago

closed because duplicate