Skip to content

Commit

Permalink
Agreements
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Jan 12, 2024
1 parent d7250a8 commit 8e30bc0
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 28 deletions.
11 changes: 10 additions & 1 deletion Model/ApiFacade/CardTransaction/CardApiFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CardApiFacade
public function __construct(TpayInterface $tpay, TpayTokensService $tokensService, TpayService $tpayService, StoreManagerInterface $storeManager)
{
$this->storeManager = $storeManager;
$this->cardOrigin = new CardOrigin($tpay, $tokensService, $tpayService);
$this->createCardOriginApiInstance($tpay, $tokensService, $tpayService);
$this->createOpenApiInstance($tpay, $tokensService, $tpayService);
}

Expand All @@ -39,6 +39,15 @@ private function getCurrent()
return $this->useOpenCard ? $this->cardOpen : $this->cardOrigin;
}

private function createCardOriginApiInstance(TpayInterface $tpay, TpayTokensService $tokensService, TpayService $tpayService)
{
try {
$this->cardOrigin = new CardOrigin($tpay, $tokensService, $tpayService);
} catch (Exception $exception) {
$this->cardOrigin = null;
}
}

private function createOpenApiInstance(TpayInterface $tpay, TpayTokensService $tokensService, TpayService $tpayService)
{
if ('PLN' !== $this->storeManager->getStore()->getCurrentCurrencyCode()) {
Expand Down
11 changes: 10 additions & 1 deletion Model/ApiFacade/Refund/RefundApiFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RefundApiFacade
public function __construct(TpayInterface $tpay)
{
$this->tpay = $tpay;
$this->originApi = new RefundOriginApi($tpay);
$this->createRefundOriginApiInstance($tpay);
$this->createOpenApiInstance($tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode());
}

Expand All @@ -45,6 +45,15 @@ private function getCurrentApi()
return $this->useOpenApi ? $this->openApi : $this->originApi;
}

private function createRefundOriginApiInstance(TpayInterface $tpay)
{
try {
$this->originApi = new RefundOriginApi($tpay);
} catch (Exception $exception) {
$this->originApi = null;
}
}

private function createOpenApiInstance(string $clientId, string $apiPassword, bool $isProd)
{
try {
Expand Down
11 changes: 10 additions & 1 deletion Model/ApiFacade/TpayConfig/ConfigFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ConfigFacade

public function __construct(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService, StoreManagerInterface $storeManager)
{
$this->originApi = new ConfigOrigin($tpay, $assetRepository, $tokensService);
$this->createOriginApiInstance($tpay, $assetRepository, $tokensService);
$this->createOpenApiInstance($tpay, $assetRepository, $tokensService, $storeManager);
}

Expand All @@ -35,6 +35,15 @@ private function getCurrentApi()
return $this->useOpenApi ? $this->openApi : $this->originApi;
}

private function createOriginApiInstance(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService)
{
try {
$this->originApi = new ConfigOrigin($tpay, $assetRepository, $tokensService);
} catch (Exception $exception) {
$this->originApi = null;
}
}

private function createOpenApiInstance(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService, StoreManagerInterface $storeManager)
{
if ('PLN' !== $storeManager->getStore()->getCurrentCurrencyCode()) {
Expand Down
21 changes: 6 additions & 15 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,33 @@
</field>
<field id="merchant_id" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Merchant ID</label>
<validate>validate-no-empty validate-number validate-length maximum-length-10</validate>
<validate>validate-number validate-length maximum-length-10</validate>
</field>
<field id="security_code" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Secure code</label>
<validate>validate-no-empty validate-length maximum-length-32</validate>
<validate>validate-length maximum-length-32</validate>
</field>
<field id="api_key_tpay" translate="label comment" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API key</label>
<validate>validate-no-empty no-whitespace validate-length maximum-length-126</validate>
<validate>no-whitespace validate-length maximum-length-126</validate>
</field>
<field id="api_password" translate="label comment" type="text" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API password</label>
<validate>validate-no-empty no-whitespace validate-length maximum-length-40</validate>
<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>validate-no-empty no-whitespace validate-length maximum-length-126</validate>
<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>validate-no-empty no-whitespace validate-length maximum-length-40</validate>
<validate>no-whitespace validate-length maximum-length-40</validate>
</field>
<field id="rsa_key" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
<label>RSA key</label>
<validate>validate-no-empty</validate>
</field>
<field id="verification_code" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Verification code</label>
<validate>validate-no-empty</validate>
</field>
<field id="card_save_enabled" translate="label" type="select" sortOrder="8" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable credit card saving</label>
Expand Down Expand Up @@ -115,13 +113,6 @@
<label>API password OPEN API</label>
<validate>validate-length maximum-length-64</validate>
</field>
<field id="open_api_security_code" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Open Api Secure code</label>
<validate>validate-no-empty validate-length maximum-length-32</validate>
</field>



</group>
</section>
</system>
Expand Down
12 changes: 9 additions & 3 deletions view/base/web/js/renderSavedCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ require(['jquery', 'mage/translate'], function ($, $t) {
$('#saved_card_payment').css('display', 'none');
return;
}
$("#tpaycom_magento2cards_submit").removeClass('disabled');

$('input[name=savedId]').each(function () {
if ($(this).val() !== 'new') {
$(this).click(function () {
if ($(this).is(":checked")) {
if ($(this).is(":checked") && $('#card_accept_tos').is(':checked')) {
$('#card_form').css({opacity: 1.0}).animate({opacity: 0.0}, 500);
setTimeout(
function () {
Expand Down Expand Up @@ -48,7 +48,6 @@ require(['jquery', 'mage/translate'], function ($, $t) {
}
}
});

}

function generateHtml() {
Expand All @@ -75,7 +74,14 @@ require(['jquery', 'mage/translate'], function ($, $t) {
}

$('document').ready(function () {
var tos = $('#card_accept_tos');

renderForm();
tos.on('change', function () {
if (tos.is(':checked')) {
$("#tpaycom_magento2cards_submit").removeClass('disabled');
}
});
});

});
21 changes: 21 additions & 0 deletions view/base/web/js/render_channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,26 @@ require(['jquery', 'mage/translate'], function ($, $t) {
payButton.addClass('disabled');
});
});

$("#tpaycom_magento2generic_submit", '.payment-method').addClass('disabled');

$('input[name="payment[method]"]').on('click', function () {
var parent = $(this).closest('.payment-method');
$('input[name="accept_tos"]', parent).prop('checked', false);

var submitBtn = $("#tpaycom_magento2generic_submit", parent);
submitBtn.addClass('disabled');
});

$("input[name='accept_tos']").on("click", function () {
var parent = $(this).closest('.payment-method-content');
var submitBtn = $("#tpaycom_magento2generic_submit", parent);

if ($('#generic_accept_tos', parent).is(':checked')) {
submitBtn.removeClass('disabled');
} else {
submitBtn.addClass('disabled');
}
});
}
);
17 changes: 12 additions & 5 deletions view/base/web/js/tpayCards.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
require(['jquery', 'mage/translate'], function ($, $t) {
function CardPayment() {
var numberInput = $('#card_number'),
var payButton = $('#tpaycom_magento2cards_submit'),
numberInput = $('#card_number'),
expiryInput = $('#expiry_date'),
cvcInput = $('#cvc'),
RSA = $('#tpayRSA').text();
RSA = $('#tpayRSA').text(),
tos = $('#card_accept_tos');

const TRIGGER_EVENTS = 'input change blur';

function setWrong($elem) {
$elem.addClass('wrong').removeClass('valid');
$("#tpaycom_magento2cards_submit").addClass('disabled');
payButton.addClass('disabled');
}

function setValid($elem) {
Expand Down Expand Up @@ -90,12 +92,14 @@ require(['jquery', 'mage/translate'], function ($, $t) {
if (cn.length === 0 || ed.length === 0 || cvc.length === 0) {
isValid = false;
}
if (isValid) {
if (isValid && tos.is(':checked')) {
encrypt.setPublicKey(decoded);
encrypted = encrypt.encrypt(cd);
$("#card_data").val(encrypted);
$("#card_short_code").val(cn.substr(-4));
$("#tpaycom_magento2cards_submit").removeClass('disabled');
payButton.removeClass('disabled');
} else {
payButton.addClass('disabled');
}
}

Expand All @@ -109,6 +113,9 @@ require(['jquery', 'mage/translate'], function ($, $t) {
validateCvc($(this));
});

tos.on('change', function () {
enablePayment();
});
}

$(document).ready(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ define(
window.location.replace(window.checkoutConfig.tpay.payment.redirectUrl);
},

getTerms: function () {
return window.checkoutConfig.tpay.payment.getTerms;
},

getLogoUrl: function (code) {
const id = code.slice(code.indexOf('-') + 1);

Expand Down
8 changes: 7 additions & 1 deletion view/frontend/web/template/payment/card-tpay-form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
<div class="payment-method-title field choice">
<input type="radio"
Expand Down Expand Up @@ -128,6 +127,13 @@
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div class="TpayRegulations">
<input type="checkbox" name="accept_tos" id="card_accept_tos"/>
<label for="card_accept_tos">
<a target="_blank"
data-bind="attr: {href: getTerms()}, text: $t('I do accept tpay.com service regulations')"></a>.
</label>
</div>
</div>
<div class="actions-toolbar">
<div class="primary">
Expand Down
14 changes: 13 additions & 1 deletion view/frontend/web/template/payment/tpay-generic-onsite.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@
</div>
<div class="payment-method-content">
<input type="hidden" id="tpay-channel-input" name="tpay-channel-input"/>
<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div class="TpayRegulations">
<input type="checkbox" name="accept_tos" id="generic_accept_tos"/>
<label for="generic_accept_tos">
<a target="_blank"
data-bind="attr: {href: getTerms()}, text: $t('I do accept tpay.com service regulations')"></a>.
</label>
</div>
</div>
<div class="actions-toolbar">
<div class="primary">
<button class="action primary checkout"
id="tpaycom_magento2basic_submit"
id="tpaycom_magento2generic_submit"
type="submit"
data-bind="
click: placeOrder,
Expand Down

0 comments on commit 8e30bc0

Please sign in to comment.