@schematichq/schematic-react 1.8.0 → 1.9.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.
@@ -47,6 +47,7 @@ __export(index_exports, {
47
47
  useBillingDataSource: () => useBillingDataSource,
48
48
  useInvalidateBillingData: () => useInvalidateBillingData,
49
49
  useInvoices: () => useInvoices,
50
+ usePaymentMethods: () => usePaymentMethods,
50
51
  useSchematic: () => useSchematic,
51
52
  useSchematicContext: () => useSchematicContext,
52
53
  useSchematicCreditBalance: () => useSchematicCreditBalance,
@@ -59,11 +60,12 @@ __export(index_exports, {
59
60
  useSchematicPlan: () => useSchematicPlan,
60
61
  useSchematicStrings: () => useSchematicStrings,
61
62
  useSchematicTranslate: () => useSchematicTranslate,
63
+ useSetupIntent: () => useSetupIntent,
62
64
  useUpcomingInvoice: () => useUpcomingInvoice
63
65
  });
64
66
  module.exports = __toCommonJS(index_exports);
65
67
 
66
- // node_modules/.pnpm/@schematichq+schematic-js@1.8.0/node_modules/@schematichq/schematic-js/dist/schematic.esm.js
68
+ // node_modules/.pnpm/@schematichq+schematic-js@1.9.0/node_modules/@schematichq/schematic-js/dist/schematic.esm.js
67
69
  var __create2 = Object.create;
68
70
  var __defProp2 = Object.defineProperty;
69
71
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -1211,7 +1213,7 @@ function contextString(context) {
1211
1213
  }, {});
1212
1214
  return JSON.stringify(sortedContext);
1213
1215
  }
1214
- var version = "1.8.0";
1216
+ var version = "1.9.0";
1215
1217
  var SINGLETON = {};
1216
1218
  var models_exports = {};
