PHPackages                             shynne109/laravel-crypto-payment-gateway - 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. [Payment Processing](/categories/payments)
4. /
5. shynne109/laravel-crypto-payment-gateway

ActiveLibrary[Payment Processing](/categories/payments)

shynne109/laravel-crypto-payment-gateway
========================================

GoUrl.io Crypto Payment Gateway for Laravel

03CSS

Since Feb 25Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Crypto Payment Gateway
==============================

[](#laravel-crypto-payment-gateway)

[GoUrl.io](https://gourl.io) Crypto Payment Gateway for Laravel.

[![Latest Version on Packagist](https://camo.githubusercontent.com/72ae7a9d26d75a4a347ade737b411cfb7b42be53c5e445afad115c661cb98242/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7368796e6e653130392f6c61726176656c2d63727970746f2d7061796d656e742d676174657761792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shynne109/laravel-crypto-payment-gateway)[![Total Downloads](https://camo.githubusercontent.com/014122579f472b7682e28137e66c01ec7410c9feadfbdcf93f9cb73bf5549c99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7368796e6e653130392f6c61726176656c2d63727970746f2d7061796d656e742d676174657761792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shynne109/laravel-crypto-payment-gateway)[![GitHub Actions](https://github.com/shynne109/laravel-crypto-payment-gateway/actions/workflows/main.yml/badge.svg)](https://github.com/shynne109/laravel-crypto-payment-gateway/actions/workflows/main.yml/badge.svg)

[![preview](https://github.com/shynne109/laravel-crypto-payment-gateway/raw/main/demo.png)](https://github.com/shynne109/laravel-crypto-payment-gateway/raw/main/demo.png)

Table of Contents
-----------------

[](#table-of-contents)

- [Laravel Crypto Payment Gateway](#laravel-crypto-payment-gateway)
    - [Table of Contents](#table-of-contents)
    - [Installation](#installation)
    - [Requirements](#requirements)
        - [Dependencies](#dependencies)
    - [Configuration](#configuration)- [Define payment routes](#define-payment-routes)- [Define the public key and private keys in environment file](#define-the-public-key-and-private-keys-in-environment-file)
        - [Config Options](#config-options)
    - [Usage](#usage)
        - [Payment Data Submission](#payment-data-submission)
            - [Usage with Form Submit](#usage-with-form-submit)
            - [Usage with AJAX Request](#usage-with-ajax-request)
            - [Usage with Session Redirect (through controller, Livewire component or anywhere in your application)](#usage-with-session-redirect-through-controller-livewire-component-or-anywhere-in-your-application)
        - [The Callback](#the-callback)
            - [Callback Controller](#callback-controller)
            - [Callback Route](#callback-route)
            - [IPN (Instant Payment Notification)](#ipn-instant-payment-notification)
        - [Eloquent Model for `crypto_payments` table](#eloquent-model-for-crypto_payments-table)
    - [Advanced Usage](#advanced-usage)
        - [Instance of GoUrl.io PHP Class API (`cryptobox.class.php`)](#instance-of-gourlio-php-class-api-cryptoboxclassphp)
    - [Resources](#resources)
    - [Testing](#testing)
    - [Changelog](#changelog)
    - [Contributing](#contributing)
        - [Security](#security)
    - [Credits](#credits)
    - [License](#license)
    - [Laravel Package Boilerplate](#laravel-package-boilerplate)

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

[](#installation)

You can install the package via composer:

```
composer require shynne109/laravel-crypto-payment-gateway
```

Next, you should publish the configuration, migration and asset files using the `vendor:publish` Artisan command. The configuration, migration and asset files will be placed in your application's `config`, `database/migrations` and `public/vendor` directory respectively:

```
php artisan vendor:publish --provider="Victorybiz\LaravelCryptoPaymentGateway\LaravelCryptoPaymentGatewayServiceProvider"
```

Requirements
------------

[](#requirements)

This package is create a laravel wrapper on the [GoUrl.io](https://gourl.io)'s [CryptoAPI Payment Gatway](https://github.com/cryptoapi/Payment-Gateway).

- Register for Free or Login on the [GoUrl.io website](https://gourl.io).
- Create [new payment box](https://gourl.io/editrecord/coin_boxes/0).
- Ensure to specify your External wallet address and Callback Url
- Obtain the Public Key and Private of each coin's payment box you want to support.

### Dependencies

[](#dependencies)

The `compact` and `standard` box template uses **Alpinejs** and **TailwindCSS**. While the `gourl-cryptobox-iframe` and `gourl-cryptobox-boostrap` uses assets provided by [GoUrl.io](https://gourl.io). You do not need to install any of the dependencies, the package uses the CDN version of dependencies.

Configuration
-------------

[](#configuration)

You need create the following files;

- A `PaymentController` with a `callback` method. [Learn more below](#the-callback).
- A static class method anywhere in your application to hook **IPN (Instant Payment Notification)**. Preferably you can just define the static method `public static function ipn($cryptoPaymentModel, $payment_details, $box_status){..}` in the same `PaymentController` for easy code management. [Learn more below](#the-ipn)
- Define the payment routes.
- Define the public key and private keys in environment file

##### Define payment routes

[](#define-payment-routes)

```
// routes/web.php

// You can protect the 'payments.crypto.pay' route with `auth` middleware to allow access by only authenticated user
Route::match(['get', 'post'], '/payments/crypto/pay', Victorybiz\LaravelCryptoPaymentGateway\Http\Controllers\CryptoPaymentController::class)
                ->name('payments.crypto.pay');

// You you need to create your own callback controller and define the route below
// The callback route should be a publicly accessible route with no auth
// However, you may also exclude the route from CSRF Protection by adding their URIs to the $except property of the VerifyCsrfToken middleware.
Route::post('/payments/crypto/callback', [App\Http\Controllers\Payment\PaymentController::class, 'callback'])
                ->withoutMiddleware(['web', 'auth']);
```

Learn more about [The Callback Route](#the-callback) below.

##### Define the public key and private keys in environment file

[](#define-the-public-key-and-private-keys-in-environment-file)

Defined the created payment box's public key and private key for the various coins in your `.env` file.

```
GOURL_PAYMENTBOX_BITCOIN_PUBLIC_KEY
GOURL_PAYMENTBOX_BITCOIN_PRIVATE_KEY

GOURL_PAYMENTBOX_BITCOINCASH_PUBLIC_KEY
GOURL_PAYMENTBOX_BITCOINCASH_PRIVATE_KEY

```

#### Config Options

[](#config-options)

See the published `config/laravel-crypto-payment-gateway.php` for available options to customize the payment box like changing `logo`, `box_template`, `box_template_options` and other configuration options.

Usage
-----

[](#usage)

### Payment Data Submission

[](#payment-data-submission)

The payment data can be submitted in the following ways;

- Form Submit
- AJAX Request
- Session Redirect (through controller, Livewire component or anywhere in your application)

Which ever method data field `amount` in BTC or `amountUSD` need to be sent, both cannot be used. And optional data fields `userID`, `orderID` (if you want to reference the data to any model in app e.g Product model) and `redirect` (a url you want to redirect to once payment is received).

##### Usage with Form Submit

[](#usage-with-form-submit)

```

  @csrf

  Pay

```

##### Usage with AJAX Request

[](#usage-with-ajax-request)

```
axios({
  method: "post",
  url: "/payments/crypto/pay",
  data: {
    amountUSD: 20.50,
    userID: 1,
    orderID: 101,
    redirect: 'https://domain.com/redirect-url',
  },
  headers: {
    'Accept': 'application/json'
    // Ensure you include your TOKEN as well
  },
})
  .then(function (response) {
    // The url is available in `data` key of the json response:
    // {
    //   status: true,
    //   message: 'Request successful.',
    //   data: 'https://your-domain.com/payments/crypto/pay?cryptopsid=some-unique-token-string'
    // }
    if (response.data.status === true) {
      const paymentUrl = response.data.data
      window.location = paymentUrl
    }
  })
  .catch(function (response) {
    //handle error
    console.log(response);
  });
```

##### Usage with Session Redirect (through controller, Livewire component or anywhere in your application)

[](#usage-with-session-redirect-through-controller-livewire-component-or-anywhere-in-your-application)

You need to ensure you validate your data before sending to the payment gateway

```
// This could be in a controller method or livewire component method
use Victorybiz\LaravelCryptoPaymentGateway\LaravelCryptoPaymentGateway;

$payment_url = LaravelCryptoPaymentGateway::startPaymentSession([
    'amountUSD' => $validatedData['amount'], // OR 'amount' when sending BTC value
    'orderID' => $product->id,
    'userID' => Auth::user()->id,
    'redirect' => url()->full(),
]);
// redirect to the payment page
redirect()->to($payment_url);
```

### The Callback

[](#the-callback)

When a user has made a payment, the [GoUrl.io](https://gourl.io)'s server will send payment data using HTTP POST method on your callback url specified in field Callback URL of your crypto payment box.

##### Callback Controller

[](#callback-controller)

Create a `PaymentController` and call instance of Laravel Crypto Payment Gateway's callback method.

```
