Skip to content

Commit

Permalink
Terms fix
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Jan 17, 2024
1 parent 9a8bf91 commit 7e9cd37
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Controller/tpay/CardPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Tpay\OriginApi\Utilities\Util;
use tpaycom\magento2basic\Api\TpayInterface;
use tpaycom\magento2basic\Model\ApiFacade\CardTransaction\CardApiFacade;
use tpaycom\magento2basic\Model\Tpay;
use tpaycom\magento2basic\Service\TpayService;
use tpaycom\magento2basic\Service\TpayTokensService;

Expand Down Expand Up @@ -49,6 +50,13 @@ public function execute()
$orderId = $this->checkoutSession->getLastRealOrderId();

if ($orderId) {
$payment = $this->tpayService->getPayment($orderId);
$additionalPaymentInformation = $payment->getData()['additional_information'];

if (!$additionalPaymentInformation[Tpay::TERMS_ACCEPT]) {
return $this->_redirect('magento2basic/tpay/error');
}

$cardTransaction = new CardApiFacade($this->tpay, $this->tokensService, $this->tpayService, $this->storeManager);
$redirectUrl = $cardTransaction->makeCardTransaction($orderId);

Expand Down
5 changes: 5 additions & 0 deletions Controller/tpay/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use tpaycom\magento2basic\Api\TpayInterface;
use tpaycom\magento2basic\Model\ApiFacade\Transaction\TransactionApiFacade;
use tpaycom\magento2basic\Model\ApiFacade\Transaction\TransactionOriginApi;
use tpaycom\magento2basic\Model\Tpay;
use tpaycom\magento2basic\Service\TpayService;

class Create extends Action
Expand Down Expand Up @@ -56,6 +57,10 @@ public function execute(): ResponseInterface
$this->transaction = new TransactionApiFacade($this->tpay, $this->cache);
$additionalPaymentInformation = $paymentData['additional_information'];

if (!$additionalPaymentInformation[Tpay::TERMS_ACCEPT]) {
return $this->_redirect('magento2basic/tpay/error');
}

$transaction = $this->prepareTransaction($orderId, $additionalPaymentInformation);

if (!isset($transaction['title'], $transaction['url'])) {
Expand Down
4 changes: 1 addition & 3 deletions Model/Tpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ public function assignData(DataObject $data)

$info->setAdditionalInformation('channel', $additionalData['channel'] ?? null);

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

// KARTY
$info->setAdditionalInformation(static::CARDDATA, $additionalData[static::CARDDATA] ?? '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ define(
paymentData = {};
paymentData['group'] = $('#tpay-channel-input').val();
paymentData['blik_code'] = $('#blik_code').val();
paymentData['accept_tos'] = $('#accept_tos').is(':checked');
paymentData['accept_tos'] = $('input[name="accept_tos"]').is(':checked');

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 @@ -33,6 +33,15 @@ define(

redirectAfterPlaceOrder: false,

getData: function () {
var parent = this._super(),
paymentData = {};

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

return $.extend(true, parent, {'additional_data': paymentData});
},

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

paymentData['card_data'] = $('input[name="card_data"]').val();
paymentData['card_save'] = $('input[name="card_save"]').is(":checked");
Expand Down

0 comments on commit 7e9cd37

Please sign in to comment.