PHP code example of iranrenter-group / laravel-online-payment

1. Go to this page and download the library: Download iranrenter-group/laravel-online-payment library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iranrenter-group / laravel-online-payment example snippets


Tartan\Larapay\LarapayServiceProvider::class,

'Larapay' => Tartan\Larapay\Facades\Larapay::class,

namespace App\Model;

use Tartan\Larapay\Transaction;

class Transaction extends Model implements TransactionInterface
{
    // set order reference Id
	public function setReferenceId($referenceId, $save = true){}

    // check if you transaction is ready for requesting payment token 
	public function checkForRequestToken(){}

    // check if transaction is ready for requesting verify transaction
	public function checkForVerify(){}

    // check if transaction is ready for requesting inqury transaction (if supported by gateway)
	public function checkForInquiry(){}

    // check if transaction is ready for requesting reverse transaction (if supported by gateway)
	public function checkForReverse(){}

    // check if transaction is ready for requesting settle/... transaction (if needed by gateway)
	public function checkForAfterVerify(){}

    // update transaction by paid card number (if provided by gateway)
	public function setCardNumber($cardNumber){}
    
    // mark transaction as verified
	public function setVerified(){}
    
    // mark transaction as settled/...
	public function setAfterVerified(){}

    // mark transaction as completed
	public function setSuccessful($flag){}

    // mark transaction as reversed
	public function setReversed(){}

    // get transaction amount
	public function getAmount(){}

    // set transactions's paid tme
	public function setPaidAt($time = 'now'){}

    // set transaction's extra details
	public function setExtra($key, $value, $save = false){}
}

    public function payOnline (Request $request, Transaction $transaction)
    {
        // check if the selected payment is active or not from your gateways table
        $paymentGateway = Gateway::activeGate()
            ->where('slug', $request->input('by_online_gateway'))
            ->first();

        if (empty($paymentGateway)) {
            return view('gateway.notfound');
        }

        // get some additional parameters for updating transaction
        $parameters = [
            'description' => $request->input('by_online_description', ''),
            'bank'        => $request->input('by_online_gateway'),
        ];

        // update transaction payment method
        $transaction = $this->transactionsRepository->setTransactionPaid(
            $transaction, TransactionPayment::ONLINE, $parameters
        );

        // make larapay payment gateway instance
        $paymentGatewayHandler = Larapay::make($paymentGateway->slug, $transaction);


        // set payment params 
        $paymentParams = [
            'order_id'     => $transaction->getBankOrderId(),
            'redirect_url' => route('payment.callback', [
                'bank' => $paymentGateway->slug,
                'transactionId' => $transaction->guid
            ]),
            'amount'       => $transaction->amount,
            'submit_label' => trans('larapay::larapay.goto_gate')
        ];

        try {
            // get goto gate form
            $form = $paymentGatewayHandler->form($paymentParams);
        } catch (\Exception $e) {
            // could not generate goto gate form
            Log::emergency($paymentGateway->slug . ' #' . $e->getCode() . '-' . $e->getMessage());
            Session::flash('alert-danger', trans('trans.could_not_create_goto_bank_form', ['gateway' => $paymentGateway->name]));

            return redirect()->back()->withInput();
        }
        if (is_null($form)) {
            return redirect()->back()->withInput();
        }

        // view goto gate view
        return view('gateway.gotogate', [
            'gateway'     => $paymentGateway,
            'form'        => $form,
        ]);
    }

