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

ActiveExtension

kevupton/laravel-coinpayments
=============================

Coinpayments for Laravel

v1.1.3(7y ago)3521.7k—0%31[9 issues](https://github.com/kevupton/laravel-coinpayments/issues)[3 PRs](https://github.com/kevupton/laravel-coinpayments/pulls)MITPHPPHP &gt;=5.5CI failing

Since Sep 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kevupton/laravel-coinpayments)[ Packagist](https://packagist.org/packages/kevupton/laravel-coinpayments)[ RSS](/packages/kevupton-laravel-coinpayments/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (19)Used By (0)

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

[](#laravel-coinpayments)

Implementation of most of the CoinPayments functionality.

[![Coinpayments Website](https://camo.githubusercontent.com/9403415aaeb0c45e00fe6fa88b22b2a8bfe3f8ced7b0c5e10df3b847769988fd/68747470733a2f2f7777772e636f696e7061796d656e74732e6e65742f696d616765732f622f383231363631653761303630343238326461353866336630653433653138383835373666353566363434353866353362313933633930613932363261346532652e706e67)](https://www.coinpayments.net/index.php?ref=a458c004de21a18c71849871781be820)

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

[](#example-api)

### Require

[](#require)

```
composer require kevupton/laravel-coinpayments

```

### 1. Install Service Provider

[](#1-install-service-provider)

```
// 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\LaravelCoinpayments\Events\Deposit\DepositComplete::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:

```
