Skip to content

Commit

Permalink
Merge pull request #85 from Invertus/SL-130/currency-select
Browse files Browse the repository at this point in the history
SL-130:currency options is now taken from API
  • Loading branch information
margud authored Nov 8, 2022
2 parents a2df45e + ada2d82 commit 08c3a80
Show file tree
Hide file tree
Showing 47 changed files with 36 additions and 15 deletions.
Empty file modified .github/.htaccess
100644 → 100755
Empty file.
Empty file modified .github/workflows/deploy.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/release.yml
100644 → 100755
Empty file.
Empty file modified User-guide-saferpay-module-for-prestashop-int-en.pdf
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions config/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ services:
- '@=service("adapter.context")'
- '@Invertus\SaferPay\Repository\SaferPayPaymentRepository'
- '@Invertus\SaferPay\Repository\SaferPayRestrictionRepository'
- '@Invertus\SaferPay\Service\SaferPayObtainPaymentMethods'
tags:
- { name: saferpay.paymentrestriction }

Expand Down
22 changes: 13 additions & 9 deletions controllers/admin/AdminSaferPayOfficialPaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected function renderShoppingPointOptions()
'paymentMethod' => $paymentMethod,
'countryOptions' => $this->getActiveCountriesList(),
'countrySelect' => $selectedCountries,
'currencyOptions' => $this->getActiveCurrenciesList(),
'currencyOptions' => $this->getActiveCurrenciesList($paymentMethod),
'currencySelect' => $selectedCurrencies,
'is_field_active' => $isFieldActive,
'supported_field_payments' => SaferPayConfig::FIELD_SUPPORTED_PAYMENT_METHODS,
Expand Down Expand Up @@ -212,17 +212,21 @@ public function getActiveCountriesList($onlyActive = true)
return $countriesWithNames;
}

