yf_payment_test user module

Fileplugins/payment/modules/yf_payment_test.class.php
Usemodule('payment_test'), URL ?object=payment_test

Public properties

A site sets them in its config with $PROJECT_CONF['payment_test']['NAME'] = ...;

PropertyDefaultDescription
$api ['Interkassa' => true, 'PerfectMoney' => true]
$currency_rate_load ['NBU' => true, 'Privat24' => true, 'CashExchange' => true]
$currency_rates_load ['NBU' => true, 'Privat24' => true, 'CashExchange' => true]
$payin ['Ecommpay' => true, 'PerfectMoney' => true]
$payout ['Interkassa' => true, 'Ecommpay' => true, 'PerfectMoney' => true]

Public methods 14

api

public function api()
    public function api()
    {
        $provider = [
            // 'Privat24',
            // 'LiqPay',
            'Interkassa',
            // 'Ecommpay',
            'PerfectMoney',
        ];
        $_provider = [];
        foreach ($provider as $item) {
            if ( ! empty($this->api[$item])) {
                $_provider[] = $item;
            }
        }
        $result = [];
        $result += $this->_chunk('api', $_provider);
        $this->_render($result);
    }
public function currency_rate_load()
    public function currency_rate_load()
    {
        $provider = [
            'NBU',
            'Privat24',
            'CashExchange',
        ];
        $_provider = [];
        foreach ($provider as $item) {
            if ( ! empty($this->{ __FUNCTION__ }[$item])) {
                $_provider[] = $item;
            }
        }
        $result = [];
        $result += $this->_chunk(__FUNCTION__, $_provider);
        $this->_render($result);
    }
public function currency_rates_current()
    public function currency_rates_current()
    {
        $result = [];
        $payment_api = _class('payment_api');
        // conversion UNT to UAH
        $currency__api = _class('payment_api__currency');
        $data = [];
        $provider = 'NBU';
        $type = 'buy';
        $from = 'USD';
        $to = 'UAH';
        $amount = 100;
        $options = [
            'provider' => $provider,
            'type' => $type,
            'amount' => $amount,
            'from' => $from,
            'to' => $to,
        ];
        $value = $currency__api->conversion($options);
        $data[] = $options + ['value' => $value];
        // --
        $options['from'] = $to;
        $options['to'] = $from;
        $value = $currency__api->conversion($options);
        $data[] = $options + ['value' => $value];
        $r = $this->_add_panel(['header' => 'Conversion currency api',
            'php' => var_export($data, true),
        ]);
        $result[] = $r;
        // conversion UNT to UAH
        $data = [];
        $currency_id = 'UAH';
        $amount = 100;
        $type = 'buy';
        $options = [
            'currency_id' => $currency_id,
            'amount' => $amount,
        ];
        $options['type'] = $type;
        $data[$type] = $payment_api->currency_conversion($options);
        // --
        $type = 'sell';
        $options['type'] = $type;
        $data[$type] = $payment_api->currency_conversion($options);
        $data = [
            'amount' => $amount,
            'from' => 'UNT',
            'to' => $currency_id,
        ] + $data;
        $r = $this->_add_panel(['header' => 'Conversion payment api',
            'php' => var_export($data, true),
        ]);
        $result[] = $r;
        // USD, EUR to UAH
        $data = [];
        $provider = 'NBU';
        $currency_id = 'USD';
        $options = ['provider' => $provider];
        $options['currency_id'] = $currency_id;
        $data[$currency_id] = $payment_api->currency_rate($options);
        $currency_id = 'EUR';
        $options['currency_id'] = $currency_id;
        $data[$currency_id] = $payment_api->currency_rate($options);
        $r = $this->_add_panel(['header' => $provider, 'php' => var_export($data, true)]);
        $result[] = $r;
        // UNT
        $currency_id = 'UNT';
        $buy = $payment_api->currency_rates__buy();
        $sell = $payment_api->currency_rates__sell();
        $r = $this->_add_panel([
            'header' => $currency_id,
            'php' => var_export([
                'buy' => $buy,
                'sell' => $sell,
            ], true),
        ]);
        $result[] = $r;
        // USD
        $currency_id = 'USD';
        $buy = $payment_api->currency_rates__buy(['currency_id' => $currency_id]);
        $sell = $payment_api->currency_rates__sell(['currency_id' => $currency_id]);
        $r = $this->_add_panel([
            'header' => $currency_id,
            'php' => var_export([
                'buy' => $buy,
                'sell' => $sell,
            ], true),
        ]);
        $result[] = $r;
        // finish
        $this->_render($result);
    }
