From 55f71a27c7df25b10fa8e075d5521acdfd6f90b4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 16 Oct 2023 07:25:47 +1100 Subject: [PATCH] Fixes for square autobill --- app/PaymentDrivers/Square/SquareWebhook.php | 10 ++++++++-- app/Services/Invoice/AutoBillInvoice.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/PaymentDrivers/Square/SquareWebhook.php b/app/PaymentDrivers/Square/SquareWebhook.php index c83b73fd4765..c638e2ad3bb7 100644 --- a/app/PaymentDrivers/Square/SquareWebhook.php +++ b/app/PaymentDrivers/Square/SquareWebhook.php @@ -134,8 +134,14 @@ class SquareWebhook implements ShouldQueue nlog("Searching by payment hash"); - $payment_hash_id = $apiResponse->getPayment()->getReferenceId() ?? false; - $square_payment = $apiResponse->getPayment()->jsonSerialize(); + $body = json_decode($apiResponse->getBody()); + + $payment_hash_id = $body->payment->reference_id ?? false; + $square_payment = $body->payment ?? false; + + if(!$payment_hash_id) + return; + $payment_hash = PaymentHash::query()->where('hash', $payment_hash_id)->firstOrFail(); $payment_hash->data = array_merge((array) $payment_hash->data, (array)$square_payment); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 0585f888bd66..19a366fdc507 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -120,7 +120,7 @@ class AutoBillInvoice extends AbstractService /* Build payment hash */ $payment_hash = PaymentHash::create([ - 'hash' => Str::random(64), + 'hash' => Str::random(32), 'data' => [ 'amount_with_fee' => $amount + $fee, 'invoices' => [