1217
1219
  __export2(models_exports, {
@@ -1219,6 +1221,11 @@ __export2(models_exports, {
1219
1221
  ApiErrorFromJSONTyped: () => ApiErrorFromJSONTyped,
1220
1222
  ApiErrorToJSON: () => ApiErrorToJSON,
1221
1223
  ApiErrorToJSONTyped: () => ApiErrorToJSONTyped,
1224
+ BillingProviderType: () => BillingProviderType,
1225
+ BillingProviderTypeFromJSON: () => BillingProviderTypeFromJSON2,
1226
+ BillingProviderTypeFromJSONTyped: () => BillingProviderTypeFromJSONTyped11,
1227
+ BillingProviderTypeToJSON: () => BillingProviderTypeToJSON2,
1228
+ BillingProviderTypeToJSONTyped: () => BillingProviderTypeToJSONTyped11,
1222
1229
  CompanyDiscountResponseDataFromJSON: () => CompanyDiscountResponseDataFromJSON,
1223
1230
  CompanyDiscountResponseDataFromJSONTyped: () => CompanyDiscountResponseDataFromJSONTyped,
1224
1231
  CompanyDiscountResponseDataToJSON: () => CompanyDiscountResponseDataToJSON,
@@ -1231,10 +1238,30 @@ __export2(models_exports, {
1231
1238
  CompanyInvoicesResponseDataFromJSONTyped: () => CompanyInvoicesResponseDataFromJSONTyped,
1232
1239
  CompanyInvoicesResponseDataToJSON: () => CompanyInvoicesResponseDataToJSON,
1233
1240
  CompanyInvoicesResponseDataToJSONTyped: () => CompanyInvoicesResponseDataToJSONTyped,
1241
+ CompanyPaymentMethodResponseDataFromJSON: () => CompanyPaymentMethodResponseDataFromJSON,
1242
+ CompanyPaymentMethodResponseDataFromJSONTyped: () => CompanyPaymentMethodResponseDataFromJSONTyped,
1243
+ CompanyPaymentMethodResponseDataToJSON: () => CompanyPaymentMethodResponseDataToJSON,
1244
+ CompanyPaymentMethodResponseDataToJSONTyped: () => CompanyPaymentMethodResponseDataToJSONTyped,
1245
+ CompanyPaymentMethodsResponseDataFromJSON: () => CompanyPaymentMethodsResponseDataFromJSON,
1246
+ CompanyPaymentMethodsResponseDataFromJSONTyped: () => CompanyPaymentMethodsResponseDataFromJSONTyped,
1247
+ CompanyPaymentMethodsResponseDataToJSON: () => CompanyPaymentMethodsResponseDataToJSON,
1248
+ CompanyPaymentMethodsResponseDataToJSONTyped: () => CompanyPaymentMethodsResponseDataToJSONTyped,
1234
1249
  CompanyUpcomingInvoiceResponseDataFromJSON: () => CompanyUpcomingInvoiceResponseDataFromJSON,
1235
1250
  CompanyUpcomingInvoiceResponseDataFromJSONTyped: () => CompanyUpcomingInvoiceResponseDataFromJSONTyped,
1236
1251
  CompanyUpcomingInvoiceResponseDataToJSON: () => CompanyUpcomingInvoiceResponseDataToJSON,
1237
1252
  CompanyUpcomingInvoiceResponseDataToJSONTyped: () => CompanyUpcomingInvoiceResponseDataToJSONTyped,
1253
+ CreateSetupIntentResponseFromJSON: () => CreateSetupIntentResponseFromJSON,
1254
+ CreateSetupIntentResponseFromJSONTyped: () => CreateSetupIntentResponseFromJSONTyped,
1255
+ CreateSetupIntentResponseToJSON: () => CreateSetupIntentResponseToJSON,
1256
+ CreateSetupIntentResponseToJSONTyped: () => CreateSetupIntentResponseToJSONTyped,
1257
+ DeletePaymentMethodResponseFromJSON: () => DeletePaymentMethodResponseFromJSON,
1258
+ DeletePaymentMethodResponseFromJSONTyped: () => DeletePaymentMethodResponseFromJSONTyped,
1259
+ DeletePaymentMethodResponseToJSON: () => DeletePaymentMethodResponseToJSON,
1260
+ DeletePaymentMethodResponseToJSONTyped: () => DeletePaymentMethodResponseToJSONTyped,
1261
+ DeleteResponseFromJSON: () => DeleteResponseFromJSON,
1262
+ DeleteResponseFromJSONTyped: () => DeleteResponseFromJSONTyped,
1263
+ DeleteResponseToJSON: () => DeleteResponseToJSON,
1264
+ DeleteResponseToJSONTyped: () => DeleteResponseToJSONTyped,
1238
1265
  GetCompanyInvoicesParamsFromJSON: () => GetCompanyInvoicesParamsFromJSON,
1239
1266
  GetCompanyInvoicesParamsFromJSONTyped: () => GetCompanyInvoicesParamsFromJSONTyped,
1240
1267
  GetCompanyInvoicesParamsToJSON: () => GetCompanyInvoicesParamsToJSON,
@@ -1243,6 +1270,10 @@ __export2(models_exports, {
1243
1270
  GetCompanyInvoicesResponseFromJSONTyped: () => GetCompanyInvoicesResponseFromJSONTyped,
1244
1271
  GetCompanyInvoicesResponseToJSON: () => GetCompanyInvoicesResponseToJSON,
1245
1272
  GetCompanyInvoicesResponseToJSONTyped: () => GetCompanyInvoicesResponseToJSONTyped,
1273
+ GetCompanyPaymentMethodsResponseFromJSON: () => GetCompanyPaymentMethodsResponseFromJSON,
1274
+ GetCompanyPaymentMethodsResponseFromJSONTyped: () => GetCompanyPaymentMethodsResponseFromJSONTyped,
1275
+ GetCompanyPaymentMethodsResponseToJSON: () => GetCompanyPaymentMethodsResponseToJSON,
1276
+ GetCompanyPaymentMethodsResponseToJSONTyped: () => GetCompanyPaymentMethodsResponseToJSONTyped,
1246
1277
  GetCompanyUpcomingInvoiceResponseFromJSON: () => GetCompanyUpcomingInvoiceResponseFromJSON,
1247
1278
  GetCompanyUpcomingInvoiceResponseFromJSONTyped: () => GetCompanyUpcomingInvoiceResponseFromJSONTyped,
1248
1279
  GetCompanyUpcomingInvoiceResponseToJSON: () => GetCompanyUpcomingInvoiceResponseToJSON,
@@ -1252,15 +1283,42 @@ __export2(models_exports, {
1252
1283
  InvoiceStatusFromJSONTyped: () => InvoiceStatusFromJSONTyped,
1253
1284
  InvoiceStatusToJSON: () => InvoiceStatusToJSON,
1254
1285
  InvoiceStatusToJSONTyped: () => InvoiceStatusToJSONTyped,
1286
+ PaymentMethodResponseDataFromJSON: () => PaymentMethodResponseDataFromJSON,
1287
+ PaymentMethodResponseDataFromJSONTyped: () => PaymentMethodResponseDataFromJSONTyped,
1288
+ PaymentMethodResponseDataToJSON: () => PaymentMethodResponseDataToJSON,
1289
+ PaymentMethodResponseDataToJSONTyped: () => PaymentMethodResponseDataToJSONTyped,
1290
+ SetupIntentResponseDataFromJSON: () => SetupIntentResponseDataFromJSON,
1291
+ SetupIntentResponseDataFromJSONTyped: () => SetupIntentResponseDataFromJSONTyped,
1292
+ SetupIntentResponseDataToJSON: () => SetupIntentResponseDataToJSON,
1293
+ SetupIntentResponseDataToJSONTyped: () => SetupIntentResponseDataToJSONTyped,
1294
+ UpdatePaymentMethodRequestBodyFromJSON: () => UpdatePaymentMethodRequestBodyFromJSON,
1295
+ UpdatePaymentMethodRequestBodyFromJSONTyped: () => UpdatePaymentMethodRequestBodyFromJSONTyped,
1296
+ UpdatePaymentMethodRequestBodyToJSON: () => UpdatePaymentMethodRequestBodyToJSON,
1297
+ UpdatePaymentMethodRequestBodyToJSONTyped: () => UpdatePaymentMethodRequestBodyToJSONTyped,
1298
+ UpdatePaymentMethodResponseFromJSON: () => UpdatePaymentMethodResponseFromJSON,
1299
+ UpdatePaymentMethodResponseFromJSONTyped: () => UpdatePaymentMethodResponseFromJSONTyped,
1300
+ UpdatePaymentMethodResponseToJSON: () => UpdatePaymentMethodResponseToJSON,
1301
+ UpdatePaymentMethodResponseToJSONTyped: () => UpdatePaymentMethodResponseToJSONTyped,
1255
1302
  instanceOfApiError: () => instanceOfApiError,
1303
+ instanceOfBillingProviderType: () => instanceOfBillingProviderType,
1256
1304
  instanceOfCompanyDiscountResponseData: () => instanceOfCompanyDiscountResponseData,
1257
1305
  instanceOfCompanyInvoiceResponseData: () => instanceOfCompanyInvoiceResponseData,
1258
1306
  instanceOfCompanyInvoicesResponseData: () => instanceOfCompanyInvoicesResponseData,
1307
+ instanceOfCompanyPaymentMethodResponseData: () => instanceOfCompanyPaymentMethodResponseData,
1308
+ instanceOfCompanyPaymentMethodsResponseData: () => instanceOfCompanyPaymentMethodsResponseData,
1259
1309
  instanceOfCompanyUpcomingInvoiceResponseData: () => instanceOfCompanyUpcomingInvoiceResponseData,
1310
+ instanceOfCreateSetupIntentResponse: () => instanceOfCreateSetupIntentResponse,
1311
+ instanceOfDeletePaymentMethodResponse: () => instanceOfDeletePaymentMethodResponse,
1312
+ instanceOfDeleteResponse: () => instanceOfDeleteResponse,
1260
1313
  instanceOfGetCompanyInvoicesParams: () => instanceOfGetCompanyInvoicesParams,
1261
1314
  instanceOfGetCompanyInvoicesResponse: () => instanceOfGetCompanyInvoicesResponse,
1315
+ instanceOfGetCompanyPaymentMethodsResponse: () => instanceOfGetCompanyPaymentMethodsResponse,
1262
1316
  instanceOfGetCompanyUpcomingInvoiceResponse: () => instanceOfGetCompanyUpcomingInvoiceResponse,
1263
- instanceOfInvoiceStatus: () => instanceOfInvoiceStatus
1317
+ instanceOfInvoiceStatus: () => instanceOfInvoiceStatus,
1318
+ instanceOfPaymentMethodResponseData: () => instanceOfPaymentMethodResponseData,
1319
+ instanceOfSetupIntentResponseData: () => instanceOfSetupIntentResponseData,
1320
+ instanceOfUpdatePaymentMethodRequestBody: () => instanceOfUpdatePaymentMethodRequestBody,
1321
+ instanceOfUpdatePaymentMethodResponse: () => instanceOfUpdatePaymentMethodResponse
1264
1322
  });
1265
1323
  function instanceOfApiError(value) {
1266
1324
  if (!("error" in value) || value["error"] === void 0) return false;
@@ -1288,6 +1346,34 @@ function ApiErrorToJSONTyped(value, ignoreDiscriminator = false) {
1288
1346
  error: value["error"]
1289
1347
  };
1290
1348
  }
1349
+ var BillingProviderType = {
1350
+ Metronome: "metronome",
1351
+ Orb: "orb",
1352
+ Schematic: "schematic",
1353
+ Stripe: "stripe"
1354
+ };
1355
+ function instanceOfBillingProviderType(value) {
1356
+ for (const key in BillingProviderType) {
1357
+ if (Object.prototype.hasOwnProperty.call(BillingProviderType, key)) {
1358
+ if (BillingProviderType[key] === value) {
1359
+ return true;
1360
+ }
1361
+ }
1362
+ }
1363
+ return false;
1364
+ }
1365
+ function BillingProviderTypeFromJSON2(json) {
1366
+ return BillingProviderTypeFromJSONTyped11(json, false);
1367
+ }
1368
+ function BillingProviderTypeFromJSONTyped11(json, ignoreDiscriminator) {
1369
+ return json;
1370
+ }
1371
+ function BillingProviderTypeToJSON2(value) {
1372
+ return value;
1373
+ }
1374
+ function BillingProviderTypeToJSONTyped11(value, ignoreDiscriminator) {
1375
+ return value;
1376
+ }
1291
1377
  function instanceOfCompanyDiscountResponseData(value) {
1292
1378
  if (!("couponName" in value) || value["couponName"] === void 0)
1293
1379
  return false;
@@ -1431,6 +1517,97 @@ function CompanyInvoicesResponseDataToJSONTyped(value, ignoreDiscriminator = fal
1431
1517
  )
1432
1518
  };
1433
1519
  }
1520
+ function instanceOfCompanyPaymentMethodResponseData(value) {
1521
+ if (!("canRemove" in value) || value["canRemove"] === void 0) return false;
1522
+ if (!("externalId" in value) || value["externalId"] === void 0)
1523
+ return false;
1524
+ if (!("id" in value) || value["id"] === void 0) return false;
1525
+ if (!("isDefault" in value) || value["isDefault"] === void 0) return false;
1526
+ if (!("type" in value) || value["type"] === void 0) return false;
1527
+ return true;
1528
+ }
1529
+ function CompanyPaymentMethodResponseDataFromJSON(json) {
1530
+ return CompanyPaymentMethodResponseDataFromJSONTyped(json, false);
1531
+ }
1532
+ function CompanyPaymentMethodResponseDataFromJSONTyped(json, ignoreDiscriminator) {
1533
+ if (json == null) {
1534
+ return json;
1535
+ }
1536
+ return {
1537
+ accountLast4: json["account_last4"] == null ? void 0 : json["account_last4"],
1538
+ accountName: json["account_name"] == null ? void 0 : json["account_name"],
1539
+ bankName: json["bank_name"] == null ? void 0 : json["bank_name"],
1540
+ billingEmail: json["billing_email"] == null ? void 0 : json["billing_email"],
1541
+ billingName: json["billing_name"] == null ? void 0 : json["billing_name"],
1542
+ canRemove: json["can_remove"],
1543
+ cardBrand: json["card_brand"] == null ? void 0 : json["card_brand"],
1544
+ cardExpMonth: json["card_exp_month"] == null ? void 0 : json["card_exp_month"],
1545
+ cardExpYear: json["card_exp_year"] == null ? void 0 : json["card_exp_year"],
1546
+ cardLast4: json["card_last4"] == null ? void 0 : json["card_last4"],
1547
+ externalId: json["external_id"],
1548
+ id: json["id"],
1549
+ isDefault: json["is_default"],
1550
+ type: json["type"]
1551
+ };
1552
+ }
1553
+ function CompanyPaymentMethodResponseDataToJSON(json) {
1554
+ return CompanyPaymentMethodResponseDataToJSONTyped(json, false);
1555
+ }
1556
+ function CompanyPaymentMethodResponseDataToJSONTyped(value, ignoreDiscriminator = false) {
1557
+ if (value == null) {
1558
+ return value;
1559
+ }
1560
+ return {
1561
+ account_last4: value["accountLast4"],
1562
+ account_name: value["accountName"],
1563
+ bank_name: value["bankName"],
1564
+ billing_email: value["billingEmail"],
1565
+ billing_name: value["billingName"],
1566
+ can_remove: value["canRemove"],
1567
+ card_brand: value["cardBrand"],
1568
+ card_exp_month: value["cardExpMonth"],
1569
+ card_exp_year: value["cardExpYear"],
1570
+ card_last4: value["cardLast4"],
1571
+ external_id: value["externalId"],
1572
+ id: value["id"],
1573
+ is_default: value["isDefault"],
1574
+ type: value["type"]
1575
+ };
1576
+ }
1577
+ function instanceOfCompanyPaymentMethodsResponseData(value) {
1578
+ if (!("count" in value) || value["count"] === void 0) return false;
1579
+ if (!("paymentMethods" in value) || value["paymentMethods"] === void 0)
1580
+ return false;
1581
+ return true;
1582
+ }
1583
+ function CompanyPaymentMethodsResponseDataFromJSON(json) {
1584
+ return CompanyPaymentMethodsResponseDataFromJSONTyped(json, false);
1585
+ }
1586
+ function CompanyPaymentMethodsResponseDataFromJSONTyped(json, ignoreDiscriminator) {
1587
+ if (json == null) {
1588
+ return json;
1589
+ }
1590
+ return {
1591
+ count: json["count"],
1592
+ paymentMethods: json["payment_methods"].map(
1593
+ CompanyPaymentMethodResponseDataFromJSON
1594
+ )
1595
+ };
1596
+ }
1597
+ function CompanyPaymentMethodsResponseDataToJSON(json) {
1598
+ return CompanyPaymentMethodsResponseDataToJSONTyped(json, false);
1599
+ }
1600
+ function CompanyPaymentMethodsResponseDataToJSONTyped(value, ignoreDiscriminator = false) {
1601
+ if (value == null) {
1602
+ return value;
1603
+ }
1604
+ return {
1605
+ count: value["count"],
1606
+ payment_methods: value["paymentMethods"].map(
1607
+ CompanyPaymentMethodResponseDataToJSON
1608
+ )
1609
+ };
1610
+ }
1434
1611
  function instanceOfCompanyUpcomingInvoiceResponseData(value) {
1435
1612
  if (!("amountDue" in value) || value["amountDue"] === void 0) return false;
1436
1613
  if (!("currency" in value) || value["currency"] === void 0) return false;
@@ -1480,6 +1657,122 @@ function CompanyUpcomingInvoiceResponseDataToJSONTyped(value, ignoreDiscriminato
1480
1657
  subtotal: value["subtotal"]
1481
1658
  };
1482
1659
  }
1660
+ function instanceOfSetupIntentResponseData(value) {
1661
+ if (!("schematicPublishableKey" in value) || value["schematicPublishableKey"] === void 0)
1662
+ return false;
1663
+ return true;
1664
+ }
1665
+ function SetupIntentResponseDataFromJSON(json) {
1666
+ return SetupIntentResponseDataFromJSONTyped(json, false);
1667
+ }
1668
+ function SetupIntentResponseDataFromJSONTyped(json, ignoreDiscriminator) {
1669
+ if (json == null) {
1670
+ return json;
1671
+ }
1672
+ return {
1673
+ accountId: json["account_id"] == null ? void 0 : json["account_id"],
1674
+ publishableKey: json["publishable_key"] == null ? void 0 : json["publishable_key"],
1675
+ schematicPublishableKey: json["schematic_publishable_key"],
1676
+ setupIntentClientSecret: json["setup_intent_client_secret"] == null ? void 0 : json["setup_intent_client_secret"]
1677
+ };
1678
+ }
1679
+ function SetupIntentResponseDataToJSON(json) {
1680
+ return SetupIntentResponseDataToJSONTyped(json, false);
1681
+ }
1682
+ function SetupIntentResponseDataToJSONTyped(value, ignoreDiscriminator = false) {
1683
+ if (value == null) {
1684
+ return value;
1685
+ }
1686
+ return {
1687
+ account_id: value["accountId"],
1688
+ publishable_key: value["publishableKey"],
1689
+ schematic_publishable_key: value["schematicPublishableKey"],
1690
+ setup_intent_client_secret: value["setupIntentClientSecret"]
1691
+ };
1692
+ }
1693
+ function instanceOfCreateSetupIntentResponse(value) {
1694
+ if (!("data" in value) || value["data"] === void 0) return false;
1695
+ if (!("params" in value) || value["params"] === void 0) return false;
1696
+ return true;
1697
+ }
1698
+ function CreateSetupIntentResponseFromJSON(json) {
1699
+ return CreateSetupIntentResponseFromJSONTyped(json, false);
1700
+ }
1701
+ function CreateSetupIntentResponseFromJSONTyped(json, ignoreDiscriminator) {
1702
+ if (json == null) {
1703
+ return json;
1704
+ }
1705
+ return {
1706
+ data: SetupIntentResponseDataFromJSON(json["data"]),
1707
+ params: json["params"]
1708
+ };
1709
+ }
1710
+ function CreateSetupIntentResponseToJSON(json) {
1711
+ return CreateSetupIntentResponseToJSONTyped(json, false);
1712
+ }
1713
+ function CreateSetupIntentResponseToJSONTyped(value, ignoreDiscriminator = false) {
1714
+ if (value == null) {
1715
+ return value;
1716
+ }
1717
+ return {
1718
+ data: SetupIntentResponseDataToJSON(value["data"]),
1719
+ params: value["params"]
1720
+ };
1721
+ }
1722
+ function instanceOfDeleteResponse(value) {
1723
+ return true;
1724
+ }
1725
+ function DeleteResponseFromJSON(json) {
1726
+ return DeleteResponseFromJSONTyped(json, false);
1727
+ }
1728
+ function DeleteResponseFromJSONTyped(json, ignoreDiscriminator) {
1729
+ if (json == null) {
1730
+ return json;
1731
+ }
1732
+ return {
1733
+ deleted: json["deleted"] == null ? void 0 : json["deleted"]
1734
+ };
1735
+ }
1736
+ function DeleteResponseToJSON(json) {
1737
+ return DeleteResponseToJSONTyped(json, false);
1738
+ }
1739
+ function DeleteResponseToJSONTyped(value, ignoreDiscriminator = false) {
1740
+ if (value == null) {
1741
+ return value;
1742
+ }
1743
+ return {
1744
+ deleted: value["deleted"]
1745
+ };
1746
+ }
1747
+ function instanceOfDeletePaymentMethodResponse(value) {
1748
+ if (!("data" in value) || value["data"] === void 0) return false;
1749
+ if (!("params" in value) || value["params"] === void 0) return false;
1750
+ return true;
1751
+ }
1752
+ function DeletePaymentMethodResponseFromJSON(json) {
1753
+ return DeletePaymentMethodResponseFromJSONTyped(json, false);
1754
+ }
1755
+ function DeletePaymentMethodResponseFromJSONTyped(json, ignoreDiscriminator) {
1756
+ if (json == null) {
1757
+ return json;
1758
+ }
1759
+ return {
1760
+ data: DeleteResponseFromJSON(json["data"]),
1761
+ params: json["params"]
1762
+ };
1763
+ }
1764
+ function DeletePaymentMethodResponseToJSON(json) {
1765
+ return DeletePaymentMethodResponseToJSONTyped(json, false);
1766
+ }
1767
+ function DeletePaymentMethodResponseToJSONTyped(value, ignoreDiscriminator = false) {
1768
+ if (value == null) {
1769
+ return value;
1770
+ }
1771
+ return {
1772
+ data: DeleteResponseToJSON(value["data"]),
1773
+ params: value["params"]
1774
+ };
1775
+ }
1483
1776
  function instanceOfGetCompanyInvoicesParams(value) {
1484
1777
  return true;
1485
1778
  }
@@ -1538,6 +1831,35 @@ function GetCompanyInvoicesResponseToJSONTyped(value, ignoreDiscriminator = fals
1538
1831
  params: GetCompanyInvoicesParamsToJSON(value["params"])
1539
1832
  };
1540
1833
  }
1834
+ function instanceOfGetCompanyPaymentMethodsResponse(value) {
1835
+ if (!("data" in value) || value["data"] === void 0) return false;
1836
+ if (!("params" in value) || value["params"] === void 0) return false;
1837
+ return true;
1838
+ }
1839
+ function GetCompanyPaymentMethodsResponseFromJSON(json) {
1840
+ return GetCompanyPaymentMethodsResponseFromJSONTyped(json, false);
1841
+ }
1842
+ function GetCompanyPaymentMethodsResponseFromJSONTyped(json, ignoreDiscriminator) {
1843
+ if (json == null) {
1844
+ return json;
1845
+ }
1846
+ return {
1847
+ data: CompanyPaymentMethodsResponseDataFromJSON(json["data"]),
1848
+ params: json["params"]
1849
+ };
1850
+ }
1851
+ function GetCompanyPaymentMethodsResponseToJSON(json) {
1852
+ return GetCompanyPaymentMethodsResponseToJSONTyped(json, false);
1853
+ }
1854
+ function GetCompanyPaymentMethodsResponseToJSONTyped(value, ignoreDiscriminator = false) {
1855
+ if (value == null) {
1856
+ return value;
1857
+ }
1858
+ return {
1859
+ data: CompanyPaymentMethodsResponseDataToJSON(value["data"]),
1860
+ params: value["params"]
1861
+ };
1862
+ }
1541
1863
  function instanceOfGetCompanyUpcomingInvoiceResponse(value) {
1542
1864
  if (!("data" in value) || value["data"] === void 0) return false;
1543
1865
  if (!("params" in value) || value["params"] === void 0) return false;
@@ -1567,6 +1889,134 @@ function GetCompanyUpcomingInvoiceResponseToJSONTyped(value, ignoreDiscriminator
1567
1889
  params: value["params"]
1568
1890
  };
1569
1891
  }
1892
+ function instanceOfPaymentMethodResponseData(value) {
1893
+ if (!("createdAt" in value) || value["createdAt"] === void 0) return false;
1894
+ if (!("customerExternalId" in value) || value["customerExternalId"] === void 0)
1895
+ return false;
1896
+ if (!("environmentId" in value) || value["environmentId"] === void 0)
1897
+ return false;
1898
+ if (!("externalId" in value) || value["externalId"] === void 0)
1899
+ return false;
1900
+ if (!("id" in value) || value["id"] === void 0) return false;
1901
+ if (!("paymentMethodType" in value) || value["paymentMethodType"] === void 0)
1902
+ return false;
1903
+ if (!("providerType" in value) || value["providerType"] === void 0)
1904
+ return false;
1905
+ if (!("updatedAt" in value) || value["updatedAt"] === void 0) return false;
1906
+ return true;
1907
+ }
1908
+ function PaymentMethodResponseDataFromJSON(json) {
1909
+ return PaymentMethodResponseDataFromJSONTyped(json, false);
1910
+ }
1911
+ function PaymentMethodResponseDataFromJSONTyped(json, ignoreDiscriminator) {
1912
+ if (json == null) {
1913
+ return json;
1914
+ }
1915
+ return {
1916
+ accountLast4: json["account_last4"] == null ? void 0 : json["account_last4"],
1917
+ accountName: json["account_name"] == null ? void 0 : json["account_name"],
1918
+ bankName: json["bank_name"] == null ? void 0 : json["bank_name"],
1919
+ billingEmail: json["billing_email"] == null ? void 0 : json["billing_email"],
1920
+ billingName: json["billing_name"] == null ? void 0 : json["billing_name"],
1921
+ cardBrand: json["card_brand"] == null ? void 0 : json["card_brand"],
1922
+ cardExpMonth: json["card_exp_month"] == null ? void 0 : json["card_exp_month"],
1923
+ cardExpYear: json["card_exp_year"] == null ? void 0 : json["card_exp_year"],
1924
+ cardLast4: json["card_last4"] == null ? void 0 : json["card_last4"],
1925
+ companyId: json["company_id"] == null ? void 0 : json["company_id"],
1926
+ createdAt: new Date(json["created_at"]),
1927
+ customerExternalId: json["customer_external_id"],
1928
+ environmentId: json["environment_id"],
1929
+ externalId: json["external_id"],
1930
+ id: json["id"],
1931
+ paymentMethodType: json["payment_method_type"],
1932
+ providerType: BillingProviderTypeFromJSON2(json["provider_type"]),
1933
+ updatedAt: new Date(json["updated_at"])
1934
+ };
1935
+ }
1936
+ function PaymentMethodResponseDataToJSON(json) {
1937
+ return PaymentMethodResponseDataToJSONTyped(json, false);
1938
+ }
1939
+ function PaymentMethodResponseDataToJSONTyped(value, ignoreDiscriminator = false) {
1940
+ if (value == null) {
1941
+ return value;
1942
+ }
1943
+ return {
1944
+ account_last4: value["accountLast4"],
1945
+ account_name: value["accountName"],
1946
+ bank_name: value["bankName"],
1947
+ billing_email: value["billingEmail"],
1948
+ billing_name: value["billingName"],
1949
+ card_brand: value["cardBrand"],
1950
+ card_exp_month: value["cardExpMonth"],
1951
+ card_exp_year: value["cardExpYear"],
1952
+ card_last4: value["cardLast4"],
1953
+ company_id: value["companyId"],
1954
+ created_at: value["createdAt"].toISOString(),
1955
+ customer_external_id: value["customerExternalId"],
1956
+ environment_id: value["environmentId"],
1957
+ external_id: value["externalId"],
1958
+ id: value["id"],
1959
+ payment_method_type: value["paymentMethodType"],
1960
+ provider_type: BillingProviderTypeToJSON2(value["providerType"]),
1961
+ updated_at: value["updatedAt"].toISOString()
1962
+ };
1963
+ }
1964
+ function instanceOfUpdatePaymentMethodRequestBody(value) {
1965
+ if (!("paymentMethodId" in value) || value["paymentMethodId"] === void 0)
1966
+ return false;
1967
+ return true;
1968
+ }
1969
+ function UpdatePaymentMethodRequestBodyFromJSON(json) {
1970
+ return UpdatePaymentMethodRequestBodyFromJSONTyped(json, false);
1971
+ }
1972
+ function UpdatePaymentMethodRequestBodyFromJSONTyped(json, ignoreDiscriminator) {
1973
+ if (json == null) {
1974
+ return json;
1975
+ }
1976
+ return {
1977
+ paymentMethodId: json["payment_method_id"]
1978
+ };
1979
+ }
1980
+ function UpdatePaymentMethodRequestBodyToJSON(json) {
1981
+ return UpdatePaymentMethodRequestBodyToJSONTyped(json, false);
1982
+ }
1983
+ function UpdatePaymentMethodRequestBodyToJSONTyped(value, ignoreDiscriminator = false) {
1984
+ if (value == null) {
1985
+ return value;
1986
+ }
1987
+ return {
1988
+ payment_method_id: value["paymentMethodId"]
1989
+ };
1990
+ }
1991
+ function instanceOfUpdatePaymentMethodResponse(value) {
1992
+ if (!("data" in value) || value["data"] === void 0) return false;
1993
+ if (!("params" in value) || value["params"] === void 0) return false;
1994
+ return true;
1995
+ }
1996
+ function UpdatePaymentMethodResponseFromJSON(json) {
1997
+ return UpdatePaymentMethodResponseFromJSONTyped(json, false);
1998
+ }
1999
+ function UpdatePaymentMethodResponseFromJSONTyped(json, ignoreDiscriminator) {
2000
+ if (json == null) {
2001
+ return json;
2002
+ }
2003
+ return {
2004
+ data: PaymentMethodResponseDataFromJSON(json["data"]),
2005
+ params: json["params"]
2006
+ };
2007
+ }
2008
+ function UpdatePaymentMethodResponseToJSON(json) {
2009
+ return UpdatePaymentMethodResponseToJSONTyped(json, false);
2010
+ }
2011
+ function UpdatePaymentMethodResponseToJSONTyped(value, ignoreDiscriminator = false) {
2012
+ if (value == null) {
2013
+ return value;
2014
+ }
2015
+ return {
2016
+ data: PaymentMethodResponseDataToJSON(value["data"]),
2017
+ params: value["params"]
2018
+ };
2019
+ }
1570
2020
  var DEFAULT_INVOICE_QUERY = {};
1571
2021
  function normalizeInvoiceQuery(query) {
1572
2022
  const { includePending, ...rest } = query;
@@ -1891,6 +2341,39 @@ var SchematicBillingClient = class {
1891
2341
  return GetCompanyUpcomingInvoiceResponseFromJSON(body).data;
1892
2342
  });
1893
2343
  }
2344
+ fetchPaymentMethods() {
2345
+ const path = "/company/payment-methods";
2346
+ return this.session.request(path).then((body) => {
2347
+ if (body === null || typeof body !== "object" || !("data" in body)) {
2348
+ throw new Error(`Malformed response from ${path}`);
2349
+ }
2350
+ const data = body.data;
2351
+ if (data == null || data.payment_methods == null) {
2352
+ return [];
2353
+ }
2354
+ return GetCompanyPaymentMethodsResponseFromJSON(body).data.paymentMethods;
2355
+ });
2356
+ }
2357
+ createSetupIntent() {
2358
+ const path = "/components/setup-intent";
2359
+ return this.session.request(path, { method: "POST" }).then((body) => {
2360
+ if (body === null || typeof body !== "object" || !("data" in body)) {
2361
+ throw new Error(`Malformed response from ${path}`);
2362
+ }
2363
+ return CreateSetupIntentResponseFromJSON(body).data;
2364
+ });
2365
+ }
2366
+ updatePaymentMethod(externalId) {
2367
+ return this.session.request("/checkout/paymentmethod/update", {
2368
+ method: "POST",
2369
+ body: { payment_method_id: externalId }
2370
+ }).then(() => void 0);
2371
+ }
2372
+ deletePaymentMethod(id) {
2373
+ return this.session.request(`/checkout/paymentmethod/${encodeURIComponent(id)}`, {
2374
+ method: "DELETE"
2375
+ }).then(() => void 0);
2376
+ }
1894
2377
  };
1895
2378
  var anonymousIdKey = "schematicId";
1896
2379
  var flagStateCachePrefix = "schematicCache";
@@ -4011,6 +4494,10 @@ var BillingStore = class {
4011
4494
  () => this._client.fetchUpcomingInvoice(),
4012
4495
  { readiness }
4013
4496
  );
4497
+ this.paymentMethods = new KeyedResource(
4498
+ () => this._client.fetchPaymentMethods(),
4499
+ { readiness }
4500
+ );
4014
4501
  const held = { key: initialData.sessionKey };
4015
4502
  if (initialData.invoices !== void 0) {
4016
4503
  held.invoices = {
@@ -4025,7 +4512,10 @@ var BillingStore = class {
4025
4512
  if (initialData.upcomingInvoice !== void 0) {
4026
4513
  held.upcomingInvoice = initialData.upcomingInvoice;
4027
4514
  }
4028
- if (held.invoices !== void 0 || held.upcomingInvoice !== void 0) {
4515
+ if (initialData.paymentMethods !== void 0) {
4516
+ held.paymentMethods = initialData.paymentMethods;
4517
+ }
4518
+ if (held.invoices !== void 0 || held.upcomingInvoice !== void 0 || held.paymentMethods !== void 0) {
4029
4519
  this._held = held;
4030
4520
  this._settleSeed(claimFrom(options.session) ?? claimOf(this._client));
4031
4521
  }
@@ -4033,6 +4523,7 @@ var BillingStore = class {
4033
4523
  _client;
4034
4524
  invoices;
4035
4525
  upcomingInvoice;
4526
+ paymentMethods;
4036
4527
  _pageSize;
4037
4528
  _unsubscribe;
4038
4529
  _connected = false;
@@ -4108,6 +4599,9 @@ var BillingStore = class {
4108
4599
  if (held.upcomingInvoice !== void 0) {
4109
4600
  this.upcomingInvoice.seed(SINGLETON, held.upcomingInvoice);
4110
4601
  }
4602
+ if (held.paymentMethods !== void 0) {
4603
+ this.paymentMethods.seed(SINGLETON, held.paymentMethods);
4604
+ }
4111
4605
  this._seedKey = held.key;
4112
4606
  this._seeded = true;
4113
4607
  }
@@ -4169,9 +4663,46 @@ var BillingStore = class {
4169
4663
  };
4170
4664
  });
4171
4665
  }
4666
+ /**
4667
+ * Makes the payment method `externalId` the company's default, then
4668
+ * reloads the list so it says so. Rejects with the client's error when
4669
+ * the write fails; a reload that fails afterwards lands on the list's
4670
+ * `error`, since the write itself went through.
4671
+ */
4672
+ async setDefaultPaymentMethod(externalId) {
4673
+ await this._client.updatePaymentMethod(externalId);
4674
+ await this._reloadPaymentMethods();
4675
+ }
4676
+ /** Removes the payment method `id`, then reloads the list. Rejects as `setDefaultPaymentMethod` does. */
4677
+ async removePaymentMethod(id) {
4678
+ await this._client.deletePaymentMethod(id);
4679
+ await this._reloadPaymentMethods();
4680
+ }
4681
+ /**
4682
+ * Mints a setup intent for adding a payment method. Nothing in the store
4683
+ * changes until the provider confirms it and the host reloads the list,
4684
+ * so this is a pass-through to the client.
4685
+ */
4686
+ createSetupIntent() {
4687
+ return this._client.createSetupIntent();
4688
+ }
4172
4689
  dispose() {
4173
4690
  this._unsubscribe?.();
4174
4691
  }
4692
+ /**
4693
+ * After a write. A list nobody has read is left alone: it loads fresh
4694
+ * when someone does. One that is loaded, or subscribed and waiting on a
4695
+ * failed load, is fetched again; `refetch` never rejects.
4696
+ */
4697
+ async _reloadPaymentMethods() {
4698
+ if (!this.paymentMethods.has(SINGLETON)) {
4699
+ return;
4700
+ }
4701
+ const resource = this.paymentMethods.get(SINGLETON);
4702
+ if (resource.snapshot.data !== void 0 || resource.subscriberCount > 0) {
4703
+ await resource.refetch();
4704
+ }
4705
+ }
4175
4706
  /**
4176
4707
  * Re-reads the window already loaded, in as many requests as the API's
4177
4708
  * page cap needs. A window paged past that cap still comes back whole:
@@ -4211,7 +4742,8 @@ var BillingStore = class {
4211
4742
  };
4212
4743
  var RESOURCE_NAMES = [
4213
4744
  "invoices",
4214
- "upcomingInvoice"
4745
+ "upcomingInvoice",
4746
+ "paymentMethods"
4215
4747
  ];
4216
4748
 
4217
4749
  // src/billing/context.tsx
@@ -4261,6 +4793,25 @@ var BillingDataContext = (0, import_react2.createContext)(
4261
4793
  );
4262
4794
  var MISSING_BILLING_SOURCE_MESSAGE = "Schematic billing hooks need a SchematicProvider with a session, billingClient, or initialData, or a BillingDataProvider.";
4263
4795
  var missingSourceError = new Error(MISSING_BILLING_SOURCE_MESSAGE);
4796
+ var BILLING_ACTION_UNAVAILABLE_MESSAGE = (name) => `Schematic billing action ${name} is not available: the provider only reads. Writes need a SchematicProvider with a session or billingClient, or a BillingDataProvider given \`actions\`.`;
4797
+ var ACTION_NAMES = [
4798
+ "setDefaultPaymentMethod",
4799
+ "removePaymentMethod",
4800
+ "createSetupIntent"
4801
+ ];
4802
+ function rejectingActions(reason, given = {}) {
4803
+ const actions = {};
4804
+ for (const name of ACTION_NAMES) {
4805
+ actions[name] = given[name] ?? (() => Promise.reject(reason(name)));
4806
+ }
4807
+ return actions;
4808
+ }
4809
+ var unavailableActions = rejectingActions(
4810
+ (name) => new Error(BILLING_ACTION_UNAVAILABLE_MESSAGE(name))
4811
+ );
4812
+ function actionsOf(source) {
4813
+ return source.actions ?? unavailableActions;
4814
+ }
4264
4815
  var missingHandle = {
4265
4816
  data: void 0,
4266
4817
  error: missingSourceError,
@@ -4274,12 +4825,16 @@ var missingBillingSource = {
4274
4825
  handle: () => missingHandle,
4275
4826
  loadMoreInvoices: () => Promise.resolve(),
4276
4827
  invalidateAll: () => {
4277
- }
4828
+ },
4829
+ // The same error a read reports, so a write outside any provider names
4830
+ // the misconfiguration rather than a source that only reads.
4831
+ actions: rejectingActions(() => missingSourceError)
4278
4832
  };
4279
4833
  function useBillingDataSource() {
4280
4834
  return (0, import_react2.useContext)(BillingDataContext) ?? missingBillingSource;
4281
4835
  }
4282
4836
  function BillingDataProvider({
4837
+ actions,
4283
4838
  children,
4284
4839
  data,
4285
4840
  locale,
@@ -4293,6 +4848,10 @@ function BillingDataProvider({
4293
4848
  const source = (0, import_react2.useMemo)(() => {
4294
4849
  const handles = /* @__PURE__ */ new Map();
4295
4850
  return {
4851
+ actions: rejectingActions(
4852
+ (name) => new Error(BILLING_ACTION_UNAVAILABLE_MESSAGE(name)),
4853
+ actions
4854
+ ),
4296
4855
  subscribe: () => () => {
4297
4856
  },
4298
4857
  handle: (name) => {
@@ -4318,7 +4877,7 @@ function BillingDataProvider({
4318
4877
  invalidateAll: () => {
4319
4878
  }
4320
4879
  };
4321
- }, [data, onLoadMoreInvoices, onRefetch, status]);
4880
+ }, [actions, data, onLoadMoreInvoices, onRefetch, status]);
4322
4881
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BillingDataContext.Provider, { value: source, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
4323
4882
  SchematicI18nProvider,
4324
4883
  {
@@ -4366,6 +4925,48 @@ function useInvoices(query = DEFAULT_INVOICE_QUERY) {
4366
4925
  function useUpcomingInvoice() {
4367
4926
  return useBillingResource("upcomingInvoice", SINGLETON);
4368
4927
  }
4928
+ var IDLE = { inflight: 0, error: void 0 };
4929
+ function usePaymentMethods() {
4930
+ const source = useBillingDataSource();
4931
+ const handle = useBillingResource("paymentMethods", SINGLETON);
4932
+ const [mutation, setMutation] = (0, import_react3.useState)(IDLE);
4933
+ const run = (0, import_react3.useCallback)(async (write) => {
4934
+ setMutation((m) => ({ inflight: m.inflight + 1, error: void 0 }));
4935
+ try {
4936
+ await write();
4937
+ } catch (cause) {
4938
+ const error = cause instanceof Error ? cause : new Error(String(cause));
4939
+ setMutation((m) => ({ inflight: m.inflight - 1, error }));
4940
+ throw error;
4941
+ }
4942
+ setMutation((m) => ({ inflight: m.inflight - 1, error: void 0 }));
4943
+ }, []);
4944
+ const setDefault = (0, import_react3.useCallback)(
4945
+ (externalId) => run(() => actionsOf(source).setDefaultPaymentMethod(externalId)),
4946
+ [run, source]
4947
+ );
4948
+ const remove = (0, import_react3.useCallback)(
4949
+ (id) => run(() => actionsOf(source).removePaymentMethod(id)),
4950
+ [run, source]
4951
+ );
4952
+ return (0, import_react3.useMemo)(
4953
+ () => ({
4954
+ ...handle,
4955
+ setDefault,
4956
+ remove,
4957
+ isMutating: mutation.inflight > 0,
4958
+ mutationError: mutation.error
4959
+ }),
4960
+ [handle, mutation, remove, setDefault]
4961
+ );
4962
+ }
4963
+ function useSetupIntent() {
4964
+ const source = useBillingDataSource();
4965
+ return (0, import_react3.useMemo)(
4966
+ () => ({ create: () => actionsOf(source).createSetupIntent() }),
4967
+ [source]
4968
+ );
4969
+ }
4369
4970
  function useInvalidateBillingData() {
4370
4971
  return useBillingDataSource().invalidateAll;
4371
4972
  }
@@ -4439,7 +5040,12 @@ function BillingProvider({
4439
5040
  subscribe: (name, params, listener) => store.resource(name).subscribe(params, listener),
4440
5041
  handle,
4441
5042
  loadMoreInvoices: (query) => store.loadMoreInvoices(query),
4442
- invalidateAll: () => store.invalidateAll()
5043
+ invalidateAll: () => store.invalidateAll(),
5044
+ actions: {
5045
+ setDefaultPaymentMethod: (externalId) => store.setDefaultPaymentMethod(externalId),
5046
+ removePaymentMethod: (id) => store.removePaymentMethod(id),
5047
+ createSetupIntent: () => store.createSetupIntent()
5048
+ }
4443
5049
  };
4444
5050
  }, [store]);
4445
5051
  const localized = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
@@ -4485,7 +5091,7 @@ function staticSource(data) {
4485
5091
  }
4486
5092
 
4487
5093
  // src/version.ts
4488
- var version2 = "1.8.0";
5094
+ var version2 = "1.9.0";
4489
5095
 
4490
5096
  // src/context/schematic.tsx
4491
5097
  var import_jsx_runtime4 = require("react/jsx-runtime");