1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Merge pull request #4153 from turbo124/v2

Refactor gateway options
This commit is contained in:
David Bomba 2020-10-11 20:17:55 +11:00 committed by GitHub
commit 0fcfe24b54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 100 additions and 77 deletions

View File

@ -236,7 +236,7 @@ class CreateSingleAccount extends Command
$client->id_number = $this->getNextClientNumber($client);
$settings = $client->settings;
$settings->currency_id = (string) rand(1, 79);
$settings->currency_id = "1";
$client->settings = $settings;
$country = Country::all()->random();

View File

@ -287,4 +287,6 @@ class InvoiceSum
{
return $this->getTotalTaxes();
}
}

View File

@ -301,4 +301,5 @@ class InvoiceSumInclusive
{
return $this->getTotalTaxes();
}
}

View File

@ -34,18 +34,7 @@ use Turbo124\Beacon\Facades\LightLogs;
class LoginController extends BaseController
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
/*
/**
* @OA\Tag(
* name="login",
* description="Authentication",

View File

@ -95,6 +95,7 @@ class InvoiceController extends Controller
}
$invoices->map(function ($invoice) {
$invoice->service()->removeUnpaidGatewayFees()->save();
$invoice->balance = Number::formatValue($invoice->balance, $invoice->client->currency());
$invoice->partial = Number::formatValue($invoice->partial, $invoice->client->currency());

View File

@ -163,19 +163,29 @@ class PaymentController extends Controller
$first_invoice = $invoices->first();
$fee_totals = round($gateway->calcGatewayFee($invoice_totals, true), $first_invoice->client->currency()->precision);
$starting_invoice_amount = $first_invoice->amount;
if (!$first_invoice->uses_inclusive_taxes) {
$fee_tax = 0;
$fee_tax += round(($first_invoice->tax_rate1 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
$fee_tax += round(($first_invoice->tax_rate2 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
$fee_tax += round(($first_invoice->tax_rate3 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
// $fee_totals = round($gateway->calcGatewayFee($invoice_totals, true), $first_invoice->client->currency()->precision);
$fee_totals += $fee_tax;
}
// if (!$first_invoice->uses_inclusive_taxes) {
// $fee_tax = 0;
// $fee_tax += round(($first_invoice->tax_rate1 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
// $fee_tax += round(($first_invoice->tax_rate2 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
// $fee_tax += round(($first_invoice->tax_rate3 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
// $fee_totals += $fee_tax;
// }
$first_invoice->service()->addGatewayFee($gateway, $invoice_totals)->save();
/**
*
* The best way to determine the exact gateway fee is to not calculate it in isolation (due to rounding)
* but to simply add it as a line item, and then subtract the starting and finishing amounts of
* the invoice.
*/
$fee_totals = $first_invoice->amount - $starting_invoice_amount;
$payment_hash = new PaymentHash;
$payment_hash->hash = Str::random(128);
$payment_hash->data = $payable_invoices;

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Account",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Activity",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="BulkAction",
* type="array",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="ClientContact",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="ClientGatewayToken",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Client",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="CompanyGateway",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="CompanyLedger",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Company",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="CompanySettings",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="CompanyToken",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="CompanyUser",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="CreditPaymentable",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Credit",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Design",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Error",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Expense",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="FeesAndLimits",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="GroupSetting",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Header(
* header="X-MINIMUM-CLIENT-VERSION",
* description="The API version",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="InvoicePaymentable",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Invoice",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Parameter(
* name="X-Api-Secret",
* in="header",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Payment",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="PaymentTerm",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Paymentable",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Product",
* type="object",

View File

@ -0,0 +1,9 @@
<?php
/**
* @OA\Schema(
* schema="Project",
* type="object",
* @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"),
* @OA\Property(property="name", type="string", example="New Project", description="______"),
* )
*/

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Quote",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="RecurringInvoice",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="RecurringQuote",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="SystemLog",
* type="object",
@ -7,9 +7,9 @@
* @OA\Property(property="company_id", type="string", example="AS3df3A", description="The company hashed id"),
* @OA\Property(property="user_id", type="string", example="AS3df3A", description="The user_id hashed id"),
* @OA\Property(property="client_id", type="string", example="AS3df3A", description="The client_id hashed id"),
* @OA\Property(property="event_id", type="int", example="1", description="The Log Type ID"),
* @OA\Property(property="category_id", type="int", example="1", description="The Category Type ID"),
* @OA\Property(property="type_id", type="int", example="1", description="The Type Type ID"),
* @OA\Property(property="event_id", type="integer", example=1, description="The Log Type ID"),
* @OA\Property(property="category_id", type="integer", example=1, description="The Category Type ID"),
* @OA\Property(property="type_id", type="integer", example=1, description="The Type Type ID"),
* @OA\Property(property="log", type="object", example="{'key':'value'}", description="The json object of the error"),
* @OA\Property(property="updated_at", type="string", example="2", description="______"),
* @OA\Property(property="created_at", type="string", example="2", description="______"),

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="TaxRate",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Template",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="User",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="ValidationError",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="VendorContact",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Vendor",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\Schema(
* schema="Webhook",
* type="object",

View File

@ -1,5 +1,5 @@
<?php
/*
/**
* @OA\OpenApi(
* @OA\Info(
* version="1.0.30",
@ -15,8 +15,8 @@
* )
* ),
* @OA\Server(
* description="InvoiceNinja host",
* url="https://virtserver.swaggerhub.com/InvoiceNinja/invoices/1.0.30"
* description="Example InvoiceNinja base url",
* url="https://ninja.test"
* ),
* @OA\ExternalDocumentation(
* description="http://docs.invoiceninja.com",

View File

@ -286,7 +286,7 @@ class CompanyGateway extends BaseModel
}
if ($fees_and_limits->fee_percent) {
$fee += $amount * $fees_and_limits->fee_percent / 100;
$fee += round(($amount * $fees_and_limits->fee_percent / 100),2);
info("fee after adding fee percent = {$fee}");
}
@ -300,17 +300,17 @@ class CompanyGateway extends BaseModel
/**/
if ($include_taxes) {
if ($fees_and_limits->fee_tax_rate1) {
$fee += $pre_tax_fee * $fees_and_limits->fee_tax_rate1 / 100;
$fee += round(($pre_tax_fee * $fees_and_limits->fee_tax_rate1 / 100),2);
info("fee after adding fee tax 1 = {$fee}");
}
if ($fees_and_limits->fee_tax_rate2) {
$fee += $pre_tax_fee * $fees_and_limits->fee_tax_rate2 / 100;
$fee += round(($pre_tax_fee * $fees_and_limits->fee_tax_rate2 / 100),2);
info("fee after adding fee tax 2 = {$fee}");
}
if ($fees_and_limits->fee_tax_rate3) {
$fee += $pre_tax_fee * $fees_and_limits->fee_tax_rate3 / 100;
$fee += round(($pre_tax_fee * $fees_and_limits->fee_tax_rate3 / 100),2);
info("fee after adding fee tax 3 = {$fee}");
}
}

View File

@ -104,19 +104,22 @@ class Gateway extends StaticModel
{
switch ($this->id) {
case 1:
return ['methods' => [GatewayType::CREDIT_CARD], 'refund' => true, 'token_billing' => true ]; //Authorize.net
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]];//Authorize.net
break;
case 15:
return ['methods' => [GatewayType::PAYPAL], 'refund' => true, 'token_billing' => false ]; //Paypal
return [GatewayType::PAYPAL => ['refund' => true, 'token_billing' => false]]; //Paypal
break;
case 20:
return ['methods' => [GatewayType::CREDIT_CARD, GatewayType::BANK_TRANSFER, GatewayType::ALIPAY, GatewayType::APPLE_PAY], 'refund' => true, 'token_billing' => true ]; //Stripe
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true],
GatewayType::ALIPAY => ['refund' => false, 'token_billing' => false],
GatewayType::APPLE_PAY => ['refund' => false, 'token_billing' => false]]; //Stripe
break;
case 39:
return ['methods' => [GatewayType::CREDIT_CARD], 'refund' => true, 'token_billing' => true ]; //Checkout
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]]; //Checkout
break;
default:
return ['methods' => [], 'refund' => false, 'token_billing' => false];
return [];
break;
}
}

