@bunnyapp/components 1.0.28 → 1.0.31
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/cjs/index.js +55 -46
- package/dist/cjs/src/components/PaymentForm/PaymentForm.d.ts +2 -1
- package/dist/cjs/src/types/billingDetails.d.ts +2 -0
- package/dist/esm/index.js +56 -47
- package/dist/esm/src/components/PaymentForm/PaymentForm.d.ts +2 -1
- package/dist/esm/src/types/billingDetails.d.ts +2 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -2742,12 +2742,14 @@ function useRemovePaymentMethod(paymentPlugins, token, apiHost, entityId, accoun
|
|
|
2742
2742
|
var Panel = antd.Collapse.Panel;
|
|
2743
2743
|
var PaymentForm = function (_a) {
|
|
2744
2744
|
var _b;
|
|
2745
|
-
var entityId = _a.entityId, invoice = _a.invoice, onFail = _a.onFail, onPaymentSuccess = _a.onPaymentSuccess, quote = _a.quote, accountId = _a.accountId, onSavePaymentMethod = _a.onSavePaymentMethod, overrideToken = _a.overrideToken, graphQLClient = _a.graphQLClient, customCheckoutFunction = _a.customCheckoutFunction;
|
|
2745
|
+
var entityId = _a.entityId, invoice = _a.invoice, onFail = _a.onFail, onPaymentSuccess = _a.onPaymentSuccess, quote = _a.quote, accountId = _a.accountId, onSavePaymentMethod = _a.onSavePaymentMethod, overrideToken = _a.overrideToken, graphQLClient = _a.graphQLClient, customCheckoutFunction = _a.customCheckoutFunction, currencyIdFromProps = _a.currencyId;
|
|
2746
2746
|
// Local state
|
|
2747
2747
|
var _c = React.useState(), selectedPaymentMethod = _c[0], setSelectedPaymentMethod = _c[1];
|
|
2748
2748
|
var _d = React.useState(false), showPaymentMethodForm = _d[0], setShowPaymentMethodForm = _d[1];
|
|
2749
2749
|
var paying = !!(quote || invoice);
|
|
2750
|
-
var currencyId = (_b = ((quote === null || quote === void 0 ? void 0 : quote.currencyId) ||
|
|
2750
|
+
var currencyId = (_b = ((quote === null || quote === void 0 ? void 0 : quote.currencyId) ||
|
|
2751
|
+
(invoice === null || invoice === void 0 ? void 0 : invoice.currencyId) ||
|
|
2752
|
+
currencyIdFromProps)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
2751
2753
|
// Hooks
|
|
2752
2754
|
var apiHost = React.useContext(BunnyContext).apiHost;
|
|
2753
2755
|
var token = useToken();
|
|
@@ -2794,9 +2796,6 @@ var PaymentForm = function (_a) {
|
|
|
2794
2796
|
onSavePaymentMethod === null || onSavePaymentMethod === void 0 ? void 0 : onSavePaymentMethod();
|
|
2795
2797
|
setShowPaymentMethodForm(false);
|
|
2796
2798
|
};
|
|
2797
|
-
if (!currencyId) {
|
|
2798
|
-
return jsxRuntime.jsx("div", { children: "No currency id found from quote or invoice" });
|
|
2799
|
-
}
|
|
2800
2799
|
return (jsxRuntime.jsx(PaymentContext.Provider, __assign({ value: {
|
|
2801
2800
|
onClickCancel: function () { return setShowPaymentMethodForm(false); },
|
|
2802
2801
|
accountId: accountId,
|
|
@@ -2811,7 +2810,7 @@ var PaymentForm = function (_a) {
|
|
|
2811
2810
|
};
|
|
2812
2811
|
function StripeWrapper(_a) {
|
|
2813
2812
|
var children = _a.children, plugin = _a.plugin, token = _a.token, apiHost = _a.apiHost, currencyId = _a.currencyId, accountId = _a.accountId;
|
|
2814
|
-
var _b = useStripePlugin(plugin, token, apiHost, currencyId, accountId), stripe = _b.stripe, options = _b.options;
|
|
2813
|
+
var _b = useStripePlugin(plugin, token, apiHost, currencyId || "usd", accountId), stripe = _b.stripe, options = _b.options;
|
|
2815
2814
|
return (jsxRuntime.jsx(reactStripeJs.Elements, __assign({ options: options, stripe: stripe }, { children: children })));
|
|
2816
2815
|
}
|
|
2817
2816
|
|
|
@@ -3639,9 +3638,37 @@ var DrawerHeader = function (_a) {
|
|
|
3639
3638
|
return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-4" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "flex items-center justify-between gap-2" }, { children: [jsxRuntime.jsx(Text$5, __assign({ className: "text-xl", style: { fontWeight: 400 } }, { children: title })), jsxRuntime.jsx("button", __assign({ onClick: onClose, className: "ant-drawer-close" }, { children: jsxRuntime.jsx(CloseOutlined$1, {}) }))] })), description && jsxRuntime.jsx("div", __assign({ className: "text-xs" }, { children: description }))] })));
|
|
3640
3639
|
};
|
|
3641
3640
|
|
|
3641
|
+
// TODO: move this to common
|
|
3642
|
+
var billingDetailsQuery = function () {
|
|
3643
|
+
return "\nquery BillingDetails {\n billingDetails {\n billingCity\n billingContact {\n email\n }\n billingCountry\n billingState\n billingStreet\n billingZip\n name\n taxNumber\n currency {\n id\n }\n }\n}";
|
|
3644
|
+
};
|
|
3645
|
+
var getBillingDetails = function (_a) {
|
|
3646
|
+
var token = _a.token, apiHost = _a.apiHost;
|
|
3647
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
3648
|
+
var response;
|
|
3649
|
+
var _b;
|
|
3650
|
+
return __generator(this, function (_c) {
|
|
3651
|
+
switch (_c.label) {
|
|
3652
|
+
case 0: return [4 /*yield*/, common.gqlRequest({
|
|
3653
|
+
query: billingDetailsQuery(),
|
|
3654
|
+
token: token,
|
|
3655
|
+
apiHost: apiHost,
|
|
3656
|
+
})];
|
|
3657
|
+
case 1:
|
|
3658
|
+
response = _c.sent();
|
|
3659
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
|
3660
|
+
throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
|
|
3661
|
+
}
|
|
3662
|
+
return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
|
|
3663
|
+
}
|
|
3664
|
+
});
|
|
3665
|
+
});
|
|
3666
|
+
};
|
|
3667
|
+
|
|
3642
3668
|
var PaymentMethod = function (_a) {
|
|
3643
|
-
var
|
|
3644
|
-
var
|
|
3669
|
+
var _b;
|
|
3670
|
+
var entityId = _a.entityId, className = _a.className, _c = _a.shadow, shadow = _c === void 0 ? "shadow-md" : _c, _d = _a.cardEnabled, cardEnabled = _d === void 0 ? true : _d;
|
|
3671
|
+
var _e = React.useContext(BunnyContext), apiHost = _e.apiHost, graphQLClient = _e.graphQLClient, onTokenExpired = _e.onTokenExpired;
|
|
3645
3672
|
var token = useToken();
|
|
3646
3673
|
// Hooks
|
|
3647
3674
|
var queryClient = reactQuery.useQueryClient();
|
|
@@ -3651,8 +3678,13 @@ var PaymentMethod = function (_a) {
|
|
|
3651
3678
|
var isMobile = common.useIsMobile();
|
|
3652
3679
|
var data = usePaymentMethod(graphQLClient, entityId, token).data;
|
|
3653
3680
|
var onClickRemove = useRemovePaymentMethod(paymentPlugins || [], token, apiHost, entityId);
|
|
3681
|
+
// Queries
|
|
3682
|
+
var _f = reactQuery.useQuery({
|
|
3683
|
+
queryKey: common.QueryKeyFactory.default.billingDetailsKey(token, entityId),
|
|
3684
|
+
queryFn: function () { return getBillingDetails({ token: token, apiHost: apiHost }); },
|
|
3685
|
+
}), billingDetails = _f.data; _f.isLoading;
|
|
3654
3686
|
// Local state
|
|
3655
|
-
var
|
|
3687
|
+
var _g = React.useState(false), showModal = _g[0], setShowModal = _g[1];
|
|
3656
3688
|
var onSuccess = function () {
|
|
3657
3689
|
queryClient.invalidateQueries({
|
|
3658
3690
|
queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
|
|
@@ -3681,7 +3713,7 @@ var PaymentMethod = function (_a) {
|
|
|
3681
3713
|
handleAllErrorFormats(error);
|
|
3682
3714
|
}, onPaymentSuccess: function () {
|
|
3683
3715
|
onSuccess();
|
|
3684
|
-
}, graphQLClient: graphQLClient }) }))] })));
|
|
3716
|
+
}, graphQLClient: graphQLClient, currencyId: (_b = billingDetails === null || billingDetails === void 0 ? void 0 : billingDetails.currency) === null || _b === void 0 ? void 0 : _b.id }) }))] })));
|
|
3685
3717
|
};
|
|
3686
3718
|
|
|
3687
3719
|
var pageWrapperClassName = function (isMobile) {
|
|
@@ -4572,9 +4604,11 @@ var SubscriptionChargeTotal = function (_a) {
|
|
|
4572
4604
|
var currencyId = subscription.currencyId;
|
|
4573
4605
|
var formattedDiscountedPrice = common.formatCurrency(charge.price, currencyId);
|
|
4574
4606
|
var formattedPeriodPrice = common.formatCurrency(charge.periodPrice, currencyId);
|
|
4575
|
-
return (jsxRuntime.jsx("div", __assign({ className: "flex gap-1 ".concat(isMobile ? "flex-col" : "") }, { children: charge.
|
|
4576
|
-
? "-"
|
|
4577
|
-
:
|
|
4607
|
+
return (jsxRuntime.jsx("div", __assign({ className: "flex gap-1 ".concat(isMobile ? "flex-col" : "") }, { children: charge.chargeType === common.ChargeType.USAGE || charge.trial
|
|
4608
|
+
? "-"
|
|
4609
|
+
: charge.kind === common.SubscriptionChargeKind.DISCOUNT
|
|
4610
|
+
? "-".concat(formattedDiscountedPrice, " ").concat(billingPeriod)
|
|
4611
|
+
: "".concat(formattedPeriodPrice, " ").concat(billingPeriod) })));
|
|
4578
4612
|
};
|
|
4579
4613
|
|
|
4580
4614
|
var SubscriptionChargeUnitPrice = function (_a) {
|
|
@@ -4585,19 +4619,21 @@ var SubscriptionChargeUnitPrice = function (_a) {
|
|
|
4585
4619
|
var isDiscount = (charge === null || charge === void 0 ? void 0 : charge.kind) === common.SubscriptionChargeKind.DISCOUNT;
|
|
4586
4620
|
if (displayPriceTiers)
|
|
4587
4621
|
return (jsxRuntime.jsx(antd.Dropdown, __assign({ dropdownRender: function () {
|
|
4588
|
-
var _a
|
|
4622
|
+
var _a;
|
|
4589
4623
|
return (jsxRuntime.jsx("div", __assign({ className: "flex flex-col rounded border border-solid border-slate-200 p-2", style: {
|
|
4590
4624
|
backgroundColor: darkMode
|
|
4591
4625
|
? "var(--row-background-dark)"
|
|
4592
4626
|
: "var(--row-background)",
|
|
4593
|
-
} }, { children: jsxRuntime.jsx("div", __assign({ className: "grid grid-cols-2", style: { columnGap: "0.5rem" } }, { children: (
|
|
4594
|
-
var _a, _b, _c
|
|
4595
|
-
var ends = ((
|
|
4596
|
-
? ((
|
|
4627
|
+
} }, { children: jsxRuntime.jsx("div", __assign({ className: "grid grid-cols-2", style: { columnGap: "0.5rem" } }, { children: (_a = charge.priceTiers) === null || _a === void 0 ? void 0 : _a.map(function (tier, index) {
|
|
4628
|
+
var _a, _b, _c;
|
|
4629
|
+
var ends = ((_b = (_a = charge.priceTiers) === null || _a === void 0 ? void 0 : _a[index + 1]) === null || _b === void 0 ? void 0 : _b.starts)
|
|
4630
|
+
? ((_c = charge.priceTiers[index + 1]) === null || _c === void 0 ? void 0 : _c.starts) - 1
|
|
4597
4631
|
: "∞";
|
|
4598
|
-
return (jsxRuntime.jsxs("div", __assign({ className: "contents" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "whitespace-nowrap" }, { children: [tier.starts.toLocaleString(), " - ", ends.toLocaleString(), "
|
|
4632
|
+
return (jsxRuntime.jsxs("div", __assign({ className: "contents" }, { children: [jsxRuntime.jsxs("div", __assign({ className: "whitespace-nowrap" }, { children: [tier.starts.toLocaleString(), " - ", ends.toLocaleString(), " :"] })), jsxRuntime.jsx("div", __assign({ className: "whitespace-nowrap text-right" }, { children: common.formatCurrency(tier.price, subscription.currencyId, charge.priceDecimals) }))] }), index));
|
|
4599
4633
|
}) })) })));
|
|
4600
4634
|
}, onOpenChange: setShowPriceTiers, open: showPriceTiers, trigger: ["click"] }, { children: jsxRuntime.jsx("div", __assign({ className: "cursor-pointer underline", onClick: function () { return setShowPriceTiers(!showPriceTiers); } }, { children: showPriceTiers ? "Hide tiers" : "Show tiers" })) })));
|
|
4635
|
+
else if (charge.chargeType === common.ChargeType.USAGE || charge.trial)
|
|
4636
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: "-" });
|
|
4601
4637
|
else if (isDiscount)
|
|
4602
4638
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: ["-", common.formatCurrency(charge.discountedPrice, subscription.currencyId)] }));
|
|
4603
4639
|
else
|
|
@@ -4834,33 +4870,6 @@ var billingDetailsUpdate = function (_a) {
|
|
|
4834
4870
|
});
|
|
4835
4871
|
};
|
|
4836
4872
|
|
|
4837
|
-
// TODO: move this to common
|
|
4838
|
-
var billingDetailsQuery = function () {
|
|
4839
|
-
return "\nquery BillingDetails {\n billingDetails {\n billingCity\n billingContact {\n email\n }\n billingCountry\n billingState\n billingStreet\n billingZip\n name\n taxNumber\n }\n}";
|
|
4840
|
-
};
|
|
4841
|
-
var getBillingDetails = function (_a) {
|
|
4842
|
-
var token = _a.token, apiHost = _a.apiHost;
|
|
4843
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
4844
|
-
var response;
|
|
4845
|
-
var _b;
|
|
4846
|
-
return __generator(this, function (_c) {
|
|
4847
|
-
switch (_c.label) {
|
|
4848
|
-
case 0: return [4 /*yield*/, common.gqlRequest({
|
|
4849
|
-
query: billingDetailsQuery(),
|
|
4850
|
-
token: token,
|
|
4851
|
-
apiHost: apiHost,
|
|
4852
|
-
})];
|
|
4853
|
-
case 1:
|
|
4854
|
-
response = _c.sent();
|
|
4855
|
-
if (response === null || response === void 0 ? void 0 : response.errors) {
|
|
4856
|
-
throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
|
|
4857
|
-
}
|
|
4858
|
-
return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
|
|
4859
|
-
}
|
|
4860
|
-
});
|
|
4861
|
-
});
|
|
4862
|
-
};
|
|
4863
|
-
|
|
4864
4873
|
var BillingDetails = function (_a) {
|
|
4865
4874
|
var entityId = _a.entityId, _b = _a.isCardEnabled, isCardEnabled = _b === void 0 ? true : _b, _c = _a.shadow, shadow = _c === void 0 ? "shadow-md" : _c, className = _a.className, hidePaymentMethodForm = _a.hidePaymentMethodForm, countryListFilter = _a.countryListFilter;
|
|
4866
4875
|
var _d = React.useContext(BunnyContext), apiHost = _d.apiHost, onTokenExpired = _d.onTokenExpired, graphQLClient = _d.graphQLClient;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormattedInvoice, PluginData, Quote } from "@bunnyapp/common";
|
|
2
2
|
import { GraphQLClient } from "graphql-request";
|
|
3
|
-
export declare const PaymentForm: ({ entityId, invoice, onFail, onPaymentSuccess, quote, accountId, onSavePaymentMethod, overrideToken, graphQLClient, customCheckoutFunction, }: {
|
|
3
|
+
export declare const PaymentForm: ({ entityId, invoice, onFail, onPaymentSuccess, quote, accountId, onSavePaymentMethod, overrideToken, graphQLClient, customCheckoutFunction, currencyId: currencyIdFromProps, }: {
|
|
4
4
|
entityId: string;
|
|
5
5
|
invoice?: FormattedInvoice | undefined;
|
|
6
6
|
quote?: Quote | undefined;
|
|
@@ -11,4 +11,5 @@ export declare const PaymentForm: ({ entityId, invoice, onFail, onPaymentSuccess
|
|
|
11
11
|
overrideToken?: string | undefined;
|
|
12
12
|
graphQLClient: GraphQLClient;
|
|
13
13
|
customCheckoutFunction?: ((plugin: PluginData | undefined) => Promise<any>) | undefined;
|
|
14
|
+
currencyId?: string | undefined;
|
|
14
15
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Currency } from "@bunnyapp/common";
|
|
1
2
|
export default interface BillingDetails {
|
|
2
3
|
name?: string;
|
|
3
4
|
billingCity?: string;
|
|
@@ -9,4 +10,5 @@ export default interface BillingDetails {
|
|
|
9
10
|
billingStreet?: string;
|
|
10
11
|
billingZip?: string;
|
|
11
12
|
taxNumber?: string;
|
|
13
|
+
currency?: Currency;
|
|
12
14
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import React__default, { createContext, useContext, useEffect, useState, useMemo
|
|
|
4
4
|
import { Markup } from 'interweave';
|
|
5
5
|
import { ConfigProvider, Button, Typography, Tag, Divider, Popconfirm, Input, Checkbox, Collapse, Modal, Form, Drawer, Card as Card$1, Select, Image, Dropdown, Skeleton } from 'antd';
|
|
6
6
|
import styled from 'styled-components';
|
|
7
|
-
import { DEFAULT_ACCENT_COLOR, DEFAULT_BRAND_COLOR, DEFAULT_SECONDARY_COLOR, DEFAULT_TOP_NAV_IMAGE_URL, gqlRequest, QueryKeyFactory, useIsMobile, isColorTooDark, MARK_PRO, INPUT_BORDER_COLOR, SLATE_50, SLATE_400, SLATE_200, getPlugins, useAllErrorFormats, formatCurrency, invokePlugin, GRAY_500, GRAY_200, useErrorNotification, useSuccessNotification, getFormattedInvoice, PAYABLE_INVOICE_STATES, BreakpointNumbers, useGraphQLmutation, formatDate, FrontendTransaction, SLATE_600, WHITE, TransactionKind, Lists, getAccount, SubscriptionChargeKind, SubscriptionState as SubscriptionState$2, MODAL_MAX_HEIGHT, SLATE_500, StringUtils, DataInterval, TAG_COLORS,
|
|
7
|
+
import { DEFAULT_ACCENT_COLOR, DEFAULT_BRAND_COLOR, DEFAULT_SECONDARY_COLOR, DEFAULT_TOP_NAV_IMAGE_URL, gqlRequest, QueryKeyFactory, useIsMobile, isColorTooDark, MARK_PRO, INPUT_BORDER_COLOR, SLATE_50, SLATE_400, SLATE_200, getPlugins, useAllErrorFormats, formatCurrency, invokePlugin, GRAY_500, GRAY_200, useErrorNotification, useSuccessNotification, getFormattedInvoice, PAYABLE_INVOICE_STATES, BreakpointNumbers, useGraphQLmutation, formatDate, FrontendTransaction, SLATE_600, WHITE, TransactionKind, Lists, getAccount, SubscriptionChargeKind, SubscriptionState as SubscriptionState$2, MODAL_MAX_HEIGHT, SLATE_500, StringUtils, DataInterval, TAG_COLORS, ChargeType, PricingModel } from '@bunnyapp/common';
|
|
8
8
|
import { QueryClient, QueryClientProvider, useQuery, useQueryClient, keepPreviousData, useMutation } from '@tanstack/react-query';
|
|
9
9
|
import theme from 'antd/lib/theme';
|
|
10
10
|
import { RecoilRoot } from 'recoil';
|
|
@@ -2714,12 +2714,14 @@ function useRemovePaymentMethod(paymentPlugins, token, apiHost, entityId, accoun
|
|
|
2714
2714
|
var Panel = Collapse.Panel;
|
|
2715
2715
|
var PaymentForm = function (_a) {
|
|
2716
2716
|
var _b;
|
|
2717
|
-
var entityId = _a.entityId, invoice = _a.invoice, onFail = _a.onFail, onPaymentSuccess = _a.onPaymentSuccess, quote = _a.quote, accountId = _a.accountId, onSavePaymentMethod = _a.onSavePaymentMethod, overrideToken = _a.overrideToken, graphQLClient = _a.graphQLClient, customCheckoutFunction = _a.customCheckoutFunction;
|
|
2717
|
+
var entityId = _a.entityId, invoice = _a.invoice, onFail = _a.onFail, onPaymentSuccess = _a.onPaymentSuccess, quote = _a.quote, accountId = _a.accountId, onSavePaymentMethod = _a.onSavePaymentMethod, overrideToken = _a.overrideToken, graphQLClient = _a.graphQLClient, customCheckoutFunction = _a.customCheckoutFunction, currencyIdFromProps = _a.currencyId;
|
|
2718
2718
|
// Local state
|
|
2719
2719
|
var _c = useState(), selectedPaymentMethod = _c[0], setSelectedPaymentMethod = _c[1];
|
|
2720
2720
|
var _d = useState(false), showPaymentMethodForm = _d[0], setShowPaymentMethodForm = _d[1];
|
|
2721
2721
|
var paying = !!(quote || invoice);
|
|
2722
|
-
var currencyId = (_b = ((quote === null || quote === void 0 ? void 0 : quote.currencyId) ||
|
|
2722
|
+
var currencyId = (_b = ((quote === null || quote === void 0 ? void 0 : quote.currencyId) ||
|
|
2723
|
+
(invoice === null || invoice === void 0 ? void 0 : invoice.currencyId) ||
|
|
2724
|
+
currencyIdFromProps)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
2723
2725
|
// Hooks
|
|
2724
2726
|
var apiHost = useContext(BunnyContext).apiHost;
|
|
2725
2727
|
var token = useToken();
|
|
@@ -2766,9 +2768,6 @@ var PaymentForm = function (_a) {
|
|
|
2766
2768
|
onSavePaymentMethod === null || onSavePaymentMethod === void 0 ? void 0 : onSavePaymentMethod();
|
|
2767
2769
|
setShowPaymentMethodForm(false);
|
|
2768
2770
|
};
|
|
2769
|
-
if (!currencyId) {
|
|
2770
|
-
return jsx("div", { children: "No currency id found from quote or invoice" });
|
|
2771
|
-
}
|
|
2772
2771
|
return (jsx(PaymentContext.Provider, __assign({ value: {
|
|
2773
2772
|
onClickCancel: function () { return setShowPaymentMethodForm(false); },
|
|
2774
2773
|
accountId: accountId,
|
|
@@ -2783,7 +2782,7 @@ var PaymentForm = function (_a) {
|
|
|
2783
2782
|
};
|
|
2784
2783
|
function StripeWrapper(_a) {
|
|
2785
2784
|
var children = _a.children, plugin = _a.plugin, token = _a.token, apiHost = _a.apiHost, currencyId = _a.currencyId, accountId = _a.accountId;
|
|
2786
|
-
var _b = useStripePlugin(plugin, token, apiHost, currencyId, accountId), stripe = _b.stripe, options = _b.options;
|
|
2785
|
+
var _b = useStripePlugin(plugin, token, apiHost, currencyId || "usd", accountId), stripe = _b.stripe, options = _b.options;
|
|
2787
2786
|
return (jsx(Elements, __assign({ options: options, stripe: stripe }, { children: children })));
|
|
2788
2787
|
}
|
|
2789
2788
|
|
|
@@ -3611,9 +3610,37 @@ var DrawerHeader = function (_a) {
|
|
|
3611
3610
|
return (jsxs("div", __assign({ className: "flex flex-col gap-4" }, { children: [jsxs("div", __assign({ className: "flex items-center justify-between gap-2" }, { children: [jsx(Text$5, __assign({ className: "text-xl", style: { fontWeight: 400 } }, { children: title })), jsx("button", __assign({ onClick: onClose, className: "ant-drawer-close" }, { children: jsx(CloseOutlined$1, {}) }))] })), description && jsx("div", __assign({ className: "text-xs" }, { children: description }))] })));
|
|
3612
3611
|
};
|
|
3613
3612
|
|
|
3613
|
+
// TODO: move this to common
|
|
3614
|
+
var billingDetailsQuery = function () {
|
|
3615
|
+
return "\nquery BillingDetails {\n billingDetails {\n billingCity\n billingContact {\n email\n }\n billingCountry\n billingState\n billingStreet\n billingZip\n name\n taxNumber\n currency {\n id\n }\n }\n}";
|
|
3616
|
+
};
|
|
3617
|
+
var getBillingDetails = function (_a) {
|
|
3618
|
+
var token = _a.token, apiHost = _a.apiHost;
|
|
3619
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
3620
|
+
var response;
|
|
3621
|
+
var _b;
|
|
3622
|
+
return __generator(this, function (_c) {
|
|
3623
|
+
switch (_c.label) {
|
|
3624
|
+
case 0: return [4 /*yield*/, gqlRequest({
|
|
3625
|
+
query: billingDetailsQuery(),
|
|
3626
|
+
token: token,
|
|
3627
|
+
apiHost: apiHost,
|
|
3628
|
+
})];
|
|
3629
|
+
case 1:
|
|
3630
|
+
response = _c.sent();
|
|
3631
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
|
3632
|
+
throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
|
|
3633
|
+
}
|
|
3634
|
+
return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
|
|
3635
|
+
}
|
|
3636
|
+
});
|
|
3637
|
+
});
|
|
3638
|
+
};
|
|
3639
|
+
|
|
3614
3640
|
var PaymentMethod = function (_a) {
|
|
3615
|
-
var
|
|
3616
|
-
var
|
|
3641
|
+
var _b;
|
|
3642
|
+
var entityId = _a.entityId, className = _a.className, _c = _a.shadow, shadow = _c === void 0 ? "shadow-md" : _c, _d = _a.cardEnabled, cardEnabled = _d === void 0 ? true : _d;
|
|
3643
|
+
var _e = useContext(BunnyContext), apiHost = _e.apiHost, graphQLClient = _e.graphQLClient, onTokenExpired = _e.onTokenExpired;
|
|
3617
3644
|
var token = useToken();
|
|
3618
3645
|
// Hooks
|
|
3619
3646
|
var queryClient = useQueryClient();
|
|
@@ -3623,8 +3650,13 @@ var PaymentMethod = function (_a) {
|
|
|
3623
3650
|
var isMobile = useIsMobile();
|
|
3624
3651
|
var data = usePaymentMethod(graphQLClient, entityId, token).data;
|
|
3625
3652
|
var onClickRemove = useRemovePaymentMethod(paymentPlugins || [], token, apiHost, entityId);
|
|
3653
|
+
// Queries
|
|
3654
|
+
var _f = useQuery({
|
|
3655
|
+
queryKey: QueryKeyFactory.default.billingDetailsKey(token, entityId),
|
|
3656
|
+
queryFn: function () { return getBillingDetails({ token: token, apiHost: apiHost }); },
|
|
3657
|
+
}), billingDetails = _f.data; _f.isLoading;
|
|
3626
3658
|
// Local state
|
|
3627
|
-
var
|
|
3659
|
+
var _g = useState(false), showModal = _g[0], setShowModal = _g[1];
|
|
3628
3660
|
var onSuccess = function () {
|
|
3629
3661
|
queryClient.invalidateQueries({
|
|
3630
3662
|
queryKey: QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
|
|
@@ -3653,7 +3685,7 @@ var PaymentMethod = function (_a) {
|
|
|
3653
3685
|
handleAllErrorFormats(error);
|
|
3654
3686
|
}, onPaymentSuccess: function () {
|
|
3655
3687
|
onSuccess();
|
|
3656
|
-
}, graphQLClient: graphQLClient }) }))] })));
|
|
3688
|
+
}, graphQLClient: graphQLClient, currencyId: (_b = billingDetails === null || billingDetails === void 0 ? void 0 : billingDetails.currency) === null || _b === void 0 ? void 0 : _b.id }) }))] })));
|
|
3657
3689
|
};
|
|
3658
3690
|
|
|
3659
3691
|
var pageWrapperClassName = function (isMobile) {
|
|
@@ -4544,9 +4576,11 @@ var SubscriptionChargeTotal = function (_a) {
|
|
|
4544
4576
|
var currencyId = subscription.currencyId;
|
|
4545
4577
|
var formattedDiscountedPrice = formatCurrency(charge.price, currencyId);
|
|
4546
4578
|
var formattedPeriodPrice = formatCurrency(charge.periodPrice, currencyId);
|
|
4547
|
-
return (jsx("div", __assign({ className: "flex gap-1 ".concat(isMobile ? "flex-col" : "") }, { children: charge.
|
|
4548
|
-
? "-"
|
|
4549
|
-
:
|
|
4579
|
+
return (jsx("div", __assign({ className: "flex gap-1 ".concat(isMobile ? "flex-col" : "") }, { children: charge.chargeType === ChargeType.USAGE || charge.trial
|
|
4580
|
+
? "-"
|
|
4581
|
+
: charge.kind === SubscriptionChargeKind.DISCOUNT
|
|
4582
|
+
? "-".concat(formattedDiscountedPrice, " ").concat(billingPeriod)
|
|
4583
|
+
: "".concat(formattedPeriodPrice, " ").concat(billingPeriod) })));
|
|
4550
4584
|
};
|
|
4551
4585
|
|
|
4552
4586
|
var SubscriptionChargeUnitPrice = function (_a) {
|
|
@@ -4557,19 +4591,21 @@ var SubscriptionChargeUnitPrice = function (_a) {
|
|
|
4557
4591
|
var isDiscount = (charge === null || charge === void 0 ? void 0 : charge.kind) === SubscriptionChargeKind.DISCOUNT;
|
|
4558
4592
|
if (displayPriceTiers)
|
|
4559
4593
|
return (jsx(Dropdown, __assign({ dropdownRender: function () {
|
|
4560
|
-
var _a
|
|
4594
|
+
var _a;
|
|
4561
4595
|
return (jsx("div", __assign({ className: "flex flex-col rounded border border-solid border-slate-200 p-2", style: {
|
|
4562
4596
|
backgroundColor: darkMode
|
|
4563
4597
|
? "var(--row-background-dark)"
|
|
4564
4598
|
: "var(--row-background)",
|
|
4565
|
-
} }, { children: jsx("div", __assign({ className: "grid grid-cols-2", style: { columnGap: "0.5rem" } }, { children: (
|
|
4566
|
-
var _a, _b, _c
|
|
4567
|
-
var ends = ((
|
|
4568
|
-
? ((
|
|
4599
|
+
} }, { children: jsx("div", __assign({ className: "grid grid-cols-2", style: { columnGap: "0.5rem" } }, { children: (_a = charge.priceTiers) === null || _a === void 0 ? void 0 : _a.map(function (tier, index) {
|
|
4600
|
+
var _a, _b, _c;
|
|
4601
|
+
var ends = ((_b = (_a = charge.priceTiers) === null || _a === void 0 ? void 0 : _a[index + 1]) === null || _b === void 0 ? void 0 : _b.starts)
|
|
4602
|
+
? ((_c = charge.priceTiers[index + 1]) === null || _c === void 0 ? void 0 : _c.starts) - 1
|
|
4569
4603
|
: "∞";
|
|
4570
|
-
return (jsxs("div", __assign({ className: "contents" }, { children: [jsxs("div", __assign({ className: "whitespace-nowrap" }, { children: [tier.starts.toLocaleString(), " - ", ends.toLocaleString(), "
|
|
4604
|
+
return (jsxs("div", __assign({ className: "contents" }, { children: [jsxs("div", __assign({ className: "whitespace-nowrap" }, { children: [tier.starts.toLocaleString(), " - ", ends.toLocaleString(), " :"] })), jsx("div", __assign({ className: "whitespace-nowrap text-right" }, { children: formatCurrency(tier.price, subscription.currencyId, charge.priceDecimals) }))] }), index));
|
|
4571
4605
|
}) })) })));
|
|
4572
4606
|
}, onOpenChange: setShowPriceTiers, open: showPriceTiers, trigger: ["click"] }, { children: jsx("div", __assign({ className: "cursor-pointer underline", onClick: function () { return setShowPriceTiers(!showPriceTiers); } }, { children: showPriceTiers ? "Hide tiers" : "Show tiers" })) })));
|
|
4607
|
+
else if (charge.chargeType === ChargeType.USAGE || charge.trial)
|
|
4608
|
+
return jsx(Fragment, { children: "-" });
|
|
4573
4609
|
else if (isDiscount)
|
|
4574
4610
|
return (jsxs(Fragment, { children: ["-", formatCurrency(charge.discountedPrice, subscription.currencyId)] }));
|
|
4575
4611
|
else
|
|
@@ -4806,33 +4842,6 @@ var billingDetailsUpdate = function (_a) {
|
|
|
4806
4842
|
});
|
|
4807
4843
|
};
|
|
4808
4844
|
|
|
4809
|
-
// TODO: move this to common
|
|
4810
|
-
var billingDetailsQuery = function () {
|
|
4811
|
-
return "\nquery BillingDetails {\n billingDetails {\n billingCity\n billingContact {\n email\n }\n billingCountry\n billingState\n billingStreet\n billingZip\n name\n taxNumber\n }\n}";
|
|
4812
|
-
};
|
|
4813
|
-
var getBillingDetails = function (_a) {
|
|
4814
|
-
var token = _a.token, apiHost = _a.apiHost;
|
|
4815
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
4816
|
-
var response;
|
|
4817
|
-
var _b;
|
|
4818
|
-
return __generator(this, function (_c) {
|
|
4819
|
-
switch (_c.label) {
|
|
4820
|
-
case 0: return [4 /*yield*/, gqlRequest({
|
|
4821
|
-
query: billingDetailsQuery(),
|
|
4822
|
-
token: token,
|
|
4823
|
-
apiHost: apiHost,
|
|
4824
|
-
})];
|
|
4825
|
-
case 1:
|
|
4826
|
-
response = _c.sent();
|
|
4827
|
-
if (response === null || response === void 0 ? void 0 : response.errors) {
|
|
4828
|
-
throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
|
|
4829
|
-
}
|
|
4830
|
-
return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
|
|
4831
|
-
}
|
|
4832
|
-
});
|
|
4833
|
-
});
|
|
4834
|
-
};
|
|
4835
|
-
|
|
4836
4845
|
var BillingDetails = function (_a) {
|
|
4837
4846
|
var entityId = _a.entityId, _b = _a.isCardEnabled, isCardEnabled = _b === void 0 ? true : _b, _c = _a.shadow, shadow = _c === void 0 ? "shadow-md" : _c, className = _a.className, hidePaymentMethodForm = _a.hidePaymentMethodForm, countryListFilter = _a.countryListFilter;
|
|
4838
4847
|
var _d = useContext(BunnyContext), apiHost = _d.apiHost, onTokenExpired = _d.onTokenExpired, graphQLClient = _d.graphQLClient;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormattedInvoice, PluginData, Quote } from "@bunnyapp/common";
|
|
2
2
|
import { GraphQLClient } from "graphql-request";
|
|
3
|
-
export declare const PaymentForm: ({ entityId, invoice, onFail, onPaymentSuccess, quote, accountId, onSavePaymentMethod, overrideToken, graphQLClient, customCheckoutFunction, }: {
|
|
3
|
+
export declare const PaymentForm: ({ entityId, invoice, onFail, onPaymentSuccess, quote, accountId, onSavePaymentMethod, overrideToken, graphQLClient, customCheckoutFunction, currencyId: currencyIdFromProps, }: {
|
|
4
4
|
entityId: string;
|
|
5
5
|
invoice?: FormattedInvoice | undefined;
|
|
6
6
|
quote?: Quote | undefined;
|
|
@@ -11,4 +11,5 @@ export declare const PaymentForm: ({ entityId, invoice, onFail, onPaymentSuccess
|
|
|
11
11
|
overrideToken?: string | undefined;
|
|
12
12
|
graphQLClient: GraphQLClient;
|
|
13
13
|
customCheckoutFunction?: ((plugin: PluginData | undefined) => Promise<any>) | undefined;
|
|
14
|
+
currencyId?: string | undefined;
|
|
14
15
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Currency } from "@bunnyapp/common";
|
|
1
2
|
export default interface BillingDetails {
|
|
2
3
|
name?: string;
|
|
3
4
|
billingCity?: string;
|
|
@@ -9,4 +10,5 @@ export default interface BillingDetails {
|
|
|
9
10
|
billingStreet?: string;
|
|
10
11
|
billingZip?: string;
|
|
11
12
|
taxNumber?: string;
|
|
13
|
+
currency?: Currency;
|
|
12
14
|
}
|
package/package.json
CHANGED