Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions payu/controllers/front/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,37 @@ public function process()
'select_payment_option' => $paymentId
]

)
);
}
}
}
elseif ($payMethod === 'ap') {
$googlePayToken = Tools::getValue('payuGoogleToken');
$paymentId = Tools::getValue('payment_id');

if ($googlePayToken) {
$this->pay($payMethod, ['googlePayToken' => $googlePayToken], $payMethod);
} else{
$this->payuNotification[$payMethod] = $this->module->l('Google Pay token is empty', 'payment');

if ($this->hasRetryPayment) {
$params = [
'id_order' => Tools::getValue('id_order'),
'select_payment_option' => $paymentId
];
$this->payuRedirectWithNotifications(
$this->context->link->getPageLink('order-detail', null, null, $params)
);
} else {
$this->payuRedirectWithNotifications(
$this->context->link->getPageLink('order',
null,
null,
[
'select_payment_option' => $paymentId
]

)
);
}
Expand Down
7 changes: 7 additions & 0 deletions payu/css/payu.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ p.payment_module a.payu_blik {
padding: 33px 40px 34px 80px;
}

p.payment_module a.payu_google_pay {
background: url('../img/payu_google_pay.svg') 15px 33px no-repeat #fbfbfb;
}

p.payment_module a.payu_google_pay {
padding: 33px 40px 34px 80px;
}
p.payment_module a.payu_main {
background: url('../img/logo-payu.svg') 15px 33px no-repeat #fbfbfb;
}
Expand Down
17 changes: 17 additions & 0 deletions payu/img/payu_google_pay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 119 additions & 12 deletions payu/js/payu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ openpayu.options = openpayu.options || {};

$(document).ready(function () {
$('#payuRetryPayment').insertAfter($('.info-order').first());

$('body').on('click', '.payu-read-more', function () {
$(this).hide();
var elementToShow = $(this).data('more');
Expand Down Expand Up @@ -81,6 +80,7 @@ function doubleClickPrevent(object) {
document.querySelectorAll('.payu-payment-fieldset-1-6 .payment_module, .repayment-options').forEach(function (elm) {
validateBeforeSubmitCardForm();
validateBeforeSubmitGatewaysForm();
validateBeforeSubmitGooglePay();
});


Expand Down Expand Up @@ -116,6 +116,7 @@ function doubleClickPrevent(object) {
function validateBeforeSubmitCardForm() {
if($('.repayment-options').length > 0 && $('.repayment-options').hasClass('has-sf') && $('[name="payMethod"]').val() == 'card' || $('.repayment-options').length == 0) {
var paymentCardSubmit = document.querySelector('#payment-confirmation .btn, .repayment-options input[type="submit"], #secure-form-pay');

if (paymentCardSubmit !== null) {
paymentCardSubmit.addEventListener('click', function (e) {
if($('#card-form-container').is(':visible')) {
Expand All @@ -131,7 +132,20 @@ function doubleClickPrevent(object) {
}
}

function validateBeforeSubmitGooglePay() {
var paymentGooglePaySubmit = document.querySelector('#payment-confirmation .btn, .repayment-options input[type="submit"], #google-pay-submit');

if(paymentGooglePaySubmit !== null) {
paymentGooglePaySubmit.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
payuGooglePayValidate();

return false;
});
}
}
function payuGatewaysValidate() {
var validateResponse = document.getElementById('transfer-response-box');
var btn = document.querySelector('.pay-transfer-accept button');
Expand Down Expand Up @@ -188,12 +202,13 @@ function doubleClickPrevent(object) {
init_sf();
validateBeforeSubmitCardForm();
validateBeforeSubmitGatewaysForm();
validateBeforeSubmitGooglePay();
}, 4000)
});

function payuCardValidate() {

hideMessageBox();
hideMessageBoxSecureForm();
window.cardTokenInput.value = '';
window.secureFormNumber.update({disabled: true});
window.secureFormDate.update({disabled: true});
Expand Down Expand Up @@ -229,17 +244,97 @@ function doubleClickPrevent(object) {
errorMessage += '<strong>' + error.message + '<strong><br>';
});

showMessageBox(errorMessage);
showMessageBoxSecureForm(errorMessage);

window.secureFormNumber.update({disabled: false});
window.secureFormDate.update({disabled: false});
window.secureFormCvv.update({disabled: false});
}
});
} catch (e) {
showMessageBox(e.message);
showMessageBoxSecureForm(e.message);
}
}

function payuGooglePayValidate(){
hideMessageBoxGooglePay();
if (!window.google?.payments?.api?.PaymentsClient) {
showMessageBoxGooglePay(googlePayErrorMessage);
return false;
}
var googleToken = document.getElementById('payu-google-token');

if(googleToken.value === ''){
const paymentsClient =
new google.payments.api.PaymentsClient({environment: env});

const isReadyToPayRequest = {
apiVersion: 2,
apiVersionMinor: 0,
allowedPaymentMethods: [
{
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['MASTERCARD', 'VISA']
}
}
]
}

const paymentDataRequest = {
apiVersion: 2,
apiVersionMinor: 0,
merchantInfo: {
merchantName,
merchantId,
},
allowedPaymentMethods: [
{
type: 'CARD',
parameters: {
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
allowedCardNetworks: ['MASTERCARD', 'VISA'],
billingAddressRequired: false
},
tokenizationSpecification: {
type: 'PAYMENT_GATEWAY',
parameters: {
gateway: 'payu',
gatewayMerchantId: posId
}
}
}
],
transactionInfo: {
totalPriceStatus: 'FINAL',
countryCode: 'PL',
totalPrice,
currencyCode: currency
}
}

paymentsClient.isReadyToPay(isReadyToPayRequest)
.then(function(response) {
if (response.result) {
paymentsClient.loadPaymentData(paymentDataRequest).then(function(paymentData){
paymentToken = paymentData.paymentMethodData.tokenizationData.token;
googleToken.value = btoa(paymentToken);
document.getElementById('payu-google-pay-form').submit();
}).catch(function(err){
console.error(err);
});
}
})
.catch(function(err) {
console.error(err);
showMessageBoxGooglePay(googlePayErrorMessage);
});

return false;
}
else return true;
}
});
})();

Expand Down Expand Up @@ -332,14 +427,26 @@ function secureFormResize() {
}
}

function showMessageBox(message) {
var responseBox = document.getElementById('response-box');
responseBox.innerHTML = message;
responseBox.style.display = '';
function showMessageBoxSecureForm(message) {
var responseBoxSecureForm = document.getElementById('response-box-secure-form');
responseBoxSecureForm.innerHTML = message;
responseBoxSecureForm.style.display = '';
}

function hideMessageBoxSecureForm() {
var responseBoxSecureForm = document.getElementById('response-box-secure-form');
responseBoxSecureForm.innerHTML = '';
responseBoxSecureForm.style.display = 'none';
}

function showMessageBoxGooglePay(message) {
var responseBoxGooglePay = document.getElementById('response-box-google-pay');
responseBoxGooglePay.innerHTML = message;
responseBoxGooglePay.style.display = '';
}

function hideMessageBox() {
var responseBox = document.getElementById('response-box');
responseBox.innerHTML = '';
responseBox.style.display = 'none';
function hideMessageBoxGooglePay(){
var responseBoxGooglePay = document.getElementById('response-box-google-pay');
responseBoxGooglePay.innerHTML = '';
responseBoxGooglePay.style.display = 'none';
}
Loading