@insforge/cli 0.1.87 → 0.1.88-razorpay.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/dist/index.js CHANGED
@@ -1173,7 +1173,7 @@ import * as clack5 from "@clack/prompts";
1173
1173
 
1174
1174
  // src/lib/analytics.ts
1175
1175
  import { PostHog } from "posthog-node";
1176
- var POSTHOG_API_KEY = "phc_ueV1ii62wdBTkH7E70ugyeqHIHu8dFDdjs0qq3TZhJz";
1176
+ var POSTHOG_API_KEY = "";
1177
1177
  var POSTHOG_HOST = process.env.POSTHOG_HOST || "https://us.i.posthog.com";
1178
1178
  var client = null;
1179
1179
  function getClient() {
@@ -7189,7 +7189,7 @@ function registerDiagnoseCommands(diagnoseCmd2) {
7189
7189
  const s = !json ? clack16.spinner() : null;
7190
7190
  s?.start("Collecting diagnostic data...");
7191
7191
  const data2 = await collectDiagnosticData(projectId, ossMode, apiUrl);
7192
- const cliVersion = "0.1.87";
7192
+ const cliVersion = "0.1.88-razorpay.0";
7193
7193
  s?.stop("Data collected");
7194
7194
  if (!json) {
7195
7195
  console.log(`
@@ -7428,75 +7428,142 @@ function withQuery(path6, params) {
7428
7428
  async function readJson(res) {
7429
7429
  return await res.json();
7430
7430
  }
7431
- function withEnvironmentPath(environment, suffix) {
7432
- return `/api/payments/${encodeURIComponent(environment)}${suffix}`;
7431
+ function withProviderPath(provider, suffix) {
7432
+ return `/api/payments/${encodeURIComponent(provider)}${suffix}`;
7433
7433
  }
7434
- async function getPaymentsStatus() {
7435
- return readJson(await ossFetch("/api/payments/status"));
7434
+ function withProviderEnvironmentPath(provider, environment, suffix) {
7435
+ return withProviderPath(
7436
+ provider,
7437
+ `/${encodeURIComponent(environment)}${suffix}`
7438
+ );
7439
+ }
7440
+ async function getStripePaymentsStatus() {
7441
+ return readJson(await ossFetch(withProviderPath("stripe", "/status")));
7442
+ }
7443
+ async function getRazorpayPaymentsStatus() {
7444
+ return readJson(await ossFetch(withProviderPath("razorpay", "/status")));
7436
7445
  }
7437
- async function getPaymentsConfig() {
7438
- return readJson(await ossFetch("/api/payments/config"));
7446
+ async function getStripePaymentsConfig() {
7447
+ return readJson(await ossFetch(withProviderPath("stripe", "/config")));
7448
+ }
7449
+ async function getRazorpayPaymentsConfig() {
7450
+ return readJson(await ossFetch(withProviderPath("razorpay", "/config")));
7439
7451
  }
7440
7452
  async function setStripeSecretKey(environment, secretKey) {
7453
+ const request = { secretKey };
7441
7454
  return readJson(
7442
- await ossFetch(withEnvironmentPath(environment, "/config"), {
7443
- method: "PUT",
7444
- body: JSON.stringify({ secretKey })
7445
- })
7455
+ await ossFetch(
7456
+ withProviderEnvironmentPath("stripe", environment, "/config"),
7457
+ {
7458
+ method: "PUT",
7459
+ body: JSON.stringify(request)
7460
+ }
7461
+ )
7462
+ );
7463
+ }
7464
+ async function setRazorpayKeys(environment, request) {
7465
+ return readJson(
7466
+ await ossFetch(
7467
+ withProviderEnvironmentPath("razorpay", environment, "/config"),
7468
+ {
7469
+ method: "PUT",
7470
+ body: JSON.stringify(request)
7471
+ }
7472
+ )
7446
7473
  );
7447
7474
  }
7448
7475
  async function removeStripeSecretKey(environment) {
7449
7476
  return readJson(
7450
- await ossFetch(withEnvironmentPath(environment, "/config"), {
7451
- method: "DELETE"
7452
- })
7477
+ await ossFetch(
7478
+ withProviderEnvironmentPath("stripe", environment, "/config"),
7479
+ {
7480
+ method: "DELETE"
7481
+ }
7482
+ )
7453
7483
  );
7454
7484
  }
7455
- async function syncPayments(environment = "all") {
7485
+ async function removeRazorpayKeys(environment) {
7456
7486
  return readJson(
7457
7487
  await ossFetch(
7458
- environment === "all" ? "/api/payments/sync" : withEnvironmentPath(environment, "/sync"),
7488
+ withProviderEnvironmentPath("razorpay", environment, "/config"),
7489
+ { method: "DELETE" }
7490
+ )
7491
+ );
7492
+ }
7493
+ async function syncStripePayments(environment = "all") {
7494
+ return readJson(
7495
+ await ossFetch(
7496
+ environment === "all" ? withProviderPath("stripe", "/sync") : withProviderEnvironmentPath("stripe", environment, "/sync"),
7459
7497
  { method: "POST" }
7460
7498
  )
7461
7499
  );
7462
7500
  }
7463
- async function configurePaymentWebhook(environment) {
7501
+ async function syncRazorpayPayments(environment = "all") {
7464
7502
  return readJson(
7465
- await ossFetch(withEnvironmentPath(environment, "/webhook"), {
7466
- method: "POST"
7467
- })
7503
+ await ossFetch(
7504
+ environment === "all" ? withProviderPath("razorpay", "/sync") : withProviderEnvironmentPath("razorpay", environment, "/sync"),
7505
+ { method: "POST" }
7506
+ )
7468
7507
  );
7469
7508
  }
7470
- async function listPaymentCatalog(environment) {
7471
- return readJson(await ossFetch(withEnvironmentPath(environment, "/catalog")));
7509
+ async function configureStripeWebhook(environment) {
7510
+ return readJson(
7511
+ await ossFetch(
7512
+ withProviderEnvironmentPath("stripe", environment, "/webhook"),
7513
+ {
7514
+ method: "POST"
7515
+ }
7516
+ )
7517
+ );
7472
7518
  }
7473
- async function listPaymentProducts(environment) {
7519
+ async function listStripeCatalog(environment) {
7474
7520
  return readJson(
7475
- await ossFetch(withEnvironmentPath(environment, "/catalog/products"))
7521
+ await ossFetch(
7522
+ withProviderEnvironmentPath("stripe", environment, "/catalog")
7523
+ )
7476
7524
  );
7477
7525
  }
7478
- async function getPaymentProduct(environment, productId) {
7526
+ async function listRazorpayCatalog(environment) {
7479
7527
  return readJson(
7480
7528
  await ossFetch(
7481
- withEnvironmentPath(
7529
+ withProviderEnvironmentPath("razorpay", environment, "/catalog")
7530
+ )
7531
+ );
7532
+ }
7533
+ async function listStripeProducts(environment) {
7534
+ return readJson(
7535
+ await ossFetch(
7536
+ withProviderEnvironmentPath("stripe", environment, "/catalog/products")
7537
+ )
7538
+ );
7539
+ }
7540
+ async function getStripeProduct(environment, productId) {
7541
+ return readJson(
7542
+ await ossFetch(
7543
+ withProviderEnvironmentPath(
7544
+ "stripe",
7482
7545
  environment,
7483
7546
  `/catalog/products/${encodeURIComponent(productId)}`
7484
7547
  )
7485
7548
  )
7486
7549
  );
7487
7550
  }
7488
- async function createPaymentProduct(environment, request) {
7551
+ async function createStripeProduct(environment, request) {
7489
7552
  return readJson(
7490
- await ossFetch(withEnvironmentPath(environment, "/catalog/products"), {
7491
- method: "POST",
7492
- body: JSON.stringify(request)
7493
- })
7553
+ await ossFetch(
7554
+ withProviderEnvironmentPath("stripe", environment, "/catalog/products"),
7555
+ {
7556
+ method: "POST",
7557
+ body: JSON.stringify(request)
7558
+ }
7559
+ )
7494
7560
  );
7495
7561
  }
7496
- async function updatePaymentProduct(environment, productId, request) {
7562
+ async function updateStripeProduct(environment, productId, request) {
7497
7563
  return readJson(
7498
7564
  await ossFetch(
7499
- withEnvironmentPath(
7565
+ withProviderEnvironmentPath(
7566
+ "stripe",
7500
7567
  environment,
7501
7568
  `/catalog/products/${encodeURIComponent(productId)}`
7502
7569
  ),
@@ -7507,10 +7574,11 @@ async function updatePaymentProduct(environment, productId, request) {
7507
7574
  )
7508
7575
  );
7509
7576
  }
7510
- async function deletePaymentProduct(environment, productId) {
7577
+ async function deleteStripeProduct(environment, productId) {
7511
7578
  return readJson(
7512
7579
  await ossFetch(
7513
- withEnvironmentPath(
7580
+ withProviderEnvironmentPath(
7581
+ "stripe",
7514
7582
  environment,
7515
7583
  `/catalog/products/${encodeURIComponent(productId)}`
7516
7584
  ),
@@ -7518,37 +7586,43 @@ async function deletePaymentProduct(environment, productId) {
7518
7586
  )
7519
7587
  );
7520
7588
  }
7521
- async function listPaymentPrices(environment, stripeProductId) {
7589
+ async function listStripePrices(environment, productId) {
7522
7590
  return readJson(
7523
7591
  await ossFetch(
7524
- withQuery(withEnvironmentPath(environment, "/catalog/prices"), {
7525
- stripeProductId
7526
- })
7592
+ withQuery(
7593
+ withProviderEnvironmentPath("stripe", environment, "/catalog/prices"),
7594
+ { productId }
7595
+ )
7527
7596
  )
7528
7597
  );
7529
7598
  }
7530
- async function getPaymentPrice(environment, priceId) {
7599
+ async function getStripePrice(environment, priceId) {
7531
7600
  return readJson(
7532
7601
  await ossFetch(
7533
- withEnvironmentPath(
7602
+ withProviderEnvironmentPath(
7603
+ "stripe",
7534
7604
  environment,
7535
7605
  `/catalog/prices/${encodeURIComponent(priceId)}`
7536
7606
  )
7537
7607
  )
7538
7608
  );
7539
7609
  }
7540
- async function createPaymentPrice(environment, request) {
7610
+ async function createStripePrice(environment, request) {
7541
7611
  return readJson(
7542
- await ossFetch(withEnvironmentPath(environment, "/catalog/prices"), {
7543
- method: "POST",
7544
- body: JSON.stringify(request)
7545
- })
7612
+ await ossFetch(
7613
+ withProviderEnvironmentPath("stripe", environment, "/catalog/prices"),
7614
+ {
7615
+ method: "POST",
7616
+ body: JSON.stringify(request)
7617
+ }
7618
+ )
7546
7619
  );
7547
7620
  }
7548
- async function updatePaymentPrice(environment, priceId, request) {
7621
+ async function updateStripePrice(environment, priceId, request) {
7549
7622
  return readJson(
7550
7623
  await ossFetch(
7551
- withEnvironmentPath(
7624
+ withProviderEnvironmentPath(
7625
+ "stripe",
7552
7626
  environment,
7553
7627
  `/catalog/prices/${encodeURIComponent(priceId)}`
7554
7628
  ),
@@ -7559,10 +7633,11 @@ async function updatePaymentPrice(environment, priceId, request) {
7559
7633
  )
7560
7634
  );
7561
7635
  }
7562
- async function archivePaymentPrice(environment, priceId) {
7636
+ async function archiveStripePrice(environment, priceId) {
7563
7637
  return readJson(
7564
7638
  await ossFetch(
7565
- withEnvironmentPath(
7639
+ withProviderEnvironmentPath(
7640
+ "stripe",
7566
7641
  environment,
7567
7642
  `/catalog/prices/${encodeURIComponent(priceId)}`
7568
7643
  ),
@@ -7570,29 +7645,99 @@ async function archivePaymentPrice(environment, priceId) {
7570
7645
  )
7571
7646
  );
7572
7647
  }
7573
- async function listSubscriptions(environment, request) {
7648
+ async function createRazorpayItem(environment, request) {
7649
+ return readJson(
7650
+ await ossFetch(
7651
+ withProviderEnvironmentPath("razorpay", environment, "/catalog/items"),
7652
+ {
7653
+ method: "POST",
7654
+ body: JSON.stringify(request)
7655
+ }
7656
+ )
7657
+ );
7658
+ }
7659
+ async function updateRazorpayItem(environment, itemId, request) {
7660
+ return readJson(
7661
+ await ossFetch(
7662
+ withProviderEnvironmentPath(
7663
+ "razorpay",
7664
+ environment,
7665
+ `/catalog/items/${encodeURIComponent(itemId)}`
7666
+ ),
7667
+ {
7668
+ method: "PATCH",
7669
+ body: JSON.stringify(request)
7670
+ }
7671
+ )
7672
+ );
7673
+ }
7674
+ async function createRazorpayPlan(environment, request) {
7675
+ return readJson(
7676
+ await ossFetch(
7677
+ withProviderEnvironmentPath("razorpay", environment, "/catalog/plans"),
7678
+ {
7679
+ method: "POST",
7680
+ body: JSON.stringify(request)
7681
+ }
7682
+ )
7683
+ );
7684
+ }
7685
+ async function listStripeSubscriptions(environment, request) {
7574
7686
  return readJson(
7575
7687
  await ossFetch(
7576
- withQuery(withEnvironmentPath(environment, "/subscriptions"), request)
7688
+ withQuery(
7689
+ withProviderEnvironmentPath("stripe", environment, "/subscriptions"),
7690
+ request
7691
+ )
7577
7692
  )
7578
7693
  );
7579
7694
  }
7580
- async function listPaymentCustomers(environment, request = {}) {
7695
+ async function listRazorpaySubscriptions(environment, request) {
7581
7696
  return readJson(
7582
7697
  await ossFetch(
7583
- withQuery(withEnvironmentPath(environment, "/customers"), request)
7698
+ withQuery(
7699
+ withProviderEnvironmentPath("razorpay", environment, "/subscriptions"),
7700
+ request
7701
+ )
7584
7702
  )
7585
7703
  );
7586
7704
  }
7587
- async function listPaymentHistory(environment, request) {
7705
+ async function listPaymentCustomers(provider, environment, request = {}) {
7588
7706
  return readJson(
7589
7707
  await ossFetch(
7590
- withQuery(withEnvironmentPath(environment, "/payment-history"), request)
7708
+ withQuery(
7709
+ withProviderEnvironmentPath(provider, environment, "/customers"),
7710
+ request
7711
+ )
7712
+ )
7713
+ );
7714
+ }
7715
+ async function listPaymentTransactions(provider, environment, request) {
7716
+ return readJson(
7717
+ await ossFetch(
7718
+ withQuery(
7719
+ withProviderEnvironmentPath(provider, environment, "/transactions"),
7720
+ request
7721
+ )
7591
7722
  )
7592
7723
  );
7593
7724
  }
7594
7725
 
7595
7726
  // src/commands/payments/utils.ts
7727
+ var MAX_TELEMETRY_ERROR_MESSAGE_LENGTH = 500;
7728
+ function getErrorTelemetry(error) {
7729
+ const message = error instanceof Error ? error.message : String(error);
7730
+ const truncatedMessage = message.length > MAX_TELEMETRY_ERROR_MESSAGE_LENGTH ? `${message.slice(0, MAX_TELEMETRY_ERROR_MESSAGE_LENGTH)}...` : message;
7731
+ return {
7732
+ error_name: error instanceof Error ? error.name : typeof error,
7733
+ error_message: truncatedMessage,
7734
+ ...error instanceof CLIError ? {
7735
+ error_code: error.code,
7736
+ exit_code: error.exitCode,
7737
+ status_code: error.statusCode
7738
+ } : {}
7739
+ };
7740
+ }
7596
7741
  function parseEnvironment(value) {
7597
7742
  if (value === "test" || value === "live") return value;
7598
7743
  throw new CLIError('Environment must be "test" or "live".');
@@ -7601,6 +7746,15 @@ function parseEnvironmentOrAll(value) {
7601
7746
  if (value === "all") return value;
7602
7747
  return parseEnvironment(value);
7603
7748
  }
7749
+ function parseRazorpayPlanPeriod(value) {
7750
+ if (value === void 0) return void 0;
7751
+ if (value === "daily" || value === "weekly" || value === "monthly" || value === "yearly") {
7752
+ return value;
7753
+ }
7754
+ throw new CLIError(
7755
+ "--period must be one of: daily, weekly, monthly, yearly."
7756
+ );
7757
+ }
7604
7758
  function parseBooleanOption(value, flagName) {
7605
7759
  if (value === void 0) return void 0;
7606
7760
  const normalized = value.toLowerCase();
@@ -7668,13 +7822,14 @@ function formatRecurring(interval, intervalCount) {
7668
7822
  if (!interval) return "one-time";
7669
7823
  return `${intervalCount && intervalCount > 1 ? `${intervalCount} ` : ""}${interval}`;
7670
7824
  }
7671
- async function trackPaymentUsage(subcommand, success, properties = {}) {
7825
+ async function trackPaymentUsage(subcommand, success, properties = {}, error) {
7672
7826
  try {
7673
7827
  const config = getProjectConfig();
7674
7828
  if (config) {
7675
7829
  trackPayments(subcommand, config, {
7676
7830
  success,
7677
- ...properties
7831
+ ...properties,
7832
+ ...error !== void 0 ? getErrorTelemetry(error) : {}
7678
7833
  });
7679
7834
  }
7680
7835
  } catch {
@@ -7684,76 +7839,138 @@ async function trackPaymentUsage(subcommand, success, properties = {}) {
7684
7839
  }
7685
7840
 
7686
7841
  // src/commands/payments/catalog.ts
7687
- function registerPaymentsCatalogCommand(paymentsCmd2) {
7688
- paymentsCmd2.command("catalog").description("List mirrored Stripe products and prices for one environment").requiredOption(
7842
+ function registerPaymentsCatalogCommand(paymentsCmd2, provider) {
7843
+ paymentsCmd2.command("catalog").description("List mirrored provider catalog records for one environment").requiredOption(
7689
7844
  "--environment <environment>",
7690
- "Stripe environment: test or live"
7845
+ "Payment environment: test or live"
7691
7846
  ).action(async (opts, cmd) => {
7692
7847
  const { json } = getRootOpts(cmd);
7693
7848
  try {
7694
7849
  const environment = parseEnvironment(opts.environment);
7695
7850
  await requireAuth();
7696
- const data = await listPaymentCatalog(environment);
7697
- if (json) {
7698
- outputJson(data);
7699
- } else {
7700
- if (data.products.length === 0 && data.prices.length === 0) {
7701
- console.log("No Stripe catalog records found.");
7702
- await trackPaymentUsage("catalog", true, { environment });
7703
- return;
7704
- }
7705
- if (data.products.length > 0) {
7706
- console.log("Products");
7707
- outputTable(
7708
- ["Env", "Product ID", "Name", "Active", "Default Price"],
7709
- data.products.map((product) => [
7710
- product.environment,
7711
- product.stripeProductId,
7712
- product.name,
7713
- product.active ? "Yes" : "No",
7714
- product.defaultPriceId ?? "-"
7715
- ])
7716
- );
7851
+ if (provider === "stripe") {
7852
+ const data = await listStripeCatalog(environment);
7853
+ if (json) {
7854
+ outputJson(data);
7855
+ } else {
7856
+ if (data.products.length === 0 && data.prices.length === 0) {
7857
+ console.log("No Stripe catalog records found.");
7858
+ await trackPaymentUsage("catalog", true, {
7859
+ provider,
7860
+ environment
7861
+ });
7862
+ return;
7863
+ }
7864
+ if (data.products.length > 0) {
7865
+ console.log("Products");
7866
+ outputTable(
7867
+ ["Env", "Product ID", "Name", "Active", "Default Price"],
7868
+ data.products.map((product) => [
7869
+ product.environment,
7870
+ product.productId,
7871
+ product.name,
7872
+ product.active ? "Yes" : "No",
7873
+ product.defaultPriceId ?? "-"
7874
+ ])
7875
+ );
7876
+ }
7877
+ if (data.prices.length > 0) {
7878
+ console.log("Prices");
7879
+ outputTable(
7880
+ [
7881
+ "Env",
7882
+ "Price ID",
7883
+ "Product ID",
7884
+ "Amount",
7885
+ "Type",
7886
+ "Active",
7887
+ "Recurring"
7888
+ ],
7889
+ data.prices.map((price) => [
7890
+ price.environment,
7891
+ price.priceId,
7892
+ price.productId ?? "-",
7893
+ formatAmount(price.unitAmount, price.currency),
7894
+ price.type,
7895
+ price.active ? "Yes" : "No",
7896
+ formatRecurring(
7897
+ price.recurringInterval,
7898
+ price.recurringIntervalCount
7899
+ )
7900
+ ])
7901
+ );
7902
+ }
7717
7903
  }
7718
- if (data.prices.length > 0) {
7719
- console.log("Prices");
7720
- outputTable(
7721
- [
7722
- "Env",
7723
- "Price ID",
7724
- "Product ID",
7725
- "Amount",
7726
- "Type",
7727
- "Active",
7728
- "Recurring"
7729
- ],
7730
- data.prices.map((price) => [
7731
- price.environment,
7732
- price.stripePriceId,
7733
- price.stripeProductId ?? "-",
7734
- formatAmount(price.unitAmount, price.currency),
7735
- price.type,
7736
- price.active ? "Yes" : "No",
7737
- formatRecurring(
7738
- price.recurringInterval,
7739
- price.recurringIntervalCount
7740
- )
7741
- ])
7742
- );
7904
+ } else {
7905
+ const data = await listRazorpayCatalog(environment);
7906
+ if (json) {
7907
+ outputJson(data);
7908
+ } else {
7909
+ if (data.items.length === 0 && data.plans.length === 0) {
7910
+ console.log("No Razorpay catalog records found.");
7911
+ await trackPaymentUsage("catalog", true, {
7912
+ provider,
7913
+ environment
7914
+ });
7915
+ return;
7916
+ }
7917
+ if (data.items.length > 0) {
7918
+ console.log("Items");
7919
+ outputTable(
7920
+ ["Env", "Item ID", "Name", "Amount", "Active", "Type"],
7921
+ data.items.map((item) => [
7922
+ item.environment,
7923
+ item.itemId,
7924
+ item.name,
7925
+ formatAmount(item.amount, item.currency),
7926
+ item.active ? "Yes" : "No",
7927
+ item.type ?? "-"
7928
+ ])
7929
+ );
7930
+ }
7931
+ if (data.plans.length > 0) {
7932
+ console.log("Plans");
7933
+ outputTable(
7934
+ [
7935
+ "Env",
7936
+ "Plan ID",
7937
+ "Item ID",
7938
+ "Amount",
7939
+ "Period",
7940
+ "Interval",
7941
+ "Active"
7942
+ ],
7943
+ data.plans.map((plan) => [
7944
+ plan.environment,
7945
+ plan.planId,
7946
+ plan.itemId,
7947
+ formatAmount(plan.amount, plan.currency),
7948
+ plan.period,
7949
+ String(plan.interval),
7950
+ plan.active ? "Yes" : "No"
7951
+ ])
7952
+ );
7953
+ }
7743
7954
  }
7744
7955
  }
7745
- await trackPaymentUsage("catalog", true, { environment });
7956
+ await trackPaymentUsage("catalog", true, { provider, environment });
7746
7957
  } catch (err) {
7747
- await trackPaymentUsage("catalog", false, {
7748
- environment: opts.environment
7749
- });
7958
+ await trackPaymentUsage(
7959
+ "catalog",
7960
+ false,
7961
+ {
7962
+ provider,
7963
+ environment: opts.environment
7964
+ },
7965
+ err
7966
+ );
7750
7967
  handleError(err, json);
7751
7968
  }
7752
7969
  });
7753
7970
  }
7754
7971
 
7755
7972
  // src/commands/payments/config.ts
7756
- function outputConfigTable(data) {
7973
+ function outputStripeConfigTable(data) {
7757
7974
  if (data.keys.length === 0) {
7758
7975
  console.log("No Stripe keys configured.");
7759
7976
  return;
@@ -7767,32 +7984,111 @@ function outputConfigTable(data) {
7767
7984
  ])
7768
7985
  );
7769
7986
  }
7770
- function registerPaymentsConfigCommand(paymentsCmd2) {
7771
- const configCmd = paymentsCmd2.command("config").description("Manage Stripe API keys for payments").action(async (_opts, cmd) => {
7987
+ function outputRazorpayConfigTable(data) {
7988
+ if (data.razorpayKeys.length === 0) {
7989
+ console.log("No Razorpay keys configured.");
7990
+ return;
7991
+ }
7992
+ outputTable(
7993
+ ["Env", "Type", "Configured", "Key"],
7994
+ data.razorpayKeys.map((key) => [
7995
+ key.environment,
7996
+ key.keyType,
7997
+ key.hasKey ? "Yes" : "No",
7998
+ key.maskedKey ?? "-"
7999
+ ])
8000
+ );
8001
+ }
8002
+ function registerPaymentsConfigCommand(paymentsCmd2, provider) {
8003
+ const configCmd = paymentsCmd2.command("config").description("Manage payment provider keys");
8004
+ configCmd.command("list").description("List configured payment provider keys").action(async (_opts, cmd) => {
7772
8005
  const { json } = getRootOpts(cmd);
7773
8006
  try {
7774
8007
  await requireAuth();
7775
- const data = await getPaymentsConfig();
8008
+ if (provider === "stripe") {
8009
+ const data = await getStripePaymentsConfig();
8010
+ if (json) {
8011
+ outputJson(data);
8012
+ } else {
8013
+ outputStripeConfigTable(data);
8014
+ }
8015
+ } else {
8016
+ const data = await getRazorpayPaymentsConfig();
8017
+ if (json) {
8018
+ outputJson(data);
8019
+ } else {
8020
+ outputRazorpayConfigTable(data);
8021
+ }
8022
+ }
8023
+ await trackPaymentUsage("config", true, { provider });
8024
+ } catch (err) {
8025
+ await trackPaymentUsage("config", false, { provider }, err);
8026
+ handleError(err, json);
8027
+ }
8028
+ });
8029
+ if (provider === "stripe") {
8030
+ registerStripeConfigSetCommand(configCmd);
8031
+ } else {
8032
+ registerRazorpayConfigSetCommand(configCmd);
8033
+ }
8034
+ configCmd.command("remove").description("Remove configured payment provider keys").requiredOption(
8035
+ "--environment <environment>",
8036
+ "Payment environment: test or live"
8037
+ ).action(async (opts, cmd) => {
8038
+ const { json, yes } = getRootOpts(cmd);
8039
+ try {
8040
+ const environment = parseEnvironment(opts.environment);
8041
+ await requireAuth();
8042
+ if (json && !yes) {
8043
+ throw new CLIError(
8044
+ "Use --yes with --json to remove payment keys non-interactively."
8045
+ );
8046
+ }
8047
+ if (!yes) {
8048
+ const confirm8 = await confirm2({
8049
+ message: `Remove ${provider} ${environment} keys? Payment sync and mutations for this environment will stop.`
8050
+ });
8051
+ if (isCancel2(confirm8) || !confirm8) process.exit(0);
8052
+ }
8053
+ const data = provider === "stripe" ? await removeStripeSecretKey(environment) : await removeRazorpayKeys(environment);
7776
8054
  if (json) {
7777
8055
  outputJson(data);
7778
8056
  } else {
7779
- outputConfigTable(data);
8057
+ outputSuccess(`${provider} ${environment} keys removed.`);
7780
8058
  }
7781
- await trackPaymentUsage("config", true);
8059
+ await trackPaymentUsage("config.remove", true, {
8060
+ provider,
8061
+ environment
8062
+ });
7782
8063
  } catch (err) {
7783
- await trackPaymentUsage("config", false);
8064
+ await trackPaymentUsage(
8065
+ "config.remove",
8066
+ false,
8067
+ {
8068
+ provider,
8069
+ environment: opts.environment
8070
+ },
8071
+ err
8072
+ );
7784
8073
  handleError(err, json);
7785
8074
  }
7786
8075
  });
7787
- configCmd.command("set <environment> [secretKey]").description("Configure a Stripe secret key for test or live payments").action(async (environmentValue, secretKeyValue, _opts, cmd) => {
8076
+ }
8077
+ function registerStripeConfigSetCommand(configCmd) {
8078
+ configCmd.command("set [secretKey]").description("Configure a Stripe secret key for test or live payments").requiredOption(
8079
+ "--environment <environment>",
8080
+ "Stripe environment: test or live"
8081
+ ).option("--secret-key <secretKey>", "Stripe secret key").action(async (secretKeyValue, opts, cmd) => {
7788
8082
  const { json } = getRootOpts(cmd);
7789
8083
  try {
7790
- const environment = parseEnvironment(environmentValue);
8084
+ const environment = parseEnvironment(opts.environment);
7791
8085
  await requireAuth();
7792
- let secretKey = secretKeyValue;
8086
+ let secretKey = opts.secretKey ?? secretKeyValue;
7793
8087
  if (!secretKey) {
7794
8088
  if (json) {
7795
- throw new CLIError("Provide secretKey when using --json.");
8089
+ throw new CLIError(
8090
+ "Provide secretKey or --secret-key when using --json."
8091
+ );
7796
8092
  }
7797
8093
  const input = await password2({
7798
8094
  message: `Stripe ${environment} secret key`
@@ -7806,35 +8102,78 @@ function registerPaymentsConfigCommand(paymentsCmd2) {
7806
8102
  } else {
7807
8103
  outputSuccess(`Stripe ${environment} key configured.`);
7808
8104
  }
7809
- await trackPaymentUsage("config.set", true, { environment });
8105
+ await trackPaymentUsage("config.set", true, {
8106
+ provider: "stripe",
8107
+ environment
8108
+ });
7810
8109
  } catch (err) {
7811
- await trackPaymentUsage("config.set", false, { environment: environmentValue });
8110
+ await trackPaymentUsage(
8111
+ "config.set",
8112
+ false,
8113
+ {
8114
+ provider: "stripe",
8115
+ environment: opts.environment
8116
+ },
8117
+ err
8118
+ );
7812
8119
  handleError(err, json);
7813
8120
  }
7814
8121
  });
7815
- configCmd.command("remove <environment>").alias("delete").description("Remove a configured Stripe secret key").action(async (environmentValue, _opts, cmd) => {
7816
- const { json, yes } = getRootOpts(cmd);
8122
+ }
8123
+ function registerRazorpayConfigSetCommand(configCmd) {
8124
+ configCmd.command("set").description("Configure Razorpay keys for test or live payments").requiredOption(
8125
+ "--environment <environment>",
8126
+ "Razorpay environment: test or live"
8127
+ ).option("--key-id <keyId>", "Razorpay key id").option("--key-secret <keySecret>", "Razorpay key secret").action(async (opts, cmd) => {
8128
+ const { json } = getRootOpts(cmd);
7817
8129
  try {
7818
- const environment = parseEnvironment(environmentValue);
8130
+ const environment = parseEnvironment(opts.environment);
7819
8131
  await requireAuth();
7820
- if (json && !yes) {
7821
- throw new CLIError("Use --yes with --json to remove a Stripe key non-interactively.");
8132
+ let keyId = opts.keyId;
8133
+ let keySecret = opts.keySecret;
8134
+ if (!keyId) {
8135
+ if (json) {
8136
+ throw new CLIError("Provide --key-id when using --json.");
8137
+ }
8138
+ const input = await text2({
8139
+ message: `Razorpay ${environment} key id`
8140
+ });
8141
+ if (isCancel2(input)) process.exit(0);
8142
+ keyId = input;
7822
8143
  }
7823
- if (!yes) {
7824
- const confirm8 = await confirm2({
7825
- message: `Remove Stripe ${environment} key? Payment sync and mutations for this environment will stop.`
8144
+ if (!keySecret) {
8145
+ if (json) {
8146
+ throw new CLIError("Provide --key-secret when using --json.");
8147
+ }
8148
+ const input = await password2({
8149
+ message: `Razorpay ${environment} key secret`
7826
8150
  });
7827
- if (isCancel2(confirm8) || !confirm8) process.exit(0);
8151
+ if (isCancel2(input)) process.exit(0);
8152
+ keySecret = input;
7828
8153
  }
7829
- const data = await removeStripeSecretKey(environment);
8154
+ const data = await setRazorpayKeys(environment, {
8155
+ keyId,
8156
+ keySecret
8157
+ });
7830
8158
  if (json) {
7831
8159
  outputJson(data);
7832
8160
  } else {
7833
- outputSuccess(`Stripe ${environment} key removed.`);
8161
+ outputSuccess(`Razorpay ${environment} keys configured.`);
7834
8162
  }
7835
- await trackPaymentUsage("config.remove", true, { environment });
8163
+ await trackPaymentUsage("config.set", true, {
8164
+ provider: "razorpay",
8165
+ environment
8166
+ });
7836
8167
  } catch (err) {
7837
- await trackPaymentUsage("config.remove", false, { environment: environmentValue });
8168
+ await trackPaymentUsage(
8169
+ "config.set",
8170
+ false,
8171
+ {
8172
+ provider: "razorpay",
8173
+ environment: opts.environment
8174
+ },
8175
+ err
8176
+ );
7838
8177
  handleError(err, json);
7839
8178
  }
7840
8179
  });
@@ -7853,21 +8192,23 @@ function formatPaymentMethod(customer) {
7853
8192
  }
7854
8193
  return "-";
7855
8194
  }
7856
- function registerPaymentsCustomersCommand(paymentsCmd2) {
7857
- paymentsCmd2.command("customers").description("List mirrored Stripe customers").requiredOption(
8195
+ function registerPaymentsCustomersCommand(paymentsCmd2, provider) {
8196
+ paymentsCmd2.command("customers").description("List mirrored payment provider customers").requiredOption(
7858
8197
  "--environment <environment>",
7859
- "Stripe environment: test or live"
8198
+ "Payment environment: test or live"
7860
8199
  ).option("--limit <limit>", "Maximum rows to return (1-100)", "50").action(async (opts, cmd) => {
7861
8200
  const { json } = getRootOpts(cmd);
7862
8201
  try {
7863
8202
  const environment = parseEnvironment(opts.environment);
7864
8203
  const limit = parseIntegerOption(opts.limit, "--limit", { min: 1, max: 100 }) ?? 50;
7865
8204
  await requireAuth();
7866
- const data = await listPaymentCustomers(environment, { limit });
8205
+ const data = await listPaymentCustomers(provider, environment, {
8206
+ limit
8207
+ });
7867
8208
  if (json) {
7868
8209
  outputJson(data);
7869
8210
  } else if (data.customers.length === 0) {
7870
- console.log("No Stripe customers found.");
8211
+ console.log(`No ${provider} customers found.`);
7871
8212
  } else {
7872
8213
  outputTable(
7873
8214
  [
@@ -7881,7 +8222,7 @@ function registerPaymentsCustomersCommand(paymentsCmd2) {
7881
8222
  "Country"
7882
8223
  ],
7883
8224
  data.customers.map((customer) => [
7884
- customer.stripeCustomerId,
8225
+ customer.providerCustomerId,
7885
8226
  customer.email ?? "-",
7886
8227
  customer.name ?? "-",
7887
8228
  String(customer.paymentsCount),
@@ -7892,72 +8233,312 @@ function registerPaymentsCustomersCommand(paymentsCmd2) {
7892
8233
  ])
7893
8234
  );
7894
8235
  }
7895
- await trackPaymentUsage("customers", true, { environment });
7896
- } catch (err) {
7897
- await trackPaymentUsage("customers", false, {
7898
- environment: opts.environment
8236
+ await trackPaymentUsage("customers", true, { provider, environment });
8237
+ } catch (err) {
8238
+ await trackPaymentUsage(
8239
+ "customers",
8240
+ false,
8241
+ {
8242
+ provider,
8243
+ environment: opts.environment
8244
+ },
8245
+ err
8246
+ );
8247
+ handleError(err, json);
8248
+ }
8249
+ });
8250
+ }
8251
+
8252
+ // src/commands/payments/items.ts
8253
+ function nullableString(value) {
8254
+ if (value === void 0) return void 0;
8255
+ return value === "null" ? null : value;
8256
+ }
8257
+ function outputItemsTable(items) {
8258
+ if (items.length === 0) {
8259
+ console.log("No Razorpay items found.");
8260
+ return;
8261
+ }
8262
+ outputTable(
8263
+ ["Env", "Item ID", "Name", "Amount", "Active", "Type", "Synced At"],
8264
+ items.map((item) => [
8265
+ item.environment,
8266
+ item.itemId,
8267
+ item.name,
8268
+ formatAmount(item.amount, item.currency),
8269
+ item.active ? "Yes" : "No",
8270
+ item.type ?? "-",
8271
+ formatDate(item.syncedAt)
8272
+ ])
8273
+ );
8274
+ }
8275
+ function registerPaymentsItemsCommand(paymentsCmd2) {
8276
+ const itemsCmd = paymentsCmd2.command("items").description("Manage Razorpay items");
8277
+ itemsCmd.command("list").description("List mirrored Razorpay items").requiredOption(
8278
+ "--environment <environment>",
8279
+ "Razorpay environment: test or live"
8280
+ ).action(async (opts, cmd) => {
8281
+ const { json } = getRootOpts(cmd);
8282
+ try {
8283
+ const environment = parseEnvironment(opts.environment);
8284
+ await requireAuth();
8285
+ const data = await listRazorpayCatalog(environment);
8286
+ if (json) {
8287
+ outputJson({ items: data.items });
8288
+ } else {
8289
+ outputItemsTable(data.items);
8290
+ }
8291
+ await trackPaymentUsage("items.list", true, {
8292
+ provider: "razorpay",
8293
+ environment
8294
+ });
8295
+ } catch (err) {
8296
+ await trackPaymentUsage(
8297
+ "items.list",
8298
+ false,
8299
+ {
8300
+ provider: "razorpay",
8301
+ environment: opts.environment
8302
+ },
8303
+ err
8304
+ );
8305
+ handleError(err, json);
8306
+ }
8307
+ });
8308
+ itemsCmd.command("create").description("Create a Razorpay item").requiredOption(
8309
+ "--environment <environment>",
8310
+ "Razorpay environment: test or live"
8311
+ ).requiredOption("--name <name>", "Item name").requiredOption("--amount <amount>", "Amount in the smallest currency unit").requiredOption(
8312
+ "--currency <currency>",
8313
+ "Three-letter currency code, e.g. inr"
8314
+ ).option("--description <description>", 'Item description, or "null"').option("--metadata <json>", "Metadata JSON object with string values").action(async (opts, cmd) => {
8315
+ const { json } = getRootOpts(cmd);
8316
+ try {
8317
+ const environment = parseEnvironment(opts.environment);
8318
+ await requireAuth();
8319
+ const request = {
8320
+ name: opts.name,
8321
+ amount: parseIntegerOption(opts.amount, "--amount", { min: 0 }) ?? 0,
8322
+ currency: opts.currency
8323
+ };
8324
+ const description = nullableString(opts.description);
8325
+ const metadata = parseMetadataOption(opts.metadata);
8326
+ if (description !== void 0) request.description = description;
8327
+ if (metadata !== void 0) request.metadata = metadata;
8328
+ const data = await createRazorpayItem(environment, request);
8329
+ if (json) {
8330
+ outputJson(data);
8331
+ } else {
8332
+ outputSuccess(`Razorpay item created: ${data.item.itemId}`);
8333
+ }
8334
+ await trackPaymentUsage("items.create", true, {
8335
+ provider: "razorpay",
8336
+ environment
8337
+ });
8338
+ } catch (err) {
8339
+ await trackPaymentUsage(
8340
+ "items.create",
8341
+ false,
8342
+ {
8343
+ provider: "razorpay",
8344
+ environment: opts.environment
8345
+ },
8346
+ err
8347
+ );
8348
+ handleError(err, json);
8349
+ }
8350
+ });
8351
+ itemsCmd.command("update <itemId>").description("Update a Razorpay item").requiredOption(
8352
+ "--environment <environment>",
8353
+ "Razorpay environment: test or live"
8354
+ ).option("--name <name>", "Item name").option("--description <description>", 'Item description, or "null"').option("--amount <amount>", "Amount in the smallest currency unit").option("--currency <currency>", "Three-letter currency code").option("--active <bool>", "Set active status (true/false)").option("--metadata <json>", "Metadata JSON object with string values").action(async (itemId, opts, cmd) => {
8355
+ const { json } = getRootOpts(cmd);
8356
+ try {
8357
+ const environment = parseEnvironment(opts.environment);
8358
+ await requireAuth();
8359
+ const request = {};
8360
+ const description = nullableString(opts.description);
8361
+ const amount = parseIntegerOption(opts.amount, "--amount", { min: 0 });
8362
+ const active = parseBooleanOption(opts.active, "--active");
8363
+ const metadata = parseMetadataOption(opts.metadata);
8364
+ if (opts.name !== void 0) request.name = opts.name;
8365
+ if (description !== void 0) request.description = description;
8366
+ if (amount !== void 0) request.amount = amount;
8367
+ if (opts.currency !== void 0) request.currency = opts.currency;
8368
+ if (active !== void 0) request.active = active;
8369
+ if (metadata !== void 0) request.metadata = metadata;
8370
+ if (Object.keys(request).length === 0) {
8371
+ throw new CLIError(
8372
+ "Provide at least one option to update (--name, --description, --amount, --currency, --active, --metadata)."
8373
+ );
8374
+ }
8375
+ const data = await updateRazorpayItem(environment, itemId, request);
8376
+ if (json) {
8377
+ outputJson(data);
8378
+ } else {
8379
+ outputSuccess(`Razorpay item updated: ${data.item.itemId}`);
8380
+ }
8381
+ await trackPaymentUsage("items.update", true, {
8382
+ provider: "razorpay",
8383
+ environment
8384
+ });
8385
+ } catch (err) {
8386
+ await trackPaymentUsage(
8387
+ "items.update",
8388
+ false,
8389
+ {
8390
+ provider: "razorpay",
8391
+ environment: opts.environment
8392
+ },
8393
+ err
8394
+ );
8395
+ handleError(err, json);
8396
+ }
8397
+ });
8398
+ }
8399
+
8400
+ // src/commands/payments/plans.ts
8401
+ function nullableString2(value) {
8402
+ if (value === void 0) return void 0;
8403
+ return value === "null" ? null : value;
8404
+ }
8405
+ function outputPlansTable(plans) {
8406
+ if (plans.length === 0) {
8407
+ console.log("No Razorpay plans found.");
8408
+ return;
8409
+ }
8410
+ outputTable(
8411
+ [
8412
+ "Env",
8413
+ "Plan ID",
8414
+ "Item ID",
8415
+ "Amount",
8416
+ "Period",
8417
+ "Interval",
8418
+ "Active",
8419
+ "Synced At"
8420
+ ],
8421
+ plans.map((plan) => [
8422
+ plan.environment,
8423
+ plan.planId,
8424
+ plan.itemId,
8425
+ formatAmount(plan.amount, plan.currency),
8426
+ plan.period,
8427
+ String(plan.interval),
8428
+ plan.active ? "Yes" : "No",
8429
+ formatDate(plan.syncedAt)
8430
+ ])
8431
+ );
8432
+ }
8433
+ function registerPaymentsPlansCommand(paymentsCmd2) {
8434
+ const plansCmd = paymentsCmd2.command("plans").description("Manage Razorpay plans");
8435
+ plansCmd.command("list").description("List mirrored Razorpay plans").requiredOption(
8436
+ "--environment <environment>",
8437
+ "Razorpay environment: test or live"
8438
+ ).action(async (opts, cmd) => {
8439
+ const { json } = getRootOpts(cmd);
8440
+ try {
8441
+ const environment = parseEnvironment(opts.environment);
8442
+ await requireAuth();
8443
+ const data = await listRazorpayCatalog(environment);
8444
+ if (json) {
8445
+ outputJson({ plans: data.plans });
8446
+ } else {
8447
+ outputPlansTable(data.plans);
8448
+ }
8449
+ await trackPaymentUsage("plans.list", true, {
8450
+ provider: "razorpay",
8451
+ environment
7899
8452
  });
8453
+ } catch (err) {
8454
+ await trackPaymentUsage(
8455
+ "plans.list",
8456
+ false,
8457
+ {
8458
+ provider: "razorpay",
8459
+ environment: opts.environment
8460
+ },
8461
+ err
8462
+ );
7900
8463
  handleError(err, json);
7901
8464
  }
7902
8465
  });
7903
- }
7904
-
7905
- // src/commands/payments/history.ts
7906
- function registerPaymentsHistoryCommand(paymentsCmd2) {
7907
- paymentsCmd2.command("history").description("List mirrored Stripe payment history").requiredOption(
8466
+ plansCmd.command("create").description("Create a Razorpay subscription plan").requiredOption(
7908
8467
  "--environment <environment>",
7909
- "Stripe environment: test or live"
7910
- ).option("--subject-type <type>", "Filter by billing subject type").option("--subject-id <id>", "Filter by billing subject id").option("--limit <limit>", "Maximum rows to return (1-100)", "50").action(async (opts, cmd) => {
8468
+ "Razorpay environment: test or live"
8469
+ ).requiredOption(
8470
+ "--period <period>",
8471
+ "Plan period: daily, weekly, monthly, or yearly"
8472
+ ).requiredOption("--interval <count>", "Billing interval count").requiredOption("--item-name <name>", "Plan item name").requiredOption(
8473
+ "--item-amount <amount>",
8474
+ "Plan item amount in the smallest currency unit"
8475
+ ).requiredOption(
8476
+ "--item-currency <currency>",
8477
+ "Three-letter currency code, e.g. inr"
8478
+ ).option(
8479
+ "--item-description <description>",
8480
+ 'Plan item description, or "null"'
8481
+ ).option("--metadata <json>", "Metadata JSON object with string values").action(async (opts, cmd) => {
7911
8482
  const { json } = getRootOpts(cmd);
7912
8483
  try {
7913
8484
  const environment = parseEnvironment(opts.environment);
7914
- const limit = parseIntegerOption(opts.limit, "--limit", { min: 1, max: 100 }) ?? 50;
7915
- await requireAuth();
7916
- const data = await listPaymentHistory(environment, {
7917
- limit,
7918
- ...opts.subjectType !== void 0 ? { subjectType: opts.subjectType } : {},
7919
- ...opts.subjectId !== void 0 ? { subjectId: opts.subjectId } : {}
8485
+ const period = parseRazorpayPlanPeriod(opts.period);
8486
+ const interval = parseIntegerOption(opts.interval, "--interval", {
8487
+ min: 1
7920
8488
  });
8489
+ const itemAmount = parseIntegerOption(
8490
+ opts.itemAmount,
8491
+ "--item-amount",
8492
+ { min: 0 }
8493
+ );
8494
+ if (!period || interval === void 0 || itemAmount === void 0) {
8495
+ throw new CLIError(
8496
+ "Provide --period, --interval, and --item-amount."
8497
+ );
8498
+ }
8499
+ await requireAuth();
8500
+ const request = {
8501
+ period,
8502
+ interval,
8503
+ item: {
8504
+ name: opts.itemName,
8505
+ amount: itemAmount,
8506
+ currency: opts.itemCurrency
8507
+ }
8508
+ };
8509
+ const itemDescription = nullableString2(opts.itemDescription);
8510
+ const metadata = parseMetadataOption(opts.metadata);
8511
+ if (itemDescription !== void 0) {
8512
+ request.item.description = itemDescription;
8513
+ }
8514
+ if (metadata !== void 0) request.metadata = metadata;
8515
+ const data = await createRazorpayPlan(environment, request);
7921
8516
  if (json) {
7922
8517
  outputJson(data);
7923
- } else if (data.paymentHistory.length === 0) {
7924
- console.log("No Stripe payment history found.");
7925
8518
  } else {
7926
- outputTable(
7927
- [
7928
- "Type",
7929
- "Status",
7930
- "Subject",
7931
- "Amount",
7932
- "Customer",
7933
- "Stripe Object",
7934
- "When"
7935
- ],
7936
- data.paymentHistory.map((entry) => [
7937
- entry.type,
7938
- entry.status,
7939
- entry.subjectType && entry.subjectId ? `${entry.subjectType}:${entry.subjectId}` : "-",
7940
- formatAmount(entry.amount, entry.currency),
7941
- entry.stripeCustomerId ?? "-",
7942
- entry.stripeCheckoutSessionId ?? entry.stripeInvoiceId ?? entry.stripePaymentIntentId ?? entry.stripeRefundId ?? "-",
7943
- formatDate(
7944
- entry.paidAt ?? entry.failedAt ?? entry.refundedAt ?? entry.stripeCreatedAt
7945
- )
7946
- ])
7947
- );
8519
+ outputSuccess(`Razorpay plan created: ${data.plan.planId}`);
7948
8520
  }
7949
- await trackPaymentUsage("history", true, { environment });
7950
- } catch (err) {
7951
- await trackPaymentUsage("history", false, {
7952
- environment: opts.environment
8521
+ await trackPaymentUsage("plans.create", true, {
8522
+ provider: "razorpay",
8523
+ environment
7953
8524
  });
8525
+ } catch (err) {
8526
+ await trackPaymentUsage(
8527
+ "plans.create",
8528
+ false,
8529
+ {
8530
+ provider: "razorpay",
8531
+ environment: opts.environment
8532
+ },
8533
+ err
8534
+ );
7954
8535
  handleError(err, json);
7955
8536
  }
7956
8537
  });
7957
8538
  }
7958
8539
 
7959
8540
  // src/commands/payments/prices.ts
7960
- function nullableString(value) {
8541
+ function nullableString3(value) {
7961
8542
  if (value === void 0) return void 0;
7962
8543
  return value === "null" ? null : value;
7963
8544
  }
@@ -7999,8 +8580,8 @@ function outputPricesTable(prices) {
7999
8580
  ],
8000
8581
  prices.map((price) => [
8001
8582
  price.environment,
8002
- price.stripePriceId,
8003
- price.stripeProductId ?? "-",
8583
+ price.priceId,
8584
+ price.productId ?? "-",
8004
8585
  formatAmount(price.unitAmount, price.currency),
8005
8586
  price.type,
8006
8587
  price.active ? "Yes" : "No",
@@ -8019,17 +8600,26 @@ function registerPaymentsPricesCommand(paymentsCmd2) {
8019
8600
  try {
8020
8601
  const environment = parseEnvironment(opts.environment);
8021
8602
  await requireAuth();
8022
- const data = await listPaymentPrices(environment, opts.product);
8603
+ const data = await listStripePrices(environment, opts.product);
8023
8604
  if (json) {
8024
8605
  outputJson(data);
8025
8606
  } else {
8026
8607
  outputPricesTable(data.prices);
8027
8608
  }
8028
- await trackPaymentUsage("prices.list", true, { environment });
8029
- } catch (err) {
8030
- await trackPaymentUsage("prices.list", false, {
8031
- environment: opts.environment
8609
+ await trackPaymentUsage("prices.list", true, {
8610
+ provider: "stripe",
8611
+ environment
8032
8612
  });
8613
+ } catch (err) {
8614
+ await trackPaymentUsage(
8615
+ "prices.list",
8616
+ false,
8617
+ {
8618
+ provider: "stripe",
8619
+ environment: opts.environment
8620
+ },
8621
+ err
8622
+ );
8033
8623
  handleError(err, json);
8034
8624
  }
8035
8625
  });
@@ -8041,17 +8631,26 @@ function registerPaymentsPricesCommand(paymentsCmd2) {
8041
8631
  try {
8042
8632
  const environment = parseEnvironment(opts.environment);
8043
8633
  await requireAuth();
8044
- const data = await getPaymentPrice(environment, priceId);
8634
+ const data = await getStripePrice(environment, priceId);
8045
8635
  if (json) {
8046
8636
  outputJson(data);
8047
8637
  } else {
8048
8638
  outputPricesTable([data.price]);
8049
8639
  }
8050
- await trackPaymentUsage("prices.get", true, { environment });
8051
- } catch (err) {
8052
- await trackPaymentUsage("prices.get", false, {
8053
- environment: opts.environment
8640
+ await trackPaymentUsage("prices.get", true, {
8641
+ provider: "stripe",
8642
+ environment
8054
8643
  });
8644
+ } catch (err) {
8645
+ await trackPaymentUsage(
8646
+ "prices.get",
8647
+ false,
8648
+ {
8649
+ provider: "stripe",
8650
+ environment: opts.environment
8651
+ },
8652
+ err
8653
+ );
8055
8654
  handleError(err, json);
8056
8655
  }
8057
8656
  });
@@ -8082,11 +8681,11 @@ function registerPaymentsPricesCommand(paymentsCmd2) {
8082
8681
  throw new CLIError("Provide --interval when using --interval-count.");
8083
8682
  }
8084
8683
  const request = {
8085
- stripeProductId: opts.product,
8684
+ productId: opts.product,
8086
8685
  currency: opts.currency,
8087
8686
  unitAmount: parseIntegerOption(opts.unitAmount, "--unit-amount", { min: 0 }) ?? 0
8088
8687
  };
8089
- const lookupKey = nullableString(opts.lookupKey);
8688
+ const lookupKey = nullableString3(opts.lookupKey);
8090
8689
  const active = parseBooleanOption(opts.active, "--active");
8091
8690
  const taxBehavior = parseTaxBehavior(opts.taxBehavior);
8092
8691
  const metadata = parseMetadataOption(opts.metadata);
@@ -8103,17 +8702,26 @@ function registerPaymentsPricesCommand(paymentsCmd2) {
8103
8702
  ...intervalCount !== void 0 ? { intervalCount } : {}
8104
8703
  };
8105
8704
  }
8106
- const data = await createPaymentPrice(environment, request);
8705
+ const data = await createStripePrice(environment, request);
8107
8706
  if (json) {
8108
8707
  outputJson(data);
8109
8708
  } else {
8110
- outputSuccess(`Stripe price created: ${data.price.stripePriceId}`);
8709
+ outputSuccess(`Stripe price created: ${data.price.priceId}`);
8111
8710
  }
8112
- await trackPaymentUsage("prices.create", true, { environment });
8113
- } catch (err) {
8114
- await trackPaymentUsage("prices.create", false, {
8115
- environment: opts.environment
8711
+ await trackPaymentUsage("prices.create", true, {
8712
+ provider: "stripe",
8713
+ environment
8116
8714
  });
8715
+ } catch (err) {
8716
+ await trackPaymentUsage(
8717
+ "prices.create",
8718
+ false,
8719
+ {
8720
+ provider: "stripe",
8721
+ environment: opts.environment
8722
+ },
8723
+ err
8724
+ );
8117
8725
  handleError(err, json);
8118
8726
  }
8119
8727
  });
@@ -8127,7 +8735,7 @@ function registerPaymentsPricesCommand(paymentsCmd2) {
8127
8735
  await requireAuth();
8128
8736
  const request = {};
8129
8737
  const active = parseBooleanOption(opts.active, "--active");
8130
- const lookupKey = nullableString(opts.lookupKey);
8738
+ const lookupKey = nullableString3(opts.lookupKey);
8131
8739
  const taxBehavior = parseTaxBehavior(opts.taxBehavior);
8132
8740
  const metadata = parseMetadataOption(opts.metadata);
8133
8741
  if (active !== void 0) request.active = active;
@@ -8139,21 +8747,30 @@ function registerPaymentsPricesCommand(paymentsCmd2) {
8139
8747
  "Provide at least one option to update (--active, --lookup-key, --tax-behavior, --metadata)."
8140
8748
  );
8141
8749
  }
8142
- const data = await updatePaymentPrice(environment, priceId, request);
8750
+ const data = await updateStripePrice(environment, priceId, request);
8143
8751
  if (json) {
8144
8752
  outputJson(data);
8145
8753
  } else {
8146
- outputSuccess(`Stripe price updated: ${data.price.stripePriceId}`);
8754
+ outputSuccess(`Stripe price updated: ${data.price.priceId}`);
8147
8755
  }
8148
- await trackPaymentUsage("prices.update", true, { environment });
8149
- } catch (err) {
8150
- await trackPaymentUsage("prices.update", false, {
8151
- environment: opts.environment
8756
+ await trackPaymentUsage("prices.update", true, {
8757
+ provider: "stripe",
8758
+ environment
8152
8759
  });
8760
+ } catch (err) {
8761
+ await trackPaymentUsage(
8762
+ "prices.update",
8763
+ false,
8764
+ {
8765
+ provider: "stripe",
8766
+ environment: opts.environment
8767
+ },
8768
+ err
8769
+ );
8153
8770
  handleError(err, json);
8154
8771
  }
8155
8772
  });
8156
- pricesCmd.command("archive <priceId>").alias("delete").description("Archive a Stripe price").requiredOption(
8773
+ pricesCmd.command("archive <priceId>").description("Archive a Stripe price").requiredOption(
8157
8774
  "--environment <environment>",
8158
8775
  "Stripe environment: test or live"
8159
8776
  ).action(async (priceId, opts, cmd) => {
@@ -8161,24 +8778,33 @@ function registerPaymentsPricesCommand(paymentsCmd2) {
8161
8778
  try {
8162
8779
  const environment = parseEnvironment(opts.environment);
8163
8780
  await requireAuth();
8164
- const data = await archivePaymentPrice(environment, priceId);
8781
+ const data = await archiveStripePrice(environment, priceId);
8165
8782
  if (json) {
8166
8783
  outputJson(data);
8167
8784
  } else {
8168
- outputSuccess(`Stripe price archived: ${data.price.stripePriceId}`);
8785
+ outputSuccess(`Stripe price archived: ${data.price.priceId}`);
8169
8786
  }
8170
- await trackPaymentUsage("prices.archive", true, { environment });
8171
- } catch (err) {
8172
- await trackPaymentUsage("prices.archive", false, {
8173
- environment: opts.environment
8787
+ await trackPaymentUsage("prices.archive", true, {
8788
+ provider: "stripe",
8789
+ environment
8174
8790
  });
8791
+ } catch (err) {
8792
+ await trackPaymentUsage(
8793
+ "prices.archive",
8794
+ false,
8795
+ {
8796
+ provider: "stripe",
8797
+ environment: opts.environment
8798
+ },
8799
+ err
8800
+ );
8175
8801
  handleError(err, json);
8176
8802
  }
8177
8803
  });
8178
8804
  }
8179
8805
 
8180
8806
  // src/commands/payments/products.ts
8181
- function nullableString2(value) {
8807
+ function nullableString4(value) {
8182
8808
  if (value === void 0) return void 0;
8183
8809
  return value === "null" ? null : value;
8184
8810
  }
@@ -8191,7 +8817,7 @@ function outputProductsTable(products) {
8191
8817
  ["Env", "Product ID", "Name", "Active", "Default Price", "Synced At"],
8192
8818
  products.map((product) => [
8193
8819
  product.environment,
8194
- product.stripeProductId,
8820
+ product.productId,
8195
8821
  product.name,
8196
8822
  product.active ? "Yes" : "No",
8197
8823
  product.defaultPriceId ?? "-",
@@ -8209,17 +8835,26 @@ function registerPaymentsProductsCommand(paymentsCmd2) {
8209
8835
  try {
8210
8836
  const environment = parseEnvironment(opts.environment);
8211
8837
  await requireAuth();
8212
- const data = await listPaymentProducts(environment);
8838
+ const data = await listStripeProducts(environment);
8213
8839
  if (json) {
8214
8840
  outputJson(data);
8215
8841
  } else {
8216
8842
  outputProductsTable(data.products);
8217
8843
  }
8218
- await trackPaymentUsage("products.list", true, { environment });
8219
- } catch (err) {
8220
- await trackPaymentUsage("products.list", false, {
8221
- environment: opts.environment
8844
+ await trackPaymentUsage("products.list", true, {
8845
+ provider: "stripe",
8846
+ environment
8222
8847
  });
8848
+ } catch (err) {
8849
+ await trackPaymentUsage(
8850
+ "products.list",
8851
+ false,
8852
+ {
8853
+ provider: "stripe",
8854
+ environment: opts.environment
8855
+ },
8856
+ err
8857
+ );
8223
8858
  handleError(err, json);
8224
8859
  }
8225
8860
  });
@@ -8231,7 +8866,7 @@ function registerPaymentsProductsCommand(paymentsCmd2) {
8231
8866
  try {
8232
8867
  const environment = parseEnvironment(opts.environment);
8233
8868
  await requireAuth();
8234
- const data = await getPaymentProduct(environment, productId);
8869
+ const data = await getStripeProduct(environment, productId);
8235
8870
  if (json) {
8236
8871
  outputJson(data);
8237
8872
  } else {
@@ -8241,7 +8876,7 @@ function registerPaymentsProductsCommand(paymentsCmd2) {
8241
8876
  outputTable(
8242
8877
  ["Price ID", "Amount", "Type", "Active", "Lookup Key"],
8243
8878
  data.prices.map((price) => [
8244
- price.stripePriceId,
8879
+ price.priceId,
8245
8880
  formatAmount(price.unitAmount, price.currency),
8246
8881
  price.type,
8247
8882
  price.active ? "Yes" : "No",
@@ -8250,11 +8885,20 @@ function registerPaymentsProductsCommand(paymentsCmd2) {
8250
8885
  );
8251
8886
  }
8252
8887
  }
8253
- await trackPaymentUsage("products.get", true, { environment });
8254
- } catch (err) {
8255
- await trackPaymentUsage("products.get", false, {
8256
- environment: opts.environment
8888
+ await trackPaymentUsage("products.get", true, {
8889
+ provider: "stripe",
8890
+ environment
8257
8891
  });
8892
+ } catch (err) {
8893
+ await trackPaymentUsage(
8894
+ "products.get",
8895
+ false,
8896
+ {
8897
+ provider: "stripe",
8898
+ environment: opts.environment
8899
+ },
8900
+ err
8901
+ );
8258
8902
  handleError(err, json);
8259
8903
  }
8260
8904
  });
@@ -8267,7 +8911,7 @@ function registerPaymentsProductsCommand(paymentsCmd2) {
8267
8911
  const environment = parseEnvironment(opts.environment);
8268
8912
  await requireAuth();
8269
8913
  const request = { name: opts.name };
8270
- const description = nullableString2(opts.description);
8914
+ const description = nullableString4(opts.description);
8271
8915
  const active = parseBooleanOption(opts.active, "--active");
8272
8916
  const metadata = parseMetadataOption(opts.metadata);
8273
8917
  if (description !== void 0) request.description = description;
@@ -8276,19 +8920,26 @@ function registerPaymentsProductsCommand(paymentsCmd2) {
8276
8920
  if (opts.idempotencyKey !== void 0) {
8277
8921
  request.idempotencyKey = opts.idempotencyKey;
8278
8922
  }
8279
- const data = await createPaymentProduct(environment, request);
8923
+ const data = await createStripeProduct(environment, request);
8280
8924
  if (json) {
8281
8925
  outputJson(data);
8282
8926
  } else {
8283
- outputSuccess(
8284
- `Stripe product created: ${data.product.stripeProductId}`
8285
- );
8927
+ outputSuccess(`Stripe product created: ${data.product.productId}`);
8286
8928
  }
8287
- await trackPaymentUsage("products.create", true, { environment });
8288
- } catch (err) {
8289
- await trackPaymentUsage("products.create", false, {
8290
- environment: opts.environment
8929
+ await trackPaymentUsage("products.create", true, {
8930
+ provider: "stripe",
8931
+ environment
8291
8932
  });
8933
+ } catch (err) {
8934
+ await trackPaymentUsage(
8935
+ "products.create",
8936
+ false,
8937
+ {
8938
+ provider: "stripe",
8939
+ environment: opts.environment
8940
+ },
8941
+ err
8942
+ );
8292
8943
  handleError(err, json);
8293
8944
  }
8294
8945
  });
@@ -8301,7 +8952,7 @@ function registerPaymentsProductsCommand(paymentsCmd2) {
8301
8952
  const environment = parseEnvironment(opts.environment);
8302
8953
  await requireAuth();
8303
8954
  const request = {};
8304
- const description = nullableString2(opts.description);
8955
+ const description = nullableString4(opts.description);
8305
8956
  const active = parseBooleanOption(opts.active, "--active");
8306
8957
  const metadata = parseMetadataOption(opts.metadata);
8307
8958
  if (opts.name !== void 0) request.name = opts.name;
@@ -8313,23 +8964,26 @@ function registerPaymentsProductsCommand(paymentsCmd2) {
8313
8964
  "Provide at least one option to update (--name, --description, --active, --metadata)."
8314
8965
  );
8315
8966
  }
8316
- const data = await updatePaymentProduct(
8317
- environment,
8318
- productId,
8319
- request
8320
- );
8967
+ const data = await updateStripeProduct(environment, productId, request);
8321
8968
  if (json) {
8322
8969
  outputJson(data);
8323
8970
  } else {
8324
- outputSuccess(
8325
- `Stripe product updated: ${data.product.stripeProductId}`
8326
- );
8971
+ outputSuccess(`Stripe product updated: ${data.product.productId}`);
8327
8972
  }
8328
- await trackPaymentUsage("products.update", true, { environment });
8329
- } catch (err) {
8330
- await trackPaymentUsage("products.update", false, {
8331
- environment: opts.environment
8973
+ await trackPaymentUsage("products.update", true, {
8974
+ provider: "stripe",
8975
+ environment
8332
8976
  });
8977
+ } catch (err) {
8978
+ await trackPaymentUsage(
8979
+ "products.update",
8980
+ false,
8981
+ {
8982
+ provider: "stripe",
8983
+ environment: opts.environment
8984
+ },
8985
+ err
8986
+ );
8333
8987
  handleError(err, json);
8334
8988
  }
8335
8989
  });
@@ -8352,153 +9006,357 @@ function registerPaymentsProductsCommand(paymentsCmd2) {
8352
9006
  });
8353
9007
  if (isCancel2(confirm8) || !confirm8) process.exit(0);
8354
9008
  }
8355
- const data = await deletePaymentProduct(environment, productId);
9009
+ const data = await deleteStripeProduct(environment, productId);
8356
9010
  if (json) {
8357
9011
  outputJson(data);
8358
9012
  } else {
8359
- outputSuccess(`Stripe product deleted: ${data.stripeProductId}`);
9013
+ outputSuccess(`Stripe product deleted: ${data.productId}`);
8360
9014
  }
8361
- await trackPaymentUsage("products.delete", true, { environment });
8362
- } catch (err) {
8363
- await trackPaymentUsage("products.delete", false, {
8364
- environment: opts.environment
9015
+ await trackPaymentUsage("products.delete", true, {
9016
+ provider: "stripe",
9017
+ environment
8365
9018
  });
9019
+ } catch (err) {
9020
+ await trackPaymentUsage(
9021
+ "products.delete",
9022
+ false,
9023
+ {
9024
+ provider: "stripe",
9025
+ environment: opts.environment
9026
+ },
9027
+ err
9028
+ );
8366
9029
  handleError(err, json);
8367
9030
  }
8368
9031
  });
8369
9032
  }
8370
9033
 
8371
9034
  // src/commands/payments/status.ts
8372
- function registerPaymentsStatusCommand(paymentsCmd2) {
8373
- paymentsCmd2.command("status").description("Show Stripe payment connection, sync, and webhook status").action(async (_opts, cmd) => {
9035
+ function registerPaymentsStatusCommand(paymentsCmd2, provider) {
9036
+ paymentsCmd2.command("status").description("Show payment connection, sync, and webhook status").action(async (opts, cmd) => {
8374
9037
  const { json } = getRootOpts(cmd);
8375
9038
  try {
8376
9039
  await requireAuth();
8377
- const data = await getPaymentsStatus();
8378
- if (json) {
8379
- outputJson(data);
8380
- } else if (data.connections.length === 0) {
8381
- console.log("No Stripe payment environments found.");
9040
+ if (provider === "stripe") {
9041
+ const data = await getStripePaymentsStatus();
9042
+ if (json) {
9043
+ outputJson(data);
9044
+ } else if (data.connections.length === 0) {
9045
+ console.log("No Stripe payment environments found.");
9046
+ } else {
9047
+ outputTable(
9048
+ [
9049
+ "Env",
9050
+ "Status",
9051
+ "Key",
9052
+ "Account",
9053
+ "Webhook",
9054
+ "Last Sync",
9055
+ "Synced At"
9056
+ ],
9057
+ data.connections.map((connection) => [
9058
+ connection.environment,
9059
+ connection.status,
9060
+ connection.maskedKey ?? "-",
9061
+ connection.accountId ?? "-",
9062
+ connection.webhookEndpointId ? "Configured" : "-",
9063
+ connection.lastSyncStatus ?? "-",
9064
+ formatDate(connection.lastSyncedAt)
9065
+ ])
9066
+ );
9067
+ }
8382
9068
  } else {
8383
- outputTable(
8384
- ["Env", "Status", "Key", "Account", "Webhook", "Last Sync", "Synced At"],
8385
- data.connections.map((connection) => [
8386
- connection.environment,
8387
- connection.status,
8388
- connection.maskedKey ?? "-",
8389
- connection.stripeAccountId ?? "-",
8390
- connection.webhookEndpointId ? "Configured" : "-",
8391
- connection.lastSyncStatus ?? "-",
8392
- formatDate(connection.lastSyncedAt)
8393
- ])
8394
- );
9069
+ const data = await getRazorpayPaymentsStatus();
9070
+ if (json) {
9071
+ outputJson(data);
9072
+ } else if (data.razorpayConnections.length === 0) {
9073
+ console.log("No Razorpay payment environments found.");
9074
+ } else {
9075
+ outputTable(
9076
+ [
9077
+ "Env",
9078
+ "Status",
9079
+ "Key",
9080
+ "Account",
9081
+ "Merchant",
9082
+ "Webhook",
9083
+ "Last Sync",
9084
+ "Synced At"
9085
+ ],
9086
+ data.razorpayConnections.map((connection) => [
9087
+ connection.environment,
9088
+ connection.status,
9089
+ connection.maskedKey ?? "-",
9090
+ connection.accountId ?? "-",
9091
+ connection.merchantName ?? "-",
9092
+ connection.webhookEndpointUrl ? "Manual" : "-",
9093
+ connection.lastSyncStatus ?? "-",
9094
+ formatDate(connection.lastSyncedAt)
9095
+ ])
9096
+ );
9097
+ }
8395
9098
  }
8396
- await trackPaymentUsage("status", true);
9099
+ await trackPaymentUsage("status", true, { provider });
8397
9100
  } catch (err) {
8398
- await trackPaymentUsage("status", false);
9101
+ await trackPaymentUsage("status", false, { provider }, err);
8399
9102
  handleError(err, json);
8400
9103
  }
8401
9104
  });
8402
9105
  }
8403
9106
 
8404
9107
  // src/commands/payments/subscriptions.ts
8405
- function registerPaymentsSubscriptionsCommand(paymentsCmd2) {
8406
- paymentsCmd2.command("subscriptions").description("List mirrored Stripe subscriptions").requiredOption(
9108
+ function formatSubject(subjectType, subjectId) {
9109
+ return subjectType && subjectId ? `${subjectType}:${subjectId}` : "-";
9110
+ }
9111
+ function registerPaymentsSubscriptionsCommand(paymentsCmd2, provider) {
9112
+ paymentsCmd2.command("subscriptions").description("List mirrored payment provider subscriptions").requiredOption(
8407
9113
  "--environment <environment>",
8408
- "Stripe environment: test or live"
8409
- ).option("--subject-type <type>", "Filter by billing subject type").option("--subject-id <id>", "Filter by billing subject id").option("--limit <limit>", "Maximum rows to return (1-100)", "50").action(async (opts, cmd) => {
9114
+ "Payment environment: test or live"
9115
+ ).option("--subject-type <type>", "Filter by app billing subject type").option(
9116
+ "--subject-id <id>",
9117
+ "Filter by app billing subject id, not provider id"
9118
+ ).option("--limit <limit>", "Maximum rows to return (1-100)", "50").action(async (opts, cmd) => {
8410
9119
  const { json } = getRootOpts(cmd);
8411
9120
  try {
8412
9121
  const environment = parseEnvironment(opts.environment);
8413
9122
  const limit = parseIntegerOption(opts.limit, "--limit", { min: 1, max: 100 }) ?? 50;
8414
- await requireAuth();
8415
- const data = await listSubscriptions(environment, {
9123
+ const request = {
8416
9124
  limit,
8417
9125
  ...opts.subjectType !== void 0 ? { subjectType: opts.subjectType } : {},
8418
9126
  ...opts.subjectId !== void 0 ? { subjectId: opts.subjectId } : {}
8419
- });
8420
- if (json) {
8421
- outputJson(data);
8422
- } else if (data.subscriptions.length === 0) {
8423
- console.log("No Stripe subscriptions found.");
9127
+ };
9128
+ await requireAuth();
9129
+ if (provider === "stripe") {
9130
+ const data = await listStripeSubscriptions(environment, request);
9131
+ if (json) {
9132
+ outputJson(data);
9133
+ } else if (data.subscriptions.length === 0) {
9134
+ console.log("No Stripe subscriptions found.");
9135
+ } else {
9136
+ outputTable(
9137
+ [
9138
+ "Subscription ID",
9139
+ "Customer",
9140
+ "Subject",
9141
+ "Status",
9142
+ "Items",
9143
+ "Period End"
9144
+ ],
9145
+ data.subscriptions.map((subscription) => [
9146
+ subscription.subscriptionId,
9147
+ subscription.customerId ?? "-",
9148
+ formatSubject(subscription.subjectType, subscription.subjectId),
9149
+ subscription.status,
9150
+ String(subscription.items?.length ?? 0),
9151
+ formatDate(subscription.currentPeriodEnd)
9152
+ ])
9153
+ );
9154
+ }
8424
9155
  } else {
8425
- outputTable(
8426
- [
8427
- "Subscription ID",
8428
- "Customer",
8429
- "Subject",
8430
- "Status",
8431
- "Items",
8432
- "Period End"
8433
- ],
8434
- data.subscriptions.map((subscription) => [
8435
- subscription.stripeSubscriptionId,
8436
- subscription.stripeCustomerId,
8437
- subscription.subjectType && subscription.subjectId ? `${subscription.subjectType}:${subscription.subjectId}` : "-",
8438
- subscription.status,
8439
- String(subscription.items?.length ?? 0),
8440
- formatDate(subscription.currentPeriodEnd)
8441
- ])
8442
- );
9156
+ const data = await listRazorpaySubscriptions(environment, request);
9157
+ if (json) {
9158
+ outputJson(data);
9159
+ } else if (data.subscriptions.length === 0) {
9160
+ console.log("No Razorpay subscriptions found.");
9161
+ } else {
9162
+ outputTable(
9163
+ [
9164
+ "Subscription ID",
9165
+ "Plan ID",
9166
+ "Customer",
9167
+ "Subject",
9168
+ "Status",
9169
+ "Paid",
9170
+ "Remaining",
9171
+ "Current End"
9172
+ ],
9173
+ data.subscriptions.map((subscription) => [
9174
+ subscription.subscriptionId,
9175
+ subscription.planId,
9176
+ subscription.customerId ?? "-",
9177
+ formatSubject(subscription.subjectType, subscription.subjectId),
9178
+ subscription.status,
9179
+ String(subscription.paidCount ?? "-"),
9180
+ String(subscription.remainingCount ?? "-"),
9181
+ formatDate(subscription.currentEnd)
9182
+ ])
9183
+ );
9184
+ }
8443
9185
  }
8444
- await trackPaymentUsage("subscriptions", true, { environment });
8445
- } catch (err) {
8446
- await trackPaymentUsage("subscriptions", false, {
8447
- environment: opts.environment
9186
+ await trackPaymentUsage("subscriptions", true, {
9187
+ provider,
9188
+ environment
8448
9189
  });
9190
+ } catch (err) {
9191
+ await trackPaymentUsage(
9192
+ "subscriptions",
9193
+ false,
9194
+ {
9195
+ provider,
9196
+ environment: opts.environment
9197
+ },
9198
+ err
9199
+ );
8449
9200
  handleError(err, json);
8450
9201
  }
8451
9202
  });
8452
9203
  }
8453
9204
 
8454
9205
  // src/commands/payments/sync.ts
8455
- function registerPaymentsSyncCommand(paymentsCmd2) {
8456
- paymentsCmd2.command("sync").description(
8457
- "Sync configured Stripe products, prices, customers, and subscriptions"
8458
- ).option(
9206
+ function registerPaymentsSyncCommand(paymentsCmd2, provider) {
9207
+ paymentsCmd2.command("sync").description("Sync configured payment provider data").option(
8459
9208
  "--environment <environment>",
8460
- "Stripe environment: test, live, or all",
9209
+ "Payment environment: test, live, or all",
8461
9210
  "all"
8462
9211
  ).action(async (opts, cmd) => {
8463
9212
  const { json } = getRootOpts(cmd);
8464
9213
  try {
8465
9214
  const environment = parseEnvironmentOrAll(opts.environment);
8466
9215
  await requireAuth();
8467
- const data = await syncPayments(environment);
9216
+ if (provider === "stripe") {
9217
+ const data = await syncStripePayments(environment);
9218
+ if (json) {
9219
+ outputJson(data);
9220
+ } else if (data.results.length === 0) {
9221
+ console.log("No configured Stripe environments to sync.");
9222
+ } else {
9223
+ outputTable(
9224
+ [
9225
+ "Env",
9226
+ "Status",
9227
+ "Products",
9228
+ "Prices",
9229
+ "Customers",
9230
+ "Subscriptions",
9231
+ "Unmapped",
9232
+ "Synced At"
9233
+ ],
9234
+ data.results.map((result) => [
9235
+ result.environment,
9236
+ result.connection.lastSyncStatus ?? result.connection.status,
9237
+ String(result.connection.lastSyncCounts.products ?? 0),
9238
+ String(result.connection.lastSyncCounts.prices ?? 0),
9239
+ String(result.connection.lastSyncCounts.customers ?? 0),
9240
+ String(result.subscriptions?.synced ?? 0),
9241
+ String(result.subscriptions?.unmapped ?? 0),
9242
+ formatDate(result.connection.lastSyncedAt)
9243
+ ])
9244
+ );
9245
+ outputSuccess("Stripe payments synced.");
9246
+ }
9247
+ } else {
9248
+ const data = await syncRazorpayPayments(environment);
9249
+ if (json) {
9250
+ outputJson(data);
9251
+ } else if (data.results.length === 0) {
9252
+ console.log("No configured Razorpay environments to sync.");
9253
+ } else {
9254
+ outputTable(
9255
+ [
9256
+ "Env",
9257
+ "Status",
9258
+ "Items",
9259
+ "Plans",
9260
+ "Customers",
9261
+ "Subscriptions",
9262
+ "Invoices",
9263
+ "Payments",
9264
+ "Synced At"
9265
+ ],
9266
+ data.results.map((result) => [
9267
+ result.environment,
9268
+ result.status,
9269
+ String(result.syncCounts.items),
9270
+ String(result.syncCounts.plans),
9271
+ String(result.syncCounts.customers),
9272
+ String(result.syncCounts.subscriptions),
9273
+ String(result.syncCounts.invoices),
9274
+ String(result.syncCounts.payments),
9275
+ formatDate(result.connection.lastSyncedAt)
9276
+ ])
9277
+ );
9278
+ outputSuccess("Razorpay payments synced.");
9279
+ }
9280
+ }
9281
+ await trackPaymentUsage("sync", true, { provider, environment });
9282
+ } catch (err) {
9283
+ await trackPaymentUsage(
9284
+ "sync",
9285
+ false,
9286
+ {
9287
+ provider,
9288
+ environment: opts.environment
9289
+ },
9290
+ err
9291
+ );
9292
+ handleError(err, json);
9293
+ }
9294
+ });
9295
+ }
9296
+
9297
+ // src/commands/payments/transactions.ts
9298
+ function registerPaymentsTransactionsCommand(paymentsCmd2, provider) {
9299
+ paymentsCmd2.command("transactions").description("List mirrored payment transactions").requiredOption(
9300
+ "--environment <environment>",
9301
+ "Payment environment: test or live"
9302
+ ).option("--subject-type <type>", "Filter by app billing subject type").option(
9303
+ "--subject-id <id>",
9304
+ "Filter by app billing subject id, not provider id"
9305
+ ).option("--limit <limit>", "Maximum rows to return (1-100)", "50").action(async (opts, cmd) => {
9306
+ const { json } = getRootOpts(cmd);
9307
+ try {
9308
+ const environment = parseEnvironment(opts.environment);
9309
+ const limit = parseIntegerOption(opts.limit, "--limit", { min: 1, max: 100 }) ?? 50;
9310
+ await requireAuth();
9311
+ const data = await listPaymentTransactions(provider, environment, {
9312
+ limit,
9313
+ ...opts.subjectType !== void 0 ? { subjectType: opts.subjectType } : {},
9314
+ ...opts.subjectId !== void 0 ? { subjectId: opts.subjectId } : {}
9315
+ });
8468
9316
  if (json) {
8469
9317
  outputJson(data);
8470
- } else if (data.results.length === 0) {
8471
- console.log("No configured Stripe environments to sync.");
9318
+ } else if (data.transactions.length === 0) {
9319
+ console.log(`No ${provider} transactions found.`);
8472
9320
  } else {
8473
9321
  outputTable(
8474
9322
  [
8475
- "Env",
9323
+ "Type",
8476
9324
  "Status",
8477
- "Products",
8478
- "Prices",
8479
- "Customers",
8480
- "Subscriptions",
8481
- "Unmapped",
8482
- "Synced At"
9325
+ "Subject",
9326
+ "Amount",
9327
+ "Refunded",
9328
+ "Customer",
9329
+ "Provider Object",
9330
+ "When"
8483
9331
  ],
8484
- data.results.map((result) => [
8485
- result.environment,
8486
- result.connection.lastSyncStatus ?? result.connection.status,
8487
- String(result.connection.lastSyncCounts.products ?? 0),
8488
- String(result.connection.lastSyncCounts.prices ?? 0),
8489
- String(result.connection.lastSyncCounts.customers ?? 0),
8490
- String(result.subscriptions?.synced ?? 0),
8491
- String(result.subscriptions?.unmapped ?? 0),
8492
- formatDate(result.connection.lastSyncedAt)
9332
+ data.transactions.map((entry) => [
9333
+ entry.type,
9334
+ entry.status,
9335
+ entry.subjectType && entry.subjectId ? `${entry.subjectType}:${entry.subjectId}` : "-",
9336
+ formatAmount(entry.amount, entry.currency),
9337
+ formatAmount(entry.amountRefunded, entry.currency),
9338
+ entry.providerCustomerId ?? entry.customerEmailSnapshot ?? "-",
9339
+ entry.providerReferenceType && entry.providerReferenceId ? `${entry.providerReferenceType}:${entry.providerReferenceId}` : entry.providerReferenceId ?? "-",
9340
+ formatDate(
9341
+ entry.paidAt ?? entry.failedAt ?? entry.refundedAt ?? entry.providerCreatedAt ?? entry.createdAt
9342
+ )
8493
9343
  ])
8494
9344
  );
8495
- outputSuccess("Stripe payments synced.");
8496
9345
  }
8497
- await trackPaymentUsage("sync", true, { environment });
8498
- } catch (err) {
8499
- await trackPaymentUsage("sync", false, {
8500
- environment: opts.environment
9346
+ await trackPaymentUsage("transactions", true, {
9347
+ provider,
9348
+ environment
8501
9349
  });
9350
+ } catch (err) {
9351
+ await trackPaymentUsage(
9352
+ "transactions",
9353
+ false,
9354
+ {
9355
+ provider,
9356
+ environment: opts.environment
9357
+ },
9358
+ err
9359
+ );
8502
9360
  handleError(err, json);
8503
9361
  }
8504
9362
  });
@@ -8506,30 +9364,46 @@ function registerPaymentsSyncCommand(paymentsCmd2) {
8506
9364
 
8507
9365
  // src/commands/payments/webhooks.ts
8508
9366
  function registerPaymentsWebhooksCommand(paymentsCmd2) {
8509
- const webhooksCmd = paymentsCmd2.command("webhooks").description("Manage InsForge-managed Stripe webhooks");
8510
- webhooksCmd.command("configure <environment>").description("Create or recreate the managed Stripe webhook endpoint").action(async (environmentValue, _opts, cmd) => {
9367
+ const webhooksCmd = paymentsCmd2.command("webhooks").description("Manage Stripe webhooks");
9368
+ webhooksCmd.command("configure").description("Create or recreate the managed Stripe webhook endpoint").requiredOption(
9369
+ "--environment <environment>",
9370
+ "Stripe environment: test or live"
9371
+ ).action(async (opts, cmd) => {
8511
9372
  const { json } = getRootOpts(cmd);
8512
9373
  try {
8513
- const environment = parseEnvironment(environmentValue);
9374
+ const environment = parseEnvironment(opts.environment);
8514
9375
  await requireAuth();
8515
- const data = await configurePaymentWebhook(environment);
9376
+ const data = await configureStripeWebhook(environment);
8516
9377
  if (json) {
8517
9378
  outputJson(data);
8518
9379
  } else {
8519
9380
  outputTable(
8520
9381
  ["Env", "Webhook ID", "URL", "Configured At"],
8521
- [[
8522
- data.connection.environment,
8523
- data.connection.webhookEndpointId ?? "-",
8524
- data.connection.webhookEndpointUrl ?? "-",
8525
- formatDate(data.connection.webhookConfiguredAt)
8526
- ]]
9382
+ [
9383
+ [
9384
+ data.connection.environment,
9385
+ data.connection.webhookEndpointId ?? "-",
9386
+ data.connection.webhookEndpointUrl ?? "-",
9387
+ formatDate(data.connection.webhookConfiguredAt)
9388
+ ]
9389
+ ]
8527
9390
  );
8528
9391
  outputSuccess(`Stripe ${environment} webhook configured.`);
8529
9392
  }
8530
- await trackPaymentUsage("webhooks.configure", true, { environment });
9393
+ await trackPaymentUsage("webhooks.configure", true, {
9394
+ provider: "stripe",
9395
+ environment
9396
+ });
8531
9397
  } catch (err) {
8532
- await trackPaymentUsage("webhooks.configure", false, { environment: environmentValue });
9398
+ await trackPaymentUsage(
9399
+ "webhooks.configure",
9400
+ false,
9401
+ {
9402
+ provider: "stripe",
9403
+ environment: opts.environment
9404
+ },
9405
+ err
9406
+ );
8533
9407
  handleError(err, json);
8534
9408
  }
8535
9409
  });
@@ -8537,17 +9411,28 @@ function registerPaymentsWebhooksCommand(paymentsCmd2) {
8537
9411
 
8538
9412
  // src/commands/payments/index.ts
8539
9413
  function registerPaymentsCommands(paymentsCmd2) {
8540
- paymentsCmd2.description("Manage Stripe payments");
8541
- registerPaymentsStatusCommand(paymentsCmd2);
8542
- registerPaymentsConfigCommand(paymentsCmd2);
8543
- registerPaymentsSyncCommand(paymentsCmd2);
8544
- registerPaymentsWebhooksCommand(paymentsCmd2);
8545
- registerPaymentsCatalogCommand(paymentsCmd2);
8546
- registerPaymentsCustomersCommand(paymentsCmd2);
8547
- registerPaymentsProductsCommand(paymentsCmd2);
8548
- registerPaymentsPricesCommand(paymentsCmd2);
8549
- registerPaymentsSubscriptionsCommand(paymentsCmd2);
8550
- registerPaymentsHistoryCommand(paymentsCmd2);
9414
+ paymentsCmd2.description("Manage payments");
9415
+ const stripeCmd = paymentsCmd2.command("stripe").description("Manage Stripe payments");
9416
+ registerPaymentsStatusCommand(stripeCmd, "stripe");
9417
+ registerPaymentsConfigCommand(stripeCmd, "stripe");
9418
+ registerPaymentsSyncCommand(stripeCmd, "stripe");
9419
+ registerPaymentsWebhooksCommand(stripeCmd);
9420
+ registerPaymentsCatalogCommand(stripeCmd, "stripe");
9421
+ registerPaymentsCustomersCommand(stripeCmd, "stripe");
9422
+ registerPaymentsProductsCommand(stripeCmd);
9423
+ registerPaymentsPricesCommand(stripeCmd);
9424
+ registerPaymentsSubscriptionsCommand(stripeCmd, "stripe");
9425
+ registerPaymentsTransactionsCommand(stripeCmd, "stripe");
9426
+ const razorpayCmd = paymentsCmd2.command("razorpay").description("Manage Razorpay payments");
9427
+ registerPaymentsStatusCommand(razorpayCmd, "razorpay");
9428
+ registerPaymentsConfigCommand(razorpayCmd, "razorpay");
9429
+ registerPaymentsSyncCommand(razorpayCmd, "razorpay");
9430
+ registerPaymentsCatalogCommand(razorpayCmd, "razorpay");
9431
+ registerPaymentsCustomersCommand(razorpayCmd, "razorpay");
9432
+ registerPaymentsItemsCommand(razorpayCmd);
9433
+ registerPaymentsPlansCommand(razorpayCmd);
9434
+ registerPaymentsSubscriptionsCommand(razorpayCmd, "razorpay");
9435
+ registerPaymentsTransactionsCommand(razorpayCmd, "razorpay");
8551
9436
  }
8552
9437
 
8553
9438
  // src/commands/posthog/setup.ts