react-native-fpay 0.4.30 → 0.4.33

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.
Files changed (71) hide show
  1. package/lib/module/FountainPayProvider.js +5 -0
  2. package/lib/module/FountainPayProvider.js.map +1 -1
  3. package/lib/module/core/api/index.js +59 -0
  4. package/lib/module/core/api/index.js.map +1 -1
  5. package/lib/module/core/types/index.js +32 -0
  6. package/lib/module/core/types/index.js.map +1 -1
  7. package/lib/module/engine/FPEngine.js +9 -0
  8. package/lib/module/engine/FPEngine.js.map +1 -1
  9. package/lib/module/ui/components/ConfirmScreen.js +43 -51
  10. package/lib/module/ui/components/ConfirmScreen.js.map +1 -1
  11. package/lib/module/ui/components/RecurringToggle.js +94 -0
  12. package/lib/module/ui/components/RecurringToggle.js.map +1 -0
  13. package/lib/module/ui/modals/FPShell.js +19 -0
  14. package/lib/module/ui/modals/FPShell.js.map +1 -1
  15. package/lib/module/ui/screens/BillsScreen.js +187 -0
  16. package/lib/module/ui/screens/BillsScreen.js.map +1 -0
  17. package/lib/module/ui/screens/ResultScreen.js +113 -28
  18. package/lib/module/ui/screens/ResultScreen.js.map +1 -1
  19. package/lib/module/ui/screens/SendScreen.js +54 -6
  20. package/lib/module/ui/screens/SendScreen.js.map +1 -1
  21. package/lib/module/ui/screens/sub/billPayment/AirtimeScreen.js +257 -0
  22. package/lib/module/ui/screens/sub/billPayment/AirtimeScreen.js.map +1 -0
  23. package/lib/module/ui/screens/sub/billPayment/CableScreen.js +264 -0
  24. package/lib/module/ui/screens/sub/billPayment/CableScreen.js.map +1 -0
  25. package/lib/module/ui/screens/sub/billPayment/DataScreen.js +273 -0
  26. package/lib/module/ui/screens/sub/billPayment/DataScreen.js.map +1 -0
  27. package/lib/module/ui/screens/sub/billPayment/ElectricityScreen.js +337 -0
  28. package/lib/module/ui/screens/sub/billPayment/ElectricityScreen.js.map +1 -0
  29. package/lib/typescript/src/FountainPayProvider.d.ts.map +1 -1
  30. package/lib/typescript/src/core/api/index.d.ts +52 -63
  31. package/lib/typescript/src/core/api/index.d.ts.map +1 -1
  32. package/lib/typescript/src/core/types/index.d.ts +146 -0
  33. package/lib/typescript/src/core/types/index.d.ts.map +1 -1
  34. package/lib/typescript/src/engine/FPEngine.d.ts +4 -2
  35. package/lib/typescript/src/engine/FPEngine.d.ts.map +1 -1
  36. package/lib/typescript/src/index.d.ts +1 -1
  37. package/lib/typescript/src/index.d.ts.map +1 -1
  38. package/lib/typescript/src/ui/components/ConfirmScreen.d.ts +25 -4
  39. package/lib/typescript/src/ui/components/ConfirmScreen.d.ts.map +1 -1
  40. package/lib/typescript/src/ui/components/RecurringToggle.d.ts +7 -0
  41. package/lib/typescript/src/ui/components/RecurringToggle.d.ts.map +1 -0
  42. package/lib/typescript/src/ui/modals/FPShell.d.ts.map +1 -1
  43. package/lib/typescript/src/ui/screens/BillsScreen.d.ts +10 -0
  44. package/lib/typescript/src/ui/screens/BillsScreen.d.ts.map +1 -0
  45. package/lib/typescript/src/ui/screens/ResultScreen.d.ts +20 -3
  46. package/lib/typescript/src/ui/screens/ResultScreen.d.ts.map +1 -1
  47. package/lib/typescript/src/ui/screens/SendScreen.d.ts.map +1 -1
  48. package/lib/typescript/src/ui/screens/sub/billPayment/AirtimeScreen.d.ts +15 -0
  49. package/lib/typescript/src/ui/screens/sub/billPayment/AirtimeScreen.d.ts.map +1 -0
  50. package/lib/typescript/src/ui/screens/sub/billPayment/CableScreen.d.ts +14 -0
  51. package/lib/typescript/src/ui/screens/sub/billPayment/CableScreen.d.ts.map +1 -0
  52. package/lib/typescript/src/ui/screens/sub/billPayment/DataScreen.d.ts +14 -0
  53. package/lib/typescript/src/ui/screens/sub/billPayment/DataScreen.d.ts.map +1 -0
  54. package/lib/typescript/src/ui/screens/sub/billPayment/ElectricityScreen.d.ts +16 -0
  55. package/lib/typescript/src/ui/screens/sub/billPayment/ElectricityScreen.d.ts.map +1 -0
  56. package/package.json +2 -2
  57. package/src/FountainPayProvider.tsx +7 -0
  58. package/src/core/api/index.ts +149 -27
  59. package/src/core/types/index.ts +181 -0
  60. package/src/engine/FPEngine.ts +12 -1
  61. package/src/index.ts +9 -1
  62. package/src/ui/components/ConfirmScreen.tsx +47 -54
  63. package/src/ui/components/RecurringToggle.tsx +106 -0
  64. package/src/ui/modals/FPShell.tsx +26 -3
  65. package/src/ui/screens/BillsScreen.tsx +198 -0
  66. package/src/ui/screens/ResultScreen.tsx +129 -28
  67. package/src/ui/screens/SendScreen.tsx +43 -6
  68. package/src/ui/screens/sub/billPayment/AirtimeScreen.tsx +252 -0
  69. package/src/ui/screens/sub/billPayment/CableScreen.tsx +274 -0
  70. package/src/ui/screens/sub/billPayment/DataScreen.tsx +263 -0
  71. package/src/ui/screens/sub/billPayment/ElectricityScreen.tsx +344 -0
