2017 © Pedro Peláez
 

yii2-extension yii2-onpay

Yii2 onpay extension

image

ejen/yii2-onpay

Yii2 onpay extension

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Yii2 extension for onpay.ru service

Installation

Yii2-onpay can be installed using composer. Run following command to download and install Yii2-onpay:, (*1)

composer require ejen/yii2-onpay ~1.0 

Configure

config/main.php

``` php ... 'components' => [ ... 'onpay' => [ 'class' => 'ejen\payment\Onpay', 'url_success' => 'http://path/to/success/page', 'url_fail' => 'http://path/to/fail/page', ], ... ], ..., (*2)


### config/main-local.php ``` php ... 'components' => [ ... 'onpay' => [ 'secret_key' => 'YOUR_SECRET_KEY', 'username' => 'YOUR_USERNAME', ], ... ], ...

Api handler example.

This example can pass all OnPay api online tests., (*3)

<?php

namespace frontend\controllers;

use ejen\payment\onpay\ApiAction;

class OnpayController extends \yii\web\Controller
{
    public function actions()
    {
        return [
            'api' => [
                'class' => ApiAction::className(),
                'payCallback' => [$this, 'payCallback'],
                'checkCallback' => [$this, 'checkCallback'],
            ],
        ];
    }

    public function payCallback($request, $response)
    {
        $amount = 100;
        $currency = 'RUR';

        if ($request->balance_amount < $amount)
        {
            $response->code = 3;
            $response->comment = 'bad_pay';
            return false;
        }

        if ($request->balance_currency != $currency)
        {
            $response->code = 3;
            $response->comment = 'bad_pay';
            return false;
        }

        return true;
    }

    public function checkCallback($request, $response)
    {
        $amount = 500;
        $currency = 'RUR';

        if ($request->amount < $amount)
        {
            $response->code = 2;
            return false;
        }

        if ($request->amount > $amount || $request->order_currency != $currency)
        {
            $response->code = 3;
            return false;
        }

        return true;
    }
}

Payment example

<?php

namespace frontend\controllers;

use Yii;

use frontend\forms\PaymentForm;

class PaymentController extends \yii\web\Controller
{

    public function actionIndex()
    {
        $model = new PaymentForm;
        if ($model->load(Yii::$app->request->post()) && $model->validate())
        {
            $payment = Yii::$app->onpay->createPayment([
                'price' => $model->amount,
                'pay_for' => Yii::$app->user->id,
            ]);

            if ($payment->validate())
            {
                return $this->redirect($payment->getUrl());
            }
        }        

        return $this->render('index', [
            'model' => $model,
        ]);
    }
}

The Versions

07/08 2017

dev-master

9999999-dev https://github.com/ejen/yii2-onpay

Yii2 onpay extension

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 onpay

07/08 2017

1.0.4

1.0.4.0 https://github.com/ejen/yii2-onpay

Yii2 onpay extension

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 onpay

28/06 2017

1.0.2

1.0.2.0 https://github.com/ejen/yii2-onpay

Yii2 onpay extension

  Sources   Download

BSD-3-Clause

The Development Requires

yii2 onpay

28/06 2017

1.0.1

1.0.1.0 https://github.com/ejen/yii2-onpay

Yii2 onpay extension

  Sources   Download

BSD-3-Clause

yii2 onpay

23/01 2017

1.0.0

1.0.0.0 https://github.com/ejen/yii2-onpay

Yii2 onpay extension

  Sources   Download

BSD-3-Clause

yii2 onpay