Skip to content

Commit f3234e1

Browse files
committed
MAGETWO-90761: [2.3.0] PayPal orders status display always as Processing
1 parent d3a849c commit f3234e1

File tree

3 files changed

+96
-108
lines changed

3 files changed

+96
-108
lines changed

app/code/Magento/Paypal/Model/Ipn.php

Lines changed: 65 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
namespace Magento\Paypal\Model;
88

99
use Exception;
10+
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;
1112
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
12-
use Magento\Paypal\Model\Info;
1313

1414
/**
1515
* PayPal Instant Payment Notification processor model
@@ -164,11 +164,11 @@ protected function _processOrder()
164164
case Info::TXN_TYPE_NEW_CASE:
165165
$this->_registerDispute();
166166
break;
167-
// handle new adjustment is created
167+
// handle new adjustment is created
168168
case Info::TXN_TYPE_ADJUSTMENT:
169169
$this->_registerAdjustment();
170170
break;
171-
//handle new transaction created
171+
//handle new transaction created
172172
default:
173173
$this->_registerTransaction();
174174
break;
@@ -239,16 +239,16 @@ protected function _registerTransaction()
239239
case Info::PAYMENTSTATUS_COMPLETED:
240240
$this->_registerPaymentCapture(true);
241241
break;
242-
// the holded payment was denied on paypal side
242+
// the holded payment was denied on paypal side
243243
case Info::PAYMENTSTATUS_DENIED:
244244
$this->_registerPaymentDenial();
245245
break;
246-
// customer attempted to pay via bank account, but failed
246+
// customer attempted to pay via bank account, but failed
247247
case Info::PAYMENTSTATUS_FAILED:
248248
// cancel order
249249
$this->_registerPaymentFailure();
250250
break;
251-
// payment was obtained, but money were not captured yet
251+
// payment was obtained, but money were not captured yet
252252
case Info::PAYMENTSTATUS_PENDING:
253253
$this->_registerPaymentPending();
254254
break;
@@ -263,7 +263,7 @@ protected function _registerTransaction()
263263
case Info::PAYMENTSTATUS_REFUNDED:
264264
$this->_registerPaymentRefund();
265265
break;
266-
// authorization expire/void
266+
// authorization expire/void
267267
case Info::PAYMENTSTATUS_EXPIRED:
268268
// break is intentionally omitted
269269
case Info::PAYMENTSTATUS_VOIDED:
@@ -288,24 +288,12 @@ protected function _registerPaymentCapture($skipFraudDetection = false)
288288
$parentTransactionId = $this->getRequestData('parent_txn_id');
289289
$this->_importPaymentInformation();
290290
$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);
309297
$payment->registerCaptureNotification(
310298
$this->getRequestData('mc_gross'),
311299
$skipFraudDetection && $parentTransactionId
@@ -318,9 +306,9 @@ protected function _registerPaymentCapture($skipFraudDetection = false)
318306
$this->orderSender->send($this->_order);
319307
$this->_order->addStatusHistoryComment(
320308
__('You notified customer about invoice #%1.', $invoice->getIncrementId())
321-
)->setIsCustomerNotified(
322-
true
323-
)->save();
309+
)
310+
->setIsCustomerNotified(true)
311+
->save();
324312
}
325313
}
326314

@@ -334,15 +322,13 @@ protected function _registerPaymentDenial()
334322
{
335323
try {
336324
$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);
344330
$this->_order->save();
345-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
331+
} catch (LocalizedException $e) {
346332
if ($e->getMessage() != __('We cannot cancel this order.')) {
347333
throw $e;
348334
}
@@ -386,13 +372,11 @@ public function _registerPaymentPending()
386372

387373
$this->_importPaymentInformation();
388374

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);
396380
$this->_order->save();
397381
}
398382

@@ -409,19 +393,12 @@ protected function _registerPaymentAuthorization()
409393
$payment->update(true);
410394
} else {
411395
$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'));
425402
}
426403
if (!$this->_order->getEmailSent()) {
427404
$this->orderSender->send($this->_order);
@@ -449,12 +426,13 @@ protected function _registerPaymentReversal()
449426
{
450427
$reasonCode = $this->getRequestData('reason_code');
451428
$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+
);
455433
$paymentStatus = $this->_filterPaymentStatus($this->getRequestData('payment_status'));
456434
$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;
458436
//Change order status to PayPal Reversed/PayPal Cancelled Reversal if it is possible.
459437
$message = __(
460438
'IPN "%1". %2 Transaction amount %3. Transaction ID: "%4"',
@@ -464,8 +442,9 @@ protected function _registerPaymentReversal()
464442
$this->getRequestData('txn_id')
465443
);
466444
$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();
469448
}
470449

471450
/**
@@ -478,17 +457,12 @@ protected function _registerPaymentRefund()
478457
$this->_importPaymentInformation();
479458
$reason = $this->getRequestData('reason_code');
480459
$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'));
492466
$this->_order->save();
493467

494468
// TODO: there is no way to close a capture right now
@@ -498,9 +472,9 @@ protected function _registerPaymentRefund()
498472
$this->creditmemoSender->send($creditMemo);
499473
$this->_order->addStatusHistoryComment(
500474
__('You notified customer about creditmemo #%1.', $creditMemo->getIncrementId())
501-
)->setIsCustomerNotified(
502-
true
503-
)->save();
475+
)
476+
->setIsCustomerNotified(true)
477+
->save();
504478
}
505479
}
506480

@@ -513,19 +487,14 @@ protected function _registerPaymentVoid()
513487
{
514488
$this->_importPaymentInformation();
515489

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');
523493

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();
529498

530499
$this->_order->save();
531500
}
@@ -546,14 +515,14 @@ protected function _importPaymentInformation()
546515
// collect basic information
547516
$from = [];
548517
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) {
557526
if (is_int($privateKey)) {
558527
$privateKey = $publicKey;
559528
}

app/code/Magento/Sales/Model/Order/Payment/State/RegisterCaptureNotificationCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(StatusResolver $statusResolver = null)
3535
*/
3636
public function execute(OrderPaymentInterface $payment, $amount, OrderInterface $order)
3737
{
38-
$state = Order::STATE_PROCESSING;
38+
$state = $order->getState() ?: Order::STATE_PROCESSING;
3939
$status = null;
4040
$message = 'Registered notification about captured amount of %1.';
4141

0 commit comments

Comments
 (0)