2017 © Pedro Peláez
 

yii2-extension yii2-free-kassa

FreeKassa component for Yii2

image

arsik/yii2-free-kassa

FreeKassa component for Yii2

  • Thursday, October 5, 2017
  • by arsik
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 7 Versions
  • 14 % Grown

The README.md

Free Kassa component for Yii2

Payment gateway and api client for Free Kassa service., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist yarcode/yii2-free-kassa "~1.0"

or add, (*4)

"yarcode/yii2-free-kassa": "~1.0"

to the require section of your composer.json., (*5)

Usage

Component configuration

Configure freeKassa component in the components section of your application., (*6)

'freeKassa' => [
    'class' => '\yarcode\freekassa\Merchant',
    'merchantId' => 'YOUR_MERCHANT_ID',
    'merchantFormSecret' => 'SECRET_1',
    'checkDataSecret' => 'SECRET_2',
    'defaultCurrency' => 'DEFAULT_CURRENCY_ID',
    'defaultLanguage' => 'ru' // or 'en' 
],

Redirecting to the payment system

To redirect user to PerfectMoney site you need to create the page with RedirectForm widget. User will redirected right after page load., (*7)

<?= \yarcode\freekassa\RedirectForm::widget([
    'message' => 'Redirecting to payment gateway...',
    'api' => Yii::$app->get('freeKassa'),
    'invoiceId' => $invoice->id,
    'amount' => $invoice->amount,
    'description' => $invoice->description,
    'email' => $invoice->owner->email
]); ?>

Gateway controller

You will need to create controller that will handle result requests from PerfectMoney service. Sample controller code:, (*8)

<?php
namespace frontend\controllers;

use common\models\Invoice;
use yii\base\Event;
use yii\helpers\ArrayHelper;
use yii\helpers\VarDumper;
use yii\web\Controller;
use yarcode\freekassa\actions\ResultAction;
use yarcode\freekassa\events\GatewayEvent;
use yarcode\freekassa\Merchant;

class PerfectMoneyController extends Controller
{
    public $enableCsrfValidation = false;

    protected $componentName = 'freeKassa';

    public function init()
    {
        parent::init();
        /** @var Api $pm */
        $freeKassa = \Yii::$app->get($this->componentName);
        $freeKassa->on(GatewayEvent::EVENT_PAYMENT_REQUEST, [$this, 'handlePaymentRequest']);
        $freeKassa->on(GatewayEvent::EVENT_PAYMENT_SUCCESS, [$this, 'handlePaymentSuccess']);
    }

    public function actions()
    {
        return [
            'result' => [
                'class' => ResultAction::className(),
                'componentName' => $this->componentName,
                'redirectUrl' => ['/site/index'],
                'sendConfirmationResponse' => true
            ],
            'success' => [
                'class' => ResultAction::className(),
                'componentName' => $this->componentName,
                'redirectUrl' => ['/site/index'],
                'silent' => true,
                'sendConfirmationResponse' => false
            ],
            'failure' => [
                'class' => ResultAction::className(),
                'componentName' => $this->componentName,
                'redirectUrl' => ['/site/index'],
                'silent' => true,
                'sendConfirmationResponse' => false
            ]
       ];
    }

    /**
     * @param GatewayEvent $event
     * @return bool
     */
    public function handlePaymentRequest($event)
    {
        $invoice = Invoice::findOne(ArrayHelper::getValue($event->gatewayData, 'MERCHANT_ORDER_ID'));

        if (!$invoice instanceof Invoice ||
            $invoice->status != Invoice::STATUS_NEW ||
            ArrayHelper::getValue($event->gatewayData, 'AMOUNT') != $invoice->amount ||
            ArrayHelper::getValue($event->gatewayData, 'MERCHANT_ID') != \Yii::$app->get($this->componentName)->merchantId
        )
            return;

        $invoice->debugData = VarDumper::dumpAsString($event->gatewayData);
        $event->invoice = $invoice;
        $event->handled = true;
    }

    /**
     * @param GatewayEvent $event
     * @return bool
     */
    public function handlePaymentSuccess($event)
    {
        $invoice = $event->invoice;

        // TODO: invoice processing goes here 
    }
}

Licence

MIT, (*9)

The Versions

05/10 2017

dev-master

9999999-dev http://yiidreamteam.com/yii2/free-kassa

FreeKassa component for Yii2

  Sources   Download

MIT

The Requires

 

payment yii2 billing yii2-extension freekassa free-kassa

11/03 2017

0.13.0

0.13.0.0 http://yiidreamteam.com/yii2/free-kassa

FreeKassa component for Yii2

  Sources   Download

MIT

The Requires

 

payment yii2 billing yii2-extension freekassa free-kassa

04/02 2017

0.12.0

0.12.0.0 http://yiidreamteam.com/yii2/free-kassa

FreeKassa component for Yii2

  Sources   Download

MIT

The Requires

 

payment yii2 billing yii2-extension freekassa free-kassa

04/02 2017

0.11.0

0.11.0.0 http://yiidreamteam.com/yii2/free-kassa

FreeKassa component for Yii2

  Sources   Download

MIT

The Requires

 

payment yii2 billing yii2-extension freekassa free-kassa

17/11 2016

0.10.0

0.10.0.0 http://yiidreamteam.com/yii2/free-kassa

FreeKassa component for Yii2

  Sources   Download

MIT

The Requires

 

payment yii2 billing yii2-extension freekassa free-kassa

01/03 2016

0.9.1

0.9.1.0 http://yiidreamteam.com/yii2/free-kassa

FreeKassa component for Yii2

  Sources   Download

MIT

The Requires

 

payment yii2 billing yii2-extension freekassa free-kassa

18/02 2016

0.9

0.9.0.0 http://yiidreamteam.com/yii2/free-kassa

FreeKassa component for Yii2

  Sources   Download

MIT

The Requires

 

payment yii2 billing yii2-extension freekassa free-kassa