add fixes for invoice balance
This commit is contained in:
parent
efaceba367
commit
8615d5bbc3
|
|
@ -16,6 +16,8 @@ use App\Models\Payment;
|
|||
use App\Models\SystemLog;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Models\Invoice;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Exceptions\PaymentFailed;
|
||||
|
|
@ -143,6 +145,8 @@ class Blockonomics implements LivewireMethodInterface
|
|||
// 'status' => ['required'],
|
||||
]);
|
||||
|
||||
$this->payment_hash = PaymentHash::where('hash', $request->payment_hash)->firstOrFail();
|
||||
|
||||
try {
|
||||
// Satoshis is the smallest unit of Bitcoin
|
||||
$amount_received_satoshis = $request->btc_amount;
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
|||
return response()->json(['message' => 'Payment not found'], 200);
|
||||
}
|
||||
|
||||
// If payment is already completed, no need to process again
|
||||
// // If payment is already completed, no need to process again
|
||||
if ($payment->status_id == Payment::STATUS_COMPLETED) {
|
||||
return response()->json(['message' => 'Payment already completed'], 200);
|
||||
}
|
||||
|
|
@ -135,6 +135,22 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
|||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
$payment->save();
|
||||
|
||||
$this->payment_hash = PaymentHash::where('payment_id', $payment->id)->firstOrFail();
|
||||
$invoices_data = $this->payment_hash->invoices();
|
||||
|
||||
$fiat_amount = $payment->amount;
|
||||
// How about recurring invoices?
|
||||
if (is_array($invoices_data)) {
|
||||
foreach ($invoices_data as $invoice_data) {
|
||||
$invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($invoice_data->invoice_id));
|
||||
// Do I need to loop through each payment for the invoice?
|
||||
if ($invoice) {
|
||||
$invoice->balance = $invoice->amount - $fiat_amount;
|
||||
$invoice->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Payment confirmed successfully',
|
||||
], 200);
|
||||
|
|
|
|||
Loading…
Reference in New Issue