@drop-africa/drop-js 0.1.1 → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Drop Africa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -8,12 +8,12 @@ Embed payment QR codes in your web app and poll for payment status changes in re
8
8
 
9
9
  ## Features
10
10
 
11
- - **QR Code Rendering**: High-quality, scannable QR codes with customizable styling
12
- - **Real-time Polling**: Automatic status updates with configurable intervals
11
+ - **QR Code Rendering**: Scannable QR codes with customizable styling
12
+ - **Polling**: Automatic status updates with configurable intervals
13
13
  - **Copyable Links**: Optional fallback for users who can't scan QR codes
14
14
  - **TypeScript Support**: Full type definitions included
15
- - **Validation**: Comprehensive input validation with clear error messages
16
- - **Browser Compatible**: Works in all modern browsers (Chrome, Firefox, Safari, Edge)
15
+ - **Validation**: Input validation with descriptive error messages
16
+ - **Browser Compatible**: Works in modern browsers (Chrome, Firefox, Safari, Edge)
17
17
  - **Lightweight**: ~22KB gzipped (ESM), ~19KB gzipped (UMD)
18
18
 
19
19
  ## Installation
@@ -50,7 +50,7 @@ npm install @drop-africa/drop-js
50
50
  ### NPM/React Usage
51
51
 
52
52
  ```typescript
53
- import { Drop } from '@drop-africa/drop-js';
53
+ import { Drop, PaymentStatuses } from '@drop-africa/drop-js';
54
54
 
55
55
  function PaymentPage() {
56
56
  useEffect(() => {
@@ -59,7 +59,7 @@ function PaymentPage() {
59
59
  instanceUrl: 'https://drop.africa/api/v1/payment-accounts/acc_123/payment-intents/pi_456',
60
60
  containerId: 'payment-qr',
61
61
  onStatusChange: (status) => {
62
- if (status === 'succeeded') {
62
+ if (status === PaymentStatuses.SUCCEEDED) {
63
63
  console.log('Payment successful!');
64
64
  }
65
65
  }
@@ -157,7 +157,7 @@ const status = instance.getStatus();
157
157
  | `succeeded` | Payment completed successfully |
158
158
  | `failed` | Payment failed (insufficient funds, network error, etc.) |
159
159
  | `cancelled` | Payment cancelled by customer or merchant |
160
- | `expired` | Payment intent expired (typically after 15 minutes) |
160
+ | `expired` | Payment intent expired (typically after 24 hours) |
161
161
 
162
162
  ### Color Formats
163
163
 
@@ -244,6 +244,30 @@ Drop.create({
244
244
  | `VALIDATION_ERROR` | Invalid configuration | ❌ |
245
245
  | `UNKNOWN` | Unexpected error | ❌ |
246
246
 
247
+ ### Using Constants
248
+
249
+ For type-safe handling, use the exported constants instead of string literals:
250
+
251
+ ```typescript
252
+ import { Drop, ErrorCodes, PaymentStatuses } from '@drop-africa/drop-js';
253
+
254
+ Drop.create({
255
+ clientSecret: 'pi_secret_1234567890',
256
+ instanceUrl: '...',
257
+ containerId: 'payment-qr',
258
+ onStatusChange: (status) => {
259
+ if (status === PaymentStatuses.SUCCEEDED) {
260
+ console.log('Payment successful!');
261
+ }
262
+ },
263
+ onError: (error) => {
264
+ if (error.code === ErrorCodes.NETWORK_ERROR) {
265
+ console.error('Network issue:', error.message);
266
+ }
267
+ }
268
+ });
269
+ ```
270
+
247
271
  ## Browser Support
248
272
 
249
273
  Drop.js works in all modern browsers:
@@ -260,7 +284,7 @@ Drop.js works in all modern browsers:
260
284
  Full TypeScript definitions are included. Import types directly:
261
285
 
262
286
  ```typescript
263
- import { Drop, DropConfig, DropInstance, DropPaymentStatus, DropError } from '@drop-africa/drop-js';
287
+ import { Drop, DropConfig, DropInstance, DropPaymentStatus, DropError, ErrorCodes, PaymentStatuses } from '@drop-africa/drop-js';
264
288
 
