Init
This commit is contained in:
62
payment/Pay2Pay/Pay2Pay.php
Normal file
62
payment/Pay2Pay/Pay2Pay.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
require_once('api/Simpla.php');
|
||||
|
||||
class Pay2Pay 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);
|
||||
|
||||
|
||||
// описание заказа
|
||||
// order description
|
||||
$desc = 'Оплата заказа №'.$order->id;
|
||||
|
||||
// Способ оплаты
|
||||
$paymode = $settings['pay2pay_paymode'];
|
||||
|
||||
$success_url = $this->config->root_url.'/order/';
|
||||
$result_url = $this->config->root_url.'/payment/Pay2Pay/callback.php';
|
||||
|
||||
$currency = $payment_currency->code;
|
||||
if ($currency == 'RUR')
|
||||
$currency = 'RUB';
|
||||
|
||||
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||
<request>
|
||||
<version>1.2</version>
|
||||
<merchant_id>".$settings['pay2pay_merchantid']."</merchant_id>
|
||||
<language>ru</language>
|
||||
<order_id>$order->id</order_id>
|
||||
<amount>$price</amount>
|
||||
<currency>$currency</currency>
|
||||
<description>$desc</description>
|
||||
<result_url>$result_url</result_url>
|
||||
<success_url>$success_url</success_url>
|
||||
<fail_url>$success_url</fail_url>";
|
||||
if ($settings['pay2pay_testmode'] == '1')
|
||||
$xml .= "<test_mode>1</test_mode>";
|
||||
$xml .= "</request>";
|
||||
|
||||
$xml_encoded = base64_encode($xml);
|
||||
|
||||
$merc_sign = $settings['pay2pay_secret'];
|
||||
$sign_encoded = base64_encode(md5($merc_sign.$xml.$merc_sign));
|
||||
|
||||
$button = '<form action="https://merchant.pay2pay.com/?page=init" method="POST" />'.
|
||||
'<input type="hidden" name="xml" value="'.$xml_encoded.'" />'.
|
||||
'<input type="hidden" name="sign" value="'.$sign_encoded.'" />'.
|
||||
'<input type="submit" class="checkout_button" value="'.$button_text.'">'.
|
||||
'</form>';
|
||||
return $button;
|
||||
}
|
||||
}
|
||||
103
payment/Pay2Pay/callback.php
Normal file
103
payment/Pay2Pay/callback.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Simpla CMS
|
||||
*
|
||||
* @copyright 2012 Pay2Pay
|
||||
* @link http://pay2pay.com
|
||||
* @author Sergey Mihaylovskiy
|
||||
*
|
||||
* К этому скрипту обращается Pay2Pay в процессе оплаты
|
||||
*
|
||||
*/
|
||||
|
||||
function get_tag_val($xml, $name)
|
||||
{
|
||||
preg_match("/<$name>(.*)<\/$name>/i", $xml, $matches);
|
||||
return trim($matches[1]);
|
||||
}
|
||||
|
||||
// Работаем в корневой директории
|
||||
chdir ('../../');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
|
||||
|
||||
$xml_post = base64_decode(str_replace(' ', '+', $_REQUEST['xml']));
|
||||
$sign_post = base64_decode(str_replace(' ', '+', $_REQUEST['sign']));
|
||||
|
||||
// Выбираем из xml нужные данные
|
||||
$order_id = intval(get_tag_val($xml_post, 'order_id'));
|
||||
$merchant_id = get_tag_val($xml_post, 'merchant_id');
|
||||
$amount = get_tag_val($xml_post, 'amount');
|
||||
$currency_code = get_tag_val($xml_post, 'currency');
|
||||
$status = get_tag_val($xml_post, 'status');
|
||||
|
||||
$err = '';
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Выберем заказ из базы
|
||||
////////////////////////////////////////////////
|
||||
$order = $simpla->orders->get_order(intval($order_id));
|
||||
if(!empty($order))
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Выбираем из базы соответствующий метод оплаты
|
||||
////////////////////////////////////////////////
|
||||
$method = $simpla->payment->get_payment_method(intval($order->payment_method_id));
|
||||
if(!empty($method))
|
||||
{
|
||||
|
||||
$settings = unserialize($method->settings);
|
||||
$payment_currency = $simpla->money->get_currency(intval($method->currency_id));
|
||||
|
||||
// Проверяем контрольную подпись
|
||||
$mysignature = md5($settings['pay2pay_hidden'].$xml_post.$settings['pay2pay_hidden']);
|
||||
if($mysignature == $sign_post)
|
||||
{
|
||||
|
||||
// Нельзя оплатить уже оплаченный заказ
|
||||
if (!$order->paid)
|
||||
{
|
||||
if($amount >= round($simpla->money->convert($order->total_price, $method->currency_id, false), 2))
|
||||
{
|
||||
$currency = $payment_currency->code;
|
||||
if ($currency == 'RUR')
|
||||
$currency = 'RUB';
|
||||
if($currency_code == $currency)
|
||||
{
|
||||
if($status == 'success')
|
||||
{
|
||||
// Установим статус оплачен
|
||||
$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));
|
||||
}
|
||||
}
|
||||
else
|
||||
$err = "Currency check failed";
|
||||
}
|
||||
else
|
||||
$err = "Amount check failed";
|
||||
}
|
||||
//else
|
||||
// $err = 'Order is paid';
|
||||
}
|
||||
else
|
||||
$err = "Security check failed";
|
||||
}
|
||||
else
|
||||
$err = "Unknown payment method";
|
||||
}
|
||||
else
|
||||
$err = "Unknown OrderId";
|
||||
|
||||
if ($err != '')
|
||||
die("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><status>no</status><err_msg>$err</err_msg></response>");
|
||||
else
|
||||
die("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><status>yes</status><err_msg></err_msg></response>");
|
||||
30
payment/Pay2Pay/settings.xml
Normal file
30
payment/Pay2Pay/settings.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module>
|
||||
<name>
|
||||
Pay2Pay
|
||||
</name>
|
||||
<settings>
|
||||
<variable>pay2pay_merchantid</variable>
|
||||
<name>ID мерчанта</name>
|
||||
</settings>
|
||||
<settings>
|
||||
<variable>pay2pay_secret</variable>
|
||||
<name>Секретный ключ</name>
|
||||
</settings>
|
||||
<settings>
|
||||
<variable>pay2pay_hidden</variable>
|
||||
<name>Скрытый ключ</name>
|
||||
</settings>
|
||||
<settings>
|
||||
<variable>pay2pay_paymode</variable>
|
||||
<name>Способ оплаты</name>
|
||||
</settings>
|
||||
<settings>
|
||||
<variable>pay2pay_testmode</variable>
|
||||
<name>Тестовый режим</name>
|
||||
<options>
|
||||
<name>Тестовый</name>
|
||||
<value>1</value>
|
||||
</options>
|
||||
</settings>
|
||||
</module>
|
||||
Reference in New Issue
Block a user