Fixes for company gateway payment method resolution

This commit is contained in:
David Bomba 2021-01-27 12:06:25 +11:00
parent 6420658b3e
commit b5ff2d8a02
9 changed files with 217 additions and 259 deletions

View File

@ -12,6 +12,7 @@
namespace App\Console\Commands;
use App\DataMapper\CompanySettings;
use App\DataMapper\FeesAndLimits;
use App\Events\Invoice\InvoiceWasCreated;
use App\Factory\InvoiceFactory;
use App\Factory\InvoiceItemFactory;
@ -491,6 +492,7 @@ class CreateSingleAccount extends Command
private function createGateways($company, $user)
{
if (config('ninja.testvars.stripe') && ($this->gateway == 'all' || $this->gateway == 'stripe')) {
$cg = new CompanyGateway;
$cg->company_id = $company->id;
$cg->user_id = $user->id;
@ -502,16 +504,15 @@ class CreateSingleAccount extends Command
$cg->config = encrypt(config('ninja.testvars.stripe'));
$cg->save();
// $cg = new CompanyGateway;
// $cg->company_id = $company->id;
// $cg->user_id = $user->id;
// $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
// $cg->require_cvv = true;
// $cg->require_billing_address = true;
// $cg->require_shipping_address = true;
// $cg->update_details = true;
// $cg->config = encrypt(config('ninja.testvars.stripe'));
// $cg->save();
$gateway_types = $cg->driver(new Client)->gatewayTypes();
$fees_and_limits = new \stdClass;
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
if (config('ninja.testvars.paypal') && ($this->gateway == 'all' || $this->gateway == 'paypal')) {
@ -525,6 +526,14 @@ class CreateSingleAccount extends Command
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.paypal'));
$cg->save();
$gateway_types = $cg->driver(new Client)->gatewayTypes();
$fees_and_limits = new \stdClass;
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
if (config('ninja.testvars.checkout') && ($this->gateway == 'all' || $this->gateway == 'checkout')) {
@ -538,6 +547,14 @@ class CreateSingleAccount extends Command
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.checkout'));
$cg->save();
$gateway_types = $cg->driver(new Client)->gatewayTypes();
$fees_and_limits = new \stdClass;
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
if (config('ninja.testvars.authorize') && ($this->gateway == 'all' || $this->gateway == 'authorizenet')) {
@ -551,6 +568,14 @@ class CreateSingleAccount extends Command
$cg->update_details = true;
$cg->config = encrypt(config('ninja.testvars.authorize'));
$cg->save();
$gateway_types = $cg->driver(new Client)->gatewayTypes();
$fees_and_limits = new \stdClass;
$fees_and_limits->{$gateway_types[0]} = new FeesAndLimits;
$cg->fees_and_limits = $fees_and_limits;
$cg->save();
}
}
}

View File

@ -437,133 +437,133 @@ class Client extends BaseModel implements HasLocalePreference
* @return array Array of payment labels and urls
* @deprecated 5.0.38 - see service()->getPaymentMethods($amount);
*/
public function getPaymentMethods($amount) :array
{
//this method will get all the possible gateways a client can pay with
//but we also need to consider payment methods that are already stored
//so we MUST filter the company gateways and remove duplicates.
// public function getPaymentMethods($amount) :array
// {
// //this method will get all the possible gateways a client can pay with
// //but we also need to consider payment methods that are already stored
// //so we MUST filter the company gateways and remove duplicates.
//Also need to harvest the list of client gateway tokens and present these
//for instant payment
// //Also need to harvest the list of client gateway tokens and present these
// //for instant payment
$company_gateways = $this->getSetting('company_gateway_ids');
// $company_gateways = $this->getSetting('company_gateway_ids');
//we need to check for "0" here as we disable a payment gateway for a client with the number "0"
if ($company_gateways || $company_gateways == '0') {
$transformed_ids = $this->transformKeys(explode(',', $company_gateways));
$gateways = $this->company
->company_gateways
->whereIn('id', $transformed_ids)
->where('gateway_key', '!=', '54faab2ab6e3223dbe848b1686490baa')
->sortby(function ($model) use ($transformed_ids) { //company gateways are sorted in order of priority
return array_search($model->id, $transformed_ids);// this closure sorts for us
});
} else {
$gateways = $this->company
->company_gateways
->where('gateway_key', '!=', '54faab2ab6e3223dbe848b1686490baa')
->where('is_deleted', false);
}
// //we need to check for "0" here as we disable a payment gateway for a client with the number "0"
// if ($company_gateways || $company_gateways == '0') {
// $transformed_ids = $this->transformKeys(explode(',', $company_gateways));
// $gateways = $this->company
// ->company_gateways
// ->whereIn('id', $transformed_ids)
// ->where('gateway_key', '!=', '54faab2ab6e3223dbe848b1686490baa')
// ->sortby(function ($model) use ($transformed_ids) { //company gateways are sorted in order of priority
// return array_search($model->id, $transformed_ids);// this closure sorts for us
// });
// } else {
// $gateways = $this->company
// ->company_gateways
// ->where('gateway_key', '!=', '54faab2ab6e3223dbe848b1686490baa')
// ->where('is_deleted', false);
// }
$payment_methods = [];
// $payment_methods = [];
foreach ($gateways as $gateway) {
foreach ($gateway->driver($this)->gatewayTypes() as $type) {
if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) {
if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $amount)) {
$payment_methods[] = [$gateway->id => $type];
}
} else {
$payment_methods[] = [$gateway->id => $type];
}
}
}
// foreach ($gateways as $gateway) {
// foreach ($gateway->driver($this)->gatewayTypes() as $type) {
// if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) {
// if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $amount)) {
// $payment_methods[] = [$gateway->id => $type];
// }
// } else {
// $payment_methods[] = [$gateway->id => $type];
// }
// }
// }
$payment_methods_collections = collect($payment_methods);
// $payment_methods_collections = collect($payment_methods);
//** Plucks the remaining keys into its own collection
$payment_methods_intersect = $payment_methods_collections->intersectByKeys($payment_methods_collections->flatten(1)->unique());
// //** Plucks the remaining keys into its own collection
// $payment_methods_intersect = $payment_methods_collections->intersectByKeys($payment_methods_collections->flatten(1)->unique());
// handle custom gateways as they are not unique'd()---------------------------------------------------------
// we need to split the query here as we allow multiple custom gateways, so we must show all of them, they query logic
// above only pulls in unique gateway types.. ie.. we only allow 1 credit card gateway, but many custom gateways.
// // handle custom gateways as they are not unique'd()---------------------------------------------------------
// // we need to split the query here as we allow multiple custom gateways, so we must show all of them, they query logic
// // above only pulls in unique gateway types.. ie.. we only allow 1 credit card gateway, but many custom gateways.
if ($company_gateways || $company_gateways == '0') {
$transformed_ids = $this->transformKeys(explode(',', $company_gateways));
$gateways = $this->company
->company_gateways
->whereIn('id', $transformed_ids)
->where('gateway_key', '=', '54faab2ab6e3223dbe848b1686490baa')
->sortby(function ($model) use ($transformed_ids) { //company gateways are sorted in order of priority
return array_search($model->id, $transformed_ids);// this closure sorts for us
});
} else {
$gateways = $this->company
->company_gateways
->where('gateway_key', '=', '54faab2ab6e3223dbe848b1686490baa')
->where('is_deleted', false);
}
// if ($company_gateways || $company_gateways == '0') {
// $transformed_ids = $this->transformKeys(explode(',', $company_gateways));
// $gateways = $this->company
// ->company_gateways
// ->whereIn('id', $transformed_ids)
// ->where('gateway_key', '=', '54faab2ab6e3223dbe848b1686490baa')
// ->sortby(function ($model) use ($transformed_ids) { //company gateways are sorted in order of priority
// return array_search($model->id, $transformed_ids);// this closure sorts for us
// });
// } else {
// $gateways = $this->company
// ->company_gateways
// ->where('gateway_key', '=', '54faab2ab6e3223dbe848b1686490baa')
// ->where('is_deleted', false);
// }
//note we have to use GatewayType::CREDIT_CARD as alias for CUSTOM
foreach ($gateways as $gateway) {
foreach ($gateway->driver($this)->gatewayTypes() as $type) {
if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) {
if ($this->validGatewayForAmount($gateway->fees_and_limits->{GatewayType::CREDIT_CARD}, $amount)) {
$payment_methods_intersect->push([$gateway->id => $type]);
}
} else {
$payment_methods_intersect->push([$gateway->id => NULL]);
}
}
}
// //note we have to use GatewayType::CREDIT_CARD as alias for CUSTOM
// foreach ($gateways as $gateway) {
// foreach ($gateway->driver($this)->gatewayTypes() as $type) {
// if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) {
// if ($this->validGatewayForAmount($gateway->fees_and_limits->{GatewayType::CREDIT_CARD}, $amount)) {
// $payment_methods_intersect->push([$gateway->id => $type]);
// }
// } else {
// $payment_methods_intersect->push([$gateway->id => NULL]);
// }
// }
// }
//handle custom gateways as they are not unique'd()---------------------------------------------------------
// //handle custom gateways as they are not unique'd()---------------------------------------------------------
$payment_urls = [];
// $payment_urls = [];
foreach ($payment_methods_intersect as $key => $child_array) {
foreach ($child_array as $gateway_id => $gateway_type_id) {
$gateway = CompanyGateway::find($gateway_id);
// foreach ($payment_methods_intersect as $key => $child_array) {
// foreach ($child_array as $gateway_id => $gateway_type_id) {
// $gateway = CompanyGateway::find($gateway_id);
$fee_label = $gateway->calcGatewayFeeLabel($amount, $this);
// $fee_label = $gateway->calcGatewayFeeLabel($amount, $this);
if(!$gateway_type_id){
// if(!$gateway_type_id){
$payment_urls[] = [
'label' => $gateway->getConfigField('name') . $fee_label,
'company_gateway_id' => $gateway_id,
'gateway_type_id' => GatewayType::CREDIT_CARD,
];
}
else
{
$payment_urls[] = [
'label' => $gateway->getTypeAlias($gateway_type_id) . $fee_label,
'company_gateway_id' => $gateway_id,
'gateway_type_id' => $gateway_type_id,
];
}
}
}
// $payment_urls[] = [
// 'label' => $gateway->getConfigField('name') . $fee_label,
// 'company_gateway_id' => $gateway_id,
// 'gateway_type_id' => GatewayType::CREDIT_CARD,
// ];
// }
// else
// {
// $payment_urls[] = [
// 'label' => $gateway->getTypeAlias($gateway_type_id) . $fee_label,
// 'company_gateway_id' => $gateway_id,
// 'gateway_type_id' => $gateway_type_id,
// ];
// }
// }
// }
if (($this->getSetting('use_credits_payment') == 'option' || $this->getSetting('use_credits_payment') == 'always') && $this->service()->getCreditBalance() > 0) {
// if (($this->getSetting('use_credits_payment') == 'option' || $this->getSetting('use_credits_payment') == 'always') && $this->service()->getCreditBalance() > 0) {
// Show credits as only payment option if both statements are true.
if (
$this->service()->getCreditBalance() > $amount
&& $this->getSetting('use_credits_payment') == 'always') {
$payment_urls = [];
}
// // Show credits as only payment option if both statements are true.
// if (
// $this->service()->getCreditBalance() > $amount
// && $this->getSetting('use_credits_payment') == 'always') {
// $payment_urls = [];
// }
$payment_urls[] = [
'label' => ctrans('texts.apply_credit'),
'company_gateway_id' => CompanyGateway::GATEWAY_CREDIT,
'gateway_type_id' => GatewayType::CREDIT,
];
}
// $payment_urls[] = [
// 'label' => ctrans('texts.apply_credit'),
// 'company_gateway_id' => CompanyGateway::GATEWAY_CREDIT,
// 'gateway_type_id' => GatewayType::CREDIT,
// ];
// }
return $payment_urls;
}
// return $payment_urls;
// }
public function validGatewayForAmount($fees_and_limits_for_payment_type, $amount) :bool
{

View File

@ -247,7 +247,7 @@ class CompanyGateway extends BaseModel
public function getFeesAndLimits($gateway_type_id)
{
if (is_null($this->fees_and_limits) || empty($this->fees_and_limits)) {
if (is_null($this->fees_and_limits) || empty($this->fees_and_limits) || !property_exists($this->fees_and_limits, $gateway_type_id)) {
return false;
}

View File

@ -95,32 +95,17 @@ class StripePaymentDriver extends BaseDriver
{
$types = [
GatewayType::CREDIT_CARD,
GatewayType::BANK_TRANSFER,
GatewayType::SEPA,
GatewayType::CRYPTO,
GatewayType::ALIPAY,
GatewayType::APPLE_PAY,
];
if ($this->company_gateway->getSofortEnabled() && $this->invitation && $this->client() && isset($this->client()->country) && in_array($this->client()->country, ['AUT', 'BEL', 'DEU', 'ITA', 'NLD', 'ESP'])) {
$types[] = GatewayType::SOFORT;
}
if ($this->company_gateway->getAchEnabled()) {
$types[] = GatewayType::BANK_TRANSFER;
}
if ($this->company_gateway->getSepaEnabled()) {
$types[] = GatewayType::SEPA;
}
if ($this->company_gateway->getBitcoinEnabled()) {
$types[] = GatewayType::CRYPTO;
}
if ($this->company_gateway->getAlipayEnabled()) {
$types[] = GatewayType::ALIPAY;
}
if ($this->company_gateway->getApplePayEnabled()) {
$types[] = GatewayType::APPLE_PAY;
}
return $types;
}

View File

@ -89,7 +89,6 @@ class PaymentMethod
}
return $this;
}
@ -134,10 +133,16 @@ class PaymentMethod
$this->payment_methods = [];
foreach ($this->gateways as $gateway) {
foreach ($gateway->driver($this->client)->gatewayTypes() as $type) {
if (isset($gateway->fees_and_limits) && property_exists($gateway->fees_and_limits, $type)) {
if ($this->validGatewayForAmount($gateway->fees_and_limits->{$type}, $this->amount) && $gateway->fees_and_limits->{$type}->is_enabled) {
if($type == GatewayType::BANK_TRANSFER);
nlog($gateway->fees_and_limits);
$this->payment_methods[] = [$gateway->id => $type];
}

View File

@ -39,74 +39,14 @@ class ClientModelTest extends TestCase
}
}
public function testPaymentMethods()
public function testPaymentMethodsWithCreditsEnforced()
{
$amount = 40;
$company_gateways = $this->client->getSetting('company_gateway_ids');
$payment_methods = $this->client->service()->getPaymentMethods(40);
//todo create a test where we actually SET a value in the settings->company_gateways object and test if we can harvest.
$this->assertEquals(1, count($payment_methods));
if ($company_gateways) {
$gateways = $this->company->company_gateways->whereIn('id', $payment_gateways);
} else {
$gateways = $this->company->company_gateways;
}
$this->assertNotNull($gateways);
$pre_count = $gateways->count();
$gateways->filter(function ($method) use ($amount) {
if ($method->min_limit !== null && $amount < $method->min_limit) {
return false;
}
if ($method->max_limit !== null && $amount > $method->min_limit) {
return false;
}
});
$post_count = $gateways->count();
$this->assertEquals($pre_count, $post_count);
$payment_methods = [];
foreach ($gateways as $gateway) {
foreach ($gateway->driver($this->client)->gatewayTypes() as $type) {
$payment_methods[] = [$gateway->id => $type];
}
}
$this->assertEquals(8, count($payment_methods));
$payment_methods_collections = collect($payment_methods);
//** Plucks the remaining keys into its own collection
$payment_methods_intersect = $payment_methods_collections->intersectByKeys($payment_methods_collections->flatten(1)->unique());
$this->assertEquals(4, $payment_methods_intersect->count());
$payment_urls = [];
foreach ($payment_methods_intersect as $key => $child_array) {
foreach ($child_array as $gateway_id => $gateway_type_id) {
$gateway = $gateways->where('id', $gateway_id)->first();
$this->assertNotNull($gateway);
$fee_label = $gateway->calcGatewayFeeLabel($amount, $this->client);
$payment_urls[] = [
'label' => ctrans('texts.'.$gateway->getTypeAlias($gateway_type_id)).$fee_label,
'url' => URL::signedRoute('client.payments.process', [
'company_gateway_id' => $gateway_id,
'gateway_type_id' => $gateway_type_id, ]),
];
}
}
$this->assertEquals(4, count($payment_urls));
}
}

View File

@ -53,6 +53,8 @@ class CompanyGatewayResolutionTest extends TestCase
$this->withoutExceptionHandling();
CompanyGateway::whereNotNull('id')->delete();
$data = [];
$data[1]['min_limit'] = -1;
$data[1]['max_limit'] = -1;
@ -66,6 +68,7 @@ class CompanyGatewayResolutionTest extends TestCase
$data[1]['fee_tax_rate3'] = 10;
$data[1]['adjust_fee_percent'] = true;
$data[1]['fee_cap'] = 0;
$data[1]['is_enabled'] = true;
$data[2]['min_limit'] = -1;
$data[2]['max_limit'] = -1;
@ -79,10 +82,10 @@ class CompanyGatewayResolutionTest extends TestCase
$data[2]['fee_tax_rate3'] = 10;
$data[2]['adjust_fee_percent'] = true;
$data[2]['fee_cap'] = 0;
$data[2]['is_enabled'] = true;
//disable ach here
$json_config = json_decode(config('ninja.testvars.stripe'));
$json_config->enable_ach = "0";
$this->cg = new CompanyGateway;
$this->cg->company_id = $this->company->id;
@ -104,8 +107,6 @@ class CompanyGatewayResolutionTest extends TestCase
{
$fee = $this->cg->calcGatewayFee(10, GatewayType::CREDIT_CARD, false);
$this->assertEquals(0.2, $fee);
// $fee = $this->cg->calcGatewayFee(10, GatewayType::CREDIT_CARD, false);
// $this->assertEquals(0.1, $fee);
}
/**
@ -121,35 +122,68 @@ class CompanyGatewayResolutionTest extends TestCase
public function testAvailablePaymentMethodsCount()
{
$amount = 10;
$payment_methods = [];
$this->assertInstanceOf("\\stdClass", $this->cg->fees_and_limits);
$this->assertObjectHasAttribute('min_limit', $this->cg->fees_and_limits->{1});
foreach ($this->cg->driver($this->client)->gatewayTypes() as $type) {
if (property_exists($this->cg->fees_and_limits, $type)) {
if ($this->client->validGatewayForAmount($this->cg->fees_and_limits->{$type}, $amount)) {
$payment_methods[] = [$this->cg->id => $type];
}
} else {
$payment_methods[] = [$this->cg->id => $type];
}
}
$payment_methods = $this->client->service()->getPaymentMethods($amount);
$this->assertEquals(3, count($payment_methods));
}
public function testAddAchBackIntoMethods()
public function testRemoveMethods()
{
$this->assertEquals(3, count($this->cg->driver($this->client)->gatewayTypes()));
$amount = 10;
CompanyGateway::whereNotNull('id')->delete();
$cg_config = json_decode(decrypt($this->cg->config));
$cg_config->enable_ach = "1";
$this->cg->config = encrypt(json_encode($cg_config));
$data = [];
$data[1]['min_limit'] = -1;
$data[1]['max_limit'] = -1;
$data[1]['fee_amount'] = 0.00;
$data[1]['fee_percent'] = 2;
$data[1]['fee_tax_name1'] = 'GST';
$data[1]['fee_tax_rate1'] = 10;
$data[1]['fee_tax_name2'] = 'GST';
$data[1]['fee_tax_rate2'] = 10;
$data[1]['fee_tax_name3'] = 'GST';
$data[1]['fee_tax_rate3'] = 10;
$data[1]['adjust_fee_percent'] = true;
$data[1]['fee_cap'] = 0;
$data[1]['is_enabled'] = true;
$data[2]['min_limit'] = -1;
$data[2]['max_limit'] = -1;
$data[2]['fee_amount'] = 0.00;
$data[2]['fee_percent'] = 1;
$data[2]['fee_tax_name1'] = 'GST';
$data[2]['fee_tax_rate1'] = 10;
$data[2]['fee_tax_name2'] = 'GST';
$data[2]['fee_tax_rate2'] = 10;
$data[2]['fee_tax_name3'] = 'GST';
$data[2]['fee_tax_rate3'] = 10;
$data[2]['adjust_fee_percent'] = true;
$data[2]['fee_cap'] = 0;
$data[2]['is_enabled'] = false;
//disable ach here
$json_config = json_decode(config('ninja.testvars.stripe'));
$this->cg = new CompanyGateway;
$this->cg->company_id = $this->company->id;
$this->cg->user_id = $this->user->id;
$this->cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
$this->cg->require_cvv = true;
$this->cg->require_billing_address = true;
$this->cg->require_shipping_address = true;
$this->cg->update_details = true;
$this->cg->config = encrypt(json_encode($json_config));
$this->cg->fees_and_limits = $data;
$this->cg->save();
$this->assertEquals(4, count($this->cg->driver($this->client)->gatewayTypes()));
// nlog($this->client->service()->getPaymentMethods($amount));
$this->assertEquals(2, count($this->client->service()->getPaymentMethods($amount)));
// nlog(print_r($this->client->getPaymentMethods(10),1));
}
}

View File

@ -57,6 +57,7 @@ class CompanyGatewayTest extends TestCase
$data[1]['fee_tax_rate3'] = 0;
$data[1]['adjust_fee_percent'] = true;
$data[1]['fee_cap'] = 0;
$data[1]['is_enabled'] = true;
$cg = new CompanyGateway;
$cg->company_id = $this->company->id;
@ -128,6 +129,7 @@ class CompanyGatewayTest extends TestCase
$data[1]['fee_tax_rate3'] = 0;
$data[1]['adjust_fee_percent'] = true;
$data[1]['fee_cap'] = 0;
$data[1]['is_enabled'] = true;
$cg = new CompanyGateway;
$cg->company_id = $this->company->id;
@ -166,6 +168,7 @@ class CompanyGatewayTest extends TestCase
$data[1]['fee_tax_rate3'] = 10;
$data[1]['adjust_fee_percent'] = true;
$data[1]['fee_cap'] = 0;
$data[1]['is_enabled'] = true;
$cg = new CompanyGateway;
$cg->company_id = $this->company->id;
@ -188,41 +191,5 @@ class CompanyGatewayTest extends TestCase
/*simple pro rata*/
$fees_and_limits = $cg->getFeesAndLimits(GatewayType::CREDIT_CARD);
/*Calculate all subcomponents of the fee*/
// $fee_component_amount = $fees_and_limits->fee_amount ?: 0;
// $fee_component_percent = $fees_and_limits->fee_percent ? ($total * $fees_and_limits->fee_percent / 100) : 0;
// $combined_fee_component = $fee_component_amount + $fee_component_percent;
// $fee_component_tax_name1 = $fees_and_limits->fee_tax_name1 ?: '';
// $fee_component_tax_rate1 = $fees_and_limits->fee_tax_rate1 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate1 / 100) : 0;
// $fee_component_tax_name2 = $fees_and_limits->fee_tax_name2 ?: '';
// $fee_component_tax_rate2 = $fees_and_limits->fee_tax_rate2 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate2 / 100) : 0;
// $fee_component_tax_name3 = $fees_and_limits->fee_tax_name3 ?: '';
// $fee_component_tax_rate3 = $fees_and_limits->fee_tax_rate3 ? ($combined_fee_component * $fees_and_limits->fee_tax_rate3 / 100) : 0;
// $pro_rata_fee = round($total_gateway_fee / $total_invoice_count,2);
// while($pro_rata_fee * $total_invoice_count != $total_gateway_fee) {
// //nudge one pro rata fee until we get the desired amount
// $sub_total_fees = ($pro_rata_fee*($total_invoice_count--));
// //work out if we have to nudge up or down
// if($pro_rata_fee*$total_invoice_count > $total_gateway_fee) {
// //nudge DOWN
// $pro_rata_fee - 0.01; //this will break if the currency doesn't have decimals
// }
// else {
// //nudge UP
// }
// }
// $this->assertEquals(1.56, $pro_rata_fee*$total_invoice_count);
}
}

View File

@ -546,6 +546,8 @@ trait MockAccountData
$data[1]['fee_tax_name3'] = '';
$data[1]['fee_tax_rate3'] = 0;
$data[1]['fee_cap'] = '';
$data[1]['is_enabled'] = true;
$cg = new CompanyGateway;
$cg->company_id = $this->company->id;
$cg->user_id = $user_id;