mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Gateway fees
This commit is contained in:
parent
1bc71fb5d8
commit
a4d0e7759e
@ -347,9 +347,6 @@ class BaseRepository
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($data['mark_sent']) && $data['mark_sent'] == true)
|
|
||||||
$model->service()->markSent()->save();
|
|
||||||
|
|
||||||
$model->save();
|
$model->save();
|
||||||
|
|
||||||
return $model->fresh();
|
return $model->fresh();
|
||||||
|
@ -71,7 +71,7 @@ class AddGatewayFee extends AbstractService
|
|||||||
private function processGatewayFee($gateway_fee)
|
private function processGatewayFee($gateway_fee)
|
||||||
{
|
{
|
||||||
$invoice_item = new InvoiceItem;
|
$invoice_item = new InvoiceItem;
|
||||||
$invoice_item->type_id = 3;
|
$invoice_item->type_id = 4;
|
||||||
$invoice_item->product_key = ctrans('texts.surcharge');
|
$invoice_item->product_key = ctrans('texts.surcharge');
|
||||||
$invoice_item->notes = ctrans('texts.online_payment_surcharge');
|
$invoice_item->notes = ctrans('texts.online_payment_surcharge');
|
||||||
$invoice_item->quantity = 1;
|
$invoice_item->quantity = 1;
|
||||||
@ -89,8 +89,14 @@ class AddGatewayFee extends AbstractService
|
|||||||
|
|
||||||
$this->invoice->line_items = $invoice_items;
|
$this->invoice->line_items = $invoice_items;
|
||||||
|
|
||||||
|
/**Refresh Invoice values*/
|
||||||
$this->invoice = $this->invoice->calc()->getInvoice();
|
$this->invoice = $this->invoice->calc()->getInvoice();
|
||||||
|
|
||||||
|
/*Update client balance*/
|
||||||
|
$this->invoice->client->service()->updateBalance($gateway_fee)->save();
|
||||||
|
|
||||||
|
$this->invoice->ledger()->updateInvoiceBalance($gateway_fee, $notes = 'Gateway fee adjustment');
|
||||||
|
|
||||||
return $this->invoice;
|
return $this->invoice;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -118,6 +124,10 @@ class AddGatewayFee extends AbstractService
|
|||||||
|
|
||||||
$this->invoice = $this->invoice->calc()->getInvoice();
|
$this->invoice = $this->invoice->calc()->getInvoice();
|
||||||
|
|
||||||
|
$this->invoice->client->service()->updateBalance($gateway_fee)->save();
|
||||||
|
|
||||||
|
$this->invoice->ledger()->updateInvoiceBalance($gateway_fee, $notes = 'Discount fee adjustment');
|
||||||
|
|
||||||
return $this->invoice;
|
return $this->invoice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,17 +62,16 @@ class AutoBillInvoice extends AbstractService
|
|||||||
$amount = $this->invoice->balance + $fee;
|
$amount = $this->invoice->balance + $fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure we remove any stale fees*/
|
|
||||||
$this->purgeStaleGatewayFees();
|
|
||||||
|
|
||||||
if($fee > 0)
|
|
||||||
$this->addFeeToInvoice($fee);
|
|
||||||
|
|
||||||
$payment = $gateway_token->gateway->driver($this->client)->tokenBilling($gateway_token, $amount, $this->invoice);
|
$payment = $gateway_token->gateway->driver($this->client)->tokenBilling($gateway_token, $amount, $this->invoice);
|
||||||
|
|
||||||
if($payment){
|
if($payment){
|
||||||
|
|
||||||
$this->invoice = $this->invoice->service()->toggleFeesPaid()->save();
|
if($this->invoice->partial > 0)
|
||||||
|
$amount = $this->invoice->partial;
|
||||||
|
else
|
||||||
|
$amount = $this->invoice->balance;
|
||||||
|
|
||||||
|
$this->invoice = $this->invoice->service()->addGatewayFee($gateway_token->gateway, $amount)->save();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -144,34 +143,34 @@ class AutoBillInvoice extends AbstractService
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
private function purgeStaleGatewayFees()
|
// private function purgeStaleGatewayFees()
|
||||||
{
|
// {
|
||||||
$starting_amount = $this->invoice->amount;
|
// $starting_amount = $this->invoice->amount;
|
||||||
|
|
||||||
$line_items = $this->invoice->line_items;
|
// $line_items = $this->invoice->line_items;
|
||||||
|
|
||||||
$new_items = [];
|
// $new_items = [];
|
||||||
|
|
||||||
foreach($line_items as $item)
|
// foreach($line_items as $item)
|
||||||
{
|
// {
|
||||||
|
|
||||||
if($item->type_id != 3)
|
// if($item->type_id != 3)
|
||||||
$new_items[] = $item;
|
// $new_items[] = $item;
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
$this->invoice->line_items = $new_items;
|
// $this->invoice->line_items = $new_items;
|
||||||
$this->invoice->save();
|
// $this->invoice->save();
|
||||||
|
|
||||||
$this->invoice = $this->invoice->calc()->getInvoice();
|
// $this->invoice = $this->invoice->calc()->getInvoice();
|
||||||
|
|
||||||
if($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT){
|
// if($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT){
|
||||||
$this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save();
|
// $this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save();
|
||||||
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, 'Invoice balance updated after stale gateway fee removed')->save();
|
// $this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, 'Invoice balance updated after stale gateway fee removed')->save();
|
||||||
}
|
// }
|
||||||
|
|
||||||
return $this;
|
// return $this;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a given gateway token is able
|
* Checks whether a given gateway token is able
|
||||||
|
@ -79,15 +79,18 @@ class InvoiceService
|
|||||||
|
|
||||||
public function addGatewayFee(CompanyGateway $company_gateway, float $amount)
|
public function addGatewayFee(CompanyGateway $company_gateway, float $amount)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->invoice = (new AddGatewayFee($company_gateway, $this->invoice, $amount))->run();
|
$this->invoice = (new AddGatewayFee($company_gateway, $this->invoice, $amount))->run();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Update an invoice balance
|
* Update an invoice balance
|
||||||
|
*
|
||||||
* @param float $balance_adjustment The amount to adjust the invoice by
|
* @param float $balance_adjustment The amount to adjust the invoice by
|
||||||
* a negative amount will REDUCE the invoice balance, a positive amount will INCREASE
|
* a negative amount will REDUCE the invoice balance, a positive amount will INCREASE
|
||||||
* the invoice balance
|
* the invoice balance
|
||||||
|
*
|
||||||
* @return InvoiceService Parent class object
|
* @return InvoiceService Parent class object
|
||||||
*/
|
*/
|
||||||
public function updateBalance($balance_adjustment)
|
public function updateBalance($balance_adjustment)
|
||||||
|
@ -56,6 +56,10 @@ class TriggeredActions extends AbstractService
|
|||||||
$this->sendEmail();
|
$this->sendEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->request->has('mark_sent') && $this->request->input('mark_sent') == 'true'){
|
||||||
|
$this->invoice = $this->invoice->service()->markSent()->save();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->invoice;
|
return $this->invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +37,6 @@ class UpdateBalance extends AbstractService
|
|||||||
|
|
||||||
if ($this->invoice->balance == 0) {
|
if ($this->invoice->balance == 0) {
|
||||||
$this->invoice->status_id = Invoice::STATUS_PAID;
|
$this->invoice->status_id = Invoice::STATUS_PAID;
|
||||||
// $this->save();
|
|
||||||
// event(new InvoiceWasPaid($this, $this->company));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->invoice;
|
return $this->invoice;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user