@bunnyapp/components 1.0.27 → 1.0.29

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 CHANGED
@@ -2070,7 +2070,7 @@ var ActualCheckoutFooter = function (_a) {
2070
2070
  var _b = React.useState(false), isPaying = _b[0], setIsPaying = _b[1];
2071
2071
  var storedPaymentMethod = React.useContext(PaymentContext).storedPaymentMethod;
2072
2072
  var amountDue = quote ? getQuoteAmountDue(quote) : invoice === null || invoice === void 0 ? void 0 : invoice.amountDue;
2073
- var currencyId = (quote === null || quote === void 0 ? void 0 : quote.currencyId) || (invoice === null || invoice === void 0 ? void 0 : invoice.currency);
2073
+ var currencyId = (quote === null || quote === void 0 ? void 0 : quote.currencyId) || (invoice === null || invoice === void 0 ? void 0 : invoice.currencyId);
2074
2074
  // Payment hooks
2075
2075
  var payDemoPay = usePay$1({
2076
2076
  onPaymentSuccess: onPaymentSuccess,
@@ -2504,13 +2504,12 @@ var fetchStripeKey = function (plugin, token, apiHost, accountId) { return __awa
2504
2504
  });
2505
2505
  }); };
2506
2506
  pure.loadStripe.setLoadParameters({ advancedFraudSignals: false });
