import { MoneroPayment } from 'monero-payment-sdk';
// Initialize the client
const moneroClient = new MoneroPayment({
gatewayUrl: 'https://your-gateway-url.com',
apiKey: 'your-optional-api-key'
});
// Create an invoice
const createInvoice = async () => {
try {
const { id, address } = await moneroClient.createInvoice({
amount: 0.01,
description: 'Premium subscription',
refund: 'optional-refund-address'
});
console.log(`Created invoice: ${id}, Pay to: ${address}`);
return { id, address };
} catch (error) {
console.error('Failed to create invoice:', error);
}
};
// Check payment status
const checkPayment = async (id) => {
try {
const info = await moneroClient.checkInvoice(id);
console.log(`Payment status: ${info.status}`);
return info;
} catch (error) {
console.error('Failed to check invoice:', error);
}
};
// Wait for payment completion
const waitForPayment = async (id) => {
try {
await moneroClient.waitForPayment(id);
console.log('Payment received!');
} catch (error) {
console.error('Payment failed or timed out:', error);
}
};