mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Gateway fees for PayPal
This commit is contained in:
parent
62e0e2e466
commit
0c5d291193
@ -32,6 +32,8 @@ class PayPalExpressPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
private $omnipay_gateway;
|
private $omnipay_gateway;
|
||||||
|
|
||||||
|
private float $fee = 0;
|
||||||
|
|
||||||
const SYSTEM_LOG_TYPE = SystemLog::TYPE_PAYPAL;
|
const SYSTEM_LOG_TYPE = SystemLog::TYPE_PAYPAL;
|
||||||
|
|
||||||
public function gatewayTypes()
|
public function gatewayTypes()
|
||||||
@ -173,11 +175,17 @@ class PayPalExpressPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
public function generatePaymentDetails(array $data)
|
public function generatePaymentDetails(array $data)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$_invoice = collect($this->payment_hash->data->invoices)->first();
|
||||||
|
$invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id));
|
||||||
|
|
||||||
|
$this->fee = $this->feeCalc($invoice, $data['total']['amount_with_fee']);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'currency' => $this->client->getCurrencyCode(),
|
'currency' => $this->client->getCurrencyCode(),
|
||||||
'transactionType' => 'Purchase',
|
'transactionType' => 'Purchase',
|
||||||
'clientIp' => request()->getClientIp(),
|
'clientIp' => request()->getClientIp(),
|
||||||
'amount' => $data['total']['amount_with_fee'],
|
'amount' => $data['total']['amount_with_fee'] + $this->fee,
|
||||||
'returnUrl' => route('client.payments.response', [
|
'returnUrl' => route('client.payments.response', [
|
||||||
'company_gateway_id' => $this->company_gateway->id,
|
'company_gateway_id' => $this->company_gateway->id,
|
||||||
'payment_hash' => $this->payment_hash->hash,
|
'payment_hash' => $this->payment_hash->hash,
|
||||||
@ -200,8 +208,6 @@ class PayPalExpressPaymentDriver extends BaseDriver
|
|||||||
$_invoice = collect($this->payment_hash->data->invoices)->first();
|
$_invoice = collect($this->payment_hash->data->invoices)->first();
|
||||||
$invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id));
|
$invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id));
|
||||||
|
|
||||||
$line_item = collect($invoice->line_items)->first();
|
|
||||||
|
|
||||||
$items = [];
|
$items = [];
|
||||||
|
|
||||||
$items[] = new Item([
|
$items[] = new Item([
|
||||||
@ -211,8 +217,44 @@ class PayPalExpressPaymentDriver extends BaseDriver
|
|||||||
'quantity' => 1,
|
'quantity' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
if($this->fee > 0.1){
|
||||||
|
|
||||||
|
$items[] = new Item([
|
||||||
|
'name' => " ",
|
||||||
|
'description' => ctrans('texts.gateway_fee_description'),
|
||||||
|
'price' => $this->fee,
|
||||||
|
'quantity' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return $items;
|
return $items;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function feeCalc($invoice, $invoice_total)
|
||||||
|
{
|
||||||
|
|
||||||
|
$invoice->service()->removeUnpaidGatewayFees();
|
||||||
|
$invoice = $invoice->fresh();
|
||||||
|
|
||||||
|
$balance = floatval($invoice->balance);
|
||||||
|
|
||||||
|
$_updated_invoice = $invoice->service()->addGatewayFee($this->company_gateway, GatewayType::PAYPAL, $invoice_total)->save();
|
||||||
|
|
||||||
|
if(floatval($_updated_invoice->balance) > $balance){
|
||||||
|
|
||||||
|
$fee = floatval($_updated_invoice->balance) - $balance;
|
||||||
|
|
||||||
|
$this->payment_hash->fee_total = $fee;
|
||||||
|
$this->payment_hash->save();
|
||||||
|
|
||||||
|
return $fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user