coinbase-commerce-node
coinbase-commerce-node copied to clipboard
Added cancel charge method
This pull request targets on adding Cancel Charge
feature.
Important use case:
- Cancel a charge before the default timeout
- In some manual integration, to disable user from completing payment, canceling charge can be used.
Changes:
- Added cancel crud method
- Added cancel test
Note: Verification with actual api call is left. If someone can verify it, it would be really helpful.
Targets issues: #64 #51 #38 #12
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);
}
};
wrote this small function that does the trick, let me know
const cancelCoinbaseCharge = 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("cancelCoinbaseCharge error:", error); } };
Yes, this works. I am using same using node-fetch
in express backend. You can remove X-CC-Api-Key
header as it is not required. (It should be required though)
wrote this small function that does the trick, let me know
const cancelCoinbaseCharge = 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("cancelCoinbaseCharge error:", error); } };
Yes, this works. I am using same using
node-fetch
in express backend. You can removeX-CC-Api-Key
header as it is not required. (It should be required though)
real weird the api key isn't required, I shall keep it tho, just in case since it should be