$month = substr($status['expiration'], 4, 2); $y = $year . $month . "01"; $n = date("Ymd"); $k = strtotime($y) - strtotime($n); $days = floor($k / (60 * 60 * 24)); $walletAlpha->data['validity'] = $days . " days"; $walletAlpha->data['type'] = WalletTypes::WALLET_ALPHA; $walletAlpha->data['uid'] = $uid; $walletAlpha->data['wallet'] = $status['Pan']; $walletAlpha->setAccessToken($status['bindingId']); $walletId = $walletAlpha->saveWallet(); // Токен получен и сохранен отправляем пользователя на страницу if ($walletId > 0) { $res = $walletAlpha->api->refund(API_AlphaBank::REGISTER_SUM, $order['order_id']); if ($res['errorCode'] == 0) { $update = array('state' => walletAlpha::STATUS_REFUND, 'pan' => $status['Pan'], 'expiration' => $status['expiration'], 'cardholder_name' => $status['cardholderName'], 'ip' => $status['Ip'], 'binding_id' => Wallet::des()->encrypt($status['bindingId'])); $walletAlpha->updateOrder($order['id'], $update); } $_SESSION['wallet_success'] = true; $redirect = '/bill/'; if (isset($_SESSION['redirect_uri_wallet']) && strpos($_SESSION['redirect_uri_wallet'], 'fail_') !== false) { $redirect = $_SESSION['redirect_uri_wallet']; } header("Location: {$redirect}"); exit; } } else { $_SESSION['errorCards'] = $status; header("Location: /bill/fail_card/"); exit; }
/** * Автооплата услуги * * @param $sum * @return bool|mixed */ public function payment($sum) { $this->createOrder($sum); $this->api->getAccessData('autopay'); $result = $this->api->register($sum, $this->orderNumber, $this->account->id); if ($result['orderId'] != '') { walletAlpha::updateOrder($this->orderNumber, array('order_id' => $result['orderId'], 'state' => walletAlpha::STATE_NEW)); $payment = $this->api->paymentOrderBinding($result['orderId']); switch ($payment['errorCode']) { case API_AlphaBank::STATUS_SUCCESS: $status = $this->api->getOrderStatus($result['orderId']); $update = array('pan' => $status['Pan'], 'expiration' => $status['expiration'], 'cardholder_name' => $status['cardholderName'], 'ip' => $status['Ip'], 'binding_id' => Wallet::des()->encrypt($status['bindingId'])); $update['state'] = $this->deposit($this->account, $this->account->id, $status, $this->data['wallet'], $this->orderNumber, $sum); $this->updateOrder($this->orderNumber, $update); break; default: // Ошибка оплаты ob_start(); var_dump($result); var_dump($payment); $content = ob_get_clean(); $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n"); $this->log->write("Request:\n " . $this->api->last_request->getBody()); $this->log->write("Result:\n {$content}"); return false; break; } } else { ob_start(); var_dump($result); $content = ob_get_clean(); $this->log->writeln("FAIL Payment:\naccount:{$this->account->id}\n"); $this->log->write("Request:\n " . $this->api->last_request->getBody()); $this->log->write("Result:\n {$content}"); return false; //error } }
/** * Шифрует ключ доступа платежей (для последующего сохранения в БД) * * @param string $token Не зашифрованные ключ */ public function setAccessToken($token) { $this->data['access_token'] = JWS_Base64::urlEncode(Wallet::des()->encrypt($token)); }