Add parameters to redirect_url/cancel_url

Hi

This is my first time working with coinbase and coinbase api overall.

I have used the Stripe API before and there it’s possible to add parameters to the cancel/redirect url like so:

      success_url: `${DOMAIN}status?session_id={CHECKOUT_SESSION_ID}`,
      cancel_url: `${DOMAIN}status?session_id={CHECKOUT_SESSION_ID}`,

Stripe automatically fills the {CHECKOUT_SESSION_ID} in.

I’m trying to do the same with Coinbase API (using node and coinbase-commerce-node package)
like so:

      redirect_url: `${DOMAIN}status?code={code}`,
      cancel_url: `${DOMAIN}status?code={code}`,

The code variable should be a charge code (like AJRIQ). Is this possible to do with the API? Or are there any other ways to do this?

Hello @MrGigi! Welcome to the forum! We appreciate your enthusiasm in trying out Coinbase APIs.

Just to confirm, you would like to fetch the charge_code in order to add parameters to the redirect_url/cancel_url? If so, you may push a POST request on https://api.commerce.coinbase.com/charges/ endpoint that will create a charge object and the response will return a charge_id and a charge_code.

Additionally, to be able to fetch all the charges made to an account, you may use the List charges endpoint for this.

We hope this helps and again, welcome to the community!

1 Like

Not quite, I’m already pushing a POST request to create a charge:

    const chargeData = {
      name: productName,
      description: productDescription,
      pricing_type: "fixed_price",
      local_price: {
        amount: productPrice,
        currency: productCurrency,
      },
      metadata: {
        discordID: req.body.discordid,
        tier: req.body.tier,
        email: req.body.email,
      },
      redirect_url: `${DOMAIN}status?code={code}`,
      cancel_url: `${DOMAIN}status?code={code}`,
    };

    const Charge = coinbase.resources.Charge;
    const chargeObj = await Charge.create(chargeData);

I need the code to be send back to the server with the customer when they are redirected back to my website, in order to show the status of the payment just like how I do it with stripe.

Basically, the status page gets the purchase id/code and shows if the purchase has been succesful or not and some other info about our product.

The status page is also server sided, there is no static html, the server “builds” a html page based on the purchase id/code and shows it to the user.

Hi @MrGigi! :wave: Good to have you back. Apologies as this does not turn out the way you expected.

Unfortunately, we cannot provide specific guidance on how to develop your application such as writing code in specific programming languages and frameworks. We are only able to provide guidance and troubleshooting for issues with the raw Coinbase APIs.

Although, we really want to help you out. So, we may suggest extracting the code from the Create a Charge API endpoint JSON response is to select the exact property you want and pull that out through dot notation, which in your case the “code” is the property you want to extract. In your end, this may be done by assigning variable to get the JSON response and by using the dot (.) notation, you can now get the “data” to “code” value (e.g. var responseJson = pm.response.json().data.code). If this example is not applicable to the programming language you are trying to use, you may utilize a compiler to convert it.

If the above suggestion works, you may now pass the “code” value to the Show a Charge API path endpoint to retrieve the details of the charge.

We hope this helps. Thank you for understanding and we hope you have a great day! :sun_behind_small_cloud:

1 Like

I know that I can extract the code from a json response, but that isn’t what I need or something that will work for my website. As there is no reliable way to store that code to a specific customer without using either a database or an account system, both of which we do not want for our website.

So if I get it right, at the moment, coinbase can’t create a charge and add the charge code to the redirect or cancel url like Stripe does? If so, it would be a great feature to request.

Hi @MrGigi! I would like to confirm that the only way to get the charge_code is by using Create a Charge API endpoint JSON response.

Regarding your request about storing the charge code without using a database or an account system, I’ve logged this as a feature request. Most new features and improvements to Coinbase products come directly from feedback like yours, so it’s very valuable to them. While Coinbase can’t offer any specific timeline for adding features, they are constantly working to build products that their customers will love.

If you want to stay up to date on the latest from Coinbase Cloud, you can also bookmark the following webpage and subscribe to email updates at the bottom of the page: https://www.coinbase.com/cloud/discover

Thank you and have a great day!

2 Likes