ОСМП

Технические вопросы по UTM 5.0
Закрыто
MiO
Сообщения: 303
Зарегистрирован: Ср окт 01, 2008 23:34

ОСМП

Сообщение MiO »

Уважаемые, делал ли кто интеграцию с ОСМП?

точнее:
https://service.someprv.ru:8443/payment ... &sum=10.45
Запрос содержит переменные:
command=pay – запрос на пополнение баланса абонента
txn_id=1234567 – внутренний номер платежа в системе ОСМП
txn_date=20050815120133 – дата учета платежа в системе ОСМП
account=4957835959 – идентификатор абонента в информационной системе провайдера
sum=10.45 – сумма к зачислению на лицевой счет абонента
Пример ответа:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<osmp_txn_id>1234567</osmp_txn_id>
<prv_txn>2016</prv_txn>
<amount>10.45</amount>
<result>0</result>
<comment>OK</comment>
</response>
Возвращая result=0 на запрос «pay», провайдер сообщает об успешном завершении операции пополнения баланса. Система полностью завершает обработку данной транзакции.
В необязательном поле comment содержится служебный комментарий.
может кто-то поделится скриптом для соединеня с этой системой мой чтото - както гдето не проходит по параметрам...

Аватара пользователя
Chrst
Сообщения: 370
Зарегистрирован: Пт май 11, 2007 09:28
Откуда: Медиахолдинг "ЛеККС"
Контактная информация:

Re: ОСМП

Сообщение Chrst »

MiO писал(а):Уважаемые, делал ли кто интеграцию с ОСМП?
Я делал, только на php. Все проверки прошли, за исключением не значимых доп. параметров. Но скрипт в живую так и не поработал.

MiO
Сообщения: 303
Зарегистрирован: Ср окт 01, 2008 23:34

Сообщение MiO »

Chrst не мог бы поделится php'ным скриптом хотяб для проведения всех проверок...

MiO
Сообщения: 303
Зарегистрирован: Ср окт 01, 2008 23:34

Сообщение MiO »

up-после падения форума)

Oleg_121
Сообщения: 81
Зарегистрирован: Пн апр 14, 2008 21:09

Сообщение Oleg_121 »

Вот скрипт который работает у нас уже 3 месяца.
Для пополнения счета используется URFA


#!/usr/bin/perl

use CGI;
use XML::Simple;
#use Digest::MD5 qw(md5_hex);

use Net::IP;
use Net::Netmask;

use SUB::UTF;
use SUB::URFA;
use SUB::UTM::users;
use SUB::PAY::osmp;

use strict;

### definitions ###
my $ref;
my $error;
my $net = Net::Netmask->new('79.142.16.0/20');
my $proto = 'GET';
###################


my $q = new CGI;

