@muhammedaksam/sipay-node 1.1.0 → 1.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.
Files changed (2) hide show
  1. package/README.md +100 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,6 +16,7 @@ An unofficial Node.js TypeScript SDK for the Sipay payment gateway.
16
16
  - 🔄 Recurring payments
17
17
  - 🏷️ Branded payment solutions
18
18
  - 📊 Commission information
19
+ - 🏷️ Status code management with detailed error handling
19
20
  - 🛡️ Type-safe with TypeScript
20
21
  - ✅ Input validation
21
22
  - 🔒 Secure payment processing
@@ -302,6 +303,105 @@ interface SipayApiResponse<T = any> {
302
303
  }
303
304
  ```
304
305
 
306
+ ## Status Code Management
307
+
308
+ The SDK provides comprehensive status code utilities to help you handle different payment scenarios effectively.
309
+
310
+ ### Available Status Codes
311
+
312
+ ```typescript
313
+ import { SipayStatusCode, getStatusCodeInfo, getSuggestedAction } from '@muhammedaksam/sipay-node';
314
+
315
+ // Status code enums
316
+ SipayStatusCode.SUCCESSFUL; // 100 - Payment successful
317
+ SipayStatusCode.BASIC_VALIDATION; // 1 - Basic validation error
318
+ SipayStatusCode.INVALID_CREDENTIALS; // 30 - Authentication failed
319
+ SipayStatusCode.ORDER_FAILED; // 41 - Payment failed
320
+ SipayStatusCode.CREDIT_CARD_BLOCKED; // 44 - Card blocked
321
+ SipayStatusCode.REFUND_FAILED; // 49 - Refund error
322
+ SipayStatusCode.FOREIGN_CARDS_NOT_ALLOWED; // 76 - Foreign cards not allowed
323
+ // ... and 50+ more status codes
324
+ ```
325
+
326
+ ### Status Code Utilities
327
+
328
+ ```typescript
329
+ import {
330
+ getStatusCodeInfo,
331
+ getSuggestedAction,
332
+ StatusCodeGroups,
333
+ isStatusInGroup,
334
+ } from '@muhammedaksam/sipay-node';
335
+
336
+ // Get detailed information about a status code
337
+ const info = getStatusCodeInfo(response.status_code);
338
+ console.log(info.description); // Human-readable description
339
+ console.log(info.category); // 'success', 'validation_error', 'payment_error', etc.
340
+ console.log(info.isRetryable); // Whether the error can be retried
341
+ console.log(info.httpEquivalent); // HTTP status equivalent (if applicable)
342
+
343
+ // Get actionable suggestions
344
+ const suggestion = getSuggestedAction(response.status_code);
345
+ console.log(suggestion); // "Check payment details and try with different parameters"
346
+
347
+ // Use predefined groups for easy error handling
348
+ if (isStatusInGroup(response.status_code, StatusCodeGroups.VALIDATION_ERRORS)) {
349
+ console.log('Please fix the validation errors in your request');
350
+ } else if (isStatusInGroup(response.status_code, StatusCodeGroups.CARD_ERRORS)) {
351
+ console.log('Please try with a different card');
352
+ }
353
+ ```
354
+
355
+ ### Enhanced Error Handling
356
+
357
+ ```typescript
358
+ import { SipayStatusCode, getStatusCodeInfo } from '@muhammedaksam/sipay-node';
359
+
360
+ try {
361
+ const response = await sipay.payments.pay2D(paymentData);
362
+
363
+ if (response.status_code === SipayStatusCode.SUCCESSFUL) {
364
+ console.log('✅ Payment successful!');
365
+ console.log('Order ID:', response.data?.order_id);
366
+ } else {
367
+ // Handle non-success responses with detailed status information
368
+ const statusInfo = getStatusCodeInfo(response.status_code);
369
+
370
+ console.log('❌ Payment failed:');
371
+ console.log('Status Code:', statusInfo.code);
372
+ console.log('Description:', statusInfo.description);
373
+ console.log('Category:', statusInfo.category);
374
+
375
+ // Handle retryable errors
376
+ if (statusInfo.isRetryable) {
377
+ console.log('🔄 This error is retryable - you can try again after a delay');
378
+ // Implement retry logic here
379
+ }
380
+ }
381
+ } catch (error) {
382
+ // SDK errors now include enhanced status information
383
+ if (error.status_code) {
384
+ const statusInfo = getStatusCodeInfo(error.status_code);
385
+ console.log('Error category:', statusInfo.category);
386
+ console.log('Suggested action:', getSuggestedAction(error.status_code));
387
+ }
388
+ }
389
+ ```
390
+
391
+ ### Status Categories
392
+
393
+ The SDK categorizes status codes for easier error handling:
394
+
395
+ - **Success**: `100`, `101`, `112` - Transaction completed successfully
396
+ - **Validation Errors**: `1`, `12`, `13`, `32`, `33`, `85`, `108`, `404` - Request validation issues
397
+ - **Authentication Errors**: `30`, `34`, `79`, `87` - Credential or permission issues
398
+ - **Payment Errors**: `41`, `43`, `49`, `31`, `69`, `105` - Payment processing failures
399
+ - **Merchant Errors**: `14`, `37`, `38`, `44`, `45-48`, `80`, `106` - Merchant configuration issues
400
+ - **Card Errors**: `44`, `60`, `70`, `76`, `77`, `86`, `88-89` - Card-related problems
401
+ - **Hash Errors**: `68`, `90-97` - Hash key validation failures
402
+ - **Recurring Errors**: `55`, `71`, `73` - Recurring payment issues
403
+ - **Retryable Errors**: `3`, `49`, `69`, `117` - Temporary errors that can be retried
404
+
305
405
  ## Development
306
406
 
307
407
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muhammedaksam/sipay-node",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Node.js TypeScript SDK for Sipay payment gateway",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",