$db->beginTransaction(); $response = $db->insertClient($request->textMessage, $request->phoneNumber, $amount, json_encode($request)); if (!$response['state']) { die('Server error. Please contact to administrator.'); } if ($request->paymentMethod == 'onlinePayment') { // online paid $publicKey = $params['liqpay']['publicKey']; $privateKey = $params['liqpay']['privateKey']; $lp = new LiqPay($publicKey, $privateKey); $url = $lp->cnb_form(array('version' => '3', 'amount' => $amount, 'currency' => 'UAH', 'description' => 'payment for order ' . $response['id'] . ' for burgerjoint.com.ua', 'server_url' => "http://{$_SERVER['HTTP_HOST']}/scripts/server.php", 'result_url' => "http://{$_SERVER['HTTP_HOST']}/scripts/result.php?id={$response['id']}", 'order_id' => $response['id'])); } else { $sms = new SmsClient($params['SmsUkraine']['login'], $params['SmsUkraine']['password']); $email = new Email(); if ($email->sendEmail($request, true, $response['id'])) { $db->setAsPaid($response['id']); $sms->sendSMS('BurgerJoint', $params['adminNumber'], 'Нове замовлення ' . $response['id']); $url = 'http://' . $_SERVER['HTTP_HOST'] . '/index.html#/success'; } else { $url = 'http://' . $_SERVER['HTTP_HOST'] . '/index.html#/failure'; } } $db->commit(); echo $url; die; } catch (Exception $e) { $email->sendEmail('Сталася помилка - ' . $e->getMessage(), false, $response['id']); $db->rollback(); echo 'index.html#/failure'; die; }
$params = (require 'params.php'); $publicKey = $params['liqpay']['publicKey']; $privateKey = $params['liqpay']['privateKey']; $liqpay = new LiqPay($publicKey, $privateKey); $db = new Database(); $email = new Email(); $allInActiveOrder = $db->getInactiveOrders(); $sms = new SmsClient($params['SmsUkraine']['login'], $params['SmsUkraine']['password']); foreach ($allInActiveOrder as $order) { $res = $liqpay->api("payment/status", array('version' => '3', 'order_id' => $order['clientId'])); if ($res->result == 'error') { if ($db->sendErrorSms($order['clientId'])) { if ($db->setAsError($order['clientId'])) { $sms->sendSMS('BurgerJoint', $order['phoneNumber'], 'Ваше замовлення скасовано. Для детальної iнформацiї звертайтесь за телефоном +38 (068) 235 50 29'); } } } elseif ($res->result == 'ok') { if ($res->amount != $order['amount']) { $temp = ['res' => $res->amount, 'amount' => $order['amount'], 'check' => $res->amount != $order['amount']]; $db->setAsError($res->order_id); $sms->sendSMS('BurgerJoint', $res->sender_phone, 'Ваше замовлення скасовано. Для детальної iнформацiї звертайтесь за телефоном +38 (068) 235 50 29'); $htmlString = $email->postDataToString(array_merge((array) $res, ['-' => '-'], $order, $temp)); $email->sendEmail('Данi не спiвпадають' . $htmlString, false, $order['clientId']); } else { if ($db->setAsPaid($order['clientId'])) { $email->sendEmail(json_decode($order['jsonData']), true, $order['clientId']); $sms->sendSMS('BurgerJoint', $params['adminNumber'], 'Нове замовлення ' . $order['clientId']); } } } }