if ( $q->param('command') eq 'check' )
{
my $user;

if ( ($q->param('sum') !~ /^\d+(\.\d{2})?$/) || ($q->param('txn_id') !~ /^\d+$/) )
{
$error->{result} = ['300'],
$error->{comment} = ['Format of data-fields incorrect, or incomplete'],
}

if ( $q->param('account') !~ /^[A-Za-z0-9\-]+$/ )
{
$error->{osmp_txn_id} = [$q->param('txn_id')],
$error->{result} = ['4'],
$error->{comment} = ['Incorrect account format'],
}

if ( !$error )
{
$user = SUB::UTM::users->retrieve(login=>$q->param('account'),is_deleted=>0);

if ( !$user )
{
$error->{osmp_txn_id} = [$q->param('txn_id')],
$error->{result} = ['5'],
$error->{comment} = ['User not found'],
}
else
{
if ( ref $user->basic_account ne 'SUB::UTM::accounts' )
{
$error->{osmp_txn_id} = [$q->param('txn_id')],
$error->{result} = ['243'],
$error->{comment} = ['Unable to check account'],
}


if ( $q->param('sum') < 1 )
{
$error->{osmp_txn_id} = [$q->param('txn_id')],
$error->{result} = ['241'],
$error->{comment} = ['Payment too small'],
}

if ( $q->param('sum') > 100000 )
{
$error->{osmp_txn_id} = [$q->param('txn_id')],
$error->{result} = ['242'],
$error->{comment} = ['Payment too large'],
}
}
}

if ( !$error )
{
my $payment = SUB::PAY::osmp->retrieve
(
account => $user->basic_account->id,
txn_id => $q->param('txn_id'),
sum => $q->param('sum'),
);

if ( !$payment )
{
$payment = SUB::PAY::osmp->insert
({
account => $user->basic_account->id,
cdate => time(),
sum => $q->param('sum'),
txn_id => $q->param('txn_id'),
});
}

if ( $payment )
{
$ref->{osmp_txn_id} = [$payment->txn_id];
$ref->{result} = [0];
}
else
{
$error->{result} = ['1'];
$error->{comment} = ['Some error while processing request. Please, contact hostmaster@xxx.ru'];
}
}
}
elsif ( $q->param('command') eq 'pay' )
{
if ( ($q->param('sum') !~ /^\d+(\.\d{2})?$/) || ($q->param('txn_id') !~ /^\d+$/) )
{
$error->{result} = ['300'],
$error->{comment} = ['Format of data-fields incorrect, or incomplete'],
}

if ( !$error )
{
my $user = SUB::UTM::users->retrieve(login=>$q->param('account'),is_deleted=>0);
my $payment = SUB::PAY::osmp->retrieve
(
account => $user->basic_account->id,
txn_id => $q->param('txn_id'),
sum => $q->param('sum'),
);

if ( $payment )
{
if ( $payment->passed eq '0' )
my $u = SUB::URFA->new();
$u->prepare
(
a => 'add_payment',
payment => $payment->sum,
account_id => $payment->account,
payment_method => '104',
comment => 'OSMP payment',
);

if ( $u->execute )
{
$payment->passed(1);
$payment->txn_date($q->param('txn_date'));
$payment->update;

$ref->{osmp_txn_id} = [$payment->txn_id];
$ref->{prv_txn} = [$payment->id];
$ref->{sum} = [$payment->sum];
$ref->{result} = [0];
$ref->{comment} = ['OK'];
}
else
{
$error->{osmp_txn_id} = [$q->param('txn_id')],
$error->{result} = ['1'],
$error->{comment} = ['An error occured while processing payment'],
}
}
elsif ( $payment->passed eq '1' )
{
$ref->{osmp_txn_id} = [$payment->txn_id];
$ref->{prv_txn} = [$payment->id];
$ref->{sum} = [$payment->sum];
$ref->{result} = [0];
$ref->{comment} = ['OK'];
}
}

else
{
$error->{result} = ['300'];
$error->{comment} = ['Incomplete request'];
}

print $q->header(-type=>'text/xml',-charset=>'utf-8');
print '<?xml version="1.0" encoding="UTF-8"?>'."\n";
print XMLout($error ? $error : $ref, 'RootName'=>'response');

MiO
Сообщения: 303
Зарегистрирован: Ср окт 01, 2008 23:34

Сообщение MiO »

Oleg_121 Спасибо большое конечно, но мне нужен скрипт только для прохождения проверок, на пополнение как раз всё готово...

и желательно без урфы =)

Аватара пользователя
Chris
Сообщения: 2323
Зарегистрирован: Чт июн 02, 2005 14:08
Откуда: 33 76 77 71 86 37 98

Сообщение Chris »

Мне то на форум выложи )))

MiO
Сообщения: 303
Зарегистрирован: Ср окт 01, 2008 23:34

Сообщение MiO »

если для проверок будет скриптик выложу :)

Аватара пользователя
Chrst
Сообщения: 370
Зарегистрирован: Пт май 11, 2007 09:28
Откуда: Медиахолдинг "ЛеККС"
Контактная информация:

Сообщение Chrst »

Вот чисто для проверок

Код: Выделить всё

<?php
//###################################################################
//http&#58;//хост/osmp/osmp_pay.php?command=check&txn_id=1234567&account=09572342&sum=10.45
// пример запроса

$prv_txn = ''; // Уникальный идентификатор платежа &#40;ответ платежной системе&#41;

