Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add regulations in english #53

Merged
merged 5 commits into from
Jun 5, 2024
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
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.6
2.0.7
23 changes: 16 additions & 7 deletions Model/ApiFacade/CardTransaction/CardApiFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ public function makeCardTransaction(string $orderId, ?array $customerToken = nul

public function payTransaction(string $orderId, array $additionalPaymentInformation, ?string $transactionId = null, ?array $customerToken = null): string
{
$this->connectApi();

return $this->useOpenCard ? $this->cardOpen->payTransaction($orderId, $additionalPaymentInformation, $transactionId, $customerToken) : 'error';
return $this->isOpenApiUse() ? $this->cardOpen->payTransaction($orderId, $additionalPaymentInformation, $transactionId, $customerToken) : 'error';
}

public function isOpenApiUse(): bool
Expand All @@ -68,29 +66,40 @@ private function getCurrent()
private function connectApi()
{
if (null == $this->cardOpen && null === $this->cardOrigin) {
$this->createCardOriginApiInstance($this->tpay, $this->tpayConfig, $this->tokensService, $this->tpayService);
$originAuthorization = $this->createCardOriginApiInstance($this->tpay, $this->tpayConfig, $this->tokensService, $this->tpayService);

if (isset($originAuthorization['content']) && 'correct' == $originAuthorization['content']) {
$this->useOpenCard = false;

return;
}

$this->createOpenApiInstance($this->tpay, $this->tpayConfig, $this->tokensService, $this->tpayService);
}
}

private function createCardOriginApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, TpayTokensService $tokensService, TpayService $tpayService)
private function createCardOriginApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, TpayTokensService $tokensService, TpayService $tpayService): array
{
if (!$tpayConfig->isCardEnabled()) {
$this->cardOrigin = null;

return;
return [];
}

try {
$this->cardOrigin = new CardOrigin($tpay, $tpayConfig, $tokensService, $tpayService);

return $this->cardOrigin->requests($this->cardOrigin->cardsApiURL.$this->tpayConfig->getCardApiKey(), ['api_password' => $this->tpayConfig->getCardApiPassword(), 'method' => 'check']);
} catch (Exception $exception) {
$this->cardOrigin = null;

return [];
}
}

private function createOpenApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, TpayTokensService $tokensService, TpayService $tpayService)
{
if (!$tpayConfig->isPlnPayment() || !$tpayConfig->isCardEnabled()) {
if (!$tpayConfig->isOpenApiEnabled() || !$tpayConfig->isPlnPayment() || !$tpayConfig->isCardEnabled()) {
$this->cardOpen = null;
$this->useOpenCard = false;

Expand Down
21 changes: 16 additions & 5 deletions Model/ApiFacade/TpayConfig/CardConfigFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,41 @@ private function getCurrentApi()
private function connectApi()
{
if (null == $this->openApi && null === $this->originApi) {
$this->createOriginApiInstance($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService, $this->tpayService);
$originAuthorization = $this->createOriginApiInstance($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService, $this->tpayService);

if (isset($originAuthorization['content']) && 'correct' == $originAuthorization['content']) {
$this->useOpenApi = false;

return;
}

$this->createOpenApiInstance($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService);
}
}

private function createOriginApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService, TpayService $tpayService)
private function createOriginApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService, TpayService $tpayService): array
{
if (!$tpayConfig->isCardEnabled()) {
$this->originApi = null;

return;
return [];
}

try {
new CardOrigin($tpay, $tpayConfig, $tokensService, $tpayService);
$cardOrigin = new CardOrigin($tpay, $tpayConfig, $tokensService, $tpayService);
$this->originApi = new ConfigOrigin($tpay, $tpayConfig, $assetRepository, $tokensService);

return $cardOrigin->requests($cardOrigin->cardsApiURL.$this->tpayConfig->getCardApiKey(), ['api_password' => $this->tpayConfig->getCardApiPassword(), 'method' => 'check']);
} catch (Exception $exception) {
$this->originApi = null;

return [];
}
}

private function createOpenApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService)
{
if (!$tpayConfig->isPlnPayment()) {
if (!$tpayConfig->isOpenApiEnabled() || !$tpayConfig->isPlnPayment()) {
$this->openApi = null;
$this->useOpenApi = false;

Expand Down
2 changes: 1 addition & 1 deletion Model/ApiFacade/TpayConfig/ConfigOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function createScript(string $script): string

public function getTerms(): ?string
{
return $this->tpay->getTermsURL();
return $this->tpayConfig->getTermsURL();
}

public function createCSS(string $css): string
Expand Down
2 changes: 1 addition & 1 deletion Model/ApiFacade/TpayConfig/ConfigOrigin.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function createScript(string $script): string

public function getTerms(): ?string
{
return $this->tpay->getTermsURL();
return $this->tpayConfig->getTermsURL();
}

public function createCSS(string $css): string
Expand Down
6 changes: 0 additions & 6 deletions Model/TpayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class TpayPayment extends Adapter implements TpayInterface
protected $_canRefund = true;
protected $_canRefundInvoicePartial = true;
protected $redirectURL = 'https://secure.tpay.com';
protected $termsURL = 'https://secure.tpay.com/regulamin.pdf';

/** @var float */
protected $minAmountBlik = 0.01;
Expand Down Expand Up @@ -179,11 +178,6 @@ public function checkBlikLevel0Settings(): bool
return $this->configurationProvider->getBlikLevelZeroStatus() && $this->checkBlikAmount();
}

public function getTermsURL(): string
{
return $this->termsURL;
}

public function getTpayFormData(?string $orderId = null): array
{
$order = $this->getOrder($orderId);
Expand Down
14 changes: 12 additions & 2 deletions Provider/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Locale\Resolver;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Tpay\Magento2\Api\TpayConfigInterface;
Expand All @@ -15,6 +16,7 @@ class ConfigurationProvider implements TpayConfigInterface
private const BASE_CONFIG_PATH = 'payment/tpaycom_magento2basic/';

protected $termsURL = 'https://secure.tpay.com/regulamin.pdf';
protected $termsEnURL = 'https://tpay.com/user/assets/files_for_download/payment-terms-and-conditions.pdf';

/** @var ScopeConfigInterface */
protected $scopeConfig;
Expand All @@ -25,11 +27,15 @@ class ConfigurationProvider implements TpayConfigInterface
/** @var StoreManagerInterface */
private $storeManager;

public function __construct(ScopeConfigInterface $scopeConfig, ProductMetadataInterface $productMetadataInterface, StoreManagerInterface $storeManager)
/** @var Resolver */
private $localeResolver;

public function __construct(ScopeConfigInterface $scopeConfig, ProductMetadataInterface $productMetadataInterface, StoreManagerInterface $storeManager, Resolver $localeResolver)
{
$this->scopeConfig = $scopeConfig;
$this->productMetadataInterface = $productMetadataInterface;
$this->storeManager = $storeManager;
$this->localeResolver = $localeResolver;
}

public function isTpayActive(): bool
Expand Down Expand Up @@ -74,7 +80,11 @@ public function getInvoiceSendMail(): string

public function getTermsURL(): string
{
return $this->termsURL;
if ('pl' == substr($this->localeResolver->getLocale(), 0, 2)) {
return $this->termsURL;
}

return $this->termsEnURL;
}

public function getOpenApiPassword(): ?string
Expand Down
Loading