Revision 691

Date:
2018/07/30 21:57:08
Author:
ahitrov
Revision Log:
Bug fixes

Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/plugins/payments/config.proto

     
    47 47 ############################################################
    48 48 # /payture.ru
    49 49
    50 # sberbank.ru
    51 ############################################################
    52 SBER_LOGIN =
    53 SBER_PASSWORD = 123
    54 SBER_TOKEN =
    55 SBER_RETURN_URL =
    56 SBER_FAIL_URL =
    57 SBER_SESSION_TIMEOUT_SECS = 1200 # Время в секундах, отводимое на оплату заказа
    58 SBER_CURRENCY_CODE = 643
    59 SBER_TEST_MODE = 1 # 0 - для боевого режима
    60
    61 # Авторизация логин-паролем или через токен. Два варианта:
    62 REWRITE += SBER_LOGIN SBER_PASSWORD SBER_RETURN_URL SBER_FAIL_URL SBER_TEST_MODE SBER_SESSION_TIMEOUT_SECS
    63 REWRITE += SBER_TOKEN SBER_RETURN_URL SBER_FAIL_URL SBER_TEST_MODE SBER_SESSION_TIMEOUT_SECS
    64 ############################################################
    65 # /sberbank.ru
    66
  • utf8/plugins/payments/lib/payments/Provider/Sber.pm

     
    22 22 $self->{app_id} = $state->{payments}{$prefix."_app_id"};
    23 23 $self->{secret} = $state->{payments}{$prefix."_app_secret"};
    24 24 $self->{token} = $state->{payments}{$prefix."_app_token"};
    25 $self->{session_timeout} = exists $params{session_timeout} ? $params{session_timeout} : $state->{payments}->{$prefix."_session_timeout"};
    25 26 $self->{test_mode} = exists $params{test_mode} ? $params{test_mode} : $state->{payments}->{$prefix."_test_mode"};
    26 27 $self->{return_url} = $params{return_url} || $state->{payments}{$prefix."_return_url"};
    27 28 $self->{fail_url} = $params{fail_url} || $state->{payments}{$prefix."_fail_url"};
     
    37 38 status => "$host/payment/rest/getOrderStatusExtended.do", # Получение статуса заказа
    38 39 is3ds => "$host/payment/rest/verifyEnrollment.do", # Запрос проверки вовлеченности карты в 3DS
    39 40 };
    40 $self->{return_url} =
    41 # $self->{return_url} = '';
    41 42
    42 43 $self->{result} = {};
    43 44
     
    93 94 if ( !exists $opts->{failUrl} && $self->{fail_url} ) {
    94 95 $opts->{failUrl} = $self->{fail_url};
    95 96 }
    97 if ( !exists $opts->{sessionTimeoutSecs} && $self->{session_timeout} ) {
    98 $opts->{sessionTimeoutSecs} = $self->{session_timeout};
    99 }
    96 100
    97 101 my $uid = delete $opts->{uid};
    98 102 unless ( $uid ) {
     
    114 118 $opts->{jsonParams}{uid} = $uid;
    115 119
    116 120 warn "Sberbank init args: ".Dumper($opts) if $DEBUG;
    117 my $operation = $self->payment_operation_register(
    121 my $operation = $self->payment_operation_register({
    118 122 order_id => $opts->{orderNumber},
    119 123 name => 'create',
    120 124 uid => $uid,
    121 125 sum => $opts->{amount},
    122 );
    126 });
    123 127 return $self unless ref $operation;
    124 128
    125 129 my $transaction = $self->get_transaction_by_order_id( $opts->{orderNumber} );
    126 if ( ref $transaction ) {
    130 if ( ref $transaction && $transaction->name eq 'Init' ) {
    127 131 ### Transaction already exists
    128 132 $self->{result}{success} = 1;
    129 133 $self->{result}{session_id} = $transaction->session_id;
    130 134 $self->{result}{transaction} = $transaction;
    131 135 } else {
    136 if ( ref $transaction && $transaction->name eq 'Expired' ) {
    137 $transaction->delete;
    138 }
    132 139 my $req = $self->_createRequestGet( $method, $opts );
    133 140 my $ua = LWP::UserAgent->new;
    134 141 $ua->agent('Mozilla/5.0');
    135 142 my $result = $ua->get( $req );
    136 143 if ( $result->code == 200 ) {
    137 144 warn "Sberbank Init result: [".$result->decoded_content."]\n" if $DEBUG;
    138 my $content = decode_json $result->decoded_content;
    145 my $content = JSON::XS->new->decode( $result->decoded_content );
    139 146 warn Dumper $content if $DEBUG;
    140 147
    141 148 if ( ref $content && exists $content->{orderId} ) {
    142 149 my $now = Contenido::DateTime->new;
    143 my $transaction = payments::Transaction->new( $keeper );
    150 $transaction = payments::Transaction->new( $keeper );
    144 151 $transaction->dtime( $now->ymd('-').' '.$now->hms );
    145 152 $transaction->provider( $self->{payment_system} );
    146 153 $transaction->session_id( $content->{orderId} );
     
    158 165 $self->{result}{session_id} = $content->{orderId};
    159 166 $self->{result}{transaction} = $transaction;
    160 167 } elsif ( ref $content && exists $content->{errorCode} && $content->{errorCode} ) {
    161 $self->{result}{error} = $content->{errorMessage};
    162 warn "[$content]\n";
    168 $self->{result}{error} = Encode::encode('utf-8', $content->{errorMessage});
    169 warn "[".$result->decoded_content."]\n";
    163 170 } else {
    164 171 $self->{result}{error} = 'Sberbank Init failed';
    165 $self->{result}{responce} = $content;
    172 $self->{result}{responce} = $result->decoded_content;
    166 173 warn $self->{result}{error}."\n";
    167 warn "[$content]\n";
    174 warn "[".$result->decoded_content."]\n";
    168 175 }
    169 176 } else {
    170 $self->{result}{error} = 'PayTure Init failed';
    177 $self->{result}{error} = 'Sberbank Init failed';
    171 178 $self->{result}{responce} = $result->status_line;
    172 179 warn $self->{result}{error}.": ".$result->status_line."\n";
    173 180 warn Dumper $result;
     
    217 224 my $self = shift;
    218 225 my $opts = shift // {};
    219 226
    220 unless ( %$opts && (exists $opts->{orderNumber} || exists $self->{result} && exists $self->{result}{transaction} && ref $self->{result}{transaction}) ) {
    227 unless ( exists $opts->{orderNumber} || exists $self->{result} && exists $self->{result}{transaction} && ref $self->{result}{transaction} ) {
    221 228 $self->{result}{error} = 'Не указан обязательный параметр orderNumber или не получена транзакция';
    222 229 return $self;
    223 230 }
     
    242 249 my $result = $ua->get( $req );
    243 250 my $return_data = {};
    244 251 if ( $result->code == 200 ) {
    245 warn "Sberbank Status result: [".$result->content."]\n" if $DEBUG;
    246 my $content = decode_json $result->decoded_content;
    252 warn "Sberbank Status: [".$result->decoded_content."]\n" if $DEBUG;
    253 my $content = JSON::XS->new->decode( $result->decoded_content );
    247 254 warn Dumper $content if $DEBUG;
    248 255
    249 if ( ref $content && exists $content->{orderStatus} && exists $content->{orderId} ) {
    256 if ( ref $content && exists $content->{orderStatus} && exists $content->{orderNumber} ) {
    250 257 $self->{result} = {
    251 258 success => 1,
    252 259 status => $content->{orderStatus},
    253 260 action => $content->{actionCode},
    254 action_description => $content->{actionCodeDescription},
    261 action_description => Encode::encode('utf-8', $content->{actionCodeDescription}),
    255 262 amount => $content->{amount},
    256 263 time_ms => $content->{date},
    257 264 ip => $content->{ip},
     
    259 266 };
    260 267 } elsif ( ref $content && exists $content->{errorCode} && $content->{errorCode} ) {
    261 268 $self->{result}{error} = $content->{errorMessage};
    262 warn "[$content]\n";
    269 warn "[".$result->decoded_content."]\n";
    263 270 } else {
    264 271 $self->{result}{error} = 'Sberbank Status failed';
    265 $self->{result}{responce} = $content;
    272 $self->{result}{responce} = $result->decoded_content;
    266 273 warn $self->{result}{error}."\n";
    267 warn "[$content]\n";
    274 warn "[".$result->decoded_content."]\n";
    268 275 }
    269 276 } else {
    270 277 $self->{result}{error} = 'Sberbank Status failed';
     
    318 325 }
    319 326
    320 327 warn "Sberbank refund args: ".Dumper($opts) if $DEBUG;
    321 my $operation = $self->payment_operation_register(
    328 my $operation = $self->payment_operation_register({
    322 329 order_id => $opts->{orderNumber},
    323 330 name => 'refund',
    324 331 uid => $uid,
    325 332 sum => $opts->{amount},
    326 );
    333 });
    327 334 return $self unless ref $operation;
    328 335
    329 336 my $transaction = $self->get_transaction_by_order_id( $opts->{orderNumber} );
     
    336 343 my $result = $ua->get( $req );
    337 344 if ( $result->code == 200 ) {
    338 345 warn "Sberbank Refund result: [".$result->decoded_content."]\n" if $DEBUG;
    339 my $content = decode_json $result->decoded_content;
    346 my $content = JSON::XS->new->decode( $result->decoded_content );
    340 347 warn Dumper $content if $DEBUG;
    341 348
    342 349 if ( ref $content && exists $content->{orderId} ) {
     
    358 365 $self->{result}{session_id} = $content->{orderId};
    359 366 $self->{result}{transaction} = $transaction;
    360 367 } elsif ( ref $content && exists $content->{errorCode} && $content->{errorCode} ) {
    361 $self->{result}{error} = $content->{errorMessage};
    362 warn "[$content]\n";
    368 $self->{result}{error} = Encode::encode('utf-8', $content->{errorMessage});
    369 warn "[".$result->decoded_content."]\n";
    363 370 } else {
    364 371 $self->{result}{error} = 'Sberbank Refund failed';
    365 $self->{result}{responce} = $content;
    372 $self->{result}{responce} = $result->decoded_content;
    366 373 warn $self->{result}{error}."\n";
    367 warn "[$content]\n";
    374 warn "[".$result->decoded_content."]\n";
    368 375 }
    369 376 } else {
    370 $self->{result}{error} = 'PayTure Init failed';
    377 $self->{result}{error} = 'Sberbank Refund failed';
    371 378 $self->{result}{responce} = $result->status_line;
    372 379 warn $self->{result}{error}.": ".$result->status_line."\n";
    373 380 warn Dumper $result;
  • utf8/plugins/payments/lib/payments/State.pm.proto

     
    84 84 $self->{sber_app_token} = '@SBER_TOKEN@';
    85 85 $self->{sber_return_url} = '@SBER_RETURN_URL@';
    86 86 $self->{sber_fail_url} = '@SBER_FAIL_URL@';
    87 $self->{sber_session_timeout} = int('@SBER_SESSION_TIMEOUT_SECS@' || 0);
    87 88 $self->{sber_test_mode} = int('@SBER_TEST_MODE@' || 0);
    88 89 $self->{sber_currency_code} = int('@SBER_CURRENCY_CODE@' || 643);
    89 90