@solvapay/server 2.1.0 → 2.2.0-preview-57b934dfcf7afd484b63b497eef3bf1599c0b597

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/edge.d.ts CHANGED
@@ -17,7 +17,7 @@ interface components {
17
17
  message?: string;
18
18
  purchaseRef?: string;
19
19
  /** @enum {string} */
20
- status: 'activated' | 'already_active' | 'topup_required' | 'payment_required' | 'invalid';
20
+ status: 'activated' | 'already_active' | 'already_purchased' | 'topup_required' | 'payment_required' | 'invalid';
21
21
  };
22
22
  AttachBusinessDetailsResponse: {
23
23
  /** @description Calculated tax breakdown */
@@ -247,7 +247,7 @@ interface components {
247
247
  * Tax ID type
248
248
  * @enum {string}
249
249
  */
250
- taxIdType?: 'eu_vat' | 'gb_vat' | 'us_ein';
250
+ taxIdType?: 'ae_trn' | 'al_tin' | 'am_tin' | 'ao_tin' | 'au_abn' | 'aw_tin' | 'az_tin' | 'ba_tin' | 'bb_tin' | 'bd_bin' | 'bf_ifu' | 'bh_vat' | 'bj_ifu' | 'bs_tin' | 'by_tin' | 'ca_gst_hst' | 'cd_nif' | 'ch_vat' | 'cl_tin' | 'cm_niu' | 'co_nit' | 'cr_tin' | 'cv_nif' | 'ec_ruc' | 'eg_tin' | 'et_tin' | 'eu_vat' | 'gb_vat' | 'ge_vat' | 'gn_nif' | 'hk_br' | 'id_npwp' | 'in_gst' | 'is_vat' | 'jp_trn' | 'ke_pin' | 'kg_tin' | 'kh_tin' | 'kr_brn' | 'kz_bin' | 'la_tin' | 'li_vat' | 'lk_vat' | 'ma_vat' | 'md_vat' | 'me_pib' | 'mk_vat' | 'mr_nif' | 'mx_rfc' | 'my_sst' | 'ng_tin' | 'no_vat' | 'np_pan' | 'nz_gst' | 'om_vat' | 'pe_ruc' | 'ph_tin' | 'rs_pib' | 'ru_inn' | 'sa_vat' | 'sg_gst' | 'sn_ninea' | 'sr_fin' | 'th_vat' | 'tj_tin' | 'tr_tin' | 'tw_vat' | 'tz_vat' | 'ua_vat' | 'ug_tin' | 'us_ein' | 'uy_ruc' | 'uz_vat' | 'vn_tin' | 'za_vat' | 'zm_tin' | 'zw_tin';
251
251
  };
252
252
  CancelPurchaseRequest: {
253
253
  reason?: string;
@@ -645,7 +645,13 @@ interface components {
645
645
  /** @enum {number} */
646
646
  debited: true;
647
647
  /**
648
- * Estimated remaining units after debit
648
+ * How many metered items the remaining credit balance still covers
649
+ * @example 99
650
+ */
651
+ remainingUnits: number;
652
+ /**
653
+ * @deprecated
654
+ * @description Deprecated alias of remainingUnits. Prefer remainingUnits.
649
655
  * @example 99
650
656
  */
651
657
  unitsRemaining: number;
@@ -724,7 +730,7 @@ interface components {
724
730
  */
725
731
  name: string;
726
732
  /** @description Active purchases */
727
- purchases?: components['schemas']['PurchaseInfo'][];
733
+ purchases?: components['schemas']['SdkPurchaseResponse'][];
728
734
  /**
729
735
  * Customer reference identifier
730
736
  * @example cus_3c4d5e6f7g8h
@@ -793,25 +799,30 @@ interface components {
793
799
  LimitBalanceDto: {
794
800
  /** @description Credit balance in credits (100 credits = 1 minor currency unit) */
795
801
  creditBalance: number;
796
- /** @description Credits per usage unit */
802
+ /** @description Credits deducted per metered item (wallet coverage: remainingUnits = balance / creditsPerUnit) */
797
803
  creditsPerUnit: number;
798
804
  currency: string;
799
- /** @description Estimated whole units remaining from prepaid credit balance */
805
+ /** @description How many metered items the credit balance still covers (`balance / creditsPerUnit`) */
800
806
  remainingUnits?: number;
801
807
  };
802
808
  LimitPlanItemDto: {
803
809
  /** @description Derived billing cycle */
804
810
  billingCycle?: string;
805
- /** @description Per-unit charge in minor units (usage-based plans) */
811
+ /**
812
+ * @deprecated
813
+ * @description Deprecated alias of perUnitChargeMinor. Same minor-units value — not credits. Prefer perUnitChargeMinor.
814
+ */
806
815
  creditsPerUnit?: number;
807
816
  currency: string;
808
- /** @description Derived included units for the metered allowance */
817
+ /** @description Derived included allowance for the metered meter. `0` is the unlimited sentinel (`LimitOption.cap === 0`). */
809
818
  freeUnits?: number;
810
819
  name?: string;
811
820
  /** @description Composable pricing options for this plan */
812
821
  options?: {
813
822
  [key: string]: unknown;
814
823
  }[];
824
+ /** @description Per-request charge in minor currency units (usage-based plans) */
825
+ perUnitChargeMinor?: number;
815
826
  /** @description Headline price in smallest currency unit (e.g. cents) */
816
827
  price: number;
817
828
  reference: string;
@@ -842,7 +853,7 @@ interface components {
842
853
  confirmationUrl?: string;
843
854
  /** @description Credit balance in credits (100 credits = 1 minor currency unit), for pre-paid usage-based plans */
844
855
  creditBalance?: number;
845
- /** @description Credits per usage unit (for pre-paid usage-based plans) */
856
+ /** @description Credits deducted per metered item (for prepaid usage-based plans) */
846
857
  creditsPerUnit?: number;
847
858
  /** @description ISO 4217 currency code for credit fields */
848
859
  currency?: string;
@@ -1057,11 +1068,18 @@ interface components {
1057
1068
  * @example 2025-10-27T10:00:00Z
1058
1069
  */
1059
1070
  completedAt: string;
1071
+ /** @description Created at */
1072
+ createdAt: string;
1060
1073
  /**
1061
1074
  * ISO 4217 currency code of the customer-facing charge
1062
1075
  * @example USD
1063
1076
  */
1064
1077
  currency: string;
1078
+ /**
1079
+ * Customer reference
1080
+ * @example cus_3C4D5E6F
1081
+ */
1082
+ customerRef: string;
1065
1083
  /**
1066
1084
  * Product reference
1067
1085
  * @example prd_abc123
@@ -1189,7 +1207,7 @@ interface components {
1189
1207
  type: 'one-time';
1190
1208
  };
1191
1209
  ProcessPaymentSucceededRecurring: {
1192
- purchase: components['schemas']['PurchaseInfo'];
1210
+ purchase: components['schemas']['SdkPurchaseResponse'];
1193
1211
  /**
1194
1212
  * discriminator enum property added by openapi-typescript
1195
1213
  * @enum {string}
@@ -1227,75 +1245,6 @@ interface components {
1227
1245
  */
1228
1246
  validityPeriod?: number;
1229
1247
  };
1230
- PurchaseInfo: {
1231
- /**
1232
- * Amount in USD cents (normalised for aggregation)
1233
- * @example 9900
1234
- */
1235
- amount: number;
1236
- /**
1237
- * Reason for cancellation
1238
- * @example Customer request
1239
- */
1240
- cancellationReason?: string;
1241
- /**
1242
- * When purchase was cancelled
1243
- * @example 2025-10-28T10:00:00Z
1244
- */
1245
- cancelledAt?: string;
1246
- /**
1247
- * ISO 4217 currency code of the customer-facing charge
1248
- * @example GBP
1249
- */
1250
- currency: string;
1251
- /**
1252
- * End date of purchase
1253
- * @example 2025-11-27T10:00:00Z
1254
- */
1255
- endDate?: string;
1256
- /**
1257
- * Exchange rate from original currency to USD
1258
- * @example 1.32
1259
- */
1260
- exchangeRate?: number;
1261
- /**
1262
- * Original amount in the payment currency (minor units)
1263
- * @example 7500
1264
- */
1265
- originalAmount?: number;
1266
- /**
1267
- * Plan reference from the plan snapshot, for reliable plan matching
1268
- * @example pln_abc123
1269
- */
1270
- planRef?: string;
1271
- /** @description Snapshot of the plan at time of purchase */
1272
- planSnapshot?: Record<string, never>;
1273
- /**
1274
- * Product name
1275
- * @example API Gateway Manager
1276
- */
1277
- productName: string;
1278
- /**
1279
- * Product reference
1280
- * @example prd_abc123
1281
- */
1282
- productRef?: string;
1283
- /**
1284
- * Purchase reference
1285
- * @example pur_1A2B3C4D
1286
- */
1287
- reference: string;
1288
- /**
1289
- * Start date
1290
- * @example 2025-10-27T10:00:00Z
1291
- */
1292
- startDate: string;
1293
- /**
1294
- * Purchase status
1295
- * @example active
1296
- */
1297
- status: string;
1298
- };
1299
1248
  PutAutoRechargeSdkDto: {
1300
1249
  currency: string;
1301
1250
  /** Format: email */
@@ -1605,6 +1554,11 @@ interface components {
1605
1554
  features?: {
1606
1555
  [key: string]: unknown;
1607
1556
  } | null;
1557
+ /**
1558
+ * Whether the frozen plan meters usage
1559
+ * @example true
1560
+ */
1561
+ isMetered?: boolean;
1608
1562
  /**
1609
1563
  * Plan name captured at purchase time
1610
1564
  * @example Pro Monthly
@@ -1714,14 +1668,20 @@ interface components {
1714
1668
  * @enum {string}
1715
1669
  */
1716
1670
  billingCycle?: 'weekly' | 'monthly' | 'quarterly' | 'yearly';
1717
- /** @description Cancellation reason */
1671
+ /**
1672
+ * Reason for cancellation
1673
+ * @example Customer request
1674
+ */
1718
1675
  cancellationReason?: string;
1719
- /** @description Cancelled at */
1676
+ /**
1677
+ * When purchase was cancelled
1678
+ * @example 2025-10-28T10:00:00Z
1679
+ */
1720
1680
  cancelledAt?: string;
1721
1681
  /** @description Created at */
1722
1682
  createdAt: string;
1723
1683
  /**
1724
- * Original payment currency code
1684
+ * ISO 4217 currency code of the customer-facing charge
1725
1685
  * @example GBP
1726
1686
  */
1727
1687
  currency: string;
@@ -1735,15 +1695,18 @@ interface components {
1735
1695
  * @example cus_3C4D5E6F
1736
1696
  */
1737
1697
  customerRef: string;
1738
- /** @description End date */
1698
+ /**
1699
+ * End date of purchase
1700
+ * @example 2025-11-27T10:00:00Z
1701
+ */
1739
1702
  endDate?: string;
1740
1703
  /**
1741
1704
  * Exchange rate from original currency to USD
1742
- * @example 1.3082
1705
+ * @example 1.32
1743
1706
  */
1744
1707
  exchangeRate?: number;
1745
1708
  /**
1746
- * Is recurring
1709
+ * Whether the purchase is recurring
1747
1710
  * @example true
1748
1711
  */
1749
1712
  isRecurring: boolean;
@@ -1760,13 +1723,18 @@ interface components {
1760
1723
  */
1761
1724
  origin?: 'paid' | 'free_default' | 'manual' | 'one_time' | 'credit_topup' | 'admin_assignment';
1762
1725
  /**
1763
- * Original amount in the payment currency (cents/pence)
1764
- * @example 10000
1726
+ * Original amount in the payment currency (minor units)
1727
+ * @example 7500
1765
1728
  */
1766
1729
  originalAmount?: number;
1767
1730
  /** @description Paid at timestamp */
1768
1731
  paidAt?: string;
1769
- /** @description Plan snapshot at time of purchase (null for credit topups) */
1732
+ /**
1733
+ * Plan reference from the plan snapshot, for reliable plan matching
1734
+ * @example pln_abc123
1735
+ */
1736
+ planRef?: string;
1737
+ /** @description Snapshot of the plan at time of purchase */
1770
1738
  planSnapshot?: components['schemas']['SdkPlanSnapshotDto'];
1771
1739
  /**
1772
1740
  * Product name
@@ -1775,7 +1743,7 @@ interface components {
1775
1743
  productName?: string;
1776
1744
  /**
1777
1745
  * Product reference
1778
- * @example prd_1A2B3C4D
1746
+ * @example prd_abc123
1779
1747
  */
1780
1748
  productRef?: string;
1781
1749
  /**
@@ -1788,7 +1756,10 @@ interface components {
1788
1756
  * @example false
1789
1757
  */
1790
1758
  requiresPayment?: boolean;
1791
- /** @description Start date */
1759
+ /**
1760
+ * Start date
1761
+ * @example 2025-10-27T10:00:00Z
1762
+ */
1792
1763
  startDate: string;
1793
1764
  /**
1794
1765
  * Purchase status
@@ -1803,6 +1774,8 @@ interface components {
1803
1774
  currency: string;
1804
1775
  /** @description Whether tax is included in the listed price */
1805
1776
  inclusive: boolean;
1777
+ /** @description True when Stripe reports taxability_reason not_collecting (no registration) */
1778
+ notRegistered?: boolean;
1806
1779
  /** @description Pre-tax amount in minor units */
1807
1780
  subtotal: number;
1808
1781
  /** @description Tax amount in minor units */
@@ -1817,7 +1790,7 @@ interface components {
1817
1790
  /** @description Total amount in minor units */
1818
1791
  total: number;
1819
1792
  /** @enum {string} */
1820
- treatment: 'reverse_charge' | 'standard' | 'none' | 'not_collecting';
1793
+ treatment: 'reverse_charge' | 'standard' | 'none' | 'not_collecting' | 'not_supported';
1821
1794
  };
1822
1795
  UpdateCustomerRequest: {
1823
1796
  description?: string;
@@ -1971,7 +1944,7 @@ interface components {
1971
1944
  */
1972
1945
  overageCost: number;
1973
1946
  /**
1974
- * Units exceeding the plan limit
1947
+ * Units exceeding the plan included amount
1975
1948
  * @example 0
1976
1949
  */
1977
1950
  overageUnits: number;
@@ -3849,6 +3822,8 @@ type WebhookEvent = {
3849
3822
  * Types related to the SolvaPay API client and backend communication.
3850
3823
  */
3851
3824
 
3825
+ /** SDK purchase row. Generated from the OpenAPI `SdkPurchaseResponse` schema. */
3826
+ type PurchaseInfo = components['schemas']['SdkPurchaseResponse'];
3852
3827
  type AttachBusinessDetailsParams = {
3853
3828
  paymentIntentId: string;
3854
3829
  customerRef?: string;
@@ -3890,8 +3865,7 @@ type LimitResponseWithPlan = components['schemas']['LimitResponse'] & {
3890
3865
  /**
3891
3866
  * Extended CustomerResponse with proper field mapping
3892
3867
  *
3893
- * Note: The backend API returns purchases as PurchaseInfo objects.
3894
- * Additional fields (paidAt, nextBillingDate) may be present in the response.
3868
+ * Note: The backend API returns purchases as SdkPurchaseResponse objects.
3895
3869
  */
3896
3870
  type CustomerResponseMapped = {
3897
3871
  customerRef: string;
@@ -3899,21 +3873,20 @@ type CustomerResponseMapped = {
3899
3873
  name?: string;
3900
3874
  externalRef?: string;
3901
3875
  plan?: string;
3902
- purchases?: Array<components['schemas']['PurchaseInfo'] & {
3903
- paidAt?: string;
3904
- nextBillingDate?: string;
3905
- }>;
3876
+ purchases?: PurchaseInfo[];
3906
3877
  };
3907
3878
  /**
3908
3879
  * One-time purchase information returned from payment processing
3909
3880
  */
3910
3881
  interface OneTimePurchaseInfo {
3911
3882
  reference: string;
3883
+ customerRef: string;
3912
3884
  productRef?: string;
3913
3885
  amount: number;
3914
3886
  currency: string;
3915
3887
  creditsAdded?: number;
3916
3888
  completedAt: string;
3889
+ createdAt: string;
3917
3890
  }
3918
3891
  /**
3919
3892
  * Result from processing a payment intent.
@@ -3933,7 +3906,7 @@ interface OneTimePurchaseInfo {
3933
3906
  type ProcessPaymentResult = {
3934
3907
  status: 'succeeded';
3935
3908
  type: 'recurring';
3936
- purchase: components['schemas']['PurchaseInfo'];
3909
+ purchase: PurchaseInfo;
3937
3910
  } | {
3938
3911
  status: 'succeeded';
3939
3912
  type: 'one-time';
@@ -4241,10 +4214,10 @@ interface SolvaPayClient {
4241
4214
  cancelPurchase?(params: {
4242
4215
  purchaseRef: string;
4243
4216
  reason?: string;
4244
- }): Promise<components['schemas']['PurchaseInfo']>;
4217
+ }): Promise<PurchaseInfo>;
4245
4218
  reactivatePurchase?(params: {
4246
4219
  purchaseRef: string;
4247
- }): Promise<components['schemas']['PurchaseInfo']>;
4220
+ }): Promise<PurchaseInfo>;
4248
4221
  processPaymentIntent?(params: {
4249
4222
  paymentIntentId: string;
4250
4223
  productRef?: string;
@@ -6257,26 +6230,7 @@ interface PurchaseCheckResult {
6257
6230
  customerRef: string;
6258
6231
  email?: string;
6259
6232
  name?: string;
6260
- purchases: Array<{
6261
- reference: string;
6262
- productName?: string;
6263
- productRef?: string;
6264
- status?: string;
6265
- startDate?: string;
6266
- planSnapshot?: {
6267
- meterId?: string;
6268
- limit?: number;
6269
- freeUnits?: number;
6270
- };
6271
- usage?: {
6272
- used?: number;
6273
- overageUnits?: number;
6274
- overageCost?: number;
6275
- periodStart?: string;
6276
- periodEnd?: string;
6277
- };
6278
- [key: string]: unknown;
6279
- }>;
6233
+ purchases: PurchaseInfo[];
6280
6234
  }
6281
6235
  declare function checkPurchaseCore(request: Request, options?: {
6282
6236
  solvaPay?: SolvaPay;
@@ -6305,8 +6259,12 @@ interface GetUsageResult {
6305
6259
  /**
6306
6260
  * Fetch the authenticated customer's usage snapshot for the active purchase.
6307
6261
  *
6308
- * Derives the values from `checkPurchaseCore` — no extra backend call.
6309
- * Returns `null` values when no usage-based plan is active.
6262
+ * Consumption (`used`, period window) comes from `checkPurchaseCore`. The cap
6263
+ * (`total`, `remaining`, `meterRef`) comes from `checkLimits` — the plan
6264
+ * snapshot no longer carries `limit` or `meterRef` on the wire, so a metered
6265
+ * plan costs one extra backend call. Non-metered plans skip it.
6266
+ *
6267
+ * Returns `null` values when no metered plan is active.
6310
6268
  */
6311
6269
  declare function getUsageCore(request: Request, options?: {
6312
6270
  solvaPay?: SolvaPay;
package/dist/edge.js CHANGED
@@ -3286,21 +3286,40 @@ async function getUsageCore(request, options = {}) {
3286
3286
  percentUsed: null
3287
3287
  };
3288
3288
  }
3289
- const snap = activePurchase.planSnapshot;
3290
3289
  const usage = activePurchase.usage;
3291
- const meterRef = snap?.meterRef ?? snap?.meterId ?? null;
3292
- const total = typeof snap?.limit === "number" ? snap.limit : null;
3293
3290
  const used = typeof usage?.used === "number" ? usage.used : 0;
3294
- const remaining = total !== null ? Math.max(0, total - used) : null;
3291
+ const period = {
3292
+ ...usage?.periodStart ? { periodStart: usage.periodStart } : {},
3293
+ ...usage?.periodEnd ? { periodEnd: usage.periodEnd } : {}
3294
+ };
3295
+ const isMetered = activePurchase.planSnapshot?.isMetered === true;
3296
+ if (!isMetered || !activePurchase.productRef) {
3297
+ return {
3298
+ meterRef: null,
3299
+ total: null,
3300
+ used,
3301
+ remaining: null,
3302
+ percentUsed: null,
3303
+ ...period,
3304
+ purchaseRef: activePurchase.reference
3305
+ };
3306
+ }
3307
+ const solvaPay = options.solvaPay || createSolvaPay();
3308
+ const limits = await solvaPay.apiClient.checkLimits({
3309
+ customerRef: purchaseResult.customerRef,
3310
+ productRef: activePurchase.productRef
3311
+ });
3312
+ const hasFiniteCap = limits.remaining >= 0;
3313
+ const remaining = hasFiniteCap ? limits.remaining : null;
3314
+ const total = remaining === null ? null : used + remaining;
3295
3315
  const percentUsed = total !== null && total > 0 ? Math.min(100, Math.round(used / total * 1e4) / 100) : null;
3296
3316
  return {
3297
- meterRef,
3317
+ meterRef: limits.meterName ?? null,
3298
3318
  total,
3299
3319
  used,
3300
3320
  remaining,
3301
3321
  percentUsed,
3302
- ...usage?.periodStart ? { periodStart: usage.periodStart } : {},
3303
- ...usage?.periodEnd ? { periodEnd: usage.periodEnd } : {},
3322
+ ...period,
3304
3323
  purchaseRef: activePurchase.reference
3305
3324
  };
3306
3325
  }