@uniwebpay/cli 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/dist/index.js +36 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -338,14 +338,14 @@ function registerPriceCommands(program2) {
338
338
  // src/commands/checkout.ts
339
339
  function registerCheckoutCommands(program2) {
340
340
  const checkout = program2.command("checkout").description("Manage checkout sessions");
341
- checkout.command("create").description("Create a new checkout session").requiredOption("-p, --price-id <priceId>", "Price ID to checkout").requiredOption("--success-url <url>", "URL to redirect on success").requiredOption("--cancel-url <url>", "URL to redirect on cancel").option("-m, --mode <mode>", "payment or subscription", "payment").option("-q, --quantity <quantity>", "Quantity", "1").option("--methods <methods>", "Payment methods (comma-separated: card,alipay,paynow,wechat)", "card,alipay,paynow,wechat").option("--customer-id <id>", "Customer ID (optional, auto-created from email at payment time)").option("--trial-days <days>", "Trial period in days (subscription mode)").action(async (opts) => {
341
+ checkout.command("create").description("Create a new checkout session").requiredOption("-p, --price-id <priceId>", "Price ID to checkout").option("--success-url <url>", "URL to redirect on success").option("--cancel-url <url>", "URL to redirect on cancel").option("-m, --mode <mode>", "payment or subscription", "payment").option("-q, --quantity <quantity>", "Quantity", "1").option("--methods <methods>", "Payment methods (comma-separated: card,alipay,paynow,wechat)", "card,alipay,paynow,wechat").option("--customer-id <id>", "Customer ID (optional, auto-created from email at payment time)").option("--trial-days <days>", "Trial period in days (subscription mode)").action(async (opts) => {
342
342
  try {
343
343
  const body = {
344
344
  mode: opts.mode,
345
- lineItems: [{ priceId: opts.priceId, quantity: parseInt(opts.quantity, 10) }],
346
- successUrl: opts.successUrl,
347
- cancelUrl: opts.cancelUrl
345
+ lineItems: [{ priceId: opts.priceId, quantity: parseInt(opts.quantity, 10) }]
348
346
  };
347
+ if (opts.successUrl) body.successUrl = opts.successUrl;
348
+ if (opts.cancelUrl) body.cancelUrl = opts.cancelUrl;
349
349
  if (opts.mode === "subscription") {
350
350
  body.paymentMethodTypes = ["card"];
351
351
  } else {
@@ -1263,6 +1263,37 @@ function registerPaymentCommands(program2) {
1263
1263
  // src/commands/refund.ts
1264
1264
  function registerRefundCommands(program2) {
1265
1265
  const refund = program2.command("refund").description("Manage refunds");
1266
+ refund.command("create").description("Create a refund for a payment").requiredOption("-p, --payment-id <paymentId>", "Payment ID to refund").option("-a, --amount <amount>", "Refund amount in cents (omit for full remaining refundable amount)").option("-r, --reason <reason>", "Refund reason (audit only \u2014 not forwarded to gateway)").option("--offline-refund", "Mark as offline refund (eCardnow only)").action(async (opts) => {
1267
+ try {
1268
+ const body = { paymentId: opts.paymentId };
1269
+ if (opts.amount !== void 0) {
1270
+ const amt = parseInt(opts.amount, 10);
1271
+ if (Number.isNaN(amt) || amt <= 0) {
1272
+ console.error("Error: amount must be a positive integer (cents)");
1273
+ process.exit(1);
1274
+ }
1275
+ body.amount = amt;
1276
+ }
1277
+ if (opts.reason) body.reason = opts.reason;
1278
+ if (opts.offlineRefund) body.offlineRefundFlag = true;
1279
+ const data = await apiRequest("POST", "/refunds", body);
1280
+ success("Refund created");
1281
+ output(data, (d) => [
1282
+ `Refund ID: ${d.id}`,
1283
+ `Payment ID: ${d.paymentId}`,
1284
+ `Amount: ${fmtAmount(d.amount, d.currency)}`,
1285
+ `Status: ${d.status}`,
1286
+ `Gateway: ${d.gateway}`,
1287
+ d.gatewayStatus ? `Gateway Status: ${d.gatewayStatus}` : null,
1288
+ d.gatewayRequestNo ? `Gateway Request No: ${d.gatewayRequestNo}` : null,
1289
+ d.gatewayTransactionId ? `Gateway Transaction ID: ${d.gatewayTransactionId}` : null,
1290
+ `Created: ${fmtDate(d.createdAt)}`
1291
+ ].filter(Boolean).join("\n"));
1292
+ } catch (err) {
1293
+ console.error(`Error: ${err.message}`);
1294
+ process.exit(1);
1295
+ }
1296
+ });
1266
1297
  refund.command("get <id>").description("Get refund status").option("--gateway", "Query gateway enquiry details").action(async (id, opts) => {
1267
1298
  try {
1268
1299
  const data = await apiRequest("GET", `/refunds/${id}${opts.gateway ? "?gateway=true" : ""}`);
@@ -1288,7 +1319,7 @@ function registerRefundCommands(program2) {
1288
1319
 
1289
1320
  // src/index.ts
1290
1321
  var program = new Command();
1291
- program.name("uniweb").description("uniweb CLI - manage payments from the command line").version("0.1.0").option("--json", "Output in JSON format").hook("preAction", (thisCommand) => {
1322
+ program.name("uniweb").description("uniweb CLI - manage payments from the command line").version("0.1.1").option("--json", "Output in JSON format").hook("preAction", (thisCommand) => {
1292
1323
  const opts = thisCommand.opts();
1293
1324
  if (opts.json) setOutputFormat("json");
1294
1325
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniwebpay/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "uniweb CLI - Payment infrastructure for the AI era. Accept cards, e-wallets, and QR payments in Southeast Asia.",
5
5
  "type": "module",
6
6
  "bin": {