From 0c55a9968dd937f09f98a52ff3b44d859518db1f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 14 May 2022 07:30:40 +1000 Subject: [PATCH] Minor fixes for gocardless --- app/PaymentDrivers/GoCardlessPaymentDriver.php | 16 +++++++++------- app/Services/Client/Statement.php | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/PaymentDrivers/GoCardlessPaymentDriver.php b/app/PaymentDrivers/GoCardlessPaymentDriver.php index 9aa9a3f54..6a774fe19 100644 --- a/app/PaymentDrivers/GoCardlessPaymentDriver.php +++ b/app/PaymentDrivers/GoCardlessPaymentDriver.php @@ -230,14 +230,11 @@ class GoCardlessPaymentDriver extends BaseDriver public function processWebhookRequest(PaymentWebhookRequest $request) { // Allow app to catch up with webhook request. - sleep(2); - $this->init(); nlog("GoCardless Event"); nlog($request->all()); - if(!is_array($request->events) || !is_object($request->events)){ nlog("No GoCardless events to process in response?"); @@ -245,19 +242,24 @@ class GoCardlessPaymentDriver extends BaseDriver } + sleep(1); + foreach ($request->events as $event) { if ($event['action'] === 'confirmed') { + + nlog("Searching for transaction reference"); + $payment = Payment::query() ->where('transaction_reference', $event['links']['payment']) - ->where('company_id', $request->getCompany()->id) + // ->where('company_id', $request->getCompany()->id) ->first(); if ($payment) { $payment->status_id = Payment::STATUS_COMPLETED; $payment->save(); } - - + else + nlog("I was unable to find the payment for this reference"); //finalize payments on invoices here. } @@ -266,7 +268,7 @@ class GoCardlessPaymentDriver extends BaseDriver $payment = Payment::query() ->where('transaction_reference', $event['links']['payment']) - ->where('company_id', $request->getCompany()->id) + // ->where('company_id', $request->getCompany()->id) ->first(); if ($payment) { diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index f968e32bb..b96e4b51f 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -226,6 +226,7 @@ class Statement ->whereIn('status_id', $this->invoiceStatuses()) ->whereBetween('date', [Carbon::parse($this->options['start_date']), Carbon::parse($this->options['end_date'])]) ->orderBy('due_date', 'ASC') + ->orderBy('date', 'ASC') ->cursor(); }