stitchua / yii2-paymento
Paymento 支付系统
v1.0.0
2021-05-23 06:28 UTC
Requires
- php: >=7.4.0
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2024-09-23 15:56:20 UTC
README
系统作为名为 paymento
的模块实现,将在配置文件 config/web.php
的 modules
部分进行配置。模块只实现了一种支付方式:[链接](https://paymentopaywall.docs.apiary.io/#/introduction/wprowadzenie)(支付网关)
安装
推荐使用 composer 安装
您可以使用
php composer.phar require --prefer-dist ststichua/yii2-paymento
或添加
"stitchua/yii2-paymento":"*"
到您的 composer.json 文件的 require
部分
安装包后,请在控制台中运行迁移
php yii migrate --migrationPath="@stitchua/paymento/migrations"
配置
用于配置模块的是
merchantId
- Paymento 支付系统中的账户 IDpayloadModelClass
- 支付订单的类,例如 'app/models/Invoice'。该类需要实现两个接口- [stitchua\paymento\base\PaymentoPayloadRequestDataInterface]
- [stitchua\paymento\base\PaymentoResponseDataInterface]
shops
- Paymento 支付系统中的商店。可能有多个商店。每个商店都使用三个参数进行配置nazwaSklepu
- 键,在商店中唯一的任意名称,可以将其添加到实现上述接口的类的常量中。serviceId
- Paymento 系统中分配给商店的标识符serviceKey
- Paymento 系统中分配的私有密钥,用于计算发送到 Paymeno 系统的数据的签名
(哈希码)。
反映发送到 Paymento 的数据的类 [[stitchua/paymento/models/Paywall]]
计算 Paymento 通知的签名
Paymento 通知中的签名是从通知中传输的所有 'transaction' 字段计算得出的,并且应该与在
x-paymento-signature
头部传输的签名进行比较
如何使用
- 在负责订单的类中实现两个接口
- [stitchua\paymento\base\PaymentoPayloadRequestDataInterface]
- [stitchua\paymento\base\PaymentoResponseDataInterface]
- 如配置部分所述进行配置
- 添加支付按钮
实现接口
// Istniejąca klasa/model Invoice namespace app\models; use stitchua\paymento\models\PaymentoTransaction; use yii\db\ActiveRecord; use stitchua\paymento\base\{ PaymentoPayloadRequestDataInterface, PaymentoResponseDataInterface }; class Invoice extends ActiveRecord implements PaymentoPayloadRequestDataInterface, PaymentoResponseDataInterface { public function getCustomerFirstName() : string{ // TODO: Implement getCustomerFirstName() method. return $this->account->first_name; } public function getCustomerLastName() : string{ // TODO: Implement getCustomerLastName() method. return $this->account->last_name; } public function getCustomerEmail() : string{ // TODO: Implement getCustomerEmail() method. return $this->account->email; } public function getAmount() : int{ // TODO: Implement getAmount() method. return $this->amount * 100; // Zwracamy w groszach } public function getId() : int{ // TODO: Implement getId() method. return $this->id; } public function getTitle() : string{ // TODO: Implement getTitle() method. return $this->invoicenumber; } public function paymentoOrderInvoiced(PaymentoTransaction $transaction){ // TODO: Implement paymentoOrderInvoiced() method. if($transaction->canBeSettled()){ $this->settle(); } } }
配置
在配置文件 config/web.php(针对基本模板)中添加
[ 'modules' => [ 'paymento' => [ 'class' => 'stitchua\paymento\Paymento', 'merchantId' => 'jahds-we4fde-erge-fgsf', // ID twojego konta w Paymento 'payloadModelClass' => 'app\models\Invoice', // Klasa realizująca interface-y 'successReturnUrl' => 'https://mysite.com/site/payment-landig-page?status=success', 'failureReturnUrl' => 'https://mysite.com/site/payment-landig-page?status=error', 'shops' => [ // Nazwa sklepu, dowolno ustawiona przez ciebie 'myShop1' => [ 'serviceId' => 'id-sklepu-nadany-przez-paymento', // ID sklepu z Paymento 'serviceKey' => 'tayny-klusz-twojego-sklepu' // klucz sklepu z Paymento ] ] ] ] ]
配置数据
重要提示!!!不要忘记提供 Paymento 反馈的 URL。否则,您的订单将不会在您的系统中进行账务处理。
创建按钮
在发票视图 app\views\invoice\view.php
中,如果发票尚未付款,则显示付款按钮
use stitchua\paymento\models\Paywall; $invoice = Invoice::findOne(10); if(!$invoice->isSettled){ echo \yii\helpers\Html::a('Opłać fakturę', [ '/stitchua/paymento/pay-for-order', 'id' => $invoice->fld_id, 'shopName' => 'myShop1', 'payMethod' => Paywall::METHOD_PBL], [ 'class' => 'btn btn-success', 'target' => '_blank' ] ); }