Skip to content

Commit 93b5370

Browse files
committed
refactor: remove generatePixQRCode function and related usage from README and example
1 parent 6f64e45 commit 93b5370

File tree

3 files changed

+41
-60
lines changed

3 files changed

+41
-60
lines changed

README.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ npm install react-native-plugpag-nitro react-native-nitro-modules
2222
import {
2323
initializeAndActivatePinPad,
2424
doPayment,
25-
generatePixQRCode,
2625
useTransactionEvent,
2726
PaymentType,
2827
ErrorCode
@@ -76,13 +75,6 @@ const result = await doPayment({
7675
});
7776
```
7877

79-
#### `generatePixQRCode(amount, userReference?)`
80-
Generate PIX QR code string.
81-
82-
```typescript
83-
const qrString = await generatePixQRCode(2500); // R$ 25.00
84-
```
85-
8678
#### `useTransactionEvent()`
8779
Real-time payment event monitoring hook.
8880

@@ -197,14 +189,6 @@ const result = await doPayment({
197189
});
198190
```
199191

200-
#### `generatePixQRCode(amount: number, userReference?: string)`
201-
Generates a PIX QR code string for payment.
202-
203-
```typescript
204-
const qrString = await generatePixQRCode(2500); // R$ 25.00
205-
// Returns the PIX QR code string to display/use
206-
```
207-
208192
#### `refundPayment(options)`
209193
Refunds a previous payment transaction.
210194

@@ -280,8 +264,7 @@ import {
280264
ErrorCode,
281265
doPayment,
282266
useTransactionEvent,
283-
initializeAndActivatePinPad,
284-
generatePixQRCode
267+
initializeAndActivatePinPad
285268
} from 'react-native-plugpag-nitro';
286269

287270
function PaymentScreen() {
@@ -330,15 +313,6 @@ function PaymentScreen() {
330313
}
331314
};
332315

333-
const handlePixPayment = async () => {
334-
try {
335-
const qrString = await generatePixQRCode(5000); // R$ 50.00
336-
Alert.alert('PIX QR Code', qrString);
337-
} catch (error) {
338-
Alert.alert('PIX Error', error.message);
339-
}
340-
};
341-
342316
return (
343317
<View style={{ padding: 20 }}>
344318
<Text>Terminal: {isInitialized ? '✅ Ready' : '❌ Not Ready'}</Text>

example/src/App.tsx

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
initializeAndActivatePinPad,
1414
doPayment,
1515
refundPayment,
16-
generatePixQRCode,
1716
useTransactionEvent,
1817
getTerminalSerialNumber,
1918
PaymentType,
@@ -124,6 +123,38 @@ export default function App() {
124123
setIsProcessing(false);
125124
};
126125

126+
// Credit payment
127+
const handlePIXPayment = async () => {
128+
if (!isInitialized) {
129+
Alert.alert('⚠️ Aviso', 'Por favor, inicialize o terminal primeiro');
130+
return;
131+
}
132+
133+
setIsProcessing(true);
134+
try {
135+
const result = await doPayment({
136+
amount: 1500, // R$ 15.00
137+
type: PaymentType.PIX,
138+
});
139+
setLastPayment(result);
140+
141+
if (result.result === ErrorCode.OK) {
142+
Alert.alert(
143+
'✅ Pagamento Aprovado',
144+
`Transação realizada com sucesso!\nCódigo: ${result.transactionCode}\nValor: R$ 25,00`
145+
);
146+
} else {
147+
Alert.alert(
148+
'❌ Pagamento Negado',
149+
result.message || 'Transação falhou'
150+
);
151+
}
152+
} catch (e: any) {
153+
Alert.alert('❌ Erro', e.message);
154+
}
155+
setIsProcessing(false);
156+
};
157+
127158
// Installment payment
128159
const handleInstallmentPayment = async () => {
129160
if (!isInitialized) {
@@ -158,16 +189,6 @@ export default function App() {
158189
setIsProcessing(false);
159190
};
160191

161-
// Generate PIX QR code
162-
const handleGeneratePix = async () => {
163-
try {
164-
const qrString = await generatePixQRCode(5000); // R$ 50.00
165-
Alert.alert('Código QR PIX', qrString);
166-
} catch (e: any) {
167-
Alert.alert('❌ Erro PIX', e.message);
168-
}
169-
};
170-
171192
// Refund last payment
172193
const handleRefund = async () => {
173194
if (!lastPayment?.transactionCode || !lastPayment.transactionId) {
@@ -263,6 +284,14 @@ export default function App() {
263284
<Text style={styles.buttonText}>Pagamento Débito - R$ 15,00</Text>
264285
</TouchableOpacity>
265286

287+
<TouchableOpacity
288+
style={styles.button}
289+
onPress={handlePIXPayment}
290+
disabled={isProcessing || !isInitialized}
291+
>
292+
<Text style={styles.buttonText}>PIX - R$ 15,00</Text>
293+
</TouchableOpacity>
294+
266295
<TouchableOpacity
267296
style={styles.button}
268297
onPress={handleInstallmentPayment}
@@ -273,10 +302,6 @@ export default function App() {
273302
</Text>
274303
</TouchableOpacity>
275304

276-
<TouchableOpacity style={styles.button} onPress={handleGeneratePix}>
277-
<Text style={styles.buttonText}>Gerar QR PIX - R$ 50,00</Text>
278-
</TouchableOpacity>
279-
280305
<TouchableOpacity
281306
style={[styles.button, styles.refundButton]}
282307
onPress={handleRefund}

src/index.tsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,6 @@ export async function reprintCustomerReceipt(): Promise<void> {
212212
);
213213
}
214214

215-
/**
216-
* Generate a PIX QR code string for custom UI
217-
* @param amount Payment amount in cents
218-
* @param userReference Optional reference for transaction
219-
* @returns QR code string from transaction result message
220-
*/
221-
export async function generatePixQRCode(
222-
amount: number,
223-
userReference?: string
224-
): Promise<string> {
225-
const result = await doPayment({
226-
amount,
227-
type: PaymentType.PIX,
228-
userReference,
229-
});
230-
return result.message ?? '';
231-
}
232-
233215
/**
234216
* Simple transaction status checker
235217
* Helper function to check if a transaction result indicates success

0 commit comments

Comments
 (0)