edfapay-softpos-sdk-rn 1.0.0 → 1.0.2

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 (2) hide show
  1. package/README.md +423 -16
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,37 +1,444 @@
1
- # edfapay-softpos-sdk-rn
1
+ # EdfaPay SoftPOS SDK — React Native
2
+ <h3>Helps developers to easily integrate EdfaPay SoftPOS to React Native mobile applications with a few simple steps.</h3>
2
3
 
3
- SoftPOS
4
+ ### [Wiki & Documentation](https://github.com/edfapay/edfapay-softpos-sdk-examples/wiki)
4
5
 
5
- ## Installation
6
6
 
7
+ # EdfaPay SoftPOS SDK
7
8
 
8
- ```sh
9
- npm install edfapay-softpos-sdk-rn
10
- ```
9
+ > [!IMPORTANT]
10
+ > ### Install edfapay-softpos-sdk-rn
11
+ > - **Add the dependency by running:**
12
+ > ```sh
13
+ > npm install edfapay-softpos-sdk-rn
14
+ > # or
15
+ > yarn add edfapay-softpos-sdk-rn
16
+ > ```
17
+
18
+ > [!IMPORTANT]
19
+ > ### Set Repository Access Credentials
20
+ > - Add the following credentials to your project **`android/gradle.properties`** or **`~/.gradle/gradle.properties`**
21
+ > ```properties
22
+ > PARTNER_REPO_USERNAME=edfapay-sdk-consumer
23
+ > PARTNER_REPO_PASSWORD=Edfapay@123
24
+ > ```
25
+
26
+ > [!IMPORTANT]
27
+ > ### FragmentActivity Requirement
28
+ > - Change the Android **MainActivity** base class from **`ReactActivity`** to **`ReactFragmentActivity`** (or ensure it extends `AppCompatActivity`)
29
+ > - Path: `android/app/src/main/java/<your_package>/MainActivity.kt` (or `.java`)
30
+ >
31
+ > **Example (Kotlin)**
32
+ > ```kotlin
33
+ > package com.yourapp
34
+ >
35
+ > import com.facebook.react.ReactFragmentActivity
36
+ >
37
+ > class MainActivity : ReactFragmentActivity()
38
+ > ```
11
39
 
12
40
 
13
41
  ## Usage
14
42
 
