Вот скрипт который работает у нас уже 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');