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/OKPay/OKPay.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
require_once('api/Simpla.php');
class OKPay extends Simpla
{
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);
$currency = $this->money->get_currency(intval($payment_method->currency_id));
// описание заказа
// order description
$desc = 'Оплата заказа №'.$order->id;
$return_url = $this->config->root_url.'/payment/OKPay/callback.php';
$button = '<form action="https://www.okpay.com/process.html" method="POST"/>'.
'<input type="hidden" name="ok_receiver" value="'.$settings['okpay_reciever'].'" />'.
'<input type="hidden" name="ok_invoice" value="'.$order->id.'" />'.
'<input type="hidden" name="ok_item_1_name" value="'.$desc.'" />'.
'<input type="hidden" name="ok_item_1_price" value="'.$price.'" />'.
'<input type="hidden" name="ok_currency" value="'.$currency->code.'" />'.
'<input type="hidden" name="ok_return_success" value="'.$return_url.'" />'.
'<input type="hidden" name="ok_return_fail" value="'.$return_url.'" />'.
'<input type=image src="https://www.okpay.com/img/buttons/x03.gif" alt="'.$button_text.'">'.
'</form>';
return $button;
}
}

115
payment/OKPay/callback.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
/**
* Simpla CMS
*
* @copyright 2011 Denis Pikusov
* @link http://simplacms.ru
* @author Denis Pikusov
*
* К этому скрипту обращается OKPay в процессе оплаты
*
*/
// Работаем в корневой директории
chdir ('../../');
require_once('api/Simpla.php');
$simpla = new Simpla();
// Read the post from OKPAY and add 'ok_verify'
$req = 'ok_verify=true';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// Post back to OKPAY to validate
$header .= "POST /ipn-verify.html HTTP/1.0\r\n";
$header .= "Host: www.okpay.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.okpay.com', 80, $errno, $errstr, 30);
if (!$fp)
{
my_exit('Error postback');
}
fputs ($fp, $header . $req);
while (!feof($fp))
$res = fgets ($fp, 1024);
fclose ($fp);
if ($res != "VERIFIED")
{
my_exit('Not verified');
}
// Проверяем данные
if($_POST['ok_txn_kind'] !== 'payment_link')
my_exit('Invalid ok_txn_kind');
if($_POST['ok_txn_status'] !== 'completed')
my_exit('Invalid ok_txn_status');
if(intval($_POST['ok_ipn_test']) !== 0)
my_exit('Test ipn');
$order_id = intval($_POST['ok_invoice']);
////////////////////////////////////////////////
// Выберем заказ из базы
////////////////////////////////////////////////
$order = $simpla->orders->get_order(intval($order_id));
if(empty($order))
my_exit('Оплачиваемый заказ не найден');
////////////////////////////////////////////////
// Выбираем из базы соответствующий метод оплаты
////////////////////////////////////////////////
$method = $simpla->payment->get_payment_method(intval($order->payment_method_id));
if(empty($method))
my_exit("Неизвестный метод оплаты");
$settings = unserialize($method->settings);
$payment_currency = $simpla->money->get_currency(intval($method->currency_id));
// Проверяем получателя платежа
if($_POST['ok_reciever'] != $settings['okpay_receiver'])
my_exit("bad reciever");
// Проверяем валюту
if($_POST['ok_txn_currency'] != $payment_currency->code)
my_exit("bad currency");
// Нельзя оплатить уже оплаченный заказ
if($order->paid)
my_exit('Этот заказ уже оплачен');
if($_POST['ok_item_1_price'] != round($simpla->money->convert($order->total_price, $method->currency_id, false), 2) || $_POST['ok_item_1_price']<=0)
my_exit("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));
// Перенаправим пользователя на страницу заказа
header('Location: '.$simpla->request->root_url.'/order/'.$order->url);
exit();
function my_exit($text)
{
header('Location: '.$simpla->request->root_url.'/order/');
exit();
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module>
<name>
OKPay
</name>
<settings>
<variable>okpay_reciever</variable>
<name>Получатель платежей (email, телефон или id)</name>
</settings>
</module>