Giter Site home page Giter Site logo

interkassa's Introduction

Build Status

Yii2 Interkassa

Extension for integration Interkassa in yii2 project. WIP.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist grandmasterx/interkassa "*"

or add

"grandmasterx/interkassa": "*"

to the require section of your composer.json file.

Update config file config/web.php

return [
    'components' => [
        'interkassa' => [
            'class' => 'grandmasterx\interkassa\Component',
            'co_id' => '', // Cashbox identifier
            'secret_key' => '', // Cashbox secret key
            'test_key' => '', // Cashbox test secret key
            'sign_algo' => 'md5', // Sign algoritm. Allow: md5, sha1
            'api_user_id' => '', // Api user id
            'api_user_key' => '' // Api user secret key
        ],
    ],
]

Usage

Example payment:

class InterkassaController extends Controller
{
    public function actions() {
        return [
            'result' => [
                'class' => 'grandmasterx\interkassa\ResultAction',
                'callback' => [$this, 'resultCallback'],
            ],
            'success' => [
                'class' => 'grandmasterx\interkassa\SuccessAction',
                'callback' => [$this, 'successCallback'],
            ],
            'fail' => [
                'class' => 'grandmasterx\interkassa\FailAction',
                'callback' => [$this, 'failCallback'],
            ],
        ];
    }

    public function actionInvoice()
    {
        $model = new Invoice();

        if ($model->load(Yii::$app->request) && $model->save())
        {
            $params = [
                'ik_pm_no' => $model->id,
                'ik_am' => $model->ammount,
                'ik_desc' => 'Site payment',
            ];

            return Yii::$app->interkassa->payment($params);
        }

        return $this->render('invoice', compact($model));
    }

    public function successCallback($ik_am, $ik_inv_st, $ik_pm_no)
    {
        return $this->render('success');
    }

    public function failCallback($ik_am, $ik_inv_st, $ik_pm_no)
    {
        return $this->render('fail');
    }

    public function resultCallback($ik_am, $ik_inv_st, $ik_pm_no)
    {

        switch ($ik_inv_st)
        {
            case 'new':
                $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_NEW]);
                break;
            case 'waitAccept':
                $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_PENDING]);
                break;
            case 'process':
                $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_PROCESS]);
                break;
            case 'success':
                $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_SUCCESS]);
                break;
            case 'canceled':
                $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_CANCELED]);
                break;
            case 'fail':
                $this->loadModel($ik_pm_no)->updateAttributes(['status' => Invoice::STATUS_FAIL])
                break;
        }
    }

    protected function loadModel($id)
    {
        $model = Invoice::findOne($id);

        if ($model === null)
            throw new BadRequestHttpException;

        return $model;
    }
}

Example withdraw:

class Withdraw
{
    protected $purse_name = 'My Purse Name';

    public function process($id)
    {
        $withdraw = Withdraw::findOne($id);
        
        if ($withdraw === null)
            throw new BadRequestHttpException;
    
        try {
            $result = Yii::$app->interkassa->withdraw(
                $withdraw->id,
                $this->purse_name,
                $withdraw->payway_name,
                ['purse' => $withdraw->purse],
                $withdraw->amount,
                'psPayeeAmount',
                'process'
            );
        } catch (WithdrawException $e) {
            return $e->getMessage();
        }
    }
}

interkassa's People

Watchers

James Cloos avatar grandmasterx avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.