PHPackages                             quantumca/laravel-coinpayments - 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. quantumca/laravel-coinpayments

ActiveExtension

quantumca/laravel-coinpayments
==============================

Coinpayments for Laravel

v1.1.5(4y ago)015MITPHPPHP &gt;=5.5CI failing

Since Sep 19Pushed 4y agoCompare

[ Source](https://github.com/quantumca/laravel-coinpayments)[ Packagist](https://packagist.org/packages/quantumca/laravel-coinpayments)[ RSS](/packages/quantumca-laravel-coinpayments/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (4)Versions (21)Used By (0)

Laravel Coinpayments
====================

[](#laravel-coinpayments)

Implementation of most of the CoinPayments functionality.

[![Coinpayments Website](https://camo.githubusercontent.com/6b2a2a7147c2c6c7a11d9989976ff85fede88916d4c34d2d4a839196767049d9/68747470733a2f2f7777772e636f696e7061796d656e74732e6e65742f696d616765732f622f62616e6e6572365f3732387839302d332e6a7067)](https://www.coinpayments.net/index.php?ref=b3eeecdbaf95ca82e86a1ee7f7ff57b0)

### [Example API](https://github.com/kevupton/example-laravel-coinpayments)

[](#example-api)

### Require

[](#require)

```
composer require quantumca/laravel-coinpayments

```

### 1. Install Service Provider (If Laravel &lt; 5.5)

[](#1-install-service-provider-if-laravel--55)

```
// add directly from the app
$app->register(\Kevupton\LaravelCoinpayments\Providers\LaravelCoinpaymentsServiceProvider::class);
```

OR

All service providers are registered in the `config/app.php` configuration file.

```
'providers' => [
    // Other Service Providers

    \Kevupton\LaravelCoinpayments\Providers\LaravelCoinpaymentsServiceProvider::class,
],
```

### 2. Configure

[](#2-configure)

`.env` configuration

```
COINPAYMENTS_DB_PREFIX=cp_
COINPAYMENTS_MERCHANT_ID=your_unique_merchant_id
COINPAYMENTS_PUBLIC_KEY=generated_public_key
COINPAYMENTS_PRIVATE_KEY=generated_private_key
COINPAYMENTS_IPN_SECRET=your_custom_ipn_secret
COINPAYMENTS_IPN_URL=your_ipn_url
COINPAYMENTS_API_FORMAT=json
COINPAYMENTS_IPN_ROUTE_ENABLED=true
COINPAYMENTS_IPN_ROUTE_PATH=/api/ipn

```

*Execute `php artisan vendor:publish` for the complete config file.*

Config: `coinpayments.php`

```
return array(

    // prefix to each of the tables in the database
    'database_prefix' => env('COINPAYMENTS_DB_PREFIX', 'cp_'),

    'merchant_id' => env('COINPAYMENTS_MERCHANT_ID'),

    // Your API public key associated with your coinpayments account
    'public_key' => env('COINPAYMENTS_PUBLIC_KEY'),

    // Your API private key associated with your coinpayments account
    'private_key' => env('COINPAYMENTS_PRIVATE_KEY'),

    // This is used to verify that an IPN is from us, use a good random string nobody can guess.
    'ipn_secret' => env('COINPAYMENTS_IPN_SECRET'),

    // URL for your IPN callbacks. If not set it will use the IPN URL in your Edit Settings page if you have one set.
    'ipn_url' => env('COINPAYMENTS_IPN_URL'),

    // The format of response to return, json or xml. (default: json)
    'format' => env('COINPAYMENTS_API_FORMAT', 'json'),

    // ALL logs all requests, ERROR logs only errors, and NONE never
    'log_level' => Log::LEVEL_ERROR,

    // Whether or not to have coinpayments automatically parse IPN's for you. If so please specify a PATH
    'route'           => [
        'enabled' => env('COINPAYMENTS_IPN_ROUTE_ENABLED', false),
        'path'    => env('COINPAYMENTS_IPN_ROUTE_PATH', '/api/ipn'),
    ],
);
```

### 3. Setup Database

[](#3-setup-database)

Run the migration to install the database tables

```
php artisan migrate
```

### 4. Usage

[](#4-usage)

Simple Transaction

```
$transaction = \Coinpayments::createTransactionSimple($cost, $currency_base, $currency_received, $extra_details);
```

Callback Address

```
$callbackAddress = \Coinpayments::getCallbackAddress($currency);
```

Withdrawal

```
$withdrawal = \Coinpayments::createWithdrawal($amount, $currency, $address, true);
```

Mass Withdrawal - *Uses the same values for withdrawal, but in an array*

```
$mass_withdrawal = \Coinpayments::createMassWithdrawal([
    [
        'amount' => $amount1,
        'address' => $address1,
        'currency' => $currency1,
    ],
    [
        'amount' => $amount2,
        'address' => $address2,
        'currency' => $currency2,
    ],
]);
```

Convert Coins

```
$conversion = \Coinpayments::convertCoins($amount, $from, $to, $address = null);
```

Withdrawal Info

```
$info = \Coinpayments::getWithdrawalInfo($id);
```

Conversion Info

```
$info = \Coinpayments::getConversionInfo($id);
```

#### IPN validation

[](#ipn-validation)

Laravel Coinpayments can automatically handle IPN's for you: Just specify, the path and enable it using the env variables.

```
COINPAYMENTS_IPN_ROUTE_ENABLED=true
COINPAYMENTS_IPN_ROUTE_PATH=/api/ipn

```

You can just subscribe to the Model events using an event listening on the following events:

###### Deposit - When someone deposits money to a callback address

[](#deposit---when-someone-deposits-money-to-a-callback-address)

- DepositCreated - When a deposit has been created
- DepositUpdated - When a deposit has been updated, but not complete.
- DepositComplete - When a deposit has completed (after all of the confirms have been received)

##### Withdrawal - When you make a withdrawal from the API

[](#withdrawal---when-you-make-a-withdrawal-from-the-api)

- WithdrawalCreated
- WithdrawalUpdated
- WithdrawalComplete

##### Transaction - When you make a transaction from the API

[](#transaction---when-you-make-a-transaction-from-the-api)

- TransactionCreated
- TransactionUpdated
- TransactionComplete

Then just subscribe to the event by adding a listener to the `App\Providers\EventServiceProvider`:

```
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        Kevupton\LarvelCoinpayments\Events\Deposit\DepositCompleted::class => [
            App\Listeners\DoSomethingOnDepositListener::class, // your own class listener for when a deposit is created
        ],
    ];
```

Then you can just do the same for each event.

Example event listener:

```
