Skip to content

Commit

Permalink
WIP: fix cards
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ddly committed Jan 5, 2024
1 parent 9810f37 commit 12ea756
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 182 deletions.
3 changes: 2 additions & 1 deletion Api/TpayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
interface TpayInterface
{
public const CODE = 'tpaycom_magento2basic';
public const CHANNEL = 'group';
public const GROUP = 'group';
public const CHANNEL = 'channel';
public const BLIK_CODE = 'blik_code';
public const TERMS_ACCEPT = 'accept_tos';
public const CARDDATA = 'card_data';
Expand Down
6 changes: 3 additions & 3 deletions Controller/tpay/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function execute()
$paymentData['additional_information']['transaction_url'] = $transactionUrl;
$payment->setData($paymentData)->save();

if (6 === strlen($additionalPaymentInformation['blik_code']) && $this->tpay->checkBlikLevel0Settings()) {
if (6 === strlen($additionalPaymentInformation['blik_code'] ?? '') && $this->tpay->checkBlikLevel0Settings()) {
if (true === $this->transaction->isOpenApiUse()) {
return $this->_redirect('magento2basic/tpay/success');
}
Expand Down Expand Up @@ -119,11 +119,11 @@ private function prepareTransaction($orderId, array $additionalPaymentInformatio
{
$data = $this->tpay->getTpayFormData($orderId);

if (6 === strlen($additionalPaymentInformation['blik_code'])) {
if (6 === strlen($additionalPaymentInformation['blik_code'] ?? '')) {
$data['group'] = TransactionOriginApi::BLIK_CHANNEL;
$this->handleBlikData($data, $additionalPaymentInformation['blik_code']);
} else {
$data['group'] = (int) $additionalPaymentInformation['group'];
$data['group'] = (int) ($additionalPaymentInformation['group'] ?? null);
$data['channel'] = (int) ($additionalPaymentInformation['channel'] ?? null);

if ($this->tpay->redirectToChannel()) {
Expand Down
6 changes: 5 additions & 1 deletion Controller/tpay/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public function execute()
{
$uid = $this->getRequest()->getParam('uid');
$orderId = $this->checkoutSession->getLastRealOrderId();

if (!$orderId || !$uid) {
return $this->_redirect('checkout/cart');
}

$payment = $this->tpayService->getPayment($orderId);
$paymentData = $payment->getData();
$additionalPaymentInfo = $paymentData['additional_information'];
Expand All @@ -41,7 +43,9 @@ public function execute()
return $this->_redirect('magento2basic/tpay/CardPayment');
}

if ((!array_key_exists(TpayInterface::CHANNEL, $additionalPaymentInfo) || (int) $additionalPaymentInfo[TpayInterface::CHANNEL] < 1) && (!array_key_exists(TpayInterface::BLIK_CODE, $additionalPaymentInfo) || 6 !== strlen($additionalPaymentInfo[TpayInterface::BLIK_CODE]))) {


if (empty(array_intersect(array_keys($additionalPaymentInfo), [TpayInterface::GROUP, TpayInterface::CHANNEL])) && (!array_key_exists(TpayInterface::BLIK_CODE, $additionalPaymentInfo) || 6 !== strlen($additionalPaymentInfo[TpayInterface::BLIK_CODE]))) {
return $this->_redirect('checkout/cart');
}
$this->tpayService->setOrderStatePendingPayment($orderId, true);
Expand Down
4 changes: 2 additions & 2 deletions Model/ApiFacade/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ private function handleDataStructure(array $data): array
];
}

if (isset($data['group'])) {
if ($data['group']) {
$paymentData['pay'] = ['groupId' => $data['group']];
}

if (isset($data['channel'])) {
if ($data['channel']) {
$paymentData['pay'] = ['channelId' => $data['channel']];
}

Expand Down
4 changes: 4 additions & 0 deletions Model/ApiFacade/TpayConfig/ConfigFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class ConfigFacade

/** @var bool */
private $useOpenApi;
/**
* @var TpayInterface
*/
private $tpay;

public function __construct(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService)
{
Expand Down
2 changes: 1 addition & 1 deletion Model/ApiFacade/TpayConfig/ConfigOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getConfig(): array
];
$config = array_merge($config, $this->getCardConfig());

return $this->tpay->isAvailable() ? $config : [];
return $config;
}

public function generateURL(string $name): string
Expand Down
1 change: 1 addition & 0 deletions Model/ApiFacade/Transaction/TransactionApiFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Magento\Framework\App\CacheInterface;
use Tpay\OpenApi\Utilities\TpayException;
use tpaycom\magento2basic\Api\TpayInterface;
use tpaycom\magento2basic\Model\ApiFacade\OpenApi;

Expand Down
21 changes: 4 additions & 17 deletions Model/GenericOnSiteConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public function __construct(
Repository $assetRepository,
MethodList $methods,
ScopeConfigInterface $scopeConfig,
TransactionApiFacade $transactionApiFacade
TransactionApiFacade $transactionApiFacade,
TpayConfigProvider $tpayConfigProvider
) {
$this->paymentHelper = $paymentHelper;
$this->assetRepository = $assetRepository;
$this->methodList = $methods;
$this->scopeConfig = $scopeConfig;
$this->transactionApiFacade = $transactionApiFacade;
$this->tpayConfigProvider = $tpayConfigProvider;
}

/**
Expand All @@ -40,22 +42,7 @@ public function getConfig()
$tpay = $this->getPaymentMethodInstance();
$onsites = explode(',', $this->scopeConfig->getValue('payment/tpaycom_magento2basic/onsite_channels', ScopeInterface::SCOPE_STORE));

$config = [
'tpay' => [
'payment' => [
'redirectUrl' => $tpay->getPaymentRedirectUrl(),
'tpayLogoUrl' => $this->generateURL('tpaycom_magento2basic::images/logo_tpay.png'),
'merchantId' => $tpay->getMerchantId(),
'showPaymentChannels' => $this->showChannels(),
'getTerms' => $this->getTerms(),
'addCSS' => $this->createCSS('tpaycom_magento2basic::css/tpay.css'),
'blikStatus' => $this->getPaymentMethodInstance()->checkBlikLevel0Settings(),
'onlyOnlineChannels' => $this->getPaymentMethodInstance()->onlyOnlineChannels(),
'getBlikChannelID' => TransactionOriginApi::BLIK_CHANNEL,
'isInstallmentsAmountValid' => $this->getPaymentMethodInstance()->getInstallmentsAmountValid(),
],
],
];
$config = $this->tpayConfigProvider->getConfig();

$channels = $this->transactionApiFacade->channels();

Expand Down
2 changes: 1 addition & 1 deletion Model/Tpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function assignData(DataObject $data)
$additionalData = $data->getData('additional_data');
$info = $this->getInfoInstance();

$info->setAdditionalInformation(static::CHANNEL, array_key_exists(static::CHANNEL, $additionalData) ? $additionalData[static::CHANNEL] : '');
$info->setAdditionalInformation(static::GROUP, array_key_exists(static::GROUP, $additionalData) ? $additionalData[static::GROUP] : '');

$info->setAdditionalInformation(static::BLIK_CODE, array_key_exists(static::BLIK_CODE, $additionalData) ? $additionalData[static::BLIK_CODE] : '');

Expand Down
3 changes: 3 additions & 0 deletions etc/payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<method name="tpaycom_magento2basic">
<allow_multiple_address>1</allow_multiple_address>
</method>
<method name="tpaycom_magento2basic_cards">
<allow_multiple_address>1</allow_multiple_address>
</method>
<method name="generic">
<allow_multiple_address>1</allow_multiple_address>
</method>
Expand Down
106 changes: 106 additions & 0 deletions view/frontend/web/js/view/payment/method-renderer/tpay-card-method.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
*
* @category payment gateway
* @package Tpaycom_Magento2.3
* @author Tpay.com
* @copyright (https://tpay.com)
*/
define(
[
'Magento_Checkout/js/view/payment/default',
'jquery',
'Magento_Checkout/js/model/totals'
],
function (Component, $) {
'use strict';

return Component.extend({
defaults: {
template: 'tpaycom_magento2basic/payment/card-tpay-form'
},

redirectAfterPlaceOrder: false,

getCode: function () {
return 'tpaycom_magento2basic_cards';
},

afterPlaceOrder: function () {
$("#card_number").val('');
$("#cvc").val('');
$("#expiry_date").val('');
$("#loading_scr").fadeIn();
window.location.replace(window.checkoutConfig.tpay.payment.redirectUrl);
},

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

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

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

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

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

cardFetchJavaScripts: function () {
return window.checkoutConfig.tpaycards.payment.fetchJavaScripts;
},
cardGetRSAkey: function () {
return window.checkoutConfig.tpaycards.payment.getRSAkey;
},
cardGetLogoUrl: function () {
return window.checkoutConfig.tpaycards.payment.tpayLogoUrl;
},
cardGetTpayLoadingGif: function () {
return window.checkoutConfig.tpaycards.payment.getTpayLoadingGif;
},
cardAddCSS: function () {
return window.checkoutConfig.tpaycards.payment.addCSS;
},

cardShowSaveBox: function () {
if (window.checkoutConfig.tpaycards.payment.isCustomerLoggedIn
&& window.checkoutConfig.tpaycards.payment.isSavingEnabled) {
$('#tpay-card-save-checkbox').css('display', 'block');
}
},

getData: function () {
var savedId = 'new';
$('input[id^=cardN]').each(function () {
if ($(this).is(":checked")) {
savedId = $(this).val();
}
});
var parent = this._super(),
paymentData = {};
paymentData['group'] = $('#tpay-channel-input').val();
paymentData['blik_code'] = $('#blik_code').val();
paymentData['accept_tos'] = $('#accept_tos').is(':checked');

paymentData['card_data'] = $('input[name="card_data"]').val();
paymentData['card_save'] = $('input[name="card_save"]').is(":checked");
paymentData['card_id'] = savedId;
paymentData['card_vendor'] = $('input[name="card_vendor"]').val();
paymentData['short_code'] = $('input[name="card_short_code"]').val();

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

isActive: function () {
return true;
},
});
}
);
3 changes: 3 additions & 0 deletions view/frontend/web/js/view/payment/tpay-payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ define(

Object.values(window.checkoutConfig.generic).forEach((element) => rendererList.push({type: `generic-${element.id}`, component: 'tpaycom_magento2basic/js/view/payment/method-renderer/tpay-generic-onsite'}))


rendererList.push({type: 'tpaycom_magento2basic_cards', component: 'tpaycom_magento2basic/js/view/payment/method-renderer/tpay-card-method'});

/** Add view logic here if needed */
return Component.extend({});
}
Expand Down
6 changes: 3 additions & 3 deletions view/frontend/web/template/payment/card-tpay-form.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

<div class="card_payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
<div class="card_payment-method-title field choice">
<input type="radio"
name="payment[card]"
class="radio"
data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
<label data-bind="attr: {'for': getCode()}" class="label">
<img data-bind="attr: {src: cardGetLogoUrl(), alt: $t('tpay.com')}" class="payment-icon"/>
<!-- <img data-bind="attr: {src: cardGetLogoUrl(), alt: $t('tpay.com')}" class="payment-icon"/>-->
<span data-bind="text: getTitle()"></span>
</label>
</div>
<div class="card_payment-method-content" id="card_payment_form">
<div class="payment-method-content" id="card_payment_form">
<div class="card_insidebg">
<div class="tpay-header-wrapper">
<div class="tpay-header-logo">
Expand Down
Loading

0 comments on commit 12ea756

Please sign in to comment.