// Добавляет строку в log файл
function str2log&#40;$logstr&#41;&#123;
  $logpath = "./log/osmp_pay.log";
  $flog = fopen&#40;$logpath, "ab"&#41;;
  $date = date&#40;"d.m.Y H&#58;i&#58;s"&#41;;
  $logstr = $date." ".$logstr."\n";
  fwrite&#40;$flog, $logstr&#41;;
  fclose&#40;$flog&#41;;
&#125;

$ip = &#40;isset&#40;$_SERVER&#91;'REMOTE_ADDR'&#93;&#41;&#41;?$_SERVER&#91;'REMOTE_ADDR'&#93;&#58;0;
// Принимать соединения только со следующих IP
/*
81.95.129.138
81.95.129.141
81.95.129.146
81.95.129.147
81.95.138.206
81.136.29.34
81.136.29.36
*/
if &#40;
    &#40;substr&#40;$ip,0,16&#41;!='81.95.129.138'&#41;
  &&&#40;substr&#40;$ip,0,16&#41;!='81.95.129.141'&#41;
  &&&#40;substr&#40;$ip,0,16&#41;!='81.95.129.146'&#41;
  &&&#40;substr&#40;$ip,0,16&#41;!='81.95.129.147'&#41;
  &&&#40;substr&#40;$ip,0,16&#41;!='81.95.138.206'&#41;
  &&&#40;substr&#40;$ip,0,16&#41;!='81.136.29.34'&#41;
  &&&#40;substr&#40;$ip,0,16&#41;!='81.136.29.36'&#41;
  &#41; &#123;
  $str = $ip." *** Access denied from this IP address !!!";
  str2log&#40;$str&#41;;
  die&#40;&#41;;
&#125;

// Проверка поля txn_id
function txn_id_check&#40;$txn_id&#41;&#123;
  global $dbhost, $dbname, $dbuser, $dbpass;

  $link = mysql_connect &#40;$dbhost, $dbuser, $dbpass&#41;;
  if &#40;!$link&#41; &#123; $str = "Database error&#58; ". mysql_error&#40;&#41;; str2log&#40;$str&#41;; return 8; &#125;
  @mysql_select_db&#40;$dbname, $link&#41;;
  $result = mysql_query&#40;"select * from osmp_transaction where txn_id=".$txn_id.""&#41;;
  if &#40;!$result&#41;&#123;
    $str = "Database Error&#58; ".mysql_error&#40;&#41;."";
    str2log&#40;$str&#41;;
    return 8;
  &#125;
  if &#40;mysql_num_rows&#40;$result&#41;>0&#41;&#123;
    str2log&#40;"*** Error&#58; txn_id $txn_id allready present"&#41;;
    return 7;
  &#125;
  return 0;
&#125;

// Проверка аккаунта
function txn_account_check&#40;$txn_account&#41;&#123;
  global $bdbhost, $bdbname, $bdbuser, $bdbpass;

  $link = mysql_connect &#40;$bdbhost, $bdbuser, $bdbpass&#41;;
  if &#40;!$link&#41; &#123; $str = "Database error&#58; ". mysql_error&#40;&#41;; str2log&#40;$str&#41;; return 8; &#125;
  @mysql_select_db&#40;$bdbname, $link&#41;;
  $result = mysql_query&#40;"select * from users where login='".addslashes&#40;$txn_account&#41;."'"&#41;;
  //Если что то пошло не так выводим ошибку
  if &#40;!$result&#41;&#123;
    $str = "Database Error&#58; ".mysql_error&#40;&#41;."";
    str2log&#40;$str&#41;;
    return 8;
  &#125;
  //Если пользователь был найден в базе
  if &#40;mysql_num_rows&#40;$result&#41;<1&#41;&#123;
    str2log&#40;"Error&#58; Account '$txn_account' not found"&#41;;
    return 7;
  &#125;
  else
    return 0;

  return 8;
&#125;

// Проверка суммы
function txn_sum_check&#40;$txn_sum&#41;&#123;
  if &#40;$txn_sum < 10&#41;&#123; return 241; &#125;
  if &#40;$txn_sum > 10000&#41;&#123; return 242; &#125;
  return 0;
