2017 © Pedro Peláez
 

yii2-extension yii2-adv-cash

AdvCash component for Yii2 framework

image

yarcode/yii2-adv-cash

AdvCash component for Yii2 framework

  • Wednesday, November 29, 2017
  • by lagman
  • Repository
  • 3 Watchers
  • 6 Stars
  • 194 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 6 Versions
  • 10 % Grown

The README.md

AdvCash component for Yii2

Payment gateway and api client for AdvCash 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-adv-cash

or add, (*4)

"yarcode/yii2-adv-cash": "*"

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

Usage

Component configuration

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

'advCash' => [
    'class' => '\yarcode\advcash\Merchant'
    'accountEmail' => null,
    'merchantName' => null,
    'merchantPassword' => null,
    'walletNumber' => null,
    'sciCurrency' => \yarcode\advcash\Merchant::CURRENCY_USD,
    'sciCheckSign' => true,
    'sciDefaultPs' => null,
    'successUrl' => null,
    'failureUrl' => null,
    'resultUrl' => null,
    'successUrlMethod' => null,
    'failureUrlMethod' => null,
    'resultUrlMethod' => null
]

Redirecting to the payment system

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

<?php echo \yarcode\advcash\RedirectForm::widget([
    'api' => Yii::$app->get('advCash'),
    'invoiceId' => $invoice->id,
    'amount' => $invoice->amount,
    'description' => $invoice->description,
]); ?>

Gateway controller

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

<?php

namespace yarcode\advcash\controllers;

use common\models\billing\Invoice;
use yarcode\advcash\actions\ResultAction;
use yarcode\advcash\events\GatewayEvent;
use yarcode\advcash\Merchant;
use yii\helpers\ArrayHelper;
use yii\helpers\VarDumper;
use yii\web\Controller;

class GatewayController extends Controller
{
    /** @inheritdoc */
    public $enableCsrfValidation = false;

    /** @var string Your component configuration name */
    public $componentName = 'advCash';

    /** @var Merchant */
    protected $component;

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();

        $this->component = \Yii::$app->get($this->componentName);

        $this->component->on(GatewayEvent::EVENT_PAYMENT_REQUEST, [$this, 'handlePaymentRequest']);
        $this->component->on(GatewayEvent::EVENT_PAYMENT_SUCCESS, [$this, 'handlePaymentSuccess']);
    }

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

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

        if (!$invoice instanceof Invoice ||
            $invoice->status != Invoice::STATUS_NEW ||
            ArrayHelper::getValue($event->gatewayData, 'ac_amount') != $invoice->amount ||
            ArrayHelper::getValue($event->gatewayData,
                'ac_transaction_status') != Merchant::TRANSACTION_STATUS_COMPLETED ||
            ArrayHelper::getValue($event->gatewayData, 'ac_sci_name') != $this->component->merchantName
        ) {
            return;
        }

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

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

        // TODO: invoice processing goes here
    }
}

Licence

MIT, (*9)

The Versions

29/11 2017

dev-master

9999999-dev http://yiidreamteam.com/yii2/adv-cash

AdvCash component for Yii2 framework

  Sources   Download

MIT

The Requires

 

payment yii2 billing advcash

28/06 2017

1.0.2

1.0.2.0 http://yiidreamteam.com/yii2/adv-cash

AdvCash component for Yii2 framework

  Sources   Download

MIT

The Requires

 

payment yii2 billing advcash

18/02 2017

1.0.1

1.0.1.0 http://yiidreamteam.com/yii2/adv-cash

AdvCash component for Yii2 framework

  Sources   Download

MIT

The Requires

 

payment yii2 billing advcash

02/12 2016

1.0.0

1.0.0.0 http://yiidreamteam.com/yii2/adv-cash

AdvCash component for Yii2 framework

  Sources   Download

MIT

The Requires

 

payment yii2 billing advcash

02/12 2016

dev-change_func

dev-change_func http://yiidreamteam.com/yii2/adv-cash

AdvCash component for Yii2 framework

  Sources   Download

MIT

The Requires

 

payment yii2 billing advcash

04/03 2016

0.1.0

0.1.0.0 http://yiidreamteam.com/yii2/adv-cash

AdvCash component for Yii2 framework

  Sources   Download

MIT

The Requires

 

payment yii2 billing advcash