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
24 changes: 12 additions & 12 deletions assets/javascripts/front/checkout/model/payment/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ let pagarmeCard = {
},
isPagarmePayment: function () {
const selectedPayment = pagarmeCard.getSelectedPaymentMethod();
if(selectedPayment.length <= 0) {
if (selectedPayment.length <= 0) {
return false;
}
const selectedPaymentVal = selectedPayment.val();
if(!selectedPaymentVal) {
if (!selectedPaymentVal) {
return false;
}
if(selectedPaymentVal.indexOf('pagarme') === -1) {
if (selectedPaymentVal.indexOf('pagarme') === -1) {
return false;
}
return selectedPaymentVal.indexOf('pagarme');
Expand All @@ -63,7 +63,7 @@ let pagarmeCard = {
}

const selectedIsPagarmeCard = pagarmeCard.getSelectedPaymentMethod().val().indexOf('card');
if(selectedIsPagarmeCard === -1) {
if (selectedIsPagarmeCard === -1) {
return false;
}

Expand All @@ -74,7 +74,7 @@ let pagarmeCard = {
const regex = /[^a-z ]/gi;
const val = jQuery(element).val();

if(regex.test(val)) {
if (regex.test(val)) {
jQuery(element).val(val.replace(regex, ''));
selectionStart--;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ let pagarmeCard = {
if (doesNotHaveBrand) {
pagarmeCard.showErrorInPaymentMethod(
PagarmeGlobalVars.checkoutErrors.pt_BR[
'invalidBrand'
'invalidBrand'
]
);
return;
Expand Down Expand Up @@ -344,7 +344,7 @@ let pagarmeCard = {
}
});
ajax.done(function (response) {
pagarmeCard._done(select, info, storageName, cardForm, JSON.parse(response));
pagarmeCard._done(select, info, storageName, cardForm, response);
});
ajax.fail(function () {
pagarmeCard._fail(cardForm);
Expand All @@ -357,7 +357,7 @@ let pagarmeCard = {
_done: function (select, info, storageName, event, response) {
if (info.length) {
info.addClass('pagarme-hidden');
if(response.installmentsConfig > 1) {
if (response.installmentsConfig > 1) {
info.removeClass('pagarme-hidden');
}
}
Expand All @@ -373,7 +373,7 @@ let pagarmeCard = {

if (typeof formattedEvent.unblock === 'function') {
formattedEvent.unblock();
return;
return;
}

if (typeof jQuery.unblockUI === 'function') {
Expand All @@ -391,7 +391,7 @@ let pagarmeCard = {
opacity: 0.6
}
});
return;
return;
}

if (typeof jQuery.blockUI === 'function') {
Expand Down Expand Up @@ -477,7 +477,7 @@ let pagarmeCard = {
pagarmeTokenize.execute();
pagarmeCard.execute(event);
},
brandIsVisaOrMaster: function() {
brandIsVisaOrMaster: function () {
const checkoutPaymentElement = this.getCheckoutPaymentElement();
const brand = jQuery(checkoutPaymentElement).find(this.brandTarget)
.val();
Expand Down Expand Up @@ -562,4 +562,4 @@ let pagarmeCard = {
this.onChangeBillingCpf();
}
};
pagarmeCard.start();
pagarmeCard.start();
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a trailing whitespace at the end of this line. Trailing whitespaces should be removed to maintain code cleanliness and avoid unnecessary git diff noise.

Suggested change
pagarmeCard.start();
pagarmeCard.start();

Copilot uses AI. Check for mistakes.
9 changes: 7 additions & 2 deletions src/Controller/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,17 @@ public function build_installments()

);
$optionsHtml = $this->cardInstallments->renderOptions($installments);
echo json_encode([

// Ensure no previous output contaminates the JSON response
if (ob_get_length()) {
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ob_get_length() function returns false if output buffering is not active, which will cause the condition to be falsy and skip the ob_clean() call. However, calling ob_clean() when no buffer is active will generate a notice. The current implementation is safe, but consider using if (ob_get_level() > 0) instead to be more explicit about checking if output buffering is active.

Suggested change
if (ob_get_length()) {
if (ob_get_level() > 0) {

Copilot uses AI. Check for mistakes.
ob_clean();
}

wp_send_json([
'installmentsConfig' => $installmentsConfig,
'optionsHtml' => wp_kses_no_null($optionsHtml),
'installments' => $installments
]);
exit();
}

public function parse_cards($data, $key = 'card')
Expand Down
5 changes: 4 additions & 1 deletion src/Controller/Webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public function handle_requests()
$this->config->log()->info('Webhook Received: empty body!');
return;
}
if (!$this->orderByWoocommerce($body->data->code, $body->data->order->metadata, $body->id) ) {
$code = $body->data->code ?? null;
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null coalescing operator ?? does not protect against accessing properties on null objects. If $body->data is null, this line will throw "Attempt to read property 'code' on null" error before the ?? operator can apply.

Consider adding an explicit check for $body->data first, or use PHP 8.0+ null-safe operator: $code = $body?->data?->code ?? null; or $code = isset($body->data->code) ? $body->data->code : null;

Copilot uses AI. Check for mistakes.
$metadata = $body->data->order->metadata ?? null;
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null coalescing operator on line 65 does not fully protect against null pointer errors. If $body->data is null, accessing $body->data->order will still throw "Attempt to read property 'order' on null" error before the ?? operator can apply.

Consider adding an explicit check: $metadata = isset($body->data->order->metadata) ? $body->data->order->metadata : null; or use the null-safe operator if PHP 8.0+ is available: $metadata = $body?->data?->order?->metadata ?? null;

Suggested change
$metadata = $body->data->order->metadata ?? null;
$metadata = isset($body->data->order->metadata) ? $body->data->order->metadata : null;

Copilot uses AI. Check for mistakes.

if (!$this->orderByWoocommerce($code, $metadata, $body->id) ) {
return;
}

Expand Down
Loading