Fixes for tests

This commit is contained in:
David Bomba 2021-01-24 20:28:18 +11:00
parent 0f8ee2d101
commit cecee6cbfe
3 changed files with 10 additions and 15 deletions

View File

@ -70,7 +70,7 @@ class ApplyCreditPayment implements ShouldQueue
$this->credit $this->credit
->service() ->service()
->setStatus(Credit::STATUS_APPLIED) ->setStatus(Credit::STATUS_APPLIED)
->updateBalance($this->amount * -1) ->adjustBalance($this->amount * -1)
->updatePaidToDate($this->amount) ->updatePaidToDate($this->amount)
->save(); ->save();
@ -79,7 +79,7 @@ class ApplyCreditPayment implements ShouldQueue
$this->credit $this->credit
->service() ->service()
->setStatus(Credit::STATUS_PARTIAL) ->setStatus(Credit::STATUS_PARTIAL)
->updateBalance($this->amount * -1) ->adjustBalance($this->amount * -1)
->updatePaidToDate($this->amount) ->updatePaidToDate($this->amount)
->save(); ->save();
} }

View File

@ -136,6 +136,7 @@ class ApplyPayment
$this->invoice $this->invoice
->service() ->service()
->updateBalance($this->amount_applied * -1) ->updateBalance($this->amount_applied * -1)
->updatePaidToDate($this->amount_applied)
->updateStatus() ->updateStatus()
->save(); ->save();

View File

@ -49,15 +49,12 @@ class AutoBillInvoice extends AbstractService
$this->invoice = $this->invoice->service()->markSent()->save(); $this->invoice = $this->invoice->service()->markSent()->save();
/* Mark the invoice as paid if there is no balance */ /* Mark the invoice as paid if there is no balance */
if ((int)$this->invoice->balance == 0) { if ((int)$this->invoice->balance == 0)
return $this->invoice->service()->markPaid()->save(); return $this->invoice->service()->markPaid()->save();
}
//if the credits cover the payments, we stop here, build the payment with credits and exit early //if the credits cover the payments, we stop here, build the payment with credits and exit early
if ($this->client->getSetting('use_credits_payment') != 'off')
if ($this->client->getSetting('use_credits_payment') != 'off') {
$this->applyCreditPayment(); $this->applyCreditPayment();
}
/* Determine $amount */ /* Determine $amount */
if ($this->invoice->partial > 0) { if ($this->invoice->partial > 0) {
@ -73,15 +70,12 @@ class AutoBillInvoice extends AbstractService
$gateway_token = $this->getGateway($amount); $gateway_token = $this->getGateway($amount);
/* Bail out if no payment methods available */ /* Bail out if no payment methods available */
if (! $gateway_token || ! $gateway_token->gateway->driver($this->client)->token_billing) { if (! $gateway_token || ! $gateway_token->gateway->driver($this->client)->token_billing)
return $this->invoice; return $this->invoice;
}
/* $gateway fee */ /* $gateway fee */
$fee = $gateway_token->gateway->calcGatewayFee($amount, $gateway_token->gateway_type_id, $this->invoice->uses_inclusive_taxes); $fee = $gateway_token->gateway->calcGatewayFee($amount, $gateway_token->gateway_type_id, $this->invoice->uses_inclusive_taxes);
//todo determine exact fee as per PaymentController
/* Build payment hash */ /* Build payment hash */
$payment_hash = PaymentHash::create([ $payment_hash = PaymentHash::create([
'hash' => Str::random(128), 'hash' => Str::random(128),
@ -196,7 +190,7 @@ class AutoBillInvoice extends AbstractService
if ($is_partial_amount) { if ($is_partial_amount) {
//more credit than needed //more credit than needed
if ($credit->balance >= $this->invoice->partial) { if ($credit->balance > $this->invoice->partial) {
$this->used_credit[$key]['credit_id'] = $credit->id; $this->used_credit[$key]['credit_id'] = $credit->id;
$this->used_credit[$key]['amount'] = $this->invoice->partial; $this->used_credit[$key]['amount'] = $this->invoice->partial;
$this->invoice->balance -= $this->invoice->partial; $this->invoice->balance -= $this->invoice->partial;
@ -213,7 +207,7 @@ class AutoBillInvoice extends AbstractService
} else { } else {
//more credit than needed //more credit than needed
if ($credit->balance >= $this->invoice->balance) { if ($credit->balance > $this->invoice->balance) {
$this->used_credit[$key]['credit_id'] = $credit->id; $this->used_credit[$key]['credit_id'] = $credit->id;
$this->used_credit[$key]['amount'] = $this->invoice->balance; $this->used_credit[$key]['amount'] = $this->invoice->balance;
$this->invoice->paid_to_date += $this->invoice->balance; $this->invoice->paid_to_date += $this->invoice->balance;