Laravel Skrill Payment Gateway Integration with LaraSkrill
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
- Install LaraSkrill Package
- Make Migration, Model and Controller
- Register Routes
- Create Blade Templates
- Test Project
- 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' => [
// ...
Obydul\LaraSkrill\LaraSkrillServiceProvider::class,
]
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:
<?php
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) {
$table->bigIncrements('id');
$table->string('transaction_id');
$table->string('mb_transaction_id');
$table->string('invoice_id');
$table->string('order_from');
$table->string('customer_id');
$table->string('customer_email');
$table->string('biller_email');
$table->string('amount');
$table->string('currency');
$table->string('status');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('skrill_payments');
}
}
Now open SkrillPaymentController from app>Http>Controllers and paste this code:
<?php
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 = 'https://i.imgur.com/BYBiIZX.png';
$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->transaction_id = 'MNPTTX0001'; // generate transaction id
$this->skrilRequest->amount = '10.26';
$this->skrilRequest->currency = 'USD';
$this->skrilRequest->language = 'EN';
$this->skrilRequest->prepare_only = '1';
$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');
$skrill_ipn->save();
}
}
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:
<?php
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()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>@yield('title')</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body style="margin-top: 40px;">
<div class="text-center">
<img src="https://i.imgur.com/hHZjfUq.png"><br>
<span class="text-secondary">Laravel Skrill Payment Gateway Integration with LaraSkrill</span>
</div>
<div class="container" style="margin-top: 40px;">
@yield('content')
</div>
</body>
</html>
@extends('layout')
@section('title', 'MyNotePaper - Laravel Skrill Payment Gateway Integration with LaraSkrill')
@section('content')
<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
Refund</a>
</div>
@php
$skrill_payments = DB::table('skrill_payments')->orderBy('id', 'desc')->get();
@endphp
<table class="table table-bordered">
<thead>
<tr>
<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>
</tr>
</thead>
<tbody>
@if(!empty($skrill_payments))
@foreach($skrill_payments as $skrill_payment)
<tr>
<td>{{$skrill_payment->id}}</td>
<td>{{$skrill_payment->mb_transaction_id}}</td>
<td>{{$skrill_payment->amount}} ({{$skrill_payment->currency}})</td>
<td>{{$skrill_payment->customer_email}}</td>
<td>{{$skrill_payment->created_at}}</td>
</tr>
@endforeach
@endif
</tbody>
</table>
@endsection
@extends('layout')
@section('title', 'Payment Completed')
@section('content')
<div class="alert alert-success" role="alert">
Payment Successfully Completed
</div>
<div class="text-center">
<a href="{{url('/')}}" class="btn btn-info"><Home</a>
</div>
@endsection
@extends('layout')
@section('title', 'Payment Cancelled')
@section('content')
<div class="alert alert-danger" role="alert">
Payment Has Been Cancelled
</div>
<div class="text-center">
<a href="{{url('/')}}" class="btn btn-info"><Home</a>
</div>
@endsection
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:
https://laradev.test/make-payment
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. 🙂
Comment
Preview may take a few seconds to load.
Markdown Basics
Below you will find some common used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet
Bold & Italic
Italics *asterisks*
Bold **double asterisks**
Code
Inline Code
`backtick`Code Block```
Three back ticks and then enter your code blocks here.
```
Headers
# This is a Heading 1
## This is a Heading 2
### This is a Heading 3
Quotes
> type a greater than sign and start typing your quote.
Links
You can add links by adding text inside of [] and the link inside of (), like so:
Lists
To add a numbered list you can simply start with a number and a ., like so:
1. The first item in my list
For an unordered list, you can add a dash -, like so:
- The start of my list
Images
You can add images by selecting the image icon, which will upload and add an image to the editor, or you can manually add the image by adding an exclamation !, followed by the alt text inside of [], and the image URL inside of (), like so:
Dividers
To add a divider you can add three dashes or three asterisks:
--- or ***

Comments (0)