Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dev/src/components/payments/DefaultPaymentConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

<slot></slot>

<div class="px-5 space-y-5">
<div v-if="config.payment_fee_allowed !== false" class="px-5 space-y-5">
<div class="space-y-2">
<h2 class="font-semibold text-sm">{{ $t(`dashboard.pages.payments.payment_fee_incl_vat`) }}</h2>
<div class="text-gray-400 text-xs">{{ $t(`dashboard.pages.payments.payment_fee_incl_vat_label`) }}</div>
Expand Down Expand Up @@ -196,6 +196,7 @@ export default {
mode: 'off',
frontend_label: '',
payment_fee: null,
payment_fee_allowed: true,
min_order_amount: null,
max_order_amount: null,
countries: [],
Expand All @@ -217,6 +218,7 @@ export default {
display_type: 'dropdown',
frontend_label: '',
payment_fee: null,
payment_fee_allowed: true,
min_order_amount: null,
max_order_amount: null,
countries: [],
Expand Down
12 changes: 12 additions & 0 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ class Config
public const PAYMENT_FEE_FRONTEND_LABEL = 'PAYMENT_FEE_FRONTEND_LABEL';

public const FILE_NAME = 'Installer';

/**
* Payment methods that do not support a configurable payment fee.
*/
private const PAYMENT_FEE_DISABLED_METHODS = [
'paybybank',
];

public static function isPaymentFeeAllowed(string $method): bool
{
return !in_array(strtolower($method), self::PAYMENT_FEE_DISABLED_METHODS, true);
}
}
10 changes: 9 additions & 1 deletion src/Service/BuckarooConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace Buckaroo\PrestaShop\Src\Service;

use Buckaroo\PrestaShop\Src\Config\Config;
use Buckaroo\PrestaShop\Src\Entity\BkConfiguration;
use Buckaroo\PrestaShop\Src\Entity\BkOrdering;
use Buckaroo\PrestaShop\Src\Entity\BkPaymentMethods;
Expand Down Expand Up @@ -49,7 +50,10 @@ public function getConfigArrayForMethod($method)
return null;
}

return $this->configurationRepository->getConfigArray($paymentMethod->getId());
$configArray = $this->configurationRepository->getConfigArray($paymentMethod->getId());
$configArray['payment_fee_allowed'] = Config::isPaymentFeeAllowed((string) $method);

return $configArray;
}

public function getConfigValue($method, $key)
Expand All @@ -73,6 +77,10 @@ public function updatePaymentMethodConfig($name, array $data): bool

$paymentMethodId = $paymentMethod->getId();

if (!Config::isPaymentFeeAllowed((string) $name)) {
$data['payment_fee'] = '';
}

// Existing config
$configArray = $this->configurationRepository->getConfigArray($paymentMethodId);
$mergedConfig = array_merge($configArray, $data);
Expand Down
7 changes: 6 additions & 1 deletion src/Service/BuckarooFeeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace Buckaroo\PrestaShop\Src\Service;

use Buckaroo\PrestaShop\Src\Config\Config;
use Buckaroo\PrestaShop\Src\Entity\BkConfiguration;
use Buckaroo\PrestaShop\Src\Entity\BkPaymentMethods;
use Doctrine\ORM\EntityManager;
Expand Down Expand Up @@ -85,7 +86,7 @@ public function getBuckarooFees(): array

public function getBuckarooFeeInputs($method)
{
$feeData = $this->getFeeData($this->getSpecificValueFromConfig($method, 'payment_fee'));
$feeData = $this->getFeeData($this->getBuckarooFeeValue($method));

$buckarooKeyInput = [
'type' => 'hidden',
Expand Down Expand Up @@ -116,6 +117,10 @@ public function getSpecificValueFromConfig($method, $key)

public function getBuckarooFeeValue($method)
{
if (!Config::isPaymentFeeAllowed((string) $method)) {
return null;
}

return $this->getSpecificValueFromConfig($method, 'payment_fee');
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,13 @@ public function testConfigConstantsHaveExpectedValues(): void
$this->assertSame('PAYMENT_FEE_MODE', Config::PAYMENT_FEE_MODE);
$this->assertSame('PAYMENT_FEE_FRONTEND_LABEL', Config::PAYMENT_FEE_FRONTEND_LABEL);
}

public function testPaymentFeeIsNotAllowedForPayByBank(): void
{
$this->assertFalse(Config::isPaymentFeeAllowed('paybybank'));
$this->assertFalse(Config::isPaymentFeeAllowed('PayByBank'));
$this->assertTrue(Config::isPaymentFeeAllowed('ideal'));
$this->assertTrue(Config::isPaymentFeeAllowed('paypal'));
}
}

34 changes: 34 additions & 0 deletions tests/Unit/Service/BuckarooFeeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,39 @@ public function getLabel(): string
$this->assertSame('ideal', $service->getPaymentMethodByLabel('iDEAL | Wero'));
$this->assertNull($service->getPaymentMethodByLabel('Unknown'));
}

public function testPayByBankDoesNotExposeConfiguredPaymentFee(): void
{
$method = new class {
public function getId(): int
{
return 7;
}

public function getName(): string
{
return 'paybybank';
}

public function getLabel(): string
{
return 'PayByBank';
}
};

$service = $this->createService(
[$method],
[
7 => ['payment_fee' => 2.50],
]
);

$this->assertNull($service->getBuckarooFeeValue('paybybank'));
$this->assertArrayNotHasKey('paybybank', $service->getBuckarooFees());

$inputs = $service->getBuckarooFeeInputs('paybybank');
$this->assertCount(1, $inputs);
$this->assertSame('paybybank', $inputs[0]['value']);
}
}

17 changes: 15 additions & 2 deletions views/js/buckaroo.vue.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion views/js/i18n-p2TvUSJi.js

This file was deleted.

5 changes: 5 additions & 0 deletions views/js/i18n-qTj21SQL.js

Large diffs are not rendered by default.

42 changes: 0 additions & 42 deletions views/js/vendor-CCl5T204.js

This file was deleted.

101 changes: 101 additions & 0 deletions views/js/vendor-LRfIAhCM.js

Large diffs are not rendered by default.

Loading