aminkt/yii2-payment-module

此包的最新版本(v2.0.0)没有可用的许可信息。

yii2的在线支付模块

安装: 112

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 1

开放问题: 0

类型:yii2-extension

v2.0.0 2019-12-18 21:47 UTC

This package is auto-updated.

Last update: 2024-09-14 01:40:38 UTC


README

如果您想帮助改进此项目,我将非常乐意使用您的帮助。有关贡献,请参阅此链接。

贡献指南

如何安装此模块

步骤1:将以下行添加到composer.json的require部分

"aminkt/yii2-payment-module": "*",

或者运行以下命令

composer require aminkt/yii2-payment-module

步骤2:在您的应用程序配置中添加以下行

'payment' => [
    'class' => aminkt\yii2\payment\Payment::class,
    'minAmount' => 100, // Min availbale money that can pay by gates.
    // If you want, same as minAmount you can set maxAmount.
    'maxAmount' => 1000000,
    // In Development you can uncomment below line to enable by pass mode.This config will pass the gates.
    // 'enableByPass' => true,
    'orderClass' => \common\models\Order::class,    Your order model class name.
    // Add this part to add your own gates.
    'components' => [
        'payment' => [
            'class' => aminkt\yii2\payment\components\Payment::class,
            // Uncomment below line if you wnat change you default callback address.
            // 'callback' => ['/v1/payment/verify'],
            'bankTimeout' => 60 * 30, // Max time user can be in bank site.
            'encryptKey' => 'wumBOOH04e', // This key will used to generate security token
            'blockTime' => 10, // How many times system allow to a user have risky actions.
            'gates' => [
               'Parsian' => [
                   'class' => \aminkt\yii2\payment\gates\Parsian::class,
                   'identityData' => [
                       'pin' => 'x8Xd1tR4So8kL50d3EV1',
                       'terminal' => '92133477'
                   ]
               ],
               'BehPardakht' => [
                   'class' => \aminkt\yii2\payment\gates\MellatGate::class,
                   'identityData' => [
                       'terminalId' => '****',
                       'userName' => '****',
                       'password' => '****',
                       'payerId' => 0,
                       'webService' => 'https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl',
                       'bankGatewayAddress' => 'https://bpm.shaparak.ir/pgwchannel/startpay.mellat',
                   ]
               ],
           
           ]
        ]
    ]
]

请始终将Mellat Bank网关添加到网关列表的底部,因为它可能会导致自动网关选择器问题。当Mellat网关不可用时,它会抛出异常,系统无法捕获它,因此进程可能失败。如果您可以修复此问题,请做出贡献。

步骤3:创建自己的订单模型,并在您的订单模型中实现aminkt\yii2\payment\interfaces\OrderInterface。在此模块中使用订单模型是必需的。

