Revision 715
- Date:
- 2018/08/21 17:43:49
- Files:
Legend:
- Added
- Removed
- Modified
-
utf8/plugins/money/lib/money/Provider/Dreamkas.pm
53 53 $self->{provider} = $prefix; 54 54 $self->{app_id} = $state->{money}{$prefix."_app_id"}; 55 55 $self->{secret} = $state->{money}{$prefix."_app_secret"}; 56 $self->{token} = $state->{money}{$prefix."_app_token"}; 56 $self->{token} = $state->{money}{$prefix."_token"}; 57 57 $self->{tax_mode} = $state->{money}{$prefix."_tax_mode"}; 58 58 unless ( exists $TAX_MODES{$self->{tax_mode}} ) { 59 59 warn "Неверная мнемоника типа налоговой системы [".$self->{tax_mode}."]\n"; … … 110 110 Если в течение этого времени не удастся произвести фискализацию, 111 111 то операция будет отменена с ошибкой. 112 112 payment_type => CASH || CASHLESS 113 # или 114 payments => ARRAY_REF по стандарту примера 113 115 }); 114 116 115 117 JSON тела вызова: … … 172 174 $self->{result}{error} = 'Неверно указан тип операции'; 173 175 return $self; 174 176 } 175 $opts->{type} ||= 'SALE'; 177 $type ||= 'SALE'; 176 178 177 179 my $data = { 178 180 type => $type, … … 284 286 } 285 287 } 286 288 $data->{attributes} = $attributes; 289 } elsif ( exists $opts->{order} && exists $keeper->{users} ) { 290 my $profile = $keeper->{users}->get_profile( id => $opts->{order}->uid ); 291 if ( ref $profile ) { 292 my $email = $profile->email; 293 my $attributes = { email => "$email" }; 294 $data->{attributes} = $attributes; 295 } 287 296 } 288 297 289 298 # Заполняем параметры оплаты: total и payments … … 298 307 $self->{result}{error} = 'Не указана итоговая сумма. Необходимо передать параметр total или order'; 299 308 return $self; 300 309 } 301 $data->{payments}{sum} = $data->{total}{priceSum}; 302 310 $MR->sum( sprintf("%.2f", $data->{total}{priceSum} / 100) ); 303 if ( exists $opts->{payment_type} && $opts->{payment_type} eq 'CASH' ) { 304 $data->{payments}{type} = 'CASH'; 311 312 if ( exists $opts->{payments} && ref $opts->{payments} eq 'ARRAY' ) { 313 $data->{payments} = $opts->{payments}; 314 } else { 315 my $payment = {sum => $data->{total}{priceSum}}; 316 if ( exists $opts->{payment_type} ) { 317 $payment->{type} = $opts->{payment_type}; 318 } else { 319 $payment->{type} = 'CASHLESS'; 320 } 321 $data->{payments} = [$payment]; 305 322 } 306 323 307 324 my $api_url = 'receipts'; 308 325 326 warn "DREAMKAS receipt data: ".Data::Dumper::Dumper( $data ) if $DEBUG; 309 327 $self->_MakeRequest( $api_url, 'post', $data ); 310 328 warn Data::Dumper::Dumper( $self->{result} ) if $DEBUG; 311 329 if ( $self->{result}{code} == 202 || $self->{result}{code} == 200 ) { … … 402 420 $ua->agent('Mozilla/5.0'); 403 421 404 422 if ( exists $self->{token} && $self->{token} ) { 423 warn "Auth by token: ".$self->{token}."\n" if $DEBUG; 405 424 $ua->default_header( 'Authorization' => "Bearer ".$self->{token} ); 406 425 } elsif ( $self->{app_id} && $self->{secret} ) { 426 warn "Auth by app id: ".$self->{app_id}."|".$self->{secret}."\n" if $DEBUG; 407 427 my $auth = encode_base64($self->{app_id}.':'.$self->{secret}); 428 warn "base64: $auth\n" if $DEBUG; 408 429 $ua->default_header( 'Authorization' => "Application: {$auth}" ); 409 430 } 410 431 $ua->default_header( 'Content-Type' => 'application/json' ); … … 413 434 $body = encode_json( $body ); 414 435 } 415 436 416 my $req = URI->new( $self->{base_url}.($url =~ /^\// ? '' : '/').$url ); 437 my $uri = URI->new( $self->{base_url}.($url =~ /^\// ? '' : '/').$url ); 438 417 439 my $res; 418 440 if ( $type eq 'post' ) { 419 $res = $ua->post( $req, Content => $body ); 441 my $req = HTTP::Request->new(POST => $uri); 442 $req->content_type('application/json'); 443 $req->content($body); 444 warn "DREAMKAS post JSON: $body\n" if $DEBUG; 445 $res = $ua->request($req); 420 446 } elsif ( $type eq 'delete' ) { 421 $res = $ua->delete( $req ); 447 $res = $ua->delete( $uri ); 422 448 } else { 423 $res = $ua->get( $req ); 449 $res = $ua->get( $uri ); 424 450 } 425 451 $self->{result} = { 426 452 code => $res->code, 427 453 status => $res->status_line, 428 content => JSON::XS->new->utf8->decode( $res->decoded_content ), 454 content => Data::Recursive::Encode->encode_utf8( JSON::XS->new->utf8->decode( $res->decoded_content ) ), 429 455 }; 430 456 return $self; 431 457 }