From cb539d5caa1736e5129802acde5aadb6db9a383d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 20 Aug 2023 21:29:39 +1000 Subject: [PATCH 1/6] Add square webhook tests --- app/PaymentDrivers/SquarePaymentDriver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index ca9c10dcb797..40590eeb138a 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -362,7 +362,8 @@ class SquarePaymentDriver extends BaseDriver public function processWebhookRequest(PaymentWebhookRequest $request) { - + nlog("square webhook {$request->all()}"); + $signature_key = $this->company_gateway->getConfigField('signatureKey'); $notification_url = $this->company_gateway->webhookUrl(); From 5334a9ab87e6717ba6e5b4b5cf6b6dd24691ecc6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 20 Aug 2023 21:33:23 +1000 Subject: [PATCH 2/6] Add square webhook tests --- app/PaymentDrivers/SquarePaymentDriver.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index 40590eeb138a..5496a0d1ca00 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -362,8 +362,9 @@ class SquarePaymentDriver extends BaseDriver public function processWebhookRequest(PaymentWebhookRequest $request) { - nlog("square webhook {$request->all()}"); - + nlog("square webhook"); + nlog($request->all()); + $signature_key = $this->company_gateway->getConfigField('signatureKey'); $notification_url = $this->company_gateway->webhookUrl(); From 1cdd3ac8bc545e900610d1507df77f9f8d767e3f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 20 Aug 2023 21:43:31 +1000 Subject: [PATCH 3/6] Add square webhook tests --- app/PaymentDrivers/Square/SquareWebhook.php | 79 +++------------------ 1 file changed, 9 insertions(+), 70 deletions(-) diff --git a/app/PaymentDrivers/Square/SquareWebhook.php b/app/PaymentDrivers/Square/SquareWebhook.php index 6f5062282bd1..ea2e812ca730 100644 --- a/app/PaymentDrivers/Square/SquareWebhook.php +++ b/app/PaymentDrivers/Square/SquareWebhook.php @@ -163,86 +163,23 @@ class SquareWebhook implements ShouldQueue $payment = Payment::withTrashed()->where('transaction_reference', $payment_reference)->first(); - if($payment) + if($payment) { + nlog("payment found, returning"); return $payment; + } /** Handles the edge case where for some reason the payment has not yet been recorded in Invoice Ninja */ $apiResponse = $this->square->getPaymentsApi()->getPayment($payment_reference); -// { -// "payment": { -// "id": "bP9mAsEMYPUGjjGNaNO5ZDVyLhSZY", -// "created_at": "2021-10-13T19:34:33.524Z", -// "updated_at": "2021-10-13T19:34:34.339Z", -// "amount_money": { -// "amount": 555, -// "currency": "USD" -// }, -// "status": "COMPLETED", -// "delay_duration": "PT168H", -// "source_type": "CARD", -// "card_details": { -// "status": "CAPTURED", -// "card": { -// "card_brand": "VISA", -// "last_4": "1111", -// "exp_month": 11, -// "exp_year": 2022, -// "fingerprint": "sq-1-Hxim77tbdcbGejOejnoAklBVJed2YFLTmirfl8Q5XZzObTc8qY_U8RkwzoNL8dCEcQ", -// "card_type": "DEBIT", -// "prepaid_type": "NOT_PREPAID", -// "bin": "411111" -// }, -// "entry_method": "KEYED", -// "cvv_status": "CVV_ACCEPTED", -// "avs_status": "AVS_ACCEPTED", -// "auth_result_code": "2Nkw7q", -// "statement_description": "SQ *EXAMPLE TEST GOSQ.C", -// "card_payment_timeline": { -// "authorized_at": "2021-10-13T19:34:33.680Z", -// "captured_at": "2021-10-13T19:34:34.340Z" -// } -// }, -// "location_id": "L88917AVBK2S5", -// "order_id": "d7eKah653Z579f3gVtjlxpSlmUcZY", -// "processing_fee": [ -// { -// "effective_at": "2021-10-13T21:34:35.000Z", -// "type": "INITIAL", -// "amount_money": { -// "amount": 34, -// "currency": "USD" -// } -// } -// ], -// "note": "Test Note", -// "total_money": { -// "amount": 555, -// "currency": "USD" -// }, -// "approved_money": { -// "amount": 555, -// "currency": "USD" -// }, -// "employee_id": "TMoK_ogh6rH1o4dV", -// "receipt_number": "bP9m", -// "receipt_url": "https://squareup.com/receipt/preview/bP9mAsEMYPUGjjGNaNO5ZDVyLhSZY", -// "delay_action": "CANCEL", -// "delayed_until": "2021-10-20T19:34:33.524Z", -// "team_member_id": "TMoK_ogh6rH1o4dV", -// "application_details": { -// "square_product": "VIRTUAL_TERMINAL", -// "application_id": "sq0ids-Pw67AZAlLVB7hsRmwlJPuA" -// }, -// "version_token": "56pRkL3slrzet2iQrTp9n0bdJVYTB9YEWdTNjQfZOPV6o" -// } -// } + nlog("searching square for payment"); if($apiResponse->isSuccess()){ + nlog("Searching by payment hash"); + $payment_hash_id = $apiResponse->getPayment()->getReferenceId() ?? false; $square_payment = $apiResponse->getPayment()->jsonSerialize(); - $payment_hash = PaymentHash::where('hash', $payment_hash_id)->firstOrFail(); + $payment_hash = PaymentHash::query()->where('hash', $payment_hash_id)->firstOrFail(); $payment_hash->data = array_merge((array) $payment_hash->data, (array)$square_payment); $payment_hash->save(); @@ -258,6 +195,8 @@ class SquareWebhook implements ShouldQueue ]; $payment = $this->driver->createPayment($data, $payment_status); + + nlog("Creating payment"); SystemLogger::dispatch( ['response' => $this->webhook_array, 'data' => $square_payment], From a3433a7efc03677724cf7c6f0a7715e29b642659 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 20 Aug 2023 21:52:51 +1000 Subject: [PATCH 4/6] Add square webhook tests --- app/PaymentDrivers/SquarePaymentDriver.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index 5496a0d1ca00..f122fb998356 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -363,13 +363,11 @@ class SquarePaymentDriver extends BaseDriver public function processWebhookRequest(PaymentWebhookRequest $request) { nlog("square webhook"); - nlog($request->all()); $signature_key = $this->company_gateway->getConfigField('signatureKey'); $notification_url = $this->company_gateway->webhookUrl(); - - // header('Content-Type: text/plain'); - // $webhook_payload = file_get_contents('php://input'); + nlog($signature_key); + nlog($notification_url); $body = ''; $handle = fopen('php://input', 'r'); From 03b3170b8c6c95217230b27e8a67ba48c2254c01 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 20 Aug 2023 21:55:37 +1000 Subject: [PATCH 5/6] cleanup --- app/PaymentDrivers/Square/SquareWebhook.php | 43 --------------------- app/PaymentDrivers/SquarePaymentDriver.php | 2 - 2 files changed, 45 deletions(-) diff --git a/app/PaymentDrivers/Square/SquareWebhook.php b/app/PaymentDrivers/Square/SquareWebhook.php index ea2e812ca730..ebe46b0af4ee 100644 --- a/app/PaymentDrivers/Square/SquareWebhook.php +++ b/app/PaymentDrivers/Square/SquareWebhook.php @@ -56,48 +56,6 @@ class SquareWebhook implements ShouldQueue { } - -/** - * { - * "merchant_id": "6SSW7HV8K2ST5", - * "type": "payment.created", - * "event_id": "13b867cf-db3d-4b1c-90b6-2f32a9d78124", - * "created_at": "2020-02-06T21:27:30.792Z", - * "data": { - * "type": "payment", - * "id": "KkAkhdMsgzn59SM8A89WgKwekxLZY", - * "object": { - * "payment": { - * "id": "hYy9pRFVxpDsO1FB05SunFWUe9JZY", - * "created_at": "2020-11-22T21:16:51.086Z", - * "updated_at": "2020-11-22T21:16:51.198Z", - * "amount_money": { - * "amount": 100, - * "currency": "USD" - * }, - * "status": "APPROVED", - * "delay_duration": "PT168H", - * "source_type": "CARD", - * "card_details": { - * "status": "AUTHORIZED", - * "card": { - * "card_brand": "MASTERCARD", - * "last_4": "9029", - * "exp_month": 11, - * "exp_year": 2022, - * "fingerprint": "sq-1-Tvruf3vPQxlvI6n0IcKYfBukrcv6IqWr8UyBdViWXU2yzGn5VMJvrsHMKpINMhPmVg", - * "card_type": "CREDIT", - * "prepaid_type": "NOT_PREPAID", - * "bin": "540988" - * }, - * "entry_method": "KEYED", - * "cvv_status": "CVV_ACCEPTED", - * "avs_status": "AVS_ACCEPTED", - * "statement_description": "SQ *DEFAULT TEST ACCOUNT", - * "card_payment_timeline": { - * "authorized_at": "2020-11-22T21:16:51.198Z" - * - */ public function handle() { nlog("Square Webhook"); @@ -155,7 +113,6 @@ class SquareWebhook implements ShouldQueue $payment->save(); } - //toggle pending to completed. } private function retrieveOrCreatePayment(?string $payment_reference, int $payment_status): ?\App\Models\Payment diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index f122fb998356..9a14358be634 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -366,8 +366,6 @@ class SquarePaymentDriver extends BaseDriver $signature_key = $this->company_gateway->getConfigField('signatureKey'); $notification_url = $this->company_gateway->webhookUrl(); - nlog($signature_key); - nlog($notification_url); $body = ''; $handle = fopen('php://input', 'r'); From b3bb7fe431dbe89b2679a0f6c3d2e8d248aba253 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 20 Aug 2023 22:14:31 +1000 Subject: [PATCH 6/6] Convert collection to array --- app/Export/CSV/CreditExport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Export/CSV/CreditExport.php b/app/Export/CSV/CreditExport.php index e64913971869..82de37a0cd04 100644 --- a/app/Export/CSV/CreditExport.php +++ b/app/Export/CSV/CreditExport.php @@ -134,7 +134,7 @@ class CreditExport extends BaseExport $this->input['report_keys'] = collect(array_values($this->entity_keys))->map(function ($value){ return 'credit.'.$value; - }); + })->toArray(); }