add anpay
This commit is contained in:
@@ -225,23 +225,24 @@ function client_find_email_kuri($mail){
|
|||||||
# узнаем id клиента по мылу или создаем его
|
# узнаем id клиента по мылу или создаем его
|
||||||
function api_add_client($mail){
|
function api_add_client($mail){
|
||||||
|
|
||||||
$find_mail = dbl_get("SELECT `client_id`, `clienthash` FROM `clients` WHERE `clientmail` = '$mail' LIMIT 1");
|
$find_client = dbl_get("SELECT `client_id`, `clientmail`, `clienthash` FROM `clients` WHERE `clientmail` = '$mail' LIMIT 1");
|
||||||
|
|
||||||
if (isset($find_mail['client_id'])){
|
if (isset($find_client['client_id'])){
|
||||||
$result = $find_mail['clienthash'];
|
$result = $find_client; // возвращаем клиента
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$add['clientmail'] = $mail;
|
$add['clientmail'] = $mail;
|
||||||
$add['clienthash'] = md5($mail);
|
$add['clienthash'] = md5($mail);
|
||||||
$add['clientdate'] = date("Y-m-d H:i:s");
|
$add['clientdate'] = date("Y-m-d H:i:s");
|
||||||
|
|
||||||
$res = db_insert('clients', $add, 'chitatel');
|
$res = db_insert('clients', $add, 'chitatel'); // создаем клиента
|
||||||
|
|
||||||
if ($res > 0){
|
if ($res > 0){
|
||||||
$result = $add['clienthash'];
|
$add['client_id'] = $res;
|
||||||
|
$result = $add;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$result = false;
|
$result = false; # клиент не добавлен
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ error_reporting(E_ALL);
|
|||||||
|
|
||||||
|
|
||||||
if (isset($_SERVER['HTTP_HOST']))
|
if (isset($_SERVER['HTTP_HOST']))
|
||||||
define('SITE', 'http://'.$_SERVER['HTTP_HOST'].'/');
|
define('SITE', 'https://'.$_SERVER['HTTP_HOST'].'/');
|
||||||
|
|
||||||
if (isset($_SERVER['HTTP_HOST']))
|
if (isset($_SERVER['HTTP_HOST']))
|
||||||
define('SITEPATH', $_SERVER['DOCUMENT_ROOT'].'/');
|
define('SITEPATH', $_SERVER['DOCUMENT_ROOT'].'/');
|
||||||
@@ -31,7 +31,13 @@ define('VIEWPATH', SITEPATH.'views/');
|
|||||||
define('API', 'http://api.argumenti.ru/');
|
define('API', 'http://api.argumenti.ru/');
|
||||||
define('IMGSRV', 'https://imgurl.argumenti.ru/');
|
define('IMGSRV', 'https://imgurl.argumenti.ru/');
|
||||||
|
|
||||||
define('PAYSITE', 'https://pay.argumenti.ru/'); //сервис оплаты
|
/* тестовый магазин ЮКАССА */
|
||||||
|
define('YID', '812455');
|
||||||
|
define('YKEY', 'test_7asbXctnircUsmb_DhtYWSfxMiWzPgJBDF7OoZ0XfvQ');
|
||||||
|
|
||||||
|
define('LOGDIR', SITEPATH.'logs/'); // папка куда падают логи
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** отправка уведомлений */
|
/** отправка уведомлений */
|
||||||
/*set('noreply',
|
/*set('noreply',
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ require 'routes/pdfserver.php';
|
|||||||
require 'routes/email.php';
|
require 'routes/email.php';
|
||||||
require 'routes/books.php';
|
require 'routes/books.php';
|
||||||
require 'routes/order.php';
|
require 'routes/order.php';
|
||||||
|
require 'routes/anpay.php';
|
||||||
|
|
||||||
#api
|
#api
|
||||||
require 'api/apiclient.php';
|
require 'api/apiclient.php';
|
||||||
|
|||||||
11
app/libs/logsave.php
Normal file
11
app/libs/logsave.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
function logsave($log, $message){
|
||||||
|
|
||||||
|
$message = date('Y-m-d H:i:s').' - '.$message;
|
||||||
|
$logfile = LOGDIR.$log.'.txt';
|
||||||
|
|
||||||
|
file_put_contents(LOGDIR.$log.'.txt', $message . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
|
}
|
||||||
154
app/routes/anpay.php
Normal file
154
app/routes/anpay.php
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use YooKassa\Client;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function anpay_kuri($buy_id){
|
||||||
|
|
||||||
|
|
||||||
|
# получаем инфу о заказе
|
||||||
|
$buy_find = "
|
||||||
|
SELECT
|
||||||
|
`buy_id`,
|
||||||
|
`buy_status`,
|
||||||
|
`pricename`,
|
||||||
|
`anbuy`.`price` as `currprice`
|
||||||
|
FROM
|
||||||
|
`anbuy`
|
||||||
|
LEFT JOIN
|
||||||
|
`price` ON `anbuy`.`number_id` = `price`.`price_id`
|
||||||
|
WHERE
|
||||||
|
`buy_id` = '$buy_id'
|
||||||
|
LIMIT 1
|
||||||
|
";
|
||||||
|
|
||||||
|
|
||||||
|
$buy_id = db_get($buy_find);
|
||||||
|
|
||||||
|
# заказ не найден
|
||||||
|
if (!isset($buy_id['buy_id'])){
|
||||||
|
echo 'заказ не найден!';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# проверяем статус заказа
|
||||||
|
if ($buy_id['buy_status']) {
|
||||||
|
echo 'заказ уже оплачен!';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
# получить ссылку на оплату
|
||||||
|
$payment = yk_pay($buy_id['currprice'], $buy_id['pricename']);
|
||||||
|
|
||||||
|
if (isset($payment['confirmation']['confirmation_url'])){
|
||||||
|
$pay_url = $payment['confirmation']['confirmation_url'];
|
||||||
|
|
||||||
|
//добавляем shop_id от ЮКАССЫ чтобы следить за статусом оплаты
|
||||||
|
$upd_shop = "
|
||||||
|
UPDATE
|
||||||
|
`anbuy`
|
||||||
|
SET
|
||||||
|
`shop_id` = '{$payment->_id}'
|
||||||
|
WHERE
|
||||||
|
`buy_id` = '{$buy_id['buy_id']}'
|
||||||
|
";
|
||||||
|
|
||||||
|
db_get($upd_shop, 'chitatel'); # фиксируем shop_id от Юкассы
|
||||||
|
header("Location: $pay_url"); // перенаправляем на оплату
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# получение результатов оплаты заказа
|
||||||
|
function resultpay_kuri(){
|
||||||
|
|
||||||
|
$source = file_get_contents('php://input');
|
||||||
|
//$source = file_get_contents('/vhosts/anpay/app/tests/result.json');
|
||||||
|
|
||||||
|
|
||||||
|
$result = json_decode($source, true);
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($result['event'])) {
|
||||||
|
|
||||||
|
if ($result['event'] == "payment.succeeded"){
|
||||||
|
$shop_id = $result['object']['id'];
|
||||||
|
$find_sql = "SELECT buy_id FROM `anbuy` WHERE `shop_id` = '$shop_id' LIMIT 1";
|
||||||
|
|
||||||
|
$find_order = db_get($find_sql);
|
||||||
|
|
||||||
|
if (isset($find_order['buy_id'])){
|
||||||
|
|
||||||
|
$currdate = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
$supd = "
|
||||||
|
UPDATE
|
||||||
|
`anbuy`
|
||||||
|
SET
|
||||||
|
`buy_status` = '1',
|
||||||
|
`buy_active` = '1',
|
||||||
|
`date` = '$currdate'
|
||||||
|
WHERE
|
||||||
|
`buy_id` = '{$find_order['buy_id']}'";
|
||||||
|
|
||||||
|
db_get($supd, 'chitatel');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo "order not fount";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
logsave('yk', $source);
|
||||||
|
|
||||||
|
return True;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function yk_pay($price, $name){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$client = new Client();
|
||||||
|
$client->setAuth(YID, YKEY);
|
||||||
|
|
||||||
|
|
||||||
|
$items = array(
|
||||||
|
'amount' => array(
|
||||||
|
'value' => 1.0,
|
||||||
|
'currency' => 'RUB',
|
||||||
|
),
|
||||||
|
'confirmation' => array(
|
||||||
|
'type' => 'redirect',
|
||||||
|
'return_url' => SITE,
|
||||||
|
),
|
||||||
|
'capture' => true,
|
||||||
|
'description' => $name,
|
||||||
|
);
|
||||||
|
|
||||||
|
$id = uniqid('', true);
|
||||||
|
|
||||||
|
|
||||||
|
$payment = $client->createPayment(
|
||||||
|
$items, $id
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return $payment;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -5,19 +5,13 @@
|
|||||||
* оформление заказа
|
* оформление заказа
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function checkout_kuri($priceslug, $buy_type = 1){
|
function checkout_kuri($priceslug, $delivery_id = 1){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$price_id = db_get("SELECT * FROM `price` WHERE `priceslug` = '$priceslug' LIMIT 1");
|
$price_id = db_get("SELECT * FROM `price` WHERE `priceslug` = '$priceslug' LIMIT 1");
|
||||||
|
|
||||||
if (isset($price_id['price_id'])) {
|
if (isset($price_id['price_id'])) {
|
||||||
|
|
||||||
|
if ($delivery_id == 1){ // тип товара
|
||||||
if ($buy_type == 1){ // тип товара
|
|
||||||
$price = $price_id['price']; // электронная книжка
|
$price = $price_id['price']; // электронная книжка
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -30,7 +24,7 @@ function checkout_kuri($priceslug, $buy_type = 1){
|
|||||||
$client = client_find_id(CLIENT_ID);
|
$client = client_find_id(CLIENT_ID);
|
||||||
|
|
||||||
if (isset($client['result']['client_id'])){
|
if (isset($client['result']['client_id'])){
|
||||||
$clienthash = $client['result']['clienthash'];
|
$client = $client['result'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -43,16 +37,42 @@ function checkout_kuri($priceslug, $buy_type = 1){
|
|||||||
$error_mail = True;
|
$error_mail = True;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# получаем хэш клиента чтобы отправить на оплату
|
# ищем или создаем клиента
|
||||||
$clienthash = api_add_client($clientmail);
|
$client = api_add_client($clientmail);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($clienthash) and $clienthash) {
|
|
||||||
$paylink = PAYSITE."anpay/$priceslug/$clienthash";
|
|
||||||
header("Location: $paylink");
|
if (isset($client['client_id'])) {
|
||||||
return True;
|
|
||||||
|
#создаем заказ
|
||||||
|
$add['client_id'] = $client['client_id'];
|
||||||
|
$add['buy_email'] = $client['clientmail'];
|
||||||
|
$add['buy_price'] = $price;
|
||||||
|
$add['price'] = $price;
|
||||||
|
$add['buy_status'] = 0;
|
||||||
|
$add['mail_status'] = 0;
|
||||||
|
$add['number_id'] = $price_id['price_id'];
|
||||||
|
$add['pay_id'] = 3; // оплата через Юкассу
|
||||||
|
$add['delivery_id'] = $delivery_id;
|
||||||
|
$add['date_start'] = date('Y-m-d H:i:s');
|
||||||
|
$add['buy_active'] = 0;
|
||||||
|
|
||||||
|
|
||||||
|
$order_id = db_insert('anbuy', $add, 'chitatel'); // добавляем в базу заказ
|
||||||
|
|
||||||
|
if (is_array($order_id)){ // неудалось создать заказ
|
||||||
|
$error_mail = True;
|
||||||
|
|
||||||
|
}
|
||||||
|
else { // заказ создался
|
||||||
|
|
||||||
|
return anpay_kuri($order_id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -61,9 +81,9 @@ function checkout_kuri($priceslug, $buy_type = 1){
|
|||||||
$error_price = True;
|
$error_price = True;
|
||||||
}
|
}
|
||||||
|
|
||||||
$submit_link = SITE."checkout/$priceslug/$buy_type";
|
$submit_link = SITE."checkout/$priceslug/$buy_type";
|
||||||
|
|
||||||
include VIEWPATH.'checkout.phtml';
|
include VIEWPATH.'checkout.phtml';
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user