1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-19 16:01:34 +02:00

Fixes for BTC Pay

This commit is contained in:
David Bomba 2024-08-30 11:10:18 +10:00
parent 638c823722
commit adf93942b2

View File

@ -12,18 +12,19 @@
namespace App\PaymentDrivers;
use App\Utils\Traits\MakesHash;
use App\Models\PaymentHash;
use App\Models\GatewayType;
use App\PaymentDrivers\BTCPay\BTCPay;
use App\Models\SystemLog;
use App\Models\Payment;
use App\Models\Client;
use App\Exceptions\PaymentFailed;
use App\Models\PaymentType;
use BTCPayServer\Client\Webhook;
use App\Http\Requests\Payments\PaymentWebhookRequest;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\SystemLog;
use App\Models\GatewayType;
use App\Models\PaymentHash;
use App\Models\PaymentType;
use App\Utils\Traits\MakesHash;
use BTCPayServer\Client\Webhook;
use App\Exceptions\PaymentFailed;
use App\PaymentDrivers\BTCPay\BTCPay;
use App\Jobs\Mail\PaymentFailedMailer;
use App\Http\Requests\Payments\PaymentWebhookRequest;
class BTCPayPaymentDriver extends BaseDriver
{
@ -138,8 +139,6 @@ class BTCPayPaymentDriver extends BaseDriver
$_invoice = $this->payment_hash->fee_invoice;
// Invoice::with('client')->withTrashed()->find($this->payment_hash->fee_invoice_id);
$this->client = $_invoice->client;
$dataPayment = [
@ -158,21 +157,49 @@ class BTCPayPaymentDriver extends BaseDriver
}
switch ($btcpayRep->type) {
case "InvoiceExpired":
if ($payment->status_id == Payment::STATUS_PENDING) {
$payment->service()->deletePayment();
$this->failedPaymentNotification($payment);
}
$StatusId = Payment::STATUS_CANCELLED;
break;
case "InvoiceInvalid":
if ($payment->status_id == Payment::STATUS_PENDING) {
$payment->service()->deletePayment();
$this->failedPaymentNotification($payment);
}
$StatusId = Payment::STATUS_FAILED;
break;
case "InvoiceSettled":
$StatusId = Payment::STATUS_COMPLETED;
break;
}
if ($payment->status_id != $StatusId) {
$payment->status_id = $StatusId;
$payment->save();
}
}
private function failedPaymentNotification(Payment $payment): void
{
$error = ctrans('texts.client_payment_failure_body', [
'invoice' => implode(',', $payment->invoices->pluck('number')->toArray()),
'amount' => array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total, ]);
PaymentFailedMailer::dispatch(
$this->payment_hash,
$payment->client->company,
$payment->client,
$error
);
}
public function refund(Payment $payment, $amount, $return_client_response = false)
{