Skip to content
Open
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
56 changes: 49 additions & 7 deletions src/Controller/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@ class Checkout
{
protected $cards = array();

/**
* @var array
* @deprecated This property appears to be unused in the codebase but is kept for backward compatibility.
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The deprecation notice format doesn't follow PHPDoc standards. Standard deprecation notices should use the @deprecated tag with a version number and optionally suggest an alternative. Consider formatting as: @deprecated since x.x.x Use get_payment_methods() instead. This property is kept for backward compatibility.

Suggested change
* @deprecated This property appears to be unused in the codebase but is kept for backward compatibility.
* @deprecated since 1.0.0 This property appears to be unused in the codebase and is kept for backward compatibility.

Copilot uses AI. Check for mistakes.
*/
protected $payment_methods = [];

/**
* Flag to indicate if translations have been loaded
* @var bool
*/
private $translations_loaded = false;

/** @var CardInstallments */
protected $cardInstallments;

Expand All @@ -45,6 +55,30 @@ public function __construct(
add_action('woocommerce_view_order', [$paymentDetails, 'render']);
add_action('wp_ajax_xqRhBHJ5sW', array($this, 'build_installments'));
add_action('wp_ajax_nopriv_xqRhBHJ5sW', array($this, 'build_installments'));

// Load translations later to avoid _load_textdomain_just_in_time warning
add_action('init', array($this, 'load_payment_methods_translations'), 20);

$this->cardInstallments = $cardInstallments;
if (!$this->cardInstallments) {
$this->cardInstallments = new CardInstallments();
}
$this->installments = $installments;
if (!$this->installments) {
$this->installments = new Installments();
}
}

/**
* Loads payment methods translations after init
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The method load_payment_methods_translations() is declared as public to be used as a WordPress action callback, but it's an internal initialization method. While this is a common pattern in WordPress, consider adding a documentation note explaining why it must be public (e.g., "Public visibility required for WordPress action hook callback").

Suggested change
* Loads payment methods translations after init
* Loads payment methods translations after init.
*
* Public visibility required for WordPress action hook callback.
*

Copilot uses AI. Check for mistakes.
* @return void
*/
public function load_payment_methods_translations()
{
if ($this->translations_loaded) {
return;
}

$this->payment_methods = [
'credit_card' => __('Credit card', 'woo-pagarme-payments'),
'billet' => __('Boleto', 'woo-pagarme-payments'),
Expand All @@ -53,14 +87,22 @@ public function __construct(
'billet_and_card' => __('Credit card and Boleto', 'woo-pagarme-payments'),
'voucher' => __('Voucher', 'woo-pagarme-payments'),
];
$this->cardInstallments = $cardInstallments;
if (!$this->cardInstallments) {
$this->cardInstallments = new CardInstallments();
}
$this->installments = $installments;
if (!$this->installments) {
$this->installments = new Installments();

$this->translations_loaded = true;
}

/**
* Get payment methods (load translations if needed)
* @return array
*/
public function get_payment_methods()
{
// If accessed before init hook fired but translations are needed
if (empty($this->payment_methods) && did_action('init')) {
Comment on lines +100 to +101
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The condition logic is flawed. If get_payment_methods() is called before the init hook fires, the method will return an empty array even though translations are needed. The condition did_action('init') returns 0 (falsy) before the hook fires, so the check empty($this->payment_methods) && did_action('init') will be false, and translations won't be loaded.

Consider inverting the logic to: if (!$this->translations_loaded && did_action('init')) to ensure translations are loaded whenever the init hook has fired, or return a meaningful result when called too early.

Suggested change
// If accessed before init hook fired but translations are needed
if (empty($this->payment_methods) && did_action('init')) {
// Load translations once init has fired and they haven't been loaded yet
if (!$this->translations_loaded && did_action('init')) {

Copilot uses AI. Check for mistakes.
$this->load_payment_methods_translations();
}

return $this->payment_methods;
}

/**
Expand Down
Loading