paymongo-cli 1.4.7 → 1.4.8
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/AGENTS.md +8 -6
- package/CHANGELOG.md +19 -0
- package/README.md +7 -5
- package/TESTING.md +6 -7
- package/dist/.tsbuildinfo +1 -1
- package/dist/commands/config/actions.js +233 -0
- package/dist/commands/config/helpers.js +153 -0
- package/dist/commands/config/rate-limit.js +138 -0
- package/dist/commands/config.js +5 -566
- package/dist/commands/dev.js +4 -0
- package/dist/commands/init.js +1 -1
- package/dist/commands/login.js +1 -1
- package/dist/commands/payments/actions.js +346 -0
- package/dist/commands/payments/helpers.js +62 -0
- package/dist/commands/payments.js +2 -459
- package/dist/commands/trigger/actions.js +293 -0
- package/dist/commands/trigger/helpers.js +230 -0
- package/dist/commands/trigger.js +3 -526
- package/dist/commands/webhooks/actions.js +426 -0
- package/dist/commands/webhooks/helpers.js +42 -0
- package/dist/commands/webhooks.js +2 -494
- package/dist/services/config/manager.js +1 -1
- package/dist/services/dev/server.js +2 -2
- package/dist/types/schemas.js +12 -0
- package/package.json +1 -1
|
@@ -1,444 +1,5 @@
|
|
|
1
|
-
import Table from 'cli-table3';
|
|
2
1
|
import { Command } from 'commander';
|
|
3
|
-
import
|
|
4
|
-
import ConfigManager from '../services/config/manager.js';
|
|
5
|
-
import ApiClient from '../services/api/client.js';
|
|
6
|
-
import { PaymentSimulator } from '../services/payments/simulator.js';
|
|
7
|
-
import { BulkOperations } from '../utils/bulk.js';
|
|
8
|
-
import Spinner from '../utils/spinner.js';
|
|
9
|
-
import { CommandError } from '../utils/errors.js';
|
|
10
|
-
export async function exportAction(options) {
|
|
11
|
-
const spinner = new Spinner();
|
|
12
|
-
const configManager = new ConfigManager();
|
|
13
|
-
try {
|
|
14
|
-
spinner.start('Loading configuration...');
|
|
15
|
-
const config = await configManager.load();
|
|
16
|
-
if (!config) {
|
|
17
|
-
spinner.fail('No configuration found');
|
|
18
|
-
console.log(chalk.yellow('No PayMongo configuration found.'));
|
|
19
|
-
console.log(chalk.gray("Run 'paymongo init' to set up your project first."));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
spinner.succeed('Configuration loaded');
|
|
23
|
-
const limit = parseInt(options.limit || '100');
|
|
24
|
-
if (isNaN(limit) || limit < 1 || limit > 1000) {
|
|
25
|
-
throw new Error('Limit must be a number between 1 and 1000');
|
|
26
|
-
}
|
|
27
|
-
spinner.start(`Fetching up to ${limit} payments...`);
|
|
28
|
-
const apiClient = new ApiClient({ config });
|
|
29
|
-
const payments = await apiClient.listPayments(limit);
|
|
30
|
-
spinner.succeed(`Found ${payments.length} payments`);
|
|
31
|
-
if (payments.length === 0) {
|
|
32
|
-
console.log(chalk.yellow('No payments found to export.'));
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
let filename = options.file;
|
|
36
|
-
if (!filename) {
|
|
37
|
-
filename = BulkOperations.generateFilename('payments', config.environment);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
filename = BulkOperations.ensureJsonExtension(filename);
|
|
41
|
-
}
|
|
42
|
-
spinner.start(`Exporting to ${filename}...`);
|
|
43
|
-
await BulkOperations.exportPayments(payments, filename, config.environment);
|
|
44
|
-
spinner.succeed('Export completed');
|
|
45
|
-
console.log('\n' + chalk.green('✅ Payments exported successfully!'));
|
|
46
|
-
console.log('');
|
|
47
|
-
console.log(`${chalk.bold('File:')} ${filename}`);
|
|
48
|
-
console.log(`${chalk.bold('Payments:')} ${payments.length}`);
|
|
49
|
-
console.log(`${chalk.bold('Environment:')} ${config.environment}`);
|
|
50
|
-
console.log(`${chalk.bold('Total size:')} ${payments.length} payments`);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
spinner.stop();
|
|
54
|
-
const err = error;
|
|
55
|
-
console.error(chalk.red('❌ Failed to export payments:'), err.message);
|
|
56
|
-
throw new CommandError();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export async function importAction(filename, options) {
|
|
60
|
-
const spinner = new Spinner();
|
|
61
|
-
try {
|
|
62
|
-
spinner.start(`Importing payments from ${filename}...`);
|
|
63
|
-
const { payments, metadata } = await BulkOperations.importPayments(filename);
|
|
64
|
-
spinner.succeed(`Loaded ${payments.length} payments from export`);
|
|
65
|
-
if (options.json) {
|
|
66
|
-
console.log(JSON.stringify({ payments, metadata }, null, 2));
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
console.log('\n' + chalk.green('✅ Payments imported successfully!'));
|
|
70
|
-
console.log('');
|
|
71
|
-
console.log(`${chalk.bold('Source:')} ${filename}`);
|
|
72
|
-
console.log(`${chalk.bold('Payments:')} ${payments.length}`);
|
|
73
|
-
console.log(`${chalk.bold('Exported from:')} ${metadata.environment} environment`);
|
|
74
|
-
console.log(`${chalk.bold('Export date:')} ${new Date(metadata.exported_at).toLocaleString()}`);
|
|
75
|
-
console.log('\n' + chalk.yellow('⚠️ Important Notes:'));
|
|
76
|
-
console.log(chalk.gray('• Payment data imported for reference only'));
|
|
77
|
-
console.log(chalk.gray('• Actual payments cannot be recreated through the API'));
|
|
78
|
-
console.log(chalk.gray('• Use this for data analysis, migration planning, or testing'));
|
|
79
|
-
if (payments.length > 0) {
|
|
80
|
-
console.log('\n' + chalk.bold('Sample Payment IDs:'));
|
|
81
|
-
payments.slice(0, 5).forEach((payment, index) => {
|
|
82
|
-
const amount = (payment.attributes.amount / 100).toFixed(2);
|
|
83
|
-
console.log(` ${index + 1}. ${payment.id} - ₱${amount} ${payment.attributes.currency}`);
|
|
84
|
-
});
|
|
85
|
-
if (payments.length > 5) {
|
|
86
|
-
console.log(chalk.gray(` ... and ${payments.length - 5} more`));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
spinner.stop();
|
|
92
|
-
const err = error;
|
|
93
|
-
console.error(chalk.red('❌ Failed to import payments:'), err.message);
|
|
94
|
-
throw new CommandError();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
export async function listAction(options) {
|
|
98
|
-
const spinner = new Spinner();
|
|
99
|
-
const configManager = new ConfigManager();
|
|
100
|
-
try {
|
|
101
|
-
spinner.start('Loading configuration...');
|
|
102
|
-
const config = await configManager.load();
|
|
103
|
-
if (!config) {
|
|
104
|
-
spinner.fail('No configuration found');
|
|
105
|
-
console.log(chalk.yellow('No PayMongo configuration found.'));
|
|
106
|
-
console.log(chalk.gray("Run 'paymongo init' to set up your project first."));
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
spinner.succeed('Configuration loaded');
|
|
110
|
-
spinner.start('Fetching payments...');
|
|
111
|
-
const apiClient = new ApiClient({ config });
|
|
112
|
-
const payments = await apiClient.listPayments(parseInt(options.limit || '10'));
|
|
113
|
-
spinner.succeed(`Found ${payments.length} payments`);
|
|
114
|
-
if (options.json) {
|
|
115
|
-
console.log(JSON.stringify(payments, null, 2));
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (payments.length === 0) {
|
|
119
|
-
console.log(chalk.gray('No payments found.'));
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const table = new Table({
|
|
123
|
-
head: [
|
|
124
|
-
chalk.bold('ID'),
|
|
125
|
-
chalk.bold('Amount'),
|
|
126
|
-
chalk.bold('Status'),
|
|
127
|
-
chalk.bold('Created'),
|
|
128
|
-
chalk.bold('Description'),
|
|
129
|
-
],
|
|
130
|
-
colWidths: [25, 12, 12, 12, 30],
|
|
131
|
-
style: {
|
|
132
|
-
head: [],
|
|
133
|
-
border: [],
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
payments.forEach((payment) => {
|
|
137
|
-
const amount = `₱${(payment.attributes.amount / 100).toFixed(2)}`;
|
|
138
|
-
const status = payment.attributes.status;
|
|
139
|
-
const created = new Date(payment.attributes.created_at * 1000).toLocaleDateString();
|
|
140
|
-
const description = payment.attributes.description || 'N/A';
|
|
141
|
-
table.push([
|
|
142
|
-
chalk.cyan(payment.id.substring(0, 20) + (payment.id.length > 20 ? '...' : '')),
|
|
143
|
-
chalk.yellow(amount),
|
|
144
|
-
getStatusColor(status)(status),
|
|
145
|
-
chalk.gray(created),
|
|
146
|
-
chalk.white(description.length > 25 ? description.substring(0, 22) + '...' : description),
|
|
147
|
-
]);
|
|
148
|
-
});
|
|
149
|
-
console.log('\n' + chalk.bold('Recent Payments'));
|
|
150
|
-
console.log(chalk.gray('─'.repeat(95)));
|
|
151
|
-
console.log(table.toString());
|
|
152
|
-
console.log(chalk.gray(`Total: ${payments.length} payments`));
|
|
153
|
-
console.log('');
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
spinner.stop();
|
|
157
|
-
const err = error;
|
|
158
|
-
console.error(chalk.red('❌ Failed to fetch payments:'), err.message);
|
|
159
|
-
throw new CommandError();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
export async function showAction(id, options) {
|
|
163
|
-
const spinner = new Spinner();
|
|
164
|
-
const configManager = new ConfigManager();
|
|
165
|
-
try {
|
|
166
|
-
spinner.start('Loading configuration...');
|
|
167
|
-
const config = await configManager.load();
|
|
168
|
-
if (!config) {
|
|
169
|
-
spinner.fail('No configuration found');
|
|
170
|
-
console.log(chalk.yellow('No PayMongo configuration found.'));
|
|
171
|
-
console.log(chalk.gray("Run 'paymongo init' to set up your project first."));
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
spinner.succeed('Configuration loaded');
|
|
175
|
-
spinner.start('Fetching payment details...');
|
|
176
|
-
const apiClient = new ApiClient({ config });
|
|
177
|
-
const payment = await apiClient.getPayment(id);
|
|
178
|
-
spinner.succeed('Payment details loaded');
|
|
179
|
-
if (options.json) {
|
|
180
|
-
console.log(JSON.stringify(payment, null, 2));
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
const attrs = payment.attributes;
|
|
184
|
-
const amount = (attrs.amount / 100).toFixed(2);
|
|
185
|
-
const fees = attrs.fees ? (attrs.fees / 100).toFixed(2) : '0.00';
|
|
186
|
-
const netAmount = attrs.net_amount ? (attrs.net_amount / 100).toFixed(2) : '0.00';
|
|
187
|
-
console.log('\n' + chalk.bold('Payment Details'));
|
|
188
|
-
console.log(chalk.gray('─'.repeat(50)));
|
|
189
|
-
console.log(`${chalk.bold('ID:')} ${payment.id}`);
|
|
190
|
-
console.log(`${chalk.bold('Amount:')} ₱${amount} ${attrs.currency}`);
|
|
191
|
-
console.log(`${chalk.bold('Status:')} ${getStatusColor(attrs.status)(attrs.status)}`);
|
|
192
|
-
console.log(`${chalk.bold('Description:')} ${attrs.description || 'N/A'}`);
|
|
193
|
-
console.log(`${chalk.bold('External Reference:')} ${attrs.external_reference_number || 'N/A'}`);
|
|
194
|
-
console.log(`${chalk.bold('Paid At:')} ${attrs.paid_at ? new Date(attrs.paid_at * 1000).toLocaleString() : 'N/A'}`);
|
|
195
|
-
console.log(`${chalk.bold('Created:')} ${new Date(attrs.created_at * 1000).toLocaleString()}`);
|
|
196
|
-
console.log(`${chalk.bold('Updated:')} ${new Date(attrs.updated_at * 1000).toLocaleString()}`);
|
|
197
|
-
if (attrs.fees) {
|
|
198
|
-
console.log(`${chalk.bold('Fees:')} ₱${fees}`);
|
|
199
|
-
console.log(`${chalk.bold('Net Amount:')} ₱${netAmount}`);
|
|
200
|
-
}
|
|
201
|
-
if (attrs.source) {
|
|
202
|
-
console.log(`${chalk.bold('Payment Method:')} ${attrs.source.attributes.type}`);
|
|
203
|
-
}
|
|
204
|
-
console.log(`${chalk.bold('Payment Intent:')} ${attrs.payment_intent_id}`);
|
|
205
|
-
console.log('');
|
|
206
|
-
console.log(chalk.gray(`View in dashboard: https://dashboard.paymongo.com/payments/${payment.id}`));
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
spinner.stop();
|
|
210
|
-
const err = error;
|
|
211
|
-
console.error(chalk.red('❌ Failed to fetch payment:'), err.message);
|
|
212
|
-
throw new CommandError();
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
export async function createIntentAction(options) {
|
|
216
|
-
const spinner = new Spinner();
|
|
217
|
-
const configManager = new ConfigManager();
|
|
218
|
-
try {
|
|
219
|
-
spinner.start('Loading configuration...');
|
|
220
|
-
const config = await configManager.load();
|
|
221
|
-
if (!config) {
|
|
222
|
-
spinner.fail('No configuration found');
|
|
223
|
-
console.log(chalk.yellow('No PayMongo configuration found.'));
|
|
224
|
-
console.log(chalk.gray("Run 'paymongo init' to set up your project first."));
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
spinner.succeed('Configuration loaded');
|
|
228
|
-
const amount = parseInt(options.amount || '10000');
|
|
229
|
-
if (isNaN(amount) || amount <= 0) {
|
|
230
|
-
throw new Error('Amount must be a positive number in centavos');
|
|
231
|
-
}
|
|
232
|
-
spinner.start('Creating payment intent...');
|
|
233
|
-
const apiClient = new ApiClient({ config });
|
|
234
|
-
const paymentIntent = await apiClient.createPaymentIntent(amount, options.currency || 'PHP', options.description);
|
|
235
|
-
spinner.succeed('Payment intent created');
|
|
236
|
-
if (options.json) {
|
|
237
|
-
console.log(JSON.stringify(paymentIntent, null, 2));
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const attrs = paymentIntent.attributes;
|
|
241
|
-
const displayAmount = (attrs.amount / 100).toFixed(2);
|
|
242
|
-
console.log('\n' + chalk.bold('Payment Intent Created'));
|
|
243
|
-
console.log(chalk.gray('─'.repeat(50)));
|
|
244
|
-
console.log(`${chalk.bold('ID:')} ${paymentIntent.id}`);
|
|
245
|
-
console.log(`${chalk.bold('Amount:')} ₱${displayAmount} ${attrs.currency}`);
|
|
246
|
-
console.log(`${chalk.bold('Status:')} ${getStatusColor(attrs.status)(attrs.status)}`);
|
|
247
|
-
console.log(`${chalk.bold('Description:')} ${attrs.description || 'N/A'}`);
|
|
248
|
-
console.log(`${chalk.bold('Created:')} ${new Date(attrs.created_at * 1000).toLocaleString()}`);
|
|
249
|
-
console.log('');
|
|
250
|
-
console.log(chalk.gray(`Use this ID to attach a payment method and confirm the payment.`));
|
|
251
|
-
}
|
|
252
|
-
catch (error) {
|
|
253
|
-
spinner.stop();
|
|
254
|
-
const err = error;
|
|
255
|
-
console.error(chalk.red('❌ Failed to create payment intent:'), err.message);
|
|
256
|
-
throw new CommandError();
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
export async function confirmAction(intentId, options) {
|
|
260
|
-
const spinner = new Spinner();
|
|
261
|
-
const configManager = new ConfigManager();
|
|
262
|
-
try {
|
|
263
|
-
spinner.start('Loading configuration...');
|
|
264
|
-
const config = await configManager.load();
|
|
265
|
-
if (!config) {
|
|
266
|
-
spinner.fail('No configuration found');
|
|
267
|
-
console.log(chalk.yellow('No PayMongo configuration found.'));
|
|
268
|
-
console.log(chalk.gray("Run 'paymongo init' to set up your project first."));
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
spinner.succeed('Configuration loaded');
|
|
272
|
-
if (options.simulate) {
|
|
273
|
-
if (!options.method) {
|
|
274
|
-
throw new Error('Payment method is required for simulation. Use --method <gcash|maya|grabpay>');
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
if (!options.paymentMethod) {
|
|
279
|
-
throw new Error('Payment method ID is required. Use --payment-method <id>');
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
if (options.simulate) {
|
|
283
|
-
const validMethods = ['gcash', 'maya', 'grabpay'];
|
|
284
|
-
const validOutcomes = ['success', 'failure', 'timeout'];
|
|
285
|
-
if (!options.method || !validMethods.includes(options.method)) {
|
|
286
|
-
throw new Error(`Invalid or missing payment method for simulation. Must be one of: ${validMethods.join(', ')}`);
|
|
287
|
-
}
|
|
288
|
-
if (!validOutcomes.includes(options.outcome || 'success')) {
|
|
289
|
-
throw new Error(`Invalid simulation outcome. Must be one of: ${validOutcomes.join(', ')}`);
|
|
290
|
-
}
|
|
291
|
-
const delayMs = options.delay ? parseInt(options.delay) : undefined;
|
|
292
|
-
if (options.delay && (delayMs === undefined || isNaN(delayMs) || delayMs <= 0)) {
|
|
293
|
-
throw new Error('Simulation delay must be a positive number in milliseconds');
|
|
294
|
-
}
|
|
295
|
-
console.log('\n' + chalk.bold('🧪 Payment Simulation Mode'));
|
|
296
|
-
console.log(chalk.gray('─'.repeat(50)));
|
|
297
|
-
console.log(`${chalk.bold('Method:')} ${options.method.toUpperCase()}`);
|
|
298
|
-
console.log(`${chalk.bold('Outcome:')} ${options.outcome}`);
|
|
299
|
-
console.log(`${chalk.bold('Delay:')} ${delayMs ? `${delayMs}ms` : 'Default for method/outcome'}`);
|
|
300
|
-
spinner.start(`Simulating ${options.method} payment...`);
|
|
301
|
-
const simulator = new PaymentSimulator();
|
|
302
|
-
const simulationOptions = {
|
|
303
|
-
paymentMethod: options.method,
|
|
304
|
-
outcome: (options.outcome || 'success'),
|
|
305
|
-
...(delayMs !== undefined && { delayMs }),
|
|
306
|
-
};
|
|
307
|
-
const result = await simulator.simulatePaymentConfirmation(intentId, simulationOptions);
|
|
308
|
-
spinner.succeed(`Simulation completed (${result.delayApplied}ms)`);
|
|
309
|
-
if (options.json) {
|
|
310
|
-
console.log(JSON.stringify(result.paymentIntent, null, 2));
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
const attrs = result.paymentIntent.attributes;
|
|
314
|
-
const displayAmount = (attrs.amount / 100).toFixed(2);
|
|
315
|
-
console.log('\n' + chalk.bold('Payment Intent Confirmed (Simulated)'));
|
|
316
|
-
console.log(chalk.gray('─'.repeat(50)));
|
|
317
|
-
console.log(`${chalk.bold('ID:')} ${result.paymentIntent.id}`);
|
|
318
|
-
console.log(`${chalk.bold('Amount:')} ₱${displayAmount} ${attrs.currency}`);
|
|
319
|
-
console.log(`${chalk.bold('Status:')} ${getStatusColor(attrs.status)(attrs.status)}`);
|
|
320
|
-
console.log(`${chalk.bold('Description:')} ${attrs.description || 'N/A'}`);
|
|
321
|
-
console.log(`${chalk.bold('Created:')} ${new Date(attrs.created_at * 1000).toLocaleString()}`);
|
|
322
|
-
console.log(`${chalk.bold('Updated:')} ${new Date(attrs.updated_at * 1000).toLocaleString()}`);
|
|
323
|
-
console.log('');
|
|
324
|
-
console.log(chalk.yellow('⚠️ This was a simulation - no real payment was processed'));
|
|
325
|
-
console.log(chalk.gray(`Simulation type: ${result.simulationType} (${result.delayApplied}ms delay)`));
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
spinner.start('Confirming payment intent...');
|
|
329
|
-
const apiClient = new ApiClient({ config });
|
|
330
|
-
const result = await apiClient.confirmPaymentIntent(intentId, options.paymentMethod ?? '', options.returnUrl);
|
|
331
|
-
spinner.succeed('Payment intent confirmed');
|
|
332
|
-
if (options.json) {
|
|
333
|
-
console.log(JSON.stringify(result, null, 2));
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
const attrs = result.attributes;
|
|
337
|
-
const displayAmount = (attrs.amount / 100).toFixed(2);
|
|
338
|
-
console.log('\n' + chalk.bold('Payment Intent Confirmed'));
|
|
339
|
-
console.log(chalk.gray('─'.repeat(50)));
|
|
340
|
-
console.log(`${chalk.bold('ID:')} ${result.id}`);
|
|
341
|
-
console.log(`${chalk.bold('Amount:')} ₱${displayAmount} ${attrs.currency}`);
|
|
342
|
-
console.log(`${chalk.bold('Status:')} ${getStatusColor(attrs.status)(attrs.status)}`);
|
|
343
|
-
console.log(`${chalk.bold('Description:')} ${attrs.description || 'N/A'}`);
|
|
344
|
-
console.log(`${chalk.bold('Created:')} ${new Date(attrs.created_at * 1000).toLocaleString()}`);
|
|
345
|
-
console.log(`${chalk.bold('Updated:')} ${new Date(attrs.updated_at * 1000).toLocaleString()}`);
|
|
346
|
-
console.log('');
|
|
347
|
-
console.log(chalk.gray(`Payment will be processed. Check status with: paymongo payments show-intent ${result.id}`));
|
|
348
|
-
}
|
|
349
|
-
catch (error) {
|
|
350
|
-
spinner.stop();
|
|
351
|
-
const err = error;
|
|
352
|
-
console.error(chalk.red('❌ Failed to confirm payment intent:'), err.message);
|
|
353
|
-
throw new CommandError();
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
export async function captureAction(intentId, options) {
|
|
357
|
-
const spinner = new Spinner();
|
|
358
|
-
const configManager = new ConfigManager();
|
|
359
|
-
try {
|
|
360
|
-
spinner.start('Loading configuration...');
|
|
361
|
-
const config = await configManager.load();
|
|
362
|
-
if (!config) {
|
|
363
|
-
spinner.fail('No configuration found');
|
|
364
|
-
console.log(chalk.yellow('No PayMongo configuration found.'));
|
|
365
|
-
console.log(chalk.gray("Run 'paymongo init' to set up your project first."));
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
spinner.succeed('Configuration loaded');
|
|
369
|
-
spinner.start('Capturing payment intent...');
|
|
370
|
-
const apiClient = new ApiClient({ config });
|
|
371
|
-
const result = await apiClient.capturePaymentIntent(intentId);
|
|
372
|
-
spinner.succeed('Payment intent captured');
|
|
373
|
-
if (options.json) {
|
|
374
|
-
console.log(JSON.stringify(result, null, 2));
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
const attrs = result.attributes;
|
|
378
|
-
const displayAmount = (attrs.amount / 100).toFixed(2);
|
|
379
|
-
console.log('\n' + chalk.bold('Payment Intent Captured'));
|
|
380
|
-
console.log(chalk.gray('─'.repeat(50)));
|
|
381
|
-
console.log(`${chalk.bold('ID:')} ${result.id}`);
|
|
382
|
-
console.log(`${chalk.bold('Amount:')} ₱${displayAmount} ${attrs.currency}`);
|
|
383
|
-
console.log(`${chalk.bold('Status:')} ${getStatusColor(attrs.status)(attrs.status)}`);
|
|
384
|
-
console.log(`${chalk.bold('Description:')} ${attrs.description || 'N/A'}`);
|
|
385
|
-
console.log(`${chalk.bold('Updated:')} ${new Date(attrs.updated_at * 1000).toLocaleString()}`);
|
|
386
|
-
console.log('');
|
|
387
|
-
console.log(chalk.green('✅ Payment has been captured and will be settled'));
|
|
388
|
-
}
|
|
389
|
-
catch (error) {
|
|
390
|
-
spinner.stop();
|
|
391
|
-
const err = error;
|
|
392
|
-
console.error(chalk.red('❌ Failed to capture payment intent:'), err.message);
|
|
393
|
-
throw new CommandError();
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
export async function refundAction(paymentId, options) {
|
|
397
|
-
const spinner = new Spinner();
|
|
398
|
-
const configManager = new ConfigManager();
|
|
399
|
-
try {
|
|
400
|
-
spinner.start('Loading configuration...');
|
|
401
|
-
const config = await configManager.load();
|
|
402
|
-
if (!config) {
|
|
403
|
-
spinner.fail('No configuration found');
|
|
404
|
-
console.log(chalk.yellow('No PayMongo configuration found.'));
|
|
405
|
-
console.log(chalk.gray("Run 'paymongo init' to set up your project first."));
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
spinner.succeed('Configuration loaded');
|
|
409
|
-
const validReasons = ['duplicate', 'fraudulent', 'requested_by_customer'];
|
|
410
|
-
if (options.reason && !validReasons.includes(options.reason)) {
|
|
411
|
-
throw new Error(`Invalid reason. Must be one of: ${validReasons.join(', ')}`);
|
|
412
|
-
}
|
|
413
|
-
spinner.start('Creating refund...');
|
|
414
|
-
const apiClient = new ApiClient({ config });
|
|
415
|
-
const refund = await apiClient.createRefund(paymentId, options.amount ? parseInt(options.amount) : undefined, options.reason);
|
|
416
|
-
spinner.succeed('Refund created');
|
|
417
|
-
if (options.json) {
|
|
418
|
-
console.log(JSON.stringify(refund, null, 2));
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
const attrs = refund.attributes;
|
|
422
|
-
const displayAmount = (attrs.amount / 100).toFixed(2);
|
|
423
|
-
console.log('\n' + chalk.bold('Refund Created'));
|
|
424
|
-
console.log(chalk.gray('─'.repeat(50)));
|
|
425
|
-
console.log(`${chalk.bold('ID:')} ${refund.id}`);
|
|
426
|
-
console.log(`${chalk.bold('Payment ID:')} ${attrs.payment_id}`);
|
|
427
|
-
console.log(`${chalk.bold('Amount:')} ₱${displayAmount} ${attrs.currency}`);
|
|
428
|
-
console.log(`${chalk.bold('Status:')} ${getStatusColor(attrs.status)(attrs.status)}`);
|
|
429
|
-
console.log(`${chalk.bold('Reason:')} ${attrs.reason || 'N/A'}`);
|
|
430
|
-
console.log(`${chalk.bold('Created:')} ${new Date(attrs.created_at * 1000).toLocaleString()}`);
|
|
431
|
-
console.log('');
|
|
432
|
-
console.log(chalk.yellow('⚠️ Refund processing may take a few minutes'));
|
|
433
|
-
console.log(chalk.gray(`Check status: paymongo payments show-refund ${refund.id}`));
|
|
434
|
-
}
|
|
435
|
-
catch (error) {
|
|
436
|
-
spinner.stop();
|
|
437
|
-
const err = error;
|
|
438
|
-
console.error(chalk.red('❌ Failed to create refund:'), err.message);
|
|
439
|
-
throw new CommandError();
|
|
440
|
-
}
|
|
441
|
-
}
|
|
2
|
+
import { captureAction, confirmAction, createIntentAction, exportAction, importAction, listAction, refundAction, showAction, } from './payments/actions.js';
|
|
442
3
|
const command = new Command('payments');
|
|
443
4
|
command
|
|
444
5
|
.description('Manage PayMongo payments')
|
|
@@ -492,23 +53,5 @@ command
|
|
|
492
53
|
.option('-r, --reason <reason>', 'Refund reason: duplicate, fraudulent, requested_by_customer')
|
|
493
54
|
.option('-j, --json', 'Output as JSON')
|
|
494
55
|
.action(refundAction));
|
|
495
|
-
|
|
496
|
-
switch (status) {
|
|
497
|
-
case 'paid':
|
|
498
|
-
case 'succeeded':
|
|
499
|
-
case 'processed':
|
|
500
|
-
return chalk.green;
|
|
501
|
-
case 'pending':
|
|
502
|
-
case 'awaiting_payment_method':
|
|
503
|
-
case 'awaiting_next_action':
|
|
504
|
-
case 'processing':
|
|
505
|
-
return chalk.yellow;
|
|
506
|
-
case 'failed':
|
|
507
|
-
return chalk.red;
|
|
508
|
-
case 'cancelled':
|
|
509
|
-
return chalk.gray;
|
|
510
|
-
default:
|
|
511
|
-
return chalk.white;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
56
|
+
export { exportAction, importAction, listAction, showAction, createIntentAction, confirmAction, captureAction, refundAction, };
|
|
514
57
|
export default command;
|