Skip to content

Pagbank v3 migration#16

Open
rotchajunior wants to merge 2 commits into
mainfrom
pagbank-v3-migration
Open

Pagbank v3 migration#16
rotchajunior wants to merge 2 commits into
mainfrom
pagbank-v3-migration

Conversation

@rotchajunior

Copy link
Copy Markdown

Código atualizado com base na documentação do PagBank https://developer.pagbank.com.br/docs/apis-pagbank

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Atualiza a integração de pagamento para a migração do PagBank/PagSeguro v3, substituindo a tokenização antiga (DirectPayment) pela criptografia de cartão via PagSeguro.encryptCard e ajustando o carregamento do SDK no frontend.

Changes:

  • Troca da geração de token do cartão (DirectPayment) por criptografia (encryptCard) e envio do valor criptografado no fluxo de compra.
  • Remoção do script legado pagseguro.directpayment.js e ajuste do carregamento do SDK atual via pagseguro.min.js.
  • Atualização do modelo de sessão para consumir public_key.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/ui/pages/purchase/purchaseSubmit/PurchaseSubmit.tsx Troca para criptografia de cartão com PagSeguro.encryptCard usando public_key.
src/ui/components/routeChangeManager/RouteChangeManager.tsx Remove referência ao script legado de DirectPayment e mantém apenas o SDK atual.
src/models/purchase.model.ts Ajusta SessionModel para expor public_key.
public/index.html Remove a tag <script> do SDK legado (pagseguro-checkout).

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

@@ -2,25 +2,21 @@ import { useEffect } from 'react';
import { FormPurchaseModel, getCardType, Plan, SessionModel, SubscriptionModel } from '@app/models/purchase.model';
Comment on lines +52 to +57
const encrypted = PagSeguro.encryptCard({
publicKey: response.public_key,
holder: form.fullName.value,
number: form.card.value.replace(/\D/g, ''),
expMonth: form.validity.value.substring(0, 2),
expYear: form.validity.value.substring(2, 6),

scriptCheckout.src = 'https://stc.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.directpayment.js';
}
});
@@ -34,7 +34,7 @@ export interface Plan {
}

export interface SessionModel extends AxiosResponse {

@diraol diraol left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review — Pagbank v3 Migration

Overall the migration is well done and cleaner than the old callback-based v2 API. Leaving a few inline comments on specific issues. No blockers, mainly dead code cleanup and typing improvements.

cardNumber: string;
brand: string | null;
cvv: string;
expirationMonth: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

errors?: any is too loose. PagBank v3 returns structured errors — consider typing this as { code: string; description: string }[] instead of any. Even unknown would be safer.

token: string;
}
hasErrors: boolean;
errors?: any;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

errors?: any is too loose. PagBank v3 returns structured errors — consider typing this as { code: string; description: string }[] instead. Even unknown would be safer than any.

@@ -2,25 +2,21 @@ import { useEffect } from 'react';
import { FormPurchaseModel, getCardType, Plan, SessionModel, SubscriptionModel } from '@app/models/purchase.model';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

getCardType is imported here but never used in this file since the v3 API handles brand detection server-side. This import (and likely the getCardType function in purchase.model.ts) can be removed entirely.

});

if (encrypted.hasErrors) {
onError(errorMessage(paymentErrorMessage));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The errors field is populated by the SDK when hasErrors is true, but it's silently ignored here. At minimum, log the errors for debugging:

if (encrypted.hasErrors) {
  console.error('PagSeguro encryption errors:', encrypted.errors);
  onError(errorMessage(paymentErrorMessage));
}

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.

3 participants