public function currency_rates_load()
    public function currency_rates_load()
    {
        $provider = [
            'NBU',
            'Privat24',
            'CashExchange',
        ];
        $_provider = [];
        foreach ($provider as $item) {
            if ( ! empty($this->{ __FUNCTION__ }[$item])) {
                $_provider[] = $item;
            }
        }
        $result = [];
        $result += $this->_chunk(__FUNCTION__, $_provider);
        $this->_render($result);
    }

mail

public function mail()
    public function mail()
    {
        $mail_tpl = [
            'payin_success' => [
                'type' => 'payin',
                'status' => 'success',
                'is_user' => true,
                'is_admin' => true,
            ],
            'payin_refused' => [
                'type' => 'payin',
                'status' => 'refused',
                'is_user' => true,
                'is_admin' => true,
            ],

            'payout_success' => [
                'type' => 'payout',
                'status' => 'success',
                'is_user' => true,
            ],
            'payout_refused' => [
                'type' => 'payout',
                'status' => 'refused',
                'is_user' => true,
            ],
            'payout_request' => [
                'type' => 'payout',
                'status' => 'request',
                'is_user' => true,
                'is_admin' => true,
            ],
            'payout_confirmation' => [
                'type' => 'payout',
                'status' => 'confirmation',
                'is_user' => true,
                'is_admin' => true,
            ],
        ];
        // exec
        $form = '';
        if (($_GET['tpl'] ?? null) || (($_GET['type'] ?? null) && ($_GET['status'] ?? null))) {
            // vars
            $payment_api = _class('payment_api');
            // prepare
            $tpl = ($_GET['tpl'] ?? null);
            $type = ($_GET['type'] ?? null);
            $status = ($_GET['status'] ?? null);
            $user_id = ($_GET['user_id'] ?? null) ?: 1;
            $is_admin = ! empty($_GET['is_admin']);
            $result = $payment_api->mail([
                'tpl' => $tpl,
                'type' => $type,
                'status' => $status,
                'force' => true,
                'user_id' => $user_id,
                'is_admin' => $is_admin,
                'data' => [
                    'operation_id' => 1,
                    'amount' => 1.1,
                    'code' => 123,
                ],
            ]);
            $form .= var_export([
                'tpl' => $tpl,
                'result' => $result,
            ], true);
        } else {
            $form = 'Select a template';
        }
        // actions
        $action = [];
        foreach ($mail_tpl as $tpl => $item) {
            if (empty($item)) {
                continue;
            }
            // uri
            $uri = [];
            $uri[] = 'tpl=' . $tpl;
            // user
            if (($item['is_user'] ?? null)) {
                $_uri = '?' . implode('&', $uri);
                $link = url_user('/@object/@action' . $_uri);
                $a = sprintf('<a href="%s" class="btn btn-default">%s</a>', $link, $tpl);
                $action[] = $a;
            }
            // admin
            if (($item['is_admin'] ?? null)) {
                $uri[] = 'is_admin=' . true;
                $_uri = '?' . implode('&', $uri);
                $link = url_user('/@object/@action' . $_uri);
                $a = sprintf('<a href="%s" class="btn btn-default">%s</a>', $link, $tpl . '_admin');
                $action[] = $a;
            }
            // uri
            $uri = [];
            $uri[] = 'type=' . $item['type'];
            $uri[] = 'status=' . $item['status'];
            // user
            if (($item['is_user'] ?? null)) {
                $_uri = '?' . implode('&', $uri);
                $link = url_user('/@object/@action' . $_uri);
                $a = sprintf('<a href="%s" class="btn btn-default">by %s - %s</a>', $link, $item['type'], $item['status']);
                $action[] = $a;
            }
            // admin
            if (($item['is_admin'] ?? null)) {
                $uri[] = 'is_admin=' . true;
                $_uri = '?' . implode('&', $uri);
                $link = url_user('/@object/@action' . $_uri);
                $a = sprintf('<a href="%s" class="btn btn-default">by %s, %s - admin</a>', $link, $item['type'], $item['status']);
                $action[] = $a;
            }
        }
        $result = $this->_add_panel([
            'header' => 'Payment mail',
            'form' => $form,
            'action' => $action,
        ]);
        $this->_render($result);
    }

payin

public function payin()
    public function payin()
    {
        if ( ! empty($_POST)) {
            $payment_api = _class('payment_api');
            $dump = $payment_api->dump();
            if (empty($_GET['server'])) {
                $result = $this->_add_panel([
                    'header' => 'Response test: ',
                    'php' => $dump,
                ]);
                $this->_render($result);
            }
            exit();
        }
        $this->_init_options();
        $provider = [
            'Privat24',
            'LiqPay',
            'Interkassa',
            'Ecommpay',
            'PerfectMoney',
        ];
        $_provider = [];
        foreach ($provider as $item) {
            if ( ! empty($this->payin[$item])) {
                $_provider[] = $item;
            }
        }
        $result = [];
        $result += $this->_chunk('payin', $_provider);
        $this->_render($result);
    }

