@wikha/sdk 1.1.13 → 1.1.15
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 +48 -2
- package/dist/src/sdk.d.ts +1 -1
- package/dist/src/sdk.js +6 -3
- package/dist/wikha-sdk.umd.js +1 -1
- package/dist/wikha-sdk.umd.js.LICENSE.txt +0 -2
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -18,6 +18,12 @@ console.log(WikhaSDK.Environment.sandbox);
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
# Processing a Payment
|
|
21
|
+
|
|
22
|
+
## Security & Payload Encryption
|
|
23
|
+
By default, when using this SDK in a browser environment, it will send the data in **plaintext** (`{ data: ... }`) if the `crypto` module is not present. However, if you are using Node.js (or if a Polyfill is provided), the SDK will automatically compress and encrypt your payload in RSA using the `encryptedData` field.
|
|
24
|
+
|
|
25
|
+
The Wikha API accepts both formats but we strongly encourage RSA encryption for production usage.
|
|
26
|
+
|
|
21
27
|
## Use the processPayment method to initiate a payment.
|
|
22
28
|
You'll need to provide a WikhaPayload object with the necessary payment details.
|
|
23
29
|
|
|
@@ -39,10 +45,20 @@ async function initiatePayment() {
|
|
|
39
45
|
payer_name: 'John Tshisola',
|
|
40
46
|
operation: WikhaSDK.PaymentType.payin,
|
|
41
47
|
currency: 'CDF',
|
|
42
|
-
notify_url: '[https://your-callback-url.com/notify](https://
|
|
43
|
-
return_url: '[https://your-website.com/success](https://
|
|
48
|
+
notify_url: '[https://your-callback-url.com/notify](https://your-callback-url.com/notify)',
|
|
49
|
+
return_url: '[https://your-website.com/success](https://your-website.com/success)',
|
|
44
50
|
};
|
|
45
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Note on Notifications (Webhooks):
|
|
54
|
+
* 1. The API supports `notify_url` or `notifyUrl`.
|
|
55
|
+
* 2. If provided in the payload, this URL will be used for webhooks.
|
|
56
|
+
* 3. NEW: If NOT provided, the API will fall back to the merchant's default notify_url
|
|
57
|
+
* configured in the Wikha Dashboard.
|
|
58
|
+
* 4. The webhook includes an 'X-Wikha-Signature' header (HMAC-SHA256) signed
|
|
59
|
+
* with your API Key.
|
|
60
|
+
*/
|
|
61
|
+
|
|
46
62
|
try {
|
|
47
63
|
const response = await sdk.processPayment(paymentData);
|
|
48
64
|
console.log('Payment initiated successfully:', response);
|
|
@@ -55,6 +71,36 @@ async function initiatePayment() {
|
|
|
55
71
|
|
|
56
72
|
initiatePayment();
|
|
57
73
|
```
|
|
74
|
+
|
|
75
|
+
## Processing a Payout (Withdrawal)
|
|
76
|
+
|
|
77
|
+
```TypeScript
|
|
78
|
+
import { WikhaSDK } from '@wikha/sdk';
|
|
79
|
+
|
|
80
|
+
const sdk = new WikhaSDK('YOUR_API_KEY', 'YOUR_MERCHANT_ID');
|
|
81
|
+
|
|
82
|
+
async function initiatePayout() {
|
|
83
|
+
const payoutData: WikhaSDK.WikhaPayload = {
|
|
84
|
+
provider: WikhaSDK.PaymentProviderType.mpesa,
|
|
85
|
+
payer_phone: '081XXXXXXX',
|
|
86
|
+
order_id: 'WITHDRAW-789',
|
|
87
|
+
amount: 50,
|
|
88
|
+
payer_name: 'Jane Doe',
|
|
89
|
+
operation: WikhaSDK.PaymentType.payout, // Mandatory for withdrawals
|
|
90
|
+
currency: 'USD',
|
|
91
|
+
notify_url: 'https://your-callback-url.com/payout-notify', // Highly recommended for async updates
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const response = await sdk.processPayment(payoutData);
|
|
96
|
+
console.log('Payout initiated:', response);
|
|
97
|
+
} catch (error: any) {
|
|
98
|
+
console.error('Payout failed:', error.message);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
initiatePayout();
|
|
103
|
+
```
|
|
58
104
|
# Query transaction status
|
|
59
105
|
|
|
60
106
|
```typescript
|
package/dist/src/sdk.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const PAY_ENDPOINT = "https://api.wikha-hitech.com/v2";
|
|
1
|
+
export declare const PAY_ENDPOINT = "https://api.wikha-hitech.com/v2/payments";
|
|
2
2
|
export declare const TRANSACTION_QUERY_ENDPOINT = "https://api.wikha-hitech.com/v2/query";
|
|
3
3
|
export declare enum PaymentProviderType {
|
|
4
4
|
mpesa = "mpesa",
|
package/dist/src/sdk.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.WikhaSDK = exports.Environment = exports.MerchantStatus = exports.PaymentAggregatorType = exports.PaymentStatus = exports.PaymentType = exports.PaymentProviderType = exports.TRANSACTION_QUERY_ENDPOINT = exports.PAY_ENDPOINT = void 0;
|
|
5
5
|
// Constants
|
|
6
|
-
exports.PAY_ENDPOINT = "https://api.wikha-hitech.com/v2";
|
|
6
|
+
exports.PAY_ENDPOINT = "https://api.wikha-hitech.com/v2/payments";
|
|
7
7
|
exports.TRANSACTION_QUERY_ENDPOINT = "https://api.wikha-hitech.com/v2/query";
|
|
8
8
|
const isNode = typeof window === 'undefined' && typeof process !== 'undefined';
|
|
9
9
|
// Interfaces & Enums
|
|
@@ -59,7 +59,9 @@ class WikhaSDK {
|
|
|
59
59
|
}
|
|
60
60
|
if (isNode) {
|
|
61
61
|
try {
|
|
62
|
-
|
|
62
|
+
// Use eval('require') to evade webpack/esbuild statically evaluating node-fetch for browsers
|
|
63
|
+
const req = eval('require');
|
|
64
|
+
return req('node-fetch');
|
|
63
65
|
}
|
|
64
66
|
catch (e) {
|
|
65
67
|
console.warn("Native fetch not found and 'node-fetch' not installed.");
|
|
@@ -95,7 +97,8 @@ class WikhaSDK {
|
|
|
95
97
|
}
|
|
96
98
|
const dataString = JSON.stringify({ ...data, merchant_id: this.merchantId });
|
|
97
99
|
if (isNode) {
|
|
98
|
-
const
|
|
100
|
+
const req = eval('require');
|
|
101
|
+
const crypto = req('crypto');
|
|
99
102
|
try {
|
|
100
103
|
const encrypted = crypto.publicEncrypt({
|
|
101
104
|
key: this.publicKey,
|