2507
- var useStripePlugin = function (plugin, token, apiHost, accountId) {
2507
+ var useStripePlugin = function (plugin, token, apiHost, currencyId, accountId) {
2508
2508
  var _a = React.useState(null), stripe = _a[0], setStripe = _a[1];
2509
2509
  var showErrorNotification = common.useErrorNotification();
2510
2510
  var options = {
2511
2511
  mode: "setup",
2512
- // TODO: Fetch currency from the entity/account
2513
- currency: "usd",
2512
+ currency: currencyId,
2514
2513
  setupFutureUsage: "off_session",
2515
2514
  };
2516
2515
  React.useEffect(function () {
@@ -2742,17 +2741,21 @@ function useRemovePaymentMethod(paymentPlugins, token, apiHost, entityId, accoun
2742
2741
 
2743
2742
  var Panel = antd.Collapse.Panel;
2744
2743
  var PaymentForm = function (_a) {
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;
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, currencyIdFromProps = _a.currencyId;
2746
2746
  // Local state
2747
- var _b = React.useState(), selectedPaymentMethod = _b[0], setSelectedPaymentMethod = _b[1];
2748
- var _c = React.useState(false), showPaymentMethodForm = _c[0], setShowPaymentMethodForm = _c[1];
2747
+ var _c = React.useState(), selectedPaymentMethod = _c[0], setSelectedPaymentMethod = _c[1];
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) ||
2751
+ (invoice === null || invoice === void 0 ? void 0 : invoice.currencyId) ||
2752
+ currencyIdFromProps)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
2750
2753
  // Hooks
2751
2754
  var apiHost = React.useContext(BunnyContext).apiHost;
2752
2755
  var token = useToken();
2753
2756
  var storedPaymentMethod = usePaymentMethod(graphQLClient, entityId, overrideToken || token).data;
2754
2757
  var isPaymentMethodFetched = storedPaymentMethod !== undefined;
2755
- var _d = usePaymentPlugins({ entityId: entityId, apiHost: apiHost, token: overrideToken || token }), paymentMethodAllowedPlugins = _d.paymentMethodAllowedPlugins, arePluginsFetched = _d.isFetched;
2758
+ var _e = usePaymentPlugins({ entityId: entityId, apiHost: apiHost, token: overrideToken || token }), paymentMethodAllowedPlugins = _e.paymentMethodAllowedPlugins, arePluginsFetched = _e.isFetched;
2756
2759
  var onClickRemove = useRemovePaymentMethod(paymentMethodAllowedPlugins || [], overrideToken || token, apiHost, entityId, accountId);
2757
2760
  var queryClient = reactQuery.useQueryClient();
2758
2761
  // Set default plugin
@@ -2799,15 +2802,15 @@ var PaymentForm = function (_a) {
2799
2802
  overrideToken: overrideToken,
2800
2803
  storedPaymentMethod: storedPaymentMethod,
2801
2804
  customCheckoutFunction: customCheckoutFunction,
2802
- } }, { children: jsxRuntime.jsx(StripeWrapper, __assign({ plugin: selectedPaymentMethod, token: token, apiHost: apiHost, accountId: accountId }, { children: jsxRuntime.jsx("div", __assign({ className: "flex flex-col gap-0 w-full" }, { children: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", __assign({ className: "px-4" }, { children: jsxRuntime.jsx(MiniCreditCard, { onClickRemove: function () { return onClickRemove(storedPaymentMethod); }, paymentMethodData: storedPaymentMethod }) })), paying && storedPaymentMethod ? (jsxRuntime.jsx("div", __assign({ className: "px-4" }, { children: jsxRuntime.jsx(CheckoutFooter, { quote: quote, invoice: invoice, onPaymentSuccess: handlePaymentSuccess, plugin: selectedPaymentMethod }) }))) : (
2805
+ } }, { children: jsxRuntime.jsx(StripeWrapper, __assign({ plugin: selectedPaymentMethod, token: token, apiHost: apiHost, currencyId: currencyId, accountId: accountId }, { children: jsxRuntime.jsx("div", __assign({ className: "flex flex-col gap-0 w-full" }, { children: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", __assign({ className: "px-4" }, { children: jsxRuntime.jsx(MiniCreditCard, { onClickRemove: function () { return onClickRemove(storedPaymentMethod); }, paymentMethodData: storedPaymentMethod }) })), paying && storedPaymentMethod ? (jsxRuntime.jsx("div", __assign({ className: "px-4" }, { children: jsxRuntime.jsx(CheckoutFooter, { quote: quote, invoice: invoice, onPaymentSuccess: handlePaymentSuccess, plugin: selectedPaymentMethod }) }))) : (
2803
2806
  //if not paying and payment method is saved, show Collapse
2804
2807
  jsxRuntime.jsx(antd.Collapse, __assign({ bordered: false, activeKey: showPaymentMethodForm ? "1" : undefined, ghost: true, collapsible: "disabled", destroyInactivePanel: true }, { children: jsxRuntime.jsx(Panel, __assign({ header: jsxRuntime.jsx(jsxRuntime.Fragment, { children: !showPaymentMethodForm ? (jsxRuntime.jsx("div", __assign({ className: "pt-2" }, { children: jsxRuntime.jsxs(antd.Button, __assign({ onClick: function () {
2805
2808
  setShowPaymentMethodForm(true);
2806
2809
  }, type: "default", className: "w-full", id: "addPaymentMethod" }, { children: [storedPaymentMethod ? "Update" : "Add", " payment method"] })) }))) : null }), showArrow: false }, { children: jsxRuntime.jsx("div", { children: selectedPaymentMethod ? (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col gap-2 mt-2" }, { children: [showPaymentMethodSelector && (jsxRuntime.jsx(PaymentMethodSelector, { onSelect: setSelectedPaymentMethod, paymentMethodAllowedPlugins: paymentMethodAllowedPlugins, value: selectedPaymentMethod })), jsxRuntime.jsx("div", __assign({ className: "flex flex-col" }, { children: jsxRuntime.jsx(PaymentMethodDetails, { onFail: onFail, onSavePaymentMethod: handleSavePaymentMethod, paymentMethod: selectedPaymentMethod }) }))] }))) : (jsxRuntime.jsx("div", { children: "No payment method selected" })) }) }), "1") })))] }) })) })) })));
2807
2810
  };
2808
2811
  function StripeWrapper(_a) {
2809
- var children = _a.children, plugin = _a.plugin, token = _a.token, apiHost = _a.apiHost, accountId = _a.accountId;
2810
- var _b = useStripePlugin(plugin, token, apiHost, accountId), stripe = _b.stripe, options = _b.options;
2812
+ var children = _a.children, plugin = _a.plugin, token = _a.token, apiHost = _a.apiHost, currencyId = _a.currencyId, accountId = _a.accountId;
2813
+ var _b = useStripePlugin(plugin, token, apiHost, currencyId || "usd", accountId), stripe = _b.stripe, options = _b.options;
2811
2814
  return (jsxRuntime.jsx(reactStripeJs.Elements, __assign({ options: options, stripe: stripe }, { children: children })));
2812
2815
  }
2813
2816
 
@@ -3635,9 +3638,37 @@ var DrawerHeader = function (_a) {
3635
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 }))] })));
3636
3639
  };
3637
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
+
3638
3668
  var PaymentMethod = function (_a) {
3639
- var entityId = _a.entityId, className = _a.className, _b = _a.shadow, shadow = _b === void 0 ? "shadow-md" : _b, _c = _a.cardEnabled, cardEnabled = _c === void 0 ? true : _c;
3640
- var _d = React.useContext(BunnyContext), apiHost = _d.apiHost, graphQLClient = _d.graphQLClient, onTokenExpired = _d.onTokenExpired;
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;
3641
3672
  var token = useToken();
3642
3673
  // Hooks
3643
3674
  var queryClient = reactQuery.useQueryClient();
@@ -3647,8 +3678,13 @@ var PaymentMethod = function (_a) {
3647
3678
  var isMobile = common.useIsMobile();
3648
3679
  var data = usePaymentMethod(graphQLClient, entityId, token).data;
3649
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;
3650
3686
  // Local state
3651
- var _e = React.useState(false), showModal = _e[0], setShowModal = _e[1];
3687
+ var _g = React.useState(false), showModal = _g[0], setShowModal = _g[1];
3652
3688
  var onSuccess = function () {
3653
3689
  queryClient.invalidateQueries({
3654
3690
  queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
@@ -3677,7 +3713,7 @@ var PaymentMethod = function (_a) {
3677
3713
  handleAllErrorFormats(error);
3678
3714
  }, onPaymentSuccess: function () {
3679
3715
  onSuccess();
3680
- }, graphQLClient: graphQLClient }) }))] })));
3716
+ }, graphQLClient: graphQLClient, currencyId: (_b = billingDetails === null || billingDetails === void 0 ? void 0 : billingDetails.currency) === null || _b === void 0 ? void 0 : _b.id }) }))] })));
3681
3717
  };
