@meterbox/customer-portal 0.1.7 → 0.1.8

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/README.md CHANGED
@@ -45,6 +45,8 @@ override it.
45
45
  ## Pages
46
46
 
47
47
  - **Account**: name, email, current plan, status (`GET /v1/customer-portal/:id/me`),
48
+ a button to update the payment method and billing details on Stripe's own
49
+ portal (`<BillingDetailsButton>`, when available),
48
50
  and **Cancel subscription**: the customer gives a reason, sees your plan's
49
51
  retention offers (a discount, a longer trial, or a downgrade) and either takes
50
52
  one or cancels at the end of the period, keeping access until then
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meterbox/customer-portal",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Drop-in multi-page React customer portal for Meterbox: Account, Plans, Credits. Built on @meterbox/react.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://meterbox.ai",
@@ -17,7 +17,7 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@meterbox/react": "0.1.5"
20
+ "@meterbox/react": "0.1.6"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "react": ">=17",
@@ -1,11 +1,13 @@
1
1
  /**
2
2
  * <AccountPage /> — fetches GET /v1/customer-portal/:id/me and renders the
3
- * customer's own profile + current plan, the way to cancel, and their
4
- * invoices with PDFs (`<InvoiceHistory>` from @meterbox/react).
3
+ * customer's own profile + current plan, a button to update their payment
4
+ * method and billing details on Stripe's portal (when available), the way to
5
+ * cancel, and their invoices with PDFs (`<InvoiceHistory>` from
6
+ * @meterbox/react).
5
7
  */
6
8
 
7
9
  const React = require("react");
8
- const { InvoiceHistory, theme } = require("@meterbox/react");
10
+ const { InvoiceHistory, BillingDetailsButton, theme } = require("@meterbox/react");
9
11
  const CancelSubscription = require("../CancelSubscription");
10
12
 
11
13
  const styles = {
@@ -56,6 +58,7 @@ function AccountPage({ baseUrl, customerId, customerToken, fetch: fetchImpl }) {
56
58
  const [me, setMe] = React.useState(null);
57
59
  const [error, setError] = React.useState(null);
58
60
  const [loading, setLoading] = React.useState(true);
61
+ const [billingError, setBillingError] = React.useState(null);
59
62
  // Bumped after a cancellation step, to show the new status.
60
63
  const [version, setVersion] = React.useState(0);
61
64
  const reload = React.useCallback(() => setVersion((v) => v + 1), []);
@@ -151,6 +154,16 @@ function AccountPage({ baseUrl, customerId, customerToken, fetch: fetchImpl }) {
151
154
  React.createElement("span", { style: styles.label }, "Ends on"),
152
155
  React.createElement("span", { style: styles.value }, String(me.cancel_at).slice(0, 10)),
153
156
  ),
157
+ me.billing_details_available &&
158
+ React.createElement(BillingDetailsButton, {
159
+ baseUrl,
160
+ customerId,
161
+ customerToken,
162
+ fetch: fetchImpl,
163
+ onError: (err) => setBillingError(err.message),
164
+ }),
165
+ billingError &&
166
+ React.createElement("span", { role: "alert", style: { color: "#dc2626" } }, billingError),
154
167
  );
155
168
  return React.createElement(
156
169
  "div",