@fadyshawky/react-native-magic 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/App.tsx +28 -19
- package/template/ios/reactnativemagic/AppDelegate.mm +5 -0
- package/template/src/common/ImageResources.g.ts +1 -33
- package/template/src/common/components/Background.tsx +7 -7
- package/template/src/common/components/Container.tsx +7 -10
- package/template/src/common/localization/LocalizationProvider.tsx +14 -17
- package/template/src/common/localization/RTLInitializer.tsx +90 -0
- package/template/src/common/localization/intlFormatter.ts +37 -0
- package/template/src/common/localization/localization.ts +1 -3
- package/template/src/common/localization/translations/commonLocalization.ts +11 -81
- package/template/src/common/localization/translations/emptyLocalization.ts +6 -2
- package/template/src/common/localization/translations/errorsLocalization.ts +33 -13
- package/template/src/common/localization/translations/homeLocalization.ts +4 -24
- package/template/src/common/localization/translations/loginLocalization.ts +26 -29
- package/template/src/common/localization/translations/mainNavigationLocalization.ts +2 -2
- package/template/src/common/localization/translations/onboardingLocalization.ts +40 -9
- package/template/src/common/localization/translations/otpLocalization.ts +8 -8
- package/template/src/common/localization/translations/pagesLocalization.ts +13 -1
- package/template/src/common/localization/translations/passwordLocalization.ts +3 -3
- package/template/src/common/localization/translations/profileLocalization.ts +4 -4
- package/template/src/core/store/app/appState.ts +2 -2
- package/template/src/core/theme/colors.ts +106 -70
- package/template/src/core/theme/commonConsts.ts +1 -1
- package/template/src/core/theme/commonSizes.ts +119 -94
- package/template/src/core/theme/commonStyles.ts +22 -22
- package/template/src/core/theme/fonts.ts +13 -14
- package/template/src/core/theme/shadows.ts +135 -0
- package/template/src/core/theme/themes.ts +386 -75
- package/template/src/core/theme/types.ts +201 -15
- package/template/src/navigation/HeaderComponents.tsx +6 -30
- package/template/src/navigation/MainStack.tsx +6 -97
- package/template/src/screens/Login/Login.tsx +5 -7
- package/template/src/screens/OTP/OTPScreen.tsx +12 -13
- package/template/src/screens/home/HomeScreen.tsx +2 -295
- package/template/src/screens/profile/Profile.tsx +2 -290
- package/template/src/common/localization/translations/posLocalization.ts +0 -196
- package/template/src/components/PrinterExample.js +0 -226
- package/template/src/modules/SunmiCard.js +0 -212
- package/template/src/modules/SunmiPrepaid.ts +0 -122
- package/template/src/screens/Categories/Categories.tsx +0 -141
- package/template/src/screens/Categories/hooks/useCategoriesData.ts +0 -33
- package/template/src/screens/Categories/types.ts +0 -7
- package/template/src/screens/Favorites/Favorites.tsx +0 -130
- package/template/src/screens/ForceChangePassword/ForceChangePasswordScreen.tsx +0 -155
- package/template/src/screens/History/History.tsx +0 -430
- package/template/src/screens/History/hooks/useHistoryData.ts +0 -49
- package/template/src/screens/History/types.ts +0 -7
- package/template/src/screens/InquiredBill/InquiredBill.tsx +0 -443
- package/template/src/screens/InquiredBill/hooks/useInquiredData.ts +0 -91
- package/template/src/screens/PaymentConfirmation/PaymentConfirmation.tsx +0 -326
- package/template/src/screens/Providers/Providers.tsx +0 -166
- package/template/src/screens/Providers/hooks/useProvidersData.ts +0 -33
- package/template/src/screens/Providers/types.ts +0 -7
- package/template/src/screens/ReceiptScreen/ReceiptScreen.tsx +0 -181
- package/template/src/screens/ReceiptScreen/hooks/useReceiptData.ts +0 -46
- package/template/src/screens/ReceiptScreen/utils/utils.tsx +0 -156
- package/template/src/screens/Services/Services.tsx +0 -144
- package/template/src/screens/Services/hooks/useServicesData.ts +0 -41
- package/template/src/screens/SingleService/Components/FawryInputs.tsx +0 -446
- package/template/src/screens/SingleService/SingleService.tsx +0 -229
- package/template/src/screens/SingleService/hooks/useServiceData.ts +0 -164
- package/template/src/services/SunmiPrinterInternal.js +0 -268
- package/template/src/types/sunmiPrepaid.d.ts +0 -20
- package/template/src/utils/SunmiPrinter.ts +0 -442
- package/template/src/utils/feesCalculator.ts +0 -92
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
export const posLocalization = {
|
|
2
|
-
en: {
|
|
3
|
-
// Common Labels
|
|
4
|
-
serialNumber: 'Serial Number',
|
|
5
|
-
serviceName: 'Service Name',
|
|
6
|
-
providerName: 'Provider Name',
|
|
7
|
-
customerNumber: 'Customer Number',
|
|
8
|
-
value: 'Value',
|
|
9
|
-
serviceCost: 'Service Cost',
|
|
10
|
-
operationNumber: 'Operation Number',
|
|
11
|
-
referenceNumber: 'Reference Number',
|
|
12
|
-
time: 'Time',
|
|
13
|
-
total: 'Total',
|
|
14
|
-
|
|
15
|
-
// Input Methods
|
|
16
|
-
scanner: 'Scanner',
|
|
17
|
-
keypad: 'Keypad',
|
|
18
|
-
keyboard: 'Keyboard',
|
|
19
|
-
touchPanel: 'Touch Panel',
|
|
20
|
-
button: 'Button',
|
|
21
|
-
|
|
22
|
-
// Actions
|
|
23
|
-
print: 'Print',
|
|
24
|
-
save: 'Save',
|
|
25
|
-
cancel: 'Cancel',
|
|
26
|
-
delete: 'Delete',
|
|
27
|
-
submit: 'Submit',
|
|
28
|
-
|
|
29
|
-
// Messages
|
|
30
|
-
success: 'Success',
|
|
31
|
-
error: 'Error',
|
|
32
|
-
required: 'This field is required',
|
|
33
|
-
invalidInput: 'Invalid input',
|
|
34
|
-
|
|
35
|
-
// Validation
|
|
36
|
-
enterValidAmount: 'Please enter a valid amount',
|
|
37
|
-
enterValidNumber: 'Please enter a valid number',
|
|
38
|
-
enterValidDate: 'Please enter a valid date',
|
|
39
|
-
|
|
40
|
-
// Printer
|
|
41
|
-
printerError: 'Printer Error',
|
|
42
|
-
printingError: 'Printing Error',
|
|
43
|
-
paperFeedError: 'Paper Feed Error',
|
|
44
|
-
qrCodeError: 'QR Code Error',
|
|
45
|
-
barcodeError: 'Barcode Error',
|
|
46
|
-
tableError: 'Table Error',
|
|
47
|
-
bufferError: 'Buffer Error',
|
|
48
|
-
|
|
49
|
-
// Bill
|
|
50
|
-
billAmount: 'Bill Amount',
|
|
51
|
-
billDetails: 'Bill Details',
|
|
52
|
-
billNumber: 'Bill Number',
|
|
53
|
-
billDate: 'Bill Date',
|
|
54
|
-
billStatus: 'Bill Status',
|
|
55
|
-
|
|
56
|
-
// Service
|
|
57
|
-
serviceDetails: 'Service Details',
|
|
58
|
-
serviceType: 'Service Type',
|
|
59
|
-
serviceStatus: 'Service Status',
|
|
60
|
-
serviceDate: 'Service Date',
|
|
61
|
-
|
|
62
|
-
// Customer
|
|
63
|
-
customerDetails: 'Customer Details',
|
|
64
|
-
customerName: 'Customer Name',
|
|
65
|
-
customerPhone: 'Customer Phone',
|
|
66
|
-
customerEmail: 'Customer Email',
|
|
67
|
-
|
|
68
|
-
// Payment
|
|
69
|
-
paymentMethod: 'Payment Method',
|
|
70
|
-
paymentStatus: 'Payment Status',
|
|
71
|
-
paymentDate: 'Payment Date',
|
|
72
|
-
paymentAmount: 'Payment Amount',
|
|
73
|
-
|
|
74
|
-
// Receipt
|
|
75
|
-
receiptNumber: 'Receipt Number',
|
|
76
|
-
receiptDate: 'Receipt Date',
|
|
77
|
-
receiptTime: 'Receipt Time',
|
|
78
|
-
receiptTotal: 'Receipt Total',
|
|
79
|
-
receiptStatus: 'Receipt Status',
|
|
80
|
-
expiryDate: 'Expiry Date',
|
|
81
|
-
|
|
82
|
-
// Printer Status
|
|
83
|
-
printerStatus_1: 'The printer works normally',
|
|
84
|
-
printerStatus_2: 'Preparing printer',
|
|
85
|
-
printerStatus_3: 'Abnormal communication',
|
|
86
|
-
printerStatus_4: 'The printer is out of paper',
|
|
87
|
-
printerStatus_5: 'Printer overheated',
|
|
88
|
-
printerStatus_6: 'Printer cover is open',
|
|
89
|
-
printerStatus_7: 'Unknown printer error',
|
|
90
|
-
|
|
91
|
-
title: 'Transaction Details',
|
|
92
|
-
trans_id: 'Transaction ID',
|
|
93
|
-
service: 'Service',
|
|
94
|
-
service_type: 'Service Type',
|
|
95
|
-
amount: 'Amount',
|
|
96
|
-
fees: 'Fees',
|
|
97
|
-
info_text: 'Details',
|
|
98
|
-
},
|
|
99
|
-
ar: {
|
|
100
|
-
// Common Labels
|
|
101
|
-
serialNumber: 'الرقم التسلسلي',
|
|
102
|
-
serviceName: 'اسم الخدمة',
|
|
103
|
-
providerName: 'اسم المقدم',
|
|
104
|
-
customerNumber: 'رقم العميل',
|
|
105
|
-
value: 'القيمة',
|
|
106
|
-
serviceCost: 'تكلفة الخدمة',
|
|
107
|
-
operationNumber: 'رقم العملية',
|
|
108
|
-
referenceNumber: 'الرقم المرجعي',
|
|
109
|
-
time: 'الوقت',
|
|
110
|
-
total: 'الإجمالي',
|
|
111
|
-
|
|
112
|
-
// Input Methods
|
|
113
|
-
scanner: 'الماسح الضوئي',
|
|
114
|
-
keypad: 'لوحة المفاتيح الرقمية',
|
|
115
|
-
keyboard: 'لوحة المفاتيح',
|
|
116
|
-
touchPanel: 'شاشة اللمس',
|
|
117
|
-
button: 'زر',
|
|
118
|
-
|
|
119
|
-
// Actions
|
|
120
|
-
print: 'طباعة',
|
|
121
|
-
save: 'حفظ',
|
|
122
|
-
cancel: 'إلغاء',
|
|
123
|
-
delete: 'حذف',
|
|
124
|
-
submit: 'إرسال',
|
|
125
|
-
|
|
126
|
-
// Messages
|
|
127
|
-
success: 'نجاح',
|
|
128
|
-
error: 'خطأ',
|
|
129
|
-
required: 'هذا الحقل مطلوب',
|
|
130
|
-
invalidInput: 'إدخال غير صالح',
|
|
131
|
-
|
|
132
|
-
// Validation
|
|
133
|
-
enterValidAmount: 'الرجاء إدخال مبلغ صحيح',
|
|
134
|
-
enterValidNumber: 'الرجاء إدخال رقم صحيح',
|
|
135
|
-
enterValidDate: 'الرجاء إدخال تاريخ صحيح',
|
|
136
|
-
|
|
137
|
-
// Printer
|
|
138
|
-
printerError: 'خطأ في الطابعة',
|
|
139
|
-
printingError: 'خطأ في الطباعة',
|
|
140
|
-
paperFeedError: 'خطأ في تغذية الورق',
|
|
141
|
-
qrCodeError: 'خطأ في رمز QR',
|
|
142
|
-
barcodeError: 'خطأ في الباركود',
|
|
143
|
-
tableError: 'خطأ في الجدول',
|
|
144
|
-
bufferError: 'خطأ في المخزن المؤقت',
|
|
145
|
-
|
|
146
|
-
// Bill
|
|
147
|
-
billAmount: 'مبلغ الفاتورة',
|
|
148
|
-
billDetails: 'تفاصيل الفاتورة',
|
|
149
|
-
billNumber: 'رقم الفاتورة',
|
|
150
|
-
billDate: 'تاريخ الفاتورة',
|
|
151
|
-
billStatus: 'حالة الفاتورة',
|
|
152
|
-
|
|
153
|
-
// Service
|
|
154
|
-
serviceDetails: 'تفاصيل الخدمة',
|
|
155
|
-
serviceType: 'نوع الخدمة',
|
|
156
|
-
serviceStatus: 'حالة الخدمة',
|
|
157
|
-
serviceDate: 'تاريخ الخدمة',
|
|
158
|
-
|
|
159
|
-
// Customer
|
|
160
|
-
customerDetails: 'تفاصيل العميل',
|
|
161
|
-
customerName: 'اسم العميل',
|
|
162
|
-
customerPhone: 'هاتف العميل',
|
|
163
|
-
customerEmail: 'بريد العميل',
|
|
164
|
-
|
|
165
|
-
// Payment
|
|
166
|
-
paymentMethod: 'طريقة الدفع',
|
|
167
|
-
paymentStatus: 'حالة الدفع',
|
|
168
|
-
paymentDate: 'تاريخ الدفع',
|
|
169
|
-
paymentAmount: 'مبلغ الدفع',
|
|
170
|
-
|
|
171
|
-
// Receipt
|
|
172
|
-
receiptNumber: 'رقم الإيصال',
|
|
173
|
-
receiptDate: 'تاريخ الإيصال',
|
|
174
|
-
receiptTime: 'وقت الإيصال',
|
|
175
|
-
receiptTotal: 'إجمالي الإيصال',
|
|
176
|
-
receiptStatus: 'حالة الإيصال',
|
|
177
|
-
expiryDate: 'تاريخ الانتهاء',
|
|
178
|
-
|
|
179
|
-
// Printer Status
|
|
180
|
-
printerStatus_1: 'الطابعة تعمل بشكل طبيعي',
|
|
181
|
-
printerStatus_2: 'جاري تجهيز الطابعة',
|
|
182
|
-
printerStatus_3: 'خطأ في الاتصال بالطابعة',
|
|
183
|
-
printerStatus_4: 'نفذ الورق من الطابعة',
|
|
184
|
-
printerStatus_5: 'الطابعة ساخنة جداً',
|
|
185
|
-
printerStatus_6: 'غطاء الطابعة مفتوح',
|
|
186
|
-
printerStatus_7: 'خطأ غير معروف في الطابعة',
|
|
187
|
-
|
|
188
|
-
title: 'تفاصيل المعاملة',
|
|
189
|
-
trans_id: 'معرف المعاملة',
|
|
190
|
-
service: 'الخدمة',
|
|
191
|
-
service_type: 'نوع الخدمة',
|
|
192
|
-
amount: 'المبلغ',
|
|
193
|
-
fees: 'مصاريف',
|
|
194
|
-
info_text: 'التفاصيل',
|
|
195
|
-
},
|
|
196
|
-
};
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import React, {useState, useEffect} from 'react';
|
|
2
|
-
import {
|
|
3
|
-
View,
|
|
4
|
-
Text,
|
|
5
|
-
StyleSheet,
|
|
6
|
-
TouchableOpacity,
|
|
7
|
-
ScrollView,
|
|
8
|
-
Alert,
|
|
9
|
-
} from 'react-native';
|
|
10
|
-
import SunmiPrinter from '../utils/SunmiPrinter';
|
|
11
|
-
|
|
12
|
-
const PrinterExample = () => {
|
|
13
|
-
const [isPrinterAvailable, setIsPrinterAvailable] = useState(false);
|
|
14
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
checkPrinterAvailability();
|
|
18
|
-
}, []);
|
|
19
|
-
|
|
20
|
-
const checkPrinterAvailability = async () => {
|
|
21
|
-
try {
|
|
22
|
-
const available = await SunmiPrinter.isPrinterAvailable();
|
|
23
|
-
setIsPrinterAvailable(available);
|
|
24
|
-
} catch (error) {
|
|
25
|
-
console.error('Error checking printer availability:', error);
|
|
26
|
-
setIsPrinterAvailable(false);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const handlePrintText = async () => {
|
|
31
|
-
if (!isPrinterAvailable) {
|
|
32
|
-
Alert.alert('Printer Error', 'Printer is not available');
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
setIsLoading(true);
|
|
37
|
-
try {
|
|
38
|
-
await SunmiPrinter.printText(
|
|
39
|
-
'Hello, Sunmi Printer!\n',
|
|
40
|
-
SunmiPrinter.FONT_SIZE_LARGE,
|
|
41
|
-
);
|
|
42
|
-
await SunmiPrinter.feedPaper(3);
|
|
43
|
-
Alert.alert('Success', 'Text printed successfully');
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.error('Error printing text:', error);
|
|
46
|
-
Alert.alert('Print Error', error.message || 'Failed to print text');
|
|
47
|
-
} finally {
|
|
48
|
-
setIsLoading(false);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const handlePrintCenteredText = async () => {
|
|
53
|
-
if (!isPrinterAvailable) {
|
|
54
|
-
Alert.alert('Printer Error', 'Printer is not available');
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
setIsLoading(true);
|
|
59
|
-
try {
|
|
60
|
-
await SunmiPrinter.printTextWithAlignment(
|
|
61
|
-
'Centered Text Example\n',
|
|
62
|
-
SunmiPrinter.FONT_SIZE_LARGE,
|
|
63
|
-
SunmiPrinter.ALIGN_CENTER,
|
|
64
|
-
);
|
|
65
|
-
await SunmiPrinter.feedPaper(3);
|
|
66
|
-
Alert.alert('Success', 'Centered text printed successfully');
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.error('Error printing centered text:', error);
|
|
69
|
-
Alert.alert(
|
|
70
|
-
'Print Error',
|
|
71
|
-
error.message || 'Failed to print centered text',
|
|
72
|
-
);
|
|
73
|
-
} finally {
|
|
74
|
-
setIsLoading(false);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const handlePrintDivider = async () => {
|
|
79
|
-
if (!isPrinterAvailable) {
|
|
80
|
-
Alert.alert('Printer Error', 'Printer is not available');
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
setIsLoading(true);
|
|
85
|
-
try {
|
|
86
|
-
await SunmiPrinter.printDivider();
|
|
87
|
-
await SunmiPrinter.feedPaper(3);
|
|
88
|
-
Alert.alert('Success', 'Divider printed successfully');
|
|
89
|
-
} catch (error) {
|
|
90
|
-
console.error('Error printing divider:', error);
|
|
91
|
-
Alert.alert('Print Error', error.message || 'Failed to print divider');
|
|
92
|
-
} finally {
|
|
93
|
-
setIsLoading(false);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const handlePrintSampleReceipt = async () => {
|
|
98
|
-
if (!isPrinterAvailable) {
|
|
99
|
-
Alert.alert('Printer Error', 'Printer is not available');
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
setIsLoading(true);
|
|
104
|
-
try {
|
|
105
|
-
await SunmiPrinter.printSampleReceipt();
|
|
106
|
-
Alert.alert('Success', 'Sample receipt printed successfully');
|
|
107
|
-
} catch (error) {
|
|
108
|
-
console.error('Error printing sample receipt:', error);
|
|
109
|
-
Alert.alert(
|
|
110
|
-
'Print Error',
|
|
111
|
-
error.message || 'Failed to print sample receipt',
|
|
112
|
-
);
|
|
113
|
-
} finally {
|
|
114
|
-
setIsLoading(false);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
return (
|
|
119
|
-
<ScrollView style={styles.container}>
|
|
120
|
-
<Text style={styles.title}>Sunmi Printer Example</Text>
|
|
121
|
-
|
|
122
|
-
<View style={styles.statusContainer}>
|
|
123
|
-
<Text style={styles.statusLabel}>Printer Status:</Text>
|
|
124
|
-
<Text
|
|
125
|
-
style={[
|
|
126
|
-
styles.statusValue,
|
|
127
|
-
{color: isPrinterAvailable ? 'green' : 'red'},
|
|
128
|
-
]}>
|
|
129
|
-
{isPrinterAvailable ? 'Available' : 'Not Available'}
|
|
130
|
-
</Text>
|
|
131
|
-
</View>
|
|
132
|
-
|
|
133
|
-
<TouchableOpacity
|
|
134
|
-
style={[styles.button, isLoading && styles.buttonDisabled]}
|
|
135
|
-
onPress={handlePrintText}
|
|
136
|
-
disabled={isLoading}>
|
|
137
|
-
<Text style={styles.buttonText}>Print Text</Text>
|
|
138
|
-
</TouchableOpacity>
|
|
139
|
-
|
|
140
|
-
<TouchableOpacity
|
|
141
|
-
style={[styles.button, isLoading && styles.buttonDisabled]}
|
|
142
|
-
onPress={handlePrintCenteredText}
|
|
143
|
-
disabled={isLoading}>
|
|
144
|
-
<Text style={styles.buttonText}>Print Centered Text</Text>
|
|
145
|
-
</TouchableOpacity>
|
|
146
|
-
|
|
147
|
-
<TouchableOpacity
|
|
148
|
-
style={[styles.button, isLoading && styles.buttonDisabled]}
|
|
149
|
-
onPress={handlePrintDivider}
|
|
150
|
-
disabled={isLoading}>
|
|
151
|
-
<Text style={styles.buttonText}>Print Divider</Text>
|
|
152
|
-
</TouchableOpacity>
|
|
153
|
-
|
|
154
|
-
<TouchableOpacity
|
|
155
|
-
style={[styles.button, isLoading && styles.buttonDisabled]}
|
|
156
|
-
onPress={handlePrintSampleReceipt}
|
|
157
|
-
disabled={isLoading}>
|
|
158
|
-
<Text style={styles.buttonText}>Print Sample Receipt</Text>
|
|
159
|
-
</TouchableOpacity>
|
|
160
|
-
|
|
161
|
-
<TouchableOpacity
|
|
162
|
-
style={[
|
|
163
|
-
styles.button,
|
|
164
|
-
styles.refreshButton,
|
|
165
|
-
isLoading && styles.buttonDisabled,
|
|
166
|
-
]}
|
|
167
|
-
onPress={checkPrinterAvailability}
|
|
168
|
-
disabled={isLoading}>
|
|
169
|
-
<Text style={styles.buttonText}>Refresh Printer Status</Text>
|
|
170
|
-
</TouchableOpacity>
|
|
171
|
-
</ScrollView>
|
|
172
|
-
);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const styles = StyleSheet.create({
|
|
176
|
-
container: {
|
|
177
|
-
flex: 1,
|
|
178
|
-
padding: 16,
|
|
179
|
-
backgroundColor: '#f5f5f5',
|
|
180
|
-
},
|
|
181
|
-
title: {
|
|
182
|
-
fontSize: 24,
|
|
183
|
-
fontWeight: 'bold',
|
|
184
|
-
marginBottom: 24,
|
|
185
|
-
textAlign: 'center',
|
|
186
|
-
},
|
|
187
|
-
statusContainer: {
|
|
188
|
-
flexDirection: 'row',
|
|
189
|
-
alignItems: 'center',
|
|
190
|
-
marginBottom: 24,
|
|
191
|
-
padding: 16,
|
|
192
|
-
backgroundColor: '#fff',
|
|
193
|
-
borderRadius: 8,
|
|
194
|
-
elevation: 2,
|
|
195
|
-
},
|
|
196
|
-
statusLabel: {
|
|
197
|
-
fontSize: 16,
|
|
198
|
-
fontWeight: 'bold',
|
|
199
|
-
marginRight: 8,
|
|
200
|
-
},
|
|
201
|
-
statusValue: {
|
|
202
|
-
fontSize: 16,
|
|
203
|
-
fontWeight: 'bold',
|
|
204
|
-
},
|
|
205
|
-
button: {
|
|
206
|
-
backgroundColor: '#2196F3',
|
|
207
|
-
padding: 16,
|
|
208
|
-
borderRadius: 8,
|
|
209
|
-
marginBottom: 16,
|
|
210
|
-
alignItems: 'center',
|
|
211
|
-
elevation: 2,
|
|
212
|
-
},
|
|
213
|
-
buttonDisabled: {
|
|
214
|
-
backgroundColor: '#cccccc',
|
|
215
|
-
},
|
|
216
|
-
buttonText: {
|
|
217
|
-
color: '#fff',
|
|
218
|
-
fontSize: 16,
|
|
219
|
-
fontWeight: 'bold',
|
|
220
|
-
},
|
|
221
|
-
refreshButton: {
|
|
222
|
-
backgroundColor: '#4CAF50',
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
export default PrinterExample;
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import {NativeModules, Platform} from 'react-native';
|
|
2
|
-
|
|
3
|
-
const {SunmiCardModule} = NativeModules;
|
|
4
|
-
|
|
5
|
-
if (!SunmiCardModule) {
|
|
6
|
-
throw new Error('SunmiCardModule is not available on this device');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Interface for Sunmi Card Reader functionality
|
|
11
|
-
*/
|
|
12
|
-
class SunmiCard {
|
|
13
|
-
/**
|
|
14
|
-
* Card types constants
|
|
15
|
-
*/
|
|
16
|
-
static CARD_TYPE_MAGNETIC = SunmiCardModule.CARD_TYPE_MAGNETIC;
|
|
17
|
-
static CARD_TYPE_IC = SunmiCardModule.CARD_TYPE_IC;
|
|
18
|
-
static CARD_TYPE_NFC = SunmiCardModule.CARD_TYPE_NFC;
|
|
19
|
-
static CARD_TYPE_MAGNETIC_IC = SunmiCardModule.CARD_TYPE_MAGNETIC_IC;
|
|
20
|
-
static CARD_TYPE_MAGNETIC_NFC = SunmiCardModule.CARD_TYPE_MAGNETIC_NFC;
|
|
21
|
-
static CARD_TYPE_IC_NFC = SunmiCardModule.CARD_TYPE_IC_NFC;
|
|
22
|
-
static CARD_TYPE_MAGNETIC_IC_NFC = SunmiCardModule.CARD_TYPE_MAGNETIC_IC_NFC;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Card reader mode constants
|
|
26
|
-
*/
|
|
27
|
-
static READ_MODE_MAGNETIC = SunmiCardModule.READ_MODE_MAGNETIC;
|
|
28
|
-
static READ_MODE_IC = SunmiCardModule.READ_MODE_IC;
|
|
29
|
-
static READ_MODE_NFC = SunmiCardModule.READ_MODE_NFC;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Track error code constants
|
|
33
|
-
*/
|
|
34
|
-
static TRACK_ERROR_NONE = SunmiCardModule.TRACK_ERROR_NONE; // No error
|
|
35
|
-
static TRACK_ERROR_NO_DATA = SunmiCardModule.TRACK_ERROR_NO_DATA; // Track has no data
|
|
36
|
-
static TRACK_ERROR_PARITY = SunmiCardModule.TRACK_ERROR_PARITY; // Track parity check error
|
|
37
|
-
static TRACK_ERROR_LRC = SunmiCardModule.TRACK_ERROR_LRC; // Track LRC check error
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Check if the Sunmi Pay SDK is connected
|
|
41
|
-
* @returns {Promise<boolean>} - True if connected
|
|
42
|
-
*/
|
|
43
|
-
static isConnected() {
|
|
44
|
-
if (Platform.OS !== 'android') {
|
|
45
|
-
return Promise.reject(
|
|
46
|
-
new Error('SunmiCard is only available on Android'),
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return SunmiCardModule.isConnected();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Check for a card to be presented
|
|
55
|
-
* @param {number} cardType - Type of card to check for (use CARD_TYPE_* constants)
|
|
56
|
-
* @param {number} timeout - Timeout in seconds
|
|
57
|
-
* @returns {Promise<Object>} - Card information or timeout/error
|
|
58
|
-
*
|
|
59
|
-
* For magnetic cards, the result will include:
|
|
60
|
-
* - type: "magnetic"
|
|
61
|
-
* - track1: Track 1 data (if available)
|
|
62
|
-
* - track2: Track 2 data (if available)
|
|
63
|
-
* - track3: Track 3 data (if available)
|
|
64
|
-
* - track1ErrorCode: Error code for track 1 (0 = no error, -1 = no data, -2 = parity error, -3 = LRC error)
|
|
65
|
-
* - track2ErrorCode: Error code for track 2
|
|
66
|
-
* - track3ErrorCode: Error code for track 3
|
|
67
|
-
*
|
|
68
|
-
* For IC cards, the result will include:
|
|
69
|
-
* - type: "ic"
|
|
70
|
-
* - atr: ATR data
|
|
71
|
-
*
|
|
72
|
-
* For NFC cards, the result will include:
|
|
73
|
-
* - type: "nfc"
|
|
74
|
-
* - uuid: Card UUID
|
|
75
|
-
*
|
|
76
|
-
* For timeout, the result will include:
|
|
77
|
-
* - type: "timeout"
|
|
78
|
-
*/
|
|
79
|
-
static checkCard(cardType, timeout = 60) {
|
|
80
|
-
if (Platform.OS !== 'android') {
|
|
81
|
-
return Promise.reject(
|
|
82
|
-
new Error('SunmiCard is only available on Android'),
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (typeof cardType !== 'number') {
|
|
87
|
-
return Promise.reject(new Error('cardType must be a number'));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (typeof timeout !== 'number') {
|
|
91
|
-
return Promise.reject(new Error('timeout must be a number'));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return SunmiCardModule.checkCard(cardType, timeout);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Cancel an ongoing card check operation
|
|
99
|
-
* @returns {Promise<boolean>} - True if successful
|
|
100
|
-
*/
|
|
101
|
-
static cancelCardCheck() {
|
|
102
|
-
if (Platform.OS !== 'android') {
|
|
103
|
-
return Promise.reject(
|
|
104
|
-
new Error('SunmiCard is only available on Android'),
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return SunmiCardModule.cancelCardCheck();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Read data from an IC card
|
|
113
|
-
* Note: This method is provided for backward compatibility.
|
|
114
|
-
* It's recommended to use checkCard with CARD_TYPE_IC instead.
|
|
115
|
-
* @returns {Promise<Object>} - IC card information
|
|
116
|
-
*/
|
|
117
|
-
static readICCard() {
|
|
118
|
-
if (Platform.OS !== 'android') {
|
|
119
|
-
return Promise.reject(
|
|
120
|
-
new Error('SunmiCard is only available on Android'),
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return SunmiCardModule.readICCard();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Read data from an NFC card
|
|
129
|
-
* Note: This method is provided for backward compatibility.
|
|
130
|
-
* It's recommended to use checkCard with CARD_TYPE_NFC instead.
|
|
131
|
-
* @returns {Promise<Object>} - NFC card information
|
|
132
|
-
*/
|
|
133
|
-
static readNFCCard() {
|
|
134
|
-
if (Platform.OS !== 'android') {
|
|
135
|
-
return Promise.reject(
|
|
136
|
-
new Error('SunmiCard is only available on Android'),
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return SunmiCardModule.readNFCCard();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Transaction types
|
|
145
|
-
*/
|
|
146
|
-
static TRANS_TYPE_CONSUME = SunmiCardModule.TRANS_TYPE_CONSUME;
|
|
147
|
-
static TRANS_TYPE_REFUND = SunmiCardModule.TRANS_TYPE_REFUND;
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Transaction result codes
|
|
151
|
-
*/
|
|
152
|
-
static TRANS_RESULT_SUCCESS = SunmiCardModule.TRANS_RESULT_SUCCESS;
|
|
153
|
-
static TRANS_RESULT_OFFLINE_APPROVED =
|
|
154
|
-
SunmiCardModule.TRANS_RESULT_OFFLINE_APPROVED;
|
|
155
|
-
static TRANS_RESULT_DECLINED = SunmiCardModule.TRANS_RESULT_DECLINED;
|
|
156
|
-
static TRANS_RESULT_TERMINATED = SunmiCardModule.TRANS_RESULT_TERMINATED;
|
|
157
|
-
static TRANS_RESULT_CANCEL = SunmiCardModule.TRANS_RESULT_CANCEL;
|
|
158
|
-
static TRANS_RESULT_TIMEOUT = SunmiCardModule.TRANS_RESULT_TIMEOUT;
|
|
159
|
-
static TRANS_RESULT_OTHER_ERROR = SunmiCardModule.TRANS_RESULT_OTHER_ERROR;
|
|
160
|
-
static TRANS_RESULT_MAC_ERROR = SunmiCardModule.TRANS_RESULT_MAC_ERROR;
|
|
161
|
-
static TRANS_RESULT_FALLBACK = SunmiCardModule.TRANS_RESULT_FALLBACK;
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Start a card payment transaction
|
|
165
|
-
* @param {number} amount - The transaction amount in cents (e.g., 1000 for $10.00)
|
|
166
|
-
* @param {string} currency - The currency code (e.g., "USD")
|
|
167
|
-
* @param {string} transactionType - The transaction type ("consume" or "refund")
|
|
168
|
-
* @param {number} timeout - Timeout in seconds for card detection
|
|
169
|
-
* @returns {Promise<Object>} - Transaction result object
|
|
170
|
-
*/
|
|
171
|
-
static startCardPayment(
|
|
172
|
-
amount,
|
|
173
|
-
currency = 'USD',
|
|
174
|
-
transactionType = 'consume',
|
|
175
|
-
timeout = 60,
|
|
176
|
-
) {
|
|
177
|
-
if (typeof amount !== 'number' || amount <= 0) {
|
|
178
|
-
return Promise.reject(new Error('Amount must be a positive number'));
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Convert transaction type string to integer
|
|
182
|
-
let transType = SunmiCard.TRANS_TYPE_CONSUME;
|
|
183
|
-
if (transactionType.toLowerCase() === 'refund') {
|
|
184
|
-
transType = SunmiCard.TRANS_TYPE_REFUND;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return SunmiCardModule.startCardPayment(
|
|
188
|
-
amount,
|
|
189
|
-
currency,
|
|
190
|
-
transactionType,
|
|
191
|
-
timeout,
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Cancel an ongoing card payment transaction
|
|
197
|
-
* @returns {Promise<boolean>} - True if canceled successfully
|
|
198
|
-
*/
|
|
199
|
-
static cancelCardPayment() {
|
|
200
|
-
return SunmiCardModule.cancelCardPayment();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Get the result of the last transaction
|
|
205
|
-
* @returns {Promise<Object|null>} - Transaction result object or null if no transaction
|
|
206
|
-
*/
|
|
207
|
-
static getLastTransactionResult() {
|
|
208
|
-
return SunmiCardModule.getLastTransactionResult();
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export default SunmiCard;
|