payout

public function payout()
    public function payout()
    {
        $provider = [
            // 'Privat24',
            // 'LiqPay',
            'Interkassa',
            'Ecommpay',
            'PerfectMoney',
        ];
        $_provider = [];
        foreach ($provider as $item) {
            if ( ! empty($this->payout[$item])) {
                $_provider[] = $item;
            }
        }
        $result = [];
        $result += $this->_chunk('payout', $_provider);
        $this->_render($result);
    }

transaction

public function transaction()
    public function transaction()
    {
        $payment_api = _class('payment_api');
        // var
        $result = [];
        $operation_id = ($_GET['operation_id'] ?? null);
        $data = ['operation_id' => $operation_id];
        // start
        $result[1]['level'] = $payment_api->transaction_isolation();

        $result[2]['start'] = $payment_api->transaction_start($data);
        $result[2]['level'] = $payment_api->transaction_isolation();
        if ($operation_id) {
            $operation = $payment_api->operation([
                'operation_id' => $operation_id,
            ]);
            $result[2]['operation'] = $operation;
        }
        $result[2]['commit'] = $payment_api->transaction_commit();

        $result[3]['start'] = $payment_api->transaction_start();
        $result[3]['rollback'] = $payment_api->transaction_rollback();

        $result[4]['start'] = $payment_api->transaction_start();
        $result[4]['commit 1'] = $payment_api->transaction_commit();
        $result[4]['commit 2'] = $payment_api->transaction_commit();

        $result[5]['start'] = $payment_api->transaction_start();
        $result[5]['rollback 1'] = $payment_api->transaction_rollback();
        $result[5]['rollback 2'] = $payment_api->transaction_rollback();

        $result[6]['start'] = $payment_api->transaction_start();
        $result[6]['rollback'] = $payment_api->transaction_rollback();
        $result[6]['commit'] = $payment_api->transaction_commit();

        $result[7]['start'] = $payment_api->transaction_start();
        $result[7]['commit'] = $payment_api->transaction_commit();
        $result[7]['rollback'] = $payment_api->transaction_rollback();

        $result[8]['level'] = $payment_api->transaction_isolation();
        // out
        $php = var_export($result, true);
        $result = $this->_add_panel([
            'header' => 'Transaction DB',
            'php' => $php,
            'is_action' => true,
        ]);
        $this->_render($result);
    }

Methods starting with _ hooks and helpers; not routable as page actions

_api_js_cors

public function _api_js_cors()
    public function _api_js_cors()
    {
        // check origin
        header('Access-Control-Allow-Origin: ' . ($_SERVER['HTTP_ORIGIN'] ?? null));
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, PATCH, DELETE');
        header('Access-Control-Allow-Headers: X-Requested-With, Content-Type, Content-Range, Content-Disposition');
        return  [
            'cors' => 'ok',
            'get' => $_GET,
            'post' => $_POST,
            'server' => $_SERVER,
        ];
    }
public function _currency_rate_load_CashExchange()
    public function _currency_rate_load_CashExchange()
    {
        $title = null;
        $options = [
            'title' => $title,
            'provider' => 'cashex',
            'currency_id' => 'USD',
            'method' => [
                'xml' => true,
                'json' => true,
            ],
        ];
        $result = $this->_currency_rate_load($options);
        return  $result;
    }
public function _currency_rate_load_NBU()
    public function _currency_rate_load_NBU()
    {
        $title = null;
        $options = [
            'title' => $title,
            'provider' => 'nbu',
            'currency_id' => 'USD',
            'method' => [
                'json' => true,
                'xml' => true,
                'html' => true,
            ],
        ];
        $result = $this->_currency_rate_load($options);
        return  $result;
    }
public function _currency_rate_load_Privat24()
    public function _currency_rate_load_Privat24()
    {
        $title = null;
        $options = [
            'title' => $title,
            'provider' => 'p24',
            'currency_id' => 'USD',
            'method' => [
                'json' => true,
            ],
        ];
        $result = $this->_currency_rate_load($options);
        return  $result;
    }

_fast_init

public function _fast_init()
    public function _fast_init()
    {
        main()->init_files();
        $this->_fast_init_route();
    }

_init

public function _init()
    public function _init()
    {
        if ( ! (defined('PAYMENT_TEST') && PAYMENT_TEST)
            && ! (defined('TEST_MODE') && TEST_MODE)) {
            $message = 'Service Unavailable';
            $header = 'Status: 503 Service Unavailable';
            $code = 503;
            http_response_code($code);
            header($header);
            die($message);
        }
    }