Revision 701

Date:
2018/08/15 22:05:14
Author:
ahitrov
Revision Log:
check -> receipt

Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/money/lib/money/Check.pm

     
    1 package money::Check;
    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 )
    14 }
    15
    16 sub class_name
    17 {
    18 return 'Money: онлайн-чек';
    19 }
    20
    21 sub class_description
    22 {
    23 return 'Money: онлайн-чек';
    24 }
    25
    26 sub class_table
    27 {
    28 return 'money::SQL::ChecksTable';
    29 }
    30
    31 1;
  • utf8/plugins/money/lib/money/Provider/Dreamkas.pm

     
    187 187 }
    188 188 }
    189 189
    190 my $MM;
    190 my $MR;
    191 191 if ( exists $opts->{order} ) {
    192 $MM = $self->_GetLastMoneyCheck( $opts->{order}->id );
    192 $MR = $self->_GetLastMoneyReceipt( $opts->{order}->id );
    193 193 }
    194 if ( ref $MM && $MM->session_id && $MM->name eq $opts->{type} ) {
    195 $self->{result}{money_check} = $MM;
    194 if ( ref $MR && $MR->session_id && $MR->name eq $opts->{type} ) {
    195 $self->{result}{receipt} = $MR;
    196 196 return $self;
    197 197 }
    198 unless ( $MM ) {
    199 $MM = money::Check->new( $keeper );
    200 $MM->name( $opts->{type} );
    201 $MM->provider( $self->{prefix} );
    202 $MM->status( $self->{test_mode} );
    203 $MM->success( 0 );
    198 unless ( $MR ) {
    199 $MR = money::Receipt->new( $keeper );
    200 $MR->name( $opts->{type} );
    201 $MR->provider( $self->{prefix} );
    202 $MR->status( $self->{test_mode} );
    203 $MR->success( 0 );
    204 204 if ( ref $opts->{order} ) {
    205 $MM->order_id( $opts->{order}->id );
    205 $MR->order_id( $opts->{order}->id );
    206 206 }
    207 $MM->currency_code( $self->{currency} );
    207 $MR->currency_code( $self->{currency} );
    208 208 }
    209 209
    210 210 if ( exists $opts->{order} && !exists $opts->{basket} ) {
     
    281 281 return $self;
    282 282 }
    283 283 $data->{payments}{sum} = $data->{total}{priceSum};
    284 $MM->sum( $data->{total}{priceSum} );
    284 $MR->sum( $data->{total}{priceSum} );
    285 285 if ( exists $opts->{payment_type} && $opts->{payment_type} eq 'CASH' ) {
    286 286 $data->{payments}{type} = 'CASH';
    287 287 }
     
    290 290
    291 291 $self->_MakeRequest( $api_url, 'post', $data );
    292 292 if ( $self->{result}{code} == 202 || $self->{result}{code} == 200 ) {
    293 $MM->success( $OP_STATUS{$self->{result}{content}{status}} );
    294 $MM->session_id( $self->{result}{content}{id} );
    295 $MM->store;
    296 $self->{result}{money_check} = $MM;
    293 $MR->success( $OP_STATUS{$self->{result}{content}{status}} );
    294 $MR->session_id( $self->{result}{content}{id} );
    295 $MR->store;
    296 $self->{result}{receipt} = $MR;
    297 297 } else {
    298 298 $self->{result}{error} = $self->{result}{status};
    299 299 }
     
    340 340 return $self;
    341 341 }
    342 342
    343 my $MM;
    344 if ( exists $self->{result}{money_check} ) {
    345 $MM = $self->{result}{money_check};
    346 } elsif ( exists $opts->{money_check} ) {
    347 $MM = $opts->{money_check};
    343 my $MR;
    344 if ( exists $self->{result}{receipt} ) {
    345 $MR = $self->{result}{receipt};
    346 } elsif ( exists $opts->{receipt} ) {
    347 $MR = $opts->{receipt};
    348 348 } elsif ( $opts->{operation_id} ) {
    349 ($MM) = $self->_GetCheckByOperationId( $opts->{operation_id} );
    349 ($MR) = $self->_GetReceiptByOperationId( $opts->{operation_id} );
    350 350 }
    351 unless ( ref $MM ) {
    351 unless ( ref $MR ) {
    352 352 $self->{result}{error} = 'Не найден объект "движение денежных средств". Проверьте входные параметры';
    353 353 return $self;
    354 354 }
    355 355
    356 my $api_url = 'operations/'.$MM->session_id;
    356 my $api_url = 'operations/'.$MR->session_id;
    357 357
    358 358 $self->_MakeRequest( $api_url, 'get' );
    359 359 if ( $self->{result}{code} == 200 ) {
    360 $MM->success( $OP_STATUS{$self->{result}{content}{status}} );
    361 $MM->store;
    362 $self->{result}{money_check} = $MM;
    360 $MR->success( $OP_STATUS{$self->{result}{content}{status}} );
    361 $MR->store;
    362 $self->{result}{receipt} = $MR;
    363 363 if ( $self->{result}{content}{status} eq 'ERROR' ) {
    364 364 $self->{result}{error} = $self->{result}{content}{data}{error}{message};
    365 365 $self->{result}{code} = $self->{result}{content}{data}{error}{code};
     
    409 409 return $self;
    410 410 }
    411 411
    412 sub _GetLastMoneyCheck {
    412 sub _GetLastMoneyReceipt {
    413 413 my $self = shift;
    414 414 my $order_id = shift;
    415 415 my ($mm) = $keeper->get_documents(
    416 class => 'money::Check',
    416 class => 'money::Receipt',
    417 417 limit => 1,
    418 418 provider => $self->{prefix},
    419 419 order_id => $order_id,
     
    422 422 return $mm;
    423 423 }
    424 424
    425 sub _GetCheckByOperationId {
    425 sub _GetReceiptByOperationId {
    426 426 my $self = shift;
    427 427 my $op_id = shift;
    428 428 my ($mm) = $keeper->get_documents(
    429 class => 'money::Check',
    429 class => 'money::Receipt',
    430 430 limit => 1,
    431 431 provider => $self->{prefix},
    432 432 session_id => $op_id,
  • utf8/plugins/money/lib/money/Receipt.pm

     
    1 package money::Receipt;
    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 )
    14 }
    15
    16 sub class_name
    17 {
    18 return 'Money: онлайн-чек';
    19 }
    20
    21 sub class_description
    22 {
    23 return 'Money: онлайн-чек';
    24 }
    25
    26 sub class_table
    27 {
    28 return 'money::SQL::ReceiptsTable';
    29 }
    30
    31 1;
  • utf8/plugins/money/lib/money/SQL/ChecksTable.pm

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

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

     
    1 create sequence money_checks_id_seq;
    2 select setval('money_checks_id_seq', 1, true);
    3
    4 create table money_checks
    5 (
    6 id integer not null primary key default nextval('public.money_checks_id_seq'::text),
    7 class text not null,
    8 ctime timestamp not null default now(),
    9 mtime timestamp not null default now(),
    10 dtime timestamp not null default now(),
    11 status smallint not null default 0,
    12 provider text,
    13 session_id text,
    14 name text,
    15 order_id integer not null,
    16 currency_code varchar(4),
    17 sum float,
    18 success smallint default 0,
    19 data text
    20 );
    21 CREATE INDEX money_checks_sessions ON money_checks USING btree (provider, session_id) WHERE session_id is not null;
    22 CREATE INDEX money_checks_orders ON money_checks USING btree (order_id);
  • utf8/plugins/money/sql/TOAST/money_receipt.sql

     
    1 create sequence money_receipts_id_seq;
    2 select setval('money_receipts_id_seq', 1, true);
    3
    4 create table money_receipts
    5 (
    6 id integer not null primary key default nextval('public.money_receipts_id_seq'::text),
    7 class text not null,
    8 ctime timestamp not null default now(),
    9 mtime timestamp not null default now(),
    10 dtime timestamp not null default now(),
    11 status smallint not null default 0,
    12 provider text,
    13 session_id text,
    14 name text,
    15 order_id integer not null,
    16 currency_code varchar(4),
    17 sum float,
    18 success smallint default 0,
    19 data text
    20 );
    21 CREATE INDEX money_receipts_sessions ON money_receipts USING btree (provider, session_id) WHERE session_id is not null;
    22 CREATE INDEX money_receipts_orders ON money_receipts USING btree (order_id);