Merge pull request #7439 from CirkaN/Cirkovic/INA-2!

Cirkovic/INA-2 (Add limit to the auto bill )
This commit is contained in:
David Bomba 2022-05-17 14:44:17 +10:00 committed by GitHub
commit d7bbc36251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 24 deletions

View File

@ -91,6 +91,7 @@ class Invoice extends BaseModel
'auto_bill_enabled', 'auto_bill_enabled',
'uses_inclusive_taxes', 'uses_inclusive_taxes',
'vendor_id', 'vendor_id',
'auto_bill_tries'
]; ];
protected $casts = [ protected $casts = [

View File

@ -117,24 +117,28 @@ class AutoBillInvoice extends AbstractService
$payment = false; $payment = false;
//TODO check retries is not past threshold > 3. //return $number_of_retries = $this->invoice->auto_bill_tries;
// if threshold exceeded. set invoices.auto_bill_enabled = false.
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
nlog("payment NOT captured for ". $this->invoice->number . " with error " . $e->getMessage()); $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(); // $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(); // return $this->invoice->fresh();

View File

@ -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');
});
}
}