How to check whether my ipn page is called by coinbase ping webhook notification

317 views Asked by At

I have built a website using CodeIgniter and php coinbase API. I have ipn file located at /var/www/html/ with 0777 permission. It is not being called when deposits are made to my coinbase BTC wallet. Other API calls like creating wallet addresses, listing transactions are working fine.

Below is code from coinbasedepositipn.php file. The file pushes the notification raw body received to a method in Notifications controller using curl.

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  $raw_body = file_get_contents('php://input');
  $signature = $_SERVER['HTTP_CB_SIGNATURE'];
  $data=array();
  $data["rawbody"] = $raw_body ;
  $data["signature"] = $signature;
  $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
  $url=$protocol.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/index.php/notifications/coinbasedepositipn";

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  $headers = [
    "accept: application/json;charset=utf-8"
  ];
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  // Execute
  $sitecontent = curl_exec($ch);
  if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
  }
  // Closing
  curl_close($ch);
  echo "$sitecontent <br><br> Notification done successfully.";
}

So I want to send "ping" notification to my server to check if everything is ok with my ipn file. Description of their API is saying that "Ping notification can be sent at any time to verify that the notification URL is functioning" But can't find how to send ping to my ipn page and know that my file is accessible from coinbase server endpoint.

Hope you can help me to find a way to send a ping notification. Thanks in advance.

0

There are 0 answers