ahmadmrj/payir

此包最新版本(1.0.0)无可用许可证信息。

laravel 库,用于处理与 pay.ir 服务的支付操作

1.0.0 2018-10-05 14:41 UTC

This package is auto-updated.

Last update: 2024-09-06 09:45:48 UTC


README

一个用于实现与 pay.ir 服务支付操作的 Laravel 库

要安装此包

composer install ahmadmrj/payir

安装后,将以下内容添加到您的 config/app.php 文件中的 provider 部分,以便将包作为服务提供者使用

'providers' => [
  .
  .
  Ahmadmrj\Payir\PaymentServiceProvider::class
]

支付控制器示例

<?php

namespace App\Http\Controllers;

use Ahmadmrj\Payir\Payir;

class PaymentController extends Controller
{
    public $payment;

    public function __construct()
    {
        $this->payment = new Payir([
            'gateWayApiUrl' => 'https://pay.ir/payment/send',
            'redirectUrl' => 'https://pay.ir/payment/gateway/',
            'verifyUrl' => 'https://pay.ir/payment/verify',
            'apiKey' => 'test',
            'callbackUrl' => Your Call Back URL,
            'mobileNumber' => '',
        ]);
    }

    public function pay(){
        $amount = AMOUNT;
        $invoice_id = Faktor NUMBER;
        $status = $this->payment->sendApiRequest($amount,$invoice_id);

        if($status) {
            // redirect to bank payment page
            return redirect($this->payment->config->redirectUrl . $this->payment->transId);
        }else{
            //in case payment operation is not successful
            return redirect('/payment')->withErrors([$this->payment->paymentErrorMessage]);
        }
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function verify(Request $request){
        //check if payment operation has been done!
        if($request->status === Payir::SUCCESSFUL_STATUS)
        {
            $verify_result = $this->payment->verify($request);

            if($verify_result){
                $verify_status = 'committed';
            }
            else{
                $verify_status = 'failed';
                $error_message = $this->payment->verifyErrorMessage;
            }
        }
        else
        {
            $verify_status = 'failed';
            $error_message = $request->message;
        }

        if($verify_status == 'committed'){
            return redirect('/payment')->with('message',__('messages.Payment has done successfully.'));
        }
        else {
            return redirect('/payment')->withErrors([$error_message]);
        }
    }
}