7
7
namespace Magento \Paypal \Model ;
8
8
9
9
use Exception ;
10
+ use Magento \Framework \Exception \LocalizedException ;
10
11
use Magento \Sales \Model \Order \Email \Sender \CreditmemoSender ;
11
12
use Magento \Sales \Model \Order \Email \Sender \OrderSender ;
12
- use Magento \Paypal \Model \Info ;
13
13
14
14
/**
15
15
* PayPal Instant Payment Notification processor model
@@ -164,11 +164,11 @@ protected function _processOrder()
164
164
case Info::TXN_TYPE_NEW_CASE :
165
165
$ this ->_registerDispute ();
166
166
break ;
167
- // handle new adjustment is created
167
+ // handle new adjustment is created
168
168
case Info::TXN_TYPE_ADJUSTMENT :
169
169
$ this ->_registerAdjustment ();
170
170
break ;
171
- //handle new transaction created
171
+ //handle new transaction created
172
172
default :
173
173
$ this ->_registerTransaction ();
174
174
break ;
@@ -239,16 +239,16 @@ protected function _registerTransaction()
239
239
case Info::PAYMENTSTATUS_COMPLETED :
240
240
$ this ->_registerPaymentCapture (true );
241
241
break ;
242
- // the holded payment was denied on paypal side
242
+ // the holded payment was denied on paypal side
243
243
case Info::PAYMENTSTATUS_DENIED :
244
244
$ this ->_registerPaymentDenial ();
245
245
break ;
246
- // customer attempted to pay via bank account, but failed
246
+ // customer attempted to pay via bank account, but failed
247
247
case Info::PAYMENTSTATUS_FAILED :
248
248
// cancel order
249
249
$ this ->_registerPaymentFailure ();
250
250
break ;
251
- // payment was obtained, but money were not captured yet
251
+ // payment was obtained, but money were not captured yet
252
252
case Info::PAYMENTSTATUS_PENDING :
253
253
$ this ->_registerPaymentPending ();
254
254
break ;
@@ -263,7 +263,7 @@ protected function _registerTransaction()
263
263
case Info::PAYMENTSTATUS_REFUNDED :
264
264
$ this ->_registerPaymentRefund ();
265
265
break ;
266
- // authorization expire/void
266
+ // authorization expire/void
267
267
case Info::PAYMENTSTATUS_EXPIRED :
268
268
// break is intentionally omitted
269
269
case Info::PAYMENTSTATUS_VOIDED :
@@ -288,24 +288,12 @@ protected function _registerPaymentCapture($skipFraudDetection = false)
288
288
$ parentTransactionId = $ this ->getRequestData ('parent_txn_id ' );
289
289
$ this ->_importPaymentInformation ();
290
290
$ payment = $ this ->_order ->getPayment ();
291
- $ payment ->setTransactionId (
292
- $ this ->getRequestData ('txn_id ' )
293
- );
294
- $ payment ->setCurrencyCode (
295
- $ this ->getRequestData ('mc_currency ' )
296
- );
297
- $ payment ->setPreparedMessage (
298
- $ this ->_createIpnComment ('' )
299
- );
300
- $ payment ->setParentTransactionId (
301
- $ parentTransactionId
302
- );
303
- $ payment ->setShouldCloseParentTransaction (
304
- 'Completed ' === $ this ->getRequestData ('auth_status ' )
305
- );
306
- $ payment ->setIsTransactionClosed (
307
- 0
308
- );
291
+ $ payment ->setTransactionId ($ this ->getRequestData ('txn_id ' ));
292
+ $ payment ->setCurrencyCode ($ this ->getRequestData ('mc_currency ' ));
293
+ $ payment ->setPreparedMessage ($ this ->_createIpnComment ('' ));
294
+ $ payment ->setParentTransactionId ($ parentTransactionId );
295
+ $ payment ->setShouldCloseParentTransaction ('Completed ' === $ this ->getRequestData ('auth_status ' ));
296
+ $ payment ->setIsTransactionClosed (0 );
309
297
$ payment ->registerCaptureNotification (
310
298
$ this ->getRequestData ('mc_gross ' ),
311
299
$ skipFraudDetection && $ parentTransactionId
@@ -318,9 +306,9 @@ protected function _registerPaymentCapture($skipFraudDetection = false)
318
306
$ this ->orderSender ->send ($ this ->_order );
319
307
$ this ->_order ->addStatusHistoryComment (
320
308
__ ('You notified customer about invoice #%1. ' , $ invoice ->getIncrementId ())
321
- )-> setIsCustomerNotified (
322
- true
323
- ) ->save ();
309
+ )
310
+ -> setIsCustomerNotified ( true )
311
+ ->save ();
324
312
}
325
313
}
326
314
@@ -334,15 +322,13 @@ protected function _registerPaymentDenial()
334
322
{
335
323
try {
336
324
$ this ->_importPaymentInformation ();
337
- $ this ->_order ->getPayment ()->setTransactionId (
338
- $ this ->getRequestData ('txn_id ' )
339
- )->setNotificationResult (
340
- true
341
- )->setIsTransactionClosed (
342
- true
343
- )->deny (false );
325
+ $ this ->_order ->getPayment ()
326
+ ->setTransactionId ($ this ->getRequestData ('txn_id ' ))
327
+ ->setNotificationResult (true )
328
+ ->setIsTransactionClosed (true )
329
+ ->deny (false );
344
330
$ this ->_order ->save ();
345
- } catch (\ Magento \ Framework \ Exception \ LocalizedException $ e ) {
331
+ } catch (LocalizedException $ e ) {
346
332
if ($ e ->getMessage () != __ ('We cannot cancel this order. ' )) {
347
333
throw $ e ;
348
334
}
@@ -386,13 +372,11 @@ public function _registerPaymentPending()
386
372
387
373
$ this ->_importPaymentInformation ();
388
374
389
- $ this ->_order ->getPayment ()->setPreparedMessage (
390
- $ this ->_createIpnComment ($ this ->_paypalInfo ->explainPendingReason ($ reason ))
391
- )->setTransactionId (
392
- $ this ->getRequestData ('txn_id ' )
393
- )->setIsTransactionClosed (
394
- 0
395
- )->update (false );
375
+ $ this ->_order ->getPayment ()
376
+ ->setPreparedMessage ($ this ->_createIpnComment ($ this ->_paypalInfo ->explainPendingReason ($ reason )))
377
+ ->setTransactionId ($ this ->getRequestData ('txn_id ' ))
378
+ ->setIsTransactionClosed (0 )
379
+ ->update (false );
396
380
$ this ->_order ->save ();
397
381
}
398
382
@@ -409,19 +393,12 @@ protected function _registerPaymentAuthorization()
409
393
$ payment ->update (true );
410
394
} else {
411
395
$ this ->_importPaymentInformation ();
412
- $ payment ->setPreparedMessage (
413
- $ this ->_createIpnComment ('' )
414
- )->setTransactionId (
415
- $ this ->getRequestData ('txn_id ' )
416
- )->setParentTransactionId (
417
- $ this ->getRequestData ('parent_txn_id ' )
418
- )->setCurrencyCode (
419
- $ this ->getRequestData ('mc_currency ' )
420
- )->setIsTransactionClosed (
421
- 0
422
- )->registerAuthorizationNotification (
423
- $ this ->getRequestData ('mc_gross ' )
424
- );
396
+ $ payment ->setPreparedMessage ($ this ->_createIpnComment ('' ))
397
+ ->setTransactionId ($ this ->getRequestData ('txn_id ' ))
398
+ ->setParentTransactionId ($ this ->getRequestData ('parent_txn_id ' ))
399
+ ->setCurrencyCode ($ this ->getRequestData ('mc_currency ' ))
400
+ ->setIsTransactionClosed (0 )
401
+ ->registerAuthorizationNotification ($ this ->getRequestData ('mc_gross ' ));
425
402
}
426
403
if (!$ this ->_order ->getEmailSent ()) {
427
404
$ this ->orderSender ->send ($ this ->_order );
@@ -449,12 +426,13 @@ protected function _registerPaymentReversal()
449
426
{
450
427
$ reasonCode = $ this ->getRequestData ('reason_code ' );
451
428
$ reasonComment = $ this ->_paypalInfo ->explainReasonCode ($ reasonCode );
452
- $ notificationAmount = $ this ->_order ->getBaseCurrency ()->formatTxt (
453
- $ this ->getRequestData ('mc_gross ' ) + $ this ->getRequestData ('mc_fee ' )
454
- );
429
+ $ notificationAmount = $ this ->_order ->getBaseCurrency ()
430
+ ->formatTxt (
431
+ $ this ->getRequestData ('mc_gross ' ) + $ this ->getRequestData ('mc_fee ' )
432
+ );
455
433
$ paymentStatus = $ this ->_filterPaymentStatus ($ this ->getRequestData ('payment_status ' ));
456
434
$ orderStatus = $ paymentStatus ==
457
- Info::PAYMENTSTATUS_REVERSED ? Info::ORDER_STATUS_REVERSED : Info::ORDER_STATUS_CANCELED_REVERSAL ;
435
+ Info::PAYMENTSTATUS_REVERSED ? Info::ORDER_STATUS_REVERSED : Info::ORDER_STATUS_CANCELED_REVERSAL ;
458
436
//Change order status to PayPal Reversed/PayPal Cancelled Reversal if it is possible.
459
437
$ message = __ (
460
438
'IPN "%1". %2 Transaction amount %3. Transaction ID: "%4" ' ,
@@ -464,8 +442,9 @@ protected function _registerPaymentReversal()
464
442
$ this ->getRequestData ('txn_id ' )
465
443
);
466
444
$ this ->_order ->setStatus ($ orderStatus );
467
- $ this ->_order ->save ();
468
- $ this ->_order ->addStatusHistoryComment ($ message , $ orderStatus )->setIsCustomerNotified (false )->save ();
445
+ $ this ->_order ->addStatusHistoryComment ($ message , $ orderStatus )
446
+ ->setIsCustomerNotified (false )
447
+ ->save ();
469
448
}
470
449
471
450
/**
@@ -478,17 +457,12 @@ protected function _registerPaymentRefund()
478
457
$ this ->_importPaymentInformation ();
479
458
$ reason = $ this ->getRequestData ('reason_code ' );
480
459
$ isRefundFinal = !$ this ->_paypalInfo ->isReversalDisputable ($ reason );
481
- $ payment = $ this ->_order ->getPayment ()->setPreparedMessage (
482
- $ this ->_createIpnComment ($ this ->_paypalInfo ->explainReasonCode ($ reason ))
483
- )->setTransactionId (
484
- $ this ->getRequestData ('txn_id ' )
485
- )->setParentTransactionId (
486
- $ this ->getRequestData ('parent_txn_id ' )
487
- )->setIsTransactionClosed (
488
- $ isRefundFinal
489
- )->registerRefundNotification (
490
- -1 * $ this ->getRequestData ('mc_gross ' )
491
- );
460
+ $ payment = $ this ->_order ->getPayment ()
461
+ ->setPreparedMessage ($ this ->_createIpnComment ($ this ->_paypalInfo ->explainReasonCode ($ reason )))
462
+ ->setTransactionId ($ this ->getRequestData ('txn_id ' ))
463
+ ->setParentTransactionId ($ this ->getRequestData ('parent_txn_id ' ))
464
+ ->setIsTransactionClosed ($ isRefundFinal )
465
+ ->registerRefundNotification (-1 * $ this ->getRequestData ('mc_gross ' ));
492
466
$ this ->_order ->save ();
493
467
494
468
// TODO: there is no way to close a capture right now
@@ -498,9 +472,9 @@ protected function _registerPaymentRefund()
498
472
$ this ->creditmemoSender ->send ($ creditMemo );
499
473
$ this ->_order ->addStatusHistoryComment (
500
474
__ ('You notified customer about creditmemo #%1. ' , $ creditMemo ->getIncrementId ())
501
- )-> setIsCustomerNotified (
502
- true
503
- ) ->save ();
475
+ )
476
+ -> setIsCustomerNotified ( true )
477
+ ->save ();
504
478
}
505
479
}
506
480
@@ -513,19 +487,14 @@ protected function _registerPaymentVoid()
513
487
{
514
488
$ this ->_importPaymentInformation ();
515
489
516
- $ parentTxnId = $ this ->getRequestData (
517
- 'transaction_entity '
518
- ) == 'auth ' ? $ this ->getRequestData (
519
- 'txn_id '
520
- ) : $ this ->getRequestData (
521
- 'parent_txn_id '
522
- );
490
+ $ parentTxnId = $ this ->getRequestData ('transaction_entity ' ) == 'auth '
491
+ ? $ this ->getRequestData ('txn_id ' )
492
+ : $ this ->getRequestData ('parent_txn_id ' );
523
493
524
- $ this ->_order ->getPayment ()->setPreparedMessage (
525
- $ this ->_createIpnComment ('' )
526
- )->setParentTransactionId (
527
- $ parentTxnId
528
- )->registerVoidNotification ();
494
+ $ this ->_order ->getPayment ()
495
+ ->setPreparedMessage ($ this ->_createIpnComment ('' ))
496
+ ->setParentTransactionId ($ parentTxnId )
497
+ ->registerVoidNotification ();
529
498
530
499
$ this ->_order ->save ();
531
500
}
@@ -546,14 +515,14 @@ protected function _importPaymentInformation()
546
515
// collect basic information
547
516
$ from = [];
548
517
foreach ([
549
- Info::PAYER_ID ,
550
- 'payer_email ' => Info::PAYER_EMAIL ,
551
- Info::PAYER_STATUS ,
552
- Info::ADDRESS_STATUS ,
553
- Info::PROTECTION_EL ,
554
- Info::PAYMENT_STATUS ,
555
- Info::PENDING_REASON ,
556
- ] as $ privateKey => $ publicKey ) {
518
+ Info::PAYER_ID ,
519
+ 'payer_email ' => Info::PAYER_EMAIL ,
520
+ Info::PAYER_STATUS ,
521
+ Info::ADDRESS_STATUS ,
522
+ Info::PROTECTION_EL ,
523
+ Info::PAYMENT_STATUS ,
524
+ Info::PENDING_REASON ,
525
+ ] as $ privateKey => $ publicKey ) {
557
526
if (is_int ($ privateKey )) {
558
527
$ privateKey = $ publicKey ;
559
528
}
0 commit comments