Pagbank v3 migration#16
Conversation
There was a problem hiding this comment.
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.jse ajuste do carregamento do SDK atual viapagseguro.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'; | |||
| 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
left a comment
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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'; | |||
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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));
}
Código atualizado com base na documentação do PagBank https://developer.pagbank.com.br/docs/apis-pagbank