@payloqa/payment-widget 1.0.0 โ†’ 1.0.1

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 +172 -339
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,198 +1,208 @@
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
+ - Create an account
22
+ - Go to the **API Keys** page
23
+ - Request payment access by filling out the KYC form
24
+ - Once approved, you'll be notified and can access:
25
+ - Your **API Key**
26
+ - Your **Platform ID**
27
+
28
+ ### 2. Install the Package
19
29
 
20
30
  ```bash
21
31
  npm install @payloqa/payment-widget
22
32
  ```
23
33
 
24
- ### Basic Usage
34
+ ### 3. Import and Use
25
35
 
26
36
  ```jsx
27
- import { PaymentWidget } from '@payloqa/payment-widget';
37
+ import { PaymentWidget } from "@payloqa/payment-widget";
38
+ import "@payloqa/payment-widget/dist/payment-widget.css";
28
39
 
29
40
  function App() {
41
+ const [isOpen, setIsOpen] = useState(false);
42
+
30
43
  const config = {
31
- apiKey: 'your-api-key',
32
- platformId: 'your-platform-id',
33
- apiUrl: 'https://api.payloqa.com/v1/payments'
44
+ apiKey: "your-api-key",
45
+ platformId: "your-platform-id",
46
+ amount: 10.00,
47
+ currency: "GHS", // Optional, defaults to "GHS"
48
+ primaryColor: "#3B82F6", // Optional, your brand color
49
+ displayMode: "modal", // "modal" | "inline" | "fullpage"
50
+ redirect_url: "https://yoursite.com/callback", // Required
51
+ webhookUrl: "https://yoursite.com/webhook", // Required
52
+ orderId: "order-123", // Optional
53
+ metadata: { // Optional
54
+ customField: "value",
55
+ },
34
56
  };
35
57
 
36
- const handleSuccess = (transaction) => {
37
- console.log('Payment successful:', transaction);
38
- console.log('Transaction ID:', transaction.id);
39
- console.log('Amount:', transaction.amount);
58
+ const handleSuccess = (payment) => {
59
+ console.log("Payment successful!", payment);
60
+ console.log("Payment ID:", payment.payment_id);
61
+ console.log("Status:", payment.status);
62
+ console.log("Amount:", payment.amount);
40
63
  };
41
64
 
42
65
  const handleError = (error) => {
43
- console.error('Payment failed:', error);
44
- };
45
-
46
- const handleStatusChange = (status) => {
47
- console.log('Payment status:', status);
66
+ console.error("Payment failed:", error.message);
67
+ alert(`Error: ${error.message}`);
48
68
  };
49
69
 
50
70
  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
- />
71
+ <div>
72
+ <button onClick={() => setIsOpen(true)}>Pay Now</button>
73
+
74
+ <PaymentWidget
75
+ config={config}
76
+ isOpen={isOpen}
77
+ onClose={() => setIsOpen(false)}
78
+ onSuccess={handleSuccess}
79
+ onError={handleError}
80
+ />
81
+ </div>
59
82
  );
60
83
  }
61
84
  ```
62
85
 
63
86
  ## โš™๏ธ Configuration
64
87
 
65
- ### PaymentWidgetConfig
88
+ ### Required Configuration
66
89
 
67
90
  ```typescript
68
91
  interface PaymentWidgetConfig {
69
- apiKey: string; // Your Payloqa API key
70
- platformId: string; // Your platform identifier
71
- apiUrl: string; // Payloqa payments API URL
92
+ apiKey: string; // Your Payloqa API key
93
+ platformId: string; // Your platform ID
94
+ amount: number; // Payment amount (e.g., 10.00)
95
+ currency?: string; // Currency code (default: "GHS")
96
+ displayMode?: string; // "modal" | "inline" | "fullpage" (default: "modal")
97
+ primaryColor?: string; // Your brand color in hex (e.g., "#3B82F6")
98
+ logoUrl?: string; // Optional logo URL to display in header
99
+ redirect_url: string; // Required: HTTPS URL for redirect after payment
100
+ webhookUrl: string; // Required: Webhook URL for server notifications
101
+ orderId?: string; // Optional order identifier
102
+ metadata?: object; // Optional metadata object
103
+ onSuccess?: (payment: PaymentData) => void;
104
+ onError?: (error: PaymentError) => void;
105
+ }
106
+ ```
107
+
108
+ ### PaymentWidget Props
109
+
110
+ ```typescript
111
+ interface PaymentWidgetProps {
112
+ config: PaymentWidgetConfig;
113
+ isOpen: boolean; // Controls widget visibility
114
+ onClose?: () => void; // Called when widget is closed
72
115
  }
73
116
  ```