return [

	/*
	|--------------------------------------------------------------------------
	| Tartan e-payment component`s operation mode
	|--------------------------------------------------------------------------
	|
	| *** very important config ***
	| please do not change it if you don't know what BankTest is
	|
	| > production: component operates with real payments gateways
	| > development: component operates with simulated "BankTest" (banktest.ir) gateways
	|
	*/
	'mode'     => env('LARAPAY_MODE', 'production'),

	/*
	|--------------------------------------------------------------------------
	| ready to serve gateways
	|--------------------------------------------------------------------------
	|
	| specifies ready to serve gateways.
	| gateway characters are case sensitive and should be exactly same as their folder name.
	|    eg, "Jahanpay" is correct not "JahanPay" or "jahanpay"
	| the gateways list is comma separated
	|
	*/
	'gateways' => env('LARAPAY_GATES', 'Mellat,Saman,Pasargad'),

	/*
	|--------------------------------------------------------------------------
	| Mellat gateway configuration
	|--------------------------------------------------------------------------
	*/
	'mellat'   => [
		'username'     => env('MELLAT_USERNAME', ''),
		'password'     => env('MELLAT_PASSWORD',''),
		'terminal_id'  => env('MELLAT_TERMINAL_ID', ''),
		'callback_url' => env('MELLAT_CALLBACK_URL', '')
	],

	/*
	|--------------------------------------------------------------------------
	| Parsian gateway configuration
	|--------------------------------------------------------------------------
	*/
	'parsian'  => [
		'pin'          => env('PARSIAN_PIN', ''),
	],
	/*
	|--------------------------------------------------------------------------
	| Pasargad gateway configuration
	|--------------------------------------------------------------------------
	*/
	'pasargad' => [
		'terminalId'       => env('PASARGAD_TERMINAL_ID', ''),
		'merchantId'       => env('PASARGAD_MERCHANT_ID', ''),
		'certificate_path' => storage_path(env('PASARGAD_CERT_PATH', 'payment/pasargad/certificate.xml')),
		'callback_url'     => env('PASARGAD_CALLBACK_URL', '')
	],

	/*
	|--------------------------------------------------------------------------
	| Sadad gateway configuration
	|--------------------------------------------------------------------------
	*/
	'sadad'    => [
		'merchant'        => env('SADAD_MERCHANT', ''),
		'transaction_key' => env('SADAD_TRANS_KEY', ''),
		'terminal_id'     => env('SADAD_TERMINAL_ID', ''),
		'callback_url'    => env('SADAD_CALLBACK_URL', ''),
	],

	'saderat' => [
		'MID' => env('SADERAT_MID', ''),
		'TID' => env('SADERAT_TID', ''),
		'public_key_path' => storage_path(env('SADERAT_CERT_PATH', 'payment/saderat/public.key')),
		'private_key_path' => storage_path(env('SADERAT_CERT_PATH', 'payment/saderat/private.key')),
	],

	/*
	|--------------------------------------------------------------------------
	| Saman gateway configuration
	|--------------------------------------------------------------------------
	*/
	'saman'    => [
		'merchant_id'   => env('SAMAN_MERCHANT_ID', ''),
		'merchant_pass' => env('SAMAN_MERCHANT_PASS', ''),
	],

	/*
	|--------------------------------------------------------------------------
	| Zarinpal gateway configuration
	|--------------------------------------------------------------------------
	|
	| types: acceptable values  --- zarin-gate or normal
	| server: acceptable values --- germany or iran or test
	|
	*/
	'zarinpal' => [
		'merchant_id'  => env('ZARINPAL_MERCHANT_ID', ''),
		'type'         => env('ZARINPAL_TYPE', 'zarin-gate'),
		'callback_url' => env('ZARINPAL_CALLBACK_URL', ''),
		'server'       => env('ZARINPAL_SERVER', 'germany'),
		'email'        => env('ZARINPAL_EMAIL', ''),
		'mobile'       => env('ZARINPAL_MOBILE', '09xxxxxxxxx'),
		'description'  => env('ZARINPAL_MOBILE', 'powered-by-TartanPayment'),
	],
	/*
	|--------------------------------------------------------------------------
	| Pay.ir gateway configuration
	|--------------------------------------------------------------------------
	*/
	'pay_ir'    => [
        	'api'   => env('PAY_IR_API_KEY', ''),
    	],

    /*
    |--------------------------------------------------------------------------
    | SoapClient Options
    |--------------------------------------------------------------------------
    |
    | useOptions: true/false
    | options: soapClient Options
    |
    */
    'soap' => [
        'useOptions' => env('SOAP_HAS_OPTIONS', false),
        'options' => [
            'proxy_host' => env('SOAP_PROXY_HOST', ''),
            'proxy_port' => env('SOAP_PROXY_PORT', ''),
            'stream_context' => stream_context_create(
                [
                    'ssl' => [
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                    ],
                ]
            ),
        ]
    ]
];
bash
php artisan vendor:publish