From 10fd839c78ee57f71adf192822adf1145b90a317 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 14 Sep 2017 11:38:54 +0300 Subject: [PATCH] Check if referral payments have been refunded --- app/Console/Commands/CalculatePayouts.php | 3 ++- app/Models/Payment.php | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/CalculatePayouts.php b/app/Console/Commands/CalculatePayouts.php index 869783dc8ad3..673b1d89f869 100644 --- a/app/Console/Commands/CalculatePayouts.php +++ b/app/Console/Commands/CalculatePayouts.php @@ -74,7 +74,8 @@ class CalculatePayouts extends Command $this->info("User: $user"); foreach ($client->payments as $payment) { - $this->info("Date: $payment->payment_date, Amount: $payment->amount, Reference: $payment->transaction_reference"); + $amount = $payment->getCompletedAmount(); + $this->info("Date: $payment->payment_date, Amount: $amount, Reference: $payment->transaction_reference"); } } } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index e1556b7d6046..0fc6da08eda2 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -295,6 +295,10 @@ class Payment extends EntityModel */ public function getCompletedAmount() { + if ($this->isFailed() || $this->isVoided()) { + return 0; + } + return $this->amount - $this->refunded; }