&#125;

// Проверка даты
function txn_date_check&#40;$txn_date&#41;&#123;
  if &#40;$txn_date == ''&#41;&#123; str2log&#40;"Error. Date not indetify"&#41;; return 7; &#125;
  return 0;
&#125;

// Проверка входящего запроса 'Check', формирование ответа платежной системе
function cmd_check&#40;$txn_id,$txn_account,$txn_sum&#41; &#123;
  str2log&#40;"Command cmd_check for txn_id=$txn_id &#40;account='$txn_account' sum='$txn_sum'&#41; is requesting"&#41;;
  $result = 500;
  // Проверка поля txn_id
  $result = txn_id_check&#40;$txn_id&#41;;
  if &#40;$result == 0&#41; &#123;
  // Проверка аккаунта
    $result = txn_account_check&#40;$txn_account&#41;;
    if &#40;$result == 0&#41; &#123;
  // Проверка допустимости суммы
      $result = txn_sum_check&#40;$txn_sum&#41;;
    &#125;
  &#125;
  // Комментарий по коду завершения операции
  switch &#40;$result&#41;&#123;
    case "0"&#58; $comment = "ОК"; break;
    case "1"&#58; $comment = "Temporaly error. Try again later"; break;
    case "4"&#58; $comment = "Wrong id format"; break;
    case "5"&#58; $comment = "Account not found"; break;
    case "7"&#58; $comment = "Pay is denied by provider"; break;
    case "8"&#58; $comment = "Pay is denied by technical reason"; break;
    case "79"&#58; $comment = "Account is not active"; break;
    case "241"&#58; $comment = "Sum is very small"; break;
    case "242"&#58; $comment = "Sum is very large"; break;
    case "243"&#58; $comment = ""; break;
    case "300"&#58; $comment = "Other error"; break;
    default&#58; $comment = ""; break;
  &#125;
  // Формирование ответа платежной системе
  $response_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                 ."<response>\n"
                 ."<osmp_txn_id>$txn_id</osmp_txn_id>\n"
                 ."<result>$result</result>\n";
  if &#40;$result>0 and $comment<>""&#41; &#123; $response_str.= "<comment>$comment</comment>\n"; &#125;
  $response_str.= "</response>\n";

  if &#40;$result==0&#41; &#123; str2log&#40;"Check for txn_id=$txn_id is successfuly done"&#41;; &#125;
    else &#123; str2log&#40;"Check for txn_id=$txn_id is unsuccessfuly. Error code &#91;$result&#93; $comment"&#41;; &#125;
  echo "$response_str";
&#125;

function dopayment&#40;$txn_id,$txn_date,$txn_account,$txn_sum&#41;&#123;
  global $dbhost, $dbname, $dbuser, $dbpass, $prv_txn;

  $link = mysql_connect &#40;$dbhost, $dbuser, $dbpass&#41;;
  if &#40;!$link&#41; &#123; $str = "Database error&#58; ". mysql_error&#40;&#41;; str2log&#40;$str&#41;; return 8; &#125;

  @mysql_select_db&#40;$dbname, $link&#41;;
  $sql = "INSERT INTO osmp_transaction&#40;id,txn_id,txn_date,txn_account,txn_sum,status&#41; VALUES &#40;'','".$txn_id."','".$txn_date."','".$txn_account."','".$txn_sum."','0'&#41;";
  $result = mysql_query&#40;$sql&#41;;
  if &#40;!$result&#41; &#123;
    $str = "Database Error&#58; ".mysql_error&#40;&#41;."";
    str2log&#40;$str&#41;;
    return 8;
  &#125;
  $result = mysql_query&#40;"select * from osmp_transaction where txn_id=".$txn_id.""&#41;;
  $row = mysql_fetch_array&#40;$result&#41;;
  $prv_txn = $row&#91;0&#93;;

  return 0;
&#125;

