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" => "https://x.com/callback.php",
    "description" => "Ticket - " . $ticket ,
    "type" => "buy_now",
    "style" => "buy_now_large"
  )
);                                                                    

$json_data = json_encode($data);                                                                                   

$ch = curl_init("https://coinbase.com/api/v1/buttons?api_key=xxxxxxxxxxxxxxxxxxxxxx");

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))
  {
        trigger_error(curl_error($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
• 26,550 points
82 views

2 answers to this question.

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: www.coinbase.com/api/doc/1.0/buttons/create.html

Hope it helps!

answered Aug 31, 2018 by slayer
• 29,050 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 = "https://api.sandbox.coinbase.com/v1/buttons?nonce=" . $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_RETURNTRANSFER => true,
       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);

   curl_close($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
• 26,550 points
25 views
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
• 67,480 points
26 views
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,340 points
76 views
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
141 views
0 votes
1 answer
0 votes
1 answer