From 26ff0f2ca4c2b984dda5aefb6626dc89fb20ab48 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Sat, 16 Nov 2024 11:57:08 +0100 Subject: [PATCH] Update payments handling --- app/Http/Controllers/BtcPaymentController.php | 6 ++-- ...0_add_invoice_status_to_payments_table.php | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2024_11_16_114640_add_invoice_status_to_payments_table.php diff --git a/app/Http/Controllers/BtcPaymentController.php b/app/Http/Controllers/BtcPaymentController.php index 57dd4de3b..188ed726c 100644 --- a/app/Http/Controllers/BtcPaymentController.php +++ b/app/Http/Controllers/BtcPaymentController.php @@ -30,7 +30,7 @@ class BtcPaymentController extends BasePageController if ($checkOrder !== null) { Log::error('Duplicate BTCPay webhook: '.$payload['webhookId']); - return response('Not Found', 404); + return response('OK', 200); } Payment::create([ @@ -57,7 +57,9 @@ class BtcPaymentController extends BasePageController if ($payload['type'] === 'InvoiceSettled') { // Check if we have the invoice_id in payments table and if we do, update the user account - $checkOrder = Payment::query()->where('invoice_id', '=', $payload['invoiceId'])->where('payment_status', '=', 'Settled')->first(); + $checkOrder = Payment::query()->where('invoice_id', '=', $payload['invoiceId'])->where('payment_status', '=', 'Settled')->where(function ($query) { + return $query->where('invoice_status', 'Pending')->orWhereNull('invoice_status'); + })->first(); if ($checkOrder !== null) { $user = User::query()->where('email', '=', $checkOrder->email)->first(); if ($user) { diff --git a/database/migrations/2024_11_16_114640_add_invoice_status_to_payments_table.php b/database/migrations/2024_11_16_114640_add_invoice_status_to_payments_table.php new file mode 100644 index 000000000..a65c9a191 --- /dev/null +++ b/database/migrations/2024_11_16_114640_add_invoice_status_to_payments_table.php @@ -0,0 +1,28 @@ +string('invoice_status')->default('Pending')->after('payment_status')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('payments', function (Blueprint $table) { + $table->dropColumn('invoice_status'); + }); + } +};