
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
react-native-plugpag-nitro
Advanced tools
High-performance React Native library for PagSeguro PlugPag payment terminals with TypeScript-first hooks API, real-time events, and 10x faster performance using Nitro Modules
High-performance PagSeguro PlugPag integration with TypeScript-first enum-based API
Built with Nitro Modules for ~10x faster performance than traditional bridges
npm install react-native-plugpag-nitro react-native-nitro-modules
Requirements: React Native ≥ 0.72, Android API ≥ 21
import {
PaymentType,
InstallmentType,
ErrorCode,
doPayment,
initializeAndActivatePinPad,
PaymentPresets,
isTransactionSuccessful
} from 'react-native-plugpag-nitro';
// Initialize terminal once
await initializeAndActivatePinPad('your-activation-code');
// Simple credit payment using presets
const result = await doPayment(PaymentPresets.creditCard(2500, 1));
// Or use enum types directly for custom payments
const customPayment = await doPayment({
amount: 5000, // R$ 50.00
type: PaymentType.CREDIT,
installmentType: InstallmentType.BUYER_INSTALLMENT,
installments: 3,
printReceipt: true,
userReference: 'order-123'
});
if (isTransactionSuccessful(result)) {
console.log('Payment approved!', result);
}
import {
PaymentType,
usePaymentFlow,
useTransactionPaymentEvent,
PaymentPresets
} from 'react-native-plugpag-nitro';
function PaymentComponent() {
const paymentFlow = usePaymentFlow();
const paymentEvent = useTransactionPaymentEvent();
const handlePayment = async () => {
try {
const result = await paymentFlow.executePayment(
PaymentPresets.creditCard(2500, 1)
);
if (paymentFlow.isTransactionSuccessful) {
console.log('Payment successful!', result);
}
} catch (error) {
console.error('Payment failed:', error);
}
};
return (
<View>
<Button
title="Pay R$ 25.00"
onPress={handlePayment}
disabled={paymentFlow.isProcessing}
/>
{paymentEvent.code > 0 && (
<Text>Status: {paymentEvent.eventName}</Text>
)}
{paymentFlow.isProcessing && <ActivityIndicator />}
</View>
);
}
enum PaymentType {
CREDIT = 1, // Credit card
DEBIT = 2, // Debit card
VOUCHER = 3, // Voucher/meal card
PIX = 5 // PIX instant payment
}
enum InstallmentType {
NO_INSTALLMENT = 1, // À vista (no installments)
SELLER_INSTALLMENT = 2, // Parcelado pelo vendedor
BUYER_INSTALLMENT = 3 // Parcelado pelo comprador
}
enum ErrorCode {
OK = 0, // Success
OPERATION_ABORTED = -1, // Operation aborted
AUTHENTICATION_FAILED = -2, // Authentication failed
COMMUNICATION_ERROR = -3, // Communication error
NO_PRINTER_DEVICE = -4, // No printer device
NO_TRANSACTION_DATA = -5 // No transaction data
}
enum PaymentEventCode {
CARD_INSERTED = 1, // Card inserted
CARD_REMOVED = 2, // Card removed
WAITING_CARD = 3, // Waiting for card
CARD_READ = 4, // Card read successfully
PAYMENT_PROCESSING = 5, // Payment processing
PAYMENT_COMPLETED = 6, // Payment completed
PAYMENT_CANCELLED = 7, // Payment cancelled
// ... and more event codes
}
initializeAndActivatePinPad(activationCode: string)
Initializes and activates the PlugPag terminal.
const result = await initializeAndActivatePinPad('403938');
// Returns: { result: ErrorCode, errorCode?: string, errorMessage?: string }
doPayment(options: PaymentOptions)
Processes a payment transaction.
interface PaymentOptions {
amount: number; // Amount in cents
type: PaymentType; // Payment type enum
installmentType?: InstallmentType; // Installment type enum
installments?: number; // Number of installments (default: 1)
printReceipt?: boolean; // Print receipt (default: true)
userReference?: string; // User reference (default: auto-generated)
}
const result = await doPayment({
amount: 2500,
type: PaymentType.CREDIT,
installmentType: InstallmentType.NO_INSTALLMENT,
installments: 1,
printReceipt: true,
userReference: 'payment-001'
});
doPaymentWithEvents(options: PaymentOptions)
Processes a payment with real-time event monitoring.
const result = await doPaymentWithEvents({
amount: 2500,
type: PaymentType.CREDIT,
installmentType: InstallmentType.NO_INSTALLMENT
});
// Events are automatically tracked via useTransactionPaymentEvent hook
refundPayment(options)
Refunds a previous payment transaction.
const result = await refundPayment({
transactionCode: 'abc123',
transactionId: 'def456',
printReceipt: true
});
usePaymentFlow()
Comprehensive payment hook with built-in state management and event tracking.
const {
isProcessing, // boolean - payment in progress
currentTransaction, // PlugpagTransactionResult | null
paymentEvent, // Current payment event
executePayment, // Function to execute payment
resetFlow, // Reset flow state
isTransactionSuccessful, // boolean - transaction success status
transactionError // string | null - error message
} = usePaymentFlow();
// Usage
const handlePayment = async () => {
try {
const result = await executePayment({
amount: 2500,
type: PaymentType.CREDIT
});
if (isTransactionSuccessful) {
console.log('Payment successful!');
}
} catch (error) {
console.error('Payment failed:', transactionError);
}
};
useTransactionPaymentEvent()
Real-time payment event monitoring hook.
const paymentEvent = useTransactionPaymentEvent();
// paymentEvent contains:
// {
// code: number, // PaymentEventCode
// eventName?: string, // Human-readable event name
// userReference?: string, // User reference
// amount?: string, // Amount
// resetEvent?: () => void // Function to reset event
// }
// Usage in component
useEffect(() => {
if (paymentEvent.code > 0) {
console.log('Payment event:', paymentEvent.eventName);
}
}, [paymentEvent]);
Quick payment setup with predefined configurations:
// Credit card payments
PaymentPresets.creditCard(amount, installments?)
PaymentPresets.creditCard(10000, 3) // R$ 100.00 in 3x
// Debit card
PaymentPresets.debitCard(2500) // R$ 25.00
// PIX payments
PaymentPresets.pix(5000) // R$ 50.00
// Voucher
PaymentPresets.voucher(1500) // R$ 15.00
// Check if transaction was successful
isTransactionSuccessful(result: PlugpagTransactionResult): boolean
// Get error message from result
getTransactionError(result: PlugpagTransactionResult): string | null
// Get terminal serial number
getTerminalSerialNumber(): string
// Get available constants
getConstants(): PlugpagConstants
// Abort current transaction
doAbort(): Promise<PlugpagAbortResult>
// Print custom receipt from file
print(filePath: string): Promise<void>
// Reprint last customer receipt
reprintCustomerReceipt(): Promise<void>
import React, { useState, useEffect } from 'react';
import {
PaymentType,
InstallmentType,
PaymentEventCode,
usePaymentFlow,
useTransactionPaymentEvent,
PaymentPresets,
initializeAndActivatePinPad
} from 'react-native-plugpag-nitro';
function ModernPaymentScreen() {
const [isInitialized, setIsInitialized] = useState(false);
const paymentFlow = usePaymentFlow();
const paymentEvent = useTransactionPaymentEvent();
// Initialize terminal on mount
useEffect(() => {
const initialize = async () => {
try {
const result = await initializeAndActivatePinPad('403938');
if (result.result === 0) {
setIsInitialized(true);
}
} catch (error) {
console.error('Initialization failed:', error);
}
};
initialize();
}, []);
// Monitor payment events
useEffect(() => {
if (paymentEvent.code > 0) {
console.log('Payment event:', paymentEvent.eventName);
// Handle specific events
switch (paymentEvent.code) {
case PaymentEventCode.CARD_INSERTED:
console.log('Card inserted, please wait...');
break;
case PaymentEventCode.PAYMENT_PROCESSING:
console.log('Processing payment...');
break;
case PaymentEventCode.PAYMENT_COMPLETED:
console.log('Payment completed!');
break;
}
}
}, [paymentEvent]);
const handleCreditPayment = async () => {
if (!isInitialized) {
Alert.alert('Error', 'Terminal not initialized');
return;
}
try {
const result = await paymentFlow.executePayment({
amount: 2500, // R$ 25.00
type: PaymentType.CREDIT,
installmentType: InstallmentType.NO_INSTALLMENT,
userReference: `payment-${Date.now()}`
});
if (paymentFlow.isTransactionSuccessful) {
Alert.alert('Success', 'Payment approved!', [
{ text: 'OK', onPress: () => paymentFlow.resetFlow() }
]);
} else {
Alert.alert('Failed', paymentFlow.transactionError || 'Payment failed');
}
} catch (error) {
Alert.alert('Error', error.message);
}
};
const handlePixPayment = async () => {
try {
const result = await paymentFlow.executePayment(
PaymentPresets.pix(5000) // R$ 50.00
);
if (paymentFlow.isTransactionSuccessful) {
Alert.alert('PIX Success', 'PIX payment completed!');
}
} catch (error) {
Alert.alert('PIX Error', error.message);
}
};
return (
<View style={{ padding: 20 }}>
<Text style={{ fontSize: 18, marginBottom: 20 }}>
Terminal: {isInitialized ? '✅ Ready' : '❌ Not Ready'}
</Text>
{/* Payment Event Display */}
{paymentEvent.code > 0 && (
<View style={{ padding: 10, backgroundColor: '#e3f2fd', marginBottom: 10 }}>
<Text>Status: {paymentEvent.eventName}</Text>
</View>
)}
{/* Processing Indicator */}
{paymentFlow.isProcessing && (
<View style={{ padding: 10, backgroundColor: '#fff3e0', marginBottom: 10 }}>
<ActivityIndicator size="small" />
<Text>Processing payment...</Text>
</View>
)}
<Button
title="Credit Card R$ 25.00"
onPress={handleCreditPayment}
disabled={!isInitialized || paymentFlow.isProcessing}
/>
<Button
title="PIX R$ 50.00"
onPress={handlePixPayment}
disabled={!isInitialized || paymentFlow.isProcessing}
/>
{/* Transaction Result Display */}
{paymentFlow.currentTransaction && (
<View style={{ marginTop: 20, padding: 10, backgroundColor: '#f5f5f5' }}>
<Text style={{ fontWeight: 'bold' }}>Last Transaction:</Text>
<Text>Code: {paymentFlow.currentTransaction.transactionCode}</Text>
<Text>Amount: R$ {(parseInt(paymentFlow.currentTransaction.amount) / 100).toFixed(2)}</Text>
<Text>Status: {paymentFlow.isTransactionSuccessful ? '✅ Approved' : '❌ Declined'}</Text>
<Text>Date: {paymentFlow.currentTransaction.date} {paymentFlow.currentTransaction.time}</Text>
</View>
)}
</View>
);
}
import React, { useState } from 'react';
import {
PaymentType,
InstallmentType,
ErrorCode,
doPayment,
doPaymentWithEvents,
initializeAndActivatePinPad,
isTransactionSuccessful,
getTransactionError,
PaymentPresets
} from 'react-native-plugpag-nitro';
function BasicPaymentScreen() {
const [isProcessing, setIsProcessing] = useState(false);
const [lastPayment, setLastPayment] = useState(null);
const handleInitialize = async () => {
try {
const result = await initializeAndActivatePinPad('403938');
if (result.result === ErrorCode.OK) {
Alert.alert('Success', 'Terminal activated successfully!');
} else {
Alert.alert('Error', result.errorMessage || 'Failed to activate terminal');
}
} catch (error) {
Alert.alert('Error', error.message);
}
};
const handleCreditPayment = async () => {
try {
setIsProcessing(true);
// Using preset for simplicity
const result = await doPayment(PaymentPresets.creditCard(2500, 1));
setLastPayment(result);
if (isTransactionSuccessful(result)) {
Alert.alert('Success', 'Payment approved!');
} else {
const errorMessage = getTransactionError(result);
Alert.alert('Payment Failed', errorMessage || 'Unknown error');
}
} catch (error) {
Alert.alert('Error', error.message);
} finally {
setIsProcessing(false);
}
};
const handlePaymentWithEvents = async () => {
try {
setIsProcessing(true);
// Payment with automatic event tracking
const result = await doPaymentWithEvents({
amount: 5000, // R$ 50.00
type: PaymentType.CREDIT,
installmentType: InstallmentType.BUYER_INSTALLMENT,
installments: 3
});
if (isTransactionSuccessful(result)) {
Alert.alert('Success', 'Payment with events completed!');
}
} catch (error) {
Alert.alert('Error', error.message);
} finally {
setIsProcessing(false);
}
};
return (
<View style={{ padding: 20 }}>
<Button title="Initialize Terminal" onPress={handleInitialize} />
<Button
title={isProcessing ? 'Processing...' : 'Credit Payment R$ 25.00'}
onPress={handleCreditPayment}
disabled={isProcessing}
/>
<Button
title="Payment with Events R$ 50.00 (3x)"
onPress={handlePaymentWithEvents}
disabled={isProcessing}
/>
{lastPayment && (
<View style={{ marginTop: 20, padding: 10, backgroundColor: '#f0f0f0' }}>
<Text>Last Transaction:</Text>
<Text>Code: {lastPayment.transactionCode}</Text>
<Text>Amount: {lastPayment.amount}</Text>
<Text>Status: {isTransactionSuccessful(lastPayment) ? 'Approved' : 'Declined'}</Text>
</View>
)}
</View>
);
}
import { useTransactionPaymentEvent, PaymentEventCode } from 'react-native-plugpag-nitro';
function PaymentEventMonitor() {
const paymentEvent = useTransactionPaymentEvent();
const getEventColor = (code: number) => {
if (code >= PaymentEventCode.CARD_INSERTED && code <= PaymentEventCode.WAITING_CARD) {
return '#007AFF'; // Blue for card events
} else if (code === PaymentEventCode.PAYMENT_PROCESSING) {
return '#FF9500'; // Orange for processing
} else if (code === PaymentEventCode.PAYMENT_COMPLETED) {
return '#34C759'; // Green for success
}
return '#8E8E93'; // Gray for others
};
return (
<View>
{paymentEvent.code > 0 && (
<View style={{
padding: 10,
backgroundColor: getEventColor(paymentEvent.code),
borderRadius: 8,
marginVertical: 5
}}>
<Text style={{ color: 'white', fontWeight: 'bold' }}>
{paymentEvent.eventName || `Event Code: ${paymentEvent.code}`}
</Text>
{paymentEvent.amount && (
<Text style={{ color: 'white' }}>Amount: {paymentEvent.amount}</Text>
)}
</View>
)}
</View>
);
}
const handlePixPayment = async () => {
try {
const result = await doPayment({
amount: 2500,
type: PaymentType.PIX,
installmentType: InstallmentType.NO_INSTALLMENT,
printReceipt: true,
userReference: 'pix-payment-001'
});
if (isTransactionSuccessful(result)) {
Alert.alert('PIX Success', 'PIX payment completed!');
}
} catch (error) {
Alert.alert('PIX Error', error.message);
}
};
import {
isTransactionSuccessful,
getTransactionError,
ErrorCode
} from 'react-native-plugpag-nitro';
try {
const result = await doPayment(PaymentPresets.creditCard(2500));
if (!isTransactionSuccessful(result)) {
const errorMessage = getTransactionError(result);
switch (result.result) {
case ErrorCode.OPERATION_ABORTED:
Alert.alert('Cancelled', 'Payment was cancelled by user');
break;
case ErrorCode.COMMUNICATION_ERROR:
Alert.alert('Connection Error', 'Check terminal connection');
break;
default:
Alert.alert('Payment Failed', errorMessage || 'Unknown error');
}
return;
}
Alert.alert('Success', 'Payment approved!');
} catch (error) {
console.error('Payment error:', error);
Alert.alert('Error', error.message || 'Payment failed');
}
git clone https://github.com/mCodex/react-native-plugpag-nitro.git
cd react-native-plugpag-nitro
yarn install
yarn prepare
yarn example android
MIT License - see LICENSE file for details.
Built with ❤️ using Nitro Modules
Making React Native payment processing faster and more type-safe
FAQs
High-performance React Native library for PagSeguro PlugPag payment terminals with TypeScript-first hooks API, real-time events, and 10x faster performance using Nitro Modules
The npm package react-native-plugpag-nitro receives a total of 6 weekly downloads. As such, react-native-plugpag-nitro popularity was classified as not popular.
We found that react-native-plugpag-nitro demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.