W
W
WalkersRei2018-09-26 22:22:17
PHP
WalkersRei, 2018-09-26 22:22:17

LiqPay integration?

Using the LiqPay documentation, I did a replenishment method, but nothing happens when executed, although I did everything according to the documentation
, what's the problem? error log is clear

<?php
class payController extends Controller {
    public function index() {
        $this->document->setActiveSection('account');
        $this->document->setActiveItem('pay');
       
        if(!$this->user->isLogged()) {
            $this->session->data['error'] = "Вы не авторизированы!";
            $this->response->redirect($this->config->url . 'account/login');
        }
        if($this->user->getAccessLevel() < 0) {
            $this->session->data['error'] = "У вас нет доступа к данному разделу!";
            $this->response->redirect($this->config->url);
        }
       
        $this->getChild(array('common/header', 'common/footer'));
        return $this->load->view('account/pay', $this->data);
    }
   
    public function ajax() {
        if(!$this->user->isLogged()) {  
            $this->data['status'] = "error";
            $this->data['error'] = "Вы не авторизированы!";
            return json_encode($this->data);
        }
        if($this->user->getAccessLevel() < 1) {
            $this->data['status'] = "error";
            $this->data['error'] = "У вас нет доступа к данному разделу!";
            return json_encode($this->data);
        }
       
        $this->load->model('invoices');
       
        if($this->request->server['REQUEST_METHOD'] == 'POST') {
            $errorPOST = $this->validatePOST();
            if(!$errorPOST) {
                $ammount = @$this->request->post['ammount'];
               
                $server = $this->config->liqpay_server;
                $public = $this->config->liqpay_public;
                $private = $this->config->liqpay_private;
               
                $userid = $this->user->getId();
               
                $invoiceData = array(
                    'user_id'           => $userid,
                    'invoice_ammount'   => $ammount,
                    'invoice_status'    => 0
                );
                $invid = $this->invoicesModel->createInvoice($invoiceData);
               
                $data = array(
                    $version = '3',
                    $public_key = $this->config->liqpay_public,                
                    $action = 'pay',
                    $amount = $ammount,
                    $currency = 'UAH',
                    $description = 'Пополнение баланса аккаунта (ID " . $userid . ")',
                    $order_id = $invid
                );
 
 
 
                $data = base64_encode(json_string($data));
                $signature = base64_encode(sha1($private.$data.$private, 1));
               
        $desc = array(
           			'data'  => $data,
           			'signature' => $signature
        );
        
        $this->data['status'] = "success";
        $this->data['url'] = 'https://www.liqpay.ua/api/3/checkout'. http_build_query($desc);
            } else {
                $this->data['status'] = "error";
                $this->data['error'] = $errorPOST;
            }
        }
 
        return json_encode($this->data);
    }
   
    private function validatePOST() {
        $this->load->library('validate');
       
        $validateLib = new validateLibrary();
       
        $result = null;
       
        $ammount = @$this->request->post['ammount'];
        if(!$validateLib->money($ammount)) {
            $result = "Укажите сумму пополнения в допустимом формате!";
        }
        elseif(10 > $ammount || $ammount > 5000) {
            $result = "Укажите сумму от 10 до 5000 рублей!";
        }
        return $result;
    }
}
?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question