PHP code example of macklus / yii2-ceca-tpv

1. Go to this page and download the library: Download macklus/yii2-ceca-tpv library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

macklus / yii2-ceca-tpv example snippets


'tpv' => [
            'class' => 'macklus\CECATpv\Tpv',
            'mode' => 'prod',
            'debug' => [
                'AcquirerBIN' => '0000XXXXXX',
                'MerchantID' => '0XXXXXXXX',
                'TerminalID' => '0000000X',
                'Exp' => 'X',
                'URL_OK' => '',
                'URL_NOK' => '',
                'Key' => 'XXXXXXXX',
            ],
            'prod' => [
                'AcquirerBIN' => '0000XXXXXX',
                'MerchantID' => '0XXXXXXXX',
                'TerminalID' => '0000000X',
                'Exp' => 'X',
                'URL_OK' => '',
                'URL_NOK' => '',
                'Key' => 'XXXXXXXX',
            ],
        ],



use Yii;


class PaymentsController extends Controller
{

    public function init()
    {
        if (isset($_POST)) {
            /* Turn off CSRF */
            Yii::$app->request->enableCsrfValidation = false;
        }
    }
    
    public function actionTpv()
    {
        $logfile = Yii::getAlias('@runtime/tpv.log');

        if (isset($_POST)) {
            file_put_contents($logfile, print_R($_POST, true), FILE_APPEND);
        }

        $response = Yii::$app->tpv->getTPVResponse();
        if ($response && $response->isValid()) {
          // do some stuff on your database or app
          if( myStuffWorkFine ) {
            $response->returnOkToServer();
          } else {
            $response->returnErrorToServer();
          }
        }

        Yii::$app->request->enableCsrfValidation = true;
    }
}


php composer.phar