Skip to content

Commit

Permalink
Refund scope update
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Jul 18, 2024
1 parent fe55e45 commit 0386022
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.8
2.0.9
10 changes: 5 additions & 5 deletions Api/TpayConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ public function getInvoiceSendMail(): string;

public function useSandboxMode(?int $storeId = null): bool;

public function getCardApiKey(): ?string;
public function getCardApiKey(?int $storeId = null): ?string;

public function getCardApiPassword(): ?string;
public function getCardApiPassword(?int $storeId = null): ?string;

public function getCardSaveEnabled(): bool;

public function getRSAKey(): ?string;
public function getRSAKey(?int $storeId = null): ?string;

public function getHashType(): ?string;
public function getHashType(?int $storeId = null): ?string;

public function getVerificationCode(): ?string;
public function getVerificationCode(?int $storeId = null): ?string;

public function isAllowSpecific(): bool;

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.9]
### Fixed
- Fixed refund scope

## [2.0.8]
### Fixed
- Fixed admin scope config
Expand Down
12 changes: 8 additions & 4 deletions Model/ApiFacade/Refund/RefundApiFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ class RefundApiFacade
/** @var bool */
private $useOpenApi;

/** @var null|bool */
private $storeId;

private $cache;

public function __construct(TpayConfigInterface $tpay, CacheInterface $cache)
public function __construct(TpayConfigInterface $tpay, CacheInterface $cache, ?int $storeId = null)
{
$this->tpay = $tpay;
$this->cache = $cache;
$this->storeId = $storeId;
}

public function makeRefund(InfoInterface $payment, float $amount)
Expand All @@ -37,7 +41,7 @@ public function makeRefund(InfoInterface $payment, float $amount)
return $this->getCurrentApi()->makeRefund($payment, $amount);
}
if (!empty($payment->getAdditionalInformation('card_data'))) {
return (new RefundCardOriginApi($this->tpay))->makeCardRefund($payment, $amount);
return (new RefundCardOriginApi($this->tpay, $this->storeId))->makeCardRefund($payment, $amount);
}

