tsapay-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.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # TsaPay Node.js SDK
2
+
3
+ ![NPM Version](https://img.shields.io/npm/v/tsapay-sdk)
4
+ ![License](https://img.shields.io/npm/l/tsapay-sdk)
5
+
6
+ The official Node.js / TypeScript SDK for **TsaPay**, the universal Mobile Money aggregator for the CEMAC zone (MTN MoMo, Orange Money).
7
+
8
+ Integrate Mobile Money payments into your e-commerce platform, mobile app backend, or SaaS in just a few lines of code.
9
+
10
+ ## 📦 Installation
11
+
12
+ ```bash
13
+ npm install tsapay-sdk
14
+ # or
15
+ yarn add tsapay-sdk
16
+ # or
17
+ pnpm add tsapay-sdk
18
+ ```
19
+
20
+ ## 🚀 Quick Start
21
+
22
+ ### 1. Initialization
23
+
24
+ First, get your API Key from your TsaPay Merchant Dashboard.
25
+
26
+ ```typescript
27
+ import { TsaPayClient } from 'tsapay-sdk';
28
+
29
+ const tsapay = new TsaPayClient({
30
+ apiKey: 'sk_test_YOUR_API_KEY_HERE',
31
+ // baseUrl is optional, defaults to the production gateway
32
+ });
33
+ ```
34
+
35
+ ### 2. Create a Payment
36
+
37
+ Initiate a USSD push directly to the customer's phone.
38
+
39
+ ```typescript
40
+ try {
41
+ const response = await tsapay.createPayment({
42
+ amount: 1500,
43
+ currency: 'XAF', // Optional, defaults to XAF
44
+ provider: 'mtn_momo', // or 'orange_money'
45
+ phoneNumber: '+237670000000', // Customer's phone number
46
+ description: 'Order #12345',
47
+ reference: 'REF-12345', // Your internal order reference
48
+ callbackUrl: 'https://your-site.com/api/webhooks/tsapay', // Where we should send the webhook
49
+ });
50
+
51
+ console.log('Payment initiated successfully:', response.payment.id);
52
+ console.log('Status:', response.payment.status); // 'pending'
53
+ } catch (error) {
54
+ console.error('Payment failed:', error.message);
55
+ }
56
+ ```
57
+
58
+ ### 3. Check Payment Status
59
+
60
+ ```typescript
61
+ const response = await tsapay.getPayment('pay_123456789');
62
+ console.log('Current status:', response.payment.status);
63
+ ```
64
+
65
+ ### 4. Verify Webhooks
66
+
67
+ When a payment succeeds or fails, TsaPay will send a POST request to your `callbackUrl`. To ensure this request actually came from TsaPay, you must verify the signature using your Webhook Secret.
68
+
69
+ ```typescript
70
+ import express from 'express';
71
+
72
+ const app = express();
73
+ const WEBHOOK_SECRET = 'whsec_YOUR_WEBHOOK_SECRET';
74
+
75
+ app.post('/api/webhooks/tsapay', express.raw({ type: 'application/json' }), (req, res) => {
76
+ const signature = req.headers['x-tsapay-signature'] as string;
77
+ const payload = req.body.toString();
78
+
79
+ // Verify the signature
80
+ const isValid = tsapay.verifyWebhookSignature(payload, signature, WEBHOOK_SECRET);
81
+
82
+ if (!isValid) {
83
+ return res.status(400).send('Invalid signature');
84
+ }
85
+
86
+ const event = JSON.parse(payload);
87
+
88
+ if (event.event_type === 'payment.success') {
89
+ console.log('Payment successful for:', event.data.reference);
90
+ // TODO: Fulfill the order in your database
91
+ }
92
+
93
+ res.send('Webhook received');
94
+ });
95
+ ```
96
+
97
+ ## 📚 Features
98
+
99
+ - **Zero dependencies** (uses native `fetch`)
100
+ - **Full TypeScript support** with strict types
101
+ - **Built-in idempotency** to prevent duplicate charges
102
+ - **Secure webhook verification** helper included
103
+
104
+ ## 📄 License
105
+
106
+ MIT
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export interface TinguilinConfig {
1
+ export interface TsaPayConfig {
2
2
  apiKey: string;
3
3
  baseUrl?: string;
4
4
  }
@@ -36,15 +36,15 @@ export interface ListPaymentsResponse {
36
36
  payments: PaymentResponse["payment"][];
37
37
  total: number;
38
38
  }
39
- export declare class TinguilinError extends Error {
39
+ export declare class TsaPayError extends Error {
40
40
  status: number;
41
41
  data: any;
42
42
  constructor(status: number, message: string, data?: any);
43
43
  }
44
- export declare class TinguilinClient {
44
+ export declare class TsaPayClient {
45
45
  private apiKey;
46
46
  private baseUrl;
47
- constructor(config: TinguilinConfig);
47
+ constructor(config: TsaPayConfig);
48
48
  private request;
49
49
  /**
50
50
  * Create a new Mobile Money payment.
package/dist/index.js CHANGED
@@ -3,20 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TinguilinClient = exports.TinguilinError = void 0;
6
+ exports.TsaPayClient = exports.TsaPayError = void 0;
7
7
  const crypto_1 = __importDefault(require("crypto"));
8
- class TinguilinError extends Error {
8
+ class TsaPayError extends Error {
9
9
  status;
10
10
  data;
11
11
  constructor(status, message, data) {
12
12
  super(message);
13
- this.name = "TinguilinError";
13
+ this.name = "TsaPayError";
14
14
  this.status = status;
15
15
  this.data = data;
16
16
  }
17
17
  }
18
- exports.TinguilinError = TinguilinError;
19
- class TinguilinClient {
18
+ exports.TsaPayError = TsaPayError;
19
+ class TsaPayClient {
20
20
  apiKey;
21
21
  baseUrl;
22
22
  constructor(config) {
@@ -41,7 +41,7 @@ class TinguilinClient {
41
41
  catch (e) {
42
42
  errorData = { message: response.statusText };
43
43
  }
44
- throw new TinguilinError(response.status, errorData.message || `API error ${response.status}`, errorData);
44
+ throw new TsaPayError(response.status, errorData.message || `API error ${response.status}`, errorData);
45
45
  }
46
46
  return response.json();
47
47
  }
@@ -102,4 +102,4 @@ class TinguilinClient {
102
102
  return expectedSignature === signatureHeader;
103
103
  }
104
104
  }
105
- exports.TinguilinClient = TinguilinClient;
105
+ exports.TsaPayClient = TsaPayClient;
@@ -1,7 +1,7 @@
1
- import { TinguilinClient } from "../src/index";
1
+ import { TsaPayClient } from "../src/index";
2
2
 
3
3
  async function run() {
4
- const client = new TinguilinClient({
4
+ const client = new TsaPayClient({
5
5
  apiKey: "sk_test_1234567890", // Replace with your real test key
6
6
  baseUrl: "http://localhost:8080/v1" // Use production URL when going live
7
7
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsapay-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "The official Node.js / TypeScript SDK for TsaPay Mobile Money Aggregator",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,16 @@
8
8
  "build": "tsc",
9
9
  "prepublishOnly": "npm run build"
10
10
  },
11
- "keywords": ["tsapay", "mobile-money", "payments", "mtn", "orange-money", "cemac", "cameroon", "fintech"],
11
+ "keywords": [
12
+ "tsapay",
13
+ "mobile-money",
14
+ "payments",
15
+ "mtn",
16
+ "orange-money",
17
+ "cemac",
18
+ "cameroon",
19
+ "fintech"
20
+ ],
12
21
  "author": "TsaPay",
13
22
  "license": "MIT",
14
23
  "type": "commonjs",
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import crypto from "crypto";
1
+ import crypto from "crypto";
2
2
 
3
- export interface TinguilinConfig {
3
+ export interface TsaPayConfig {
4
4
  apiKey: string;
5
5
  baseUrl?: string;
6
6
  }
@@ -43,23 +43,23 @@ export interface ListPaymentsResponse {
43
43
  total: number;
44
44
  }
45
45
 
46
- export class TinguilinError extends Error {
46
+ export class TsaPayError extends Error {
47
47
  public status: number;
48
48
  public data: any;
49
49
 
50
50
  constructor(status: number, message: string, data?: any) {
51
51
  super(message);
52
- this.name = "TinguilinError";
52
+ this.name = "TsaPayError";
53
53
  this.status = status;
54
54
  this.data = data;
55
55
  }
56
56
  }
57
57
 
58
- export class TinguilinClient {
58
+ export class TsaPayClient {
59
59
  private apiKey: string;
60
60
  private baseUrl: string;
61
61
 
62
- constructor(config: TinguilinConfig) {
62
+ constructor(config: TsaPayConfig) {
63
63
  if (!config.apiKey) {
64
64
  throw new Error("TsaPay API key is required");
65
65
  }
@@ -84,7 +84,7 @@ export class TinguilinClient {
84
84
  } catch (e) {
85
85
  errorData = { message: response.statusText };
86
86
  }
87
- throw new TinguilinError(
87
+ throw new TsaPayError(
88
88
  response.status,
89
89
  errorData.message || `API error ${response.status}`,
90
90
  errorData