3682
3718
 
3683
3719
  var pageWrapperClassName = function (isMobile) {
@@ -4050,8 +4086,8 @@ function InitialSignupForm(_a) {
4050
4086
 
4051
4087
  var Title = antd.Typography.Title, Text$4 = antd.Typography.Text;
4052
4088
  function PaymentSuccessDisplay(_a) {
4053
- var amountPaid = _a.amountPaid, className = _a.className, companyName = _a.companyName, returnUrl = _a.returnUrl, style = _a.style;
4054
- return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col items-center justify-center h-full ".concat(className), style: style }, { children: [jsxRuntime.jsx(CheckCircleFilled$1, { style: { fontSize: "48px", color: "rgb(52 211 153)" } }), jsxRuntime.jsxs(Title, __assign({ level: 3, className: "mt-2 m-0" }, { children: ["Payment of ", common.formatCurrency(amountPaid, "USD"), " successful"] })), returnUrl && (jsxRuntime.jsxs(Text$4, __assign({ className: "text-slate-500 cursor-pointer underline", onClick: function () { return (window.location.href = returnUrl); } }, { children: ["Back to ", companyName] })))] })));
4089
+ var amountPaid = _a.amountPaid, className = _a.className, companyName = _a.companyName, returnUrl = _a.returnUrl, style = _a.style, currencyId = _a.currencyId;
4090
+ return (jsxRuntime.jsxs("div", __assign({ className: "flex flex-col items-center justify-center h-full ".concat(className), style: style }, { children: [jsxRuntime.jsx(CheckCircleFilled$1, { style: { fontSize: "48px", color: "rgb(52 211 153)" } }), jsxRuntime.jsxs(Title, __assign({ level: 3, className: "mt-2 m-0" }, { children: ["Payment of ", common.formatCurrency(amountPaid, currencyId), " successful"] })), returnUrl && (jsxRuntime.jsxs(Text$4, __assign({ className: "text-slate-500 cursor-pointer underline", onClick: function () { return (window.location.href = returnUrl); } }, { children: ["Back to ", companyName] })))] })));
4055
4091
  }
4056
4092
 
4057
4093
  var Text$3 = antd.Typography.Text;
@@ -4171,7 +4207,7 @@ function Signup(_a) {
4171
4207
  var children = _a.children, className = _a.className, style = _a.style;
4172
4208
  return isCardEnabled ? (jsxRuntime.jsx(Card, __assign({ className: className, style: style }, { children: children }))) : (jsxRuntime.jsx("div", __assign({ className: className, style: style }, { children: children })));
4173
4209
  };
4174
- return (jsxRuntime.jsx(WrapperComponent, __assign({ className: "p-4 flex flex-col ".concat(shadow, " ").concat(className), style: style }, { children: purchaseSucceeded ? (jsxRuntime.jsx(PaymentSuccessDisplay, { amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, className: "w-full", companyName: companyName, returnUrl: returnUrl })) : (jsxRuntime.jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex flex-col ".concat(isMobile ? "items-center" : "w-1/2 items-center") }, { children: jsxRuntime.jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile ? "h-full" : "my-4") }, { children: jsxRuntime.jsx(antd.Divider, { className: "h-full", type: isMobile ? undefined : "vertical" }) })), jsxRuntime.jsx("div", __assign({ className: "flex ".concat(isMobile
4210
+ return (jsxRuntime.jsx(WrapperComponent, __assign({ className: "p-4 flex flex-col ".concat(shadow, " ").concat(className), style: style }, { children: purchaseSucceeded ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: (quote === null || quote === void 0 ? void 0 : quote.currencyId) !== undefined ? (jsxRuntime.jsx(PaymentSuccessDisplay, { amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, className: "w-full", companyName: companyName, returnUrl: returnUrl, currencyId: quote === null || quote === void 0 ? void 0 : quote.currencyId })) : (jsxRuntime.jsx("div", { children: "No currency ID found from Quote" })) })) : (jsxRuntime.jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsxRuntime.jsx("div", __assign({ className: "flex flex-col ".concat(isMobile ? "items-center" : "w-1/2 items-center") }, { children: jsxRuntime.jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile ? "h-full" : "my-4") }, { children: jsxRuntime.jsx(antd.Divider, { className: "h-full", type: isMobile ? undefined : "vertical" }) })), jsxRuntime.jsx("div", __assign({ className: "flex ".concat(isMobile
4175
4211
  ? "items-center justify-center my-12"
4176
4212
  : "w-1/2 items-center justify-center my-12") }, { children: jsxRuntime.jsx("div", __assign({ className: "".concat(isMobile ? "w-full" : "w-1/2") }, { children: jsxRuntime.jsx(PaymentForms, { entityId: entityId, quote: quote, handlePaymentSuccess: handlePaymentSuccess, handlePaymentFail: handlePaymentFail, handleSubmit: handleSubmit, proceedingToPayment: proceedingToPayment, accountId: accountId, overrideToken: portalSessionToken, customCheckoutFunction: accountSignupFunction }) })) }))] }))) })));
