Skip to content

Commit

Permalink
Form fix
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Jan 19, 2024
1 parent 41ad80d commit e965f34
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Api/TpayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function useSandboxMode(): bool;
/** Check if checkout amount is in range of installments payment channel */
public function getInstallmentsAmountValid(): bool;

// KARTY
public function getCardApiKey(): ?string;

public function getCardApiPassword(): ?string;
Expand All @@ -88,6 +87,10 @@ public function getHashType(): ?string;

public function getVerificationCode(): ?string;

public function isAllowSpecific(): bool;

public function getSpecificCountry(): array;

/** @param string $orderId */
public function getCustomerId($orderId);

Expand Down
5 changes: 5 additions & 0 deletions Model/ConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public function validate(array $constraints): bool
return true;
}

public function isClientCountryValid(bool $isAllowed, string $clientCountry, array $specificCountry): bool
{
return $isAllowed && !in_array($clientCountry, $specificCountry);
}

private function validateMinimalTotal(float $minimal): bool
{
return $this->checkoutSession->getQuote()->getGrandTotal() > $minimal;
Expand Down
15 changes: 14 additions & 1 deletion Model/MethodListPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,21 @@ public function afterGetAvailableMethods(MethodList $compiled, $result)
$channelList = $onsiteChannels ? explode(',', $onsiteChannels) : [];
$channels = $this->transactions->channels();

if ($this->constraintValidator->isClientCountryValid($this->tpay->isAllowSpecific(), $this->checkoutSession->getQuote()->getBillingAddress()->getCountryId(), $this->tpay->getSpecificCountry())) {
return [];
}

if (!$this->tpay->isCartValid($this->checkoutSession->getQuote()->getGrandTotal())) {
return $result;
}

$result = $this->addCardMethod($result);
$result = $this->filterResult($result);

if (!$this->transactions->isOpenApiUse() || !$this->isPlnPayment()) {
return $result;
}

foreach ($channelList as $onsiteChannel) {
$channel = $channels[$onsiteChannel];

Expand Down Expand Up @@ -111,12 +119,17 @@ private function addCardMethod(array $result): array

private function filterResult(array $result): array
{
if ('PLN' === $this->storeManager->getStore()->getCurrentCurrencyCode()) {
if ($this->isPlnPayment()) {
return $result;
}

return array_filter($result, function ($method) {
return 'tpaycom_magento2basic' !== $method->getCode();
});
}

private function isPlnPayment(): bool
{
return 'PLN' === $this->storeManager->getStore()->getCurrentCurrencyCode();
}
}
12 changes: 10 additions & 2 deletions Model/Tpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ public function assignData(DataObject $data)

$info->setAdditionalInformation(static::TERMS_ACCEPT, isset($additionalData[static::TERMS_ACCEPT]) ? '1' === $additionalData[static::TERMS_ACCEPT] : false);

// KARTY
$info->setAdditionalInformation(static::CARDDATA, $additionalData[static::CARDDATA] ?? '');
$info->setAdditionalInformation(static::CARD_VENDOR, isset($additionalData[static::CARD_VENDOR]) && in_array($additionalData[static::CARD_VENDOR], $this->supportedVendors) ? $additionalData[static::CARD_VENDOR] : 'undefined');
$info->setAdditionalInformation(static::CARD_SAVE, isset($additionalData[static::CARD_SAVE]) ? '1' === $additionalData[static::CARD_SAVE] : false);
Expand Down Expand Up @@ -381,7 +380,6 @@ public function getConfigData($field, $storeId = null)
return parent::getConfigData($field, $storeId);
}

// KARTY
public function getCardSaveEnabled(): bool
{
return (bool) $this->getConfigData('cardpayment_settings/card_save_enabled');
Expand Down Expand Up @@ -422,6 +420,16 @@ public function getVerificationCode(): string
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/verification_code');
}

public function isAllowSpecific(): bool
{
return (bool) $this->getConfigData('sale_settings/allowspecific') ?? false;
}

public function getSpecificCountry(): array
{
return $this->getConfigData('sale_settings/specificcountry') ? explode(',', $this->getConfigData('sale_settings/specificcountry')) : [];
}

/**
* @param string $orderId
*
Expand Down
1 change: 0 additions & 1 deletion Service/TpayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public function getOrderById(string $orderId): OrderInterface
return $this->orderRepository->getByIncrementId($orderId);
}

// KARTY
public function setCardOrderStatus($orderId, array $validParams, $tpayModel)
{
/** @var Order $order */
Expand Down
3 changes: 2 additions & 1 deletion view/frontend/web/template/payment/card-tpay-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<!-- ko i18n: 'CVC' --><!-- /ko -->
</div>
<input id="cvc"
maxlength="4"
maxlength="3"
type="tel"
autocomplete="off"
autocompletetype="cc-cvc"
Expand All @@ -90,6 +90,7 @@
<span data-bind="html: cardShowSaveBox()"></span>
<input type="hidden" name="card_data" id="card_data"/>
<input type="hidden" name="card_vendor" id="card_vendor"/>
<input type="hidden" name="card_short_code" id="card_short_code"/>
</div>
<div class="tpay-amPmCheckbox" id="tpay-card-save-checkbox" style="display: none">
<input type="checkbox" id="card_save" name="card_save"/>
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/web/template/payment/tpay-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
</div>
<input id="blik_code"
name="blik_code"
pattern="\d*"
type="tel"
autocomplete="off"
maxlength="6"
Expand All @@ -41,6 +40,7 @@
tabindex="1"
value=""
class="tpay-input-value tpay-blik-input"
oninput="this.value = this.value.replace(/\D/g, '')"
/>
</div>
</div>
Expand Down

0 comments on commit e965f34

Please sign in to comment.