@vonpay/checkout-cli 0.13.0 → 0.15.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/README.md +30 -5
- package/dist/index.js +2795 -13
- package/package.json +6 -4
- package/dist/app-info.d.ts +0 -5
- package/dist/app-info.d.ts.map +0 -1
- package/dist/app-info.js +0 -11
- package/dist/app-info.js.map +0 -1
- package/dist/client-factory.d.ts +0 -10
- package/dist/client-factory.d.ts.map +0 -1
- package/dist/client-factory.js +0 -31
- package/dist/client-factory.js.map +0 -1
- package/dist/commands/capabilities.d.ts +0 -22
- package/dist/commands/capabilities.d.ts.map +0 -1
- package/dist/commands/capabilities.js +0 -123
- package/dist/commands/capabilities.js.map +0 -1
- package/dist/commands/checkout.d.ts +0 -3
- package/dist/commands/checkout.d.ts.map +0 -1
- package/dist/commands/checkout.js +0 -39
- package/dist/commands/checkout.js.map +0 -1
- package/dist/commands/doctor.d.ts +0 -59
- package/dist/commands/doctor.d.ts.map +0 -1
- package/dist/commands/doctor.js +0 -366
- package/dist/commands/doctor.js.map +0 -1
- package/dist/commands/health.d.ts +0 -3
- package/dist/commands/health.d.ts.map +0 -1
- package/dist/commands/health.js +0 -52
- package/dist/commands/health.js.map +0 -1
- package/dist/commands/init.d.ts +0 -10
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -112
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/listen.d.ts +0 -19
- package/dist/commands/listen.d.ts.map +0 -1
- package/dist/commands/listen.js +0 -249
- package/dist/commands/listen.js.map +0 -1
- package/dist/commands/login.d.ts +0 -27
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/login.js +0 -75
- package/dist/commands/login.js.map +0 -1
- package/dist/commands/logout.d.ts +0 -3
- package/dist/commands/logout.d.ts.map +0 -1
- package/dist/commands/logout.js +0 -23
- package/dist/commands/logout.js.map +0 -1
- package/dist/commands/payment-intents.d.ts +0 -62
- package/dist/commands/payment-intents.d.ts.map +0 -1
- package/dist/commands/payment-intents.js +0 -271
- package/dist/commands/payment-intents.js.map +0 -1
- package/dist/commands/refunds.d.ts +0 -40
- package/dist/commands/refunds.d.ts.map +0 -1
- package/dist/commands/refunds.js +0 -142
- package/dist/commands/refunds.js.map +0 -1
- package/dist/commands/sessions.d.ts +0 -16
- package/dist/commands/sessions.d.ts.map +0 -1
- package/dist/commands/sessions.js +0 -152
- package/dist/commands/sessions.js.map +0 -1
- package/dist/commands/tokens.d.ts +0 -3
- package/dist/commands/tokens.d.ts.map +0 -1
- package/dist/commands/tokens.js +0 -89
- package/dist/commands/tokens.js.map +0 -1
- package/dist/commands/trigger.d.ts +0 -38
- package/dist/commands/trigger.d.ts.map +0 -1
- package/dist/commands/trigger.js +0 -246
- package/dist/commands/trigger.js.map +0 -1
- package/dist/config.d.ts +0 -22
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -72
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/utils/errors.d.ts +0 -80
- package/dist/utils/errors.d.ts.map +0 -1
- package/dist/utils/errors.js +0 -179
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/forward-to.d.ts +0 -38
- package/dist/utils/forward-to.d.ts.map +0 -1
- package/dist/utils/forward-to.js +0 -92
- package/dist/utils/forward-to.js.map +0 -1
- package/dist/utils/json-errors.d.ts +0 -16
- package/dist/utils/json-errors.d.ts.map +0 -1
- package/dist/utils/json-errors.js +0 -41
- package/dist/utils/json-errors.js.map +0 -1
- package/dist/utils/listen-forward.d.ts +0 -49
- package/dist/utils/listen-forward.d.ts.map +0 -1
- package/dist/utils/listen-forward.js +0 -113
- package/dist/utils/listen-forward.js.map +0 -1
- package/dist/utils/listen-output.d.ts +0 -52
- package/dist/utils/listen-output.d.ts.map +0 -1
- package/dist/utils/listen-output.js +0 -85
- package/dist/utils/listen-output.js.map +0 -1
- package/dist/utils/live-key.d.ts +0 -22
- package/dist/utils/live-key.d.ts.map +0 -1
- package/dist/utils/live-key.js +0 -37
- package/dist/utils/live-key.js.map +0 -1
- package/dist/utils/metadata.d.ts +0 -2
- package/dist/utils/metadata.d.ts.map +0 -1
- package/dist/utils/metadata.js +0 -31
- package/dist/utils/metadata.js.map +0 -1
- package/dist/utils/sanitize.d.ts +0 -4
- package/dist/utils/sanitize.d.ts.map +0 -1
- package/dist/utils/sanitize.js +0 -18
- package/dist/utils/sanitize.js.map +0 -1
- package/dist/utils/spinner.d.ts +0 -15
- package/dist/utils/spinner.d.ts.map +0 -1
- package/dist/utils/spinner.js +0 -18
- package/dist/utils/spinner.js.map +0 -1
- package/dist/utils/sse-consumer.d.ts +0 -81
- package/dist/utils/sse-consumer.d.ts.map +0 -1
- package/dist/utils/sse-consumer.js +0 -172
- package/dist/utils/sse-consumer.js.map +0 -1
- package/dist/utils/sse-parser.d.ts +0 -63
- package/dist/utils/sse-parser.d.ts.map +0 -1
- package/dist/utils/sse-parser.js +0 -149
- package/dist/utils/sse-parser.js.map +0 -1
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { Command } from "commander";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import { startSpinner } from "../utils/spinner.js";
|
|
5
|
-
import { formatMinorUnits } from "@vonpay/checkout-node";
|
|
6
|
-
import { requireApiKey } from "../config.js";
|
|
7
|
-
import { makeCheckoutClient } from "../client-factory.js";
|
|
8
|
-
import { parseMetadata } from "../utils/metadata.js";
|
|
9
|
-
import { safeDisplay } from "../utils/sanitize.js";
|
|
10
|
-
import { exitWithCliError, handleError } from "../utils/errors.js";
|
|
11
|
-
import { requireLiveConfirmation } from "../utils/live-key.js";
|
|
12
|
-
const MIT_INITIATORS = ["merchant", "customer"];
|
|
13
|
-
const MIT_REASONS = [
|
|
14
|
-
"recurring",
|
|
15
|
-
"unscheduled",
|
|
16
|
-
"installment",
|
|
17
|
-
];
|
|
18
|
-
/**
|
|
19
|
-
* Assemble the create-intent body from parsed flags.
|
|
20
|
-
*
|
|
21
|
-
* Extracted from the action handler so the wiring is TESTABLE. A flag can be
|
|
22
|
-
* declared on the command and never reach the SDK call — and for
|
|
23
|
-
* `--payment-method`, `--session-id` and `--buyer-id` that failure is silent
|
|
24
|
-
* and expensive: the first names the saved card to bill, the other two are
|
|
25
|
-
* money-safety controls that only apply when actually sent.
|
|
26
|
-
*
|
|
27
|
-
* Every optional field is set only when supplied. An omitted flag must stay
|
|
28
|
-
* ABSENT rather than become an explicit `undefined` — asserting a null buyer
|
|
29
|
-
* is a different request from never asserting one. Empty strings count as
|
|
30
|
-
* not-provided, matching `buildMITBlock`.
|
|
31
|
-
*/
|
|
32
|
-
function buildCreateParams(opts, resolved) {
|
|
33
|
-
const params = {
|
|
34
|
-
amount: opts.amount,
|
|
35
|
-
currency: opts.currency.toUpperCase(),
|
|
36
|
-
};
|
|
37
|
-
if (resolved.captureMethod !== undefined) {
|
|
38
|
-
params.captureMethod = resolved.captureMethod;
|
|
39
|
-
}
|
|
40
|
-
if (resolved.metadata !== undefined) {
|
|
41
|
-
params.metadata = resolved.metadata;
|
|
42
|
-
}
|
|
43
|
-
if (resolved.mit !== undefined) {
|
|
44
|
-
params.mit = resolved.mit;
|
|
45
|
-
}
|
|
46
|
-
const paymentMethodId = opts.paymentMethod?.trim();
|
|
47
|
-
if (paymentMethodId) {
|
|
48
|
-
params.paymentMethod = { id: paymentMethodId };
|
|
49
|
-
}
|
|
50
|
-
const sessionId = opts.sessionId?.trim();
|
|
51
|
-
if (sessionId) {
|
|
52
|
-
params.sessionId = sessionId;
|
|
53
|
-
}
|
|
54
|
-
const buyerId = opts.buyerId?.trim();
|
|
55
|
-
if (buyerId) {
|
|
56
|
-
params.buyerId = buyerId;
|
|
57
|
-
}
|
|
58
|
-
const buyerEmail = opts.buyerEmail?.trim();
|
|
59
|
-
if (buyerEmail) {
|
|
60
|
-
params.buyerEmail = buyerEmail;
|
|
61
|
-
}
|
|
62
|
-
return params;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* The idempotency key this charge is sent with: the caller's
|
|
66
|
-
* `--idempotency-key` when given (trimmed), otherwise a freshly generated one.
|
|
67
|
-
*
|
|
68
|
-
* Every charge carries a key. The API refuses a keyless charge from
|
|
69
|
-
* 28 October 2026 (`400 idempotency_key_required`), and a key is also what
|
|
70
|
-
* lets the SDK retry an ambiguous failure (timeout, 5xx) inside this one
|
|
71
|
-
* command without risking a second charge. A generated key protects only that
|
|
72
|
-
* single invocation — re-running the command makes a new key and therefore a
|
|
73
|
-
* new charge — so it is printed (to stderr, keeping `--json` stdout clean)
|
|
74
|
-
* for the caller to pass back on a deliberate retry of the SAME charge.
|
|
75
|
-
*/
|
|
76
|
-
function resolveIdempotencyKey(flag) {
|
|
77
|
-
const given = flag?.trim();
|
|
78
|
-
if (given)
|
|
79
|
-
return { key: given, generated: false };
|
|
80
|
-
return { key: `cli-${randomUUID()}`, generated: true };
|
|
81
|
-
}
|
|
82
|
-
function buildMITBlock(opts) {
|
|
83
|
-
// Treat empty string as not provided — `--mit-original-transaction-id ""`
|
|
84
|
-
// would otherwise build a malformed MIT block that the server may reject
|
|
85
|
-
// ambiguously.
|
|
86
|
-
const initiator = opts.mitInitiator?.trim().toLowerCase();
|
|
87
|
-
const reason = opts.mitReason?.trim().toLowerCase();
|
|
88
|
-
const originalTransactionId = opts.mitOriginalTransactionId?.trim();
|
|
89
|
-
const provided = [initiator, reason, originalTransactionId].filter((v) => v !== undefined && v !== "").length;
|
|
90
|
-
if (provided === 0)
|
|
91
|
-
return undefined;
|
|
92
|
-
if (provided !== 3) {
|
|
93
|
-
throw new Error("MIT requires all three of --mit-initiator, --mit-reason, --mit-original-transaction-id (non-empty).");
|
|
94
|
-
}
|
|
95
|
-
if (!MIT_INITIATORS.includes(initiator)) {
|
|
96
|
-
throw new Error(`Invalid --mit-initiator "${opts.mitInitiator}". Expected: ${MIT_INITIATORS.join(", ")}`);
|
|
97
|
-
}
|
|
98
|
-
if (!MIT_REASONS.includes(reason)) {
|
|
99
|
-
throw new Error(`Invalid --mit-reason "${opts.mitReason}". Expected: ${MIT_REASONS.join(", ")}`);
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
initiator: initiator,
|
|
103
|
-
reason: reason,
|
|
104
|
-
originalTransactionId: originalTransactionId,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function printPaymentIntent(intent) {
|
|
108
|
-
const statusColor = intent.status === "succeeded"
|
|
109
|
-
? chalk.green
|
|
110
|
-
: intent.status === "authorized"
|
|
111
|
-
? chalk.cyan
|
|
112
|
-
: intent.status === "requires_action"
|
|
113
|
-
? chalk.yellow
|
|
114
|
-
: intent.status === "failed" || intent.status === "canceled"
|
|
115
|
-
? chalk.red
|
|
116
|
-
: chalk.gray;
|
|
117
|
-
console.log(` ID: ${intent.id}`);
|
|
118
|
-
console.log(` Status: ${statusColor(intent.status)}`);
|
|
119
|
-
console.log(` Amount: ${formatMinorUnits(intent.amount, intent.currency)}`);
|
|
120
|
-
console.log(` Capture: ${intent.captureMethod}`);
|
|
121
|
-
if (intent.nextAction) {
|
|
122
|
-
// nextAction is the structured 3DS action object, not a bare URL — reading
|
|
123
|
-
// it as a string would print "[object Object]". `type` and the redirect URL
|
|
124
|
-
// are server-supplied, so sanitize before echoing to the terminal (same
|
|
125
|
-
// pattern as refunds.ts for refund.reason).
|
|
126
|
-
console.log(` Next action: ${chalk.yellow(safeDisplay(intent.nextAction.type))}`);
|
|
127
|
-
if (intent.nextAction.type === "redirect_to_url") {
|
|
128
|
-
console.log(` Redirect: ${chalk.yellow(safeDisplay(intent.nextAction.redirectToUrl.url))}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (intent.declineCode) {
|
|
132
|
-
console.log(` Decline code: ${chalk.red(safeDisplay(intent.declineCode))}`);
|
|
133
|
-
}
|
|
134
|
-
console.log(` Created: ${intent.createdAt}`);
|
|
135
|
-
}
|
|
136
|
-
const CONFIRM_LIVE_DESCRIPTION = "Required to proceed when the loaded key is vp_sk_live_* (this operation is irreversible)";
|
|
137
|
-
export function paymentIntentsCommand() {
|
|
138
|
-
const intents = new Command("payment-intents").description("Create, capture, and void payment intents (discrete lifecycle)");
|
|
139
|
-
intents
|
|
140
|
-
.command("create")
|
|
141
|
-
.description("Create a new payment intent")
|
|
142
|
-
.requiredOption("--amount <cents>", "Amount in minor units (e.g. 1499 = $14.99)", (v) => parseInt(v, 10))
|
|
143
|
-
.requiredOption("--currency <code>", "ISO 4217 currency (e.g. USD)")
|
|
144
|
-
.option("--capture-method <mode>", "automatic (default) or manual (parks at authorized)")
|
|
145
|
-
.option("--metadata <pair...>", "Metadata key=value (repeat flag for multiple pairs)")
|
|
146
|
-
.option("--mit-initiator <initiator>", `MIT initiator (${MIT_INITIATORS.join(" | ")})`)
|
|
147
|
-
.option("--mit-reason <reason>", `MIT reason (${MIT_REASONS.join(" | ")})`)
|
|
148
|
-
.option("--mit-original-transaction-id <id>", "Cardholder-initiated anchor payment intent ID (vpi_*)")
|
|
149
|
-
.option("--payment-method <id>", "Stored card to charge (vp_pmt_*). Required for saved-card / recurring charges — --mit alone declares the charge merchant-initiated but does not say which card to bill")
|
|
150
|
-
.option("--session-id <id>", "Checkout session this charge belongs to (vp_cs_*). Arms the double-charge guard: refused if that session already charged at submit. Safe to always send")
|
|
151
|
-
.option("--buyer-id <id>", "Your customer reference. Send on EVERY saved-card charge — it is what makes the server reject a charge against the wrong customer's stored card")
|
|
152
|
-
.option("--buyer-email <email>", "Buyer email for this charge")
|
|
153
|
-
.option("--idempotency-key <key>", "Idempotency key for this charge. Reuse the SAME key to retry the same charge safely. Generated (and printed) when omitted")
|
|
154
|
-
.option("--confirm-live", CONFIRM_LIVE_DESCRIPTION)
|
|
155
|
-
.option("--json", "Output raw JSON")
|
|
156
|
-
.action(async (opts) => {
|
|
157
|
-
const apiKey = requireApiKey();
|
|
158
|
-
requireLiveConfirmation(apiKey, opts, "create a payment intent");
|
|
159
|
-
const client = makeCheckoutClient();
|
|
160
|
-
const spinner = startSpinner("Creating payment intent...");
|
|
161
|
-
try {
|
|
162
|
-
const captureMethod = opts.captureMethod?.toLowerCase();
|
|
163
|
-
if (captureMethod !== undefined &&
|
|
164
|
-
captureMethod !== "automatic" &&
|
|
165
|
-
captureMethod !== "manual") {
|
|
166
|
-
spinner.stop();
|
|
167
|
-
const message = `Invalid --capture-method "${opts.captureMethod}". Expected automatic or manual.`;
|
|
168
|
-
exitWithCliError(message, chalk.red(message));
|
|
169
|
-
}
|
|
170
|
-
const metadata = parseMetadata(opts.metadata);
|
|
171
|
-
const mit = buildMITBlock(opts);
|
|
172
|
-
const params = buildCreateParams(opts, { captureMethod, metadata, mit });
|
|
173
|
-
const { key: idempotencyKey, generated } = resolveIdempotencyKey(opts.idempotencyKey);
|
|
174
|
-
if (generated) {
|
|
175
|
-
// Printed BEFORE the request so it is on screen even if the call
|
|
176
|
-
// times out — that is exactly when the caller needs it to retry.
|
|
177
|
-
spinner.stop();
|
|
178
|
-
console.error(chalk.dim(`Idempotency key: ${idempotencyKey} (to retry this same charge, re-run with --idempotency-key ${idempotencyKey})`));
|
|
179
|
-
spinner.start();
|
|
180
|
-
}
|
|
181
|
-
const intent = await client.paymentIntents.create(params, {
|
|
182
|
-
idempotencyKey,
|
|
183
|
-
});
|
|
184
|
-
spinner.stop();
|
|
185
|
-
if (opts.json) {
|
|
186
|
-
console.log(JSON.stringify(intent, null, 2));
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
console.log(chalk.green("✓ Payment intent created"));
|
|
190
|
-
printPaymentIntent(intent);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
catch (err) {
|
|
194
|
-
spinner.stop();
|
|
195
|
-
handleError(err);
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
intents
|
|
199
|
-
.command("capture")
|
|
200
|
-
.description("Capture an authorized payment intent")
|
|
201
|
-
.argument("<id>", "Payment intent ID (vpi_*)")
|
|
202
|
-
.option("--amount-to-capture <cents>", "Partial capture amount in minor units (omit for full)", (v) => parseInt(v, 10))
|
|
203
|
-
.option("--idempotency-key <key>", "Idempotency key for safe retries")
|
|
204
|
-
.option("--confirm-live", CONFIRM_LIVE_DESCRIPTION)
|
|
205
|
-
.option("--json", "Output raw JSON")
|
|
206
|
-
.action(async (id, opts) => {
|
|
207
|
-
const apiKey = requireApiKey();
|
|
208
|
-
requireLiveConfirmation(apiKey, opts, "capture a payment intent");
|
|
209
|
-
const client = makeCheckoutClient();
|
|
210
|
-
const spinner = startSpinner("Capturing payment intent...");
|
|
211
|
-
try {
|
|
212
|
-
const intent = await client.paymentIntents.capture(id, opts.amountToCapture !== undefined
|
|
213
|
-
? { amountToCapture: opts.amountToCapture }
|
|
214
|
-
: undefined, opts.idempotencyKey
|
|
215
|
-
? { idempotencyKey: opts.idempotencyKey }
|
|
216
|
-
: undefined);
|
|
217
|
-
spinner.stop();
|
|
218
|
-
if (opts.json) {
|
|
219
|
-
console.log(JSON.stringify(intent, null, 2));
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
const captureLabel = opts.amountToCapture !== undefined
|
|
223
|
-
? ` (partial: ${formatMinorUnits(opts.amountToCapture, intent.currency)})`
|
|
224
|
-
: "";
|
|
225
|
-
console.log(chalk.green(`✓ Payment intent captured${captureLabel}`));
|
|
226
|
-
printPaymentIntent(intent);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
catch (err) {
|
|
230
|
-
spinner.stop();
|
|
231
|
-
handleError(err);
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
intents
|
|
235
|
-
.command("void")
|
|
236
|
-
.description("Void an authorized (uncaptured) payment intent")
|
|
237
|
-
.argument("<id>", "Payment intent ID (vpi_*)")
|
|
238
|
-
.option("--idempotency-key <key>", "Idempotency key for safe retries")
|
|
239
|
-
.option("--confirm-live", CONFIRM_LIVE_DESCRIPTION)
|
|
240
|
-
.option("--json", "Output raw JSON")
|
|
241
|
-
.action(async (id, opts) => {
|
|
242
|
-
const apiKey = requireApiKey();
|
|
243
|
-
requireLiveConfirmation(apiKey, opts, "void a payment intent");
|
|
244
|
-
const client = makeCheckoutClient();
|
|
245
|
-
const spinner = startSpinner("Voiding payment intent...");
|
|
246
|
-
try {
|
|
247
|
-
const intent = await client.paymentIntents.void(id, opts.idempotencyKey
|
|
248
|
-
? { idempotencyKey: opts.idempotencyKey }
|
|
249
|
-
: undefined);
|
|
250
|
-
spinner.stop();
|
|
251
|
-
if (opts.json) {
|
|
252
|
-
console.log(JSON.stringify(intent, null, 2));
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
console.log(chalk.green("✓ Payment intent voided"));
|
|
256
|
-
printPaymentIntent(intent);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
catch (err) {
|
|
260
|
-
spinner.stop();
|
|
261
|
-
handleError(err);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
return intents;
|
|
265
|
-
}
|
|
266
|
-
export const __testing__ = {
|
|
267
|
-
buildMITBlock,
|
|
268
|
-
buildCreateParams,
|
|
269
|
-
resolveIdempotencyKey,
|
|
270
|
-
};
|
|
271
|
-
//# sourceMappingURL=payment-intents.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payment-intents.js","sourceRoot":"","sources":["../../src/commands/payment-intents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQzD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBA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,CAAC;YACF,OAAO,CAAC,IAAI,EAAE,CAAC;YAEf,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACd,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC,CAAC;gBACpD,kBAAkB,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,EAAE,CAAC;YACf,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CACF,CAAC;IAEJ,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,aAAa;IACb,iBAAiB;IACjB,qBAAqB;CACtB,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import type { CreateRefundParams, Refund, TransactionRefund } from "@vonpay/checkout-node";
|
|
3
|
-
interface RefundCreateOpts {
|
|
4
|
-
paymentIntent?: string;
|
|
5
|
-
transaction?: string;
|
|
6
|
-
amount?: number;
|
|
7
|
-
currency?: string;
|
|
8
|
-
reason?: string;
|
|
9
|
-
metadata?: string[];
|
|
10
|
-
idempotencyKey?: string;
|
|
11
|
-
confirmLive?: boolean;
|
|
12
|
-
json?: boolean;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* A refund names exactly one target. Refuse both / neither here, before the
|
|
16
|
-
* live-key gate and before any request, with a message that names the flags.
|
|
17
|
-
*/
|
|
18
|
-
/** Help text, exported for the doc guard test. */
|
|
19
|
-
declare function helpFor(flag: "--payment-intent" | "--transaction"): string;
|
|
20
|
-
declare function resolveRefundTarget(opts: Pick<RefundCreateOpts, "paymentIntent" | "transaction">): {
|
|
21
|
-
paymentIntent: string;
|
|
22
|
-
} | {
|
|
23
|
-
transaction: string;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* The params sent to `refunds.create()`. Typed as the whole union: the target
|
|
27
|
-
* is chosen at runtime, so the SDK's return type is `Refund | TransactionRefund`
|
|
28
|
-
* and `printRefund` takes both.
|
|
29
|
-
*/
|
|
30
|
-
declare function buildRefundParams(opts: RefundCreateOpts, metadata: Record<string, string> | undefined): CreateRefundParams;
|
|
31
|
-
declare function printRefund(refund: Refund | TransactionRefund): void;
|
|
32
|
-
export declare function refundsCommand(): Command;
|
|
33
|
-
export declare const __testing__: {
|
|
34
|
-
helpFor: typeof helpFor;
|
|
35
|
-
resolveRefundTarget: typeof resolveRefundTarget;
|
|
36
|
-
buildRefundParams: typeof buildRefundParams;
|
|
37
|
-
printRefund: typeof printRefund;
|
|
38
|
-
};
|
|
39
|
-
export {};
|
|
40
|
-
//# sourceMappingURL=refunds.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"refunds.d.ts","sourceRoot":"","sources":["../../src/commands/refunds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,KAAK,EACV,kBAAkB,EAClB,MAAM,EACN,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAQ/B,UAAU,gBAAgB;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAOD;;;GAGG;AACH,kDAAkD;AAClD,iBAAS,OAAO,CAAC,IAAI,EAAE,kBAAkB,GAAG,eAAe,GAAG,MAAM,CAKnE;AAED,iBAAS,mBAAmB,CAC1B,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,eAAe,GAAG,aAAa,CAAC,GAC5D;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAarD;AAED;;;;GAIG;AACH,iBAAS,iBAAiB,CACxB,IAAI,EAAE,gBAAgB,EACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAC3C,kBAAkB,CASpB;AAED,iBAAS,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAyB7D;AAED,wBAAgB,cAAc,IAAI,OAAO,CAiFxC;AAED,eAAO,MAAM,WAAW;;;;;CAKvB,CAAC"}
|
package/dist/commands/refunds.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import { startSpinner } from "../utils/spinner.js";
|
|
4
|
-
import { formatMinorUnits } from "@vonpay/checkout-node";
|
|
5
|
-
import { requireApiKey } from "../config.js";
|
|
6
|
-
import { makeCheckoutClient } from "../client-factory.js";
|
|
7
|
-
import { parseMetadata } from "../utils/metadata.js";
|
|
8
|
-
import { exitWithCliError, handleError } from "../utils/errors.js";
|
|
9
|
-
import { requireLiveConfirmation } from "../utils/live-key.js";
|
|
10
|
-
import { safeDisplay } from "../utils/sanitize.js";
|
|
11
|
-
/** Empty / whitespace-only flag values count as not provided. */
|
|
12
|
-
function present(v) {
|
|
13
|
-
return v !== undefined && v.trim() !== "";
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* A refund names exactly one target. Refuse both / neither here, before the
|
|
17
|
-
* live-key gate and before any request, with a message that names the flags.
|
|
18
|
-
*/
|
|
19
|
-
/** Help text, exported for the doc guard test. */
|
|
20
|
-
function helpFor(flag) {
|
|
21
|
-
const opt = refundsCommand()
|
|
22
|
-
.commands.find((c) => c.name() === "create")
|
|
23
|
-
.options.find((o) => o.long === flag);
|
|
24
|
-
return opt.description;
|
|
25
|
-
}
|
|
26
|
-
function resolveRefundTarget(opts) {
|
|
27
|
-
const hasPi = present(opts.paymentIntent);
|
|
28
|
-
const hasTx = present(opts.transaction);
|
|
29
|
-
if (hasPi && hasTx) {
|
|
30
|
-
throw new Error("Pass exactly one of --payment-intent or --transaction, not both. A refund is issued against one target.");
|
|
31
|
-
}
|
|
32
|
-
if (hasPi)
|
|
33
|
-
return { paymentIntent: opts.paymentIntent.trim() };
|
|
34
|
-
if (hasTx)
|
|
35
|
-
return { transaction: opts.transaction.trim() };
|
|
36
|
-
throw new Error("A refund target is required: pass --payment-intent <vpi_*> or --transaction <vp_tx_*>.");
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* The params sent to `refunds.create()`. Typed as the whole union: the target
|
|
40
|
-
* is chosen at runtime, so the SDK's return type is `Refund | TransactionRefund`
|
|
41
|
-
* and `printRefund` takes both.
|
|
42
|
-
*/
|
|
43
|
-
function buildRefundParams(opts, metadata) {
|
|
44
|
-
const params = { ...resolveRefundTarget(opts) };
|
|
45
|
-
if (opts.amount !== undefined)
|
|
46
|
-
params.amount = opts.amount;
|
|
47
|
-
if (opts.currency !== undefined) {
|
|
48
|
-
params.currency = opts.currency.toUpperCase();
|
|
49
|
-
}
|
|
50
|
-
if (opts.reason !== undefined)
|
|
51
|
-
params.reason = opts.reason;
|
|
52
|
-
if (metadata !== undefined)
|
|
53
|
-
params.metadata = metadata;
|
|
54
|
-
return params;
|
|
55
|
-
}
|
|
56
|
-
function printRefund(refund) {
|
|
57
|
-
const statusColor = refund.status === "succeeded"
|
|
58
|
-
? chalk.green
|
|
59
|
-
: refund.status === "failed"
|
|
60
|
-
? chalk.red
|
|
61
|
-
: chalk.yellow;
|
|
62
|
-
console.log(` ID: ${refund.id}`);
|
|
63
|
-
// Exactly one target is set; print whichever it is.
|
|
64
|
-
if (refund.transaction !== null) {
|
|
65
|
-
console.log(` Transaction: ${refund.transaction}`);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
console.log(` Payment intent: ${refund.paymentIntent}`);
|
|
69
|
-
}
|
|
70
|
-
console.log(` Status: ${statusColor(refund.status)}`);
|
|
71
|
-
console.log(` Amount: ${formatMinorUnits(refund.amount, refund.currency)}`);
|
|
72
|
-
if (refund.reason) {
|
|
73
|
-
// Server echoes back the user-supplied reason; strip terminal escapes
|
|
74
|
-
// before printing so a malicious or accidentally-formatted reason can't
|
|
75
|
-
// repaint the terminal.
|
|
76
|
-
console.log(` Reason: ${safeDisplay(refund.reason)}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export function refundsCommand() {
|
|
80
|
-
const refunds = new Command("refunds").description("Refund a captured payment intent or a settled transaction");
|
|
81
|
-
refunds
|
|
82
|
-
.command("create")
|
|
83
|
-
.description("Create a refund against a payment intent (--payment-intent) or a transaction (--transaction) — exactly one")
|
|
84
|
-
.option("--payment-intent <id>", "Payment intent ID to refund (vpi_*). Use this OR --transaction. A payment intent id is also " +
|
|
85
|
-
"visible to the shopper's browser — it is not proof a refund is wanted; only refund one you " +
|
|
86
|
-
"looked up from your own order records")
|
|
87
|
-
.option("--transaction <id>", "Transaction ID to refund (vp_tx_*), instead of --payment-intent (prefer --payment-intent " +
|
|
88
|
-
"whenever the payment has one). Use it for a payment that has no payment intent, to " +
|
|
89
|
-
"follow the transaction a refund_target_is_duplicate error names, or as the vp_tx_id " +
|
|
90
|
-
"read from the session when its payment has no payment intent — only when vp_tx_count " +
|
|
91
|
-
"is exactly 1, and only after matching it to the order in your own records. A " +
|
|
92
|
-
"transaction id is also visible to the shopper's browser — only refund one you looked " +
|
|
93
|
-
"up from your own order records")
|
|
94
|
-
.option("--amount <cents>", "Refund amount in minor units (omit for full remaining balance)", (v) => parseInt(v, 10))
|
|
95
|
-
.option("--currency <code>", "ISO 4217 currency code")
|
|
96
|
-
.option("--reason <text>", "Free-form reason (mirrored back on the record)")
|
|
97
|
-
.option("--metadata <pair...>", "Metadata key=value (repeat flag for multiple pairs)")
|
|
98
|
-
.option("--idempotency-key <key>", "Idempotency key for safe retries")
|
|
99
|
-
.option("--confirm-live", "Required to proceed when the loaded key is vp_sk_live_* (this operation is irreversible)")
|
|
100
|
-
.option("--json", "Output raw JSON")
|
|
101
|
-
.action(async (opts) => {
|
|
102
|
-
// Target check first: a usage error needs no key and sends nothing.
|
|
103
|
-
try {
|
|
104
|
-
resolveRefundTarget(opts);
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
const message = err.message;
|
|
108
|
-
exitWithCliError(message, chalk.red(`Error: ${message}`));
|
|
109
|
-
}
|
|
110
|
-
const apiKey = requireApiKey();
|
|
111
|
-
requireLiveConfirmation(apiKey, opts, "create a refund");
|
|
112
|
-
const client = makeCheckoutClient();
|
|
113
|
-
const spinner = startSpinner("Creating refund...");
|
|
114
|
-
try {
|
|
115
|
-
const metadata = parseMetadata(opts.metadata);
|
|
116
|
-
const params = buildRefundParams(opts, metadata);
|
|
117
|
-
const refund = await client.refunds.create(params, opts.idempotencyKey
|
|
118
|
-
? { idempotencyKey: opts.idempotencyKey }
|
|
119
|
-
: undefined);
|
|
120
|
-
spinner.stop();
|
|
121
|
-
if (opts.json) {
|
|
122
|
-
console.log(JSON.stringify(refund, null, 2));
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
console.log(chalk.green("✓ Refund created"));
|
|
126
|
-
printRefund(refund);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (err) {
|
|
130
|
-
spinner.stop();
|
|
131
|
-
handleError(err);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
return refunds;
|
|
135
|
-
}
|
|
136
|
-
export const __testing__ = {
|
|
137
|
-
helpFor,
|
|
138
|
-
resolveRefundTarget,
|
|
139
|
-
buildRefundParams,
|
|
140
|
-
printRefund,
|
|
141
|
-
};
|
|
142
|
-
//# sourceMappingURL=refunds.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"refunds.js","sourceRoot":"","sources":["../../src/commands/refunds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAMzD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAcnD,iEAAiE;AACjE,SAAS,OAAO,CAAC,CAAqB;IACpC,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC5C,CAAC;AAED;;;GAGG;AACH,kDAAkD;AAClD,SAAS,OAAO,CAAC,IAA0C;IACzD,MAAM,GAAG,GAAG,cAAc,EAAE;SACzB,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,QAAQ,CAAE;SAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAE,CAAC;IACzC,OAAO,GAAG,CAAC,WAAW,CAAC;AACzB,CAAC;AAED,SAAS,mBAAmB,CAC1B,IAA6D;IAE7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;gBACzC,CAAC,CAAC,SAAS,CACd,CAAC;YACF,OAAO,CAAC,IAAI,EAAE,CAAC;YAEf,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACd,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC;gBAC7C,WAAW,CAAC,MAAM,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,EAAE,CAAC;YACf,WAAW,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,OAAO;IACP,mBAAmB;IACnB,iBAAiB;IACjB,WAAW;CACZ,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { makeCheckoutClient } from "../client-factory.js";
|
|
3
|
-
type SessionRead = Awaited<ReturnType<ReturnType<typeof makeCheckoutClient>["sessions"]["get"]>>;
|
|
4
|
-
/**
|
|
5
|
-
* The human-readable `sessions get` output. A hand-written field list, so it
|
|
6
|
-
* is exported for a test that pins the money fields: before this, the printer
|
|
7
|
-
* showed neither whether the money moved nor the payment intent a held
|
|
8
|
-
* payment is captured with, and a merchant reading it could not see a hold.
|
|
9
|
-
*/
|
|
10
|
-
declare function sessionLines(session: SessionRead): string[];
|
|
11
|
-
export declare const __testing__: {
|
|
12
|
-
sessionLines: typeof sessionLines;
|
|
13
|
-
};
|
|
14
|
-
export declare function sessionsCommand(): Command;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=sessions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../src/commands/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAK1D,KAAK,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEjG;;;;;GAKG;AACH,iBAAS,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,EAAE,CAuDpD;AAED,eAAO,MAAM,WAAW;;CAAmB,CAAC;AAE5C,wBAAgB,eAAe,IAAI,OAAO,CAkGzC"}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import { startSpinner } from "../utils/spinner.js";
|
|
4
|
-
import { formatMinorUnits } from "@vonpay/checkout-node";
|
|
5
|
-
import { makeCheckoutClient } from "../client-factory.js";
|
|
6
|
-
import { handleError } from "../utils/errors.js";
|
|
7
|
-
const makeClient = makeCheckoutClient;
|
|
8
|
-
/**
|
|
9
|
-
* The human-readable `sessions get` output. A hand-written field list, so it
|
|
10
|
-
* is exported for a test that pins the money fields: before this, the printer
|
|
11
|
-
* showed neither whether the money moved nor the payment intent a held
|
|
12
|
-
* payment is captured with, and a merchant reading it could not see a hold.
|
|
13
|
-
*/
|
|
14
|
-
function sessionLines(session) {
|
|
15
|
-
const statusColor = session.status === "succeeded"
|
|
16
|
-
? chalk.green
|
|
17
|
-
: session.status === "failed"
|
|
18
|
-
? chalk.red
|
|
19
|
-
: session.status === "expired"
|
|
20
|
-
? chalk.gray
|
|
21
|
-
: chalk.yellow;
|
|
22
|
-
const lines = [
|
|
23
|
-
` ID: ${session.id}`,
|
|
24
|
-
` Status: ${statusColor(session.status)}`,
|
|
25
|
-
` Amount: ${formatMinorUnits(session.amount, session.currency)}`,
|
|
26
|
-
];
|
|
27
|
-
if (session.paymentStatus) {
|
|
28
|
-
const paymentColor = session.paymentStatus === "paid"
|
|
29
|
-
? chalk.green
|
|
30
|
-
: session.paymentStatus === "held"
|
|
31
|
-
? chalk.yellow
|
|
32
|
-
: chalk.gray;
|
|
33
|
-
lines.push(` Payment: ${paymentColor(session.paymentStatus)}`);
|
|
34
|
-
if (session.paymentStatus === "held") {
|
|
35
|
-
lines.push(chalk.yellow(" Held, not taken: capture it to take the money, or void it. Do not ship on a hold alone."));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (session.paymentIntentId) {
|
|
39
|
-
lines.push(` Intent: ${session.paymentIntentId}`);
|
|
40
|
-
}
|
|
41
|
-
if (session.transactionId) {
|
|
42
|
-
lines.push(` Transaction: ${session.transactionId}`);
|
|
43
|
-
}
|
|
44
|
-
// The refund id (`refunds create --transaction`). Shown only when it is a
|
|
45
|
-
// string; vp_tx_count 2+ means the buyer was charged more than once and no
|
|
46
|
-
// single id is a safe refund target.
|
|
47
|
-
if (typeof session.vp_tx_id === "string") {
|
|
48
|
-
lines.push(` Refund id: ${session.vp_tx_id}`);
|
|
49
|
-
}
|
|
50
|
-
if (typeof session.vp_tx_count === "number") {
|
|
51
|
-
lines.push(` Payments: ${session.vp_tx_count}`);
|
|
52
|
-
if (session.vp_tx_count >= 2) {
|
|
53
|
-
lines.push(chalk.red(` ⚠ Charged ${session.vp_tx_count} times: there is no single refund id. Have a person check the payments before refunding or fulfilling.`));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
lines.push(` Created: ${session.createdAt}`);
|
|
57
|
-
lines.push(` Expires: ${session.expiresAt}`);
|
|
58
|
-
return lines;
|
|
59
|
-
}
|
|
60
|
-
export const __testing__ = { sessionLines };
|
|
61
|
-
export function sessionsCommand() {
|
|
62
|
-
const sessions = new Command("sessions").description("Create and manage checkout sessions");
|
|
63
|
-
sessions
|
|
64
|
-
.command("create")
|
|
65
|
-
.description("Create a new checkout session")
|
|
66
|
-
.requiredOption("--amount <cents>", "Amount in minor units (e.g. 1499 = $14.99)", (v) => parseInt(v, 10))
|
|
67
|
-
.requiredOption("--currency <code>", "Currency code (e.g. USD)")
|
|
68
|
-
.option("--country <code>", "Country code (e.g. US)")
|
|
69
|
-
.option("--description <text>", "Session description")
|
|
70
|
-
.option("--success-url <url>", "Redirect URL on success")
|
|
71
|
-
.option("--cancel-url <url>", "Redirect URL on cancel")
|
|
72
|
-
.option("--idempotency-key <key>", "Idempotency key for safe retries")
|
|
73
|
-
.option("--dry-run", "Validate without creating a session")
|
|
74
|
-
.option("--json", "Output raw JSON")
|
|
75
|
-
.action(async (opts) => {
|
|
76
|
-
const client = makeClient();
|
|
77
|
-
const spinner = startSpinner("Creating session...");
|
|
78
|
-
try {
|
|
79
|
-
const params = {
|
|
80
|
-
amount: opts.amount,
|
|
81
|
-
currency: opts.currency.toUpperCase(),
|
|
82
|
-
country: opts.country?.toUpperCase(),
|
|
83
|
-
description: opts.description,
|
|
84
|
-
successUrl: opts.successUrl,
|
|
85
|
-
cancelUrl: opts.cancelUrl,
|
|
86
|
-
};
|
|
87
|
-
if (opts.dryRun) {
|
|
88
|
-
spinner.text = "Validating...";
|
|
89
|
-
const result = await client.sessions.validate(params);
|
|
90
|
-
spinner.stop();
|
|
91
|
-
if (opts.json) {
|
|
92
|
-
console.log(JSON.stringify(result, null, 2));
|
|
93
|
-
}
|
|
94
|
-
else if (result.valid) {
|
|
95
|
-
console.log(chalk.green("✓ Valid request"));
|
|
96
|
-
if (result.warnings.length > 0) {
|
|
97
|
-
for (const w of result.warnings) {
|
|
98
|
-
console.log(chalk.yellow(` ⚠ ${w}`));
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
console.log(chalk.red("✗ Invalid request"));
|
|
104
|
-
}
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const session = await client.sessions.create(params, opts.idempotencyKey
|
|
108
|
-
? { idempotencyKey: opts.idempotencyKey }
|
|
109
|
-
: undefined);
|
|
110
|
-
spinner.stop();
|
|
111
|
-
if (opts.json) {
|
|
112
|
-
console.log(JSON.stringify(session, null, 2));
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
console.log(chalk.green("✓ Session created"));
|
|
116
|
-
console.log(` ID: ${session.id}`);
|
|
117
|
-
console.log(` URL: ${chalk.cyan(session.checkoutUrl)}`);
|
|
118
|
-
console.log(` Expires: ${session.expiresAt}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
catch (err) {
|
|
122
|
-
spinner.stop();
|
|
123
|
-
handleError(err);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
sessions
|
|
127
|
-
.command("get")
|
|
128
|
-
.description("Get session status")
|
|
129
|
-
.argument("<id>", "Session ID")
|
|
130
|
-
.option("--json", "Output raw JSON")
|
|
131
|
-
.action(async (id, opts) => {
|
|
132
|
-
const client = makeClient();
|
|
133
|
-
const spinner = startSpinner("Fetching session...");
|
|
134
|
-
try {
|
|
135
|
-
const session = await client.sessions.get(id);
|
|
136
|
-
spinner.stop();
|
|
137
|
-
if (opts.json) {
|
|
138
|
-
console.log(JSON.stringify(session, null, 2));
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
for (const line of sessionLines(session))
|
|
142
|
-
console.log(line);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch (err) {
|
|
146
|
-
spinner.stop();
|
|
147
|
-
handleError(err);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
return sessions;
|
|
151
|
-
}
|
|
152
|
-
//# sourceMappingURL=sessions.js.map
|