Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Conversation

@SlayerAnsh
Copy link

@SlayerAnsh SlayerAnsh commented Jun 29, 2022

This pull request targets on adding Cancel Charge feature.

Important use case:

  1. Cancel a charge before the default timeout
  2. In some manual integration, to disable user from completing payment, canceling charge can be used.

Changes:

  1. Added cancel crud method
  2. Added cancel test

Note: Verification with actual api call is left. If someone can verify it, it would be really helpful.

@SlayerAnsh
Copy link
Author

Targets issues: #64 #51 #38 #12

@hjacque
Copy link

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

@SlayerAnsh
Copy link
Author

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)

@hjacque
Copy link

hjacque commented Jun 30, 2022

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)

real weird the api key isn't required, I shall keep it tho, just in case since it should be

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants