Skip to content

Commit

Permalink
move checks when ordeer is cancelled into same block
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko committed May 10, 2018
1 parent 5ef535f commit 759a095
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/Libraries/Payments/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,22 +217,22 @@ public function cancel()
$order = $this->getOrder();
$payment = $order->payments->where('cancelled', false)->first();

if ($payment === null && $order->status === 'cancelled') {
// payment not processed, manually cancelled - don't explode
// notify and bail out.
$this->dispatchErrorEvent(
new Exception('Order already cancelled with no existing payment found.'),
$order
);
if ($order->status === 'cancelled') {
if ($payment === null) {
// payment not processed, manually cancelled - don't explode
// notify and bail out.
$this->dispatchErrorEvent(
new Exception('Order already cancelled with no existing payment found.'),
$order
);

return;
}
return;
}

if ($order->status === 'cancelled') {
// check for pre-existing cancelled payment.
// Paypal sends multiple notifications that we treat as a cancellation.
$cancelled = $order->payments->where('cancelled', true)->first();
if ($cancelled !== null) {
// If the order is already cancelled and the payment cancelled, skip the rest.
if ($order->payments->where('cancelled', true)->first() !== null) {
$this->dispatchErrorEvent(
new Exception('Order already cancelled.'),
$order
Expand Down

0 comments on commit 759a095

Please sign in to comment.