coinbase / coinbase-commerce-node

Coinbase Commerce Node
MIT License
148 stars 54 forks source link

Cancel a charge #12

Closed borodadada closed 5 years ago

borodadada commented 5 years ago

Hello, how i can delete( cancel) charge ? I have 2 charge where both timeline expired. Or after some time they delete automatically?

guacamoli commented 5 years ago

Here’s the API docs on how to cancel a charge: https://commerce.coinbase.com/docs/api/#cancel-a-charge.

Additionally, a charge is marked as expired if no payment is detected within 60 minutes of charge creation. However, if a payment comes in after 60 minutes but within 7 days of charge creation, the payment will still be detected and accounted for.

Here’s a diagram of all the payment statuses that can occur: https://commerce.coinbase.com/docs/images/payment_statuses_diagram.png

basit1327 commented 5 years ago

Is this library doesn't have any method to delete a charge , retrieve etc

penielny commented 3 years ago

how do I cancel it with node js integration

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);
  }
};