PHPackages                             galal/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. [API Development](/categories/api)
4. /
5. galal/coinbase

ActivePackage[API Development](/categories/api)

galal/coinbase
==============

Laravel wrapper for the Coinbase Wallet API v2

1304PHP

Since Apr 21Pushed 8y agoCompare

[ Source](https://github.com/ahmedggalal/galal-coinbase)[ Packagist](https://packagist.org/packages/galal/coinbase)[ RSS](/packages/galal-coinbase/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Coinbase Wallet Laravel Wrapper
===============================

[](#coinbase-wallet-laravel-wrapper)

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

[](#installation)

Install the library using Composer. Please read the [Composer Documentation](https://getcomposer.org/doc/01-basic-usage.md) if you are unfamiliar with Composer or dependency managers in general.

```
composer require galal/coinbase

```

```
Provider => Galal\Coinbase\CoinbaseServiceProvider::class,
```

```
Aliase => 'Coinbase'=>Galal\Coinbase\Facades\Coinbase::class,
```

To get started, you'll need to publish all vendor assets:

```
$ php artisan vendor:publish

```

Authentication
--------------

[](#authentication)

### API Key

[](#api-key)

Add an API key and secret of your own Coinbase account to config/coinbase.php .

```
use Galal\Coinbase\Facades\Coinbase;

$client = Coinbase::client();
```

### OAuth2

[](#oauth2)

Use OAuth2 authentication to access a user's account other than your own. This library does not handle the handshake process, and assumes you have an access token when it's initialized. You can handle the handshake process using an \[OAuth2 client\] such as \[league/oauth2-client\].

```
use Galal\Coinbase\Facades\Coinbase;

// with a refresh token
$client = Coinbase::clientUsingOauth($accessToken, $refreshToken);

// without a refresh token
$client = Coinbase::clientUsingOauth($accessToken);
```

### Two factor authentication

[](#two-factor-authentication)

The send money endpoint requires a 2FA token in certain situations . A specific exception is thrown when this is required.

```
use Galal\Coinbase\Facades\Coinbase;

$transaction = Coinbase::transaction()->send([
    'toEmail' => 'test@test.com',
    'bitcoinAmount' => 1
]);

$account = Coinbase::client()->getPrimaryAccount();
try {
    Coinbase::client()->createAccountTransaction($account, $transaction);
} catch (TwoFactorRequiredException $e) {
    // show 2FA dialog to user and collect 2FA token

    // retry call with token
    Coinbase::client()->createAccountTransaction($account, $transaction, [
        Coinbase::param()::TWO_FACTOR_TOKEN => '123456',
    ]);
}
```

### Warnings

[](#warnings)

It's prudent to be conscious of warnings. The library will log all warnings to a standard PSR-3 logger if one is configured.

```
use Galal\Coinbase\Facades\Coinbase;

$client = Coinbase::clientWithLogging($logger);
```

You can also request that the API return an expanded resource in the initial request by using the `expand` parameter.

```
$deposit = $this->client->getAccountDeposit($account, $depositId, [
    Coinbase::param()::EXPAND = ['transaction'],
]);
```

Resource references can be used when creating new resources, avoiding the overhead of requesting a resource from the API.

```
$deposit = Coinbase::deposit([
    'paymentMethod' => Coinbase::paymentMethod()->reference($paymentMethodId)
]);

// or use the convenience method
$deposit = Coinbase::deposit([
    'paymentMethodId' => $paymentMethodId
]);
```

### Responses

[](#responses)

There are multiple ways to access raw response data. First, each resource object has a `getRawData()` method which you can use to access any field that are not mapped to the object properties.

```
$data = $deposit->getRawData();
```

Raw data from the last HTTP response is also available on the client object.

```
$data = $client->decodeLastResponse();
```

### Active record methods

[](#active-record-methods)

The library includes support for active record methods on resource objects. You must enable this functionality when bootstrapping your application.

```
$client->enableActiveRecord();
```

Once enabled, you can call active record methods on resource objects.

```
$transactions = $account->getTransactions([
    Coinbase::param()::FETCH_ALL => true,
]);
```

Usage
-----

[](#usage)

**List supported native currencies**

```
$currencies = $client->getCurrencies();
```

**List exchange rates**

```
$rates = $client->getExchangeRates();
```

**Buy price**

```
$buyPrice = $client->getBuyPrice('BTC-USD');
```

**Sell price**

```
$sellPrice = $client->getSellPrice('BTC-USD');
```

**Spot price**

```
$spotPrice = $client->getSpotPrice('BTC-USD');
```

**Current server time**

```
$time = $client->getTime();
```

**Get authorization info**

```
$auth = $client->getCurrentAuthorization();
```

**Lookup user info**

```
$user = $client->getUser($userId);
```

**Get current user**

```
$user = $client->getCurrentUser();
```

**Update current user**

```
$user->setName('New Name');
$client->updateCurrentUser($user);
```

**List all accounts**

```
$accounts = $client->getAccounts();
```

**List account details**

```
$account = $client->getAccount($accountId);
```

**List primary account details**

```
$account = $client->getPrimaryAccount();
```

**Set account as primary**

```
$client->setPrimaryAccount($account);
```

**Create a new bitcoin account**

```
$account = Coinbase::account([
    'name' => 'New Account'
]);
$client->createAccount($account);
```

**Update an account**

```
$account->setName('New Account Name');
$client->updateAccount($account):
```

**Delete an account**

```
$client->deleteAccount($account);
```

**List receive addresses for account**

```
$addresses = $client->getAccountAddresses($account);
```

**Get receive address info**

```
$address = $client->getAccountAddress($account, $addressId);
```

**List transactions for address**

```
$transactions = $client->getAddressTransactions($address);
```

**Create a new receive address**

```
$address = Coinbase::address([
    'name' => 'New Address'
]);
$client->createAccountAddress($account, $address);
```

**List transactions**

```
$transactions = $client->getAccountTransactions($account);
```

**Get transaction info**

```
$transaction = $client->getAccountTransaction($account, $transactionId);
```

**Send funds**

```
$transaction = Coinbase::transaction()->send([
    'toBitcoinAddress' => 'ADDRESS',
    'amount'           => new Money(5, CurrencyCode::USD),
    'description'      => 'Your first bitcoin!',
    'fee'              => '0.0001' // only required for transactions under BTC0.0001
]);

$client->createAccountTransaction($account, $transaction);
```

**Transfer funds to a new account**

```
$fromAccount = Coinbase::account()->reference($accountId);

$toAccount = Coinbase::account()([
    'name' => 'New Account'
]);
$client->createAccount($toAccount);

$transaction = Coinbase::transaction()->transfer([
    'to'            => $toAccount,
    'bitcoinAmount' => 1,
    'description'   => 'Your first bitcoin!'
]);

$client->createAccountTransaction($fromAccount, $transaction);
```

**Request funds**

```
$transaction = Coinbase::transaction()->request([
    'amount'      => Coinbase::money(8, CurrencyCode::USD),
    'description' => 'Burrito'
]);

$client->createAccountTransaction($transaction);
```

**Resend request**

```
$account->resendTransaction($transaction);
```

**Cancel request**

```
$account->cancelTransaction($transaction);
```

**Fulfill request**

```
$account->completeTransaction($transaction);
```

**List buys**

```
$buys = $client->getAccountBuys($account);
```

**Get buy info**

```
$buy = $client->getAccountBuy($account, $buyId);
```

**Buy bitcoins**

```
$buy = Coinbase::buy([
    'bitcoinAmount' => 1
]);

$client->createAccountBuy($account, $buy);
```

**Commit a buy**

You only need to do this if you pass `commit=false` when you create the buy.

```
$client->createAccountBuy($account, $buy, [Coinbase::param()::COMMIT => false]);
$client->commitBuy($buy);
```

**List sells**

```
$sells = $client->getAccountSells($account);
```

**Get sell info**

```
$sell = $client->getAccountSell($account, $sellId);
```

**Sell bitcoins**

```
$sell = Coinbase::sell([
    'bitcoinAmount' => 1
]);

$client->createAccountSell($account, $sell);
```

**Commit a sell**

You only need to do this if you pass `commit=false` when you create the sell.

```
$client->createAccountSell($account, $sell, [Coinbase::param()::COMMIT => false]);
$client->commitSell($sell);
```

**List deposits**

```
$deposits = $client->getAccountDeposits($account);
```

**Get deposit info**

```
$deposit = $client->getAccountDeposit($account, $depositId);
```

**Deposit funds**

```
$deposit = Coinbase::deposit([
    'amount' => Coinbase::money(10, Coinbase::currencyCode()::USD)
]);

$client->createAccountDeposit($account, $deposit);
```

**Commit a deposit**

You only need to do this if you pass `commit=false` when you create the deposit.

```
$client->createAccountDeposit($account, $deposit, [Coinbase::param()::COMMIT => false]);
$client->commitDeposit($deposit);
```

**List withdrawals**

```
$withdrawals = $client->getAccountWithdrawals($account);
```

**Get withdrawal**

```
$withdrawal = $client->getAccountWithdrawal($account, $withdrawalId);
```

**Withdraw funds**

```
$withdrawal = Coinbase::withdrawal([
    'amount' => new Money(10, CurrencyCode::USD)
]);

$client->createAccountWithdrawal($account, $withdrawal);
```

**Commit a withdrawal**

You only need to do this if you pass `commit=true` when you call the withdrawal method.

```
$client->createAccountWithdrawal($account, $withdrawal, [Coinbase::param()::COMMIT => false]);
$client->commitWithdrawal($withdrawal);
```

**List payment methods**

```
$paymentMethods = $client->getPaymentMethods();
```

**Get payment method**

```
$paymentMethod = $client->getPaymentMethod($paymentMethodId);
```

#### Get merchant

[](#get-merchant)

```
$merchant = $client->getMerchant($merchantId);
```

#### List orders

[](#list-orders)

```
$orders = $client->getOrders();
```

#### Get order

[](#get-order)

```
$order = $client->getOrder($orderId);
```

#### Create order

[](#create-order)

```
$order = Coinbase::order([
    'name' => 'Order #1234',
    'amount' => Coinbase::moneyBTC(1)
]);

$client->createOrder($order);
```

#### Refund order

[](#refund-order)

```
$client->refundOrder($order, Coinbase::currencyCode()::BTC);
```

### Checkouts

[](#checkouts)

#### List checkouts

[](#list-checkouts)

```
$checkouts = $client->getCheckouts();
```

#### Create checkout

[](#create-checkout)

```
$params = array(
    'name'               => 'My Order',
    'amount'             => Coinbase::money(100, 'USD'),
    'metadata'           => array( 'order_id' => $custom_order_id )
);

$checkout = new Checkout($params);
$client->createCheckout($checkout);
$code = $checkout->getEmbedCode();
$redirect_url = "https://www.coinbase.com/checkouts/$code";
```

#### Get checkout

[](#get-checkout)

```
$checkout = $client->getCheckout($checkoutId);
```

#### Get checkout's orders

[](#get-checkouts-orders)

```
$orders = $client->getCheckoutOrders($checkout);
```

#### Create order for checkout

[](#create-order-for-checkout)

```
$order = $client->createNewCheckoutOrder($checkout);
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6011be2013bea5c9b8879d816d6fa10b249ad7ec0c9fa3624c83260d13c7fa01?d=identicon)[ahmedggalal](/maintainers/ahmedggalal)

---

Top Contributors

[![ahmedggalal](https://avatars.githubusercontent.com/u/38420331?v=4)](https://github.com/ahmedggalal "ahmedggalal (6 commits)")

### Embed Badge

![Health badge](/badges/galal-coinbase/health.svg)

```
[![Health](https://phpackages.com/badges/galal-coinbase/health.svg)](https://phpackages.com/packages/galal-coinbase)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