265
289
  const config: DropConfig = {
266
290
  clientSecret: 'pi_secret_1234567890',
@@ -277,11 +301,11 @@ const status: DropPaymentStatus = instance.getStatus();
277
301
  ### React Component
278
302
 
279
303
  ```typescript
280
- import { Drop, DropPaymentStatus } from '@drop-africa/drop-js';
304
+ import { Drop, DropPaymentStatus, PaymentStatuses } from '@drop-africa/drop-js';
281
305
  import { useEffect, useState } from 'react';
282
306
 
283
307
  export function Payment({ clientSecret, instanceUrl }) {
284
- const [status, setStatus] = useState<DropPaymentStatus>('initiated');
308
+ const [status, setStatus] = useState<DropPaymentStatus>(PaymentStatuses.INITIATED);
285
309
 
286
310
  useEffect(() => {
287
311
  const instance = await Drop.create({
@@ -296,7 +320,7 @@ export function Payment({ clientSecret, instanceUrl }) {
296
320
 
297
321
  return (
298
322
  <div>
299
- {status === 'succeeded' ? (
323
+ {status === PaymentStatuses.SUCCEEDED ? (
300
324
  <p>Payment successful!</p>
301
325
  ) : (
302
326
  <div id="payment-qr"></div>
@@ -311,17 +335,17 @@ export function Payment({ clientSecret, instanceUrl }) {
311
335
  ```vue
312
336
  <template>
313
337
  <div>
314
- <div v-if="status === 'succeeded'">Payment successful!</div>
338
+ <div v-if="status === PaymentStatuses.SUCCEEDED">Payment successful!</div>
315
339
  <div v-else id="payment-qr"></div>
316
340
  </div>
317
341
  </template>
318
342
 
319
343
  <script setup>
320
- import { Drop } from '@drop-africa/drop-js';
344
+ import { Drop, PaymentStatuses } from '@drop-africa/drop-js';
321
345
  import { ref, onMounted, onUnmounted } from 'vue';
322
346
 
323
347
  const props = defineProps(['clientSecret', 'instanceUrl']);
324
- const status = ref('initiated');
348
+ const status = ref(PaymentStatuses.INITIATED);
325
349
  let instance;
326
350
 
327
351
  onMounted(async () => {
@@ -355,13 +379,15 @@ onUnmounted(() => {
355
379
 
356
380
  <script src="https://cdn.drop.africa/sdk/drop.js"></script>
357
381
  <script>
382
+ const { PaymentStatuses } = Drop;
383
+
358
384
  Drop.create({
359
385
  clientSecret: 'pi_secret_1234567890abcdef',
360
386
  instanceUrl: 'https://drop.africa/api/v1/payment-accounts/acc_123/payment-intents/pi_456',
361
387
  containerId: 'payment-qr',
362
388
  onStatusChange: (status) => {
363
389
  document.getElementById('status').textContent = `Status: ${status}`;
364
- if (status === 'succeeded') {
390
+ if (status === PaymentStatuses.SUCCEEDED) {
365
391
  alert('Payment successful!');
366
392
  }
367
393
  },
@@ -376,10 +402,10 @@ onUnmounted(() => {
376
402
 
377
403
  ## Links
378
404
 
379
- - [Documentation](https://github.com/Fabaladibbasey/drop/tree/main/sdk/drop-js)
380
- - [GitHub Repository](https://github.com/Fabaladibbasey/drop)
405
+ - [Documentation](https://github.com/drop-africa/Drop.js-SDK#readme)
406
+ - [GitHub Repository](https://github.com/drop-africa/Drop.js-SDK)
381
407
  - [npm Package](https://www.npmjs.com/package/@drop-africa/drop-js)
382
- - [Issues](https://github.com/Fabaladibbasey/drop/issues)
408
+ - [Issues](https://github.com/drop-africa/Drop.js-SDK/issues)
383
409
 
384
410
  ## License
385
411