@schematichq/schematic-react 1.7.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.
- package/dist/schematic-react.cjs.js +646 -19
- package/dist/schematic-react.d.ts +354 -30
- package/dist/schematic-react.esm.js +653 -20
- package/package.json +8 -8
|
@@ -36,6 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
INVOICE_PAGE_SIZE: () => INVOICE_PAGE_SIZE,
|
|
37
37
|
InvoiceStatus: () => InvoiceStatus,
|
|
38
38
|
RuleType: () => RuleType,
|
|
39
|
+
SINGLETON: () => SINGLETON,
|
|
39
40
|
Schematic: () => Schematic,
|
|
40
41
|
SchematicI18nContext: () => SchematicI18nContext,
|
|
41
42
|
SchematicI18nProvider: () => SchematicI18nProvider,
|
|
@@ -46,6 +47,7 @@ __export(index_exports, {
|
|
|
46
47
|
useBillingDataSource: () => useBillingDataSource,
|
|
47
48
|
useInvalidateBillingData: () => useInvalidateBillingData,
|
|
48
49
|
useInvoices: () => useInvoices,
|
|
50
|
+
usePaymentMethods: () => usePaymentMethods,
|
|
49
51
|
useSchematic: () => useSchematic,
|
|
50
52
|
useSchematicContext: () => useSchematicContext,
|
|
51
53
|
useSchematicCreditBalance: () => useSchematicCreditBalance,
|
|
@@ -57,11 +59,13 @@ __export(index_exports, {
|
|
|
57
59
|
useSchematicLocale: () => useSchematicLocale,
|
|
58
60
|
useSchematicPlan: () => useSchematicPlan,
|
|
59
61
|
useSchematicStrings: () => useSchematicStrings,
|
|
60
|
-
useSchematicTranslate: () => useSchematicTranslate
|
|
62
|
+
useSchematicTranslate: () => useSchematicTranslate,
|
|
63
|
+
useSetupIntent: () => useSetupIntent,
|
|
64
|
+
useUpcomingInvoice: () => useUpcomingInvoice
|
|
61
65
|
});
|
|
62
66
|
module.exports = __toCommonJS(index_exports);
|
|
63
67
|
|
|
64
|
-
// node_modules/.pnpm/@schematichq+schematic-js@1.
|
|
68
|
+
// node_modules/.pnpm/@schematichq+schematic-js@1.9.0/node_modules/@schematichq/schematic-js/dist/schematic.esm.js
|
|
65
69
|
var __create2 = Object.create;
|
|
66
70
|
var __defProp2 = Object.defineProperty;
|
|
67
71
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
@@ -1209,13 +1213,19 @@ function contextString(context) {
|
|
|
1209
1213
|
}, {});
|
|
1210
1214
|
return JSON.stringify(sortedContext);
|
|
1211
1215
|
}
|
|
1212
|
-
var version = "1.
|
|
1216
|
+
var version = "1.9.0";
|
|
1217
|
+
var SINGLETON = {};
|
|
1213
1218
|
var models_exports = {};
|
|
1214
1219
|
__export2(models_exports, {
|
|
1215
1220
|
ApiErrorFromJSON: () => ApiErrorFromJSON,
|
|
1216
1221
|
ApiErrorFromJSONTyped: () => ApiErrorFromJSONTyped,
|
|
1217
1222
|
ApiErrorToJSON: () => ApiErrorToJSON,
|
|
1218
1223
|
ApiErrorToJSONTyped: () => ApiErrorToJSONTyped,
|
|
1224
|
+
BillingProviderType: () => BillingProviderType,
|
|
1225
|
+
BillingProviderTypeFromJSON: () => BillingProviderTypeFromJSON2,
|
|
1226
|
+
BillingProviderTypeFromJSONTyped: () => BillingProviderTypeFromJSONTyped11,
|
|
1227
|
+
BillingProviderTypeToJSON: () => BillingProviderTypeToJSON2,
|
|
1228
|
+
BillingProviderTypeToJSONTyped: () => BillingProviderTypeToJSONTyped11,
|
|
1219
1229
|
CompanyDiscountResponseDataFromJSON: () => CompanyDiscountResponseDataFromJSON,
|
|
1220
1230
|
CompanyDiscountResponseDataFromJSONTyped: () => CompanyDiscountResponseDataFromJSONTyped,
|
|
1221
1231
|
CompanyDiscountResponseDataToJSON: () => CompanyDiscountResponseDataToJSON,
|
|
@@ -1228,10 +1238,30 @@ __export2(models_exports, {
|
|
|
1228
1238
|
CompanyInvoicesResponseDataFromJSONTyped: () => CompanyInvoicesResponseDataFromJSONTyped,
|
|
1229
1239
|
CompanyInvoicesResponseDataToJSON: () => CompanyInvoicesResponseDataToJSON,
|
|
1230
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,
|
|
1231
1249
|
CompanyUpcomingInvoiceResponseDataFromJSON: () => CompanyUpcomingInvoiceResponseDataFromJSON,
|
|
1232
1250
|
CompanyUpcomingInvoiceResponseDataFromJSONTyped: () => CompanyUpcomingInvoiceResponseDataFromJSONTyped,
|
|
1233
1251
|
CompanyUpcomingInvoiceResponseDataToJSON: () => CompanyUpcomingInvoiceResponseDataToJSON,
|
|
1234
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,
|
|
1235
1265
|
GetCompanyInvoicesParamsFromJSON: () => GetCompanyInvoicesParamsFromJSON,
|
|
1236
1266
|
GetCompanyInvoicesParamsFromJSONTyped: () => GetCompanyInvoicesParamsFromJSONTyped,
|
|
1237
1267
|
GetCompanyInvoicesParamsToJSON: () => GetCompanyInvoicesParamsToJSON,
|
|
@@ -1240,6 +1270,10 @@ __export2(models_exports, {
|
|
|
1240
1270
|
GetCompanyInvoicesResponseFromJSONTyped: () => GetCompanyInvoicesResponseFromJSONTyped,
|
|
1241
1271
|
GetCompanyInvoicesResponseToJSON: () => GetCompanyInvoicesResponseToJSON,
|
|
1242
1272
|
GetCompanyInvoicesResponseToJSONTyped: () => GetCompanyInvoicesResponseToJSONTyped,
|
|
1273
|
+
GetCompanyPaymentMethodsResponseFromJSON: () => GetCompanyPaymentMethodsResponseFromJSON,
|
|
1274
|
+
GetCompanyPaymentMethodsResponseFromJSONTyped: () => GetCompanyPaymentMethodsResponseFromJSONTyped,
|
|
1275
|
+
GetCompanyPaymentMethodsResponseToJSON: () => GetCompanyPaymentMethodsResponseToJSON,
|
|
1276
|
+
GetCompanyPaymentMethodsResponseToJSONTyped: () => GetCompanyPaymentMethodsResponseToJSONTyped,
|
|
1243
1277
|
GetCompanyUpcomingInvoiceResponseFromJSON: () => GetCompanyUpcomingInvoiceResponseFromJSON,
|
|
1244
1278
|
GetCompanyUpcomingInvoiceResponseFromJSONTyped: () => GetCompanyUpcomingInvoiceResponseFromJSONTyped,
|
|
1245
1279
|
GetCompanyUpcomingInvoiceResponseToJSON: () => GetCompanyUpcomingInvoiceResponseToJSON,
|
|
@@ -1249,15 +1283,42 @@ __export2(models_exports, {
|
|
|
1249
1283
|
InvoiceStatusFromJSONTyped: () => InvoiceStatusFromJSONTyped,
|
|
1250
1284
|
InvoiceStatusToJSON: () => InvoiceStatusToJSON,
|
|
1251
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,
|
|
1252
1302
|
instanceOfApiError: () => instanceOfApiError,
|
|
1303
|
+
instanceOfBillingProviderType: () => instanceOfBillingProviderType,
|
|
1253
1304
|
instanceOfCompanyDiscountResponseData: () => instanceOfCompanyDiscountResponseData,
|
|
1254
1305
|
instanceOfCompanyInvoiceResponseData: () => instanceOfCompanyInvoiceResponseData,
|
|
1255
1306
|
instanceOfCompanyInvoicesResponseData: () => instanceOfCompanyInvoicesResponseData,
|
|
1307
|
+
instanceOfCompanyPaymentMethodResponseData: () => instanceOfCompanyPaymentMethodResponseData,
|
|
1308
|
+
instanceOfCompanyPaymentMethodsResponseData: () => instanceOfCompanyPaymentMethodsResponseData,
|
|
1256
1309
|
instanceOfCompanyUpcomingInvoiceResponseData: () => instanceOfCompanyUpcomingInvoiceResponseData,
|
|
1310
|
+
instanceOfCreateSetupIntentResponse: () => instanceOfCreateSetupIntentResponse,
|
|
1311
|
+
instanceOfDeletePaymentMethodResponse: () => instanceOfDeletePaymentMethodResponse,
|
|
1312
|
+
instanceOfDeleteResponse: () => instanceOfDeleteResponse,
|
|
1257
1313
|
instanceOfGetCompanyInvoicesParams: () => instanceOfGetCompanyInvoicesParams,
|
|
1258
1314
|
instanceOfGetCompanyInvoicesResponse: () => instanceOfGetCompanyInvoicesResponse,
|
|
1315
|
+
instanceOfGetCompanyPaymentMethodsResponse: () => instanceOfGetCompanyPaymentMethodsResponse,
|
|
1259
1316
|
instanceOfGetCompanyUpcomingInvoiceResponse: () => instanceOfGetCompanyUpcomingInvoiceResponse,
|
|
1260
|
-
instanceOfInvoiceStatus: () => instanceOfInvoiceStatus
|
|
1317
|
+
instanceOfInvoiceStatus: () => instanceOfInvoiceStatus,
|
|
1318
|
+
instanceOfPaymentMethodResponseData: () => instanceOfPaymentMethodResponseData,
|
|
1319
|
+
instanceOfSetupIntentResponseData: () => instanceOfSetupIntentResponseData,
|
|
1320
|
+
instanceOfUpdatePaymentMethodRequestBody: () => instanceOfUpdatePaymentMethodRequestBody,
|
|
1321
|
+
instanceOfUpdatePaymentMethodResponse: () => instanceOfUpdatePaymentMethodResponse
|
|
1261
1322
|
});
|
|
1262
1323
|
function instanceOfApiError(value) {
|
|
1263
1324
|
if (!("error" in value) || value["error"] === void 0) return false;
|
|
@@ -1285,6 +1346,34 @@ function ApiErrorToJSONTyped(value, ignoreDiscriminator = false) {
|
|
|
1285
1346
|
error: value["error"]
|
|
1286
1347
|
};
|
|
1287
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
|
+
}
|
|
1288
1377
|
function instanceOfCompanyDiscountResponseData(value) {
|
|
1289
1378
|
if (!("couponName" in value) || value["couponName"] === void 0)
|
|
1290
1379
|
return false;
|
|
@@ -1428,6 +1517,97 @@ function CompanyInvoicesResponseDataToJSONTyped(value, ignoreDiscriminator = fal
|
|
|
1428
1517
|
)
|
|
1429
1518
|
};
|
|
1430
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
|
+
}
|
|
1431
1611
|
function instanceOfCompanyUpcomingInvoiceResponseData(value) {
|
|
1432
1612
|
if (!("amountDue" in value) || value["amountDue"] === void 0) return false;
|
|
1433
1613
|
if (!("currency" in value) || value["currency"] === void 0) return false;
|
|
@@ -1477,6 +1657,122 @@ function CompanyUpcomingInvoiceResponseDataToJSONTyped(value, ignoreDiscriminato
|
|
|
1477
1657
|
subtotal: value["subtotal"]
|
|
1478
1658
|
};
|
|
1479
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
|
+
}
|
|
1480
1776
|
function instanceOfGetCompanyInvoicesParams(value) {
|
|
1481
1777
|
return true;
|
|
1482
1778
|
}
|
|
@@ -1535,6 +1831,35 @@ function GetCompanyInvoicesResponseToJSONTyped(value, ignoreDiscriminator = fals
|
|
|
1535
1831
|
params: GetCompanyInvoicesParamsToJSON(value["params"])
|
|
1536
1832
|
};
|
|
1537
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
|
+
}
|
|
1538
1863
|
function instanceOfGetCompanyUpcomingInvoiceResponse(value) {
|
|
1539
1864
|
if (!("data" in value) || value["data"] === void 0) return false;
|
|
1540
1865
|
if (!("params" in value) || value["params"] === void 0) return false;
|
|
@@ -1564,6 +1889,134 @@ function GetCompanyUpcomingInvoiceResponseToJSONTyped(value, ignoreDiscriminator
|
|
|
1564
1889
|
params: value["params"]
|
|
1565
1890
|
};
|
|
1566
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
|
+
}
|
|
1567
2020
|
var DEFAULT_INVOICE_QUERY = {};
|
|
1568
2021
|
function normalizeInvoiceQuery(query) {
|
|
1569
2022
|
const { includePending, ...rest } = query;
|
|
@@ -1888,6 +2341,39 @@ var SchematicBillingClient = class {
|
|
|
1888
2341
|
return GetCompanyUpcomingInvoiceResponseFromJSON(body).data;
|
|
1889
2342
|
});
|
|
1890
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
|
+
}
|
|
1891
2377
|
};
|
|
1892
2378
|
var anonymousIdKey = "schematicId";
|
|
1893
2379
|
var flagStateCachePrefix = "schematicCache";
|
|
@@ -3996,33 +4482,48 @@ var BillingStore = class {
|
|
|
3996
4482
|
constructor(_client, initialData = {}, options = {}) {
|
|
3997
4483
|
this._client = _client;
|
|
3998
4484
|
this._pageSize = options.pageSize ?? INVOICE_PAGE_SIZE;
|
|
4485
|
+
const readiness = () => this._connected ? READINESS[this._client.sessionStatus] : "waiting";
|
|
3999
4486
|
this.invoices = new KeyedResource(
|
|
4000
4487
|
(query, current) => this._reloadWindow(
|
|
4001
4488
|
query,
|
|
4002
4489
|
Math.max(this._pageSize, current?.invoices.length ?? 0)
|
|
4003
4490
|
),
|
|
4004
|
-
|
|
4005
|
-
// pending, and one that has ended settles empty rather than recording
|
|
4006
|
-
// the client's refusal as an error.
|
|
4007
|
-
{
|
|
4008
|
-
readiness: () => this._connected ? READINESS[this._client.sessionStatus] : "waiting"
|
|
4009
|
-
}
|
|
4491
|
+
{ readiness }
|
|
4010
4492
|
);
|
|
4493
|
+
this.upcomingInvoice = new KeyedResource(
|
|
4494
|
+
() => this._client.fetchUpcomingInvoice(),
|
|
4495
|
+
{ readiness }
|
|
4496
|
+
);
|
|
4497
|
+
this.paymentMethods = new KeyedResource(
|
|
4498
|
+
() => this._client.fetchPaymentMethods(),
|
|
4499
|
+
{ readiness }
|
|
4500
|
+
);
|
|
4501
|
+
const held = { key: initialData.sessionKey };
|
|
4011
4502
|
if (initialData.invoices !== void 0) {
|
|
4012
|
-
|
|
4503
|
+
held.invoices = {
|
|
4013
4504
|
// Normalized the way the hook normalizes, or the caller asking for
|
|
4014
4505
|
// it fetches the same page again.
|
|
4015
4506
|
params: normalizeInvoiceQuery2(
|
|
4016
4507
|
initialData.params?.invoices ?? DEFAULT_INVOICE_QUERY
|
|
4017
4508
|
),
|
|
4018
|
-
data: initialData.invoices
|
|
4019
|
-
key: initialData.sessionKey
|
|
4509
|
+
data: initialData.invoices
|
|
4020
4510
|
};
|
|
4511
|
+
}
|
|
4512
|
+
if (initialData.upcomingInvoice !== void 0) {
|
|
4513
|
+
held.upcomingInvoice = initialData.upcomingInvoice;
|
|
4514
|
+
}
|
|
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) {
|
|
4519
|
+
this._held = held;
|
|
4021
4520
|
this._settleSeed(claimFrom(options.session) ?? claimOf(this._client));
|
|
4022
4521
|
}
|
|
4023
4522
|
}
|
|
4024
4523
|
_client;
|
|
4025
4524
|
invoices;
|
|
4525
|
+
upcomingInvoice;
|
|
4526
|
+
paymentMethods;
|
|
4026
4527
|
_pageSize;
|
|
4027
4528
|
_unsubscribe;
|
|
4028
4529
|
_connected = false;
|
|
@@ -4092,7 +4593,15 @@ var BillingStore = class {
|
|
|
4092
4593
|
}
|
|
4093
4594
|
this._held = void 0;
|
|
4094
4595
|
if (verdict === "adopt") {
|
|
4095
|
-
|
|
4596
|
+
if (held.invoices !== void 0) {
|
|
4597
|
+
this.invoices.seed(held.invoices.params, held.invoices.data);
|
|
4598
|
+
}
|
|
4599
|
+
if (held.upcomingInvoice !== void 0) {
|
|
4600
|
+
this.upcomingInvoice.seed(SINGLETON, held.upcomingInvoice);
|
|
4601
|
+
}
|
|
4602
|
+
if (held.paymentMethods !== void 0) {
|
|
4603
|
+
this.paymentMethods.seed(SINGLETON, held.paymentMethods);
|
|
4604
|
+
}
|
|
4096
4605
|
this._seedKey = held.key;
|
|
4097
4606
|
this._seeded = true;
|
|
4098
4607
|
}
|
|
@@ -4154,9 +4663,46 @@ var BillingStore = class {
|
|
|
4154
4663
|
};
|
|
4155
4664
|
});
|
|
4156
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
|
+
}
|
|
4157
4689
|
dispose() {
|
|
4158
4690
|
this._unsubscribe?.();
|
|
4159
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
|
+
}
|
|
4160
4706
|
/**
|
|
4161
4707
|
* Re-reads the window already loaded, in as many requests as the API's
|
|
4162
4708
|
* page cap needs. A window paged past that cap still comes back whole:
|
|
@@ -4194,7 +4740,11 @@ var BillingStore = class {
|
|
|
4194
4740
|
return this._client.fetchInvoices({ ...query, limit, offset });
|
|
4195
4741
|
}
|
|
4196
4742
|
};
|
|
4197
|
-
var RESOURCE_NAMES = [
|
|
4743
|
+
var RESOURCE_NAMES = [
|
|
4744
|
+
"invoices",
|
|
4745
|
+
"upcomingInvoice",
|
|
4746
|
+
"paymentMethods"
|
|
4747
|
+
];
|
|
4198
4748
|
|
|
4199
4749
|
// src/billing/context.tsx
|
|
4200
4750
|
var import_react2 = require("react");
|
|
@@ -4243,6 +4793,25 @@ var BillingDataContext = (0, import_react2.createContext)(
|
|
|
4243
4793
|
);
|
|
4244
4794
|
var MISSING_BILLING_SOURCE_MESSAGE = "Schematic billing hooks need a SchematicProvider with a session, billingClient, or initialData, or a BillingDataProvider.";
|
|
4245
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
|
+
}
|
|
4246
4815
|
var missingHandle = {
|
|
4247
4816
|
data: void 0,
|
|
4248
4817
|
error: missingSourceError,
|
|
@@ -4256,12 +4825,16 @@ var missingBillingSource = {
|
|
|
4256
4825
|
handle: () => missingHandle,
|
|
4257
4826
|
loadMoreInvoices: () => Promise.resolve(),
|
|
4258
4827
|
invalidateAll: () => {
|
|
4259
|
-
}
|
|
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)
|
|
4260
4832
|
};
|
|
4261
4833
|
function useBillingDataSource() {
|
|
4262
4834
|
return (0, import_react2.useContext)(BillingDataContext) ?? missingBillingSource;
|
|
4263
4835
|
}
|
|
4264
4836
|
function BillingDataProvider({
|
|
4837
|
+
actions,
|
|
4265
4838
|
children,
|
|
4266
4839
|
data,
|
|
4267
4840
|
locale,
|
|
@@ -4275,6 +4848,10 @@ function BillingDataProvider({
|
|
|
4275
4848
|
const source = (0, import_react2.useMemo)(() => {
|
|
4276
4849
|
const handles = /* @__PURE__ */ new Map();
|
|
4277
4850
|
return {
|
|
4851
|
+
actions: rejectingActions(
|
|
4852
|
+
(name) => new Error(BILLING_ACTION_UNAVAILABLE_MESSAGE(name)),
|
|
4853
|
+
actions
|
|
4854
|
+
),
|
|
4278
4855
|
subscribe: () => () => {
|
|
4279
4856
|
},
|
|
4280
4857
|
handle: (name) => {
|
|
@@ -4300,7 +4877,7 @@ function BillingDataProvider({
|
|
|
4300
4877
|
invalidateAll: () => {
|
|
4301
4878
|
}
|
|
4302
4879
|
};
|
|
4303
|
-
}, [data, onLoadMoreInvoices, onRefetch, status]);
|
|
4880
|
+
}, [actions, data, onLoadMoreInvoices, onRefetch, status]);
|
|
4304
4881
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BillingDataContext.Provider, { value: source, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
4305
4882
|
SchematicI18nProvider,
|
|
4306
4883
|
{
|
|
@@ -4345,6 +4922,51 @@ function useInvoices(query = DEFAULT_INVOICE_QUERY) {
|
|
|
4345
4922
|
);
|
|
4346
4923
|
return (0, import_react3.useMemo)(() => ({ ...handle, loadMore }), [handle, loadMore]);
|
|
4347
4924
|
}
|
|
4925
|
+
function useUpcomingInvoice() {
|
|
4926
|
+
return useBillingResource("upcomingInvoice", SINGLETON);
|
|
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
|
+
}
|
|
4348
4970
|
function useInvalidateBillingData() {
|
|
4349
4971
|
return useBillingDataSource().invalidateAll;
|
|
4350
4972
|
}
|
|
@@ -4418,7 +5040,12 @@ function BillingProvider({
|
|
|
4418
5040
|
subscribe: (name, params, listener) => store.resource(name).subscribe(params, listener),
|
|
4419
5041
|
handle,
|
|
4420
5042
|
loadMoreInvoices: (query) => store.loadMoreInvoices(query),
|
|
4421
|
-
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
|
+
}
|
|
4422
5049
|
};
|
|
4423
5050
|
}, [store]);
|
|
4424
5051
|
const localized = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
@@ -4464,7 +5091,7 @@ function staticSource(data) {
|
|
|
4464
5091
|
}
|
|
4465
5092
|
|
|
4466
5093
|
// src/version.ts
|
|
4467
|
-
var version2 = "1.
|
|
5094
|
+
var version2 = "1.9.0";
|
|
4468
5095
|
|
|
4469
5096
|
// src/context/schematic.tsx
|
|
4470
5097
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|