return $this->originApi->makeRefund($payment, $amount);
Expand All @@ -61,7 +65,7 @@ private function connectApi()
private function createRefundOriginApiInstance(TpayConfigInterface $tpay)
{
try {
$this->originApi = new RefundOriginApi($tpay);
$this->originApi = new RefundOriginApi($tpay, $this->storeId);
} catch (Exception $exception) {
$this->originApi = null;
}
Expand All @@ -70,7 +74,7 @@ private function createRefundOriginApiInstance(TpayConfigInterface $tpay)
private function createOpenApiInstance(TpayConfigInterface $tpay)
{
try {
$this->openApi = new OpenApi($tpay, $this->cache);
$this->openApi = new OpenApi($tpay, $this->cache, $this->storeId);
$this->useOpenApi = true;
} catch (Exception $exception) {
$this->openApi = null;
Expand Down
12 changes: 6 additions & 6 deletions Model/ApiFacade/Refund/RefundCardOriginApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

class RefundCardOriginApi extends CardRefunds
{
public function __construct(TpayConfigInterface $tpay)
public function __construct(TpayConfigInterface $tpay, ?int $storeId = null)
{
Util::$loggingEnabled = false;
$this->cardApiKey = $tpay->getCardApiKey();
$this->cardApiPass = $tpay->getCardApiPassword();
$this->cardVerificationCode = $tpay->getVerificationCode();
$this->cardKeyRSA = $tpay->getRSAKey();
$this->cardHashAlg = $tpay->getHashType();
$this->cardApiKey = $tpay->getCardApiKey($storeId);
$this->cardApiPass = $tpay->getCardApiPassword($storeId);
$this->cardVerificationCode = $tpay->getVerificationCode($storeId);
$this->cardKeyRSA = $tpay->getRSAKey($storeId);
$this->cardHashAlg = $tpay->getHashType($storeId);
parent::__construct();
}

Expand Down
12 changes: 6 additions & 6 deletions Model/ApiFacade/Refund/RefundOriginApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

class RefundOriginApi extends BasicRefunds
{
public function __construct(TpayConfigInterface $tpay)
public function __construct(TpayConfigInterface $tpay, ?int $storeId = null)
{
$this->trApiKey = $tpay->getApiPassword();
$this->trApiPass = $tpay->getApiKey();
$this->merchantId = $tpay->getMerchantId();
$this->merchantSecret = $tpay->getSecurityCode();
$this->trApiKey = $tpay->getApiPassword($storeId);
$this->trApiPass = $tpay->getApiKey($storeId);
$this->merchantId = $tpay->getMerchantId($storeId);
$this->merchantSecret = $tpay->getSecurityCode($storeId);
parent::__construct();
if ($tpay->useSandboxMode()) {
if ($tpay->useSandboxMode($storeId)) {
$this->apiURL = 'https://secure.sandbox.tpay.com/api/gw/';
}
}
Expand Down
3 changes: 2 additions & 1 deletion Model/TpayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ public function assignData(DataObject $data)
*/
public function refund(InfoInterface $payment, $amount)
{
$refundService = new RefundApiFacade($this->configurationProvider, $this->cache);
$storeId = $payment->getOrder()->getStoreId() ? (int) $payment->getOrder()->getStoreId() : null;
$refundService = new RefundApiFacade($this->configurationProvider, $this->cache, $storeId);

$refundResult = $refundService->makeRefund($payment, (float) $amount);
try {
Expand Down
20 changes: 10 additions & 10 deletions Provider/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ public function getApiKey(?int $storeId = null): ?string
return $this->getConfigData('originapi_settings/api_key_tpay', $storeId);
}

public function getCardApiKey(): ?string
public function getCardApiKey(?int $storeId = null): ?string
{
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_key_tpay');
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_key_tpay', $storeId);
}

public function getApiPassword(?int $storeId = null): ?string
{
return $this->getConfigData('originapi_settings/api_password', $storeId);
}

public function getCardApiPassword(): ?string
public function getCardApiPassword(?int $storeId = null): ?string
{
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_password');
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_password', $storeId);
}

public function getInvoiceSendMail(): string
Expand Down Expand Up @@ -174,19 +174,19 @@ public function getCardSaveEnabled(): bool
return (bool) $this->getConfigData('cardpayment_settings/card_save_enabled');
}

public function getRSAKey(): ?string
public function getRSAKey(?int $storeId = null): ?string
{
return $this->getConfigData('cardpayment_settings/rsa_key');
return $this->getConfigData('cardpayment_settings/rsa_key', $storeId);
}

public function getHashType(): ?string
public function getHashType(?int $storeId = null): ?string
{
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/hash_type');
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/hash_type', $storeId);
}

public function getVerificationCode(): ?string
public function getVerificationCode(?int $storeId = null): ?string
{
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/verification_code');
return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/verification_code', $storeId);
}

public function isAllowSpecific(): bool
Expand Down
4 changes: 1 addition & 3 deletions view/base/web/css/tpay.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions view/base/web/css/tpaycards.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions view/base/web/js/open_render_channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/
require(['jquery', 'mage/translate'], function ($, $t) {

var payButton = $('#tpaycom_magento2basic_submit'),
tos = $('#accept_tos');
var payButton = $('#tpaycom_magento2basic_submit');

function getBankTile(groupId, groupName, logoSrc) {
return '<div class="tpay-group-holder tpay-with-logo" id="bank-' + groupId + '">' +
Expand Down Expand Up @@ -103,7 +102,7 @@ require(['jquery', 'mage/translate'], function ($, $t) {
active_bank_blocks[0].className = active_bank_blocks[0].className.replace('tpay-active', '');
}
this.className = this.className + ' tpay-active';
if (input.val() > 0 && $('#blik_code').val().length === 0 && tos.is(':checked')) {
if (input.val() > 0 && $('#blik_code').val().length === 0) {
payButton.removeClass('disabled');
}
});
Expand All @@ -128,8 +127,6 @@ require(['jquery', 'mage/translate'], function ($, $t) {
}
if (
(that.val().length === 6 || (that.val().length === 0 && $('#tpay-channel-input').val() > 0))
&&
tos.is(':checked')
) {
payButton.removeClass('disabled');
}
Expand Down
2 changes: 1 addition & 1 deletion view/base/web/js/renderSavedCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require(['jquery', 'mage/translate'], function ($, $t) {
$('input[name=savedId]').each(function () {
if ($(this).val() !== 'new') {
$(this).click(function () {
if ($(this).is(":checked") && $('#card_accept_tos').is(':checked')) {
if ($(this).is(":checked")) {
$('#card_form').css({opacity: 1.0}).animate({opacity: 0.0}, 500);
setTimeout(
function () {
Expand Down
8 changes: 2 additions & 6 deletions view/base/web/js/render_channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/
require(['jquery', 'mage/translate'], function ($, $t) {

var payButton = $('#tpaycom_magento2basic_submit'),
tos = $('#accept_tos');
var payButton = $('#tpaycom_magento2basic_submit');

function getBankTile(groupId, groupName, logoSrc) {
return '<div class="tpay-group-holder tpay-with-logo" id="bank-' + groupId + '">' +
Expand Down Expand Up @@ -90,7 +89,7 @@ require(['jquery', 'mage/translate'], function ($, $t) {
active_bank_blocks[0].className = active_bank_blocks[0].className.replace('tpay-active', '');
}
this.className = this.className + ' tpay-active';
if (input.val() > 0 && $('#blik_code').val().length === 0 && tos.is(':checked')) {
if (input.val() > 0 && $('#blik_code').val().length === 0) {
payButton.removeClass('disabled');
}
});
Expand Down Expand Up @@ -122,8 +121,6 @@ require(['jquery', 'mage/translate'], function ($, $t) {
}
if (
(that.val().length === 6 || (that.val().length === 0 && $('#tpay-channel-input').val() > 0))
&&
tos.is(':checked')
) {
payButton.removeClass('disabled');
}
Expand All @@ -148,7 +145,6 @@ require(['jquery', 'mage/translate'], function ($, $t) {

$('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');
Expand Down
5 changes: 2 additions & 3 deletions view/base/web/js/tpayCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ require(['jquery', 'mage/translate'], function ($, $t) {
numberInput = $('#card_number'),
expiryInput = $('#expiry_date'),
cvcInput = $('#cvc'),
RSA = $('#tpayRSA').text(),
tos = $('#card_accept_tos');
RSA = $('#tpayRSA').text();

const TRIGGER_EVENTS = 'input change blur';

Expand Down Expand Up @@ -92,7 +91,7 @@ require(['jquery', 'mage/translate'], function ($, $t) {
if (cn.length === 0 || ed.length === 0 || cvc.length === 0) {
isValid = false;
}
if (isValid && tos.is(':checked')) {
if (isValid) {
encrypt.setPublicKey(decoded);
encrypted = encrypt.encrypt(cd);
$("#card_data").val(encrypted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ define(
paymentData = {};
paymentData['group'] = $('#tpay-channel-input').val();
paymentData['blik_code'] = $('#blik_code').val();
paymentData['accept_tos'] = $('input[name="accept_tos"]').is(':checked');
paymentData['accept_tos'] = true;

paymentData['card_data'] = $('input[name="card_data"]').val();
paymentData['card_save'] = $('input[name="card_save"]').is(":checked");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ define(
var parent = this._super(),
paymentData = {};

paymentData['accept_tos'] = $('input[name="accept_tos"]').is(':checked');
paymentData['accept_tos'] = true;

return $.extend(true, parent, {'additional_data': paymentData});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ define(
paymentData = {};
paymentData['group'] = $('#tpay-channel-input').val();
paymentData['blik_code'] = $('#blik_code').val();
paymentData['accept_tos'] = $('input[name="accept_tos"]').is(':checked');
paymentData['accept_tos'] = true;
paymentData['channel'] = "";

return $.extend(true, parent, {'additional_data': paymentData});
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/web/template/payment/card-tpay-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div class="TpayRegulations">
<input type="checkbox" name="accept_tos" id="card_accept_tos" checked/>
<input name="accept_tos" id="card_accept_tos"/>
<label for="card_accept_tos">
<span data-bind="text: $t('By paying, you accept ')"></span>
<a target="_blank" data-bind="attr: {href: getTerms()}, text: $t('regulations')"></a>.<br>
Expand All @@ -149,4 +149,4 @@
</div>
</div>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions view/frontend/web/template/payment/tpay-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div class="TpayRegulations tpay-regulations-offset">
<input type="checkbox" name="accept_tos" id="accept_tos" checked/>
<input name="accept_tos" id="accept_tos"/>
<label for="accept_tos">
<span data-bind="text: $t('By paying, you accept ')"></span>
<a target="_blank" data-bind="attr: {href: getTerms()}, text: $t('regulations')"></a>.<br>
Expand All @@ -91,4 +91,4 @@
</div>
</div>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions view/frontend/web/template/payment/tpay-generic-onsite.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div class="TpayRegulations">
<input type="checkbox" name="accept_tos" class="generic_accept_tos" checked/>
<input name="accept_tos" class="generic_accept_tos"/>
<label for="generic_accept_tos">
<span data-bind="text: $t('By paying, you accept ')"></span>
<a target="_blank" data-bind="attr: {href: getTerms()}, text: $t('regulations')"></a>.<br>
Expand All @@ -41,4 +41,4 @@
</div>
</div>
</div>
</div>
</div>

0 comments on commit 0386022

Please sign in to comment.