74
117
 
75
118
  ### Callbacks
76
119
 
77
120
  ```typescript
78
- // Success callback
79
- onSuccess: (transaction: PaymentTransaction) => void
121
+ // Success callback - called when payment succeeds
122
+ onSuccess: (payment: PaymentData) => void
80
123
 
81
- // Error callback
124
+ // Error callback - called when payment fails
82
125
  onError: (error: PaymentError) => void
83
126
 
84
- // Status change callback
85
- onStatusChange: (status: PaymentStatus) => void
127
+ // Close callback - called when widget is closed
128
+ onClose: () => void
86
129
  ```
87
130
 
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
- }
131
+ ## ๐Ÿ“ฑ Display Modes
104
132
 
105
- .payment-method-selector {
106
- @apply border-2 border-gray-300 rounded-lg p-4;
107
- }
133
+ The widget supports three display modes:
108
134
 
109
- .payment-form {
110
- @apply space-y-4;
111
- }
135
+ ### Modal (Default)
136
+ ```jsx
137
+ <PaymentWidget
138
+ config={{ ...config, displayMode: "modal" }}
139
+ isOpen={isOpen}
140
+ onClose={() => setIsOpen(false)}
141
+ />
112
142
  ```
143
+ Displays as a centered modal overlay with backdrop.
113
144
 
114
- ## ๐Ÿงช Testing
145
+ ### Inline
146
+ ```jsx
147
+ <PaymentWidget
148
+ config={{ ...config, displayMode: "inline" }}
149
+ isOpen={isOpen}
150
+ onClose={() => setIsOpen(false)}
151
+ />
152
+ ```
153
+ Displays inline within your page layout.
115
154
 
116
- ### HTML Test Interface
155
+ ### Fullpage
156
+ ```jsx
157
+ <PaymentWidget
158
+ config={{ ...config, displayMode: "fullpage" }}
159
+ isOpen={isOpen}
160
+ onClose={() => setIsOpen(false)}
161
+ />
162
+ ```
163
+ Displays as a full-page experience.
117
164
 
118
- The widget includes a comprehensive HTML test file:
165
+ ## ๐Ÿ’ณ Supported Networks
119
166
 
120
- ```bash
121
- # Open the test interface
122
- open test.html
123
- ```
167
+ The widget supports mobile money payments for:
124
168
 
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
169
+ - **MTN** - MTN Mobile Money
170
+ - **Telecel** - Telecel Cash (formerly Vodafone)
171
+ - **AirtelTigo** - AirtelTigo Money
133
172
 
134
- ### Framework Testing
173
+ ## ๐Ÿ”„ Payment Flow
135
174
 
136
- Test the widget in different React frameworks:
175
+ 1. **Phone Input** - User enters phone number and selects network
176
+ 2. **OTP Verification** - User receives and enters 4-digit OTP code
177
+ 3. **Processing** - Payment is processed and status is polled
178
+ 4. **Completion** - Success or error screen is shown
137
179
 
