Multipay
simple PHP payment package , supports multiple drivers
Install / Use
/learn @shetabit/MultipayREADME
PHP Payment Gateway
![Software License][ico-license]
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Total Downloads on Packagist][ico-download]][link-packagist]
[![Quality Score][ico-code-quality]][link-code-quality]
This is a PHP Package for Payment Gateway Integration. This package supports PHP 7.2+.
Donate me if you like this package :sunglasses: :bowtie:
For Laravel integration you can use shetabit/payment package.
This package works with multiple drivers, and you can create custom drivers if you can't find them in the current drivers list (below list).
- [داکیومنت فارسی][link-fa]
- [English documents][link-en]
- [中文文档][link-zh]
List of contents
List of available drivers
-
aqayepardakht :heavy_check_mark:
-
asanpardakht :heavy_check_mark:
-
atipay :heavy_check_mark:
-
azkiVam (Installment payment) :heavy_check_mark:
-
behpardakht (mellat) :heavy_check_mark:
-
bitpay :heavy_check_mark:
-
daracard :heavy_check_mark:
-
digipay :heavy_check_mark:
-
etebarino (Installment payment) :heavy_check_mark:
-
fanavacard :heavy_check_mark:
-
gooyapay :heavy_check_mark:
-
irandargah :heavy_check_mark:
-
irankish :heavy_check_mark:
-
jibit :heavy_check_mark:
-
local :heavy_check_mark:
-
minipay :heavy_check_mark:
-
nextpay :heavy_check_mark:
-
omidpay :heavy_check_mark:
-
parsian :heavy_check_mark:
-
parspal :heavy_check_mark:
-
pasargad :heavy_check_mark:
-
panapal :heavy_check_mark:
-
payfa :heavy_check_mark:
-
paypal (will be added soon in next version)
-
payping :heavy_check_mark:
-
paystar :heavy_check_mark:
-
poolam :heavy_check_mark:
-
pna :heavy_check_mark:
-
rayanpay :heavy_check_mark:
-
sadad (melli) :heavy_check_mark:
-
saman :heavy_check_mark:
-
sep (saman electronic payment) Keshavarzi & Saderat :heavy_check_mark:
-
sepehr (saderat) :heavy_check_mark:
-
sepordeh :heavy_check_mark:
-
shepa :heavy_check_mark:
-
sizpay :heavy_check_mark:
-
snapppay :heavy_check_mark:
-
toman :heavy_check_mark:
-
vandar :heavy_check_mark:
-
yekpay :heavy_check_mark:
-
zarinpal :heavy_check_mark:
-
zibal :heavy_check_mark:
-
novinopay :heavy_check_mark:
-
stripe :heavy_check_mark:
-
xendit :heavy_check_mark:
-
Others are under way.
Help me to add the gateways below by creating pull requests
- authorize
- 2checkout
- braintree
- skrill
- payU
- amazon payments
- wepay
- payoneer
- paysimple
you can create your own custom drivers if it doesn't exist in the list, read the
Create custom driverssection.
Install
Via Composer
composer require shetabit/multipay
Configure
a. Copy config/payment.php into somewhere in your project. (you can also find it in vendor/shetabit/multipay/config/payment.php path).
b. In the config file you can set the default driver to be used for all your payments and you can also change the driver at runtime.
Choose what gateway you would like to use in your application. Then make that as default driver so that you don't have to specify that everywhere. But, you can also use multiple gateways in a project.
// Eg. if you want to use zarinpal.
'default' => 'zarinpal',
Then fill the credentials for that gateway in the drivers array.
'drivers' => [
'zarinpal' => [
// Fill in the credentials here.
'apiPurchaseUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentRequest.json',
'apiPaymentUrl' => 'https://www.zarinpal.com/pg/StartPay/',
'apiVerificationUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentVerification.json',
'merchantId' => '',
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
...
]
c. Instantiate the Payment class and pass configs to it like the below:
use Shetabit\Multipay\Payment;
// load the config file from your project
$paymentConfig = require('path/to/payment.php');
$payment = new Payment($paymentConfig);
How to use
your Invoice holds your payment details, so initially we'll talk about Invoice class.
Working with invoices
before doing any thing you need to use Invoice class to create an invoice.
In your code, use it like the below:
// At the top of the file.
use Shetabit\Multipay\Invoice;
...
// Create new invoice.
$invoice = new Invoice;
// Set invoice amount.
$invoice->amount(1000);
// Add invoice details: There are 4 syntax available for this.
// 1
$invoice->detail(['detailName' => 'your detail goes here']);
// 2
$invoice->detail('detailName','your detail goes here');
// 3
$invoice->detail(['name1' => 'detail1','name2' => 'detail2']);
// 4
$invoice->detail('detailName1','your detail1 goes here')
->detail('detailName2','your detail2 goes here');
Available methods:
uuid: set the invoice unique idgetUuid: retrieve the invoice current unique iddetail: attach some custom details into invoicegetDetails: retrieve all custom detailsamount: set the invoice amountgetAmount: retrieve invoice amounttransactionId: set invoice payment transaction idgetTransactionId: retrieve payment transaction idvia: set a driver we use to pay the invoicegetDriver: retrieve the driver
Purchase invoice
In order to pay the invoice, we need the payment transactionId. We purchase the invoice to retrieve transaction id:
// At the top of the file.
use Shetabit\Multipay\Invoice;
use Shetabit\Multipay\Payment;
...
// load the config file from your project
$paymentConfig = require('path/to/payment.php');
$payment = new Payment($paymentConfig);
// Create new invoice.
$invoice = (new Invoice)->amount(1000);
// Purchase the given invoice.
$payment->purchase($invoice,function($driver, $transactionId) {
// We can store $transactionId in database.
});
// Purchase method accepts a callback function.
$payment->purchase($invoice, function($driver, $transactionId) {
// We can store $transactionId in database.
});
// You can specify callbackUrl
$payment->callbackUrl('http://yoursite.com/verify')->purchase(
$invoice,
function($driver, $transactionId) {
// We can store $transactionId in database.
}
);
Pay invoice
After purchasing the invoice, we can redirect the user to the bank payment page:
// At the top of the file.
use Shetabit\Multipay\Invoice;
use Shetabit\Multipay\Payment;
...
// load the config file from your project
$paymentConfig = require('path/to/payment.php');
$payment = new Payment($paymentConfig);
// Create new invoice.
$invoice = (new Invoice)->amount(1000);
// Purchase and pay the given invoice.
// You should use return statement to redirect user to the bank page.
return $payment->purchase($invoice, function($driver, $transactionId) {
// Store transactionId in database as we need it to verify payment in the future.
})->pay()->render();
// Do all things together in a single line.
return $payment->purchase(
(new Invoice)->amount(1000),
function($driver, $transactionId) {
// Store transactionId in database.
// We need the transactionId to verify payment in the future.
}
)->pay()->render();
// Retrieve json format of Redirection (in this case you can handle redirection to bank gateway)
return $payment->purchase(
(new Invoice)->amount(1000),
function($driver, $transactionId) {
// Store transactionId in database.
// We need the transactionId to verify payment in the future.
}
)->pay()->toJson();
Verify payment
When user has completed the payment, the bank redirects them to your website, then you need to verify your payment in order to ensure the invoice has been paid.
// At the top o