4177
4213
  }
@@ -4830,33 +4866,6 @@ var billingDetailsUpdate = function (_a) {
4830
4866
  });
4831
4867
  };
4832
4868
 
4833
- // TODO: move this to common
4834
- var billingDetailsQuery = function () {
4835
- 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}";
4836
- };
4837
- var getBillingDetails = function (_a) {
4838
- var token = _a.token, apiHost = _a.apiHost;
4839
- return __awaiter(void 0, void 0, void 0, function () {
4840
- var response;
4841
- var _b;
4842
- return __generator(this, function (_c) {
4843
- switch (_c.label) {
4844
- case 0: return [4 /*yield*/, common.gqlRequest({
4845
- query: billingDetailsQuery(),
4846
- token: token,
4847
- apiHost: apiHost,
4848
- })];
4849
- case 1:
4850
- response = _c.sent();
4851
- if (response === null || response === void 0 ? void 0 : response.errors) {
4852
- throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
4853
- }
4854
- return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
4855
- }
4856
- });
4857
- });
4858
- };
4859
-
4860
4869
  var BillingDetails = function (_a) {
4861
4870
  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;
4862
4871
  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;
@@ -16,7 +16,7 @@ export declare const createPaymentIntent: ({ payable, savePaymentMethod, memo, p
16
16
  token: string;
17
17
  apiHost: string;
18
18
  }) => Promise<any>;
19
- export declare const useStripePlugin: (plugin: PluginData | undefined, token: string, apiHost: string, accountId?: string) => {
19
+ export declare const useStripePlugin: (plugin: PluginData | undefined, token: string, apiHost: string, currencyId: string, accountId?: string) => {
20
20
  stripe: Stripe | null;
21
21
  options: {
22
22
  mode: "setup";
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" />
2
- export default function PaymentSuccessDisplay({ amountPaid, className, companyName, returnUrl, style, }: {
2
+ export default function PaymentSuccessDisplay({ amountPaid, className, companyName, returnUrl, style, currencyId, }: {
3
3
  amountPaid: number;
4
4
  className: string;
5
5
  companyName: string;
6
6
  returnUrl?: string;
7
7
  style?: React.CSSProperties;
8
+ currencyId: string;
8
9
  }): 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
@@ -2042,7 +2042,7 @@ var ActualCheckoutFooter = function (_a) {
2042
2042
  var _b = useState(false), isPaying = _b[0], setIsPaying = _b[1];
2043
2043
  var storedPaymentMethod = useContext(PaymentContext).storedPaymentMethod;
2044
2044
  var amountDue = quote ? getQuoteAmountDue(quote) : invoice === null || invoice === void 0 ? void 0 : invoice.amountDue;
2045
- var currencyId = (quote === null || quote === void 0 ? void 0 : quote.currencyId) || (invoice === null || invoice === void 0 ? void 0 : invoice.currency);
2045
+ var currencyId = (quote === null || quote === void 0 ? void 0 : quote.currencyId) || (invoice === null || invoice === void 0 ? void 0 : invoice.currencyId);
2046
2046
  // Payment hooks
2047
2047
  var payDemoPay = usePay$1({
2048
2048
  onPaymentSuccess: onPaymentSuccess,
@@ -2476,13 +2476,12 @@ var fetchStripeKey = function (plugin, token, apiHost, accountId) { return __awa
2476
2476
  });
2477
2477
  }); };
2478
2478
  loadStripe.setLoadParameters({ advancedFraudSignals: false });
2479
- var useStripePlugin = function (plugin, token, apiHost, accountId) {
2479
+ var useStripePlugin = function (plugin, token, apiHost, currencyId, accountId) {
2480
2480
  var _a = useState(null), stripe = _a[0], setStripe = _a[1];
2481
2481
  var showErrorNotification = useErrorNotification();
2482
2482
  var options = {
2483
2483
  mode: "setup",
2484
- // TODO: Fetch currency from the entity/account
2485
- currency: "usd",
2484
+ currency: currencyId,
2486
2485
  setupFutureUsage: "off_session",
2487
2486
  };
2488
2487
  useEffect(function () {
@@ -2714,17 +2713,21 @@ function useRemovePaymentMethod(paymentPlugins, token, apiHost, entityId, accoun
2714
2713
 
2715
2714
  var Panel = Collapse.Panel;
2716
2715
  var PaymentForm = function (_a) {
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;
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, currencyIdFromProps = _a.currencyId;
2718
2718
  // Local state
2719
- var _b = useState(), selectedPaymentMethod = _b[0], setSelectedPaymentMethod = _b[1];
2720
- var _c = useState(false), showPaymentMethodForm = _c[0], setShowPaymentMethodForm = _c[1];
2719
+ var _c = useState(), selectedPaymentMethod = _c[0], setSelectedPaymentMethod = _c[1];
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) ||
2723
+ (invoice === null || invoice === void 0 ? void 0 : invoice.currencyId) ||
2724
+ currencyIdFromProps)) === null || _b === void 0 ? void 0 : _b.toLowerCase();
2722
2725
  // Hooks
2723
2726
  var apiHost = useContext(BunnyContext).apiHost;
2724
2727
  var token = useToken();
2725
2728
  var storedPaymentMethod = usePaymentMethod(graphQLClient, entityId, overrideToken || token).data;
2726
2729
  var isPaymentMethodFetched = storedPaymentMethod !== undefined;
2727
- var _d = usePaymentPlugins({ entityId: entityId, apiHost: apiHost, token: overrideToken || token }), paymentMethodAllowedPlugins = _d.paymentMethodAllowedPlugins, arePluginsFetched = _d.isFetched;
2730
+ var _e = usePaymentPlugins({ entityId: entityId, apiHost: apiHost, token: overrideToken || token }), paymentMethodAllowedPlugins = _e.paymentMethodAllowedPlugins, arePluginsFetched = _e.isFetched;
2728
2731
  var onClickRemove = useRemovePaymentMethod(paymentMethodAllowedPlugins || [], overrideToken || token, apiHost, entityId, accountId);
2729
2732
  var queryClient = useQueryClient();
2730
2733
  // Set default plugin
@@ -2771,15 +2774,15 @@ var PaymentForm = function (_a) {
2771
2774
  overrideToken: overrideToken,
2772
2775
  storedPaymentMethod: storedPaymentMethod,
2773
2776
  customCheckoutFunction: customCheckoutFunction,
2774
- } }, { children: jsx(StripeWrapper, __assign({ plugin: selectedPaymentMethod, token: token, apiHost: apiHost, accountId: accountId }, { children: jsx("div", __assign({ className: "flex flex-col gap-0 w-full" }, { children: jsxs(Fragment, { children: [jsx("div", __assign({ className: "px-4" }, { children: jsx(MiniCreditCard, { onClickRemove: function () { return onClickRemove(storedPaymentMethod); }, paymentMethodData: storedPaymentMethod }) })), paying && storedPaymentMethod ? (jsx("div", __assign({ className: "px-4" }, { children: jsx(CheckoutFooter, { quote: quote, invoice: invoice, onPaymentSuccess: handlePaymentSuccess, plugin: selectedPaymentMethod }) }))) : (
2777
+ } }, { children: jsx(StripeWrapper, __assign({ plugin: selectedPaymentMethod, token: token, apiHost: apiHost, currencyId: currencyId, accountId: accountId }, { children: jsx("div", __assign({ className: "flex flex-col gap-0 w-full" }, { children: jsxs(Fragment, { children: [jsx("div", __assign({ className: "px-4" }, { children: jsx(MiniCreditCard, { onClickRemove: function () { return onClickRemove(storedPaymentMethod); }, paymentMethodData: storedPaymentMethod }) })), paying && storedPaymentMethod ? (jsx("div", __assign({ className: "px-4" }, { children: jsx(CheckoutFooter, { quote: quote, invoice: invoice, onPaymentSuccess: handlePaymentSuccess, plugin: selectedPaymentMethod }) }))) : (
2775
2778
  //if not paying and payment method is saved, show Collapse
2776
2779
  jsx(Collapse, __assign({ bordered: false, activeKey: showPaymentMethodForm ? "1" : undefined, ghost: true, collapsible: "disabled", destroyInactivePanel: true }, { children: jsx(Panel, __assign({ header: jsx(Fragment, { children: !showPaymentMethodForm ? (jsx("div", __assign({ className: "pt-2" }, { children: jsxs(Button, __assign({ onClick: function () {
2777
2780
  setShowPaymentMethodForm(true);
2778
2781
  }, type: "default", className: "w-full", id: "addPaymentMethod" }, { children: [storedPaymentMethod ? "Update" : "Add", " payment method"] })) }))) : null }), showArrow: false }, { children: jsx("div", { children: selectedPaymentMethod ? (jsxs("div", __assign({ className: "flex flex-col gap-2 mt-2" }, { children: [showPaymentMethodSelector && (jsx(PaymentMethodSelector, { onSelect: setSelectedPaymentMethod, paymentMethodAllowedPlugins: paymentMethodAllowedPlugins, value: selectedPaymentMethod })), jsx("div", __assign({ className: "flex flex-col" }, { children: jsx(PaymentMethodDetails, { onFail: onFail, onSavePaymentMethod: handleSavePaymentMethod, paymentMethod: selectedPaymentMethod }) }))] }))) : (jsx("div", { children: "No payment method selected" })) }) }), "1") })))] }) })) })) })));
2779
2782
  };
2780
2783
  function StripeWrapper(_a) {
2781
- var children = _a.children, plugin = _a.plugin, token = _a.token, apiHost = _a.apiHost, accountId = _a.accountId;
2782
- var _b = useStripePlugin(plugin, token, apiHost, accountId), stripe = _b.stripe, options = _b.options;
2784
+ var children = _a.children, plugin = _a.plugin, token = _a.token, apiHost = _a.apiHost, currencyId = _a.currencyId, accountId = _a.accountId;
2785
+ var _b = useStripePlugin(plugin, token, apiHost, currencyId || "usd", accountId), stripe = _b.stripe, options = _b.options;
2783
2786
  return (jsx(Elements, __assign({ options: options, stripe: stripe }, { children: children })));
2784
2787
  }
2785
2788
 
@@ -3607,9 +3610,37 @@ var DrawerHeader = function (_a) {
3607
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 }))] })));
3608
3611
  };
3609
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
+
3610
3640
  var PaymentMethod = function (_a) {
3611
- var entityId = _a.entityId, className = _a.className, _b = _a.shadow, shadow = _b === void 0 ? "shadow-md" : _b, _c = _a.cardEnabled, cardEnabled = _c === void 0 ? true : _c;
3612
- var _d = useContext(BunnyContext), apiHost = _d.apiHost, graphQLClient = _d.graphQLClient, onTokenExpired = _d.onTokenExpired;
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;
3613
3644
  var token = useToken();
3614
3645
  // Hooks
3615
3646
  var queryClient = useQueryClient();
@@ -3619,8 +3650,13 @@ var PaymentMethod = function (_a) {
3619
3650
  var isMobile = useIsMobile();
3620
3651
  var data = usePaymentMethod(graphQLClient, entityId, token).data;
3621
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;
3622
3658
  // Local state
3623
- var _e = useState(false), showModal = _e[0], setShowModal = _e[1];
3659
+ var _g = useState(false), showModal = _g[0], setShowModal = _g[1];
3624
3660
  var onSuccess = function () {
3625
3661
  queryClient.invalidateQueries({
3626
3662
  queryKey: QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
@@ -3649,7 +3685,7 @@ var PaymentMethod = function (_a) {
3649
3685
  handleAllErrorFormats(error);
3650
3686
  }, onPaymentSuccess: function () {
3651
3687
  onSuccess();
3652
- }, graphQLClient: graphQLClient }) }))] })));
3688
+ }, graphQLClient: graphQLClient, currencyId: (_b = billingDetails === null || billingDetails === void 0 ? void 0 : billingDetails.currency) === null || _b === void 0 ? void 0 : _b.id }) }))] })));
3653
3689
  };
