Laravel Skrill Payment Gateway Integration with LaraSkrill

Published on Jul 09, 2019

Today, I'm going to show how to integrate Skrill payment gateway in Laravel with LaraSkrill package. By using this package we are able to make payment and do refund. So, let's start:

Table of Contents

  1. Install LaraSkrill Package
  2. Make Migration, Model and Controller
  3. Register Routes
  4. Create Blade Templates
  5. Test Project
  6. Note

Step 1 : Install LaraSkrill Package

At first, let's install LaraSkrill package by typing this command:

composer require obydul/laraskrill

Now we have to register LaraSkrill provider. Go to config >> app.php and find the providers & add this:

'providers' => [
    // ...

Step 2 : Make Migration, Model and Controller

We are going to create migration, model and controller for Skrill payment. Run this artisan command to create the three things:

php artisan make:model SkrillPayment -mcr

The migration file is for Skrill IPN. Like PayPal, Skrill provides Instant Payment Notification (IPN) too. To save payment information, we use IPN. If you don't need to save payment information in your database, then you don't this need.

Go to database>migrations and open the newly created migration file. Then paste this code:


use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSkrillPaymentsTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('skrill_payments', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()

Now open SkrillPaymentController from app>Http>Controllers and paste this code:


namespace App\Http\Controllers;

use App\SkrillPayment;
use Illuminate\Http\Request;
use Obydul\LaraSkrill\SkrillClient;
use Obydul\LaraSkrill\SkrillRequest;
use Redirect;

class SkrillPaymentController extends Controller
     * Construct.
    private $skrilRequest;

    public function __construct()
        // skrill config
        $this->skrilRequest = new SkrillRequest();
        $this->skrilRequest->pay_to_email = '[email protected]';
        $this->skrilRequest->return_url = 'http://laradev.test/payment-completed';
        $this->skrilRequest->cancel_url = 'http://laradev.test/payment-cancelled';
        $this->skrilRequest->logo_url = '';
        $this->skrilRequest->status_url = 'email or ipn';
        $this->skrilRequest->status_url2 = 'email or ipn';

     * Make Payment
    public function makePayment()
        // create object instance of SkrillRequest
        $this->skrilRequest->prepare_only = 1;
        // $this->skrilRequest->transaction_id = 'MNPTTX0001'; // generate transaction id (optional)
        $this->skrilRequest->amount = '10.26';
        $this->skrilRequest->currency = 'USD';
        $this->skrilRequest->language = 'EN';
        $this->skrilRequest->merchant_fields = 'site_name, customer_email';
        $this->skrilRequest->site_name = 'Your Website';
        $this->skrilRequest->customer_email = '[email protected]';
        $this->skrilRequest->detail1_description = 'Product ID:';
        $this->skrilRequest->detail1_text = '101';

        // create object instance of SkrillClient
        $client = new SkrillClient($this->skrilRequest);
        $sid = $client->generateSID(); //return SESSION ID

        // handle error
        $jsonSID = json_decode($sid);
        if ($jsonSID != null && $jsonSID->code == "BAD_REQUEST")
            return $jsonSID->message;

        // do the payment
        $redirectUrl = $client->paymentRedirectUrl($sid); //return redirect url
        return Redirect::to($redirectUrl); // redirect user to Skrill payment page

     * Do Refund
    public function doRefund()
        // Create object instance of SkrillRequest
        $prepare_refund_request = new SkrillRequest();
        // config
        $prepare_refund_request->email = 'merchant_email';
        $prepare_refund_request->password = 'api_password';
        $prepare_refund_request->refund_status_url = 'refund_status_url';
        // request
        $prepare_refund_request->transaction_id = 'MNPTTX0001';
        $prepare_refund_request->amount = '5.56';
        $prepare_refund_request->refund_note = 'Product no longer in stock';
        $prepare_refund_request->merchant_fields = 'site_name, customer_email';
        $prepare_refund_request->site_name = 'Your Website';
        $prepare_refund_request->customer_email = '[email protected]';

        // do prepare refund request
        $client_prepare_refund = new SkrillClient($prepare_refund_request);
        $refund_prepare_response = $client_prepare_refund->prepareRefund(); // return sid or error code

        // refund requests
        $refund_request = new SkrillRequest();
        $refund_request->sid = $refund_prepare_response;

        // do refund
        $client_refund = new SkrillClient($refund_request);
        $do_refund = $client_refund->doRefund();
        dd($do_refund); // response

     * Instant Payment Notification (IPN) from Skrill
    public function ipn(Request $request)
        // skrill data - get more fields from Skrill Quick Checkout Integration Guide 7.9 (page 23)
        $transaction_id = $request->transaction_id;
        $mb_transaction_id = $request->mb_transaction_id;
        $invoice_id = $request->invoice_id; // custom field
        $order_from = $request->order_from; // custom field
        $customer_email = $request->customer_email; // custom field
        $biller_email = $request->pay_from_email;
        $customer_id = $request->customer_id;
        $amount = $request->amount;
        $currency = $request->currency;
        $status = $request->status;

        // status message
        if ($status == '-2') {
            $status_message = 'Failed';
        } else if ($status == '2') {
            $status_message = 'Processed';
        } else if ($status == '0') {
            $status_message = 'Pending';
        } else if ($status == '-1') {
            $status_message = 'Cancelled';

        // now store data to database
        $skrill_ipn = new SkrillPayment();
        $skrill_ipn->transaction_id = $transaction_id;
        $skrill_ipn->mb_transaction_id = $mb_transaction_id;
        $skrill_ipn->invoice_id = $invoice_id;
        $skrill_ipn->order_from = $order_from;
        $skrill_ipn->customer_email = $customer_email;
        $skrill_ipn->biller_email = $biller_email;
        $skrill_ipn->customer_id = $customer_id;
        $skrill_ipn->amount = $amount;
        $skrill_ipn->currency = $currency;
        $skrill_ipn->status = $status_message;
        $skrill_ipn->created_at = Date('Y-m-d H:i:s');
        $skrill_ipn->updated_at = Date('Y-m-d H:i:s');

In the SkrillPaymentController, I've created three functions.

  • makePayment(): to make a payment
  • doRefund(): to send refund
  • ipn(): to receive payment information from Skrill

Step 3 : Register Routes

Let's define the routes for our project. Open web.php from routes folder and paste this routes:


Route::get('/', function () {
    return view('home');

Route::get('make-payment', '[email protected]');
Route::get('do-refund', '[email protected]');
Route::post('ipn', '[email protected]');

Route::get('payment-completed', function () {
    return view('payment-completed');
Route::get('payment-cancelled', function () {
    return view('payment-cancelled');

Step 4 : Create Blade Templates

We have defined 3 views on the routes. Let's make the blade flies. Go to resources/views folder make 4 blade files like below:

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="">
<body style="margin-top: 40px;">

<div class="text-center">
    <img src=""><br>
    <span class="text-secondary">Laravel Skrill Payment Gateway Integration with LaraSkrill</span>

<div class="container" style="margin-top: 40px;">


@section('title', 'MyNotePaper - Laravel Skrill Payment Gateway Integration with LaraSkrill')

    <div class="text-center" style="margin-bottom: 25px;">
        <a href="{{url('make-payment')}}" class="btn btn-info">Make Payment</a> <a href="{{url('do-refund')}}"
                                                                                   class="btn btn-danger">Do
        $skrill_payments = DB::table('skrill_payments')->orderBy('id', 'desc')->get();
    <table class="table table-bordered">
            <th scope="col">#</th>
            <th scope="col">MB Transaction ID</th>
            <th scope="col">Amount</th>
            <th scope="col">Customer Email</th>
            <th scope="col">Created At</th>
            @foreach($skrill_payments as $skrill_payment)
                    <td>{{$skrill_payment->amount}} ({{$skrill_payment->currency}})</td>

@section('title', 'Payment Completed')

    <div class="alert alert-success" role="alert">
        Payment Successfully Completed

    <div class="text-center">
        <a href="{{url('/')}}" class="btn btn-info">&lt;Home</a>

@section('title', 'Payment Cancelled')

    <div class="alert alert-danger" role="alert">
        Payment Has Been Cancelled

    <div class="text-center">
        <a href="{{url('/')}}" class="btn btn-info">&lt;Home</a>

Step 5 : Test Project

We have completed all the steps. It's time to test our project. My test project URL is https://laradev.test/.

Skrill test card VISA number: 4000001234567890

Run the project and visit make payment route:


If everything is correct, you will be redirected to this page:

Enter the test card and fill-up the rest fields with any data. Please enter correct email to receive payment receipt. Then click "PAY NOW" button.

I've seen the success message. You can click continue button or it will automatically redirect to your return URL.

I've set IPN and received data from Skrill. I've stored the data in the database.

Note: IPN doesn't work in localhost. For localhost, please test with email.

** To do refund, you have to add your IP in white-list. The option is in Skrill settings. You need to generate MQI/API password too.

We have successfully integrated Skrill payment gateway in Laravel using LaraSkrill. You can download this project from GitHub

Step 6 : Note

I've created this LaraSkrill package. You will find more information on GitHub. If you notice any issues, please write in the comment section. Thank you. 🙂

Comments (2)

03, Jul 2022 2:12 PM

ErrorException Header may not contain NUL bytes Showing This Error

03, Jul 2022 7:10 PM

Hi Md. Abdul Hakim bro,

I've just tested. It works for me. Please remove this line from your request and try:


Also I've just released v1.2.0. If you are using Laravel 7+, then you can upgrade the package to latest version.