1- # 🚀 React Native PlugPag Nitro
1+ # react-native-plugpag-nitro
22
3- High-performance PagSeguro PlugPag integration for React Native with TypeScript support and real-time events.
3+ <div align =" center " >
4+ <h3 >🚀 High-performance PagSeguro PlugPag integration for React Native</h3 >
5+ <p >TypeScript-first payment processing with real-time events and JSI performance</p >
6+
7+ [ ![ npm version] ( https://img.shields.io/npm/v/react-native-plugpag-nitro )] ( https://www.npmjs.com/package/react-native-plugpag-nitro )
8+ [ ![ npm downloads] ( https://img.shields.io/npm/dm/react-native-plugpag-nitro )] ( https://www.npmjs.com/package/react-native-plugpag-nitro )
9+ [ ![ license] ( https://img.shields.io/npm/l/react-native-plugpag-nitro )] ( LICENSE )
10+ [ ![ Built with Nitro] ( https://img.shields.io/badge/Built%20with-Nitro%20Modules-purple )] ( https://nitro.margelo.com/ )
11+ </div >
412
5- [ ![ npm] ( https://img.shields.io/npm/v/react-native-plugpag-nitro )] ( https://www.npmjs.com/package/react-native-plugpag-nitro )
6- [ ![ license] ( https://img.shields.io/npm/l/react-native-plugpag-nitro )] ( LICENSE )
7- [ ![ Built with Nitro] ( https://img.shields.io/badge/Built%20with-Nitro%20Modules-purple )] ( https://nitro.margelo.com/ )
13+ ## ✨ Features
814
9- ** Features** : TypeScript-first • Real-time Events • High Performance JSI • Credit/Debit/PIX Support
15+ - 🚀 ** High Performance** - Built with Nitro Modules for JSI performance
16+ - 📘 ** TypeScript First** - Complete type safety and IntelliSense support
17+ - ⚡ ** Real-time Events** - Monitor payment status with React hooks
18+ - 💳 ** Multiple Payment Types** - Credit, Debit, Voucher, and PIX support
19+ - 🔄 ** Transaction Management** - Payment, refund, and cancellation support
20+ - 🖨️ ** Receipt Printing** - Integrated thermal receipt printing
21+ - 🛡️ ** Error Handling** - Comprehensive error codes and messages
1022
11- ## Installation
23+ ## 📦 Installation
1224
1325``` bash
1426npm install react-native-plugpag-nitro react-native-nitro-modules
1527```
1628
17- > Requires React Native ≥ 0.72, Android API ≥ 21
29+ ### Requirements
1830
19- ## Quick Start
31+ - React Native ≥ 0.72
32+ - Android API ≥ 21
33+ - PagSeguro PlugPag terminal
34+
35+ ## 🚀 Quick Start
2036
2137``` typescript
2238import {
@@ -58,116 +74,22 @@ function PaymentScreen() {
5874}
5975```
6076
61- ## API Reference
77+ ## 📚 API Reference
6278
6379### Core Functions
6480
65- #### ` doPayment(options) `
66- Process payments with type-safe enums.
67-
68- ``` typescript
69- const result = await doPayment ({
70- amount: 2500 , // Amount in cents
71- type: PaymentType .CREDIT , // CREDIT | DEBIT | VOUCHER | PIX
72- installmentType?: InstallmentType .BUYER_INSTALLMENT , // Optional
73- installments?: 3 , // Optional
74- printReceipt?: true // Optional
75- });
76- ```
77-
78- #### ` useTransactionEvent() `
79- Real-time payment event monitoring hook.
80-
81- ``` typescript
82- const paymentEvent = useTransactionEvent ();
83- // Returns: { code: number, message: string, customMessage?: string }
84- ```
85-
86- ### Enums
87-
88- ``` typescript
89- enum PaymentType {
90- CREDIT = 1 , // Credit card
91- DEBIT = 2 , // Debit card
92- VOUCHER = 3 , // Voucher/meal card
93- PIX = 5 // PIX instant payment
94- }
95-
96- enum ErrorCode {
97- OK = 0 , // Success
98- OPERATION_ABORTED = - 1 , // Operation aborted
99- COMMUNICATION_ERROR = - 3 , // Connection error
100- // ... more error codes
101- }
102- ```
103-
104- ### Other Functions
105-
106- - ` initializeAndActivatePinPad(code) ` - Initialize terminal
107- - ` refundPayment({ transactionCode, transactionId }) ` - Refund transaction
108- - ` getTerminalSerialNumber() ` - Get terminal serial
109- - ` doAbort() ` - Abort current transaction
110- - ` print(filePath) ` - Print receipt from file
111- ```
112-
113- ## Error Handling
114-
115- ```typescript
116- try {
117- const result = await doPayment({ amount: 2500, type: PaymentType.CREDIT });
118-
119- if (result.result !== ErrorCode.OK) {
120- // Handle specific errors
121- switch (result.result) {
122- case ErrorCode.OPERATION_ABORTED:
123- console.log('Payment cancelled by user');
124- break;
125- case ErrorCode.COMMUNICATION_ERROR:
126- console.log('Connection error - check terminal');
127- break;
128- default:
129- console.log('Payment failed:', result.message);
130- }
131- return;
132- }
133-
134- console.log('Payment successful!', result);
135- } catch (error) {
136- console.error('Payment error:', error.message);
137- }
138- ```
139-
140- ## Contributing
141-
142- ``` bash
143- git clone https://github.com/mCodex/react-native-plugpag-nitro.git
144- cd react-native-plugpag-nitro
145- yarn install
146- yarn example android
147- ```
148-
149- ## License
150-
151- MIT - see [ LICENSE] ( LICENSE ) for details.
152-
153- ## Links
154-
155- - [ 📚 Nitro Modules] ( https://nitro.margelo.com/ )
156- - [ 🏢 PagSeguro PlugPag] ( https://dev.pagseguro.uol.com.br/ )
157- - [ 🐛 Issues] ( https://github.com/mCodex/react-native-plugpag-nitro/issues )
158-
159- ### 💳 Core Functions
160-
16181#### ` initializeAndActivatePinPad(activationCode: string) `
82+
16283Initializes and activates the PlugPag terminal.
16384
16485``` typescript
165- const result = await initializeAndActivatePinPad (' 403938 ' );
86+ const result = await initializeAndActivatePinPad (' YOUR_ACTIVATION_CODE ' );
16687// Returns: { result: ErrorCode, errorCode?: string, errorMessage?: string }
16788```
16889
16990#### ` doPayment(options: PaymentOptions) `
170- Processes a payment transaction.
91+
92+ Process payments with type-safe enums.
17193
17294``` typescript
17395interface PaymentOptions {
@@ -180,16 +102,16 @@ interface PaymentOptions {
180102}
181103
182104const result = await doPayment ({
183- amount: 2500 ,
184- type: PaymentType .CREDIT ,
185- installmentType: InstallmentType .NO_INSTALLMENT ,
186- installments: 1 ,
187- printReceipt: true ,
188- userReference: ' payment-001'
105+ amount: 2500 , // Amount in cents
106+ type: PaymentType .CREDIT , // CREDIT | DEBIT | VOUCHER | PIX
107+ installmentType: InstallmentType .BUYER_INSTALLMENT , // Optional
108+ installments: 3 , // Optional
109+ printReceipt: true // Optional
189110});
190111```
191112
192113#### ` refundPayment(options) `
114+
193115Refunds a previous payment transaction.
194116
195117``` typescript
@@ -200,33 +122,15 @@ const result = await refundPayment({
200122});
201123```
202124
203- ### 🎣 React Hooks
204- #### ` useTransactionEvent() `
205- Real-time payment event monitoring hook to track status updates during transactions.
206-
207- ``` typescript
208- const paymentEvent = useTransactionEvent ();
125+ ### React Hooks
209126
210- useEffect (() => {
211- if (paymentEvent .code > 0 ) {
212- console .log (' Payment event:' , paymentEvent .eventName );
213- }
214- }, [paymentEvent ]);
215- ```
216-
217- ### 🎣 React Hooks
218127#### ` useTransactionEvent() `
219- Real-time payment event monitoring hook to track status updates during transactions.
128+
129+ Real-time payment event monitoring hook.
220130
221131``` typescript
222132const paymentEvent = useTransactionEvent ();
223-
224- // paymentEvent contains:
225- // {
226- // code: PaymentEventCode, // Event code
227- // message: string, // Event message
228- // customMessage?: string // Custom message if any
229- // }
133+ // Returns: { code: number, message: string, customMessage?: string }
230134
231135useEffect (() => {
232136 if (paymentEvent .code > 0 ) {
@@ -235,7 +139,7 @@ useEffect(() => {
235139}, [paymentEvent ]);
236140```
237141
238- ### 🔧 Utility Functions
142+ ### Utility Functions
239143
240144``` typescript
241145// Get terminal serial number
@@ -251,11 +155,33 @@ doAbort(): Promise<PlugpagAbortResult>
251155print (filePath : string ): Promise < void >
252156```
253157
254- ---
158+ ### Type Definitions
159+
160+ ``` typescript
161+ enum PaymentType {
162+ CREDIT = 1 , // Credit card
163+ DEBIT = 2 , // Debit card
164+ VOUCHER = 3 , // Voucher/meal card
165+ PIX = 5 // PIX instant payment
166+ }
167+
168+ enum ErrorCode {
169+ OK = 0 , // Success
170+ OPERATION_ABORTED = - 1 , // Operation aborted
171+ COMMUNICATION_ERROR = - 3 , // Connection error
172+ // ... more error codes
173+ }
174+
175+ enum InstallmentType {
176+ NO_INSTALLMENT = 1 , // No installment
177+ BUYER_INSTALLMENT = 2 , // Buyer pays installment fee
178+ SELLER_INSTALLMENT = 3 // Seller pays installment fee
179+ }
180+ ```
255181
256182## 💡 Usage Examples
257183
258- ### Real-time Event Monitoring with Payment
184+ ### Complete Payment Flow
259185
260186``` typescript
261187import React , { useState , useEffect } from ' react' ;
@@ -276,7 +202,7 @@ function PaymentScreen() {
276202 useEffect (() => {
277203 const initialize = async () => {
278204 try {
279- const result = await initializeAndActivatePinPad (' 403938 ' );
205+ const result = await initializeAndActivatePinPad (' YOUR_ACTIVATION_CODE ' );
280206 if (result .result === ErrorCode .OK ) {
281207 setIsInitialized (true );
282208 }
@@ -330,18 +256,12 @@ function PaymentScreen() {
330256 onPress = {handleCreditPayment }
331257 disabled = {!isInitialized || isProcessing }
332258 / >
333-
334- < Button
335- title = " Generate PIX QR R$ 50.00"
336- onPress = {handlePixPayment }
337- disabled = {!isInitialized }
338- / >
339259 < / View >
340260 );
341261}
342262```
343263
344- ### Error Handling
264+ ## ⚠️ Error Handling
345265
346266``` typescript
347267import { ErrorCode , doPayment , PaymentType } from ' react-native-plugpag-nitro' ;
@@ -350,51 +270,54 @@ try {
350270 const result = await doPayment ({ amount: 2500 , type: PaymentType .CREDIT });
351271
352272 if (result .result !== ErrorCode .OK ) {
273+ // Handle specific errors
353274 switch (result .result ) {
354275 case ErrorCode .OPERATION_ABORTED :
355- Alert . alert ( ' Cancelled ' , ' Payment was cancelled by user' );
276+ console . log ( ' Payment cancelled by user' );
356277 break ;
357278 case ErrorCode .COMMUNICATION_ERROR :
358- Alert . alert (' Connection Error ' , ' Check terminal connection ' );
279+ console . log (' Connection error - check terminal ' );
359280 break ;
360281 default :
361- Alert . alert (' Payment Failed ' , result .message || ' Unknown error ' );
282+ console . log (' Payment failed: ' , result .message );
362283 }
363284 return ;
364285 }
365286
366- Alert . alert ( ' Success ' , ' Payment approved! ' );
287+ console . log ( ' Payment successful! ' , result );
367288} catch (error ) {
368- console .error (' Payment error:' , error );
369- Alert .alert (' Error' , error .message || ' Payment failed' );
289+ console .error (' Payment error:' , error .message );
370290}
371291```
372292
373- ---
374-
375- ## 🤝 Contributing
293+ ## 🛠️ Development
376294
377295``` bash
296+ # Clone the repository
378297git clone https://github.com/mCodex/react-native-plugpag-nitro.git
379298cd react-native-plugpag-nitro
299+
300+ # Install dependencies
380301yarn install
381- yarn prepare
302+
303+ # Setup the example project
382304yarn example android
383305```
384306
385- ---
307+ ## 🤝 Contributing
386308
387- ## 📄 License
309+ We welcome contributions! Please see our [ Contributing Guide ] ( CONTRIBUTING.md ) for details.
388310
389- MIT License - see [ LICENSE ] ( LICENSE ) file for details.
311+ ## � License
390312
391- ---
313+ This project is licensed under the MIT License - see the [ LICENSE ] ( LICENSE ) file for details.
392314
393315## 🔗 Links
394316
395- - [ 📚 Nitro Modules] ( https://nitro.margelo.com/ )
396- - [ 🏢 PagSeguro PlugPag] ( https://dev.pagseguro.uol.com.br/ )
397- - [ 🐛 Issues] ( https://github.com/mCodex/react-native-plugpag-nitro/issues )
317+ - [ 📚 Nitro Modules Documentation] ( https://nitro.margelo.com/ )
318+ - [ 🏢 PagSeguro PlugPag Official Docs] ( https://dev.pagseguro.uol.com.br/ )
319+ - [ 🐛 Report Issues] ( https://github.com/mCodex/react-native-plugpag-nitro/issues )
320+ - [ � Discussions] ( https://github.com/mCodex/react-native-plugpag-nitro/discussions )
398321
399322---
400323
0 commit comments