Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coinbase.resources.Charge.cancel #51

Open
joekim opened this issue Jul 6, 2021 · 1 comment
Open

coinbase.resources.Charge.cancel #51

joekim opened this issue Jul 6, 2021 · 1 comment

Comments

@joekim
Copy link

joekim commented Jul 6, 2021

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: #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.

@hippolyte42
Copy link

hippolyte42 commented Jun 30, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants