0

I want to accept bitcoin payment using coinbase commerce API(https://commerce.coinbase.com/docs/api/)

I was created a payment address using curl as below.

$curl = curl_init();
$postFilds=array(
    'name' => 'Test Name',
    'description' => 'Testing for checkout api',
    'pricing_type' => 'fixed_price',
    'local_price' => [
        'amount' => '100.00',
        'currency' => 'USD'
    ],
    'requested_info' => ['Test', 'test@gmail.com'],
    'metadata' => ['userId'=>10]
);
$postFilds=urldecode(http_build_query($postFilds));
curl_setopt_array($curl, 
    array(
        CURLOPT_URL => "https://api.commerce.coinbase.com/charges",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => $postFilds,
            CURLOPT_HTTPHEADER => array(
                "X-CC-Api-Key: api_key",
                "X-CC-Version: 2018-03-22",
                "content-type: multipart/form-data"
            ),
        )
);
$response = curl_exec($curl);

now I want to check payment status is failed or successes using curl OR PHP

I don't know how to use webhook. my site is in laravel 5

Thank You!

  • 1
    https://github.com/coinbase/coinbase-commerce-php/blob/master/examples/Webhook/Webhook.php – KIKO Software Apr 06 '21 at 11:11
  • Error occured. Invalid payload provided. No JSON object could be decoded, What is "X-Cc-Webhook-Signature" and how to get it ? @KIKOSoftware –  Apr 06 '21 at 11:23
  • Read the comment in the code. You need to replace `SECRET_KEY`, and leave `X-Cc-Webhook-Signature` as it is. – KIKO Software Apr 06 '21 at 11:35
  • Yes, I do it and respond 200 in ajax call but giving error -> "Error occured. Invalid payload provided. No JSON object could be decoded." –  Apr 06 '21 at 11:41
  • The payload is supposed to come from CoinBase. When you're running the code there is (probably) no payload. You need to configure your webhook in CoinBase. – KIKO Software Apr 06 '21 at 11:47
  • Here's a [basic explanation of a webhook](https://blog.codeanalogies.com/2018/03/05/the-difference-between-apis-and-webhooks-explained/) – KIKO Software Apr 06 '21 at 11:52

0 Answers0