43
+ ### 1: Imports
44
+ ```tsx
45
+ import {
46
+ EdfaPayPlugin,
47
+ EdfaPayCredentials,
48
+ Env,
49
+ TxnParams,
50
+ Transaction,
51
+ TransactionType,
52
+ FlowType,
53
+ Presentation,
54
+ PresentationConfig,
55
+ PurchaseSecondaryAction,
56
+ } from 'edfapay-softpos-sdk-rn';
57
+ ```
58
+
59
+ ### 2: Setting Theme (Optional)
60
+
61
+ **2.1: Colors and Logos**
62
+ ```ts
63
+ const logoBase64 = "base64 encoded image string";
64
+
65
+ EdfaPayPlugin.theme()
66
+ .setPrimaryColor('#06E59F')
67
+ .setSecondaryColor('#000000')
68
+ .setPoweredByImage(logoBase64)
69
+ .setHeaderImage(logoBase64);
70
+ ```
71
+
72
+ **2.2: Setting Presentation**
73
+ - `Presentation.FULLSCREEN`
74
+ - `Presentation.DIALOG_CENTER`
75
+ - `Presentation.DIALOG_TOP_FILL`
76
+ - `Presentation.DIALOG_BOTTOM_FILL`
77
+ - `Presentation.DIALOG_TOP_START`
78
+ - `Presentation.DIALOG_TOP_END`
79
+ - `Presentation.DIALOG_TOP_CENTER`
80
+ - `Presentation.DIALOG_BOTTOM_START`
81
+ - `Presentation.DIALOG_BOTTOM_END`
82
+ - `Presentation.DIALOG_BOTTOM_CENTER`
83
+
84
+ ```ts
85
+ EdfaPayPlugin.theme()
86
+ .setPresentation(
87
+ new PresentationConfig(Presentation.DIALOG_CENTER)
88
+ .sizePercent(0.85) // 0.20 to 1.0, aligned to screen smallest axis
89
+ .dismissOnBackPress(true)
90
+ .dismissOnTouchOutside(true)
91
+ .animateExit(true)
92
+ .animateEntry(true)
93
+ .dimBackground(true)
94
+ .dimAmount(1.0) // 0.0 to 1.0
95
+ .marginAll(0)
96
+ .cornerRadius(20)
97
+ .marginHorizontal(10)
98
+ .marginVertical(10)
99
+ .setPurchaseSecondaryAction(PurchaseSecondaryAction.NONE)
100
+ );
101
+ ```
102
+
103
+ **2.3: Secondary / Post-Purchase Action**
104
+ - `PurchaseSecondaryAction.REVERSE`
105
+ - `PurchaseSecondaryAction.REFUND`
106
+ - `PurchaseSecondaryAction.NONE`
107
+
108
+ ```ts
109
+ EdfaPayPlugin.theme()
110
+ .setPresentation(
111
+ new PresentationConfig(Presentation.DIALOG_CENTER)
112
+ .setPurchaseSecondaryAction(PurchaseSecondaryAction.REVERSE)
113
+ );
114
+ ```
115
+
116
+ **2.4: PIN PAD Shuffle**
117
+ ```ts
118
+ EdfaPayPlugin.theme()
119
+ .setPresentation(
120
+ new PresentationConfig(Presentation.DIALOG_CENTER)
121
+ .setShufflePinPad(true) // default false
122
+ );
123
+ ```
124
+
125
+ ### 3: Initialization
126
+
127
+ **3.1: Create Credentials**
128
+
129
+ - Prompt for credentials (email/password or token input):
130
+ ```ts
131
+ const credentials = EdfaPayCredentials.withInput(Env.PRODUCTION);
132
+ ```
133
+
134
+ - Prompt with pre-filled email/password:
135
+ ```ts
136
+ const credentials = EdfaPayCredentials.withEmailPassword(
137
+ Env.DEVELOPMENT,
138
+ 'user@email.com',
139
+ 'Password@123'
140
+ );
141
+ ```
142
+
143
+ - Prompt with pre-filled email only:
144
+ ```ts
145
+ const credentials = EdfaPayCredentials.withEmail(Env.DEVELOPMENT, 'user@email.com');
146
+ ```
147
+
148
+ - Silent initialization with a Terminal Token:
149
+ ```ts
150
+ const credentials = EdfaPayCredentials.withToken(
151
+ Env.DEVELOPMENT, // also: Env.STAGING | Env.SANDBOX | Env.PRODUCTION | Env.REVAMP
152
+ '****Terminal Token Generated at EdfaPay SoftPOS Portal****'
153
+ );
154
+ ```
155
+
156
+ **3.2: Initialize with Credentials**
157
+ ```ts
158
+ EdfaPayPlugin.enableLogs(true);
159
+ EdfaPayPlugin.setAnimationSpeedX(2.5); // Optional: animation speed multiplier
160
+
161
+ EdfaPayPlugin.initiate({
162
+ credentials,
163
+ onSuccess: (sessionId) => {
164
+ console.log('>>> SDK Initialized — Session ID: ' + sessionId);
165
+ },
166
+ onTerminalBindingTask: (task) => {
167
+ console.log('>>> Terminal Binding Required');
168
+
169
+ const terminals = task.terminals;
170
+
171
+ // Option 1: Show SDK's built-in terminal selection UI
172
+ task.bind();
173
+
174
+ // Option 2: Bind the first terminal programmatically
175
+ terminals[0]?.bind();
176
+
177
+ // Option 3: Refresh terminal list from server, then show custom UI
178
+ task.refresh((error, list) => {
179
+ if (error) {
180
+ console.error('>>> Refresh error: ' + JSON.stringify(error));
181
+ } else {
182
+ console.log('>>> Terminals refreshed: ' + list.length);
183
+ }
184
+ });
185
+ },
186
+ onError: (error) => {
187
+ console.error('>>> Init error: ' + JSON.stringify(error));
188
+ },
189
+ });
190
+ ```
191
+
192
+ **3.3: Enable Remote Channel (Optional)**
193
+
194
+ Open after successful initialization to accept transactions from a remote source (e.g. POS terminal on the same local network):
195
+
196
+ ```ts
197
+ // Open local network channel on port 8080 with 30s timeout
198
+ EdfaPayPlugin.RemoteChannel.LocalNetwork({ port: 8080, timeout: 30 }).open();
199
+ ```
200
+
201
+ Send a transaction request from a remote source:
202
+ ```shell
203
+ echo '{"id":"pay.1","data":{"fun":"purchase","flowType":"DETAIL","amount":"12.0"}}' | nc 192.168.1.100 8080
204
+ ```
205
+
206
+ ### 4: Purchase
207
+
208
+ **FlowType options:**
209
+ - `FlowType.IMMEDIATE` — closes card scan UI immediately after server response
210
+ - `FlowType.STATUS` — closes at status animation (check/cross)
211
+ - `FlowType.DETAIL` — flows to transaction detail screen, completes on screen close
212
+
213
+ > **Note:** Observe the 4th `isFlowComplete` parameter of `onPaymentProcessComplete`.
214
+
215
+ ```ts
216
+ const params = new TxnParams('01.010', '12340987');
217
+
218
+ EdfaPayPlugin.purchase({
219
+ txnParams: params,
220
+ flowType: FlowType.DETAIL,
221
+ onPaymentProcessComplete: (status, code, transaction, isFlowComplete) => {
222
+ if (status) {
223
+ console.log('>>> Success: ' + JSON.stringify(transaction));
224
+ } else {
225
+ console.log('>>> Failed: ' + JSON.stringify(transaction));
226
+ }
227
+ },
228
+ onRequestTimerEnd: () => {
229
+ console.log('>>> Server Timeout');
230
+ },
231
+ onCardScanTimerEnd: () => {
232
+ console.log('>>> Scan Card Timeout');
233
+ },
234
+ onCancelByUser: () => {
235
+ console.log('>>> Canceled By User');
236
+ },
237
+ onError: (error) => {
238
+ console.error('>>> Error: ' + JSON.stringify(error));
239
+ },
240
+ });
241
+ ```
242
+
243
+ ### 5: Refund
244
+
245
+ ```ts
246
+ const params = new TxnParams(
247
+ '01.010',
248
+ '',
249
+ Transaction.withRRN('123456789012', '', TransactionType.PURCHASE)
250
+ );
251
+
252
+ EdfaPayPlugin.refund({
253
+ txnParams: params,
254
+ onPaymentProcessComplete: (status, code, transaction, isFlowComplete) => {
255
+ console.log('>>> Refund ' + (status ? 'Success' : 'Failed'));
256
+ },
257
+ onRequestTimerEnd: () => { console.log('>>> Server Timeout'); },
258
+ onCardScanTimerEnd: () => { console.log('>>> Scan Card Timeout'); },
259
+ onCancelByUser: () => { console.log('>>> Canceled By User'); },
260
+ onError: (error) => { console.error('>>> Error: ' + JSON.stringify(error)); },
261
+ });
262
+ ```
263
+
264
+ ### 6: Reverse Last Transaction
265
+
266
+ ```ts
267
+ EdfaPayPlugin.reverseLastTransaction({
268
+ onSuccess: (response) => {
269
+ console.log('>>> Reverse Success: ' + JSON.stringify(response));
270
+ },
271
+ onError: (error) => {
272
+ console.error('>>> Reverse Error: ' + JSON.stringify(error));
273
+ },
274
+ });
275
+ ```
15
276
 
