@ktmcp-cli/nowpayments 1.0.0
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/.env.example +17 -0
- package/AGENT.md +513 -0
- package/INSTALL.md +392 -0
- package/LICENSE +21 -0
- package/OPENCLAW.md +628 -0
- package/PROJECT_SUMMARY.md +305 -0
- package/README.md +375 -0
- package/banner.png +0 -0
- package/bin/nowpayments.js +89 -0
- package/examples/basic-payment.js +66 -0
- package/examples/invoice-flow.js +78 -0
- package/examples/monitor-payment.js +94 -0
- package/logo.png +0 -0
- package/openapi.json +2791 -0
- package/package.json +40 -0
- package/src/commands/auth.js +65 -0
- package/src/commands/currencies.js +95 -0
- package/src/commands/estimate.js +85 -0
- package/src/commands/invoice.js +188 -0
- package/src/commands/payment.js +241 -0
- package/src/commands/payout.js +184 -0
- package/src/commands/status.js +28 -0
- package/src/lib/api.js +133 -0
- package/src/lib/auth.js +70 -0
- package/src/lib/config.js +110 -0
- package/test.sh +250 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* NOWPayments CLI Entry Point
|
|
5
|
+
*
|
|
6
|
+
* A production-ready command-line interface for the NOWPayments cryptocurrency
|
|
7
|
+
* payment processing API.
|
|
8
|
+
*
|
|
9
|
+
* @see https://documenter.getpostman.com/view/7907941/S1a32n38
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const { Command } = require('commander');
|
|
13
|
+
const chalk = require('chalk');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
|
|
17
|
+
// Load environment variables
|
|
18
|
+
require('dotenv').config();
|
|
19
|
+
|
|
20
|
+
const program = new Command();
|
|
21
|
+
|
|
22
|
+
// Import commands
|
|
23
|
+
const statusCommand = require('../src/commands/status');
|
|
24
|
+
const currenciesCommand = require('../src/commands/currencies');
|
|
25
|
+
const estimateCommand = require('../src/commands/estimate');
|
|
26
|
+
const paymentCommand = require('../src/commands/payment');
|
|
27
|
+
const invoiceCommand = require('../src/commands/invoice');
|
|
28
|
+
const payoutCommand = require('../src/commands/payout');
|
|
29
|
+
const authCommand = require('../src/commands/auth');
|
|
30
|
+
|
|
31
|
+
// CLI metadata
|
|
32
|
+
program
|
|
33
|
+
.name('nowpayments')
|
|
34
|
+
.description('NOWPayments API CLI - Cryptocurrency payment processing from the command line')
|
|
35
|
+
.version('1.0.0')
|
|
36
|
+
.option('-k, --api-key <key>', 'NOWPayments API key (or set NOWPAYMENTS_API_KEY env var)')
|
|
37
|
+
.option('--sandbox', 'Use sandbox environment (sandbox.nowpayments.io)')
|
|
38
|
+
.option('--json', 'Output raw JSON responses')
|
|
39
|
+
.option('--debug', 'Enable debug logging')
|
|
40
|
+
.hook('preAction', (thisCommand, actionCommand) => {
|
|
41
|
+
// Make global options available to all commands
|
|
42
|
+
const opts = thisCommand.opts();
|
|
43
|
+
program._apiKey = opts.apiKey || process.env.NOWPAYMENTS_API_KEY;
|
|
44
|
+
program._sandbox = opts.sandbox || false;
|
|
45
|
+
program._json = opts.json || false;
|
|
46
|
+
program._debug = opts.debug || false;
|
|
47
|
+
|
|
48
|
+
if (program._debug) {
|
|
49
|
+
console.log(chalk.gray(`[DEBUG] Command: ${actionCommand.name()}`));
|
|
50
|
+
console.log(chalk.gray(`[DEBUG] Sandbox: ${program._sandbox}`));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Register commands
|
|
55
|
+
program.addCommand(authCommand);
|
|
56
|
+
program.addCommand(statusCommand);
|
|
57
|
+
program.addCommand(currenciesCommand);
|
|
58
|
+
program.addCommand(estimateCommand);
|
|
59
|
+
program.addCommand(paymentCommand);
|
|
60
|
+
program.addCommand(invoiceCommand);
|
|
61
|
+
program.addCommand(payoutCommand);
|
|
62
|
+
|
|
63
|
+
// Display helpful message when no command is provided
|
|
64
|
+
program.on('--help', () => {
|
|
65
|
+
console.log('');
|
|
66
|
+
console.log('Examples:');
|
|
67
|
+
console.log(' $ nowpayments status');
|
|
68
|
+
console.log(' $ nowpayments currencies --available');
|
|
69
|
+
console.log(' $ nowpayments estimate --from USD --to BTC --amount 100');
|
|
70
|
+
console.log(' $ nowpayments payment create --price 99.99 --currency USD --pay-currency BTC');
|
|
71
|
+
console.log(' $ nowpayments payment get <payment_id>');
|
|
72
|
+
console.log('');
|
|
73
|
+
console.log('Authentication:');
|
|
74
|
+
console.log(' Set NOWPAYMENTS_API_KEY in .env file or use --api-key flag');
|
|
75
|
+
console.log(' $ nowpayments auth set YOUR_API_KEY');
|
|
76
|
+
console.log('');
|
|
77
|
+
console.log('Documentation:');
|
|
78
|
+
console.log(' README.md - General usage and examples');
|
|
79
|
+
console.log(' AGENT.md - AI agent integration patterns');
|
|
80
|
+
console.log(' OPENCLAW.md - OpenClaw integration guide');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Parse and execute
|
|
84
|
+
program.parse(process.argv);
|
|
85
|
+
|
|
86
|
+
// Show help if no command provided
|
|
87
|
+
if (!process.argv.slice(2).length) {
|
|
88
|
+
program.outputHelp();
|
|
89
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Basic Payment Example
|
|
5
|
+
*
|
|
6
|
+
* Demonstrates creating a simple cryptocurrency payment with NOWPayments CLI.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { exec } = require('child_process');
|
|
10
|
+
const util = require('util');
|
|
11
|
+
|
|
12
|
+
const execPromise = util.promisify(exec);
|
|
13
|
+
|
|
14
|
+
async function createBasicPayment() {
|
|
15
|
+
console.log('Creating a basic payment...\n');
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Step 1: Check API status
|
|
19
|
+
console.log('1. Checking API status...');
|
|
20
|
+
await execPromise('nowpayments status');
|
|
21
|
+
console.log(' ✓ API is online\n');
|
|
22
|
+
|
|
23
|
+
// Step 2: Get estimate
|
|
24
|
+
console.log('2. Getting price estimate...');
|
|
25
|
+
const estimateResult = await execPromise(
|
|
26
|
+
'nowpayments --json estimate convert --from USD --to BTC --amount 100'
|
|
27
|
+
);
|
|
28
|
+
const estimate = JSON.parse(estimateResult.stdout);
|
|
29
|
+
console.log(` ✓ $100 USD ≈ ${estimate.estimated_amount} BTC\n`);
|
|
30
|
+
|
|
31
|
+
// Step 3: Create payment
|
|
32
|
+
console.log('3. Creating payment...');
|
|
33
|
+
const paymentResult = await execPromise(`
|
|
34
|
+
nowpayments --json payment create \
|
|
35
|
+
--price 100 \
|
|
36
|
+
--currency USD \
|
|
37
|
+
--pay-currency BTC \
|
|
38
|
+
--order-id "DEMO-${Date.now()}" \
|
|
39
|
+
--order-description "Basic payment example"
|
|
40
|
+
`);
|
|
41
|
+
const payment = JSON.parse(paymentResult.stdout);
|
|
42
|
+
|
|
43
|
+
console.log(' ✓ Payment created successfully!\n');
|
|
44
|
+
console.log('Payment Details:');
|
|
45
|
+
console.log(` Payment ID: ${payment.payment_id}`);
|
|
46
|
+
console.log(` Status: ${payment.payment_status}`);
|
|
47
|
+
console.log(` Pay Amount: ${payment.pay_amount} ${payment.pay_currency}`);
|
|
48
|
+
console.log(` Pay Address: ${payment.pay_address}`);
|
|
49
|
+
console.log(` Created: ${new Date(payment.created_at).toLocaleString()}\n`);
|
|
50
|
+
|
|
51
|
+
// Step 4: Check payment status
|
|
52
|
+
console.log('4. Checking payment status...');
|
|
53
|
+
const statusResult = await execPromise(
|
|
54
|
+
`nowpayments --json payment get ${payment.payment_id}`
|
|
55
|
+
);
|
|
56
|
+
const status = JSON.parse(statusResult.stdout);
|
|
57
|
+
console.log(` Status: ${status.payment_status}`);
|
|
58
|
+
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error('Error:', error.message);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Run the example
|
|
66
|
+
createBasicPayment();
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Invoice Flow Example
|
|
5
|
+
*
|
|
6
|
+
* Demonstrates creating and managing payment invoices.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { exec } = require('child_process');
|
|
10
|
+
const util = require('util');
|
|
11
|
+
|
|
12
|
+
const execPromise = util.promisify(exec);
|
|
13
|
+
|
|
14
|
+
async function createInvoiceFlow() {
|
|
15
|
+
console.log('Creating payment invoice...\n');
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Step 1: Create invoice
|
|
19
|
+
console.log('1. Creating invoice...');
|
|
20
|
+
const invoiceResult = await execPromise(`
|
|
21
|
+
nowpayments --json invoice create \
|
|
22
|
+
--price 49.99 \
|
|
23
|
+
--currency USD \
|
|
24
|
+
--order-id "INV-${Date.now()}" \
|
|
25
|
+
--order-description "Premium subscription" \
|
|
26
|
+
--success-url "https://example.com/success" \
|
|
27
|
+
--cancel-url "https://example.com/cancel"
|
|
28
|
+
`);
|
|
29
|
+
const invoice = JSON.parse(invoiceResult.stdout);
|
|
30
|
+
|
|
31
|
+
console.log(' ✓ Invoice created!\n');
|
|
32
|
+
console.log('Invoice Details:');
|
|
33
|
+
console.log(` Invoice ID: ${invoice.id}`);
|
|
34
|
+
console.log(` Status: ${invoice.invoice_status}`);
|
|
35
|
+
console.log(` Amount: $${invoice.price_amount} ${invoice.price_currency}`);
|
|
36
|
+
console.log(` Invoice URL: ${invoice.invoice_url}`);
|
|
37
|
+
console.log(` Created: ${new Date(invoice.created_at).toLocaleString()}\n`);
|
|
38
|
+
|
|
39
|
+
console.log('Share this URL with your customer:');
|
|
40
|
+
console.log(` ${invoice.invoice_url}\n`);
|
|
41
|
+
|
|
42
|
+
// Step 2: Check invoice status
|
|
43
|
+
console.log('2. Checking invoice status...');
|
|
44
|
+
const statusResult = await execPromise(
|
|
45
|
+
`nowpayments --json invoice get ${invoice.id}`
|
|
46
|
+
);
|
|
47
|
+
const status = JSON.parse(statusResult.stdout);
|
|
48
|
+
|
|
49
|
+
console.log(` Status: ${status.invoice_status}`);
|
|
50
|
+
|
|
51
|
+
if (status.payment_id) {
|
|
52
|
+
console.log(` Payment ID: ${status.payment_id}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Step 3: List recent invoices
|
|
56
|
+
console.log('\n3. Listing recent invoices...');
|
|
57
|
+
const listResult = await execPromise(
|
|
58
|
+
'nowpayments --json invoice list --limit 5'
|
|
59
|
+
);
|
|
60
|
+
const list = JSON.parse(listResult.stdout);
|
|
61
|
+
|
|
62
|
+
console.log(` Found ${list.data.length} invoices:\n`);
|
|
63
|
+
list.data.forEach((inv, i) => {
|
|
64
|
+
console.log(` ${i + 1}. ${inv.id}`);
|
|
65
|
+
console.log(` Status: ${inv.invoice_status}`);
|
|
66
|
+
console.log(` Amount: $${inv.price_amount}`);
|
|
67
|
+
console.log(` Created: ${new Date(inv.created_at).toLocaleString()}`);
|
|
68
|
+
console.log('');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error('Error:', error.message);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Run the example
|
|
78
|
+
createInvoiceFlow();
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Payment Monitoring Example
|
|
5
|
+
*
|
|
6
|
+
* Demonstrates monitoring a payment until completion or timeout.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { exec } = require('child_process');
|
|
10
|
+
const util = require('util');
|
|
11
|
+
|
|
12
|
+
const execPromise = util.promisify(exec);
|
|
13
|
+
|
|
14
|
+
// Configuration
|
|
15
|
+
const CHECK_INTERVAL = 30000; // 30 seconds
|
|
16
|
+
const MAX_DURATION = 30 * 60 * 1000; // 30 minutes
|
|
17
|
+
|
|
18
|
+
async function monitorPayment(paymentId) {
|
|
19
|
+
const startTime = Date.now();
|
|
20
|
+
|
|
21
|
+
console.log(`Monitoring payment: ${paymentId}`);
|
|
22
|
+
console.log(`Check interval: ${CHECK_INTERVAL / 1000}s`);
|
|
23
|
+
console.log(`Max duration: ${MAX_DURATION / 60000} minutes\n`);
|
|
24
|
+
|
|
25
|
+
while (Date.now() - startTime < MAX_DURATION) {
|
|
26
|
+
try {
|
|
27
|
+
// Check payment status
|
|
28
|
+
const result = await execPromise(
|
|
29
|
+
`nowpayments --json payment get ${paymentId}`
|
|
30
|
+
);
|
|
31
|
+
const payment = JSON.parse(result.stdout);
|
|
32
|
+
|
|
33
|
+
const elapsed = Math.round((Date.now() - startTime) / 1000);
|
|
34
|
+
console.log(`[${elapsed}s] Status: ${payment.payment_status}`);
|
|
35
|
+
|
|
36
|
+
// Check for terminal states
|
|
37
|
+
switch (payment.payment_status) {
|
|
38
|
+
case 'finished':
|
|
39
|
+
console.log('\n✓ Payment completed successfully!');
|
|
40
|
+
console.log(` Amount paid: ${payment.actually_paid} ${payment.pay_currency}`);
|
|
41
|
+
console.log(` Outcome: ${payment.outcome_amount} ${payment.outcome_currency}`);
|
|
42
|
+
return { success: true, payment };
|
|
43
|
+
|
|
44
|
+
case 'failed':
|
|
45
|
+
console.log('\n✗ Payment failed');
|
|
46
|
+
return { success: false, reason: 'failed', payment };
|
|
47
|
+
|
|
48
|
+
case 'expired':
|
|
49
|
+
console.log('\n✗ Payment expired');
|
|
50
|
+
return { success: false, reason: 'expired', payment };
|
|
51
|
+
|
|
52
|
+
case 'partially_paid':
|
|
53
|
+
console.log(`\n⚠ Partially paid: ${payment.actually_paid}/${payment.pay_amount} ${payment.pay_currency}`);
|
|
54
|
+
// Continue monitoring
|
|
55
|
+
break;
|
|
56
|
+
|
|
57
|
+
case 'waiting':
|
|
58
|
+
case 'confirming':
|
|
59
|
+
case 'confirmed':
|
|
60
|
+
case 'sending':
|
|
61
|
+
// Still processing, continue monitoring
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Wait before next check
|
|
66
|
+
await new Promise(resolve => setTimeout(resolve, CHECK_INTERVAL));
|
|
67
|
+
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error(`Error checking payment: ${error.message}`);
|
|
70
|
+
await new Promise(resolve => setTimeout(resolve, CHECK_INTERVAL));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.log('\n⏱ Monitoring timeout reached');
|
|
75
|
+
return { success: false, reason: 'timeout' };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Get payment ID from command line
|
|
79
|
+
const paymentId = process.argv[2];
|
|
80
|
+
|
|
81
|
+
if (!paymentId) {
|
|
82
|
+
console.error('Usage: node monitor-payment.js <payment_id>');
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Run monitoring
|
|
87
|
+
monitorPayment(paymentId)
|
|
88
|
+
.then(result => {
|
|
89
|
+
process.exit(result.success ? 0 : 1);
|
|
90
|
+
})
|
|
91
|
+
.catch(error => {
|
|
92
|
+
console.error('Fatal error:', error);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
package/logo.png
ADDED
|
Binary file
|