Minor job cleanup, import Ezypay payments update
This commit is contained in:
@@ -2,11 +2,10 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Classes\External\Payments\Ezypay;
|
||||
use App\Models\{Account,Checkout,Payment};
|
||||
use App\Jobs\PaymentsImport as Job;
|
||||
|
||||
class PaymentsEzypayImport extends Command
|
||||
{
|
||||
@@ -24,16 +23,6 @@ class PaymentsEzypayImport extends Command
|
||||
*/
|
||||
protected $description = 'Retrieve payments from Ezypay';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
@@ -41,67 +30,6 @@ class PaymentsEzypayImport extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$poo = new Ezypay();
|
||||
|
||||
// Get our checkout IDs for this plugin
|
||||
$cos = Checkout::where('plugin',config('services.ezypay.plugin'))->pluck('id');
|
||||
|
||||
foreach ($poo->getCustomers() as $c)
|
||||
{
|
||||
if ($c->BillingStatus == 'Inactive')
|
||||
{
|
||||
$this->info(sprintf('Ignoring INACTIVE: [%s] %s %s',$c->EzypayReferenceNumber,$c->Firstname,$c->Surname));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Load Account Details from ReferenceId
|
||||
$ao = Account::where('site_id',(int)substr($c->ReferenceId,0,2))
|
||||
->where('id',(int)substr($c->ReferenceId,2,4))
|
||||
->first();
|
||||
|
||||
if (! $ao)
|
||||
{
|
||||
$this->warn(sprintf('Missing: [%s] %s %s (%s)',$c->EzypayReferenceNumber,$c->Firstname,$c->Surname,$c->ReferenceId));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find the last payment logged
|
||||
$last = Carbon::createFromTimestamp(Payment::whereIN('checkout_id',$cos)->where('account_id',$ao->id)->max('payment_date'));
|
||||
|
||||
$o = $poo->getDebits([
|
||||
'customerId'=>$c->Id,
|
||||
'dateFrom'=>$last->format('Y-m-d'),
|
||||
'dateTo'=>$last->addQuarter()->format('Y-m-d'),
|
||||
'pageSize'=>100,
|
||||
]);
|
||||
|
||||
// Load the payments
|
||||
if ($o->count())
|
||||
{
|
||||
foreach ($o->reverse() as $p)
|
||||
{
|
||||
// If not success, ignore it.
|
||||
if ($p->Status != 'Success')
|
||||
continue;
|
||||
|
||||
$pd = Carbon::createFromFormat('Y-m-d?H:i:s.u',$p->Date);
|
||||
$lp = $ao->payments->last();
|
||||
|
||||
if ($lp AND (($pd == $lp->payment_date) OR ($p->Id == $lp->checkout_data)))
|
||||
continue;
|
||||
|
||||
// New Payment
|
||||
$po = new Payment;
|
||||
$po->site_id = 1; // @todo
|
||||
$po->payment_date = $pd;
|
||||
$po->checkout_id = '999'; // @todo
|
||||
$po->checkout_data = $p->Id;
|
||||
$po->total_amt = $p->Amount;
|
||||
$ao->payments()->save($po);
|
||||
|
||||
$this->info(sprintf('Recorded: Payment for [%s] %s %s (%s) on %s',$c->EzypayReferenceNumber,$c->Firstname,$c->Surname,$po->id,$pd));
|
||||
}
|
||||
}
|
||||
}
|
||||
Job::dispatchSync(new Ezypay);
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Classes\External\Payments\Ezypay;
|
||||
@@ -23,16 +24,6 @@ class PaymentsEzypayNext extends Command
|
||||
*/
|
||||
protected $description = 'Load next payments, and ensure they cover the next invoice';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
@@ -40,12 +31,10 @@ class PaymentsEzypayNext extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$poo = new Ezypay();
|
||||
$poo = new Ezypay;
|
||||
|
||||
foreach ($poo->getCustomers() as $c)
|
||||
{
|
||||
if ($c->BillingStatus == 'Inactive')
|
||||
{
|
||||
foreach ($poo->getCustomers() as $c) {
|
||||
if ($c->BillingStatus == 'Inactive') {
|
||||
$this->info(sprintf('Ignoring INACTIVE: [%s] %s %s',$c->EzypayReferenceNumber,$c->Firstname,$c->Surname));
|
||||
continue;
|
||||
}
|
||||
@@ -53,10 +42,9 @@ class PaymentsEzypayNext extends Command
|
||||
// Load Account Details from ReferenceId
|
||||
$ao = Account::where('site_id',(int)substr($c->ReferenceId,0,2))
|
||||
->where('id',(int)substr($c->ReferenceId,2,4))
|
||||
->first();
|
||||
->single();
|
||||
|
||||
if (! $ao)
|
||||
{
|
||||
if (! $ao) {
|
||||
$this->warn(sprintf('Missing: [%s] %s %s (%s)',$c->EzypayReferenceNumber,$c->Firstname,$c->Surname,$c->ReferenceId));
|
||||
continue;
|
||||
}
|
||||
@@ -70,12 +58,33 @@ class PaymentsEzypayNext extends Command
|
||||
'dateTo'=>now()->addQuarter()->format('Y-m-d'),
|
||||
])->reverse()->first();
|
||||
|
||||
if ($next_pay->Status !== 'Pending') {
|
||||
$this->warn(sprintf('Next payment is not pending for (%s)',$ao->name));
|
||||
continue;
|
||||
}
|
||||
|
||||
$next_paydate = Carbon::createFromTimeString($next_pay->Date);
|
||||
|
||||
if ($next_pay->Amount < $account_due)
|
||||
$this->warn(sprintf('Next payment for (%s) [%s] not sufficient for outstanding balance [%s]',$ao->name,number_format($next_pay->Amount,2),number_format($account_due,2)));
|
||||
$this->warn(sprintf('Next payment on [%s] for (%s) [%s] not sufficient for outstanding balance [%s]',
|
||||
$next_paydate->format('Y-m-d'),
|
||||
$ao->name,
|
||||
number_format($next_pay->Amount,2),
|
||||
number_format($account_due,2)));
|
||||
|
||||
elseif ($next_pay->Amount > $account_due)
|
||||
$this->warn(sprintf('Next payment for (%s) [%s] is too much for outstanding balance [%s]',$ao->name,number_format($next_pay->Amount,2),number_format($account_due,2)));
|
||||
$this->warn(sprintf('Next payment on [%s] for (%s) [%s] is too much for outstanding balance [%s]',
|
||||
$next_paydate->format('Y-m-d'),
|
||||
$ao->name,
|
||||
number_format($next_pay->Amount,2),
|
||||
number_format($account_due,2)));
|
||||
|
||||
else
|
||||
$this->info(sprintf('Next payment for (%s) [%s] will cover outstanding balance [%s]',$ao->name,number_format($next_pay->Amount,2),number_format($account_due,2)));
|
||||
$this->info(sprintf('Next payment on [%s] for (%s) [%s] will cover outstanding balance [%s]',
|
||||
$next_paydate->format('Y-m-d'),
|
||||
$ao->name,
|
||||
number_format($next_pay->Amount,2),
|
||||
number_format($account_due,2)));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user