16
- ```js
17
- import { multiply } from 'edfapay-softpos-sdk-rn';
277
+ ### 7: Reconciliation
18
278
 
19
- // ...
279
+ ```ts
280
+ EdfaPayPlugin.reconcile({
281
+ onSuccess: (response) => {
282
+ console.log('>>> Reconciliation Success: ' + JSON.stringify(response));
283
+ },
284
+ onError: (error) => {
285
+ console.error('>>> Reconciliation Error: ' + JSON.stringify(error));
286
+ },
287
+ });
288
+ ```
289
+
290
+ ### 8: Transaction History
20
291
 
21
- const result = multiply(3, 7);
292
+ ```ts
293
+ EdfaPayPlugin.txnHistory({
294
+ onSuccess: (response) => {
295
+ console.log('>>> Txn History: ' + JSON.stringify(response));
296
+ },
297
+ onError: (error) => {
298
+ console.error('>>> Txn History Error: ' + JSON.stringify(error));
299
+ },
300
+ });
22
301
  ```
23
302
 
24
303
 
25
- ## Contributing
304
+ # Example
305
+
306
+ Full working example — copy and paste into your `App.tsx`:
307
+
308
+ ```tsx
309
+ import * as React from 'react';
310
+ import { View, Button } from 'react-native';
311
+ import {
312
+ EdfaPayPlugin,
313
+ EdfaPayCredentials,
314
+ Env,
315
+ TxnParams,
316
+ Transaction,
317
+ TransactionType,
318
+ } from 'edfapay-softpos-sdk-rn';
319
+
320
+ const TERMINAL_TOKEN = '****Your Terminal Token****';
321
+ const amountToPay = '01.010';
322
+
323
+ export default function App() {
324
+ const [initialized, setInitialized] = React.useState(false);
325
+
326
+ return (
327
+ <View style={{ flex: 1, justifyContent: 'flex-end', padding: 20, gap: 12 }}>
328
+ {!initialized && (
329
+ <Button
330
+ color="#06E59F"
331
+ title="Initialize"
332
+ onPress={() => initiateSdk(setInitialized)}
333
+ />
334
+ )}
335
+ {initialized && (
336
+ <>
337
+ <Button color="#06E59F" title={'Purchase ' + amountToPay} onPress={purchase} />
338
+ <Button color="#FF9800" title={'Refund ' + amountToPay} onPress={refund} />
339
+ <Button color="#F44336" title="Reverse Last Transaction" onPress={reverse} />
340
+ <Button color="#2196F3" title="Reconciliation" onPress={reconcile} />
341
+ <Button color="#9C27B0" title="Txn History" onPress={txnHistory} />
342
+ </>
343
+ )}
344
+ </View>
345
+ );
346
+ }
347
+
348
+ function initiateSdk(onInitialized: (status: boolean) => void) {
349
+ EdfaPayPlugin.enableLogs(true);
350
+ EdfaPayPlugin.setAnimationSpeedX(2.5);
26
351
 
27
- - [Development workflow](CONTRIBUTING.md#development-workflow)
28
- - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
29
- - [Code of conduct](CODE_OF_CONDUCT.md)
352
+ const credentials = EdfaPayCredentials.withToken(Env.DEVELOPMENT, TERMINAL_TOKEN);
353
+
354
+ EdfaPayPlugin.initiate({
355
+ credentials,
356
+ onSuccess: (sessionId) => {
357
+ onInitialized(true);
358
+ console.log('>>> SDK Initialized — Session ID: ' + sessionId);
359
+ },
360
+ onTerminalBindingTask: (task) => {
361
+ console.log('>>> Terminal Binding Required');
362
+ // Option 1: Show SDK's built-in terminal selection UI
363
+ task.bind();
364
+ // Option 2: Bind first terminal programmatically
365
+ // task.terminals[0]?.bind();
366
+ },
367
+ onError: (error) => {
368
+ onInitialized(false);
369
+ console.error('>>> Init Error: ' + JSON.stringify(error));
370
+ },
371
+ });
372
+ }
373
+
374
+ function purchase() {
375
+ EdfaPayPlugin.purchase({
376
+ txnParams: new TxnParams(amountToPay),
377
+ onPaymentProcessComplete: (status, code, transaction, isFlowComplete) => {
378
+ console.log('>>> Purchase ' + (status ? 'Success' : 'Failed') + ' | Code: ' + code);
379
+ console.log('>>> Transaction: ' + JSON.stringify(transaction));
380
+ },
381
+ onRequestTimerEnd: () => { console.log('>>> Server Timeout'); },
382
+ onCardScanTimerEnd: () => { console.log('>>> Scan Card Timeout'); },
383
+ onCancelByUser: () => { console.log('>>> Canceled By User'); },
384
+ onError: (error) => { console.error('>>> Error: ' + JSON.stringify(error)); },
385
+ });
386
+ }
387
+
388
+ function refund() {
389
+ const params = new TxnParams(
390
+ amountToPay,
391
+ '',
392
+ Transaction.withRRN('123456789012', '', TransactionType.PURCHASE)
393
+ );
394
+ EdfaPayPlugin.refund({
395
+ txnParams: params,
396
+ onPaymentProcessComplete: (status, code, transaction, isFlowComplete) => {
397
+ console.log('>>> Refund ' + (status ? 'Success' : 'Failed') + ' | Code: ' + code);
398
+ },
399
+ onRequestTimerEnd: () => { console.log('>>> Server Timeout'); },
400
+ onCardScanTimerEnd: () => { console.log('>>> Scan Card Timeout'); },
401
+ onCancelByUser: () => { console.log('>>> Canceled By User'); },
402
+ onError: (error) => { console.error('>>> Error: ' + JSON.stringify(error)); },
403
+ });
404
+ }
405
+
406
+ function reverse() {
407
+ EdfaPayPlugin.reverseLastTransaction({
408
+ onSuccess: (response) => {
409
+ console.log('>>> Reverse Success: ' + JSON.stringify(response));
410
+ },
411
+ onError: (error) => {
412
+ console.error('>>> Reverse Error: ' + JSON.stringify(error));
413
+ },
414
+ });
415
+ }
416
+
417
+ function reconcile() {
418
+ EdfaPayPlugin.reconcile({
419
+ onSuccess: (response) => {
420
+ console.log('>>> Reconciliation Success: ' + JSON.stringify(response));
421
+ },
422
+ onError: (error) => {
423
+ console.error('>>> Reconciliation Error: ' + JSON.stringify(error));
424
+ },
425
+ });
426
+ }
427
+
428
+ function txnHistory() {
429
+ EdfaPayPlugin.txnHistory({
430
+ onSuccess: (response) => {
431
+ console.log('>>> Txn History: ' + JSON.stringify(response));
432
+ },
433
+ onError: (error) => {
434
+ console.error('>>> Txn History Error: ' + JSON.stringify(error));
435
+ },
436
+ });
437
+ }
438
+ ```
30
439
 
31
440
  ## License
32
441
 
33
442
  MIT
34
443
 
35
444
  ---
36
-
37
- Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edfapay-softpos-sdk-rn",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Edfapay SoftPOS SDK helps developer to easily integrate Edfapay SoftPOS to their mobile application",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",