Revision 328

Date:
2013/05/01 19:15:26
Author:
ahitrov
Revision Log:
Transactions
Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/monetaru/comps/www/monetaru/pay.xml

     
    1 SUCCESS
    2 <%once>
    3
    4 use Digest::MD5;
    5
    6 </%once>
    1 7 <%args>
    2 8
    3 9 $MNT_ID => undef
     
    5 11 $MNT_OPERATION_ID => undef
    6 12 $MNT_AMOUNT => 0
    7 13 $MNT_CURRENCY_CODE => undef
    8 $MNT_TEST_MODE => undef
    14 $MNT_TEST_MODE => 0
    9 15 $MNT_SIGNATURE => undef
    10 16 $MNT_USER => undef
    11 17 $MNT_CORRACCOUNT => undef
     
    16 22 </%args>
    17 23 <%init>
    18 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 }
    19 30
    31 my ($obj) = $keeper->get_documents(
    32 class => 'monetaru::Transaction',
    33 operation_id => $MNT_OPERATION_ID,
    34 limit => 1,
    35 );
    36 my $str = $MNT_ID . $MNT_TRANSACTION_ID . $MNT_OPERATION_ID . $MNT_AMOUNT . $MNT_CURRENCY_CODE . $MNT_TEST_MODE . $state->{monetaru}->{moneta_sig_code};
    37 my $md5 = Digest::MD5::md5_hex ( $str );
    38 unless ( $MNT_SIGNATURE eq $md5 ) {
    39 $m->out('FAIL');
    40 return;
    41 }
    20 42
    43 unless ( $obj ) {
    44 $obj = monetaru::Transaction->new( $keeper );
    45 $obj->status( $MNT_TEST_MODE || 0 );
    46 $obj->account_id( $MNT_ID );
    47 $obj->order_id( $MNT_TRANSACTION_ID );
    48 $obj->operation_id( $MNT_OPERATION_ID );
    49 $obj->sum( $MNT_AMOUNT );
    50 $obj->currency_code( $MNT_CURRENCY_CODE );
    51 $obj->account_user( $MNT_USER );
    52 $obj->account_corr( $MNT_CORRACCOUNT );
    53 $obj->payment_system( $ARGS{'paymentSystem.unitId'} );
    54 $obj->name( $MNT_CUSTOM1 );
    55 $obj->custom1( $MNT_CUSTOM1 );
    56 $obj->custom2( $MNT_CUSTOM2 );
    57 $obj->custom3( $MNT_CUSTOM3 );
    58 $obj->store;
    59 }
    60
    21 61 </%init>
  • utf8/plugins/monetaru/lib/monetaru/Init.pm

     
    12 12 # monetaru::SQL::SomeTable
    13 13 # monetaru::SomeClass
    14 14 Contenido::Init::load_classes(qw(
    15 monetaru::SQL::TransactionsTable
    16 monetaru::Transaction
    17
    18 monetaru::TransactionSection
    15 19 ));
    16 20
    17 21 sub init {
    22 push @{ $state->{'available_documents'} }, qw( monetaru::Transaction );
    23 push @{ $state->{'available_sections'} }, qw( monetaru::TransactionSection );
    18 24 0;
    19 25 }
    20 26
  • utf8/plugins/monetaru/lib/monetaru/Keeper.pm

     
    6 6
    7 7 use Contenido::Globals;
    8 8 use Digest::MD5;
    9 use Data::Dumper;
    9 10
    10
    11 11 sub get_form {
    12 12 my $self = shift;
    13 13 my (%opts) = @_;
     
    41 41 push @{$fields{hidden}}, { name => 'MNT_FAIL_URL', value => $opts{fail} }
    42 42 }
    43 43 if ( $self->state->{moneta_sig_code} ) {
    44 my $md5 = Digest::MD5::md5_hex (
    45 $self->state->{moneta_app_id}.$id.$sum.$self->state->{moneta_currency_code}.$self->state->{moneta_test_mode}.$self->state->{moneta_sig_code}
    46 );
    44 my $str = $self->state->{moneta_app_id}.$id.$sum.$self->state->{moneta_currency_code}.$self->state->{moneta_test_mode}.$self->state->{moneta_sig_code};
    45 my $md5 = Digest::MD5::md5_hex ( $str );
    47 46 push @{$fields{hidden}}, { name => 'MNT_SIGNATURE', value => $md5 }
    48 47 }
    49 48
  • utf8/plugins/monetaru/lib/monetaru/SQL/TransactionsTable.pm

     
    1 package monetaru::SQL::TransactionsTable;
    2
    3 use base 'SQL::DocumentTable';
    4
    5 sub db_table
    6 {
    7 return 'monetaru_transactions';
    8 }
    9
    10
    11 sub available_filters {
    12 my @available_filters = qw(
    13
    14 _class_filter
    15 _status_filter
    16 _in_id_filter
    17 _id_filter
    18 _name_filter
    19 _class_excludes_filter
    20 _sfilter_filter
    21 _excludes_filter
    22 _datetime_filter
    23 _date_equal_filter
    24 _date_filter
    25 _previous_days_filter
    26
    27 _operation_id_filter
    28 _order_id_filter
    29 );
    30
    31 return \@available_filters;
    32 }
    33
    34 # ----------------------------------------------------------------------------
    35 # Свойства храним в массивах, потому что порядок важен!
    36 # Это общие свойства - одинаковые для всех документов.
    37 #
    38 # attr - обязательный параметр, название атрибута;
    39 # type - тип аттрибута, требуется для отображдения;
    40 # rusname - русское название, опять же требуется для отображения;
    41 # hidden - равен 1, когда
    42 # readonly - инициализации при записи только без изменения в дальнейшем
    43 # db_field - поле в таблице
    44 # default - значение по умолчанию (поле всегда имеет это значение)
    45 # ----------------------------------------------------------------------------
    46 sub required_properties
    47 {
    48 my $self = shift;
    49
    50 my @parent_properties = $self->SUPER::required_properties;
    51 return (
    52 @parent_properties,
    53 {
    54 'attr' => 'account_id',
    55 'type' => 'integer',
    56 'rusname' => 'Аккаунт',
    57 'db_field' => 'account_id',
    58 'db_type' => 'numeric',
    59 'db_opts' => "default 0",
    60 },
    61 { # ID заказа
    62 'attr' => 'order_id',
    63 'type' => 'integer',
    64 'rusname' => 'ID заказа',
    65 'db_field' => 'order_id',
    66 'db_type' => 'integer',
    67 'db_opts' => "not null",
    68 },
    69 { # ID заказа
    70 'attr' => 'operation_id',
    71 'type' => 'integer',
    72 'rusname' => 'ID транзакции',
    73 'db_field' => 'operation_id',
    74 'db_type' => 'numeric',
    75 'db_opts' => "not null",
    76 },
    77 {
    78 'attr' => 'currency_code',
    79 'type' => 'string',
    80 'rusname' => 'ID валюты',
    81 'db_field' => 'currency_code',
    82 'db_type' => 'varchar(4)',
    83 },
    84 {
    85 'attr' => 'sum',
    86 'type' => 'string',
    87 'rusname' => 'Сумма платежа',
    88 'db_field' => 'sum',
    89 'db_type' => 'float',
    90 },
    91 {
    92 'attr' => 'account_user',
    93 'type' => 'string',
    94 'rusname' => 'Номер счета пользователя',
    95 'db_field' => 'account_user',
    96 'db_type' => 'text',
    97 },
    98 {
    99 'attr' => 'account_corr',
    100 'type' => 'string',
    101 'rusname' => 'Номер счета плательщика',
    102 'db_field' => 'account_corr',
    103 'db_type' => 'text',
    104 },
    105 {
    106 'attr' => 'payment_system',
    107 'type' => 'string',
    108 'rusname' => 'Идентификатор платежной системы',
    109 'db_field' => 'payment_system',
    110 'db_type' => 'text',
    111 },
    112 );
    113 }
    114
    115
    116 ########### FILTERS DESCRIPTION ###############################################################################
    117 sub _operation_id_filter {
    118 my ($self,%opts)=@_;
    119 return undef unless ( exists $opts{operation_id} );
    120 return &SQL::Common::_generic_int_filter('d.operation_id', $opts{operation_id});
    121 }
    122
    123 sub _order_id_filter {
    124 my ($self,%opts)=@_;
    125 return undef unless ( exists $opts{order_id} );
    126 return &SQL::Common::_generic_int_filter('d.order_id', $opts{order_id});
    127 }
    128
    129 1;
  • utf8/plugins/monetaru/lib/monetaru/Transaction.pm

     
    1 package monetaru::Transaction;
    2
    3 use base "Contenido::Document";
    4 sub extra_properties
    5 {
    6 return (
    7 { 'attr' => 'status', 'type' => 'status', 'rusname' => 'Статус тестирования',
    8 'cases' => [
    9 [0, 'Реальная оплата'],
    10 [1, 'Тестовая оплата'],
    11 ],
    12 },
    13 { 'attr' => 'custom1', 'type' => 'string', 'rusname' => 'Параметр 1' },
    14 { 'attr' => 'custom2', 'type' => 'string', 'rusname' => 'Параметр 2' },
    15 { 'attr' => 'custom3', 'type' => 'string', 'rusname' => 'Параметр 3' },
    16 )
    17 }
    18
    19 sub class_name
    20 {
    21 return 'Moneta.ru: транзакция';
    22 }
    23
    24 sub class_description
    25 {
    26 return 'Moneta.ru: транзакция';
    27 }
    28
    29 sub class_table
    30 {
    31 return 'monetaru::SQL::TransactionsTable';
    32 }
    33
    34 1;
  • utf8/plugins/monetaru/lib/monetaru/TransactionSection.pm

     
    1 package monetaru::TransactionSection;
    2
    3 use base 'Contenido::Section';
    4
    5 sub extra_properties
    6 {
    7 return (
    8 { 'attr' => 'brief', 'type' => 'text', 'rusname' => 'Описание секции' },
    9 { 'attr' => 'default_document_class', 'default' => 'monetaru::Transaction' },
    10 { 'attr' => '_sorted', 'hidden' => 1 },
    11 { 'attr' => 'order_by', 'hidden' => 1 },
    12 )
    13 }
    14
    15 sub class_name
    16 {
    17 return 'Moneta.ru: Секция транзакций';
    18 }
    19
    20 sub class_description
    21 {
    22 return 'Moneta.ru: Секция транзакций';
    23 }
    24
    25 1;
  • utf8/plugins/monetaru/sql/TOAST/transactions.sql

     
    1 create table monetaru_transactions
    2 (
    3 id integer not null primary key default nextval('public.documents_id_seq'::text),
    4 class text not null,
    5 ctime timestamp not null default now(),
    6 mtime timestamp not null default now(),
    7 status smallint not null default 0,
    8 name text,
    9 account_id numeric,
    10 order_id integer not null,
    11 operation_id numeric not null,
    12 currency_code varchar(4),
    13 sum float,
    14 account_user text,
    15 payment_system text,
    16 account_corr text,
    17 data
    18 );
    19 CREATE INDEX monetaru_transactions_operations ON monetaru_transactions USING btree (operation_id);
    20 CREATE INDEX monetaru_transactions_orders ON monetaru_transactions USING btree (order_id);