Revision 350
- Date:
- 2013/05/22 17:41:46
- Files:
-
- /utf8/plugins/monetaru/comps/www/monetaru/check.xml (Diff) (Checkout)
- /utf8/plugins/monetaru/comps/www/monetaru/pay.txt (Diff) (Checkout)
- /utf8/plugins/monetaru/comps/www/monetaru/pay.xml (Diff) (Checkout)
- /utf8/plugins/monetaru/lib/monetaru/Init.pm (Diff) (Checkout)
- /utf8/plugins/monetaru/lib/monetaru/Keeper.pm (Diff) (Checkout)
- /utf8/plugins/monetaru/lib/monetaru/Operation.pm (Diff) (Checkout)
- /utf8/plugins/monetaru/lib/monetaru/SQL/OperationsTable.pm (Diff) (Checkout)
- /utf8/plugins/monetaru/sql/TOAST/operations.sql (Diff) (Checkout)
Legend:
- Added
- Removed
- Modified
-
utf8/plugins/monetaru/comps/www/monetaru/check.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <MNT_RESPONSE> 3 <MNT_ID><% $MNT_ID %></MNT_ID> 4 <MNT_TRANSACTION_ID><% $MNT_TRANSACTION_ID %></MNT_TRANSACTION_ID> 5 <MNT_RESULT_CODE><% $reply_code %></MNT_RESULT_CODE> 6 % if ( ref $last ) { 7 <MNT_DESCRIPTION><% $last->name %></MNT_DESCRIPTION> 8 % } 9 <MNT_AMOUNT><% $MNT_AMOUNT %></MNT_AMOUNT> 10 <MNT_SIGNATURE><% $reply_md5 %></MNT_SIGNATURE> 11 <%doc> 12 <MNT_ATTRIBUTES> 13 <ATTRIBUTE> 14 <KEY></KEY> 15 <VALUE></VALUE> 16 </ATTRIBUTE> 17 </MNT_ATTRIBUTES> 18 </%doc> 19 </MNT_RESPONSE> 20 <%once> 21 22 use Digest::MD5; 23 24 </%once> 25 <%args> 26 27 $MNT_COMMAND => '' 28 $MNT_ID => undef 29 $MNT_TRANSACTION_ID => undef 30 $MNT_OPERATION_ID => '' 31 $MNT_AMOUNT => '' 32 $MNT_CURRENCY_CODE => undef 33 $MNT_TEST_MODE => 0 34 $MNT_SIGNATURE => undef 35 $MNT_USER => undef 36 $MNT_CORRACCOUNT => undef 37 $MNT_CUSTOM1 => undef 38 $MNT_CUSTOM2 => undef 39 $MNT_CUSTOM3 => undef 40 41 </%args> 42 <%init> 43 44 warn Dumper \%ARGS if $DEBUG; 45 unless ( $MNT_ID && $MNT_TRANSACTION_ID && $MNT_OPERATION_ID && $MNT_AMOUNT && $MNT_CURRENCY_CODE ) { 46 $m->out('FAIL'); 47 return; 48 } 49 50 my $str = $MNT_COMMAND . $MNT_ID . $MNT_TRANSACTION_ID . $MNT_OPERATION_ID . $MNT_AMOUNT . $MNT_CURRENCY_CODE . $MNT_TEST_MODE . $state->{monetaru}->{moneta_sig_code}; 51 my $md5 = Digest::MD5::md5_hex ( $str ); 52 unless ( $MNT_SIGNATURE eq $md5 ) { 53 $m->out('FAIL'); 54 return; 55 } 56 57 my $reply_code; 58 my $last = $keeper->{monetaru}->check( $MNT_TRANSACTION_ID ); 59 if ( ref $last ) { 60 my $sum = sprintf("%.2f", $last->sum); 61 if ( $last->name eq 'cancel' ) { 62 $reply_code = 500; 63 } elsif ( !$MNT_AMOUNT && $last->name =~ /(create|reform)/ ) { 64 $MNT_AMOUNT = $last->sum; 65 $reply_code = 100; 66 } elsif ( $last->name =~ /(create|reform)/ && $sum ne $MNT_AMOUNT ) { 67 $MNT_AMOUNT = $last->sum; 68 $reply_code = 100; 69 } elsif ( $last->name eq 'suspend' ) { 70 $reply_code = 302; 71 } 72 } else { 73 $reply_code = 500; 74 } 75 76 unless ( $reply_code ) { 77 my ($obj) = $keeper->get_documents( 78 class => 'monetaru::Transaction', 79 operation_id => $MNT_OPERATION_ID, 80 order_id => $MNT_TRANSACTION_ID, 81 limit => 1, 82 ); 83 if ( ref $obj ) { 84 $reply_code = 200; 85 } else { 86 $reply_code = 402; 87 } 88 } 89 warn "CHECK_URL: Reply code = [$reply_code]\n" if $DEBUG; 90 91 $str = $reply_code . $MNT_ID . $MNT_TRANSACTION_ID . $state->{monetaru}->{moneta_sig_code}; 92 my $reply_md5 = Digest::MD5::md5_hex ( $str ); 93 94 </%init> -
utf8/plugins/monetaru/comps/www/monetaru/pay.txt
1 SUCCESS 2 <%once> 3 4 use Digest::MD5; 5 6 </%once> 7 <%args> 8 9 $MNT_ID => undef 10 $MNT_TRANSACTION_ID => undef 11 $MNT_OPERATION_ID => undef 12 $MNT_AMOUNT => 0 13 $MNT_CURRENCY_CODE => undef 14 $MNT_TEST_MODE => 0 15 $MNT_SIGNATURE => undef 16 $MNT_USER => undef 17 $MNT_CORRACCOUNT => undef 18 $MNT_CUSTOM1 => undef 19 $MNT_CUSTOM2 => undef 20 $MNT_CUSTOM3 => undef 21 22 </%args> 23 <%init> 24 25 warn Dumper \%ARGS if $DEBUG; 26 unless ( $MNT_ID && $MNT_TRANSACTION_ID && $MNT_OPERATION_ID && $MNT_AMOUNT && $MNT_CURRENCY_CODE ) { 27 $m->out('FAIL'); 28 return; 29 } 30 31 my ($obj) = $keeper->get_documents( 32 class => 'monetaru::Transaction', 33 operation_id => $MNT_OPERATION_ID, 34 order_id => $MNT_TRANSACTION_ID, 35 limit => 1, 36 ); 37 my $str = $MNT_ID . $MNT_TRANSACTION_ID . $MNT_OPERATION_ID . $MNT_AMOUNT . $MNT_CURRENCY_CODE . $MNT_TEST_MODE . $state->{monetaru}->{moneta_sig_code}; 38 my $md5 = Digest::MD5::md5_hex ( $str ); 39 unless ( $MNT_SIGNATURE eq $md5 ) { 40 $m->out('FAIL'); 41 return; 42 } 43 44 unless ( $obj ) { 45 $obj = monetaru::Transaction->new( $keeper ); 46 $obj->status( $MNT_TEST_MODE || 0 ); 47 $obj->account_id( $MNT_ID ); 48 $obj->order_id( $MNT_TRANSACTION_ID ); 49 $obj->operation_id( $MNT_OPERATION_ID ); 50 $obj->sum( $MNT_AMOUNT ); 51 $obj->currency_code( $MNT_CURRENCY_CODE ); 52 $obj->account_user( $MNT_USER ); 53 $obj->account_corr( $MNT_CORRACCOUNT ); 54 $obj->payment_system( $ARGS{'paymentSystem.unitId'} ); 55 $obj->name( $MNT_CUSTOM1 ); 56 $obj->custom1( $MNT_CUSTOM1 ); 57 $obj->custom2( $MNT_CUSTOM2 ); 58 $obj->custom3( $MNT_CUSTOM3 ); 59 $obj->store; 60 } 61 62 </%init> -
utf8/plugins/monetaru/comps/www/monetaru/pay.xml
1 SUCCESS 1 <?xml version="1.0" encoding="UTF-8"?> 2 <MNT_RESPONSE> 3 <MNT_ID><% $MNT_ID %></MNT_ID> 4 <MNT_TRANSACTION_ID><% $MNT_TRANSACTION_ID %></MNT_TRANSACTION_ID> 5 <MNT_RESULT_CODE><% $reply_code %></MNT_RESULT_CODE> 6 <MNT_SIGNATURE><% $reply_md5 %></MNT_SIGNATURE> 7 <%doc> 8 <MNT_ATTRIBUTES> 9 <ATTRIBUTE> 10 <KEY></KEY> 11 <VALUE></VALUE> 12 </ATTRIBUTE> 13 </MNT_ATTRIBUTES> 14 </%doc> 15 </MNT_RESPONSE> 2 16 <%once> 3 17 4 18 use Digest::MD5; … … 9 23 $MNT_ID => undef 10 24 $MNT_TRANSACTION_ID => undef 11 25 $MNT_OPERATION_ID => undef 12 $MNT_AMOUNT => 0 26 $MNT_AMOUNT => '' 13 27 $MNT_CURRENCY_CODE => undef 14 28 $MNT_TEST_MODE => 0 15 29 $MNT_SIGNATURE => undef … … 28 42 return; 29 43 } 30 44 31 my ($obj) = $keeper->get_documents( 32 class => 'monetaru::Transaction', 33 operation_id => $MNT_OPERATION_ID, 34 order_id => $MNT_TRANSACTION_ID, 35 limit => 1, 36 ); 37 45 my $str = $MNT_ID . $MNT_TRANSACTION_ID . $MNT_OPERATION_ID . $MNT_AMOUNT . $MNT_CURRENCY_CODE . $MNT_TEST_MODE . $state->{monetaru}->{moneta_sig_code}; 38 46 my $md5 = Digest::MD5::md5_hex ( $str ); 39 47 unless ( $MNT_SIGNATURE eq $md5 ) { … … 41 49 return; 42 50 } 43 51 44 unless ( $obj ) { 45 $obj = monetaru::Transaction->new( $keeper ); 46 $obj->status( $MNT_TEST_MODE || 0 ); 47 $obj->account_id( $MNT_ID ); 48 $obj->order_id( $MNT_TRANSACTION_ID ); 49 $obj->operation_id( $MNT_OPERATION_ID ); 50 $obj->sum( $MNT_AMOUNT ); 51 $obj->currency_code( $MNT_CURRENCY_CODE ); 52 $obj->account_user( $MNT_USER ); 53 $obj->account_corr( $MNT_CORRACCOUNT ); 54 $obj->payment_system( $ARGS{'paymentSystem.unitId'} ); 55 $obj->name( $MNT_CUSTOM1 ); 56 $obj->custom1( $MNT_CUSTOM1 ); 57 $obj->custom2( $MNT_CUSTOM2 ); 58 $obj->custom3( $MNT_CUSTOM3 ); 59 $obj->store; 52 my $reply_code; 53 my $last = $keeper->{monetaru}->check( $MNT_TRANSACTION_ID ); 54 if ( ref $last ) { 55 my $sum = sprintf("%.2f", $last->sum); 56 if ( $last->name eq 'cancel' ) { 57 $reply_code = 500; 58 } elsif ( $last->name eq 'suspend' ) { 59 $reply_code = 500; 60 } 61 } else { 62 $reply_code = 500; 60 63 } 61 64 65 unless ( $reply_code ) { 66 my ($obj) = $keeper->get_documents( 67 class => 'monetaru::Transaction', 68 operation_id => $MNT_OPERATION_ID, 69 order_id => $MNT_TRANSACTION_ID, 70 limit => 1, 71 ); 72 73 unless ( $obj ) { 74 $obj = monetaru::Transaction->new( $keeper ); 75 $obj->status( $MNT_TEST_MODE || 0 ); 76 $obj->account_id( $MNT_ID ); 77 $obj->order_id( $MNT_TRANSACTION_ID ); 78 $obj->operation_id( $MNT_OPERATION_ID ); 79 $obj->sum( $MNT_AMOUNT ); 80 $obj->currency_code( $MNT_CURRENCY_CODE ); 81 $obj->account_user( $MNT_USER ); 82 $obj->account_corr( $MNT_CORRACCOUNT ); 83 $obj->payment_system( $ARGS{'paymentSystem.unitId'} ); 84 $obj->name( $MNT_CUSTOM1 ); 85 $obj->custom1( $MNT_CUSTOM1 ); 86 $obj->custom2( $MNT_CUSTOM2 ); 87 $obj->custom3( $MNT_CUSTOM3 ); 88 $obj->store; 89 } 90 if ( $obj->id ) { 91 $reply_code = 200; 92 } else { 93 $reply_code = 100; 94 } 95 } 96 97 $str = $reply_code . $MNT_ID . $MNT_TRANSACTION_ID . $state->{monetaru}->{moneta_sig_code}; 98 my $reply_md5 = Digest::MD5::md5_hex ( $str ); 99 62 100 </%init> -
utf8/plugins/monetaru/lib/monetaru/Init.pm
15 15 monetaru::SQL::TransactionsTable 16 16 monetaru::Transaction 17 17 18 monetaru::SQL::OperationsTable 19 monetaru::Operation 20 18 21 monetaru::TransactionSection 19 22 )); 20 23 21 24 sub init { 22 push @{ $state->{'available_documents'} }, qw( monetaru::Transaction ); 25 push @{ $state->{'available_documents'} }, qw( monetaru::Transaction monetaru::Operation ); 23 26 push @{ $state->{'available_sections'} }, qw( monetaru::TransactionSection ); 24 27 0; 25 28 } -
utf8/plugins/monetaru/lib/monetaru/Keeper.pm
64 64 my $self = shift; 65 65 my (%opts) = @_; 66 66 67 return undef unless $opts{type} && $opts{uid} && $opts{order}; 68 return undef unless $opts{type} =~ /^(create|suspend|cancel)$/; 67 return undef unless $opts{type} && ( $opts{order} && ref $opts{order} eq 'webshop::Order' || $opts{uid} && $opts{order} && $opts{sum}); 68 return undef unless $opts{type} =~ /^(create|suspend|cancel|reform)$/; 69 69 70 70 my $op = monetaru::Operation->new( $keeper ); 71 71 $op->status(1); 72 72 $op->name( $opts{type} ); 73 $op->uid( $opts{uid} ); 74 $op->order_id( $opts{order} ); 73 if ( ref $opts{order} ) { 74 $op->uid( $opts{order}->uid ); 75 $op->order_id( $opts{order}->id ); 76 $op->sum( $opts{order}->sum_total ); 77 } else { 78 $op->uid( $opts{uid} ); 79 $op->order_id( $opts{order} ); 80 $op->sum( $opts{sum} ); 81 } 75 82 $op->store; 76 83 77 84 return $op; … … 81 88 sub check { 82 89 my $self = shift; 83 90 my $order_id = shift; 91 return undef unless $order_id; 84 92 85 return undef unless $order_id; 86 93 my $ops = $keeper->get_documents( 87 94 class => 'monetaru::Operation', 88 95 order_id => $order_id, 89 96 order_by => 'ctime', 90 97 return_mode => 'array_ref', 91 98 ); 92 if ( ref $ops eq 'ARRAY' && @$ops && $ops->[-1]->name =~ /^(create)$/ ) { 93 return 1; 94 } else { 95 return 0; 99 if ( ref $ops eq 'ARRAY' && @$ops ) { 100 return $ops->[-1]; 96 101 } 102 return undef; 97 103 } 98 104 99 105 1; -
utf8/plugins/monetaru/lib/monetaru/Operation.pm
7 7 { 'attr' => 'name', 'type' => 'status', 'rusname' => 'Тип операции', 8 8 'cases' => [ 9 9 ['create', 'Заказ создан'], 10 ['suspend', 'Оплата отложена'], 10 ['suspend', 'Заказ заморожен'], 11 ['reform', 'Заказ изменен'], 11 12 ['cancel', 'Заказ отменен'], 12 13 ], 13 14 }, … … 16 17 17 18 sub class_name 18 19 { 19 return 'Moneta.ru: операция'; 20 return 'Moneta.ru: операция с заказом'; 20 21 } 21 22 22 23 sub class_description 23 24 { 24 return 'Moneta.ru: внутренняя операция в магазине'; 25 return 'Moneta.ru: операция с заказом'; 25 26 } 26 27 27 28 sub class_table -
utf8/plugins/monetaru/lib/monetaru/SQL/OperationsTable.pm
66 66 'db_type' => 'integer', 67 67 'db_opts' => "not null", 68 68 }, 69 { 70 'attr' => 'sum', 71 'type' => 'string', 72 'rusname' => 'Сумма', 73 'db_field' => 'sum', 74 'db_type' => 'float', 75 }, 69 76 ); 70 77 } 71 78 -
utf8/plugins/monetaru/sql/TOAST/operations.sql
8 8 name text, 9 9 order_id integer not null, 10 10 uid integer not null, 11 sum float, 11 12 data text 12 13 ); 13 14 CREATE INDEX monetaru_operations_order ON monetaru_operations USING btree (order_id);