View File

@ -44,6 +44,9 @@ class AddGatewayFee extends AbstractService
{
$gateway_fee = round($this->company_gateway->calcGatewayFee($this->amount), $this->invoice->client->currency()->precision);
if((int)$gateway_fee == 0)
return;
$this->cleanPendingGatewayFees();
if ($gateway_fee > 0) {

View File

@ -212,6 +212,8 @@ class InvoiceService
public function updateStatus()
{
info("invoice balance = {$this->invoice->balance}");
if((int)$this->invoice->balance == 0)
$this->setStatus(Invoice::STATUS_PAID);
@ -232,7 +234,7 @@ class InvoiceService
return $item;
})->toArray();
$this->invoice = $this->invoice->calc()->getInvoice();
//$this->invoice = $this->invoice->calc()->getInvoice();
$this->deletePdf();

View File

@ -67,12 +67,16 @@ class PaymentService
}
});
$this->payment->ledger()->updatePaymentBalance($this->payment->amount);
$this->payment
->ledger()
->updatePaymentBalance($this->payment->amount);
$client->service()
->updateBalance($this->payment->amount)
->updatePaidToDate($this->payment->amount * -1)
->save();
return $this;
}
public function refundPayment(array $data) :?Payment

View File

@ -31,7 +31,6 @@ class UpdateGatewayTableVisibleColumn extends Migration
});
Schema::table('expenses', function ($t){
$t->renameColumn('invoice_category_id', 'category_id');
});