1. Go to this page and download the library: Download forecho/coinbase 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/ */
namespace App\Jobs\CoinbaseWebhooks;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Forecho\Coinbase\Models\CoinbaseWebhookCall;
class HandleCreatedCharge implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/** @var \Forecho\Coinbase\Models\CoinbaseWebhookCall */
public $webhookCall;
public function __construct(CoinbaseWebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}
public function handle()
{
// do your work here
// you can access the payload of the webhook call with `$this->webhookCall->payload`
}
}
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'coinbase::charge:created' => [
App\Listeners\ChargeCreatedListener::class,
],
];
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Forecho\Coinbase\Models\CoinbaseWebhookCall;
class ChargeCreatedListener implements ShouldQueue
{
public function handle(CoinbaseWebhookCall $webhookCall)
{
// do your work here
// you can access the payload of the webhook call with `$webhookCall->payload`
}
}
use Forecho\Coinbase\Models\CoinbaseWebhookCall;
CoinbaseWebhookCall::find($id)->process();
use Forecho\Coinbase\Models\CoinbaseWebhookCall;
class MyCustomWebhookCall extends CoinbaseWebhookCall
{
public function process()
{
// do some custom stuff beforehand
parent::process();
// do some custom stuff afterwards
}
}