Basic Information:
This article is about the Pei payment gateway. It is a payment method owned by Greiðsluiðlun ehf . Payment intermediation is the development and operation of payment solutions, credit purchases, and debt management for companies, NGOs, pension funds, and public bodies.
Here in this article, we will operate the Norra registration and payment system. Like sports clubs, organizations, municipalities, and companies to simplify registration and payment for courses, events, and various other services.
Let’s Start
Let’s start now. First of all, you need to initialize composer if the composer is not installed please [click here] to follow installation instructions.
Therefor, I assume composer is installed so please follow below steps
$ cd your/project/path/dir
$ composer init
You need to run this command in your terminal.
While performing the steps the composer will ask for a couple of questions.
Therefore, you just need to answer it or just hit enter throughout with default values.
Now time to run and install package of PEI payment as below.
$ composer require "coderubix/php-pei":"dev-master"
Or alternatively you can add below code to you composer.json file at “require” section
{
"require": {
"coderubix/php-pei":"dev-master"
}
}
Now run composer update
$ composer update
$ composer dump-autoload
You will see successfully installation of package as below screen.
Now create pei-redirect.php file and pass relevant parameter in that.
Make sure and don’t forgot to use the PEI class.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
//If you are using core PHP then first include the class from relevent directory from your code.
require_once __DIR__ . '/vendor/coderubix/php-pei/src/pei/PeiPayment.php';
use Pei\PeiPayment as PeiPayment;
$config = [
'live' => [
'auth_url' => 'https://auth.pei.is/core/connect/token/',
'order_url' => 'https://api.pei.is/api/orders/',
'payment_url' => 'https://gattin.pei.is/',
'client_id' => 'XXXXXXXXXXXXXXX', // replace this with your client id provided by pei.is
'secret_key' => 'XXXXXXXXXXXXXXX', // replace this with your secret provided by pei.is
'merchantid' => 1, // replace this with your merchant id provided by pei.is
'postback_url' => '',
'cancel_url' => '',
'success_url' => ''
],
'sandbox' => [
'auth_url' => 'https://authstaging.pei.is/core/connect/token/',
'order_url' => 'https://externalapistaging.pei.is/api/orders/',
'payment_url' => 'https://gattinstaging.pei.is/',
'client_id' => 'democlient',
'secret_key' => 'demosecret',
'merchantid' => 1,
'postback_url' => '',
'cancel_url' => '',
'success_url' => 'success.php'
]
];
$PeiPayment = new PeiPayment($config, 'sandbox');
// get auth token
//$auth_token = $PeiPayment->authorize();
$ssn = 5554452454;
$order_info = [
'order_id' => uniqid(),
'user' => [
'firstname' => 'jhon',
'lastname' => 'doe',
'email' => 'developer7039@gmail.com'
],
//optional
'tax' => [
'label' => 'Vat',
'amount' => 100
],
//optional
'shipping' => [
'label' => 'Shipping',
'amount' => 50
],
'items' => [
[
'name' => 'item 1',
'code' => '#FFER23', //optional
'quantity' => 20,
'price' => 100
],
[
'name' => 'item 2',
'quantity' => 30,
'price' => 150
]
]
];
$PeiPayment->pay($ssn, $order_info);
?>
Create success.php and write your code which can be perform after successful transaction.
Now the next steps is to open a browser and enter the URL till pei-redirect.php
It will redirect and process the code as below screenshots.
There will be two options for payment “Pei 30/Pei 60” and “Credit Card” as above screenshot.
The Pei payment gateway suggests to integrated with a hosted page.
It is very easy to integrate but you can always use credit card payment integration on your own website.
if required for that Pei payment gateway provides REST API.
Feel free to comment if you find any issue or need any improvement.
Congratulations !! we are done here to learn and implementation of Pei gateway. Enjoy coding.
Below provided link is another article about the Razorpay payment gateway integration.