@payloqa/payment-widget 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 +171 -339
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,198 +1,207 @@
1
1
  # ๐Ÿ’ณ Payloqa Payment Widget
2
2
 
3
- A secure React payment processing widget for handling transactions with multiple payment methods.
3
+ A React payment widget for processing mobile money payments. Easily integrate secure payment processing into your React applications.
4
4
 
5
5
  ## โœจ Features
6
6
 
7
- - ๐Ÿ’ณ **Multiple Payment Methods** - Credit cards, mobile money, bank transfers
8
- - ๐Ÿ”’ **Secure Processing** - PCI-compliant payment handling
9
- - ๐Ÿ“ฑ **Responsive Design** - Works on desktop, tablet, and mobile
10
- - ๐ŸŽจ **Customizable UI** - Easy to style and brand
11
- - ๐Ÿ“Š **Real-time Validation** - Instant payment method validation
12
- - ๐Ÿ”„ **Transaction Status** - Real-time payment status updates
13
- - ๐Ÿงช **HTML Testing** - Comprehensive test interface
14
- - ๐Ÿ“ฆ **Multiple Builds** - UMD, ESM, and TypeScript declarations
7
+ - ๐Ÿ“ฑ Mobile money payment processing (MTN, Telecel, AirtelTigo)
8
+ - ๐Ÿ” OTP verification for secure transactions
9
+ - ๐Ÿ“ฑ Fully responsive design
10
+ - ๐ŸŽจ Customizable branding with primary color
11
+ - โšก Easy integration with React
12
+ - ๐Ÿ”„ Real-time payment status updates
13
+ - โฑ๏ธ Automatic timeout handling
15
14
 
16
- ## ๐Ÿš€ Quick Start
15
+ ## ๐Ÿš€ Getting Started
17
16
 