138
- ```bash
139
- # Next.js
140
- npx create-next-app@latest my-app
141
- cd my-app
142
- npm install @payloqa/payment-widget
180
+ ## ๐Ÿ“ Sample Responses
143
181
 
144
- # Create React App
145
- npx create-react-app my-app
146
- cd my-app
147
- npm install @payloqa/payment-widget
182
+ ### Success Response
148
183
 
149
- # Vite
150
- npm create vite@latest my-app -- --template react-ts
151
- cd my-app
152
- npm install @payloqa/payment-widget
184
+ ```typescript
185
+ {
186
+ payment_id: "pay_abc123",
187
+ status: "completed",
188
+ amount: 10.00,
189
+ currency: "GHS",
190
+ payment_method: "mobile_money",
191
+ phone_number: "+233XXXXXXXXX",
192
+ network: "mtn",
193
+ created_at: "2024-01-24T12:00:00Z",
194
+ updated_at: "2024-01-24T12:01:00Z",
195
+ paid_at: "2024-01-24T12:01:00Z"
196
+ }
153
197
  ```
154
198
 
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>
199
+ ### Error Response
200
+
201
+ ```typescript
202
+ {
203
+ message: "Invalid OTP code",
204
+ code: "INVALID_OTP"
205
+ }
196
206
  ```
197
207
 
198
208
  ## ๐Ÿ”ง Development
@@ -216,160 +226,49 @@ npm run build
216
226
 
217
227
  # Type checking
218
228
  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
229
  ```
248
230
 
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
231
  ## ๐Ÿ› Troubleshooting
307
232
 
308
- ### Common Issues
233
+ ### Widget doesn't open
309
234
 
310
- **Widget doesn't load:**
311
- - Check if React and ReactDOM are loaded
312
- - Verify the widget script is included
235
+ - Ensure `isOpen` prop is set to `true`
313
236
  - Check browser console for errors
237
+ - Verify React and ReactDOM are loaded
314
238
 
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
239
+ ### Payment processing fails
319
240
 
320
- **Payment processing fails:**
321
- - Check API configuration
322
- - Verify payment method details
241
+ - Verify your API key and platform ID are correct
242
+ - Check that you have payment access enabled
243
+ - Ensure your account has completed KYC verification
323
244
  - Check network connectivity
324
245
  - Review error messages in console
325
246
 
326
- **Styling issues:**
327
- - Ensure CSS file is loaded
328
- - Check for CSS conflicts with your app
329
- - Verify Tailwind CSS is available
247
+ ### OTP not received
330
248
 
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
- ```
249
+ - Verify phone number is correct and in E.164 format
250
+ - Check that the selected network matches the phone number
251
+ - Ensure you have sufficient balance for the transaction
252
+ - Check spam folder for OTP messages
345
253
 
346
254
  ## ๐Ÿ“„ API Reference
347
255
 
348
- ### PaymentWidget Props
256
+ ### PaymentData
349
257
 
350
258
  ```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;
259
+ interface PaymentData {
260
+ payment_id: string;
261
+ status: "pending" | "processing" | "completed" | "failed" | "cancelled" | "expired";
262
+ amount: number | string;
368
263
  currency: string;
369
- status: PaymentStatus;
370
- paymentMethod: string;
371
- createdAt: string;
372
- updatedAt: string;
264
+ payment_method: "mobile_money";
265
+ phone_number?: string;
266
+ network?: "mtn" | "vodafone" | "airteltigo";
267
+ reference?: string;
268
+ created_at: string;
269
+ updated_at: string;
270
+ paid_at?: string;
271
+ metadata?: Record<string, any>;
373
272
  }
374
273
  ```
375
274
 
@@ -383,78 +282,12 @@ interface PaymentError {
383
282
  }
384
283
  ```
385
284
 
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
285
  ## ๐Ÿ†˜ Support
453
286
 
454
287
  - ๐Ÿ“ง Email: support@payloqa.com
455
- - ๐Ÿ“– Documentation: [docs.payloqa.com](https://docs.payloqa.com)
288
+ - ๐Ÿ“– Documentation: [docs.payloqa.com](https://payloqa.com/developer-docs)
456
289
  - ๐Ÿ› Issues: [GitHub Issues](https://github.com/kobbycoder/payloqa-widgets/issues)
457
290
 
458
291
  ---
459
292
 
460
- Built with โค๏ธ by the Payloqa Team
293
+ 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.1",
4
4
  "type": "module",
5
5
  "description": "React-based payment widget for Payloqa",
6
6
  "main": "dist/index.umd.js",