mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Minor refactor for auto billing
This commit is contained in:
parent
d7bbc36251
commit
ede64ef03d
@ -90,8 +90,7 @@ class Invoice extends BaseModel
|
|||||||
'subscription_id',
|
'subscription_id',
|
||||||
'auto_bill_enabled',
|
'auto_bill_enabled',
|
||||||
'uses_inclusive_taxes',
|
'uses_inclusive_taxes',
|
||||||
'vendor_id',
|
'vendor_id'
|
||||||
'auto_bill_tries'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
@ -117,31 +117,26 @@ class AutoBillInvoice extends AbstractService
|
|||||||
|
|
||||||
$payment = false;
|
$payment = false;
|
||||||
|
|
||||||
$number_of_retries = $this->invoice->auto_bill_tries;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$payment = $gateway_token->gateway
|
$payment = $gateway_token->gateway
|
||||||
->driver($this->client)
|
->driver($this->client)
|
||||||
->setPaymentHash($payment_hash)
|
->setPaymentHash($payment_hash)
|
||||||
->tokenBilling($gateway_token, $payment_hash);
|
->tokenBilling($gateway_token, $payment_hash);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
//increase the counter
|
|
||||||
$this->invoice->auto_bill_tries = $number_of_retries + 1;
|
$this->invoice->auto_bill_tries = $number_of_retries + 1;
|
||||||
$this->invoice->save();
|
|
||||||
//disable auto bill if limit of 3 is reached
|
|
||||||
if ($this->invoice->auto_bill_tries == 3) {
|
if ($this->invoice->auto_bill_tries == 3) {
|
||||||
$this->invoice->auto_bill_enabled = false;
|
$this->invoice->auto_bill_enabled = false;
|
||||||
|
$this->invoice->auto_bill_tries = 0; //reset the counter here in case auto billing is turned on again in the future.
|
||||||
$this->invoice->save();
|
$this->invoice->save();
|
||||||
}
|
}
|
||||||
nlog("payment NOT captured for " . $this->invoice->number . " with error " . $e->getMessage());
|
nlog("payment NOT captured for " . $this->invoice->number . " with error " . $e->getMessage());
|
||||||
// $this->invoice->service()->removeUnpaidGatewayFees();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($payment) {
|
if ($payment) {
|
||||||
info("Auto Bill payment captured for " . $this->invoice->number);
|
info("Auto Bill payment captured for " . $this->invoice->number);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return $this->invoice->fresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user