// Проверка входящего запроса 'Pay', формирование ответа платежной системе
function cmd_pay&#40;$txn_id,$txn_date,$txn_account,$txn_sum&#41; &#123;
  global $prv_txn;
  str2log&#40;"Command cmd_pay for txn_id=$txn_id &#40;account='$txn_account' sum='$txn_sum'&#41; is requeresting"&#41;;
  $result = 500;
  // Проверка поля txn_id
  $result = txn_id_check&#40;$txn_id&#41;;
  if &#40;$result == 0&#41; &#123;
  // Проверка аккаунта
    $result = txn_account_check&#40;$txn_account&#41;;
    if &#40;$result == 0&#41; &#123;
  // Проверка допустимости суммы
      $result = txn_sum_check&#40;$txn_sum&#41;;
       if &#40;$result == 0&#41; &#123;
  // Проверка допустимости суммы
        $result = txn_date_check&#40;$txn_date&#41;;
       &#125;
    &#125;
  &#125;
  if &#40;$result==0&#41; &#123;
  // Внесение информации о платеже в таблицу транзакций
    $result = dopayment&#40;$txn_id,$txn_date,$txn_account,$txn_sum&#41;;
  &#125;
  // Комментарий по коду завершения операции
  switch &#40;$result&#41;&#123;
    case "0"&#58; $comment = "ОК"; break;
    case "1"&#58; $comment = "Temporaly error. Try again later"; break;
    case "4"&#58; $comment = "Wrong id format"; break;
    case "5"&#58; $comment = "Account not found"; break;
    case "7"&#58; $comment = "Pay is denied by provider"; break;
    case "8"&#58; $comment = "Pay is denied by technical reason"; break;
    case "79"&#58; $comment = "Account is not active"; break;
    case "241"&#58; $comment = "Sum is very small"; break;
    case "242"&#58; $comment = "Sum is very large"; break;
    case "243"&#58; $comment = ""; break;
    case "300"&#58; $comment = "Other error"; break;
    default&#58; $comment = ""; break;
  &#125;
  // Формирование ответа платежной системе
  $response_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                 ."<response>\n"
                 ."<osmp_txn_id>$txn_id</osmp_txn_id>\n"
                 ."<prv_txn>$prv_txn</prv_txn>\n"
                 ."<result>$result</result>\n";
  if &#40;$result>0 and $comment<>""&#41; &#123; $response_str.= "<comment>$comment</comment>\n"; &#125;
  $response_str.= "</response>\n";

  if &#40;$result==0&#41; &#123; str2log&#40;"Payment for txn_id=$txn_id &#40;account='$txn_account' sum='$txn_sum'&#41; is successfuly done"&#41;; &#125;
    else &#123; str2log&#40;"Payment for txn_id=$txn_id is unsuccessfuly. Error code &#91;$result&#93; $comment"&#41;; &#125;

  echo "$response_str";
&#125;

$txn_command = $_GET&#91;'command'&#93;;
$txn_id = $_GET&#91;'txn_id'&#93;;
$txn_account = $_GET&#91;'account'&#93;;
$txn_date = $_GET&#91;'date'&#93;;
$txn_sum = $_GET&#91;'sum'&#93;;

switch &#40;$txn_command&#41;&#123;
  case "check"&#58;
    cmd_check&#40;$txn_id,$txn_account,$txn_sum&#41;;
    break;
  case "pay"&#58;
    cmd_pay&#40;$txn_id,$txn_date,$txn_account,$txn_sum&#41;;
    break;
  default&#58;
    // Формирование ответа платежной системе при неверном запросе
    $response_str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                   ."<response>\n"
                   ."<osmp_txn_id></osmp_txn_id>\n"
                   ."<result>300</result>\n"
                   ."<comment>Incomplete request</comment>\n"
                   ."</response>\n";
    str2log&#40;"Error. Code &#91;300&#93; Incomlete request"&#41;;
    echo "$response_str";
    break;
&#125;
?>

Oleg_121
Сообщения: 81
Зарегистрирован: Пн апр 14, 2008 21:09

Сообщение Oleg_121 »

Скрипт сначала проверяет правильность транзакции а потом зачисляет деньги используя урфу. Сначала идут проверки где описанны коды ошибок. Можно использовать только кусок прверки на ошибки :)

Закрыто