-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-flow.ts
More file actions
48 lines (40 loc) · 1.57 KB
/
Copy pathtest-flow.ts
File metadata and controls
48 lines (40 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { RasediClient, Gateway } from './src';
const privateKey = `-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIPDnRmDLxXvyxszuCOMT7F50fDCHllNHMf4XgPNJ5YWx
-----END PRIVATE KEY-----`;
const secretKey = 'test_ipstIrJ1vp2fuDogJMn_3VyP0hvA0So9D0UDMhCDF4BaIg';
const client = new RasediClient(privateKey, secretKey);
async function runTests() {
try {
console.log("1. Creating Payment...");
const createResp = await client.createPayment({
amount: "1050",
title: "Test Payment",
description: "Testing Rasedi SDK",
gateways: [Gateway.ZAIN, Gateway.FIB, Gateway.CREDIT_CARD],
redirectUrl: "https://example.com/success",
callbackUrl: "https://example.com/webhook",
collectFeeFromCustomer: false,
collectCustomerEmail: true,
collectCustomerPhoneNumber: true
});
const refCode = createResp.body.referenceCode;
console.log(`✅ Payment Created!`);
console.log(`Reference Code: ${refCode}`);
console.log(`Payment Link: ${createResp.body.redirectUrl}`);
console.log("\n2. Getting Payment Status...");
const statusResp = await client.getPaymentByReference(refCode);
console.log(`✅ Status retrieved: ${statusResp.body.status}`);
console.log("\n3. Canceling Payment...");
const cancelResp = await client.cancelPayment(refCode);
console.log(`✅ Cancelation successful, new status: ${cancelResp.body.status}`);
} catch (err: any) {
if (err.response) {
console.error("API Error:");
console.error(err.response.data);
} else {
console.error(err);
}
}
}
runTests();