danialpanah/webpay

Laravel在线支付网关Webpay处理包

1.0.0 2020-04-03 10:55 UTC

This package is auto-updated.

Last update: 2024-09-04 20:19:27 UTC


README

Build Status Latest Release on Packagist Software License

介绍

这是一个Laravel包,用于连接并在您的Laravel应用程序中通过Webpay支付网关接受支付。

安装

  • 使用以下命令进行安装
composer require danialpanah/webpay

此包支持Laravel自动发现功能。如果您正在使用Laravel 5.5或更高版本,则无需执行任何其他操作,否则请按照以下步骤进行。

  • 将服务提供者添加到您的laravel应用程序中config/app.php文件的providers[]数组中
DanialPanah\Webpay\WebpayServiceProvider::class
  • 要使用Laravel Facade,请将别名添加到您的Laravel config/app.php文件中的aliases[]数组中
'Webpay': DanialPanah\Webpay\Facades\Webpay::class

配置

  • 安装后,您需要添加您的Webpay API设置。您可以通过更新发布的文件config/webpay.php或在您的Laravel .env文件中。

  • 运行以下命令发布配置文件

php artisan vendor:publish --provider "DanialPanah\Webpay\WebpayServiceProvider"
  • config/webpay.php
return [
    'api_key' => env('WEBPAY_API_KEY', ''),
    'callback_url' => env('WEBPAY_CALLBACK_URL', '')
];
  • 将以下内容添加到.env.example.env文件中
#Webpay API key and Settings

#your webpay api key e.g "webpay:2bbc6c62-4fe..."
WEBPAY_API_KEY=

#address of rediricting after payment e.g "/payment/test"
WEBPAY_CALLBACK_URL=

用法

以下是一些通过Webpay包发起支付的方法

  • 发起支付并接收支付URL
// Importing the class namespaces before using it
use DanialPanah\WebPay\Webpay;

$samplePayment = [
   'amount' => 10000,  //required
   'reference_number' => '#####',  //required - invoice number(unique)
   'payer_mobile' => '',  //optional - payer mobile number for save/load cards in gateway
   'cards' => '',  //optional - allowed cards for perform payment
];

$webPay = new Webpay();
$paymentUrl = $webPay->sendPayment($samplePayment);
  • 使用Facades(发起支付)
use DanialPanah\WebPay\Facades\Webpay;

$paymentUrl = Webpay::sendPayment($samplePayment);
  • 验证支付
$paymentDetails = [
   'amount' => 10000,  //required
   'reference_number' => '#####'  //required - invoice number
];

$webPay = new Webpay();
$response = $webPay->verifyPayment($paymentDetails);
  • 使用Facades(验证支付)
use DanialPanah\WebPay\Facades\Webpay;

$response = Webpay::verifyPayment($paymentDetails);
  • 验证成功支付的示例响应
array: [
  "ok" => true
  "result" => {
      "state": "paid"
      "total": 10000
      "wage": 1500
      "gateway": "sep"
      "terminal": "11423087"
      "pay_ref": "KmsctypmKSs0WfEB01H3ROJPLN2ZQrauExLR90nnXk"
      "pay_trace": "228945"
      "pay_pan": "610422******8585"
      "pay_cid": "4470D3E90AA5Z3FB7B21B3348D34EE25EC331915BCQP68BC4D0D1C0678548B8D"
      "pay_time": "2020-04-02T17:47:14.391164Z"
  }
]
  • Laravel示例控制器
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DanialPanah\WebPay\Facades\Webpay;

class PaymentController extends Controller
{
    /**
     * @return RedirectResponse|Redirector
     * @throws WebpayException
     */    
     public function pay()
    {
        $userTrustedCards = ['6219196262191962', '6104046161040461'];

        $samplePayment = [
           'amount' => 10000,
           'reference_number' => '999999',
           'payer_mobile' => '09121111111',
           'cards' => $userTrustedCards,
        ];

        $paymentUrl = Webpay::sendPayment($samplePayment);

        return redirect($paymentUrl);
    }


    /**
     * @param Request $request
     * @throws VerifyException
     */
    public function verify(Request $request)
    {
        $paymentDetails = [
            'amount' => 10000,
            'reference_number' => '999999',
        ];

        $response = Webpay::verifyPayment($paymentDetails);

        if(!$reponse['ok'] === true) {
            //Transactions was not successful
        }

        //Do something for successful transactoin

    }
}

支持和安全

此包支持Laravel 5.1或更高版本,6.x和7.x,以及PHP 7.2及以上版本。

  • 如果在发现任何问题时,请在此问题部分创建一个。
  • 对于贡献,请分叉此存储库并实现您的代码,然后创建一个PR。

许可证

此存储库是在MIT许可证下开源的软件。