xcel-paygate-sdk 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 +378 -116
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,141 +1,352 @@
1
- # XCEL PayGate SDK
1
+ # XCEL PayGate SDK for React Native
2
2
 
3
- Official React Native SDK for XCEL PayGate payment integration. Accept mobile money and card payments in your React Native apps with just a few lines of code.
3
+ Accept mobile money and card payments in your React Native app with just a few lines of code.
4
4
 
5
- [![npm version](https://badge.fury.io/js/@xcelapp%2Fpaygate-sdk.svg)](https://www.npmjs.com/package/@xcelapp/paygate-sdk)
5
+ [![npm version](https://badge.fury.io/js/xcel-paygate-sdk.svg)](https://www.npmjs.com/package/xcel-paygate-sdk)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
 
8
- ## Features
8
+ ## Why Choose XCEL PayGate?
9
9
 
10
- ✅ **Easy Integration** - Get started in 5 minutes with drop-in UI components
11
- **Multiple Payment Methods** - Mobile Money, Cards, and more
12
- **TypeScript Support** - Full type safety out of the box
13
- **Customizable UI** - Pre-built components that match your brand
14
- **Zero Native Code** - Pure JavaScript/TypeScript SDK
15
- **Production Ready** - Built-in error handling and loading states
16
-
17
- ## Supported Countries
18
-
19
- 🇨🇲 Cameroon | 🇬🇭 Ghana | 🇰🇪 Kenya | 🇳🇬 Nigeria | And more across Africa
10
+ - ✅ **5-Minute Setup** - Start accepting payments in minutes, not days
11
+ - 💰 **Multiple Payment Methods** - Mobile Money, Cards, Bank Transfers
12
+ - 🌍 **Pan-African Coverage** - Cameroon, Ghana, Kenya, Nigeria, and more
13
+ - 🔒 **Secure & Reliable** - Bank-grade security built-in
14
+ - 📱 **Zero Native Code** - Pure JavaScript/TypeScript, works with Expo
15
+ - 🎨 **Pre-Built UI** - Beautiful payment forms ready to use
20
16
 
21
17
  ## Installation
22
18
 
23
19
  ```bash
24
- npm install @xcelapp/paygate-sdk react-native-webview
20
+ npm install xcel-paygate-sdk react-native-webview
25
21
  ```
26
22
 
27
- or with yarn:
23
+ That's it! No native code linking required.
28
24
 
29
- ```bash
30
- yarn add @xcelapp/paygate-sdk react-native-webview
31
- ```
25
+ ## Getting Your API Keys
26
+
27
+ Before you start, you'll need API credentials:
32
28
 
33
- ## Quick Start
29
+ 1. Go to [XCEL Business Dashboard](https://business.xcelapp.com/)
30
+ 2. Sign up for a free account
31
+ 3. Copy your **Merchant ID** and **Public Key**
34
32
 
35
- ### Option 1: All-in-One Component (Easiest)
33
+ Keep these safe - you'll need them in the next step!
36
34
 
37
- The quickest way to get started. This component handles everything:
35
+ ## Quick Start - Copy & Paste Ready
36
+
37
+ ### Step 1: Create Your Environment File
38
+
39
+ Create a `.env` file in your project root:
40
+
41
+ ```env
42
+ EXPO_PUBLIC_XCEL_MERCHANT_ID=your_merchant_id_here
43
+ EXPO_PUBLIC_XCEL_PUBLIC_KEY=your_public_key_here
44
+ ```
45
+
46
+ ### Step 2: Add the Payment Component
47
+
48
+ Copy this code into your payment screen:
38
49
 
39
50
  ```tsx
40
- import { XcelPaymentFlow } from '@xcelapp/paygate-sdk';
51
+ import { XcelPaymentFlow } from 'xcel-paygate-sdk';
52
+ import { View } from 'react-native';
41
53
 
42
54
  export default function PaymentScreen() {
43
55
  return (
44
- <XcelPaymentFlow
45
- config={{
46
- merchantId: 'YOUR_MERCHANT_ID',
47
- publicKey: 'YOUR_PUBLIC_KEY',
48
- }}
49
- onPaymentComplete={(result) => {
50
- if (result.status === 'SUCCESS') {
51
- console.log('Payment successful!', result);
52
- } else {
53
- console.log('Payment failed', result);
54
- }
55
- }}
56
- />
56
+ <View style={{ flex: 1 }}>
57
+ <XcelPaymentFlow
58
+ config={{
59
+ merchantId: process.env.EXPO_PUBLIC_XCEL_MERCHANT_ID,
60
+ publicKey: process.env.EXPO_PUBLIC_XCEL_PUBLIC_KEY,
61
+ }}
62
+ onPaymentComplete={(result) => {
63
+ if (result.status === 'SUCCESS') {
64
+ alert('Payment successful! 🎉');
65
+ // Navigate to success screen
66
+ } else {
67
+ alert('Payment failed. Please try again.');
68
+ }
69
+ }}
70
+ />
71
+ </View>
57
72
  );
58
73
  }
59
74
  ```
60
75
 
61
- ### Option 2: Individual Components (More Control)
76
+ That's it! You now have a fully functional payment screen.
77
+
78
+ ## What You Get Out of the Box
79
+
80
+ When you use `XcelPaymentFlow`, you automatically get:
81
+
82
+ - ✅ A complete payment form with validation
83
+ - ✅ Automatic payment link generation
84
+ - ✅ Secure payment webview
85
+ - ✅ Real-time payment status checking
86
+ - ✅ Success/failure handling
87
+ - ✅ Loading states and error messages
88
+
89
+ ## How It Works
90
+
91
+ ```
92
+ 1. Customer fills payment form
93
+
94
+ 2. SDK generates secure payment link
95
+
96
+ 3. Customer completes payment
97
+
98
+ 4. SDK checks payment status
99
+
100
+ 5. Your app gets success/failure callback
101
+ ```
102
+
103
+ ## Customizing the Payment Amount
62
104
 
63
- For more control over the payment flow:
105
+ ### Pre-fill the Amount
64
106
 
65
107
  ```tsx
66
- import { XcelPaymentScreen } from '@xcelapp/paygate-sdk';
67
- import { useRouter } from 'expo-router';
108
+ <XcelPaymentFlow
109
+ config={config}
110
+ screenProps={{
111
+ defaultValues: {
112
+ amount: '5000', // Pre-fill amount
113
+ description: 'Order #123',
114
+ },
115
+ }}
116
+ onPaymentComplete={(result) => {
117
+ console.log('Payment complete!', result);
118
+ }}
119
+ />
120
+ ```
68
121
 
69
- export default function PaymentScreen() {
70
- const router = useRouter();
122
+ ### Make Amount Read-Only
123
+
124
+ ```tsx
125
+ <XcelPaymentFlow
126
+ config={config}
127
+ screenProps={{
128
+ defaultValues: { amount: '5000' },
129
+ readOnly: {
130
+ amount: true, // User cannot change amount
131
+ },
132
+ }}
133
+ onPaymentComplete={(result) => {
134
+ console.log('Payment complete!', result);
135
+ }}
136
+ />
137
+ ```
138
+
139
+ ## Checking Payment Status
140
+
141
+ ### Automatic Status Checking (Recommended)
142
+
143
+ The SDK automatically checks payment status for you:
144
+
145
+ ```tsx
146
+ import { usePaymentPolling } from 'xcel-paygate-sdk';
147
+
148
+ function PaymentTracker({ paymentCode }) {
149
+ const { result, isPolling } = usePaymentPolling(
150
+ {
151
+ merchantId: process.env.EXPO_PUBLIC_XCEL_MERCHANT_ID,
152
+ publicKey: process.env.EXPO_PUBLIC_XCEL_PUBLIC_KEY,
153
+ },
154
+ paymentCode,
155
+ {
156
+ enabled: true,
157
+ onSuccess: (result) => {
158
+ alert('Payment successful! 🎉');
159
+ },
160
+ onFailure: (result) => {
161
+ alert('Payment failed ❌');
162
+ },
163
+ }
164
+ );
165
+
166
+ if (isPolling) {
167
+ return <Text>Checking payment status...</Text>;
168
+ }
169
+
170
+ return <Text>Status: {result?.transaction.status}</Text>;
171
+ }
172
+ ```
173
+
174
+ ### Manual Status Check
175
+
176
+ ```tsx
177
+ import { useCheckout } from 'xcel-paygate-sdk';
178
+
179
+ function MyComponent() {
180
+ const { checkStatus } = useCheckout(config);
181
+
182
+ const handleCheckPayment = async (paymentCode) => {
183
+ const result = await checkStatus(paymentCode);
184
+
185
+ if (result.transaction.paid) {
186
+ alert('Payment successful!');
187
+ }
188
+ };
71
189
 
72
190
  return (
73
- <XcelPaymentScreen
74
- config={{
75
- merchantId: 'YOUR_MERCHANT_ID',
76
- publicKey: 'YOUR_PUBLIC_KEY',
77
- }}
78
- onPaymentLinkGenerated={(paymentLink, paymentCode) => {
79
- router.push({
80
- pathname: '/payment-webview',
81
- params: { paymentLink, paymentCode },
82
- });
83
- }}
84
- defaultValues={{
85
- amount: '1000',
86
- email: 'customer@example.com',
87
- }}
191
+ <Button
192
+ title="Check Payment Status"
193
+ onPress={() => handleCheckPayment('PMT123456')}
88
194
  />
89
195
  );
90
196
  }
91
197
  ```
92
198
 
93
- ### Option 3: Hooks Only (Maximum Control)
199
+ ## Working with Products (Electricity, Water Bills, etc.)
94
200
 
95
- Use just the hooks for complete control over UI:
201
+ Some merchants offer specific products like electricity tokens or water bills.
202
+
203
+ ### Fetch Available Products
96
204
 
97
205
  ```tsx
98
- import { useCheckout } from '@xcelapp/paygate-sdk';
206
+ import { XcelPayGateClient } from 'xcel-paygate-sdk';
207
+ import { useEffect, useState } from 'react';
99
208
 
100
- export default function PaymentScreen() {
101
- const { initiatePayment, loading } = useCheckout({
102
- merchantId: 'YOUR_MERCHANT_ID',
103
- publicKey: 'YOUR_PUBLIC_KEY',
104
- });
209
+ function ElectricityPayment() {
210
+ const [products, setProducts] = useState([]);
211
+
212
+ useEffect(() => {
213
+ const client = new XcelPayGateClient({
214
+ merchantId: process.env.EXPO_PUBLIC_XCEL_MERCHANT_ID,
215
+ publicKey: process.env.EXPO_PUBLIC_XCEL_PUBLIC_KEY,
216
+ });
217
+
218
+ // Fetch available products
219
+ client.getMerchantProducts()
220
+ .then(response => setProducts(response.data.data))
221
+ .catch(error => console.error(error));
222
+ }, []);
223
+
224
+ return (
225
+ <View>
226
+ {products.map(product => (
227
+ <Text key={product.product_id}>{product.name}</Text>
228
+ ))}
229
+ </View>
230
+ );
231
+ }
232
+ ```
233
+
234
+ ### Pay with a Specific Product
235
+
236
+ ```tsx
237
+ import { useCheckout } from 'xcel-paygate-sdk';
238
+
239
+ function PayElectricityBill() {
240
+ const { initiatePayment } = useCheckout(config);
105
241
 
106
242
  const handlePay = async () => {
107
- const result = await initiatePayment({
108
- amount: '1000',
243
+ await initiatePayment({
244
+ amount: '5000',
109
245
  currency: 'XAF',
246
+ products: [
247
+ {
248
+ product_id: 'your_product_id', // From getMerchantProducts()
249
+ amount: '5000',
250
+ },
251
+ ],
110
252
  customer_email: 'customer@example.com',
253
+ customer_phone: '237123456789',
254
+ description: 'Electricity bill payment',
111
255
  channel: 'WEB',
112
- redirect_url: 'https://yourapp.com/callback',
113
256
  });
114
-
115
- console.log('Payment link:', result.data.payment_link);
116
257
  };
117
258
 
259
+ return <Button title="Pay Electricity Bill" onPress={handlePay} />;
260
+ }
261
+ ```
262
+
263
+ ## Advanced: Using Individual Components
264
+
265
+ For complete control over the UI:
266
+
267
+ ### Payment Form Only
268
+
269
+ ```tsx
270
+ import { XcelPaymentScreen } from 'xcel-paygate-sdk';
271
+
272
+ function CustomPayment() {
273
+ return (
274
+ <XcelPaymentScreen
275
+ config={config}
276
+ onPaymentLinkGenerated={(paymentLink, paymentCode) => {
277
+ // You handle what to do with the payment link
278
+ console.log('Payment link:', paymentLink);
279
+ // Maybe navigate to your custom webview
280
+ }}
281
+ defaultValues={{
282
+ amount: '1000',
283
+ email: 'customer@example.com',
284
+ }}
285
+ />
286
+ );
287
+ }
288
+ ```
289
+
290
+ ### Payment WebView Only
291
+
292
+ ```tsx
293
+ import { XcelPaymentWebView } from 'xcel-paygate-sdk';
294
+
295
+ function PaymentWebViewScreen({ route }) {
296
+ const { paymentLink, paymentCode } = route.params;
297
+
118
298
  return (
119
- <Button title="Pay Now" onPress={handlePay} disabled={loading} />
299
+ <XcelPaymentWebView
300
+ paymentLink={paymentLink}
301
+ paymentCode={paymentCode}
302
+ config={config}
303
+ onSuccess={(result) => {
304
+ alert('Payment successful!');
305
+ }}
306
+ onFailure={(error) => {
307
+ alert('Payment failed');
308
+ }}
309
+ />
120
310
  );
121
311
  }
122
312
  ```
123
313
 
124
- ## Get Your API Credentials
314
+ ## Getting Payment Receipts
125
315
 
126
- 1. Visit [XCEL Business Dashboard](https://business.xcelapp.com/)
127
- 2. Sign up or log in
128
- 3. Get your **Merchant ID** and **Public Key** from the dashboard
316
+ After a successful payment, get detailed receipt information:
129
317
 
130
- ## Configuration
318
+ ```tsx
319
+ import { usePaymentCompletion } from 'xcel-paygate-sdk';
131
320
 
132
- ### Using Provider Pattern (Recommended for multiple screens)
321
+ function ReceiptScreen({ paymentCode }) {
322
+ const { receipt, loading } = usePaymentCompletion(config, paymentCode);
133
323
 
134
- Wrap your app with the provider to share config across all screens:
324
+ if (loading) {
325
+ return <Text>Loading receipt...</Text>;
326
+ }
327
+
328
+ return (
329
+ <View>
330
+ <Text>Receipt ID: {receipt.receiptId}</Text>
331
+ <Text>Amount: {receipt.amount} {receipt.currency}</Text>
332
+ <Text>Status: {receipt.status}</Text>
333
+ <Text>Payment Method: {receipt.paymentMethod}</Text>
334
+ <Text>Date: {new Date(receipt.timestamp).toLocaleString()}</Text>
335
+ <Text>Reference: {receipt.transactionId}</Text>
336
+ </View>
337
+ );
338
+ }
339
+ ```
340
+
341
+ ## Using with Provider Pattern (For Multiple Screens)
342
+
343
+ If you have multiple payment screens, use the Provider to avoid repeating config:
344
+
345
+ ### Step 1: Wrap Your App
135
346
 
136
347
  ```tsx
137
348
  // app/_layout.tsx
138
- import { XcelPayGateProvider } from '@xcelapp/paygate-sdk';
349
+ import { XcelPayGateProvider } from 'xcel-paygate-sdk';
139
350
 
140
351
  export default function RootLayout() {
141
352
  return (
@@ -145,44 +356,80 @@ export default function RootLayout() {
145
356
  publicKey: process.env.EXPO_PUBLIC_XCEL_PUBLIC_KEY,
146
357
  }}
147
358
  >
148
- {/* Your app */}
359
+ {/* Your app screens */}
149
360
  </XcelPayGateProvider>
150
361
  );
151
362
  }
363
+ ```
364
+
365
+ ### Step 2: Use Without Config
152
366
 
367
+ ```tsx
153
368
  // app/payment.tsx
154
- // No config needed - components use Provider context automatically!
155
- import { XcelPaymentScreen } from '@xcelapp/paygate-sdk';
369
+ import { XcelPaymentFlow } from 'xcel-paygate-sdk';
156
370
 
157
371
  export default function Payment() {
158
- return <XcelPaymentScreen />;
372
+ // No need to pass config - it uses Provider!
373
+ return (
374
+ <XcelPaymentFlow
375
+ onPaymentComplete={(result) => {
376
+ console.log('Done!', result);
377
+ }}
378
+ />
379
+ );
159
380
  }
160
381
  ```
161
382
 
162
- ### Environment Variables
383
+ ## Webhooks (For Production Apps)
163
384
 
164
- Create a `.env` file:
385
+ For real-time payment notifications, set up webhooks on your server:
165
386
 
166
- ```env
167
- EXPO_PUBLIC_XCEL_MERCHANT_ID=your_merchant_id
168
- EXPO_PUBLIC_XCEL_PUBLIC_KEY=your_public_key
387
+ ```typescript
388
+ // Your server (Node.js/Express example)
389
+ app.post('/webhook', (req, res) => {
390
+ const { transaction_id, status, amount } = req.body;
391
+
392
+ if (status === 'SUCCESS') {
393
+ // Update your database
394
+ // Send confirmation email
395
+ // Fulfill the order
396
+ }
397
+
398
+ res.status(200).send('OK');
399
+ });
169
400
  ```
170
401
 
171
- ## Documentation
402
+ Then configure webhook URL when making payments:
172
403
 
173
- - 📖 [Complete API Reference](./INTEGRATION_REFERENCE.md) - All endpoints and types
174
- - 🎨 [Component Usage Guide](./COMPONENT_USAGE.md) - UI components documentation
175
- - 🚀 [Quick Start Examples](./COMPONENT_USAGE.md#complete-examples)
404
+ ```tsx
405
+ await initiatePayment({
406
+ amount: '1000',
407
+ currency: 'XAF',
408
+ // ... other fields
409
+ webhook_url: 'https://your-server.com/webhook',
410
+ redirect_url: 'https://your-app.com/success',
411
+ });
412
+ ```
176
413
 
177
- ## Requirements
414
+ ## Supported Countries & Currencies
178
415
 
179
- - React Native >= 0.60.0
180
- - React >= 16.8.0
181
- - react-native-webview (for UI components)
416
+ | Country | Currency | Code |
417
+ |------------|----------|------|
418
+ | Cameroon | XAF | CMR |
419
+ | Ghana | GHS | GHA |
420
+ | Kenya | KES | KEN |
421
+ | Nigeria | NGN | NGA |
422
+
423
+ ## Payment Methods Available
424
+
425
+ - 📱 Mobile Money (MTN, Orange, Moov, Airtel, etc.)
426
+ - 💳 Visa & Mastercard
427
+ - 🏦 Bank Transfers
428
+ - 💰 XCEL Wallet
182
429
 
183
430
  ## TypeScript Support
184
431
 
185
- The SDK is written in TypeScript and includes full type definitions:
432
+ Full TypeScript support included:
186
433
 
187
434
  ```tsx
188
435
  import type {
@@ -190,36 +437,51 @@ import type {
190
437
  TransactionData,
191
438
  PaymentRequest,
192
439
  PaymentResult,
193
- } from '@xcelapp/paygate-sdk';
440
+ PaymentStatus,
441
+ } from 'xcel-paygate-sdk';
442
+
443
+ const config: XcelPayGateConfig = {
444
+ merchantId: 'YOUR_MERCHANT_ID',
445
+ publicKey: 'YOUR_PUBLIC_KEY',
446
+ };
194
447
  ```
195
448
 
196
- ## Supported Payment Methods
449
+ ## Requirements
197
450
 
198
- - 📱 Mobile Money (MTN, Orange, Moov, etc.)
199
- - 💳 Card Payments (Visa, Mastercard)
200
- - 🏦 Bank Transfers
201
- - 💰 XCEL Wallet
451
+ - React Native >= 0.60.0
452
+ - React >= 16.8.0
453
+ - `react-native-webview` (auto-installed)
454
+
455
+ ## Troubleshooting
456
+
457
+ ### Payment not completing?
458
+
459
+ Make sure you're checking the payment status. Payments can take a few seconds to process.
460
+
461
+ ### Can't see the payment form?
462
+
463
+ Check that you've installed `react-native-webview`:
464
+
465
+ ```bash
466
+ npm install react-native-webview
467
+ ```
468
+
469
+ ### Environment variables not working?
470
+
471
+ Make sure your `.env` file is in the project root and variables start with `EXPO_PUBLIC_`.
202
472
 
203
473
  ## Support
204
474
 
475
+ Need help? We're here for you:
476
+
205
477
  - 📧 Email: support@xcelapp.com
206
- - 🐛 Issues: [GitHub Issues](https://github.com/xcelapp/xcel-paygate-sdk/issues)
207
- - 📚 Docs: [GitHub Repository](https://github.com/xcelapp/xcel-paygate-sdk)
478
+ - 📚 Documentation: [GitHub](https://github.com/etranzact-global-reloaded/xcel-paygate-sdk-react-native)
479
+ - 🐛 Report Issues: [GitHub Issues](https://github.com/etranzact-global-reloaded/xcel-paygate-sdk-react-native/issues)
208
480
 
209
481
  ## License
210
482
 
211
483
  MIT © XCEL
212
484
 
213
- ## Changelog
214
-
215
- ### 1.0.0 (2025-01-13)
216
-
217
- - Initial release
218
- - Drop-in UI components
219
- - TypeScript support
220
- - Provider pattern
221
- - Comprehensive documentation
222
-
223
485
  ---
224
486
 
225
- **Made with ❤️ by XCEL**
487
+ **Made with ❤️ @ eTranzact Global**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcel-paygate-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Official React Native SDK for XCEL PayGate payment integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "license": "MIT",
32
32
  "repository": {
33
33
  "type": "git",
34
- "url": "https://github.com/etranzact-global-reloaded/xcel-paygate-sdk-react-native"
34
+ "url": "git+https://github.com/etranzact-global-reloaded/xcel-paygate-sdk-react-native.git"
35
35
  },
36
36
  "homepage": "https://github.com/etranzact-global-reloaded/xcel-paygate-sdk-react-native#readme",
37
37
  "bugs": {