Skip to content

Commit

Permalink
Merge pull request #412 from pagarme/develop
Browse files Browse the repository at this point in the history
Release 3.2.2
  • Loading branch information
mateus-picoloto authored Apr 18, 2024
2 parents ca1981f + c5ae2c6 commit 33d54bc
Show file tree
Hide file tree
Showing 81 changed files with 2,262 additions and 521 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
with:
args: >
-Dsonar.php.coverage.reportPaths=coverage/clover.xml
-Dsonar.coverage.exclusions=tests/**,assets/**,templates/**,woo-pagarme-payments.php
-Dsonar.coverage.exclusions=tests/**,assets/**,src/Controller/**,templates/**,woo-pagarme-payments.php
-Dsonar.tests=tests/
-Dsonar.sources=src,assets,templates,woo-pagarme-payments.php
Expand Down
43 changes: 21 additions & 22 deletions assets/javascripts/admin/pagarme_notices.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { __ } = wp.i18n;
/* jshint esversion: 6 */
jQuery(function ($) {
$('.pagarme-get-hub-account-info').on('click', function (e) {
try {
swal({
title: ' ',
text: __('Processing', 'woo-pagarme-payments'),
swal.fire({
title: 'Processando',
icon: 'warning',
allowOutsideClick: false
});
swal.showLoading();
Expand All @@ -16,30 +16,29 @@ jQuery(function ($) {
command: 'get'
}),
success: function (response) {
swal(
__('Success!', 'woo-pagarme-payments'),
__('Dash configuration was retrieved successfully. The page is reloading. Please, wait a moment.',
'woo-pagarme-payments'
),
'success'
)
swal.fire({
title: 'Sucesso!',
text: 'As configurações da Dash foram recuperadas com sucesso. A página está recarregando.' +
' Por favor, aguarde um momento.',
icon: 'success'
});
document.location.reload(true);
},
fail: function (response) {
swal(
__('Fail!', 'woo-pagarme-payments'),
__('Dash configuration was not retrieved. Please, try again.', 'woo-pagarme-payments'),
'error'
)
swal.fire({
title: 'Falha!',
text: 'As configurações da Dash não foram recuperadas. Por favor, tente novamente.',
icon: 'error'
});
}

});
} catch (e) {
swal(
__('Fail!', 'woo-pagarme-payments'),
__('Dash configuration was not retrieved. Please, try again.', 'woo-pagarme-payments'),
'error'
)
} catch (error) {
swal.fire({
title: 'Falha!',
text: 'As configurações da Dash não foram recuperadas. Por favor, tente novamente.',
icon: 'error'
});
}
});
});
13 changes: 6 additions & 7 deletions assets/javascripts/admin/pagarme_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,19 @@
const element = $(this);
const value = element.val();
if (value === 'yes') {
swal({
swal.fire({
type: 'warning',
title: allow_no_address_swal.title,
text: allow_no_address_swal.text,
showConfirmButton: true,
showCancelButton: true,
cancelButtonText: allow_no_address_swal.cancelButtonText,
showDenyButton: true,
denyButtonText: allow_no_address_swal.cancelButtonText,
allowOutsideClick: false,
}).then(
function (confirm) {},
function (cancel) {
}).then((result) => {
if (!result.isConfirmed) {
element.val('no');
}
);
});
}
}
);
Expand Down
22 changes: 12 additions & 10 deletions assets/javascripts/admin/sales/order/view/cancel-capture.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* jshint esversion: 6 */
$ = jQuery;
const actionsTarget = '[data-ref]:enabled';
const modalTarget = '.modal';
Expand Down Expand Up @@ -101,9 +102,9 @@ let pagarmeCancelCapture = {
},

