-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.js
More file actions
36 lines (32 loc) · 1.17 KB
/
Node.js
File metadata and controls
36 lines (32 loc) · 1.17 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
const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json());
const PI_API_KEY = 'YOUR_API_KEY'; // From Pi Developer Portal
const PI_API_URL = 'https://api.minepi.com/v2';
// Approve payment
app.post('/approve-payment/:paymentId', async (req, res) => {
try {
await axios.post(`${PI_API_URL}/payments/${req.params.paymentId}/approve`, {}, {
headers: { 'Authorization': `Key ${PI_API_KEY}` }
});
res.status(200).send('Approved');
} catch (error) {
console.error('Approval error:', error.response?.data || error.message);
res.status(500).send('Approval failed');
}
});
// Complete payment
app.post('/complete-payment/:paymentId', async (req, res) => {
const { txid } = req.body;
try {
await axios.post(`${PI_API_URL}/payments/${req.params.paymentId}/complete`, { txid }, {
headers: { 'Authorization': `Key ${PI_API_KEY}` }
});
res.status(200).send('Completed');
} catch (error) {
console.error('Completion error:', error.response?.data || error.message);
res.status(500).send('Completion failed');
}
});
app.listen(3000, () => console.log('Server running on port 3000'));