Coinbase api v1, problems creating a payment button

293 views Asked by At

So, i'm trying to create a button

<div id="coinbasetest" class="coinbase-button" data-code="6ad16caf532b5d802a1141766ee4d823" data-button-style="none"></div><script src="https://www.coinbase.com/assets/button.js" type="text/javascript"></script>

(This is just a temporarily div), I replace the "data-code" attribute with another value through ajax and php script. The problem is, when i replace it, it doesn't work. It says it can't find the model.. and it CLEARLY matches up

See image for console log: https://i.stack.imgur.com/diCOs.png

Ajax:

success: function(response) {
                            var test = document.getElementById('coinbasetest');
                            test.setAttribute("data-code", response.buttonCode);
                            console.log(test);
                            $(document).trigger('coinbase_show_modal', response.buttonCode);

If I just replace the data-button with a "static" one, it seems to work but the data-code is not static because my checkout depends on what the other users decide to purchase!

2

There are 2 answers

4
mardlin On

Apparently, once you set the data-token, you can no longer change it otherwise it won't work. Any suggestions over this? I don't want to redirect to another page and i want to use my own button

Correct. What's happening is the modal is created when the page first loads, so switching out the data-code later on doesn't do anything useful.

The way we recommend handling this is:

  1. Use a static image of our button (available here) on your page when it first loads,
  2. Get a new button code from the API (v1) (v2)
  3. Generate an iFrame using the new button code
  4. Display the iFrame in a modal which you create yourself.
0
user3123747 On

After adding the coinbase-button class, the only required parameter is data-code which hard codes the name, price, and description fields (these are set at the time the button is created and cannot be changed later).

Apparently they can't be changed afterwards for some reason, anyone know why?