-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (29 loc) · 788 Bytes
/
Copy pathindex.js
File metadata and controls
34 lines (29 loc) · 788 Bytes
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
import axios from "axios";
const API_KEY = "pk_YOUR_API_KEY";
const createPayment = async () => {
try {
const paymentData = {
phone: "255657779003",
amount: 5000,
name: "Benjamini Omary",
email: "sam@gmail.com",
};
const response = await axios.post(
"https://sonicpesa.com/api/payment/create", paymentData,
{
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`,
},
}
);
console.log("Payment created successfully: ", response.data);
} catch (error) {
if (error.response) {
console.error("❌ API Error:", error.response.data);
} else {
console.error("❌ Request Error:", error.message);
}
}
}
createPayment();