Skip to content

Commit

Permalink
Add card group
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Jan 16, 2024
1 parent 146b7fa commit dd7e542
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 44 deletions.
12 changes: 12 additions & 0 deletions Api/TpayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@ public function getRedirectURL(): string;
/** Return data for form */
public function getTpayFormData(?string $orderId = null): array;

public function getCardTitle(): ?string;

public function isOriginApiEnabled(): bool;

public function isOpenApiEnabled(): bool;

public function isCardEnabled(): bool;

public function isOriginApiCardUse(): bool;

public function getApiPassword(): ?string;

public function getOpenApiPassword(): ?string;

public function getApiKey(): ?string;

public function getSecurityCode(): ?string;
Expand Down
8 changes: 7 additions & 1 deletion Model/ApiFacade/CardTransaction/CardApiFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ private function getCurrent()

private function createCardOriginApiInstance(TpayInterface $tpay, TpayTokensService $tokensService, TpayService $tpayService)
{
if (!$tpay->isOriginApiEnabled()()){
$this->cardOrigin = null;

return;
}

try {
$this->cardOrigin = new CardOrigin($tpay, $tokensService, $tpayService);
} catch (Exception $exception) {
Expand All @@ -50,7 +56,7 @@ private function createCardOriginApiInstance(TpayInterface $tpay, TpayTokensServ

private function createOpenApiInstance(TpayInterface $tpay, TpayTokensService $tokensService, TpayService $tpayService)
{
if ('PLN' !== $this->storeManager->getStore()->getCurrentCurrencyCode()) {
if ('PLN' !== $this->storeManager->getStore()->getCurrentCurrencyCode() && !$tpay->isOpenApiEnabled()) {
$this->cardOpen = null;
$this->useOpenCard = false;

Expand Down
8 changes: 7 additions & 1 deletion Model/ApiFacade/TpayConfig/ConfigFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ private function getCurrentApi()

private function createOriginApiInstance(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService)
{
if (!$tpay->isOriginApiEnabled()){
$this->originApi = null;

return;
}

try {
$this->originApi = new ConfigOrigin($tpay, $assetRepository, $tokensService);
} catch (Exception $exception) {
Expand All @@ -46,7 +52,7 @@ private function createOriginApiInstance(TpayInterface $tpay, Repository $assetR

private function createOpenApiInstance(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService, StoreManagerInterface $storeManager)
{
if ('PLN' !== $storeManager->getStore()->getCurrentCurrencyCode()) {
if ('PLN' !== $storeManager->getStore()->getCurrentCurrencyCode() && !$tpay->isOpenApiEnabled()) {
$this->openApi = null;
$this->useOpenApi = false;

Expand Down
13 changes: 13 additions & 0 deletions Model/ApiFacade/Transaction/TransactionApiFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ private function getCurrentApi()

private function createOriginApiInstance(TpayInterface $tpay)
{
if (!$tpay->isOriginApiEnabled()){
$this->originApi = null;

return;
}

try {
$this->originApi = new TransactionOriginApi($tpay->getApiPassword(), $tpay->getApiKey(), $tpay->getMerchantId(), $tpay->getSecurityCode(), !$tpay->useSandboxMode());
} catch (Exception $exception) {
Expand All @@ -95,6 +101,13 @@ private function createOriginApiInstance(TpayInterface $tpay)

private function createOpenApiInstance(TpayInterface $tpay)
{
if (!$tpay->isOpenApiEnabled()) {
$this->openApi = null;
$this->useOpenApi = false;

return;
}

try {
$this->openApi = new OpenApi($tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode());
$this->openApi->authorization();
Expand Down
11 changes: 10 additions & 1 deletion Model/MethodListPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function afterGetAvailableMethods(MethodList $compiled, $result)
return $result;
}

$result[] = $this->getMethodInstance('tpay.com - Płatność kartą', 'tpaycom_magento2basic_cards');
$result = $this->addCardMethod($result);
$result = $this->filterResult($result);

foreach ($channelList as $onsiteChannel) {
Expand Down Expand Up @@ -100,6 +100,15 @@ public function getMethodInstance(string $title, string $code): MethodInterface
return $method;
}

private function addCardMethod(array $result): array
{
if ($this->tpay->isCardEnabled()) {
$result[] = $this->getMethodInstance($this->tpay->getCardTitle(), 'tpaycom_magento2basic_cards');
}

return $result;
}

private function filterResult(array $result): array
{
if ('PLN' === $this->storeManager->getStore()->getCurrentCurrencyCode()) {
Expand Down
35 changes: 30 additions & 5 deletions Model/Tpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function getApiKey(): ?string

public function getCardApiKey(): ?string
{
return $this->getConfigData('originapi_settings/card_api_key_tpay');
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_key_tpay');
}

public function getApiPassword(): ?string
Expand All @@ -162,7 +162,7 @@ public function getApiPassword(): ?string

public function getCardApiPassword(): ?string
{
return $this->getConfigData('originapi_settings/card_api_password');
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_password');
}

public function getInvoiceSendMail(): string
Expand All @@ -175,7 +175,7 @@ public function getTermsURL(): string
return $this->termsURL;
}

public function getOpenApiPassword()
public function getOpenApiPassword(): ?string
{
return $this->getConfigData('openapi_settings/open_api_password');
}
Expand Down Expand Up @@ -249,6 +249,31 @@ public function getTitle(): string
return $this->_title ?? $this->getConfigData('general_settings/title');
}

public function getCardTitle(): ?string
{
return $this->getConfigData('cardpayment_settings/card_title') ?? '';
}

public function isOriginApiEnabled(): bool
{
return (bool) $this->getConfigData('originapi_settings/origin_api_active');
}

public function isOpenApiEnabled(): bool
{
return (bool) $this->getConfigData('openapi_settings/open_api_active');
}

public function isCardEnabled(): bool
{
return (bool) $this->getConfigData('cardpayment_settings/cardpayment_api_active');
}

public function isOriginApiCardUse(): bool
{
return (bool) $this->getConfigData('cardpayment_settings/cardpayment_origin_api_use');
}

public function useSandboxMode(): bool
{
return (bool) $this->getConfigData('general_settings/use_sandbox');
Expand Down Expand Up @@ -391,12 +416,12 @@ public function isCustomerLoggedIn(): bool

public function getHashType(): string
{
return $this->getConfigData('cardpayment_settings/hash_type');
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/hash_type');
}

public function getVerificationCode(): string
{
return $this->getConfigData('cardpayment_settings/verification_code');
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/verification_code');
}

/**
Expand Down
101 changes: 65 additions & 36 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
<label>Active</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<group id="general_settings" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General settings</label>
<attribute type="expanded">1</attribute>
<field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="general_settings" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General settings</label>
<attribute type="expanded">1</attribute>
<field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Description</label>
<validate>validate-no-empty</validate>
</field>
<field id="merchant_id" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Merchant ID</label>
Expand All @@ -32,73 +33,101 @@
<label>Secure code</label>
<validate>validate-length maximum-length-32</validate>
</field>
<field id="show_payment_channels_online" translate="label" type="select" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Only online methods</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="redirect_directly_to_channel" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Redirect directly to bank</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="blik_level_zero" translate="label" type="select" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1">
<label>BLIK level zero</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="use_sandbox" translate="label" type="select" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Use sandbox mode (avoid using it in real production store)</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<field id="show_payment_channels_online" translate="label" type="select" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Only online methods</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="redirect_directly_to_channel" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Redirect directly to bank</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="blik_level_zero" translate="label" type="select" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1">
<label>BLIK level zero</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="use_sandbox" translate="label" type="select" sortOrder="11" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Use sandbox mode (avoid using it in real production store)</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<group id="openapi_settings" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Open Api</label>
<field id="open_api_active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Active</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="open_api_client_id" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Client ID OPEN API</label>
<validate>validate-length maximum-length-64</validate>
<depends><field id="open_api_active">1</field></depends>
</field>
<field id="open_api_password" translate="label comment" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API password OPEN API</label>
<validate>validate-length maximum-length-64</validate>
<depends><field id="open_api_active">1</field></depends>
</field>
<field id="onsite_channels" translate="label" type="multiselect" sortOrder="18" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Generic onsites</label>
<can_be_empty>1</can_be_empty>
<source_model>tpaycom\magento2basic\Model\Config\Source\OnsiteChannels</source_model>
<depends><field id="open_api_active">1</field></depends>
</field>
</group>
<group id="originapi_settings" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Origin Api</label>
<field id="origin_api_active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Active</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="api_key_tpay" translate="label comment" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API key</label>
<validate>no-whitespace validate-length maximum-length-126</validate>
<depends><field id="origin_api_active">1</field></depends>
</field>
<field id="api_password" translate="label comment" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API password</label>
<validate>no-whitespace validate-length maximum-length-40</validate>
</field>
<field id="card_api_key_tpay" translate="label comment" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Card API key</label>
<validate>no-whitespace validate-length maximum-length-126</validate>
</field>
<field id="card_api_password" translate="label comment" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Card API password</label>
<validate>no-whitespace validate-length maximum-length-40</validate>
<depends><field id="origin_api_active">1</field></depends>
</field>
</group>
<group id="cardpayment_settings" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Card payment settings</label>
<field id="cardpayment_api_active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Active</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<group id="cardpayment_originapi_settings" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Origin Api card payment settings</label>
<depends><field id="cardpayment_api_active">1</field></depends>
<field id="hash_type" translate="label" type="select" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Hash type</label>
<source_model>tpaycom\magento2basic\Model\Config\Source\HashTypes</source_model>
</field>
<field id="verification_code" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Verification code</label>
</field>
<field id="card_api_key_tpay" translate="label comment" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Card API key</label>
<validate>no-whitespace validate-length maximum-length-126</validate>
</field>
<field id="card_api_password" translate="label comment" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Card API password</label>
<validate>no-whitespace validate-length maximum-length-40</validate>
</field>
</group>
<field id="card_title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Card description</label>
<validate>validate-no-empty</validate>
<depends><field id="cardpayment_api_active">1</field></depends>
</field>
<field id="rsa_key" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
<label>RSA key</label>
</field>
<field id="verification_code" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Verification code</label>
<depends><field id="cardpayment_api_active">1</field></depends>
</field>
<field id="card_save_enabled" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable credit card saving</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="hash_type" translate="label" type="select" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Hash type</label>
<source_model>tpaycom\magento2basic\Model\Config\Source\HashTypes</source_model>
<depends><field id="cardpayment_api_active">1</field></depends>
</field>
</group>
<group id="sale_settings" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down

0 comments on commit dd7e542

Please sign in to comment.