1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #4470 from turbo124/v5-develop

Custom gateway query.
This commit is contained in:
David Bomba 2020-12-11 08:11:27 +11:00 committed by GitHub
commit f7852c793a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,8 @@ namespace App\Models;
use App\DataMapper\ClientSettings; use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings; use App\DataMapper\CompanySettings;
use App\Models\CompanyGateway;
use App\Models\Gateway;
use App\Models\Presenters\ClientPresenter; use App\Models\Presenters\ClientPresenter;
use App\Services\Client\ClientService; use App\Services\Client\ClientService;
use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\GeneratesCounter;
@ -452,11 +454,15 @@ class Client extends BaseModel implements HasLocalePreference
$gateways = $this->company $gateways = $this->company
->company_gateways ->company_gateways
->whereIn('id', $transformed_ids) ->whereIn('id', $transformed_ids)
->where('gateway_key', '!=', '54faab2ab6e3223dbe848b1686490baa')
->sortby(function ($model) use ($transformed_ids) { //company gateways are sorted in order of priority ->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 return array_search($model->id, $transformed_ids);// this closure sorts for us
}); });
} else { } else {
$gateways = $this->company->company_gateways->where('is_deleted', false); $gateways = $this->company
->company_gateways
->where('gateway_key', '!=', '54faab2ab6e3223dbe848b1686490baa')
->where('is_deleted', false);
} }
$payment_methods = []; $payment_methods = [];
@ -478,11 +484,47 @@ class Client extends BaseModel implements HasLocalePreference
//** Plucks the remaining keys into its own collection //** Plucks the remaining keys into its own collection
$payment_methods_intersect = $payment_methods_collections->intersectByKeys($payment_methods_collections->flatten(1)->unique()); $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.
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 => $type]);
}
}
}
//handle custom gateways as they are not unique'd()---------------------------------------------------------
$payment_urls = []; $payment_urls = [];
foreach ($payment_methods_intersect as $key => $child_array) { foreach ($payment_methods_intersect as $key => $child_array) {
foreach ($child_array as $gateway_id => $gateway_type_id) { foreach ($child_array as $gateway_id => $gateway_type_id) {
$gateway = $gateways->where('id', $gateway_id)->first(); $gateway = CompanyGateway::find($gateway_id);
$fee_label = $gateway->calcGatewayFeeLabel($amount, $this); $fee_label = $gateway->calcGatewayFeeLabel($amount, $this);