0

I want to accept bitcoin payment using the Coinbase Commerce API. I have created a charge using curl. Now I want to create a webhook to verify payment status.

I crate webhook as below (https://github.com/coinbase/coinbase-commerce-php/blob/master/examples/Webhook/Webhook.php)

require_once __DIR__ . "/vendor/autoload.php";

use CoinbaseCommerce\Webhook;

$secret = 'SECRET_KEY';
$headerName = 'X-Cc-Webhook-Signature';
$headers = getallheaders();
$signraturHeader = isset($headers[$headerName]) ? $headers[$headerName] : null;
$payload = trim(file_get_contents('php://input'));

try {
    $event = Webhook::buildEvent($payload, $signraturHeader, $secret);
    http_response_code(200);
    echo sprintf('Successully verified event with id %s and type %s.', $event->id, $event->type);
} catch (\Exception $exception) {
    http_response_code(400);
    echo 'Error occured. ' . $exception->getMessage();
}

I try to call using GET and POST Method. Getting $payload and $signraturHeader blank.

John Conde
  • 217,595
  • 99
  • 455
  • 496
  • they are probably the headers used to send you the hash / certificate so that you can be sure that the request you have received actually comes from them, and not from someone else – Alberto Sinigaglia Apr 07 '21 at 11:04
  • When i test form "Webhook subscriptions(https://commerce.coinbase.com/dashboard/settings)" send test show error-> Failed to establish a connection to the remote server at www.xxx.com @Berto99 –  Apr 07 '21 at 11:09
  • Have you installed the [official PHP library for CoinBase](https://github.com/coinbase/coinbase-commerce-php#installation)? Checked the error logs? – KIKO Software Apr 07 '21 at 11:16
  • 1
    _“Failed to establish a connection to the remote server at www.xxx.com”_ sounds like it could not reach your server at all. Are you sure you uploaded this to somewhere where it is publicly available, without any access restrictions? – CBroe Apr 07 '21 at 11:16
  • Yes @KIKOSoftware –  Apr 07 '21 at 11:17
  • Yes Dear, @CBroe –  Apr 07 '21 at 11:26
  • Can you give us a URL to verify that? _“I try to call using GET and POST Method”_ - if you want to test this by making the request yourself, then you would of course need to provide a proper signature value in that header. And using GET makes little sense to begin with, as this tries to read from `php://input`, which takes the data from the request body, which usually only POST request have. – CBroe Apr 07 '21 at 11:31
  • Does anyone solved this problem? – Pablo Mar 04 '22 at 13:56

0 Answers0