1. Go to this page and download the library: Download borsaco/coinbase-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
borsaco / coinbase-bundle example snippets
$code = "2G3GM4X9";
/**
* get a single charge
* @var Charge $charge
*/
$charge = $coinbaseHandler->showCharge($code);
$hosted_url = $charge->getHostedUrl();
/**
* list charges
* @var Charges $charges
*/
$charges = $this->_coinbaseHandler->listCharges();
//iterate through the charges
foreach ($charges->getData() as $charge){
print_r($charge);
}
/**
* @Route("/webhooks/", name="webhooks")
* @throws \Exception
*/
public function webHook(Request $request, CoinbaseHandler $coinbaseHandler){
if ($request->getMethod() != 'POST') {
return new Response( 'Only post requests accepted!', 400);
}
$jsonString = $request->getContent();//get the json string from the request
// This header contains the SHA256 HMAC signature of the raw request payload
$cc_signagure = isset($_SERVER["HTTP_X_CC_WEBHOOK_SIGNATURE"]) ? $_SERVER["HTTP_X_CC_WEBHOOK_SIGNATURE"] : '';
if(!$coinbaseHandler->validateWebhookSignature($cc_signagure, $request)){
throw new \Exception("Request could not be validated");
}
/** @var Webhook $webhook */
$webhook = $coinbaseHandler->parseWebhook($jsonString);
//You have your webhook object. Do Something... save webhook data to database or email people or anything useful
if($webhook->getEvent()->getType() == Event::TYPE_CHARGE_CREATED){
//Do Something
}
return new Response('',Response::HTTP_OK, array('Content-Type' => 'text/html'));//make sure you respond with status 200 (OK) at the end
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.