Skip to content

Fix/json parse error#594

Open
proteusbr1 wants to merge 4 commits intopagarme:developfrom
proteusbr1:fix/json-parse-error
Open

Fix/json parse error#594
proteusbr1 wants to merge 4 commits intopagarme:developfrom
proteusbr1:fix/json-parse-error

Conversation

@proteusbr1
Copy link
Copy Markdown

Git Merge

Qual o tipo de PR é esse? (marque todos os aplicáveis)

  • Refatoração
  • Adição de funcionalidade
  • Correção de bug
  • Otimização
  • Atualização de documentação

Descrição

Este PR corrige um erro crítico (SyntaxError: Unexpected token '<') que ocorria no frontend durante o checkout.

A action AJAX xqRhBHJ5sW (responsável por buscar as configurações de parcelamento) estava retornando HTML ou avisos PHP misturados com o JSON, o que quebrava o JSON.parse no JavaScript card.js.

Alterações realizadas:

  • Substituição do echo json_encode(...) pela função nativa do WordPress wp_send_json(...), que garante os headers corretos e encerra a execução adequadamente.
  • Adição de ob_clean() antes do envio da resposta para limpar qualquer "sujeira" (notices, espaços em branco, hooks de outros plugins) que possa ter sido impressa no buffer de saída antes do JSON.

This commit adds safe property access (null coalescing) for webhook payload data, specifically preventing errors when 'data->order' is missing in the webhook body.
Copilot AI review requested due to automatic review settings January 16, 2026 14:53
@backstage-catalog-validator
Copy link
Copy Markdown

⚠️ Este repositório ainda não está catalogado no Backstage. ⚠️

Por favor, catalogue-o seguindo as instruções nesta documentação. [Via VPN].

💁 Qualquer problema ou dúvida, estamos no Slack, basta abrir um ticket no canal #help-foundation-platform.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug where AJAX responses in the checkout process were returning malformed JSON due to PHP warnings or HTML output being mixed with JSON data, causing SyntaxError: Unexpected token '<' errors in the frontend.

Changes:

  • Replaced echo json_encode() with WordPress's native wp_send_json() function for proper JSON responses
  • Added output buffer cleaning before sending JSON to prevent contamination from previous output
  • Added defensive null coalescing operators to prevent potential errors when accessing webhook data properties

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Controller/Checkout.php Fixed AJAX JSON response handling by using wp_send_json() instead of manual echo json_encode(), added output buffer cleaning, and removed redundant exit() call
src/Controller/Webhooks.php Added null coalescing operators to safely access potentially undefined webhook data properties

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

$code = $body->data->code ?? null;
$metadata = $body->data->order->metadata ?? null;

if (!$this->orderByWoocommerce($code, $metadata, $body->id) ) {
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.

Extra space before closing parenthesis. Remove the space to maintain consistent code formatting throughout the codebase.

Suggested change
if (!$this->orderByWoocommerce($code, $metadata, $body->id) ) {
if (!$this->orderByWoocommerce($code, $metadata, $body->id)) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants