PHPackages                             antimech/coinbase - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. antimech/coinbase

ActiveLibrary

antimech/coinbase
=================

Laravel wrapper for the Coinbase Commerce API

v0.13.0(2y ago)823.3k—0%MITPHPPHP ^8.1

Since May 31Pushed 1y agoCompare

[ Source](https://github.com/antimech/laravel-coinbase)[ Packagist](https://packagist.org/packages/antimech/coinbase)[ RSS](/packages/antimech-coinbase/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (4)Versions (10)Used By (0)

Laravel wrapper for the Coinbase Commerce API
=============================================

[](#laravel-wrapper-for-the-coinbase-commerce-api)

This composer package is a SDK to Coinbase Commerce. It follows the "Laravel Way" and takes a lot of manual work from a developer.

[![Latest Stable Version](https://camo.githubusercontent.com/3a09d7f63cda1b4b589c0ba35de5cece2d581327e815f7e19b55102a051ac317/68747470733a2f2f706f7365722e707567782e6f72672f616e74696d6563682f636f696e626173652f76)](https://packagist.org/packages/antimech/coinbase)[![Total Downloads](https://camo.githubusercontent.com/88e5968a493c53692fd3163dfe73d4e138821e97de4c22c4958c7bfc496ddb11/68747470733a2f2f706f7365722e707567782e6f72672f616e74696d6563682f636f696e626173652f646f776e6c6f616473)](https://packagist.org/packages/antimech/coinbase)[![Latest Unstable Version](https://camo.githubusercontent.com/2802486c4b21727d94946d12013c0d17b10e4c0de9e1917d37338efc39ad7d29/68747470733a2f2f706f7365722e707567782e6f72672f616e74696d6563682f636f696e626173652f762f756e737461626c65)](https://packagist.org/packages/antimech/coinbase)[![License](https://camo.githubusercontent.com/e5c769bc98a575416e389f687a41c986dde322ab112c196ef8dc956ebe310444/68747470733a2f2f706f7365722e707567782e6f72672f616e74696d6563682f636f696e626173652f6c6963656e7365)](https://packagist.org/packages/antimech/coinbase)[![PHP Version Require](https://camo.githubusercontent.com/2d1ce1a758e185f1bcd408b138e30e8c6c32cbb2afba3085130e93f090dd693b/68747470733a2f2f706f7365722e707567782e6f72672f616e74696d6563682f636f696e626173652f726571756972652f706870)](https://packagist.org/packages/antimech/coinbase)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require antimech/coinbase
```

The service provider will automatically register itself.

You may publish the config file with:

```
php artisan vendor:publish --provider="Antimech\Coinbase\CoinbaseServiceProvider" --tag="config"
```

This is the contents of the config file that will be published at `config/coinbase.php`:

```
return [
    'api_key' => env('COINBASE_COMMERCE_API_KEY'),
    'api_version' => env('COINBASE_COMMERCE_API_VERSION', '2018-03-22'),

    'webhook_secret' => env('COINBASE_COMMERCE_WEBHOOK_SECRET'),
    'webhook_jobs' => [
        // 'charge:created' => \App\Jobs\CoinbaseWebhooks\HandleCreatedCharge::class,
        // 'charge:confirmed' => \App\Jobs\CoinbaseWebhooks\HandleConfirmedCharge::class,
        // 'charge:failed' => \App\Jobs\CoinbaseWebhooks\HandleFailedCharge::class,
        // 'charge:delayed' => \App\Jobs\CoinbaseWebhooks\HandleDelayedCharge::class,
        // 'charge:pending' => \App\Jobs\CoinbaseWebhooks\HandlePendingCharge::class,
        // 'charge:resolved' => \App\Jobs\CoinbaseWebhooks\HandleResolvedCharge::class,
    ],
    'webhook_model' => Antimech\Coinbase\Models\CoinbaseWebhookCall::class,
];
```

In the `webhook_secret` key of the config file you should add a valid webhook secret. You can find the secret used at [the webhook configuration settings on the Coinbase Commerce dashboard](https://commerce.coinbase.com/dashboard/settings).

Next, you must publish the migration with:

```
php artisan vendor:publish --provider="Antimech\Coinbase\CoinbaseServiceProvider" --tag="migrations"
```

After the migration has been published you can create the `coinbase_webhook_calls` table by running the migrations:

```
php artisan migrate
```

Finally, take care of the routing: At [the Coinbase Commerce dashboard](https://commerce.coinbase.com/dashboard/settings) you must add a webhook endpoint, for example: `https://example.com/api/coinbase/webhook`

Usage
-----

[](#usage)

### Charges

[](#charges)

List charges:

```
$charges = Coinbase::getCharges();
```

Create a charge:

```
$charge = Coinbase::createCharge([
    'name' => 'Name',
    'description' => 'Description',
    'local_price' => [
        'amount' => 100,
        'currency' => 'USD',
    ],
    'pricing_type' => 'fixed_price',
]);
```

Show a charge:

```
$charge = Coinbase::getCharge($chargeId);
```

Cancel a charge:

```
$charge = Coinbase::cancelCharge($chargeId);
```

Resolve a charge:

```
$charge = Coinbase::resolveCharge($chargeId);
```

### Checkouts

[](#checkouts)

List checkouts:

```
$checkouts = Coinbase::getCheckouts();
```

Create a checkout:

```
$checkout = Coinbase::createCheckout([
    'name' => 'Name',
    'description' => 'Description',
    'requested_info' => [],
    'local_price' => [
        'amount' => 100,
        'currency' => 'USD',
    ],
    'pricing_type' => 'fixed_price',
]);
```

Show a checkout:

```
$checkout = Coinbase::getCheckout($checkoutId);
```

Update a checkout:

```
$checkout = Coinbase::updateCheckout($checkoutId, [
    'name' => 'New Name',
    'description' => 'New Description',
    'local_price' => [
        'amount' => 200,
        'currency' => 'USD',
    ],
    'requested_info' => [
        'name',
    ],
]);
```

Delete a checkout:

```
$checkout = Coinbase::deleteCheckout($checkoutId);
```

### Invoices

[](#invoices)

List invoices:

```
$invoices = Coinbase::getInvoices();
```

Create an invoice:

```
$invoice = Coinbase::createInvoice([
    'business_name' => 'Business Name',
    'customer_email' => 'customer@example.com',
    'customer_name' => 'Customer Name',
    'local_price' => [
        'amount' => 100,
        'currency' => 'USD',
    ],
    'memo' => 'A memo/description for the invoice',
]);
```

Show an invoice:

```
$invoice = Coinbase::getInvoice($invoiceId);
```

Void an invoice:

```
$invoice = Coinbase::voidInvoice($invoiceId);
```

Resolve an invoice:

```
$invoice = Coinbase::resolveInvoice($invoiceId);
```

### Events

[](#events)

List events:

```
$events = Coinbase::getEvents();
```

Show an event:

```
$event = Coinbase::getEvent($eventId);
```

### Webhooks

[](#webhooks)

Coinbase Commerce will send out webhooks for several event types. You can find the [full list of events types](https://docs.cloud.coinbase.com/commerce/docs/webhooks-events#events) in the Coinbase Commerce documentation.

Coinbase Commerce will sign all requests hitting the webhook url of your app. This package will automatically verify if the signature is valid. If it is not, the request was probably not sent by Coinbase Commerce.

Unless something goes terribly wrong, this package will always respond with a `200` to webhook requests. Sending a `200` will prevent Coinbase Commerce from resending the same event over and over again. All webhook requests with a valid signature will be logged in the `coinbase_webhook_calls` table. The table has a `payload` column where the entire payload of the incoming webhook is saved.

If the signature is not valid, the request will not be logged in the `coinbase_webhook_calls` table but a `Antimech\Coinbase\Exceptions\WebhookFailed` exception will be thrown. If something goes wrong during the webhook request the thrown exception will be saved in the `exception` column. In that case the controller will send a `500` instead of `200`.

There are two ways this package enables you to handle webhook requests: you can opt to queue a job or listen to the events the package will fire.

### Handling webhook requests using jobs

[](#handling-webhook-requests-using-jobs)

If you want to do something when a specific event type comes in you can define a job that does the work. Here's an example of such a job:

```
