mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 05:44:32 -04:00
Merge pull request #7439 from CirkaN/Cirkovic/INA-2!
Cirkovic/INA-2 (Add limit to the auto bill )
This commit is contained in:
commit
d7bbc36251
@ -91,6 +91,7 @@ class Invoice extends BaseModel
|
||||
'auto_bill_enabled',
|
||||
'uses_inclusive_taxes',
|
||||
'vendor_id',
|
||||
'auto_bill_tries'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@ -445,14 +446,14 @@ class Invoice extends BaseModel
|
||||
$file_path = CreateEntityPdf::dispatchNow($invitation, config('filesystems.default'));
|
||||
return Storage::disk(config('filesystems.default'))->{$type}($file_path);
|
||||
}
|
||||
|
||||
|
||||
try{
|
||||
$file_exists = Storage::disk('public')->exists($file_path);
|
||||
}
|
||||
catch(\Exception $e){
|
||||
|
||||
nlog($e->getMessage());
|
||||
|
||||
|
||||
}
|
||||
|
||||
if($file_exists)
|
||||
@ -553,10 +554,10 @@ class Invoice extends BaseModel
|
||||
$invoice = $this->fresh();
|
||||
|
||||
return [
|
||||
'invoice_id' => $invoice->id,
|
||||
'invoice_amount' => $invoice->amount ?: 0,
|
||||
'invoice_partial' => $invoice->partial ?: 0,
|
||||
'invoice_balance' => $invoice->balance ?: 0,
|
||||
'invoice_id' => $invoice->id,
|
||||
'invoice_amount' => $invoice->amount ?: 0,
|
||||
'invoice_partial' => $invoice->partial ?: 0,
|
||||
'invoice_balance' => $invoice->balance ?: 0,
|
||||
'invoice_paid_to_date' => $invoice->paid_to_date ?: 0,
|
||||
'invoice_status' => $invoice->status_id ?: 1,
|
||||
];
|
||||
|
@ -38,7 +38,7 @@ class AutoBillInvoice extends AbstractService
|
||||
public function __construct(Invoice $invoice, $db)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
|
||||
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ class AutoBillInvoice extends AbstractService
|
||||
$is_partial = false;
|
||||
|
||||
/* Is the invoice payable? */
|
||||
if (! $this->invoice->isPayable())
|
||||
if (! $this->invoice->isPayable())
|
||||
return $this->invoice;
|
||||
|
||||
/* Mark the invoice as sent */
|
||||
@ -114,27 +114,31 @@ class AutoBillInvoice extends AbstractService
|
||||
]);
|
||||
|
||||
nlog("Payment hash created => {$payment_hash->id}");
|
||||
|
||||
|
||||
$payment = false;
|
||||
|
||||
//TODO check retries is not past threshold > 3. //return
|
||||
// if threshold exceeded. set invoices.auto_bill_enabled = false.
|
||||
$number_of_retries = $this->invoice->auto_bill_tries;
|
||||
|
||||
try{
|
||||
$payment = $gateway_token->gateway
|
||||
->driver($this->client)
|
||||
->setPaymentHash($payment_hash)
|
||||
->tokenBilling($gateway_token, $payment_hash);
|
||||
}
|
||||
catch(\Exception $e){
|
||||
nlog("payment NOT captured for ". $this->invoice->number . " with error " . $e->getMessage());
|
||||
try {
|
||||
$payment = $gateway_token->gateway
|
||||
->driver($this->client)
|
||||
->setPaymentHash($payment_hash)
|
||||
->tokenBilling($gateway_token, $payment_hash);
|
||||
} catch (\Exception $e) {
|
||||
//increase the counter
|
||||
$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) {
|
||||
$this->invoice->auto_bill_enabled = false;
|
||||
$this->invoice->save();
|
||||
}
|
||||
nlog("payment NOT captured for " . $this->invoice->number . " with error " . $e->getMessage());
|
||||
// $this->invoice->service()->removeUnpaidGatewayFees();
|
||||
}
|
||||
|
||||
//@TODO increment auto_bill_tries here
|
||||
}
|
||||
|
||||
if($payment){
|
||||
info("Auto Bill payment captured for ".$this->invoice->number);
|
||||
if ($payment) {
|
||||
info("Auto Bill payment captured for " . $this->invoice->number);
|
||||
}
|
||||
|
||||
// return $this->invoice->fresh();
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddAutoBillTriesToInvoicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->smallInteger('auto_bill_tries')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('invoices', function (Blueprint $table) {
|
||||
$table->dropColumn('auto_bill_tries');
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user