@wikha/sdk 1.1.12 → 1.1.14
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 +17 -15
- package/dist/src/sdk.js +5 -2
- package/dist/wikha-sdk.umd.js +1 -1
- package/dist/wikha-sdk.umd.js.LICENSE.txt +0 -2
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
Import the `WikhaSDK` class and initialize it with your API key, merchant ID, and public key:
|
|
6
6
|
|
|
7
7
|
```typescript
|
|
8
|
-
import WikhaSDK from 'wikha
|
|
8
|
+
import { WikhaSDK } from '@wikha/sdk';
|
|
9
9
|
|
|
10
10
|
const sdk = new WikhaSDK(
|
|
11
11
|
'YOUR_API_KEY',
|
|
12
|
-
'YOUR_MERCHANT_ID'
|
|
13
|
-
'YOUR_PUBLIC_KEY'
|
|
12
|
+
'YOUR_MERCHANT_ID'
|
|
14
13
|
);
|
|
15
14
|
|
|
16
15
|
// You can also access static enums for convenience
|
|
@@ -19,17 +18,22 @@ console.log(WikhaSDK.Environment.sandbox);
|
|
|
19
18
|
|
|
20
19
|
|
|
21
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
|
+
|
|
22
27
|
## Use the processPayment method to initiate a payment.
|
|
23
28
|
You'll need to provide a WikhaPayload object with the necessary payment details.
|
|
24
29
|
|
|
25
30
|
```TypeScript
|
|
26
31
|
|
|
27
|
-
import WikhaSDK from 'wikha
|
|
32
|
+
import { WikhaSDK } from '@wikha/sdk';
|
|
28
33
|
|
|
29
34
|
const sdk = new WikhaSDK(
|
|
30
35
|
'YOUR_API_KEY',
|
|
31
|
-
'YOUR_MERCHANT_ID'
|
|
32
|
-
'YOUR_PUBLIC_KEY'
|
|
36
|
+
'YOUR_MERCHANT_ID'
|
|
33
37
|
);
|
|
34
38
|
|
|
35
39
|
async function initiatePayment() {
|
|
@@ -60,13 +64,12 @@ initiatePayment();
|
|
|
60
64
|
# Query transaction status
|
|
61
65
|
|
|
62
66
|
```typescript
|
|
63
|
-
import WikhaSDK from 'wikha
|
|
67
|
+
import { WikhaSDK } from '@wikha/sdk';
|
|
64
68
|
|
|
65
|
-
// Initialize your SDK instance (API Key
|
|
69
|
+
// Initialize your SDK instance (API Key and Merchant ID)
|
|
66
70
|
const sdk = new WikhaSDK(
|
|
67
71
|
'YOUR_API_KEY',
|
|
68
|
-
'YOUR_MERCHANT_ID'
|
|
69
|
-
'YOUR_PUBLIC_KEY'
|
|
72
|
+
'YOUR_MERCHANT_ID'
|
|
70
73
|
);
|
|
71
74
|
|
|
72
75
|
async function checkTransactionStatus(transactionId: string) {
|
|
@@ -96,7 +99,7 @@ checkTransactionStatus('YOUR_TRANSACTION_ID');
|
|
|
96
99
|
#Using Static Enums
|
|
97
100
|
|
|
98
101
|
```typescript
|
|
99
|
-
import WikhaSDK from 'wikha
|
|
102
|
+
import { WikhaSDK, PaymentEventPayload, PaymentType, PaymentStatus, PaymentProviderType, Environment } from '@wikha/sdk';
|
|
100
103
|
|
|
101
104
|
function handlePaymentEvent(event: WikhaSDK.PaymentEventPayload) {
|
|
102
105
|
console.log('Payment Event Received:', event);
|
|
@@ -257,16 +260,15 @@ console.log('Sandbox Environment Value:', WikhaSDK.Environment.sandbox);
|
|
|
257
260
|
</button>
|
|
258
261
|
</div>
|
|
259
262
|
|
|
260
|
-
<script src="https://unpkg.com/
|
|
263
|
+
<script src="https://unpkg.com/@wikha/sdk@latest/dist/wikha-sdk.umd.js"></script>
|
|
261
264
|
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
|
|
262
265
|
<script>
|
|
263
266
|
let sdk;
|
|
264
267
|
let transactionId;
|
|
265
268
|
|
|
266
269
|
async function initiatePayment() {
|
|
267
|
-
const apiKey = '
|
|
270
|
+
const apiKey = 'API_KEY'; // Replace with your actual API key
|
|
268
271
|
const merchantId = 'MERCHANT_ID'; // Replace with your actual merchant ID
|
|
269
|
-
const publicKey = 'PUBLIC_KEY'; // Replace with your actual public key
|
|
270
272
|
|
|
271
273
|
const provider = document.getElementById('provider').value;
|
|
272
274
|
const payer_phone = document.getElementById('payer_phone').value;
|
|
@@ -286,7 +288,7 @@ console.log('Sandbox Environment Value:', WikhaSDK.Environment.sandbox);
|
|
|
286
288
|
// You can add optional fields like notify_url and return_url here
|
|
287
289
|
};
|
|
288
290
|
|
|
289
|
-
sdk = new wikha.WikhaSDK(apiKey, merchantId
|
|
291
|
+
sdk = new wikha.WikhaSDK(apiKey, merchantId);
|
|
290
292
|
const responseDiv = document.getElementById('paymentResponse');
|
|
291
293
|
const errorDiv = document.getElementById('paymentError');
|
|
292
294
|
const checkTransactionButton = document.getElementById('checkTransactionButton');
|
package/dist/src/sdk.js
CHANGED
|
@@ -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,
|