注意:使用表格作为订单模型是跟踪您试图销售的所有内容的标准模式。有关更多信息,请参阅此链接:[http://www.databaseanswers.org/data_models/customers_and_orders/index.htm](http://www.databaseanswers.org/data_models/customers_and_orders/index.htm)

数据库迁移

在使用此扩展之前,我们还需要准备数据库。

php yii migrate --migrationPath=@vendor/aminkt/yii2-payment-module/migrations

用法

在您的代码中,当您想要创建一个支付请求时,请使用以下代码

$payment = \aminkt\payment\Payment::getInstance()->payment;
$data = $payment->payRequest($orderModel);

使用$orderModel在您的订单表和支付数据之间建立连接。通过定义此连接,您可以从支付日志中稍后访问您的订单。

当用户付款时,他们将被重定向到您定义的页面。默认情况下,用户将被重定向到/payment/default/verify路由。

要更改默认回调页面,请使用以下代码

$payment = \aminkt\payment\Payment::getInstance()->payment;
$payment->callback = ['/your-controller/your-action']; // callBack give an array defined a route.

您还可以在模块配置中全局设置回调地址。

在您的验证页面中,使用以下代码来验证支付

$verify = Payment::getInstance()
            ->getPayment()
            ->verify();

if($verify) {
    // Payment was successfull.
} else {
    // Paymen verify become failed.
}

$verify如果验证操作失败则为false,否则返回true

安全

模块将检查安全问题,并在yii2日志系统中记录它们。您还可以在支付组件配置中定义以下属性,以更改安全系统的默认行为。

网关配置

每个网关都有自己的配置。在此模块中,准备了一些默认网关,您可以使用。

如果您想创建自己的网关,请参阅创建网关类部分。

您可以为此报告贡献您的网关,并帮助我提高生产力。

网关列表

创建网关类

要创建网关类,您应该在您的应用程序中创建一个新的类,并从\aminkt\yii2\payment\gates\AbstractGate扩展它。

实现未完成的方法,然后使用以下规则从模块配置中读取身份数据和配置

如您所知,每个网关都有自己的配置,用户将将其作为数组准备。您可以通过调用getIdentity方法从您的网关访问此配置。

例如,如果用户使用以下配置

[
    'class' => \name\space\of\your\CustomGate::class,
    'password' => 'some password',
    'verifyUrl' => 'http://your/verify.url'
]

那么在CustomGate中,您可以访问以下方法

getIdentityPassword();
getIdentityVerifyUrl();

实现您的网关。请参阅示例,如果您喜欢,请在此存储库中贡献它。

网关配置

Sep

"Sep" => [
    'class' => \aminkt\payment\lib\Sep::className(),
    'identityData' => [
        'MID' => '******',
        'password' => '******',
        'bankGatewayAddress' => 'https://sep.shaparak.ir/payment.aspx',
        'webService' => "https://sep.shaparak.ir/payments/referencepayment.asmx?WSDL",
    ]
],

MellatGate

'BehPardakht' => [
    'class' => \aminkt\yii2\payment\gates\MellatGate::class,
    'identityData' => [
        'terminalId' => '****',
        'userName' => '****',
        'password' => '****',
        'payerId' => 0,
        'webService' => 'https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl',
        'bankGatewayAddress' => 'https://bpm.shaparak.ir/pgwchannel/startpay.mellat',
    ]
],

Parsian

'Parsian' => [
    'class' => \aminkt\yii2\payment\gates\Parsian::class,
    'identityData' => [
        'payRequestUrl' => 'https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx?WSDL',
        'verifyUrl' => 'https://pec.shaparak.ir/NewIPGServices/Confirm/ConfirmService.asmx?WSDL',
        'gateAddress' => 'https://pec.shaparak.ir/NewIPG/',
        'pin' => '**********',
        'terminal' => '********'
    ]
]

IranKish

'IranKish' => [
    'class' => \aminkt\yii2\payment\gates\IranKish::class,
    'payRequestUrl' => 'https://ikc.shaparak.ir/XToken/Tokens.xml',
    'verifyUrl' => 'https://ikc.shaparak.ir/XVerify/Verify.xml',
    'gateAddress' => 'https://ikc.shaparak.ir/TPayment/Payment/index',
    'merchantId' => '******'
]

ZarinPal

"Zarinpal" => [
    'class' => \aminkt\payment\lib\ZarinPal::className(),
    'identityData' => [
        'merchantCode' => '******',
        'redirectUrl' => 'https://zarinpal.com/pg/StartPay/%u',
        'payRequestUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentRequest.json',
        'verifyRequestUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentVerification.json',
        'isZarin' => false,
        'enableSandbox' => false
    ]
],

报告

在旧版本中,您可以使用一些路由在您的后端面板中查看一些视图以查看日志,但在当前版本中,我们改进了我们的模块以用于REST模块,因此您仍然有一个路由来读取日志,但作为RESTAPI

此部分尚未完成。

表格和类结构

Data base scheme