Skip to content

Commit

Permalink
Merge pull request #834 from buckaroo-it/BP-2964-limit-klarna-country…
Browse files Browse the repository at this point in the history
…-and-currency-settings

BP-2964 - limit klarna country and currency settings
  • Loading branch information
LucianTuriacArnia authored Oct 26, 2023
2 parents 23f1fde + e85340e commit cd89fb8
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Model/ConfigProvider/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ public function getParsedLabel(Store $store, OrderInterface $order, string $labe
return $store->getName();
}

$label = preg_replace('/\{order_number\}/', $order->getIncrementId(), $label);
$label = preg_replace('/\{shop_name\}/', $store->getName(), $label);
$label = str_replace('{order_number}', $order->getIncrementId(), $label);
$label = str_replace('{shop_name}', $order->getIncrementId(), $label);

$products = $order->getItems();
if (count($products)) {
$label = preg_replace('/\{product_name\}/', array_values($products)[0]->getName(), $label);
$label = str_replace('{product_name}', array_values($products)[0]->getName(), $label);
}
return mb_substr($label, 0, 244);
}
Expand Down
31 changes: 31 additions & 0 deletions Model/ConfigProvider/Method/Klarna.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ class Klarna extends AbstractConfigProvider
{
public const CODE = 'buckaroo_magento2_klarna';

/**
* @var array
*/
protected $allowedCurrencies = [
'EUR',
'GBP',
'DKK',
'SEK',
'NOK',
'CHF',
];

/**
* @var array
*/
protected $allowedCountries = [
'NL',
'DE',
'AT',
'GB',
'DK',
'SE',
'NO',
'FI',
'IT',
'FR',
'ES',
'CH',
'BE',
];

/**
* @inheritdoc
*
Expand Down
24 changes: 24 additions & 0 deletions Model/ConfigProvider/Method/Klarnain.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ class Klarnain extends AbstractConfigProvider
{
public const CODE = 'buckaroo_magento2_klarnain';

/**
* @var array
*/
protected $allowedCurrencies = [
'EUR',
'GBP',
'DKK',
'SEK',
'NOK'
];

/**
* @var array
*/
protected $allowedCountries = [
'DE',
'AT',
'GB',
'DK',
'SE',
'NO',
'FI',
];

/**
* @inheritdoc
*
Expand Down
35 changes: 35 additions & 0 deletions Model/ConfigProvider/Method/Klarnakp.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,41 @@ class Klarnakp extends AbstractConfigProvider
public const XPATH_KLARNAKP_CREATE_INVOICE_BY_SHIP =
'payment/buckaroo_magento2_klarnakp/create_invoice_after_shipment';

/**
* @var array
*/
protected $allowedCurrencies = [
'EUR',
'AUD',
'CAD',
'CHF',
'DKK',
'GBP',
'NOK',
'SEK'
];

/**
* @var array
*/
protected $allowedCountries = [
'NL',
'BE',
'DE',
'AT',
'FI',
'IT',
'FR',
'ES',
'AU',
'CA',
'CH',
'DK',
'GB',
'NO',
'SE'
];

/**
* @inheritdoc
*
Expand Down
4 changes: 2 additions & 2 deletions etc/adminhtml/system/payment_methods/klarna.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
<field id="specificcountry" translate="label" type="multiselect" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment from Specific Country</label>
<comment><![CDATA[Only available when set to 'specific countries'.]]></comment>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<source_model>Buckaroo\Magento2\Model\Config\Source\AllowedCountries::klarna</source_model>
<can_be_empty>1</can_be_empty>
<config_path>payment/buckaroo_magento2_klarna/specificcountry</config_path>
<depends>
Expand All @@ -164,7 +164,7 @@
<comment><![CDATA[Select payment method specific currencies.]]></comment>
<tooltip>Your contract with Buckaroo must allow for the selected currencies to be used with this payment method.</tooltip>
<config_path>payment/buckaroo_magento2_klarna/allowed_currencies</config_path>
<source_model>Buckaroo\Magento2\Model\Config\Source\AllowedCurrencies::ideal</source_model>
<source_model>Buckaroo\Magento2\Model\Config\Source\AllowedCurrencies::klarna</source_model>
<backend_model>Buckaroo\Magento2\Model\Config\Backend\AllowedCurrencies</backend_model>
</field>
</group>
Expand Down
4 changes: 2 additions & 2 deletions etc/adminhtml/system/payment_methods/klarnain.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<field id="specificcountry" translate="label" type="multiselect" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment from Specific Country</label>
<comment><![CDATA[Only available when set to 'specific countries'.]]></comment>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<source_model>Buckaroo\Magento2\Model\Config\Source\AllowedCountries::klarnain</source_model>
<can_be_empty>1</can_be_empty>
<config_path>payment/buckaroo_magento2_klarnain/specificcountry</config_path>
<depends>
Expand All @@ -165,7 +165,7 @@
<comment><![CDATA[Select payment method specific currencies.]]></comment>
<tooltip>Your contract with Buckaroo must allow for the selected currencies to be used with this payment method.</tooltip>
<config_path>payment/buckaroo_magento2_klarnain/allowed_currencies</config_path>
<source_model>Buckaroo\Magento2\Model\Config\Source\AllowedCurrencies::ideal</source_model>
<source_model>Buckaroo\Magento2\Model\Config\Source\AllowedCurrencies::klarnain</source_model>
<backend_model>Buckaroo\Magento2\Model\Config\Backend\AllowedCurrencies</backend_model>
</field>
</group>
Expand Down
4 changes: 2 additions & 2 deletions etc/adminhtml/system/payment_methods/klarnakp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<field id="specificcountry" translate="label" type="multiselect" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment from Specific Country</label>
<comment><![CDATA[Only available when set to 'specific countries'.]]></comment>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<source_model>Buckaroo\Magento2\Model\Config\Source\AllowedCountries::klarnakp</source_model>
<can_be_empty>1</can_be_empty>
<config_path>payment/buckaroo_magento2_klarnakp/specificcountry</config_path>
<depends>
Expand All @@ -176,7 +176,7 @@
<comment><![CDATA[Select payment method specific currencies.]]></comment>
<tooltip>Your contract with Buckaroo must allow for the selected currencies to be used with this payment method.</tooltip>
<config_path>payment/buckaroo_magento2_klarnakp/allowed_currencies</config_path>
<source_model>Buckaroo\Magento2\Model\Config\Source\AllowedCurrencies::ideal</source_model>
<source_model>Buckaroo\Magento2\Model\Config\Source\AllowedCurrencies::klarnakp</source_model>
<backend_model>Buckaroo\Magento2\Model\Config\Backend\AllowedCurrencies</backend_model>
</field>
</group>
Expand Down

0 comments on commit cd89fb8

Please sign in to comment.