kllakk/yii2-yandex-kassa-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kllakk/yii2-yandex-kassa-api

Composer 安装命令:

composer require kllakk/yii2-yandex-kassa-api

包简介

This extensions allows you obtain money from users by new Yandex.Kassa's API

README 文档

README

This extension allows you to obtain money from users by new Yandex.Kassa's API.
It was designed to be pretty simple to use so you don't have to deep down into Yandex.Kassa's workflow.

This extension strongly in beta, so feel free to send pull requests and fix bugs

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist kllakk/yii2-yandex-kassa-api "*"

or add

"kllakk/yii2-yandex-kassa-api": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, you have to follow next few steps:

1. Add extension into your configuration file

'components' => [
    ...
    'kassa' => [
        'class' => 'kllakk\YandexKassaAPI\YandexKassaAPI',
        'returnUrl' => '',
        'shopId' => '',
        'key' => '',
    ],

returnUrl - User will get there after payment has got succeeded
shopId - Your shop id (from Yandex)
key - Your secret key (from Yandex)
currency - Currency obviously (RUB by default)

2. Implement OrderInterface in your Order model

class Orders extends Model implements OrderInterface {
    
    ...
      
    public function setInvoiceId($invoiceId) {
        $this->invoice_id = $invoiceId;
    }

    
    public function getInvoiceId() {
        return $this->invoice_id;
    }

    
    public function getPaymentAmount() {
        return $this->amount;
    }

    
    public function findByInvoiceId($invoiceId) {
        return self::find()->where(['invoice_id' => $invoiceId]);
    }
    
    public function findById($id) {
        return self::findOne($id);
    }

}

3. Add new actions to your controller

 public function actions() {
        return [
            'create-payment' => [
                'class'=>'kllakk\YandexKassaAPI\actions\CreatePaymentAction',
                'orderClass' => Orders::className(),
                'beforePayment' => function($order) {
                    return $order->status == Orders::STATUS_NEW;
                }
            ],
            'notify' => [
                'class'=>'kllakk\YandexKassaAPI\actions\ConfirmPaymentAction',
                'orderClass' => Orders::className(),
                'beforeConfirm' => function($payment, $order) {
                    $order->status = Orders::STATUS_PAID; 
                    return $order->save();
                }
            ]
        ];
    }

Here we have two callbacks.

beforePayment checks is our order okay. You can provide some logic there and return false if something went wrong and you wanna cancel your payment.

The second one is beforeConfirm. It executes when user successfully paid your payment and now you have to confirm this order, send sms notification, etc. Be careful, if you return false is this callback, payment won't be confirmed and user will receive his money back in a few hours.

4. Config your Yandex.Kassa notification page

Settings page

Set your notification page Url as same as you used in your controller.
For example, if you added your actions to SiteController, it would be https://yoursite.com/site/notify
Don't forget about SSL - Yandex sends notifications only through it.

5. Redirect user to payment action afterwards

if ($order->payment_type == $order::PAYTYPE_ONLINE) {
    return $this->redirect(['order/create-payment', 'id' =>$order->id]);
} else {
    return $this->redirect(['order/success']);
}

You have to pass $id to the action so it could find your model by findById method.

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固