Skip to content

Commit

Permalink
Merge pull request #14 from paynl/feature/PLUG-872
Browse files Browse the repository at this point in the history
PLUG_872 - Settings fix
  • Loading branch information
woutse authored Mar 11, 2022
2 parents 5879e80 + 932b92b commit c5891c1
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
75 changes: 73 additions & 2 deletions paynlpaymentmethods/paynlpaymentmethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,7 @@ private function getPaymentMethodsCombined()
$this->sdkLogin();
$paymentmethods = \Paynl\Paymentmethods::getList();
$paymentmethods = (array)$paymentmethods;
$languages = Language::getLanguages(true);
foreach ($savedPaymentMethods as $paymentmethod) {
if (isset($paymentmethods[$paymentmethod->id])) {
# The paymentmethod allready exists in the config. Check if fields are set..
Expand All @@ -1574,22 +1575,92 @@ private function getPaymentMethodsCombined()
$changed = true;
}

if (!isset($paymentmethod->limit_countries)) {
$paymentmethod->limit_countries = false;
$changed = true;
}

if (!isset($paymentmethod->allowed_countries)) {
$paymentmethod->allowed_countries = [];
$changed = true;
}
if (isset($paymentmethod->allowed_countries) && !is_array($paymentmethod->allowed_countries)) {
$paymentmethod->allowed_countries = [];
$changed = true;
}

if (!isset($paymentmethod->limit_carriers)) {
$paymentmethod->limit_carriers = false;
$changed = true;
}

if (!isset($paymentmethod->allowed_carriers)) {
$paymentmethod->allowed_carriers = [];
$changed = true;
}
if (isset($paymentmethod->allowed_carriers) && !is_array($paymentmethod->allowed_carriers)) {
$paymentmethod->allowed_carriers = [];
$changed = true;
}

if (!isset($paymentmethod->fee_percentage)) {
$paymentmethod->fee_percentage = false;
$changed = true;
}

if (!isset($paymentmethod->fee_value)) {
$paymentmethod->fee_value = '';
$changed = true;
}

if (!isset($paymentmethod->customer_type)) {
$paymentmethod->customer_type = 'both';
$changed = true;
}

foreach ($languages as $language) {
$key_name = 'name_' . $language['iso_code'];
if (!isset($paymentmethod->$key_name)) {
$paymentmethod->$key_name = '';
$changed = true;
}
$key_description = 'description_' . $language['iso_code'];
if (!isset($paymentmethod->$key_description)) {
$paymentmethod->$key_description = '';
$changed = true;
}
}

$resultArray[] = $paymentmethod;
unset($paymentmethods[$paymentmethod->id]);
}
}

# Nieuwe payment methods voorzien van standaard values.
foreach ($paymentmethods as $paymentmethod) {
$resultArray[] = (object) [
$defaultArray = [
'id' => $paymentmethod['id'],
'name' => empty($paymentmethod['visibleName']) ? $paymentmethod['name'] : $paymentmethod['visibleName'],
'enabled' => false,
'min_amount' => isset($paymentmethod['min_amount']) ? intval($paymentmethod['min_amount'] / 100) : null,
'max_amount' => isset($paymentmethod['max_amount']) ? intval($paymentmethod['max_amount'] / 100) : null,
'description' => isset($paymentmethod['brand']['public_description']) ? $paymentmethod['brand']['public_description'] : '',
'brand_id' => isset($paymentmethod['brand']['id']) ? $paymentmethod['brand']['id'] : ''
'brand_id' => isset($paymentmethod['brand']['id']) ? $paymentmethod['brand']['id'] : '',
'limit_countries' => false,
'allowed_countries' => [],
'limit_carriers' => false,
'allowed_carriers' => [],
'fee_percentage' => false,
'fee_value' => '',
'customer_type' => 'both'
];

foreach ($languages as $language) {
$defaultArray['name_' . $language['iso_code']] = '';
$defaultArray['description_' . $language['iso_code']] = '';
}

$resultArray[] = (object) $defaultArray;
$changed = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@
//Add all select data
$(this).find('select').each(function(){
$paymentmethod[$(this).attr("name")] = $(this).find("option:selected").val();
if ($(this).prop('multiple')) {
var values = new Array();
$(this).find("option:selected").each(function() {
values.push(this.value);
});
$paymentmethod[$(this).attr("name")] = values;
}
});
$paymentmethods.push($paymentmethod);
}
Expand Down

0 comments on commit c5891c1

Please sign in to comment.