mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 05:24:29 -04:00
commit
7cce901bc9
@ -12,14 +12,13 @@
|
|||||||
|
|
||||||
namespace App\PaymentDrivers\BTCPay;
|
namespace App\PaymentDrivers\BTCPay;
|
||||||
|
|
||||||
use App\Models\GatewayType;
|
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\PaymentType;
|
|
||||||
use App\PaymentDrivers\BTCPayPaymentDriver;
|
use App\PaymentDrivers\BTCPayPaymentDriver;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\PaymentDrivers\Common\MethodInterface;
|
use App\PaymentDrivers\Common\MethodInterface;
|
||||||
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
||||||
use App\Exceptions\PaymentFailed;
|
use App\Exceptions\PaymentFailed;
|
||||||
|
use App\Jobs\Mail\PaymentFailureMailer;
|
||||||
use Illuminate\Mail\Mailables\Address;
|
use Illuminate\Mail\Mailables\Address;
|
||||||
use App\Services\Email\EmailObject;
|
use App\Services\Email\EmailObject;
|
||||||
use App\Services\Email\Email;
|
use App\Services\Email\Email;
|
||||||
@ -83,15 +82,6 @@ class BTCPay implements MethodInterface
|
|||||||
$_invoice = collect($drv->payment_hash->data->invoices)->first();
|
$_invoice = collect($drv->payment_hash->data->invoices)->first();
|
||||||
$cli = $drv->client;
|
$cli = $drv->client;
|
||||||
|
|
||||||
$dataPayment = [
|
|
||||||
'payment_method' => $drv->payment_method,
|
|
||||||
'payment_type' => PaymentType::CRYPTO,
|
|
||||||
'amount' => $request->amount,
|
|
||||||
'gateway_type_id' => GatewayType::CRYPTO,
|
|
||||||
'transaction_reference' => 'xxx'
|
|
||||||
];
|
|
||||||
$payment = $drv->createPayment($dataPayment, \App\Models\Payment::STATUS_PENDING);
|
|
||||||
|
|
||||||
$metaData = [
|
$metaData = [
|
||||||
'buyerName' => $cli->name,
|
'buyerName' => $cli->name,
|
||||||
'buyerAddress1' => $cli->address1,
|
'buyerAddress1' => $cli->address1,
|
||||||
@ -102,11 +92,11 @@ class BTCPay implements MethodInterface
|
|||||||
'buyerCountry' => $cli->country_id,
|
'buyerCountry' => $cli->country_id,
|
||||||
'buyerPhone' => $cli->phone,
|
'buyerPhone' => $cli->phone,
|
||||||
'itemDesc' => "From InvoiceNinja",
|
'itemDesc' => "From InvoiceNinja",
|
||||||
'paymentID' => $payment->id
|
'InvoiceNinjaPaymentHash' => $drv->payment_hash->hash
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
$urlRedirect = redirect()->route('client.payments.show', ['payment' => $payment->hashed_id])->getTargetUrl();
|
$urlRedirect = redirect()->route('client.invoice.show', ['invoice' => $_invoice->invoice_id])->getTargetUrl();
|
||||||
$checkoutOptions = new \BTCPayServer\Client\InvoiceCheckoutOptions();
|
$checkoutOptions = new \BTCPayServer\Client\InvoiceCheckoutOptions();
|
||||||
$checkoutOptions->setRedirectURL($urlRedirect);
|
$checkoutOptions->setRedirectURL($urlRedirect);
|
||||||
|
|
||||||
@ -120,11 +110,12 @@ class BTCPay implements MethodInterface
|
|||||||
$metaData,
|
$metaData,
|
||||||
$checkoutOptions
|
$checkoutOptions
|
||||||
);
|
);
|
||||||
$payment->transaction_reference = $rep->getId();
|
//$payment->transaction_reference = $rep->getId();
|
||||||
$payment->save();
|
// $payment->save();
|
||||||
|
|
||||||
return redirect($rep->getCheckoutLink());
|
return redirect($rep->getCheckoutLink());
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
PaymentFailureMailer::dispatch($drv->client, $drv->payment_hash->data, $drv->client->company, $request->amount);
|
||||||
throw new PaymentFailed('Error during BTCPay payment : ' . $e->getMessage());
|
throw new PaymentFailed('Error during BTCPay payment : ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,17 @@
|
|||||||
namespace App\PaymentDrivers;
|
namespace App\PaymentDrivers;
|
||||||
|
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Models\PaymentHash;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
use App\PaymentDrivers\BTCPay\BTCPay;
|
use App\PaymentDrivers\BTCPay\BTCPay;
|
||||||
use App\Models\SystemLog;
|
use App\Models\SystemLog;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Exceptions\PaymentFailed;
|
use App\Exceptions\PaymentFailed;
|
||||||
|
use App\Models\PaymentType;
|
||||||
use BTCPayServer\Client\Webhook;
|
use BTCPayServer\Client\Webhook;
|
||||||
|
use App\Http\Requests\Payments\PaymentWebhookRequest;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
|
||||||
class BTCPayPaymentDriver extends BaseDriver
|
class BTCPayPaymentDriver extends BaseDriver
|
||||||
{
|
{
|
||||||
@ -87,8 +91,7 @@ class BTCPayPaymentDriver extends BaseDriver
|
|||||||
public function processWebhookRequest()
|
public function processWebhookRequest()
|
||||||
{
|
{
|
||||||
$webhook_payload = file_get_contents('php://input');
|
$webhook_payload = file_get_contents('php://input');
|
||||||
$sig = false;
|
|
||||||
/** @var \stdClass $btcpayRep */
|
|
||||||
$btcpayRep = json_decode($webhook_payload);
|
$btcpayRep = json_decode($webhook_payload);
|
||||||
if ($btcpayRep == null) {
|
if ($btcpayRep == null) {
|
||||||
throw new PaymentFailed('Empty data');
|
throw new PaymentFailed('Empty data');
|
||||||
@ -98,7 +101,11 @@ class BTCPayPaymentDriver extends BaseDriver
|
|||||||
'Invalid BTCPayServer payment notification- did not receive invoice ID.'
|
'Invalid BTCPayServer payment notification- did not receive invoice ID.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (str_starts_with($btcpayRep->invoiceId, "__test__") || $btcpayRep->type == "InvoiceCreated") {
|
if (
|
||||||
|
str_starts_with($btcpayRep->invoiceId, "__test__")
|
||||||
|
|| $btcpayRep->type == "InvoiceProcessing"
|
||||||
|
|| $btcpayRep->type == "InvoiceCreated"
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,20 +125,40 @@ class BTCPayPaymentDriver extends BaseDriver
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var \App\Models\Payment $payment **/
|
$this->setPaymentMethod(GatewayType::CRYPTO);
|
||||||
$payment = Payment::find($btcpayRep->metafata->paymentID);
|
$this->payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$btcpayRep->metadata->InvoiceNinjaPaymentHash])->firstOrFail();
|
||||||
|
$StatusId = Payment::STATUS_PENDING;
|
||||||
|
if ($this->payment_hash->payment_id == null) {
|
||||||
|
//$_invoice = collect($this->payment_hash->data->invoices)->first();
|
||||||
|
$_invoice = Invoice::query()->where('number', $btcpayRep->metadata->orderId)->first();
|
||||||
|
$this->client = Client::find($_invoice->client_id);
|
||||||
|
$dataPayment = [
|
||||||
|
'payment_method' => $this->payment_method,
|
||||||
|
'payment_type' => PaymentType::CRYPTO,
|
||||||
|
'amount' => $_invoice->amount,
|
||||||
|
'gateway_type_id' => GatewayType::CRYPTO,
|
||||||
|
'transaction_reference' => $btcpayRep->invoiceId
|
||||||
|
];
|
||||||
|
$payment = $this->createPayment($dataPayment, $StatusId);
|
||||||
|
} else {
|
||||||
|
$payment = Payment::find($this->payment_hash->payment_id);
|
||||||
|
$StatusId = $payment->status_id;
|
||||||
|
}
|
||||||
switch ($btcpayRep->type) {
|
switch ($btcpayRep->type) {
|
||||||
case "InvoiceExpired":
|
case "InvoiceExpired":
|
||||||
$payment->status_id = Payment::STATUS_CANCELLED;
|
$StatusId = Payment::STATUS_CANCELLED;
|
||||||
break;
|
break;
|
||||||
case "InvoiceInvalid":
|
case "InvoiceInvalid":
|
||||||
$payment->status_id = Payment::STATUS_FAILED;
|
$StatusId = Payment::STATUS_FAILED;
|
||||||
break;
|
break;
|
||||||
case "InvoiceSettled":
|
case "InvoiceSettled":
|
||||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
$StatusId = Payment::STATUS_COMPLETED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$payment->save();
|
if ($payment->status_id != $StatusId) {
|
||||||
|
$payment->status_id = $StatusId;
|
||||||
|
$payment->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user