dena-a / iran-payment by dena-a

a Laravel package to handle Internet Payment Gateways for Iran Banking System
1,677
20
3
Package Data
Maintainer Username: dena-a
Package Create Date: 2016-11-02
Package Last Update: 2024-03-11
Home Page: https://iran-payment.oneapp.ir/
Language: PHP
License: MIT
Last Refreshed: 2024-04-22 03:08:41
Package Statistics
Total Downloads: 1,677
Monthly Downloads: 28
Daily Downloads: 1
Total Stars: 20
Total Watchers: 3
Total Forks: 15
Total Open Issues: 2

IranPayment

a Laravel package to handle Internet Payment Gateways for Iran Banking System

Installation

You can install the package via composer:

$ composer require dena-a/iran-payment

This service provider must be installed.

// config/app.php
'providers' => [
    ...
    Dena\IranPayment\IranPaymentServiceProvider::class
];

Add aliases:

// config/app.php
'aliases' => [
    ...
    'IranPayment' => Dena\IranPayment\IranPayment::class,
];

Publish the config-file and migration with:

php artisan vendor:publish --provider="Dena\IranPayment\IranPaymentServiceProvider"

After the migration has been published you can create the transactions-tables by running the migrations:

php artisan migrate

Usage

New Payment:

//default gateway
$payment = new IranPayment();
// OR one of ['zarinpal', 'saman', 'payir']
$payment = new IranPayment('zarinpal');
// OR test gateway (Only works on debug mode)
$payment = new IranPayment('test');

$payment->build()
        ->setUserId($user->id)
        ->setAmount($data['amount'])
        ->setCallbackUrl(route('bank.callback'))
        ->ready();

return $payment->redirectView();

Verify Payment:

$payment = new IranPayment();
$payment->build()->verify($transaction);
$trackingCode = $payment->getTrackingCode();
$statusText = $payment->getTransactionStatusText();

Extends

use Dena\IranPayment\Providers\BaseProvider;
use Dena\IranPayment\Providers\GatewayInterface;

class NewGateway extends BaseProvider implements GatewayInterface {
    
    public function getName() {
        return 'new-gateway';
    }
    
    public function payRequest() {
        $code = rand(1, 10000);
        $this->setReferenceNumber($code);
        $this->transactionPending([
            'reference_number'	=> intval($code)
        ]);
    }
    
    public function verifyRequest() {
        $this->transactionVerifyPending();
        $code = rand(1, 10000);
        $this->setTrackingCode($code);
		$this->transactionSucceed(['tracking_code' => $code]);
    }
    
    public function redirectView() {
        return view('welcome')->with([
            'transaction' => $this->getTransaction()
        ]);
    }
    
    public function payBack() {
    }
}

$payment = new IranPayment();
$payment->extends(NewGateway::class);

License

The MIT License (MIT). Please see License File for more information.