Version: 2.2.7 Pro rev3148
Здравствуйте, помогите с интеграцией платежной системы Сбербанка.
Пытаюсь написать модуль, возникает следующие проблемы
1) public function getRedirectUrl - вызывается 12 раз и не переходит на платежную форму Сбербанка. Первый раз запрос к Себрбанку проходит корректно, остальные Сбербанк отвечает, что такой заказ уже обработан. Данная проблема уже обсуждалась на форуме http://forum.jbzoo.c...ma-troekratnog/ , но решение так и не было найдено. Для решения этой проблемы были добавлены сессионные переменные $_SESSION['SberbankOrderId'] и $_SESSION['SberbankFormUrl']. Я понимаю, что это "костыли", но ничего другого не придумала. Теперь public function getRedirectUrl все равно вызывается 12 раз, но переход на платежную форму Сбербанка с необходимыми параметрами происходит корректно.
2) Но теперь встала другая проблема - после того, как пользователь произвел оплату на сайте Сбербанка, Сбербанк редиректит на сайт магазина, вызывается public function getRequestOrderId(), но не вызываются функции public function getRequestOrderSum() и public function isValid. При этом в функции getRequestOrderId() делается запрос на страницу проверки состояния оплаты, возвращается корректный номер заказа. Но после этого статус оплаты не меняется на оплачено. В контексте этой функции я не могу обратиться к заказу, он просто не видит текущий заказ.
$order = $this->getOrder();
$orderId = $this->getOrderId();
Как-нибудь можно принудительно поменять статус на оплачено после проверки статуса вот здесь?
if ($orderStatus == '1' || $orderStatus == '2')
{
$this->logInfo("getRequestOrderId:1 " . $action_adr, "| " . $orderNumber, "| " . $this->isDebug());
return $orderNumber;
}
Или есть иные, стандартные способы смены статуса?
Во вложении архив с модулем оплаты (sberbank.zip), простейший пример, который даёт Сбербанк (rest.php), пример модуля оплаты для Виртуемарт (Плагин joomla (Vm_3.0.20).rar), инструкция от Сбербанка.
<?php
/**
* JBZoo App is universal Joomla CCK, application for YooTheme Zoo component
*
* @package jbzoo
* @version 2.x Pro
* @author JBZoo App http://jbzoo.com
* @copyright Copyright (C) JBZoo.com, All rights reserved.
* @license http://jbzoo.com/license-pro.php JBZoo Licence
* @coder Denis Smetannikov <denis@jbzoo.com>
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
/**
* Class JBCartElementPaymentSberbank
*/
class JBCartElementPaymentSberbank extends JBCartElementPayment
{
public function getRedirectUrl()
{
$method_step = $this->config->get('method_step');
$order = $this->getOrder();
$orderId = $this->getOrderId();
$payCurrency = $this->getDefaultCurrency();
$orderAmount = $this->_order->val($this->getOrderSumm(), $order->getCurrency())->convert($payCurrency);
$orderAmount = $orderAmount->val() * 100;
if (!session_id())
{
session_start();
}
if (!isset($_SESSION['SberbankOrderId']))
{
$_SESSION['SberbankOrderId'] = 0;
$_SESSION['SberbankFormUrl'] = "";
}
if ($_SESSION['SberbankOrderId'] != $orderId)
{
$_SESSION['SberbankOrderId'] = $orderId;
$fields = array
(
'userName' => JString::trim($this->config->get('merchant')),
'password' => JString::trim($this->config->get('password')),
'amount' => $orderAmount,
'orderNumber' => $orderId, //$this->getOrderId(),
'returnUrl' => $this->_jbrouter->payment('success'), //'http://мойсайт/index.php?option=com_zoo&controller=payment&task=paymentSuccess',
'failUrl' => $this->_jbrouter->payment('fail') //'http://мойсайт/index.php?option=com_zoo&controller=payment&task=paymentFail'
);
if($this->isDebug())
{
$action_adr = $this->config->get('API_URL_TEST');
}
else
{
$action_adr = $this->config->get('API_URL_PROD');
}
if ($method_step == '1')
{
$action_adr .= 'register.do';
}
else
{
$action_adr .= 'registerPreAuth.do';
}
$rbsCurl = curl_init();
curl_setopt_array($rbsCurl, array(
CURLOPT_URL => $action_adr,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($fields)
));
$response = curl_exec($rbsCurl);
curl_close($rbsCurl);
//if($this->isDebug())
//{
$this->logInfo("getRedirectUrl: " . $action_adr, http_build_query($fields), $response);
//}
$response = json_decode($response, true);
$errorCode = $response['errorCode'];
if ($errorCode > 0)
{
echo 'ошибка #'.$errorCode.': '.$response['errorMessage'];
}
$_SESSION['SberbankFormUrl'] = $response['formUrl'];
return $response['formUrl'];
}
else
{
return $_SESSION['SberbankFormUrl'];
}
}
public function isValid($params = array())
{
$this->logInfo("getRequestOrderId:3 " . $action_adr, "", "");
return true;
}
public function getRequestOrderId()
{
$method_step = $this->config->get('method_step');
$fields = array(
'userName' => $this->config->get('merchant'),
'password' => $this->config->get('password'),
'orderId' => $_GET['orderId']
);
if ($this->isDebug())
{
$action_adr = $this->config->get('API_URL_TEST');
}
else
{
$action_adr = $this->config->get('API_URL_PROD');
}
$action_adr .= 'getOrderStatus.do';
$rbsCurl = curl_init();
curl_setopt_array($rbsCurl, array(
CURLOPT_URL => $action_adr,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($fields)
));
$response = curl_exec($rbsCurl);
curl_close($rbsCurl);
//if($this->isDebug())
//{
$this->logInfo("getRequestOrderId: " . $action_adr, http_build_query($fields), $response);
//}
$response = json_decode($response, true);
$orderStatus = $response['OrderStatus'];
$orderNumber = $response['OrderNumber'];
if ($orderStatus == '1' || $orderStatus == '2')
{
$this->logInfo("getRequestOrderId:1 " . $action_adr, "| " . $orderNumber, "| " . $this->isDebug());
return $orderNumber;
}
else
{
$this->logInfo("getRequestOrderId:2 " . $action_adr, "", "");
return 0;
}
//return $this->app->jbrequest->get('OrderNumber');
}
public function getRequestOrderSum()
{
/*
$method_step = $this->config->get('method_step');
$fields = array(
'userName' => $this->config->get('merchant'),
'password' => $this->config->get('password'),
'orderId' => $_GET['orderId']
);
if ($this->isDebug())
{
$action_adr = $this->config->get('API_URL_TEST');
}
else
{
$action_adr = $this->config->get('API_URL_PROD');
}
$action_adr .= 'getOrderStatus.do';
$rbsCurl = curl_init();
curl_setopt_array($rbsCurl, array(
CURLOPT_URL => $action_adr,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($fields)
));
$response = curl_exec($rbsCurl);
curl_close($rbsCurl);
//if($this->isDebug())
//{
$this->logInfo("getRequestOrderSum: " . $action_adr, http_build_query($fields), $response);
//}
$response = json_decode($response, true);
$order = $this->getOrder();
$amount = $this->_order->val($response['Amount'], $order->getCurrency());
return $amount;
*/
$this->logInfo("getRequestOrderId:4 " . $action_adr, "", "");
$order = $this->getOrder();
$orderId = $this->getOrderId();
$payCurrency = $this->getDefaultCurrency();
$orderAmount = $this->_order->val($this->getOrderSumm(), $order->getCurrency())->convert($payCurrency);
$amount = $orderAmount->val();
return $amount;
}
public function logInfo ($action, $request, $response) {
$file = JPATH_ROOT . "/logs/rbs_payment.log";
$date = JFactory::getDate ();
$fp = fopen ($file, 'a');
fwrite ($fp, "\n" . $date->Format ('%Y-%m-%d %H:%M:%S') . " " . $action . "\nrequest: " . $request . "\nresponse: " . $response);
fclose ($fp);
}
}
Прикрепленные файлы
Сообщение отредактировал Irina: 18 January 2018 - 09:52