requestInProgress: function () {
swal({
title: ' ',
text: 'Processando...',
swal.fire({
title: 'Processando',
icon: 'warning',
allowOutsideClick: false
});
swal.showLoading();
Expand All @@ -113,14 +114,14 @@ let pagarmeCancelCapture = {
this.lock = false;
$( modalTarget ).iziModal('close');
swal.close();
swal({
type: 'success',
swal.fire({
icon: 'success',
title: ' ',
html: response.data.message,
showConfirmButton: false,
timer: 2000
timer: 2000,
timerProgressBar: true
}).then(
function () { },
function (dismiss) {
window.location.reload();
}
Expand All @@ -135,12 +136,13 @@ let pagarmeCancelCapture = {
this.lock = false;
swal.close();
let data = JSON.parse(xhr.responseText);
swal({
type: 'error',
swal.fire({
icon: 'error',
title: ' ',
html: data.message,
showConfirmButton: false,
timer: 2000
timer: 2000,
timerProgressBar: true
});
},

Expand Down
34 changes: 0 additions & 34 deletions assets/javascripts/front/checkout/model/payment.js

This file was deleted.

117 changes: 84 additions & 33 deletions assets/javascripts/front/checkout/model/payment/card.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/* globals wc_pagarme_checkout */
/*jshint esversion: 8 */
/* jshint esversion: 11 */
let pagarmeCard = {
limitTokenize: 10,
tokenExpirationAttribute: 'data-pagarmecheckout-expiration',
cardNumberTarget: 'input[data-element="pagarme-card-number"]',
brandTarget: 'input[data-pagarmecheckout-element="brand-input"]',
valueTarget: 'input[data-pagarmecheckout-element="order-value"]',
cardHolderNameTarget: 'input[data-element="card-holder-name"]',
cardExpiryTarget: 'input[data-element="card-expiry"]',
cardCvvTarget: 'input[data-element="card-cvv"]',
brandTarget: 'input[data-pagarme-element="brand-input"]',
valueTarget: 'input[data-pagarme-element="order-value"]',
installmentsTarget: '[data-pagarme-component="installments"]',
installmentsInfoTarget: '[data-pagarme-component="installments-info"]',
mundiCdn: 'https://cdn.mundipagg.com/assets/images/logos/brands/png/',
tokenElement: '[data-pagarmecheckout-element="token"]',
tokenElement: '[data-pagarme-element="token"]',
fieldsetCardElements: 'fieldset[data-pagarmecheckout="card"]',
billingCpfId: '#billing_cpf',
voucherDocumentHolder: 'input[name="pagarme[voucher][cards][1][document-holder]"]',
Expand Down Expand Up @@ -221,6 +224,17 @@ let pagarmeCard = {

let imageSrc = this.getImageSrc(card);
let imgElem = jQuery(elem).parent().find('img');

const doesNotHaveBrand = !card[0].brand || card[0]?.brand?.length === 0;
if (doesNotHaveBrand) {
pagarmeCard.showErrorInPaymentMethod(
PagarmeGlobalVars.checkoutErrors.pt_BR[
'invalidBrand'
]
);
return;
}

jQuery(elem).parents('.pagarme-card-number-row').find(this.brandTarget).attr('value', card[0].brand);
if (imgElem.length) {
imgElem.attr('src', imageSrc);
Expand All @@ -233,6 +247,24 @@ let pagarmeCard = {
);
}
},
showErrorInPaymentMethod: function (error) {
const element = jQuery('input[name$="payment_method"]:checked')
.closest("li")
.find("#wcmp-checkout-errors");

swal.close();

wc_pagarme_checkout.errorList = `<li>${error}<\li>`;

element.find(".woocommerce-error").html(wc_pagarme_checkout.errorList);
element.slideDown();

const rect = element.get(0).getBoundingClientRect();

jQuery("#wcmp-submit").removeAttr("disabled", "disabled");

window.scrollTo(0, rect.top + window.scrollY - 40);
},
getImageSrc: function (card) {
if (card[0].image) {
return card[0].image;
Expand Down Expand Up @@ -288,17 +320,17 @@ let pagarmeCard = {
}
});
ajax.done(function (response) {
pagarmeCard._done(select, info, storageName, cardForm, JSON.parse(response));
pagarmeCard._done(select, info, storageName, JSON.parse(response));
});
ajax.fail(function () {
pagarmeCard._fail(cardForm);
pagarmeCard._fail();
});
pagarmeCard.showLoader(cardForm);
pagarmeCard.showLoader();
}
return true;
},

_done: function (select, info, storageName, event, response) {
_done: function (select, info, storageName, response) {
if (info.length) {
info.addClass('pagarme-hidden');
if(response.installmentsConfig > 1) {
Expand All @@ -307,35 +339,35 @@ let pagarmeCard = {
}
select.html(response.optionsHtml);
sessionStorage.setItem(storageName, response);
this.removeLoader(event);
this.removeLoader();
},
_fail: function (event) {
this.removeLoader(event);
_fail: function () {
this.removeLoader();
},
removeLoader: function (event) {
if (!(event instanceof jQuery)) {
event = jQuery(event);
removeLoader: function () {
if (typeof jQuery.unblockUI === 'function') {
jQuery.unblockUI();
}
event.unblock();
},
showLoader: function (event) {
event = this.formatEventToJQuery(event)
event.block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
showLoader: function () {
if (typeof jQuery.blockUI === 'function') {
jQuery.blockUI({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
}
},
showError: function (text) {
const errorMessageText = this.translateErrors('card', text);
const message = {
type: 'error',
icon: 'error',
html: errorMessageText,
allowOutsideClick: false
};
swal(message);
swal.fire(message);
},
translateErrors: function (error, message) {
error = error.replace('request.', '');
Expand All @@ -347,15 +379,14 @@ let pagarmeCard = {
return output;
},
execute: async function (event) {
const checkoutPaymentElement = this.getCheckoutPaymentElement();
try {
for (let i = 1; !pagarmeCard.isTokenized() && i <= this.limitTokenize; i++) {
if (i === this.limit) {
this.removeLoader(checkoutPaymentElement);
this.removeLoader();
throw new Error("Tokenize timeout");
}
if (wc_pagarme_checkout.errorTokenize === true) {
this.removeLoader(checkoutPaymentElement);
this.removeLoader();
return;
}
await pagarmeCard.wait();
Expand All @@ -371,20 +402,39 @@ let pagarmeCard = {
}
},
canExecute: function (event) {
if (!wc_pagarme_checkout.validate() || wc_pagarme_checkout.errorTokenize === true) {
const checkoutPaymentElement = pagarmeCard.getCheckoutPaymentElement();
const cardBrand = checkoutPaymentElement.parents('.pagarme-card-number-row')
.find(this.brandTarget);
if (cardBrand?.val()?.length === 0 || wc_pagarme_checkout.errorTokenize === true) {
return false;
}
let checkoutPaymentElement = pagarmeCard.getCheckoutPaymentElement();

if (pagarmeCard.isPagarmePayment() &&
!pagarmeCard.isTokenized() &&
pagarmeCard.haveCardForm(checkoutPaymentElement)
) {
pagarmeTokenize.execute();
pagarmeCard.execute(event);
if (typeof pagarmeTds == 'object') {
const tdsExecuted = pagarmeTds.start(event);

if (tdsExecuted) {
return false;
}
}
this.executeAll(event);
return false;
}
return true;
},
executeAll: function (event) {
pagarmeTokenize.execute();
pagarmeCard.execute(event);
},
brandIsVisaOrMaster: function() {
const checkoutPaymentElement = this.getCheckoutPaymentElement();
const brand = jQuery(checkoutPaymentElement).find(this.brandTarget)
.val();
return brand === "visa" || brand === "mastercard";
},
onChangeBillingCpf: function () {
let cpf = jQuery(this.billingCpfId).val();
jQuery(this.voucherDocumentHolder).empty();
Expand Down Expand Up @@ -435,6 +485,7 @@ let pagarmeCard = {
}
},
start: function () {
jQuery.jMaskGlobals.watchDataMask = true;
this.getCardsMethods();
this.addEventListener();
this.onChangeBillingCpf();
Expand Down
Loading

0 comments on commit 33d54bc

Please sign in to comment.