This commit is contained in:
Alan
2026-02-14 19:34:54 +03:00
commit 5c3329238b
867 changed files with 214778 additions and 0 deletions

40
payment/Yandex/Yandex.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
require_once('api/Simpla.php');
class Yandex extends Simpla
{
// Комиссия Яндекса, %
private $fee = 0.5;
public function checkout_form($order_id, $button_text = null)
{
if(empty($button_text))
$button_text = 'Перейти к оплате';
$order = $this->orders->get_order((int)$order_id);
$payment_method = $this->payment->get_payment_method($order->payment_method_id);
$payment_currency = $this->money->get_currency(intval($payment_method->currency_id));
$settings = $this->payment->get_payment_settings($payment_method->id);
$price = round($this->money->convert($order->total_price, $payment_method->currency_id, false), 2);
// Учесть комиссию Яндекса
$price = $price+max(0.01, $price*$this->fee/100);
// описание заказа
$desc = 'Оплата заказа №'.$order->id.' на сайте '.$this->settings->site_name;
$button = '<form method="POST" action="https://money.yandex.ru/quickpay/confirm.xml">
<input name="receiver" type="hidden" value="'.$settings['yandex_id'].'">
<input name="short-dest" type="hidden" value="'.$desc.'">
<input type="hidden" name="comment" value="'.$desc.'"/>
<input name="quickpay-form" type="hidden" value="shop">
<input data-type="number" type="hidden" name="sum" value="'.$price.'">
<input name="label" type="hidden" value="'.$order->id.'">
<input type="submit" name="submit-button" value="'.$button_text.'" class="checkout_button">
</form>';
return $button;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Simpla CMS
*
* @copyright 2013 Denis Pikusov
* @link http://simplacms.ru
* @author Denis Pikusov
*
* К этому скрипту обращается Yandex для уведомления об оплате
*
*/
// Работаем в корневой директории
chdir ('../../');
require_once('api/Simpla.php');
$simpla = new Simpla();
////////////////////////////////////////////////
// Проверка статуса
////////////////////////////////////////////////
if($_POST['notification_type'] !== 'p2p-incoming')
err('bad status');
////////////////////////////////////////////////
// Выберем заказ из базы
////////////////////////////////////////////////
$order = $simpla->orders->get_order(intval($_POST['label']));
if(empty($order))
err('Оплачиваемый заказ не найден');
////////////////////////////////////////////////
// Выбираем из базы соответствующий метод оплаты
////////////////////////////////////////////////
$method = $simpla->payment->get_payment_method(intval($order->payment_method_id));
if(empty($method))
err("Неизвестный метод оплаты");
$settings = unserialize($method->settings);
$payment_currency = $simpla->money->get_currency(intval($method->currency_id));
// Проверяем контрольную подпись
$hash = sha1($_POST['notification_type'].'&'.$_POST['operation_id'].'&'.$_POST['amount'].'&'.$_POST['currency'].'&'.$_POST['datetime'].'&'.$_POST['sender'].'&'.$_POST['codepro'].'&'.$settings['yandex_secret'].'&'.$_POST['label']);
if($hash !== $_POST['sha1_hash'])
err('bad sign');
// Нельзя оплатить уже оплаченный заказ
if($order->paid)
err('Этот заказ уже оплачен');
// Учет комиссии Яндекса
$amount = round($simpla->money->convert($order->total_price, $method->currency_id, false), 2);
if($_POST['amount'] != $amount || $_POST['amount']<=0)
err("incorrect price");
// Установим статус оплачен
$simpla->orders->update_order(intval($order->id), array('paid'=>1));
// Отправим уведомление на email
$simpla->notify->email_order_user(intval($order->id));
$simpla->notify->email_order_admin(intval($order->id));
// Спишем товары
$simpla->orders->close(intval($order->id));
function err($msg)
{
header($_SERVER['SERVER_PROTOCOL'].' 400 Bad Request', true, 400);
// mail("test@test", "yandex: $msg", $msg);
die($msg);
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module>
<name>
Яндекс Деньги
</name>
<settings>
<variable>yandex_id</variable>
<name>Кошелек получателя</name>
</settings>
<settings>
<variable>yandex_secret</variable>
<name>Секретный ключ</name>
</settings>
</module>