3654
3690
 
3655
3691
  var pageWrapperClassName = function (isMobile) {
@@ -4022,8 +4058,8 @@ function InitialSignupForm(_a) {
4022
4058
 
4023
4059
  var Title = Typography.Title, Text$4 = Typography.Text;
4024
4060
  function PaymentSuccessDisplay(_a) {
4025
- var amountPaid = _a.amountPaid, className = _a.className, companyName = _a.companyName, returnUrl = _a.returnUrl, style = _a.style;
4026
- return (jsxs("div", __assign({ className: "flex flex-col items-center justify-center h-full ".concat(className), style: style }, { children: [jsx(CheckCircleFilled$1, { style: { fontSize: "48px", color: "rgb(52 211 153)" } }), jsxs(Title, __assign({ level: 3, className: "mt-2 m-0" }, { children: ["Payment of ", formatCurrency(amountPaid, "USD"), " successful"] })), returnUrl && (jsxs(Text$4, __assign({ className: "text-slate-500 cursor-pointer underline", onClick: function () { return (window.location.href = returnUrl); } }, { children: ["Back to ", companyName] })))] })));
4061
+ var amountPaid = _a.amountPaid, className = _a.className, companyName = _a.companyName, returnUrl = _a.returnUrl, style = _a.style, currencyId = _a.currencyId;
4062
+ return (jsxs("div", __assign({ className: "flex flex-col items-center justify-center h-full ".concat(className), style: style }, { children: [jsx(CheckCircleFilled$1, { style: { fontSize: "48px", color: "rgb(52 211 153)" } }), jsxs(Title, __assign({ level: 3, className: "mt-2 m-0" }, { children: ["Payment of ", formatCurrency(amountPaid, currencyId), " successful"] })), returnUrl && (jsxs(Text$4, __assign({ className: "text-slate-500 cursor-pointer underline", onClick: function () { return (window.location.href = returnUrl); } }, { children: ["Back to ", companyName] })))] })));
4027
4063
  }
4028
4064
 
4029
4065
  var Text$3 = Typography.Text;
@@ -4143,7 +4179,7 @@ function Signup(_a) {
4143
4179
  var children = _a.children, className = _a.className, style = _a.style;
4144
4180
  return isCardEnabled ? (jsx(Card, __assign({ className: className, style: style }, { children: children }))) : (jsx("div", __assign({ className: className, style: style }, { children: children })));
4145
4181
  };
4146
- return (jsx(WrapperComponent, __assign({ className: "p-4 flex flex-col ".concat(shadow, " ").concat(className), style: style }, { children: purchaseSucceeded ? (jsx(PaymentSuccessDisplay, { amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, className: "w-full", companyName: companyName, returnUrl: returnUrl })) : (jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsx("div", __assign({ className: "flex flex-col ".concat(isMobile ? "items-center" : "w-1/2 items-center") }, { children: jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsx("div", __assign({ className: "".concat(isMobile ? "h-full" : "my-4") }, { children: jsx(Divider, { className: "h-full", type: isMobile ? undefined : "vertical" }) })), jsx("div", __assign({ className: "flex ".concat(isMobile
4182
+ return (jsx(WrapperComponent, __assign({ className: "p-4 flex flex-col ".concat(shadow, " ").concat(className), style: style }, { children: purchaseSucceeded ? (jsx(Fragment, { children: (quote === null || quote === void 0 ? void 0 : quote.currencyId) !== undefined ? (jsx(PaymentSuccessDisplay, { amountPaid: (quote === null || quote === void 0 ? void 0 : quote.amountDue) || 0, className: "w-full", companyName: companyName, returnUrl: returnUrl, currencyId: quote === null || quote === void 0 ? void 0 : quote.currencyId })) : (jsx("div", { children: "No currency ID found from Quote" })) })) : (jsxs("div", __assign({ className: "flex ".concat(isMobile ? "flex-col" : "flex-row", " h-full w-full") }, { children: [jsx("div", __assign({ className: "flex flex-col ".concat(isMobile ? "items-center" : "w-1/2 items-center") }, { children: jsx(PriceListDisplay, { priceListData: priceListData, topNavImageUrl: topNavImageUrl }) })), jsx("div", __assign({ className: "".concat(isMobile ? "h-full" : "my-4") }, { children: jsx(Divider, { className: "h-full", type: isMobile ? undefined : "vertical" }) })), jsx("div", __assign({ className: "flex ".concat(isMobile
4147
4183
  ? "items-center justify-center my-12"
4148
4184
  : "w-1/2 items-center justify-center my-12") }, { children: jsx("div", __assign({ className: "".concat(isMobile ? "w-full" : "w-1/2") }, { children: jsx(PaymentForms, { entityId: entityId, quote: quote, handlePaymentSuccess: handlePaymentSuccess, handlePaymentFail: handlePaymentFail, handleSubmit: handleSubmit, proceedingToPayment: proceedingToPayment, accountId: accountId, overrideToken: portalSessionToken, customCheckoutFunction: accountSignupFunction }) })) }))] }))) })));
4149
4185
  }
@@ -4802,33 +4838,6 @@ var billingDetailsUpdate = function (_a) {
4802
4838
  });
4803
4839
  };
4804
4840
 
4805
- // TODO: move this to common
4806
- var billingDetailsQuery = function () {
4807
- 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}";
4808
- };
4809
- var getBillingDetails = function (_a) {
4810
- var token = _a.token, apiHost = _a.apiHost;
4811
- return __awaiter(void 0, void 0, void 0, function () {
4812
- var response;
4813
- var _b;
4814
- return __generator(this, function (_c) {
4815
- switch (_c.label) {
4816
- case 0: return [4 /*yield*/, gqlRequest({
4817
- query: billingDetailsQuery(),
4818
- token: token,
4819
- apiHost: apiHost,
4820
- })];
4821
- case 1:
4822
- response = _c.sent();
4823
- if (response === null || response === void 0 ? void 0 : response.errors) {
4824
- throw new Error((_b = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _b === void 0 ? void 0 : _b.message);
4825
- }
4826
- return [2 /*return*/, response === null || response === void 0 ? void 0 : response.billingDetails];
4827
- }
4828
- });
4829
- });
4830
- };
4831
-
4832
4841
  var BillingDetails = function (_a) {
4833
4842
  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;
4834
4843
  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;
@@ -16,7 +16,7 @@ export declare const createPaymentIntent: ({ payable, savePaymentMethod, memo, p
16
16
  token: string;
17
17
  apiHost: string;
18
18
  }) => Promise<any>;
19
- export declare const useStripePlugin: (plugin: PluginData | undefined, token: string, apiHost: string, accountId?: string) => {
19
+ export declare const useStripePlugin: (plugin: PluginData | undefined, token: string, apiHost: string, currencyId: string, accountId?: string) => {
20
20
  stripe: Stripe | null;
21
21
  options: {
22
22
  mode: "setup";
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" />
2
- export default function PaymentSuccessDisplay({ amountPaid, className, companyName, returnUrl, style, }: {
2
+ export default function PaymentSuccessDisplay({ amountPaid, className, companyName, returnUrl, style, currencyId, }: {
3
3
  amountPaid: number;
4
4
  className: string;
5
5
  companyName: string;
6
6
  returnUrl?: string;
7
7
  style?: React.CSSProperties;
8
+ currencyId: string;
8
9
  }): 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunnyapp/components",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "Components from the Bunny portal to embed Bunny UI functionality into your application.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",