@@ -0,0 +1,344 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { View, Text, TouchableOpacity, ScrollView, KeyboardAvoidingView, Platform, Switch, ActivityIndicator } from 'react-native';
3
+ import styled from 'styled-components/native';
4
+ import { C, F, R, S } from '../../../theme';
5
+ import { billsAPI } from '../../../../core/api';
6
+ import type { FPBillProvider, FPMeterType, FPElectricityPurchaseRequest, FPUserInfo } from '../../../../core/types';
7
+
8
+ const Container = styled(View)`
9
+ flex: 1;
10
+ background-color: ${C.white};
11
+ `;
12
+
13
+ const Body = styled(ScrollView)`
14
+ flex: 1;
15
+ padding: ${S.lg}px;
16
+ `;
17
+
18
+ const FieldLabel = styled(Text)`
19
+ font-size: ${F.sm}px;
20
+ font-weight: 600;
21
+ color: ${C.muted};
22
+ margin-bottom: ${S.xs}px;
23
+ `;
24
+
25
+ const InputBox = styled.View`
26
+ background-color: ${C.surface};
27
+ border-radius: ${R.lg}px;
28
+ padding: 0 ${S.md}px;
29
+ height: 52px;
30
+ flex-direction: row;
31
+ align-items: center;
32
+ margin-bottom: ${S.md}px;
33
+ `;
34
+
35
+ const StyledInput = styled.TextInput`
36
+ flex: 1;
37
+ font-size: ${F.md}px;
38
+ color: ${C.ink};
39
+ `;
40
+
41
+ const CurrencyPrefix = styled(Text)`
42
+ font-size: ${F.md}px;
43
+ color: ${C.muted};
44
+ margin-right: ${S.xs}px;
45
+ `;
46
+
47
+ const SelectBox = styled(TouchableOpacity)`
48
+ background-color: ${C.surface};
49
+ border-radius: ${R.lg}px;
50
+ padding: 0 ${S.md}px;
51
+ height: 52px;
52
+ flex-direction: row;
53
+ align-items: center;
54
+ justify-content: space-between;
55
+ margin-bottom: ${S.md}px;
56
+ `;
57
+
58
+ const SelectBoxText = styled(Text)<{ placeholder?: boolean }>`
59
+ font-size: ${F.md}px;
60
+ color: ${(props: any) => (props.placeholder ? C.ghost : C.ink)};
61
+ `;
62
+
63
+ const DiscoSheet = styled(View)`
64
+ background-color: ${C.white};
65
+ border-radius: ${R.xl}px;
66
+ padding: ${S.md}px;
67
+ margin-bottom: ${S.md}px;
68
+ max-height: 240px;
69
+ `;
70
+
71
+ const DiscoRow = styled(TouchableOpacity)<{ selected: boolean }>`
72
+ padding: ${S.sm}px ${S.md}px;
73
+ border-radius: ${R.md}px;
74
+ background-color: ${(props: any) => (props.selected ? C.brandLight : 'transparent')};
75
+ margin-bottom: 4px;
76
+ `;
77
+
78
+ const DiscoRowText = styled(Text)`
79
+ font-size: ${F.md}px;
80
+ color: ${C.ink};
81
+ font-weight: 600;
82
+ `;
83
+
84
+ const TypeRow = styled(View)`
85
+ flex-direction: row;
86
+ gap: ${S.sm}px;
87
+ margin-bottom: ${S.md}px;
88
+ `;
89
+
90
+ const TypeChip = styled(TouchableOpacity)<{ selected: boolean }>`
91
+ flex: 1;
92
+ height: 44px;
93
+ border-radius: ${R.md}px;
94
+ align-items: center;
95
+ justify-content: center;
96
+ background-color: ${(props: any) => (props.selected ? C.brand : C.surface)};
97
+ `;
98
+
99
+ const TypeChipText = styled(Text)<{ selected: boolean }>`
100
+ font-size: ${F.sm}px;
101
+ font-weight: 700;
102
+ color: ${(props: any) => (props.selected ? C.white : C.muted)};
103
+ `;
104
+
105
+ const CustomerNameBox = styled(View)`
106
+ background-color: ${C.greenLight};
107
+ border-radius: ${R.md}px;
108
+ padding: ${S.sm}px ${S.md}px;
109
+ margin-bottom: ${S.md}px;
110
+ `;
111
+
112
+ const CustomerNameText = styled(Text)`
113
+ color: ${C.green};
114
+ font-weight: 700;
115
+ font-size: ${F.sm}px;
116
+ `;
117
+
118
+ const SwitchRow = styled(View)`
119
+ flex-direction: row;
120
+ justify-content: space-between;
121
+ align-items: center;
122
+ margin-bottom: ${S.md}px;
123
+ `;
124
+
125
+ const SwitchLabel = styled(Text)`
126
+ font-size: ${F.md}px;
127
+ color: ${C.ink};
128
+ font-weight: 600;
129
+ `;
130
+
131
+ const ContinueButton = styled(TouchableOpacity)<{ disabled?: boolean }>`
132
+ background-color: ${(props: any) => (props.disabled ? C.ghost : C.brand)};
133
+ border-radius: ${R.full}px;
134
+ padding: ${S.md}px 0;
135
+ align-items: center;
136
+ margin-top: ${S.sm}px;
137
+ `;
138
+
139
+ const ContinueButtonText = styled(Text)`
140
+ color: ${C.white};
141
+ font-weight: 800;
142
+ font-size: ${F.md}px;
143
+ `;
144
+
145
+ interface Props {
146
+ amount: number;
147
+ user: FPUserInfo | null;
148
+ onProcessTransaction: (
149
+ payload: FPElectricityPurchaseRequest,
150
+ summaryRows: { label: string; value: string }[]
151
+ ) => void;
152
+ onError?: (err: { code: string; message: string }) => void;
153
+ }
154
+
155
+ export default function ElectricityScreen({ amount, user, onProcessTransaction, onError }: Props) {
156
+ const [discos, setDiscos] = useState<FPBillProvider[]>([]);
157
+ const [discoPickerOpen, setDiscoPickerOpen] = useState(false);
158
+ const [disco, setDisco] = useState<FPBillProvider | null>(null);
159
+ const [meterType, setMeterType] = useState<FPMeterType>('PREPAID');
160
+ const [meterNumber, setMeterNumber] = useState('');
161
+ const [validating, setValidating] = useState(false);
162
+ const [customerName, setCustomerName] = useState<string | null>(null);
163
+ const [minVendInKobo, setMinVendInKobo] = useState<number | null>(null);
164
+ const [purchaseAmount, setPurchaseAmount] = useState<string>(amount > 0 ? String(amount) : '');
165
+ const [forSelf, setForSelf] = useState(true);
166
+ const [phone, setPhone] = useState('');
167
+ const [email, setEmail] = useState('');
168
+
169
+ useEffect(() => {
170
+ billsAPI
171
+ .getDiscos()
172
+ .then((res: any) => {
173
+ if (res.status) setDiscos(res.payload.filter((d: FPBillProvider) => d.isActive));
174
+ })
175
+ .catch(() => onError?.({ code: 'DISCO_LOAD_FAILED', message: 'Could not load electricity providers' }));
176
+ }, []);
177
+
178
+ // Re-validate whenever the meter number reaches a plausible length, or
179
+ // the disco/type changes — mirrors checkMeterNumber()'s trigger in the
180
+ // existing BuyPower-backed Electricity screen.
181
+ useEffect(() => {
182
+ setCustomerName(null);
183
+ setMinVendInKobo(null);
184
+ if (!disco || meterNumber.length < 10) return;
185
+
186
+ setValidating(true);
187
+ billsAPI
188
+ .validateMeter(meterNumber, disco.code, meterType)
189
+ .then((res: any) => {
190
+ if (res.status) {
191
+ setCustomerName(res.payload.customerName);
192
+ setMinVendInKobo(res.payload.minVendAmountInKobo ?? null);
193
+ } else {
194
+ onError?.({ code: 'METER_INVALID', message: res.message });
195
+ }
196
+ })
197
+ .catch(() => onError?.({ code: 'METER_VALIDATION_FAILED', message: 'Could not validate meter number' }))
198
+ .finally(() => setValidating(false));
199
+ }, [disco, meterType, meterNumber]);
200
+
201
+ const amountInKobo = Math.round((Number(purchaseAmount) || 0) * 100);
202
+ const meetsMinVend = minVendInKobo == null || amountInKobo >= minVendInKobo;
203
+ const contactValid = forSelf || (/^0\d{10}$/.test(phone) && /\S+@\S+\.\S+/.test(email));
204
+
205
+ const isValid =
206
+ !!disco && meterNumber.length >= 10 && !!customerName && amountInKobo > 0 && meetsMinVend && contactValid;
207
+
208
+ const handleContinue = () => {
209
+ if (!isValid || !disco) return;
210
+ onProcessTransaction(
211
+ {
212
+ category: 'ELECTRICITY',
213
+ meterNumber,
214
+ disco: disco.code,
215
+ meterType,
216
+ amountInKobo,
217
+ forSelf,
218
+ phoneNumber: forSelf ? (user?.phone ?? '') : phone,
219
+ email: forSelf ? (user?.email ?? '') : email,
220
+ idempotencyKey: `electricity_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
221
+ },
222
+ [
223
+ { label: 'Disco', value: disco.displayName },
224
+ { label: 'Meter Type', value: meterType },
225
+ { label: 'Meter Number', value: meterNumber },
226
+ { label: 'Customer', value: customerName ?? '' },
227
+ ]
228
+ );
229
+ };
230
+
231
+ return (
232
+ <Container>
233
+ <KeyboardAvoidingView style={{ flex: 1 }} behavior={Platform.OS === 'ios' ? 'padding' : undefined}>
234
+ <Body keyboardShouldPersistTaps="handled" showsVerticalScrollIndicator={false}>
235
+ <FieldLabel>Distribution Company</FieldLabel>
236
+ <SelectBox onPress={() => setDiscoPickerOpen((v: any) => !v)}>
237
+ <SelectBoxText placeholder={!disco}>{disco?.displayName ?? 'Select a disco'}</SelectBoxText>
238
+ <Text>{discoPickerOpen ? '▲' : '▼'}</Text>
239
+ </SelectBox>
240
+
241
+ {discoPickerOpen && (
242
+ <DiscoSheet>
243
+ <ScrollView showsVerticalScrollIndicator={false}>
244
+ {discos.map((d: any) => (
245
+ <DiscoRow
246
+ key={d.code}
247
+ selected={disco?.code === d.code}
248
+ onPress={() => {
249
+ setDisco(d);
250
+ setDiscoPickerOpen(false);
251
+ }}
252
+ >
253
+ <DiscoRowText>{d.displayName}</DiscoRowText>
254
+ </DiscoRow>
255
+ ))}
256
+ </ScrollView>
257
+ </DiscoSheet>
258
+ )}
259
+
260
+ <FieldLabel>Meter Type</FieldLabel>
261
+ <TypeRow>
262
+ <TypeChip selected={meterType === 'PREPAID'} onPress={() => setMeterType('PREPAID')}>
263
+ <TypeChipText selected={meterType === 'PREPAID'}>Prepaid</TypeChipText>
264
+ </TypeChip>
265
+ <TypeChip selected={meterType === 'POSTPAID'} onPress={() => setMeterType('POSTPAID')}>
266
+ <TypeChipText selected={meterType === 'POSTPAID'}>Postpaid</TypeChipText>
267
+ </TypeChip>
268
+ </TypeRow>
269
+
270
+ <FieldLabel>Meter Number</FieldLabel>
271
+ <InputBox>
272
+ <StyledInput
273
+ placeholder="Enter meter number"
274
+ placeholderTextColor={C.ghost}
275
+ keyboardType="number-pad"
276
+ value={meterNumber}
277
+ onChangeText={setMeterNumber}
278
+ />
279
+ </InputBox>
280
+ {validating && <ActivityIndicator color={C.brand} style={{ marginBottom: S.md }} />}
281
+ {customerName && (
282
+ <CustomerNameBox>
283
+ <CustomerNameText>{customerName}</CustomerNameText>
284
+ </CustomerNameBox>
285
+ )}
286
+
287
+ <FieldLabel>Amount</FieldLabel>
288
+ <InputBox>
289
+ <CurrencyPrefix>₦</CurrencyPrefix>
290
+ <StyledInput
291
+ placeholder="Enter amount"
292
+ placeholderTextColor={C.ghost}
293
+ keyboardType="number-pad"
294
+ value={purchaseAmount}
295
+ onChangeText={setPurchaseAmount}
296
+ />
297
+ </InputBox>
298
+ {minVendInKobo != null && !meetsMinVend && (
299
+ <Text style={{ color: C.red, fontSize: F.xs, marginBottom: S.md }}>
300
+ Minimum amount is ₦{(minVendInKobo / 100).toLocaleString()}
301
+ </Text>
302
+ )}
303
+
304
+ <SwitchRow>
305
+ <SwitchLabel>This is for me</SwitchLabel>
306
+ <Switch
307
+ value={forSelf}
308
+ onValueChange={setForSelf}
309
+ trackColor={{ false: C.border, true: C.brandLight }}
310
+ thumbColor={forSelf ? C.brand : C.ghost}
311
+ />
312
+ </SwitchRow>
313
+
314
+ {!forSelf && (
315
+ <>
316
+ <InputBox>
317
+ <StyledInput
318
+ placeholder="Phone number"
319
+ placeholderTextColor={C.ghost}
320
+ keyboardType="number-pad"
321
+ value={phone}
322
+ onChangeText={setPhone}
323
+ />
324
+ </InputBox>
325
+ <InputBox>
326
+ <StyledInput
327
+ placeholder="Email address"
328
+ placeholderTextColor={C.ghost}
329
+ keyboardType="email-address"
330
+ value={email}
331
+ onChangeText={setEmail}
332
+ />
333
+ </InputBox>
334
+ </>
335
+ )}
336
+
337
+ <ContinueButton disabled={!isValid} onPress={handleContinue} activeOpacity={0.85}>
338
+ <ContinueButtonText>Continue</ContinueButtonText>
339
+ </ContinueButton>
340
+ </Body>
341
+ </KeyboardAvoidingView>
342
+ </Container>
343
+ );
344
+ }