Example #1
0
 public function post_payu()
 {
     Tools::log('payu', ['post', $this->data]);
     if (!$this->data('session_id')) {
         die;
     }
     $payment = new paymentModel($this->data['session_id']);
     if (!$payment->id) {
         die;
     }
     $config = Bootstrap::$main->getConfig();
     $this->data['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
     $payment->d_response = Bootstrap::$main->now;
     $payment->notify = json_encode($this->data);
     $payment->save();
     $req = array();
     $req['pos_id'] = $this->data('pos_id');
     $req['session_id'] = $this->data('session_id');
     $req['ts'] = time() + microtime(true);
     $req['sig'] = md5($req['pos_id'] . $req['session_id'] . $req['ts'] . $config['payu.key1']);
     $url = 'https://www.platnosci.pl/paygw/UTF/Payment/get/txt';
     $resp = $this->req($url, $req);
     if (!$payment->response) {
         $payment->response = '';
     }
     $payment->response = $payment->response . date('d-m-Y H:i:s') . " GMT\n" . $resp . "\n";
     $res = $this->resp2array($resp);
     Tools::log('payu', ['check', $res, $payment->data()]);
     if ($res['status'] == 'OK') {
         $payment->status = $res['trans_status'] + 0;
         if ($res['trans_status'] == 99 || $res['trans_status'] == 5) {
             $this->paid($payment, $res['trans_amount'] / 100);
         }
         if ($res['trans_status'] == 3 || $res['trans_status'] == 7) {
             $payment->d_cancel_commit = Bootstrap::$main->now;
         }
     }
     $payment->save();
     die('OK');
 }