public function getActiveCurrenciesList($onlyActive = true)
public function getActiveCurrenciesList($paymentMethod)
{
$langId = $this->context->language->id;
$currencies = Currency::getCurrencies($langId, $onlyActive);
$currenciesWithNames = [];
$currenciesWithNames[0] = $this->l('All');
foreach ($currencies as $currency) {
$currenciesWithNames[$currency->id] = $currency->name;
/** @var \Invertus\SaferPay\Service\SaferPayObtainPaymentMethods $saferPayObtainPaymentMethods */
$saferPayObtainPaymentMethods = $this->module->getModuleContainer()->get(SaferPayObtainPaymentMethods::class);

$paymentMethods = $saferPayObtainPaymentMethods->obtainPaymentMethods();

$currencyOptions[0] = $this->l('All');
foreach ($paymentMethods[$paymentMethod]['currencies'] as $currencyIso) {
if (Currency::getIdByIsoCode($currencyIso)) {
$currencyOptions[Currency::getIdByIsoCode($currencyIso)] = $currencyIso;
}
}

return $currenciesWithNames;
return $currencyOptions;
}

protected function initForm()
Expand Down
Empty file modified cypress/fixtures/example.json
100644 → 100755
Empty file.
Empty file modified cypress/plugins/index.js
100644 → 100755
Empty file.
Empty file modified src/Api/Request/ObtainPaymentMethodsService.php
100644 → 100755
Empty file.
Empty file.
Empty file modified src/DTO/Request/PendingNotification.php
100644 → 100755
Empty file.
Empty file modified src/Enum/ControllerName.php
100644 → 100755
Empty file.
Empty file modified src/Enum/PaymentType.php
100644 → 100755
Empty file.
Empty file modified src/Presentation/Loader/PaymentFormAssetLoader.php
100644 → 100755
Empty file.
Empty file modified src/Provider/PaymentRestrictionProvider.php
100644 → 100755
Empty file.
Empty file modified src/Provider/PaymentRestrictionProviderInterface.php
100644 → 100755
Empty file.
Empty file modified src/Provider/PaymentTypeProvider.php
100644 → 100755
Empty file.
Empty file modified src/Service/LegacyTranslator.php
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

namespace Invertus\SaferPay\Service\PaymentRestrictionValidation;

use Currency;
use Invertus\SaferPay\Adapter\LegacyContext;
use Invertus\SaferPay\Repository\SaferPayPaymentRepository;
use Invertus\SaferPay\Repository\SaferPayRestrictionRepository;
use Invertus\SaferPay\Service\SaferPayObtainPaymentMethods;
use Invertus\SaferPay\Service\SaferPayRestrictionCreator;

class BasePaymentRestrictionValidation implements PaymentRestrictionValidationInterface
Expand All @@ -45,14 +47,21 @@ class BasePaymentRestrictionValidation implements PaymentRestrictionValidationIn
*/
private $legacyContext;

/**
* @var SaferPayObtainPaymentMethods
*/
private $obtainPaymentMethods;

public function __construct(
LegacyContext $legacyContext,
SaferPayPaymentRepository $paymentRepository,
SaferPayRestrictionRepository $restrictionRepository
SaferPayRestrictionRepository $restrictionRepository,
SaferPayObtainPaymentMethods $obtainPaymentMethods
) {
$this->paymentRepository = $paymentRepository;
$this->restrictionRepository = $restrictionRepository;
$this->legacyContext = $legacyContext;
$this->obtainPaymentMethods = $obtainPaymentMethods;
}

/**
Expand Down Expand Up @@ -133,9 +142,14 @@ private function isCurrencySupportedByPaymentName($paymentName)
{
$enabledCurrencies = $this->getEnabledCurrenciesByPaymentName($paymentName);

$isAllCurrencies = in_array('0', $enabledCurrencies);
$isCurrencyInList = in_array($this->legacyContext->getCurrencyId(), $enabledCurrencies);
if (in_array('0', $enabledCurrencies)) {
$enabledCurrencies = [];
$currencyOptions = $this->obtainPaymentMethods->obtainPaymentMethods()[$paymentName]['currencies'];
foreach ($currencyOptions as $isoCode) {
$enabledCurrencies[$isoCode] = $isoCode;
}
}

return $isCurrencyInList || $isAllCurrencies;
return in_array($this->legacyContext->getCurrencyIsoCode(), $enabledCurrencies);
}
}
Empty file.
Empty file modified src/Service/Request/ObtainPaymentMethodsObjectCreator.php
100644 → 100755
Empty file.
Empty file modified src/Service/SaferPayMailService.php
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions src/Service/SaferPayObtainPaymentMethods.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ public function obtainPaymentMethods()
if (!empty($paymentMethodsObject->PaymentMethods)) {
foreach ($paymentMethodsObject->PaymentMethods as $paymentMethodObject) {
$paymentNotation = $this->saferPayPaymentNotation->getShortName($paymentMethodObject->PaymentMethod);
$paymentMethods[] = [
$paymentMethods[$paymentNotation] = [
'paymentMethod' => $paymentNotation,
'logoUrl' => $paymentMethodObject->LogoUrl,
'currencies' => $paymentMethodObject->Currencies
];
}
}

if (!empty($paymentMethodsObject->Wallets)) {
foreach ($paymentMethodsObject->Wallets as $wallet) {
$paymentMethods[] = [
$paymentMethods[$wallet->WalletName] = [
'paymentMethod' => $wallet->WalletName,
'logoUrl' => $wallet->LogoUrl,
'currencies' => $paymentMethodObject->Currencies
];
}
}
Expand Down
Empty file modified src/Service/SaferPayPaymentNotation.php
100644 → 100755
Empty file.
Empty file modified src/Service/SaferPayRefreshPaymentsService.php
100644 → 100755
Empty file.
Empty file modified src/Service/TranslatorInterface.php
100644 → 100755
Empty file.
Empty file.
Empty file modified tests/Unit/Service/SaferPayPaymentNotationTest.php
100644 → 100755
Empty file.
Empty file added translations/lt.php
Empty file.
Empty file modified upgrade/install-1.0.18.php
100644 → 100755
Empty file.
Empty file modified views/img/APPLEPAY.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/BANCONTACT.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/IDEAL.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/KLARNA.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/WLCRYPTOPAYMENTS.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/readme/img.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/readme/pic1.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/readme/pic2.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/readme/ss1.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/readme/ss2.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/readme/ss3.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/readme/ss4.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/readme/ss5.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/readme/ss6.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/img/readme/ss7.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified views/js/front/hosted-templates/hosted_fields.js
100644 → 100755
Empty file.
Empty file modified views/js/front/hosted-templates/hosted_fields_16.js
100644 → 100755
Empty file.

0 comments on commit 08c3a80

Please sign in to comment.