Coinbase button creation and callback

0 votes

Im trying to create a button and assign a callback URL with coinbase.

I'm getting some CAPTCHA data returned when trying to post to coinbase API.

I think my webhost is getting blocked by CloudFlare, disabling my code.

Here's what I have:

<a class="coinbase-button" data-code="<?php

$data = array(
  "button" => array(
    "name" => "Ticket",
    "price_string" => "0.01",
    "price_currency_iso" => "BTC",
    "custom" => $OrderNext . "- " . $ticket,
    "callback_url" => "",
    "description" => "Ticket - " . $ticket ,
    "type" => "buy_now",
    "style" => "buy_now_large"

$json_data = json_encode($data);                                                                                   

$ch = curl_init("");

curl_setopt($ch, CURLOPT_POST, 1);                                                                  
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);                                                                  
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
  'Content-Type: application/json',                                                                                
  'Content-Length: ' . strlen($json_data))                                                                       

if( ! $output = curl_exec($ch))

$result = json_decode($output);

$output returns a CAPTCHA page.

$result is null.

How do I solve this problem?

Aug 31, 2018 in Blockchain by digger
• 27,620 points

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

I got the solution for this on the internet somewhere

Brian from Coinbase here. It looks like you are hitting the API to generate a new payment button for each page load which, depending on the amount of traffic you get, could trigger our rate limiting either internally or through CloudFlare.

We currently have the merchant create button api limited to 10,000 calls per day internally, for example, for most merchants.

A better approach would be to hit the API once for each product (or if the price changes) and store the resulting 'code' parameter. If you save this in your database you can reuse it on every page load. This will help your pages load faster also.

More details:

Hope it helps!

answered Aug 31, 2018 by slayer
• 29,040 points
0 votes

You can use the following code for generating button for payment:

$apikey ="***************"; 
   $apisecret = "************************";
   $nonce = sprintf('%0.0f',round(microtime(true) * 1000000));

   $url = "" . $nonce;

   $parameters = [];
   $parameters["button"]["name"] = "Checkout Invoice";
   $parameters["button"]["custom"] = $orderId;
   $parameters["button"]["price_string"] = $priceString;
   $parameters["button"]["type"] = "buy_now";
   $parameters["button"]["subscription"] = false;
   $parameters["button"]["price_currency_iso"] = "USD";
   $parameters["button"]["description"] = "Checkout Invoice";
   $parameters["button"]["style"] = "custom_large";
   $parameters["button"]["include_email"] = true;
   $parameters["button"]["callback_url"] = url("bitcoin/callback");
   $parameters = http_build_query($parameters, true);

  $signature = hash_hmac("sha256", $nonce . $url . $parameters, $apisecret);

   $ch = curl_init();

   curl_setopt_array($ch, array(
       CURLOPT_URL => $url,
       CURLOPT_HTTPHEADER => array(
           "ACCESS_KEY: " . $apikey,
           "ACCESS_NONCE: " . $nonce,
           "ACCESS_SIGNATURE: " . $signature

   curl_setopt_array($ch, array(
       CURLOPT_POSTFIELDS => $parameters,
       CURLOPT_POST => true,

   $response = curl_exec($ch);


   $decodeResponse = json_decode($response);
answered Sep 3, 2018 by Nitika

Related Questions In Blockchain

0 votes
1 answer

Can't get simple Coinbase button in Node to work

Try this //- Incoming params: title, user, message, ...READ MORE

answered Sep 10, 2018 in Blockchain by digger
• 27,620 points
0 votes
1 answer

Nodejs Express: Getting different output in console.log and callback

If your getOrderStatus() function is like this: function getOrderStatus(_orderId, callback) ...READ MORE

answered Oct 9, 2018 in Blockchain by Omkar
• 65,820 points
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
0 votes
1 answer
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.