mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 01:17:30 -05:00 
			
		
		
		
	INA-2 | Added counter logic into the auto bill service
This commit is contained in:
		
							parent
							
								
									b15018a73a
								
							
						
					
					
						commit
						6d2b3a1c05
					
				@ -38,7 +38,7 @@ class AutoBillInvoice extends AbstractService
 | 
				
			|||||||
    public function __construct(Invoice $invoice, $db)
 | 
					    public function __construct(Invoice $invoice, $db)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->invoice = $invoice;
 | 
					        $this->invoice = $invoice;
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
        $this->db = $db;
 | 
					        $this->db = $db;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -52,7 +52,7 @@ class AutoBillInvoice extends AbstractService
 | 
				
			|||||||
        $is_partial = false;
 | 
					        $is_partial = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Is the invoice payable? */
 | 
					        /* Is the invoice payable? */
 | 
				
			||||||
        if (! $this->invoice->isPayable()) 
 | 
					        if (! $this->invoice->isPayable())
 | 
				
			||||||
            return $this->invoice;
 | 
					            return $this->invoice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Mark the invoice as sent */
 | 
					        /* Mark the invoice as sent */
 | 
				
			||||||
@ -117,19 +117,28 @@ class AutoBillInvoice extends AbstractService
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $payment = false;
 | 
					        $payment = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try{
 | 
					        $number_of_retries = $this->invoice->auto_bill_tries;
 | 
				
			||||||
        $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());
 | 
					 | 
				
			||||||
         //   $this->invoice->service()->removeUnpaidGatewayFees();
 | 
					 | 
				
			||||||
         }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if($payment){
 | 
					        try {
 | 
				
			||||||
            info("Auto Bill payment captured for ".$this->invoice->number);
 | 
					            $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();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ($payment) {
 | 
				
			||||||
 | 
					            info("Auto Bill payment captured for " . $this->invoice->number);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // return $this->invoice->fresh();
 | 
					        // return $this->invoice->fresh();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user