Init
This commit is contained in:
38
payment/Platon/Platon.php
Normal file
38
payment/Platon/Platon.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
require_once('api/Simpla.php');
|
||||
|
||||
class Platon 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
|
||||
$data = base64_encode( serialize( array('amount'=>$price, 'currency'=>$payment_currency->code, 'name'=>'Оплата заказа №'.$order->id)));
|
||||
|
||||
$return_url = $this->config->root_url.'/order/'.$order->url;
|
||||
|
||||
$sign = md5(strtoupper(strrev($_SERVER["REMOTE_ADDR"]).strrev($settings['platon_key']).strrev($data).strrev($return_url).strrev($settings['platon_password'])));
|
||||
|
||||
$button = '<form action="https://secure.platononline.com/webpaygw/pcc.php?a=auth" method="POST"/>'.
|
||||
'<input type="hidden" name="key" value="'.$settings['platon_key'].'" />'.
|
||||
'<input type="hidden" name="order" value="'.$order->id.'" />'.
|
||||
'<input type="hidden" name="data" value="'.$data.'" />'.
|
||||
'<input type="hidden" name="url" value="'.$return_url.'" />'.
|
||||
'<input type="hidden" name="sign" value="'.$sign.'" />'.
|
||||
'<input type=submit class=checkout_button value="'.$button_text.'">'.
|
||||
'</form>';
|
||||
return $button;
|
||||
}
|
||||
}
|
||||
83
payment/Platon/callback.php
Normal file
83
payment/Platon/callback.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Simpla CMS
|
||||
*
|
||||
* @copyright 2011 Denis Pikusov
|
||||
* @link http://simplacms.ru
|
||||
* @author Denis Pikusov
|
||||
*
|
||||
* К этому скрипту обращается Platon в процессе оплаты
|
||||
*
|
||||
*/
|
||||
|
||||
// Работаем в корневой директории
|
||||
chdir ('../../');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
|
||||
// Сумма, которую заплатил покупатель. Дробная часть отделяется точкой.
|
||||
$amount = $_POST['amount'];
|
||||
|
||||
// Внутренний номер покупки продавца
|
||||
// В этом поле передается id заказа в нашем магазине.
|
||||
$order_id = intval($_POST['order']);
|
||||
|
||||
// Контрольная подпись
|
||||
$sign = $_POST['sign'];
|
||||
|
||||
// Проверим статус
|
||||
if($_POST['status'] !== 'SALE')
|
||||
die('Incorrect Status');
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Выберем заказ из базы
|
||||
////////////////////////////////////////////////
|
||||
$order = $simpla->orders->get_order(intval($order_id));
|
||||
if(empty($order))
|
||||
die('Оплачиваемый заказ не найден');
|
||||
|
||||
// Нельзя оплатить уже оплаченный заказ
|
||||
if($order->paid)
|
||||
die('Этот заказ уже оплачен');
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Выбираем из базы соответствующий метод оплаты
|
||||
////////////////////////////////////////////////
|
||||
$method = $simpla->payment->get_payment_method(intval($order->payment_method_id));
|
||||
if(empty($method))
|
||||
die("Неизвестный метод оплаты");
|
||||
|
||||
$settings = unserialize($method->settings);
|
||||
|
||||
// Проверяем контрольную подпись
|
||||
$my_sign = md5(strtoupper(strrev($_POST['email']).$settings['platon_password'].$order->id.strrev(substr($_POST['card'],0,6).substr($_POST['card'],-4))));
|
||||
if($sign !== $my_sign)
|
||||
die("bad sign\n");
|
||||
|
||||
if($amount != $simpla->money->convert($order->total_price, $method->currency_id, false) || $amount<=0)
|
||||
die("incorrect price\n");
|
||||
|
||||
////////////////////////////////////
|
||||
// Проверка наличия товара
|
||||
////////////////////////////////////
|
||||
$purchases = $simpla->orders->get_purchases(array('order_id'=>intval($order->id)));
|
||||
foreach($purchases as $purchase)
|
||||
{
|
||||
$variant = $simpla->variants->get_variant(intval($purchase->variant_id));
|
||||
if(empty($variant) || (!$variant->infinity && $variant->stock < $purchase->amount))
|
||||
{
|
||||
die("Нехватка товара $purchase->product_name $purchase->variant_name");
|
||||
}
|
||||
}
|
||||
|
||||
// Установим статус оплачен
|
||||
$simpla->orders->update_order(intval($order->id), array('paid'=>1));
|
||||
|
||||
// Спишем товары
|
||||
$simpla->orders->close(intval($order->id));
|
||||
$simpla->notify->email_order_user(intval($order->id));
|
||||
$simpla->notify->email_order_admin(intval($order->id));
|
||||
|
||||
die("OK".$order_id."\n");
|
||||
14
payment/Platon/settings.xml
Normal file
14
payment/Platon/settings.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module>
|
||||
<name>
|
||||
Platon
|
||||
</name>
|
||||
<settings>
|
||||
<variable>platon_key</variable>
|
||||
<name>Ключ</name>
|
||||
</settings>
|
||||
<settings>
|
||||
<variable>platon_password</variable>
|
||||
<name>Пароль</name>
|
||||
</settings>
|
||||
</module>
|
||||
Reference in New Issue
Block a user