Skip to content

Feat/simplified version #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 22, 2025
Merged

Feat/simplified version #1

merged 3 commits into from
Jul 22, 2025

Conversation

mCodex
Copy link
Owner

@mCodex mCodex commented Jul 22, 2025

This pull request introduces significant changes to the PlugpagNitro module, focusing on simplifying the payment flow, removing redundant methods, and improving event handling. The most notable updates include the consolidation of payment methods, the removal of the doPaymentWithEvents method, and enhancements to the event listener interface. Additionally, unused helper functions and presets were removed to streamline the codebase.

Event Handling Enhancements:

  • Added initialization in PlugpagEventEmitter to save an instance for emitting events and improved logging for emitPaymentEvent to handle null instances gracefully (PlugpagEventEmitter.kt, [1] [2].

Payment Flow Simplification:

  • Removed the doPaymentWithEvents method and consolidated its functionality into the existing doPayment method, which now includes built-in event handling (PlugpagNitro.kt, [1]; index.tsx, [2] [3].
  • Updated the useTransactionEvent hook to include a resetEvent method, replacing the older useTransactionPaymentEvent hook (index.tsx, [1] [2].

Codebase Cleanup:

  • Removed unused helper functions (isTransactionSuccessful, getTransactionError) and payment presets (PaymentPresets) to reduce clutter and improve maintainability (index.tsx, src/index.tsxL304-L356).
  • Deleted the custom usePaymentFlow hook, as its functionality is no longer required after the payment flow simplification (index.tsx, src/index.tsxL197-L258).

Configuration Updates:

  • Removed the react-native.config.js file, as it is no longer necessary for module configuration (react-native.config.js, react-native.config.jsL1-L13).

TypeScript Interface Adjustments:

  • Removed the doPaymentWithEvents method from the PlugpagNitro TypeScript interface to align with the updated API (PlugpagNitro.nitro.ts, src/PlugpagNitro.nitro.tsL186-L204).

mCodex added 3 commits July 22, 2025 13:20
- Updated `emitPaymentEvent` in `PlugpagEventEmitter.kt` to include a custom message parameter for better event logging.
- Refactored `App.tsx` to utilize the new event emission structure, displaying real-time payment event updates.
- Removed deprecated `doPaymentWithEvents` function and integrated its functionality into the standard `doPayment` method.
- Simplified payment flow management by eliminating the `usePaymentFlow` hook.
- Added a new function `generatePixQRCode` for generating PIX QR codes.
- Cleaned up unused styles and components in the UI for better readability and performance.
@Copilot Copilot AI review requested due to automatic review settings July 22, 2025 19:30
@mCodex mCodex merged commit e02d6e2 into main Jul 22, 2025
2 of 4 checks passed
Copy link

@Copilot 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 simplifies the React Native PlugPag Nitro library by removing complex payment flow features and consolidating functionality into a more streamlined API. The changes focus on providing essential payment processing capabilities with real-time event monitoring while removing advanced workflow management features.

  • Removes the doPaymentWithEvents function and consolidates event handling into the main doPayment function
  • Simplifies the React hooks API by replacing useTransactionPaymentEvent with useTransactionEvent and removing usePaymentFlow
  • Eliminates helper functions, payment presets, and React Native configuration files to reduce API surface area

Reviewed Changes

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

Show a summary per file
File Description
src/index.tsx Major API simplification removing payment flow hooks, helper functions, and payment presets
src/PlugpagNitro.nitro.ts Removes doPaymentWithEvents interface definition
react-native.config.js Completely removes React Native configuration file
example/src/App.tsx Updates example app to use simplified API with basic payment functions
android/.../PlugpagNitro.kt Consolidates payment methods by removing separate doPayment implementation
android/.../PlugpagEventEmitter.kt Enhances event emitter with better logging and custom message support
README.md Comprehensive documentation update reflecting the simplified API
Comments suppressed due to low confidence (1)

example/src/App.tsx:127

  • [nitpick] Function name uses inconsistent casing 'PIX' compared to other payment functions which use camelCase. Should be 'handlePixPayment' for consistency.
  const handlePIXPayment = async () => {

Alert.alert(
'✅ Pagamento Aprovado',
`Transação PIX realizada com sucesso!\n\nValor: ${formatCurrency(2500)}\nCódigo: ${result.transactionCode}\nNSU: ${result.hostNsu}`
`Transação realizada com sucesso!\nCódigo: ${result.transactionCode}\nValor: R$ 25,00`
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Hardcoded amount display (R$ 25,00) doesn't match the actual payment amount (R$ 15,00) used in the PIX payment function. This will show incorrect amount information to users.

Suggested change
`Transação realizada com sucesso!\nCódigo: ${result.transactionCode}\nValor: R$ 25,00`
`Transação realizada com sucesso!\nCódigo: ${result.transactionCode}\nValor: R$ ${(result.amount / 100).toFixed(2).replace('.', ',')}`

Copilot uses AI. Check for mistakes.

@@ -194,68 +164,13 @@ export function useTransactionPaymentEvent(): PaymentEvent {
return {
...paymentEvent,
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

The return statement uses an object literal instead of the typed return that was removed. This creates inconsistency with the function's return type annotation which expects PaymentEvent & { resetEvent: () => void }.

Suggested change
...paymentEvent,
code: paymentEvent.code,
message: paymentEvent.message,

Copilot uses AI. Check for mistakes.

instance?.let { emitter ->
val params = Arguments.createMap().apply {
putDouble("code", code)
putString("message", message)
putString("customMessage", customMessage ?: "")
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Passing an empty string for null customMessage instead of null itself changes the API contract. JavaScript consumers expecting null/undefined will receive an empty string, which could break conditional logic checking for the presence of customMessage.

Suggested change
putString("customMessage", customMessage ?: "")
putString("customMessage", customMessage)

Copilot uses AI. Check for mistakes.

@mCodex mCodex deleted the feat/simplifiedVersion branch July 22, 2025 20:18
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.

1 participant