18
- ### Installation
17
+ ### 1. Get Your API Credentials
18
+
19
+ Visit [https://developer.payloqa.com/](https://developer.payloqa.com/) to:
20
+
21
+ - Login with your phone number (simple phone number authentication)
22
+ - Go to the **API Keys** page
23
+ - Create your **API Key** and get your **Platform ID**
24
+ - Request payment access by filling out the KYC form
25
+ - Once approved, you'll be notified and can start processing payments
26
+
27
+ ### 2. Install the Package
19
28
 
20
29
  ```bash
21
30
  npm install @payloqa/payment-widget
22
31
  ```
23
32
 
24
- ### Basic Usage
33
+ ### 3. Import and Use
25
34
 
26
35
  ```jsx
27
- import { PaymentWidget } from '@payloqa/payment-widget';
36
+ import { PaymentWidget } from "@payloqa/payment-widget";
37
+ import "@payloqa/payment-widget/dist/payment-widget.css";
28
38
 
29
39
  function App() {
40
+ const [isOpen, setIsOpen] = useState(false);
41
+
30
42
  const config = {
31
- apiKey: 'your-api-key',
32
- platformId: 'your-platform-id',
33
- apiUrl: 'https://api.payloqa.com/v1/payments'
43
+ apiKey: "your-api-key",
44
+ platformId: "your-platform-id",
45
+ amount: 10.00,
46
+ currency: "GHS", // Optional, defaults to "GHS"
47
+ primaryColor: "#3B82F6", // Optional, your brand color
48
+ displayMode: "modal", // "modal" | "inline" | "fullpage"
49
+ redirect_url: "https://yoursite.com/callback", // Required
50
+ webhookUrl: "https://yoursite.com/webhook", // Required
51
+ orderId: "order-123", // Optional
52
+ metadata: { // Optional
53
+ customField: "value",
54
+ },
34
55
  };
35
56
 
36
- const handleSuccess = (transaction) => {
37
- console.log('Payment successful:', transaction);
38
- console.log('Transaction ID:', transaction.id);
39
- console.log('Amount:', transaction.amount);
57
+ const handleSuccess = (payment) => {
58
+ console.log("Payment successful!", payment);
59
+ console.log("Payment ID:", payment.payment_id);
60
+ console.log("Status:", payment.status);
61
+ console.log("Amount:", payment.amount);
40
62
  };
41
63
 
42
64
  const handleError = (error) => {
43
- console.error('Payment failed:', error);
44
- };
45
-
46
- const handleStatusChange = (status) => {
47
- console.log('Payment status:', status);
65
+ console.error("Payment failed:", error.message);
66
+ alert(`Error: ${error.message}`);
48
67
  };
49
68
 
50
69
  return (
51
- <PaymentWidget
52
- config={config}
53
- amount={1000} // Amount in cents
54
- currency="USD"
55
- onSuccess={handleSuccess}
56
- onError={handleError}
57
- onStatusChange={handleStatusChange}
58
- />
70
+ <div>
71
+ <button onClick={() => setIsOpen(true)}>Pay Now</button>
72
+
73
+ <PaymentWidget
74
+ config={config}
75
+ isOpen={isOpen}
76
+ onClose={() => setIsOpen(false)}
77
+ onSuccess={handleSuccess}
78
+ onError={handleError}
79
+ />
80
+ </div>
59
81
  );
60
82
  }
61
83
  ```
62
84
 
63
85
  ## โš™๏ธ Configuration
64
86
 
65
- ### PaymentWidgetConfig
87
+ ### Required Configuration
66
88
 
67
89
  ```typescript
68
90
  interface PaymentWidgetConfig {
69
- apiKey: string; // Your Payloqa API key
70
- platformId: string; // Your platform identifier
71
- apiUrl: string; // Payloqa payments API URL
91
+ apiKey: string; // Your Payloqa API key
92
+ platformId: string; // Your platform ID
93
+ amount: number; // Payment amount (e.g., 10.00)
94
+ currency?: string; // Currency code (default: "GHS")
95
+ displayMode?: string; // "modal" | "inline" | "fullpage" (default: "modal")
96
+ primaryColor?: string; // Your brand color in hex (e.g., "#3B82F6")
97
+ logoUrl?: string; // Optional logo URL to display in header
98
+ redirect_url: string; // Required: HTTPS URL for redirect after payment
99
+ webhookUrl: string; // Required: Webhook URL for server notifications
100
+ orderId?: string; // Optional order identifier
101
+ metadata?: object; // Optional metadata object
102
+ onSuccess?: (payment: PaymentData) => void;
103
+ onError?: (error: PaymentError) => void;
104
+ }
105
+ ```
106
+
107
+ ### PaymentWidget Props
108
+
109
+ ```typescript
110
+ interface PaymentWidgetProps {
111
+ config: PaymentWidgetConfig;
112
+ isOpen: boolean; // Controls widget visibility
113
+ onClose?: () => void; // Called when widget is closed
72
114
  }
73
115
  ```
74
116
 
75
117
  ### Callbacks
76
118
 
77
119
  ```typescript
78
- // Success callback
79
- onSuccess: (transaction: PaymentTransaction) => void
120
+ // Success callback - called when payment succeeds
121
+ onSuccess: (payment: PaymentData) => void
80
122
 
81
- // Error callback
123
+ // Error callback - called when payment fails
82
124
  onError: (error: PaymentError) => void
83
125
 
84
- // Status change callback
85
- onStatusChange: (status: PaymentStatus) => void
126
+ // Close callback - called when widget is closed
127
+ onClose: () => void
86
128
  ```
87
129
 
88
- ## ๐ŸŽจ Styling
89
-
90
- The widget uses Tailwind CSS for styling. You can customize the appearance:
91
-
92
- ```css
93
- /* Custom styles */
94
- .payloqa-payment-widget {
95
- --primary-color: #3b82f6;
96
- --error-color: #ef4444;
97
- --success-color: #10b981;
98
- }
99
-
100
- /* Override specific components */
101
- .payment-widget-container {
102
- @apply bg-white rounded-lg shadow-lg p-6;
103
- }
130
+ ## ๐Ÿ“ฑ Display Modes
104
131
 
105
- .payment-method-selector {
106
- @apply border-2 border-gray-300 rounded-lg p-4;
107
- }
132
+ The widget supports three display modes:
108
133
 
109
- .payment-form {
110
- @apply space-y-4;
111
- }
134
+ ### Modal (Default)
135
+ ```jsx
136
+ <PaymentWidget
137
+ config={{ ...config, displayMode: "modal" }}
138
+ isOpen={isOpen}
139
+ onClose={() => setIsOpen(false)}
140
+ />
112
141
  ```
142
+ Displays as a centered modal overlay with backdrop.
113
143
 
114
- ## ๐Ÿงช Testing
144
+ ### Inline
145
+ ```jsx
146
+ <PaymentWidget
147
+ config={{ ...config, displayMode: "inline" }}
148
+ isOpen={isOpen}
149
+ onClose={() => setIsOpen(false)}
150
+ />
151
+ ```
152
+ Displays inline within your page layout.
115
153
 
116
- ### HTML Test Interface
154
+ ### Fullpage
155
+ ```jsx
156
+ <PaymentWidget
157
+ config={{ ...config, displayMode: "fullpage" }}
158
+ isOpen={isOpen}
159
+ onClose={() => setIsOpen(false)}
160
+ />
161
+ ```
162
+ Displays as a full-page experience.
117
163
 
118
- The widget includes a comprehensive HTML test file:
164
+ ## ๐Ÿ’ณ Supported Networks
119
165
 
120
- ```bash
121
- # Open the test interface
122
- open test.html
123
- ```
166
+ The widget supports mobile money payments for:
124
167
 
125
- **Test Features:**
126
- - โœ… Widget loading and mounting
127
- - โœ… Payment method selection
128
- - โœ… Form validation testing
129
- - โœ… Transaction processing simulation
130
- - โœ… Mobile responsiveness testing
131
- - โœ… Error scenario simulation
132
- - โœ… Real-time logging
168
+ - **MTN** - MTN Mobile Money
169
+ - **Telecel** - Telecel Cash (formerly Vodafone)
170
+ - **AirtelTigo** - AirtelTigo Money
133
171
 
134
- ### Framework Testing
172
+ ## ๐Ÿ”„ Payment Flow
135
173
 
136
- Test the widget in different React frameworks:
174
+ 1. **Phone Input** - User enters phone number and selects network
175
+ 2. **OTP Verification** - User receives and enters 4-digit OTP code
176
+ 3. **Processing** - Payment is processed and status is polled
177
+ 4. **Completion** - Success or error screen is shown
137
178
 
138
- ```bash
139
- # Next.js
140
- npx create-next-app@latest my-app
141
- cd my-app
142
- npm install @payloqa/payment-widget
179
+ ## ๐Ÿ“ Sample Responses
143
180
 
144
- # Create React App
145
- npx create-react-app my-app
146
- cd my-app
147
- npm install @payloqa/payment-widget
181
+ ### Success Response
148
182
 
149
- # Vite
150
- npm create vite@latest my-app -- --template react-ts
151
- cd my-app
152
- npm install @payloqa/payment-widget
183
+ ```typescript
184
+ {
185
+ payment_id: "pay_abc123",
186
+ status: "completed",
187
+ amount: 10.00,
188
+ currency: "GHS",
189
+ payment_method: "mobile_money",
190
+ phone_number: "+233XXXXXXXXX",
191
+ network: "mtn",
192
+ created_at: "2024-01-24T12:00:00Z",
193
+ updated_at: "2024-01-24T12:01:00Z",
194
+ paid_at: "2024-01-24T12:01:00Z"
195
+ }
153
196
  ```
154
197
 
155
- ## ๐Ÿ“ฆ Build Outputs
156
-
157
- The widget is built for multiple formats:
158
-
159
- - **UMD** (`dist/index.umd.js`) - For direct browser use
160
- - **ESM** (`dist/index.esm.js`) - For modern bundlers
161
- - **TypeScript** (`dist/index.d.ts`) - Type definitions
162
-
163
- ### Browser Usage
164
-
165
- ```html
166
- <!DOCTYPE html>
167
- <html>
168
- <head>
169
- <link rel="stylesheet" href="https://unpkg.com/@payloqa/payment-widget/dist/styles.css">
170
- </head>
171
- <body>
172
- <div id="payment-widget"></div>
173
-
174
- <script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
175
- <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
176
- <script src="https://unpkg.com/@payloqa/payment-widget/dist/index.umd.js"></script>
177
-
178
- <script>
179
- const config = {
180
- apiKey: 'your-api-key',
181
- platformId: 'your-platform-id',
182
- apiUrl: 'https://api.payloqa.com/v1/payments'
183
- };
184
-
185
- const root = ReactDOM.createRoot(document.getElementById('payment-widget'));
186
- root.render(React.createElement(PayloqaPaymentWidget.PaymentWidget, {
187
- config: config,
188
- amount: 1000,
189
- currency: 'USD',
190
- onSuccess: (transaction) => console.log('Success:', transaction),
191
- onError: (error) => console.error('Error:', error)
192
- }));
193
- </script>
194
- </body>
195
- </html>
198
+ ### Error Response
199
+
200
+ ```typescript
201
+ {
202
+ message: "Invalid OTP code",
203
+ code: "INVALID_OTP"
204
+ }
196
205
  ```
197
206
 
198
207
  ## ๐Ÿ”ง Development
@@ -216,160 +225,49 @@ npm run build
216
225
 
217
226
  # Type checking
218
227
  npm run type-check
219
-
220
- # Clean build artifacts
221
- npm run clean
222
- ```
223
-
224
- ### Project Structure
225
-
226
- ```
227
- payment-widget/
228
- โ”œโ”€โ”€ src/
229
- โ”‚ โ”œโ”€โ”€ components/
230
- โ”‚ โ”‚ โ”œโ”€โ”€ PaymentWidget.tsx # Main widget component
231
- โ”‚ โ”‚ โ”œโ”€โ”€ PaymentMethodSelector.tsx # Payment method selection
232
- โ”‚ โ”‚ โ”œโ”€โ”€ PaymentForm.tsx # Payment form
233
- โ”‚ โ”‚ โ””โ”€โ”€ TransactionStatus.tsx # Transaction status display
234
- โ”‚ โ”œโ”€โ”€ services/
235
- โ”‚ โ”‚ โ””โ”€โ”€ paymentService.ts # API service layer
236
- โ”‚ โ”œโ”€โ”€ types/
237
- โ”‚ โ”‚ โ””โ”€โ”€ payment.ts # TypeScript definitions
238
- โ”‚ โ”œโ”€โ”€ utils/
239
- โ”‚ โ”‚ โ”œโ”€โ”€ validation.ts # Validation schemas
240
- โ”‚ โ”‚ โ””โ”€โ”€ index.ts # Utility functions
241
- โ”‚ โ”œโ”€โ”€ styles.css # Global styles
242
- โ”‚ โ””โ”€โ”€ index.ts # Main entry point
243
- โ”œโ”€โ”€ dist/ # Build output
244
- โ”œโ”€โ”€ test.html # HTML test interface
245
- โ”œโ”€โ”€ package.json
246
- โ””โ”€โ”€ README.md
247
228
  ```
248
229
 
249
- ## ๐Ÿ’ณ Payment Methods
250
-
251
- The widget supports multiple payment methods:
252
-
253
- ### Credit/Debit Cards
254
- - Visa
255
- - Mastercard
256
- - American Express
257
- - Discover
258
-
259
- ### Mobile Money
260
- - M-Pesa (Kenya)
261
- - MTN Mobile Money (Ghana)
262
- - Airtel Money (Multiple countries)
263
- - Vodafone Cash (Ghana)
264
-
265
- ### Bank Transfers
266
- - Direct bank transfers
267
- - ACH payments (US)
268
- - SEPA transfers (EU)
269
-
270
- ## ๐Ÿ”’ Security
271
-
272
- ### PCI Compliance
273
-
274
- The widget is designed to be PCI-compliant:
275
-
276
- - **No card data storage** - Card details are never stored locally
277
- - **Secure transmission** - All data is encrypted in transit
278
- - **Tokenization** - Sensitive data is tokenized for processing
279
-
280
- ### API Security
281
-
282
- - All API calls include your API key
283
- - Request signing for additional security
284
- - Rate limiting protection
285
-
286
- ## ๐Ÿ“ฑ Mobile Support
287
-
288
- The widget is fully responsive and optimized for mobile devices:
289
-
290
- - **Touch-friendly** payment method selection
291
- - **Mobile-optimized** forms
292
- - **Responsive** design that adapts to screen size
293
- - **Native mobile** payment method integration
294
-
295
- ## ๐Ÿ”„ Transaction Flow
296
-
297
- The widget handles the complete payment flow:
298
-
299
- 1. **Payment Method Selection** - User chooses payment method
300
- 2. **Form Display** - Relevant payment form is shown
301
- 3. **Validation** - Real-time form validation
302
- 4. **Processing** - Payment is processed securely
303
- 5. **Status Updates** - Real-time transaction status
304
- 6. **Completion** - Success or error handling
305
-
306
230
  ## ๐Ÿ› Troubleshooting
307
231
 
308
- ### Common Issues
232
+ ### Widget doesn't open
309
233
 
310
- **Widget doesn't load:**
311
- - Check if React and ReactDOM are loaded
312
- - Verify the widget script is included
234
+ - Ensure `isOpen` prop is set to `true`
313
235
  - Check browser console for errors
236
+ - Verify React and ReactDOM are loaded
314
237
 
315
- **Payment methods not showing:**
316
- - Verify your API key has payment permissions
317
- - Check if payment methods are enabled for your account
318
- - Ensure you're in a supported region
238
+ ### Payment processing fails
319
239
 
320
- **Payment processing fails:**
321
- - Check API configuration
322
- - Verify payment method details
240
+ - Verify your API key and platform ID are correct
241
+ - Check that you have payment access enabled
242
+ - Ensure your account has completed KYC verification
323
243
  - Check network connectivity
324
244
  - Review error messages in console
325
245
 
326
- **Styling issues:**
327
- - Ensure CSS file is loaded
328
- - Check for CSS conflicts with your app
329
- - Verify Tailwind CSS is available
246
+ ### OTP not received
330
247
 
331
- ### Debug Mode
332
-
333
- Enable debug logging:
334
-
335
- ```jsx
336
- <PaymentWidget
337
- config={config}
338
- amount={1000}
339
- currency="USD"
340
- onSuccess={handleSuccess}
341
- onError={handleError}
342
- debug={true} // Enable debug logging
343
- />
344
- ```
248
+ - Verify phone number is correct and in E.164 format
249
+ - Check that the selected network matches the phone number
250
+ - Ensure you have sufficient balance for the transaction
251
+ - Check spam folder for OTP messages
345
252
 
346
253
  ## ๐Ÿ“„ API Reference
347
254
 
348
- ### PaymentWidget Props
255
+ ### PaymentData
349
256
 
350
257
  ```typescript
351
- interface PaymentWidgetProps {
352
- config: PaymentWidgetConfig;
353
- amount: number; // Amount in cents
354
- currency: string; // ISO currency code
355
- onSuccess?: (transaction: PaymentTransaction) => void;
356
- onError?: (error: PaymentError) => void;
357
- onStatusChange?: (status: PaymentStatus) => void;
358
- debug?: boolean;
359
- }
360
- ```
361
-
362
- ### PaymentTransaction
363
-
364
- ```typescript
365
- interface PaymentTransaction {
366
- id: string;
367
- amount: number;
258
+ interface PaymentData {
259
+ payment_id: string;
260
+ status: "pending" | "processing" | "completed" | "failed" | "cancelled" | "expired";
261
+ amount: number | string;
368
262
  currency: string;
369
- status: PaymentStatus;
370
- paymentMethod: string;
371
- createdAt: string;
372
- updatedAt: string;
263
+ payment_method: "mobile_money";
264
+ phone_number?: string;
265
+ network?: "mtn" | "vodafone" | "airteltigo";
266
+ reference?: string;
267
+ created_at: string;
268
+ updated_at: string;
269
+ paid_at?: string;
270
+ metadata?: Record<string, any>;
373
271
  }
374
272
  ```
375
273
 
@@ -383,78 +281,12 @@ interface PaymentError {
383
281
  }
384
282
  ```
385
283
 
386
- ### PaymentStatus
387
-
388
- ```typescript
389
- type PaymentStatus =
390
- | 'pending' // Payment is being processed
391
- | 'processing' // Payment is being authorized
392
- | 'completed' // Payment was successful
393
- | 'failed' // Payment failed
394
- | 'cancelled' // Payment was cancelled
395
- | 'refunded'; // Payment was refunded
396
- ```
397
-
398
- ## ๐ŸŒ Supported Countries
399
-
400
- The widget supports payments from multiple countries:
401
-
402
- ### Africa
403
- - Ghana
404
- - Kenya
405
- - Nigeria
406
- - South Africa
407
- - Uganda
408
- - Tanzania
409
-
410
- ### Europe
411
- - United Kingdom
412
- - Germany
413
- - France
414
- - Netherlands
415
- - Spain
416
- - Italy
417
-
418
- ### Americas
419
- - United States
420
- - Canada
421
- - Brazil
422
- - Mexico
423
-
424
- ### Asia
425
- - India
426
- - Singapore
427
- - Malaysia
428
- - Philippines
429
-
430
- ## ๐Ÿ’ฐ Pricing
431
-
432
- The widget is free to use. Transaction fees apply based on your Payloqa account:
433
-
434
- - **Credit/Debit Cards**: 2.9% + $0.30
435
- - **Mobile Money**: 1.5% + $0.10
436
- - **Bank Transfers**: 0.5% + $0.10
437
-
438
- *Fees may vary by region and payment method*
439
-
440
- ## ๐Ÿค Contributing
441
-
442
- 1. Fork the repository
443
- 2. Create a feature branch
444
- 3. Make your changes
445
- 4. Add tests if applicable
446
- 5. Submit a pull request
447
-
448
- ## ๐Ÿ“„ License
449
-
450
- MIT License - see [LICENSE](../../LICENSE) for details.
451
-
452
284
  ## ๐Ÿ†˜ Support
453
285
 
454
286
  - ๐Ÿ“ง Email: support@payloqa.com
455
- - ๐Ÿ“– Documentation: [docs.payloqa.com](https://docs.payloqa.com)
287
+ - ๐Ÿ“– Documentation: [docs.payloqa.com](https://payloqa.com/developer-docs)
456
288
  - ๐Ÿ› Issues: [GitHub Issues](https://github.com/kobbycoder/payloqa-widgets/issues)
457
289
 
458
290
  ---
459
291
 
460
- Built with โค๏ธ by the Payloqa Team
292
+ Built with โค๏ธ by the Payloqa Team
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloqa/payment-widget",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "description": "React-based payment widget for Payloqa",
6
6
  "main": "dist/index.umd.js",