Open joekim opened 3 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);
}
};
The coinbase commerce API has an affordance to cancel charges this node library should support this API call.
https://commerce.coinbase.com/docs/api/#cancel-a-charge
This issue was previously brought up with: https://github.com/coinbase/coinbase-commerce-node/issues/38
Why would someone need to cancel a charge if it's just going to expire? One scenario is if the user is given less than the expiration time to complete the charge and the system wants to explicitly close the charge to prevent payment if it hasn't been done yet.