From 787400ff3974b1195aa004f8f2ebfc6701353532 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 20 Aug 2023 19:17:21 +1000 Subject: [PATCH] Fixes for squar --- app/PaymentDrivers/Square/CreditCard.php | 2 +- app/PaymentDrivers/Square/SquareWebhook.php | 8 +++++--- app/PaymentDrivers/SquarePaymentDriver.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/PaymentDrivers/Square/CreditCard.php b/app/PaymentDrivers/Square/CreditCard.php index 616bbbbff046..59139361a946 100644 --- a/app/PaymentDrivers/Square/CreditCard.php +++ b/app/PaymentDrivers/Square/CreditCard.php @@ -116,7 +116,7 @@ class CreditCard implements MethodInterface $amount_money->setAmount($amount); $amount_money->setCurrency($this->square_driver->client->currency()->code); - $body = new \Square\Models\CreatePaymentRequest($token, $request->idempotencyKey, $amount_money); + $body = new \Square\Models\CreatePaymentRequest($token, $request->idempotencyKey); $body->setAmountMoney($amount_money); $body->setAutocomplete(true); $body->setLocationId($this->square_driver->company_gateway->getConfigField('locationId')); diff --git a/app/PaymentDrivers/Square/SquareWebhook.php b/app/PaymentDrivers/Square/SquareWebhook.php index 6b6a1841095d..8e99e160e10a 100644 --- a/app/PaymentDrivers/Square/SquareWebhook.php +++ b/app/PaymentDrivers/Square/SquareWebhook.php @@ -104,13 +104,15 @@ class SquareWebhook implements ShouldQueue MultiDB::findAndSetDbByCompanyKey($this->company_key); - $this->company_gateway = CompanyGateway::queyr()->withTrashed()->find($this->company_gateway_id); + $this->company_gateway = CompanyGateway::query()->withTrashed()->find($this->company_gateway_id); $this->driver = $this->company_gateway->driver()->init(); $this->square = $this->driver->square; $status = $this->webhook_array['data']['object']['payment']['status'] ?? false; $payment_id = $this->webhook_array['data']['object']['payment']['id'] ?? null; + $payment_status = false; + match($status){ 'APPROVED' => $payment_status = false, 'COMPLETED' => $payment_status = Payment::STATUS_COMPLETED, @@ -131,7 +133,6 @@ class SquareWebhook implements ShouldQueue if($payment->status_id == Payment::STATUS_PENDING && in_array($payment_status, [Payment::STATUS_CANCELLED, Payment::STATUS_FAILED])){ $payment->service()->deletePayment(); - if ($this->driver->payment_hash) { $error = ctrans('texts.client_payment_failure_body', [ 'invoice' => implode(',', $payment->invoices->pluck('number')->toArray()), @@ -157,7 +158,7 @@ class SquareWebhook implements ShouldQueue //toggle pending to completed. } - private function retrieveOrCreatePayment(?string $payment_reference, int $payment_status): \App\Models\Payment + private function retrieveOrCreatePayment(?string $payment_reference, int $payment_status): ?\App\Models\Payment { $payment = Payment::withTrashed()->where('transaction_reference', $payment_reference)->first(); @@ -273,6 +274,7 @@ class SquareWebhook implements ShouldQueue else{ nlog("Square Webhook - Payment not found: $payment_reference"); nlog($apiResponse->getErrors()); + return null; } } } \ No newline at end of file diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index 5c9b5515821a..3ff5e09121a3 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -230,7 +230,7 @@ class SquarePaymentDriver extends BaseDriver $amount_money->setAmount($amount); $amount_money->setCurrency($this->client->currency()->code); - $body = new \Square\Models\CreatePaymentRequest($cgt->token, \Illuminate\Support\Str::random(32), $amount_money); + $body = new \Square\Models\CreatePaymentRequest($cgt->token, \Illuminate\Support\Str::random(32)); $body->setCustomerId($cgt->gateway_customer_reference); $body->setAmountMoney($amount_money); $body->setReferenceId($payment_hash->hash);