diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 4c58f62f4624..b0c5353c2d27 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -57,6 +57,21 @@ class PaymentService extends BaseService return false; } + if ($credits = $client->credits->sum('balance')) { + $balance = $invoice->balance; + $amount = min($credits, $balance); + $data = [ + 'payment_type_id' => PAYMENT_TYPE_CREDIT, + 'invoice_id' => $invoice->id, + 'client_id' => $client->id, + 'amount' => $amount, + ]; + $payment = $this->paymentRepo->save($data); + if ($amount == $balance) { + return $payment; + } + } + $paymentDriver = $account->paymentDriver($invitation, GATEWAY_TYPE_TOKEN); $customer = $paymentDriver->customer();