@bunnyapp/components 1.0.26 → 1.0.28
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 +50 -74
- package/dist/cjs/src/components/PaymentForm/Stripe/stripeUtils.d.ts +1 -1
- package/dist/cjs/src/components/PaymentForm/useRemovePaymentMethod.d.ts +1 -1
- package/dist/cjs/src/components/Signup/PaymentSuccess.d.ts +2 -1
- package/dist/cjs/src/hooks/usePaymentMethod.d.ts +1 -1
- package/dist/esm/index.js +57 -80
- package/dist/esm/src/components/PaymentForm/Stripe/stripeUtils.d.ts +1 -1
- package/dist/esm/src/components/PaymentForm/useRemovePaymentMethod.d.ts +1 -1
- package/dist/esm/src/components/Signup/PaymentSuccess.d.ts +2 -1
- package/dist/esm/src/hooks/usePaymentMethod.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +2 -2
- package/dist/cjs/src/graphql/graphqlUtil.d.ts +0 -10
- package/dist/esm/src/graphql/graphqlUtil.d.ts +0 -10
package/dist/cjs/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var common = require('@bunnyapp/common');
|
|
|
11
11
|
var reactQuery = require('@tanstack/react-query');
|
|
12
12
|
var theme = require('antd/lib/theme');
|
|
13
13
|
var recoil = require('recoil');
|
|
14
|
-
var
|
|
14
|
+
var graphqlRequest = import('graphql-request');
|
|
15
15
|
var reactStripeJs = require('@stripe/react-stripe-js');
|
|
16
16
|
var pure = require('@stripe/stripe-js/pure');
|
|
17
17
|
var lodash = require('lodash');
|
|
@@ -41,7 +41,6 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
|
41
41
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
42
42
|
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
43
43
|
var theme__default = /*#__PURE__*/_interopDefaultLegacy(theme);
|
|
44
|
-
var request__default = /*#__PURE__*/_interopDefaultLegacy(request);
|
|
45
44
|
|
|
46
45
|
function styleInject(css, ref) {
|
|
47
46
|
if ( ref === void 0 ) ref = {};
|
|
@@ -1618,7 +1617,7 @@ var getBranding = function (_a) {
|
|
|
1618
1617
|
};
|
|
1619
1618
|
|
|
1620
1619
|
var createGraphQLClient = function (token, apiHost) {
|
|
1621
|
-
return new
|
|
1620
|
+
return new graphqlRequest.GraphQLClient(apiHost + "/graphql", {
|
|
1622
1621
|
headers: {
|
|
1623
1622
|
Authorization: token,
|
|
1624
1623
|
},
|
|
@@ -1653,7 +1652,7 @@ function ContextualWrapper(_a) {
|
|
|
1653
1652
|
var _b = React.useState(false), interFontLoaded = _b[0], setInterFontLoaded = _b[1];
|
|
1654
1653
|
var _c = React.useContext(BunnyContext), apiHost = _c.apiHost, token = _c.token;
|
|
1655
1654
|
var branding = reactQuery.useQuery({
|
|
1656
|
-
queryKey: common.QueryKeyFactory.default.brandingKey,
|
|
1655
|
+
queryKey: common.QueryKeyFactory.default.brandingKey(token),
|
|
1657
1656
|
queryFn: function () { return getBranding({ token: token, apiHost: apiHost }); },
|
|
1658
1657
|
}).data;
|
|
1659
1658
|
var isMobile = common.useIsMobile();
|
|
@@ -1871,9 +1870,9 @@ function InvoicePDF(_a) {
|
|
|
1871
1870
|
}
|
|
1872
1871
|
|
|
1873
1872
|
var paymentMethodsQuery = "query paymentMethods ($filter: String, $first: Int, $sort: String) {\n paymentMethods (filter: $filter, first: $first, sort: $sort) {\n nodes {\n id\n disabled\n pluginId\n accountId\n expirationDate\n plugin {\n guid\n id\n }\n state\n metadata {\n issuer\n identifier\n kind\n description\n icon\n }\n }\n }\n}";
|
|
1874
|
-
var usePaymentMethod = function (graphQLClient) {
|
|
1873
|
+
var usePaymentMethod = function (graphQLClient, entityId, token) {
|
|
1875
1874
|
var result = reactQuery.useQuery({
|
|
1876
|
-
queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey,
|
|
1875
|
+
queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
|
|
1877
1876
|
queryFn: function () {
|
|
1878
1877
|
return graphQLClient
|
|
1879
1878
|
.request(paymentMethodsQuery, {
|
|
@@ -1894,7 +1893,7 @@ var usePaymentMethod = function (graphQLClient) {
|
|
|
1894
1893
|
var usePlugins = function (_a) {
|
|
1895
1894
|
var entityId = _a.entityId, apiHost = _a.apiHost, token = _a.token;
|
|
1896
1895
|
var response = reactQuery.useQuery({
|
|
1897
|
-
queryKey: common.QueryKeyFactory.default.pluginsKey,
|
|
1896
|
+
queryKey: common.QueryKeyFactory.default.pluginsKey(token),
|
|
1898
1897
|
queryFn: function () {
|
|
1899
1898
|
var plugins = common.getPlugins({
|
|
1900
1899
|
entityId: entityId,
|
|
@@ -1939,34 +1938,6 @@ var getQuoteAmountDue = function (quote) {
|
|
|
1939
1938
|
return quote.amountDue;
|
|
1940
1939
|
};
|
|
1941
1940
|
|
|
1942
|
-
var DEFAULT_HEADERS = {
|
|
1943
|
-
"Content-type": "application/json; charset=utf-8",
|
|
1944
|
-
};
|
|
1945
|
-
// !!! Duplicated from @bunnyapp/common due to bug in signup. Uses BunnyProvider token instead of apiToken.
|
|
1946
|
-
var gqlRequest = function (_a) {
|
|
1947
|
-
var query = _a.query, _b = _a.vars, vars = _b === void 0 ? {} : _b, headers = _a.headers, token = _a.token, isInPreviewMode = _a.isInPreviewMode, apiHost = _a.apiHost;
|
|
1948
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
1949
|
-
var graphqlEndpoint, requestHeaders, authorizationHeader, error_1;
|
|
1950
|
-
return __generator(this, function (_c) {
|
|
1951
|
-
switch (_c.label) {
|
|
1952
|
-
case 0:
|
|
1953
|
-
_c.trys.push([0, 2, , 3]);
|
|
1954
|
-
graphqlEndpoint = common.DEFAULT_CONFIG.graphqlEndpoint;
|
|
1955
|
-
requestHeaders = headers || DEFAULT_HEADERS;
|
|
1956
|
-
authorizationHeader = "Bearer ".concat(token);
|
|
1957
|
-
if (!requestHeaders.Authorization && !isInPreviewMode)
|
|
1958
|
-
requestHeaders.Authorization = authorizationHeader;
|
|
1959
|
-
return [4 /*yield*/, request__default["default"]("".concat(apiHost).concat(graphqlEndpoint), query, vars, requestHeaders)];
|
|
1960
|
-
case 1: return [2 /*return*/, _c.sent()];
|
|
1961
|
-
case 2:
|
|
1962
|
-
error_1 = _c.sent();
|
|
1963
|
-
throw error_1;
|
|
1964
|
-
case 3: return [2 /*return*/];
|
|
1965
|
-
}
|
|
1966
|
-
});
|
|
1967
|
-
});
|
|
1968
|
-
};
|
|
1969
|
-
|
|
1970
1941
|
var MUTATION$7 = "\n mutation checkout(\n $invoiceId: ID,\n $quoteId: ID,\n $paymentMethodId: ID,\n $paymentMethodData: CheckoutPaymentMethodAttributes\n ) {\n checkout(\n invoiceId: $invoiceId,\n quoteId: $quoteId,\n paymentMethodId: $paymentMethodId,\n paymentMethodData: $paymentMethodData\n ) {\n invoice {\n id\n state\n amount\n amountDue\n }\n payment {\n id\n state\n amount\n }\n paymentApplication {\n id\n invoiceId\n paymentId\n }\n transaction {\n id\n amount\n }\n }\n }\n";
|
|
1971
1942
|
var checkout = function (_a) {
|
|
1972
1943
|
var quoteId = _a.quoteId, invoiceId = _a.invoiceId, paymentMethodId = _a.paymentMethodId, paymentMethodData = _a.paymentMethodData, token = _a.token, apiHost = _a.apiHost;
|
|
@@ -1983,7 +1954,7 @@ var checkout = function (_a) {
|
|
|
1983
1954
|
if (paymentMethodData) {
|
|
1984
1955
|
mutationVars.paymentMethodData = __assign(__assign({}, paymentMethodData), { metadata: paymentMethodData.metadata });
|
|
1985
1956
|
}
|
|
1986
|
-
return [4 /*yield*/, gqlRequest({
|
|
1957
|
+
return [4 /*yield*/, common.gqlRequest({
|
|
1987
1958
|
query: MUTATION$7,
|
|
1988
1959
|
token: token,
|
|
1989
1960
|
vars: mutationVars,
|
|
@@ -2099,7 +2070,7 @@ var ActualCheckoutFooter = function (_a) {
|
|
|
2099
2070
|
var _b = React.useState(false), isPaying = _b[0], setIsPaying = _b[1];
|
|
2100
2071
|
var storedPaymentMethod = React.useContext(PaymentContext).storedPaymentMethod;
|
|
2101
2072
|
var amountDue = quote ? getQuoteAmountDue(quote) : invoice === null || invoice === void 0 ? void 0 : invoice.amountDue;
|
|
2102
|
-
var currencyId = (quote === null || quote === void 0 ? void 0 : quote.currencyId) || (invoice === null || invoice === void 0 ? void 0 : invoice.
|
|
2073
|
+
var currencyId = (quote === null || quote === void 0 ? void 0 : quote.currencyId) || (invoice === null || invoice === void 0 ? void 0 : invoice.currencyId);
|
|
2103
2074
|
// Payment hooks
|
|
2104
2075
|
var payDemoPay = usePay$1({
|
|
2105
2076
|
onPaymentSuccess: onPaymentSuccess,
|
|
@@ -2533,13 +2504,12 @@ var fetchStripeKey = function (plugin, token, apiHost, accountId) { return __awa
|
|
|
2533
2504
|
});
|
|
2534
2505
|
}); };
|
|
2535
2506
|
pure.loadStripe.setLoadParameters({ advancedFraudSignals: false });
|
|
2536
|
-
var useStripePlugin = function (plugin, token, apiHost, accountId) {
|
|
2507
|
+
var useStripePlugin = function (plugin, token, apiHost, currencyId, accountId) {
|
|
2537
2508
|
var _a = React.useState(null), stripe = _a[0], setStripe = _a[1];
|
|
2538
2509
|
var showErrorNotification = common.useErrorNotification();
|
|
2539
2510
|
var options = {
|
|
2540
2511
|
mode: "setup",
|
|
2541
|
-
|
|
2542
|
-
currency: "usd",
|
|
2512
|
+
currency: currencyId,
|
|
2543
2513
|
setupFutureUsage: "off_session",
|
|
2544
2514
|
};
|
|
2545
2515
|
React.useEffect(function () {
|
|
@@ -2575,7 +2545,7 @@ function useSave(_a) {
|
|
|
2575
2545
|
var save = function (_a) {
|
|
2576
2546
|
var plugin = _a.plugin;
|
|
2577
2547
|
return __awaiter(_this, void 0, void 0, function () {
|
|
2578
|
-
var submitError, response, clientSecret, intentResponse, paymentMethodId, paymentMethodResponse
|
|
2548
|
+
var submitError, response, clientSecret, intentResponse, paymentMethodId, paymentMethodResponse;
|
|
2579
2549
|
var _b, _c;
|
|
2580
2550
|
return __generator(this, function (_d) {
|
|
2581
2551
|
switch (_d.label) {
|
|
@@ -2636,8 +2606,9 @@ function useSave(_a) {
|
|
|
2636
2606
|
});
|
|
2637
2607
|
return [3 /*break*/, 7];
|
|
2638
2608
|
case 5:
|
|
2639
|
-
|
|
2640
|
-
console.error(
|
|
2609
|
+
_d.sent();
|
|
2610
|
+
// console.error(error);
|
|
2611
|
+
console.log("fancy error right here");
|
|
2641
2612
|
return [3 /*break*/, 7];
|
|
2642
2613
|
case 6:
|
|
2643
2614
|
setIsSaving(false);
|
|
@@ -2729,7 +2700,7 @@ var PaymentOptionContainer = styled__default["default"].div(templateObject_1$5 |
|
|
|
2729
2700
|
});
|
|
2730
2701
|
var templateObject_1$5;
|
|
2731
2702
|
|
|
2732
|
-
function useRemovePaymentMethod(paymentPlugins, token, apiHost, accountId) {
|
|
2703
|
+
function useRemovePaymentMethod(paymentPlugins, token, apiHost, entityId, accountId) {
|
|
2733
2704
|
var _this = this;
|
|
2734
2705
|
var queryClient = reactQuery.useQueryClient();
|
|
2735
2706
|
var showErrorNotification = common.useErrorNotification();
|
|
@@ -2753,7 +2724,7 @@ function useRemovePaymentMethod(paymentPlugins, token, apiHost, accountId) {
|
|
|
2753
2724
|
})
|
|
2754
2725
|
.then(function () {
|
|
2755
2726
|
showSuccessNotification("Payment method was removed", "Success");
|
|
2756
|
-
queryClient.setQueryData(common.QueryKeyFactory.default.accountPaymentMethodKey, null);
|
|
2727
|
+
queryClient.setQueryData(common.QueryKeyFactory.default.accountPaymentMethodKey(token, entityId), null);
|
|
2757
2728
|
})
|
|
2758
2729
|
.catch(function (error) {
|
|
2759
2730
|
showErrorNotification(error.message, "Error removing payment method");
|
|
@@ -2770,18 +2741,20 @@ function useRemovePaymentMethod(paymentPlugins, token, apiHost, accountId) {
|
|
|
2770
2741
|
|
|
2771
2742
|
var Panel = antd.Collapse.Panel;
|
|
2772
2743
|
var PaymentForm = function (_a) {
|
|
2744
|
+
var _b;
|
|
2773
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;
|
|
2774
2746
|
// Local state
|
|
2775
|
-
var
|
|
2776
|
-
var
|
|
2747
|
+
var _c = React.useState(), selectedPaymentMethod = _c[0], setSelectedPaymentMethod = _c[1];
|
|
2748
|
+
var _d = React.useState(false), showPaymentMethodForm = _d[0], setShowPaymentMethodForm = _d[1];
|
|
2777
2749
|
var paying = !!(quote || invoice);
|
|
2750
|
+
var currencyId = (_b = ((quote === null || quote === void 0 ? void 0 : quote.currencyId) || (invoice === null || invoice === void 0 ? void 0 : invoice.currencyId))) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
2778
2751
|
// Hooks
|
|
2779
2752
|
var apiHost = React.useContext(BunnyContext).apiHost;
|
|
2780
2753
|
var token = useToken();
|
|
2781
|
-
var storedPaymentMethod = usePaymentMethod(graphQLClient).data;
|
|
2754
|
+
var storedPaymentMethod = usePaymentMethod(graphQLClient, entityId, overrideToken || token).data;
|
|
2782
2755
|
var isPaymentMethodFetched = storedPaymentMethod !== undefined;
|
|
2783
|
-
var
|
|
2784
|
-
var onClickRemove = useRemovePaymentMethod(paymentMethodAllowedPlugins || [], overrideToken || token, apiHost, accountId);
|
|
2756
|
+
var _e = usePaymentPlugins({ entityId: entityId, apiHost: apiHost, token: overrideToken || token }), paymentMethodAllowedPlugins = _e.paymentMethodAllowedPlugins, arePluginsFetched = _e.isFetched;
|
|
2757
|
+
var onClickRemove = useRemovePaymentMethod(paymentMethodAllowedPlugins || [], overrideToken || token, apiHost, entityId, accountId);
|
|
2785
2758
|
var queryClient = reactQuery.useQueryClient();
|
|
2786
2759
|
// Set default plugin
|
|
2787
2760
|
React.useEffect(function () {
|
|
@@ -2816,26 +2789,29 @@ var PaymentForm = function (_a) {
|
|
|
2816
2789
|
};
|
|
2817
2790
|
var handleSavePaymentMethod = function () {
|
|
2818
2791
|
queryClient.invalidateQueries({
|
|
2819
|
-
queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey,
|
|
2792
|
+
queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
|
|
2820
2793
|
});
|
|
2821
2794
|
onSavePaymentMethod === null || onSavePaymentMethod === void 0 ? void 0 : onSavePaymentMethod();
|
|
2822
2795
|
setShowPaymentMethodForm(false);
|
|
2823
2796
|
};
|
|
2797
|
+
if (!currencyId) {
|
|
2798
|
+
return jsxRuntime.jsx("div", { children: "No currency id found from quote or invoice" });
|
|
2799
|
+
}
|
|
2824
2800
|
return (jsxRuntime.jsx(PaymentContext.Provider, __assign({ value: {
|
|
2825
2801
|
onClickCancel: function () { return setShowPaymentMethodForm(false); },
|
|
2826
2802
|
accountId: accountId,
|
|
2827
2803
|
overrideToken: overrideToken,
|
|
2828
2804
|
storedPaymentMethod: storedPaymentMethod,
|
|
2829
2805
|
customCheckoutFunction: customCheckoutFunction,
|
|
2830
|
-
} }, { 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 }) }))) : (
|
|
2806
|
+
} }, { 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 }) }))) : (
|
|
2831
2807
|
//if not paying and payment method is saved, show Collapse
|
|
2832
2808
|
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 () {
|
|
2833
2809
|
setShowPaymentMethodForm(true);
|
|
2834
2810
|
}, 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") })))] }) })) })) })));
|
|
2835
2811
|
};
|
|
2836
2812
|
function StripeWrapper(_a) {
|
|
2837
|
-
var children = _a.children, plugin = _a.plugin, token = _a.token, apiHost = _a.apiHost, accountId = _a.accountId;
|
|
2838
|
-
var _b = useStripePlugin(plugin, token, apiHost, accountId), stripe = _b.stripe, options = _b.options;
|
|
2813
|
+
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;
|
|
2839
2815
|
return (jsxRuntime.jsx(reactStripeJs.Elements, __assign({ options: options, stripe: stripe }, { children: children })));
|
|
2840
2816
|
}
|
|
2841
2817
|
|
|
@@ -2876,7 +2852,7 @@ function ActualInvoice() {
|
|
|
2876
2852
|
var isMobile = common.useIsMobile(isInvoicePayable ? common.BreakpointNumbers.lg : undefined);
|
|
2877
2853
|
var onSuccess = function () {
|
|
2878
2854
|
queryClient.invalidateQueries({
|
|
2879
|
-
queryKey: common.QueryKeyFactory.default.transactionsKey(),
|
|
2855
|
+
queryKey: common.QueryKeyFactory.default.transactionsKey(token),
|
|
2880
2856
|
});
|
|
2881
2857
|
queryClient.invalidateQueries({
|
|
2882
2858
|
queryKey: common.QueryKeyFactory.default.createFormattedInvoiceKey(token, id),
|
|
@@ -3050,7 +3026,7 @@ var useSigningComplete = function (_a) {
|
|
|
3050
3026
|
React.useEffect(function () {
|
|
3051
3027
|
if (data && eventParam === "signing_complete") {
|
|
3052
3028
|
data.state = "ACCEPTED";
|
|
3053
|
-
queryClient.setQueryData(common.QueryKeyFactory.default.
|
|
3029
|
+
queryClient.setQueryData(common.QueryKeyFactory.default.createQuoteKey(token), data);
|
|
3054
3030
|
}
|
|
3055
3031
|
}, [data, eventParam, queryClient, token]);
|
|
3056
3032
|
};
|
|
@@ -3673,13 +3649,13 @@ var PaymentMethod = function (_a) {
|
|
|
3673
3649
|
var showSuccessNotification = common.useSuccessNotification();
|
|
3674
3650
|
var handleAllErrorFormats = common.useAllErrorFormats(onTokenExpired);
|
|
3675
3651
|
var isMobile = common.useIsMobile();
|
|
3676
|
-
var data = usePaymentMethod(graphQLClient).data;
|
|
3677
|
-
var onClickRemove = useRemovePaymentMethod(paymentPlugins || [], token, apiHost);
|
|
3652
|
+
var data = usePaymentMethod(graphQLClient, entityId, token).data;
|
|
3653
|
+
var onClickRemove = useRemovePaymentMethod(paymentPlugins || [], token, apiHost, entityId);
|
|
3678
3654
|
// Local state
|
|
3679
3655
|
var _e = React.useState(false), showModal = _e[0], setShowModal = _e[1];
|
|
3680
3656
|
var onSuccess = function () {
|
|
3681
3657
|
queryClient.invalidateQueries({
|
|
3682
|
-
queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey,
|
|
3658
|
+
queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
|
|
3683
3659
|
});
|
|
3684
3660
|
setShowModal(false);
|
|
3685
3661
|
showSuccessNotification("Your payment method has been saved");
|
|
@@ -3925,7 +3901,7 @@ var Checkout = function (_a) {
|
|
|
3925
3901
|
((taxationRequiredAccountFields === null || taxationRequiredAccountFields === void 0 ? void 0 : taxationRequiredAccountFields.length) || 0) > 0,
|
|
3926
3902
|
}), account = _g.data, isLoadingAccount = _g.isLoading;
|
|
3927
3903
|
reactQuery.useQuery({
|
|
3928
|
-
queryKey: queryKeyFactory.createQuoteTaxCalculateKey(quote === null || quote === void 0 ? void 0 : quote.id),
|
|
3904
|
+
queryKey: queryKeyFactory.createQuoteTaxCalculateKey(token, quote === null || quote === void 0 ? void 0 : quote.id),
|
|
3929
3905
|
queryFn: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
3930
3906
|
var updatedQuote;
|
|
3931
3907
|
return __generator(this, function (_a) {
|
|
@@ -3941,7 +3917,7 @@ var Checkout = function (_a) {
|
|
|
3941
3917
|
updatedQuote = _a.sent();
|
|
3942
3918
|
if (updatedQuote) {
|
|
3943
3919
|
queryClient.setQueryData(queryKeyFactory.createObjectKey("editingQuote", updatedQuote.id), updatedQuote);
|
|
3944
|
-
queryClient.setQueryData(queryKeyFactory.calculatedPricesKey(quantity, selectedPriceList === null || selectedPriceList === void 0 ? void 0 : selectedPriceList.id), updatedQuote);
|
|
3920
|
+
queryClient.setQueryData(queryKeyFactory.calculatedPricesKey(token, quantity, selectedPriceList === null || selectedPriceList === void 0 ? void 0 : selectedPriceList.id), updatedQuote);
|
|
3945
3921
|
}
|
|
3946
3922
|
_a.label = 2;
|
|
3947
3923
|
case 2: return [2 /*return*/, {}];
|
|
@@ -3985,7 +3961,7 @@ var accountSignup = function (_a) {
|
|
|
3985
3961
|
paymentMethodId: paymentMethodId,
|
|
3986
3962
|
priceListCode: priceListCode,
|
|
3987
3963
|
};
|
|
3988
|
-
return [4 /*yield*/, gqlRequest({
|
|
3964
|
+
return [4 /*yield*/, common.gqlRequest({
|
|
3989
3965
|
query: MUTATION$3(),
|
|
3990
3966
|
token: token,
|
|
3991
3967
|
vars: vars,
|
|
@@ -4017,7 +3993,7 @@ var quoteAccountSignup = function (_a) {
|
|
|
4017
3993
|
accountName: accountName,
|
|
4018
3994
|
billingContact: billingContact,
|
|
4019
3995
|
};
|
|
4020
|
-
return [4 /*yield*/, gqlRequest({
|
|
3996
|
+
return [4 /*yield*/, common.gqlRequest({
|
|
4021
3997
|
query: MUTATION$2(),
|
|
4022
3998
|
token: token,
|
|
4023
3999
|
vars: vars,
|
|
@@ -4041,7 +4017,7 @@ var getPriceList = function (_a) {
|
|
|
4041
4017
|
var response;
|
|
4042
4018
|
return __generator(this, function (_b) {
|
|
4043
4019
|
switch (_b.label) {
|
|
4044
|
-
case 0: return [4 /*yield*/, gqlRequest({
|
|
4020
|
+
case 0: return [4 /*yield*/, common.gqlRequest({
|
|
4045
4021
|
query: MUTATION$1(),
|
|
4046
4022
|
token: token,
|
|
4047
4023
|
vars: { code: code },
|
|
@@ -4078,8 +4054,8 @@ function InitialSignupForm(_a) {
|
|
|
4078
4054
|
|
|
4079
4055
|
var Title = antd.Typography.Title, Text$4 = antd.Typography.Text;
|
|
4080
4056
|
function PaymentSuccessDisplay(_a) {
|
|
4081
|
-
var amountPaid = _a.amountPaid, className = _a.className, companyName = _a.companyName, returnUrl = _a.returnUrl, style = _a.style;
|
|
4082
|
-
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,
|
|
4057
|
+
var amountPaid = _a.amountPaid, className = _a.className, companyName = _a.companyName, returnUrl = _a.returnUrl, style = _a.style, currencyId = _a.currencyId;
|
|
4058
|
+
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] })))] })));
|
|
4083
4059
|
}
|
|
4084
4060
|
|
|
4085
4061
|
var Text$3 = antd.Typography.Text;
|
|
@@ -4105,7 +4081,7 @@ function Signup(_a) {
|
|
|
4105
4081
|
var _h = React.useState(false), proceedingToPayment = _h[0], setProceedingToPayment = _h[1];
|
|
4106
4082
|
var _j = React.useState(false), purchaseSucceeded = _j[0], setPurchaseSucceeded = _j[1];
|
|
4107
4083
|
var _k = React.useState(undefined), paymentMethodGraphQLClient = _k[0], setPaymentMethodGraphQLClient = _k[1];
|
|
4108
|
-
var paymentMethod = usePaymentMethod(paymentMethodGraphQLClient || graphQLClient).data;
|
|
4084
|
+
var paymentMethod = usePaymentMethod(paymentMethodGraphQLClient || graphQLClient, entityId, token).data;
|
|
4109
4085
|
var queryClient = reactQuery.useQueryClient();
|
|
4110
4086
|
// Queries
|
|
4111
4087
|
var priceListData = reactQuery.useQuery({
|
|
@@ -4140,7 +4116,7 @@ function Signup(_a) {
|
|
|
4140
4116
|
// We must invalidate the accountPaymentMethodKey query in order to clear payment methods from the provided api token,
|
|
4141
4117
|
// to instead use paymentMethods from portalSessionToken.
|
|
4142
4118
|
queryClient.invalidateQueries({
|
|
4143
|
-
queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey,
|
|
4119
|
+
queryKey: common.QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
|
|
4144
4120
|
});
|
|
4145
4121
|
setProceedingToPayment(false);
|
|
4146
4122
|
setQuote(data.quote);
|
|
@@ -4199,7 +4175,7 @@ function Signup(_a) {
|
|
|
4199
4175
|
var children = _a.children, className = _a.className, style = _a.style;
|
|
4200
4176
|
return isCardEnabled ? (jsxRuntime.jsx(Card, __assign({ className: className, style: style }, { children: children }))) : (jsxRuntime.jsx("div", __assign({ className: className, style: style }, { children: children })));
|
|
4201
4177
|
};
|
|
4202
|
-
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
|
|
4178
|
+
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
|
|
4203
4179
|
? "items-center justify-center my-12"
|
|
4204
4180
|
: "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 }) })) }))] }))) })));
|
|
4205
4181
|
}
|
|
@@ -4806,12 +4782,12 @@ var Subscriptions = function (_a) {
|
|
|
4806
4782
|
var token = useToken();
|
|
4807
4783
|
// Queries
|
|
4808
4784
|
var _d = reactQuery.useQuery({
|
|
4809
|
-
queryKey: common.QueryKeyFactory.default.createTableKey("subscriptions"),
|
|
4785
|
+
queryKey: common.QueryKeyFactory.default.createTableKey(token, "subscriptions"),
|
|
4810
4786
|
queryFn: function () { return getSubscriptions({ entityId: entityId, token: token, apiHost: apiHost }); },
|
|
4811
4787
|
enabled: Boolean(entityId),
|
|
4812
4788
|
}), rawSubscriptions = _d.data, subscriptionsAreLoading = _d.isLoading;
|
|
4813
4789
|
var _e = reactQuery.useQuery({
|
|
4814
|
-
queryKey: common.QueryKeyFactory.default.planChangeOptionsKey(),
|
|
4790
|
+
queryKey: common.QueryKeyFactory.default.planChangeOptionsKey(token),
|
|
4815
4791
|
queryFn: function () { return getPlanChangeOptions({ token: token, apiHost: apiHost }); },
|
|
4816
4792
|
enabled: Boolean(onChangePlanClick),
|
|
4817
4793
|
}), planChangeOptions = _e.data, arePlanChangeOptionsLoading = _e.isLoading;
|
|
@@ -4907,7 +4883,7 @@ var BillingDetails = function (_a) {
|
|
|
4907
4883
|
var values = antd.Form.useWatch([], form);
|
|
4908
4884
|
// Queries
|
|
4909
4885
|
var _g = reactQuery.useQuery({
|
|
4910
|
-
queryKey:
|
|
4886
|
+
queryKey: common.QueryKeyFactory.default.billingDetailsKey(token, entityId),
|
|
4911
4887
|
queryFn: function () { return getBillingDetails({ token: token, apiHost: apiHost }); },
|
|
4912
4888
|
}), billingDetails = _g.data, isLoadingBillingDetails = _g.isLoading;
|
|
4913
4889
|
var _h = reactQuery.useMutation({
|
|
@@ -4931,7 +4907,7 @@ var BillingDetails = function (_a) {
|
|
|
4931
4907
|
})];
|
|
4932
4908
|
case 1:
|
|
4933
4909
|
updatedBillingDetails = _a.sent();
|
|
4934
|
-
queryClient.setQueryData(
|
|
4910
|
+
queryClient.setQueryData(common.QueryKeyFactory.default.billingDetailsKey(token, entityId), function (old) {
|
|
4935
4911
|
return __assign(__assign({}, old), updatedBillingDetails.billingDetails);
|
|
4936
4912
|
});
|
|
4937
4913
|
return [2 /*return*/, updatedBillingDetails];
|
|
@@ -4941,7 +4917,7 @@ var BillingDetails = function (_a) {
|
|
|
4941
4917
|
onSuccess: function () {
|
|
4942
4918
|
showSuccessNotification("Your account details have been saved");
|
|
4943
4919
|
queryClient.invalidateQueries({
|
|
4944
|
-
queryKey:
|
|
4920
|
+
queryKey: common.QueryKeyFactory.default.taxationRequiredAccountFieldsKey(token, entityId),
|
|
4945
4921
|
});
|
|
4946
4922
|
},
|
|
4947
4923
|
}), updateBillingDetails = _h.mutate, isUpdatingBillingDetails = _h.isPending;
|
|
@@ -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,3 +1,3 @@
|
|
|
1
1
|
import { PluginData } from "@bunnyapp/common";
|
|
2
|
-
declare function useRemovePaymentMethod(paymentPlugins: PluginData[], token: string, apiHost: string, accountId?: string): (data: any) => Promise<void>;
|
|
2
|
+
declare function useRemovePaymentMethod(paymentPlugins: PluginData[], token: string, apiHost: string, entityId: string, accountId?: string): (data: any) => Promise<void>;
|
|
3
3
|
export default useRemovePaymentMethod;
|
|
@@ -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,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLClient } from "graphql-request";
|
|
2
|
-
export declare const usePaymentMethod: (graphQLClient: GraphQLClient) => import("@tanstack/react-query/build/legacy/types").UseQueryResult<any, Error>;
|
|
2
|
+
export declare const usePaymentMethod: (graphQLClient: GraphQLClient, entityId: string, token: string) => import("@tanstack/react-query/build/legacy/types").UseQueryResult<any, Error>;
|
package/dist/esm/index.js
CHANGED
|
@@ -4,11 +4,11 @@ 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
|
|
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, PricingModel, ChargeType } 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';
|
|
11
|
-
import
|
|
11
|
+
import { GraphQLClient } from 'graphql-request';
|
|
12
12
|
import { useElements, useStripe, PaymentElement, Elements } from '@stripe/react-stripe-js';
|
|
13
13
|
import { loadStripe } from '@stripe/stripe-js/pure';
|
|
14
14
|
import { capitalize, startCase, cloneDeep, omit } from 'lodash';
|
|
@@ -1575,7 +1575,7 @@ var getBranding = function (_a) {
|
|
|
1575
1575
|
var response;
|
|
1576
1576
|
return __generator(this, function (_b) {
|
|
1577
1577
|
switch (_b.label) {
|
|
1578
|
-
case 0: return [4 /*yield*/, gqlRequest
|
|
1578
|
+
case 0: return [4 /*yield*/, gqlRequest({
|
|
1579
1579
|
query: MUTATION$8,
|
|
1580
1580
|
token: token,
|
|
1581
1581
|
apiHost: apiHost,
|
|
@@ -1624,7 +1624,7 @@ function ContextualWrapper(_a) {
|
|
|
1624
1624
|
var _b = useState(false), interFontLoaded = _b[0], setInterFontLoaded = _b[1];
|
|
1625
1625
|
var _c = useContext(BunnyContext), apiHost = _c.apiHost, token = _c.token;
|
|
1626
1626
|
var branding = useQuery({
|
|
1627
|
-
queryKey: QueryKeyFactory.default.brandingKey,
|
|
1627
|
+
queryKey: QueryKeyFactory.default.brandingKey(token),
|
|
1628
1628
|
queryFn: function () { return getBranding({ token: token, apiHost: apiHost }); },
|
|
1629
1629
|
}).data;
|
|
1630
1630
|
var isMobile = useIsMobile();
|
|
@@ -1842,9 +1842,9 @@ function InvoicePDF(_a) {
|
|
|
1842
1842
|
}
|
|
1843
1843
|
|
|
1844
1844
|
var paymentMethodsQuery = "query paymentMethods ($filter: String, $first: Int, $sort: String) {\n paymentMethods (filter: $filter, first: $first, sort: $sort) {\n nodes {\n id\n disabled\n pluginId\n accountId\n expirationDate\n plugin {\n guid\n id\n }\n state\n metadata {\n issuer\n identifier\n kind\n description\n icon\n }\n }\n }\n}";
|
|
1845
|
-
var usePaymentMethod = function (graphQLClient) {
|
|
1845
|
+
var usePaymentMethod = function (graphQLClient, entityId, token) {
|
|
1846
1846
|
var result = useQuery({
|
|
1847
|
-
queryKey: QueryKeyFactory.default.accountPaymentMethodKey,
|
|
1847
|
+
queryKey: QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
|
|
1848
1848
|
queryFn: function () {
|
|
1849
1849
|
return graphQLClient
|
|
1850
1850
|
.request(paymentMethodsQuery, {
|
|
@@ -1865,7 +1865,7 @@ var usePaymentMethod = function (graphQLClient) {
|
|
|
1865
1865
|
var usePlugins = function (_a) {
|
|
1866
1866
|
var entityId = _a.entityId, apiHost = _a.apiHost, token = _a.token;
|
|
1867
1867
|
var response = useQuery({
|
|
1868
|
-
queryKey: QueryKeyFactory.default.pluginsKey,
|
|
1868
|
+
queryKey: QueryKeyFactory.default.pluginsKey(token),
|
|
1869
1869
|
queryFn: function () {
|
|
1870
1870
|
var plugins = getPlugins({
|
|
1871
1871
|
entityId: entityId,
|
|
@@ -1910,34 +1910,6 @@ var getQuoteAmountDue = function (quote) {
|
|
|
1910
1910
|
return quote.amountDue;
|
|
1911
1911
|
};
|
|
1912
1912
|
|
|
1913
|
-
var DEFAULT_HEADERS = {
|
|
1914
|
-
"Content-type": "application/json; charset=utf-8",
|
|
1915
|
-
};
|
|
1916
|
-
// !!! Duplicated from @bunnyapp/common due to bug in signup. Uses BunnyProvider token instead of apiToken.
|
|
1917
|
-
var gqlRequest = function (_a) {
|
|
1918
|
-
var query = _a.query, _b = _a.vars, vars = _b === void 0 ? {} : _b, headers = _a.headers, token = _a.token, isInPreviewMode = _a.isInPreviewMode, apiHost = _a.apiHost;
|
|
1919
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
1920
|
-
var graphqlEndpoint, requestHeaders, authorizationHeader, error_1;
|
|
1921
|
-
return __generator(this, function (_c) {
|
|
1922
|
-
switch (_c.label) {
|
|
1923
|
-
case 0:
|
|
1924
|
-
_c.trys.push([0, 2, , 3]);
|
|
1925
|
-
graphqlEndpoint = DEFAULT_CONFIG.graphqlEndpoint;
|
|
1926
|
-
requestHeaders = headers || DEFAULT_HEADERS;
|
|
1927
|
-
authorizationHeader = "Bearer ".concat(token);
|
|
1928
|
-
if (!requestHeaders.Authorization && !isInPreviewMode)
|
|
1929
|
-
requestHeaders.Authorization = authorizationHeader;
|
|
1930
|
-
return [4 /*yield*/, request("".concat(apiHost).concat(graphqlEndpoint), query, vars, requestHeaders)];
|
|
1931
|
-
case 1: return [2 /*return*/, _c.sent()];
|
|
1932
|
-
case 2:
|
|
1933
|
-
error_1 = _c.sent();
|
|
1934
|
-
throw error_1;
|
|
1935
|
-
case 3: return [2 /*return*/];
|
|
1936
|
-
}
|
|
1937
|
-
});
|
|
1938
|
-
});
|
|
1939
|
-
};
|
|
1940
|
-
|
|
1941
1913
|
var MUTATION$7 = "\n mutation checkout(\n $invoiceId: ID,\n $quoteId: ID,\n $paymentMethodId: ID,\n $paymentMethodData: CheckoutPaymentMethodAttributes\n ) {\n checkout(\n invoiceId: $invoiceId,\n quoteId: $quoteId,\n paymentMethodId: $paymentMethodId,\n paymentMethodData: $paymentMethodData\n ) {\n invoice {\n id\n state\n amount\n amountDue\n }\n payment {\n id\n state\n amount\n }\n paymentApplication {\n id\n invoiceId\n paymentId\n }\n transaction {\n id\n amount\n }\n }\n }\n";
|
|
1942
1914
|
var checkout = function (_a) {
|
|
1943
1915
|
var quoteId = _a.quoteId, invoiceId = _a.invoiceId, paymentMethodId = _a.paymentMethodId, paymentMethodData = _a.paymentMethodData, token = _a.token, apiHost = _a.apiHost;
|
|
@@ -2070,7 +2042,7 @@ var ActualCheckoutFooter = function (_a) {
|
|
|
2070
2042
|
var _b = useState(false), isPaying = _b[0], setIsPaying = _b[1];
|
|
2071
2043
|
var storedPaymentMethod = useContext(PaymentContext).storedPaymentMethod;
|
|
2072
2044
|
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.
|
|
2045
|
+
var currencyId = (quote === null || quote === void 0 ? void 0 : quote.currencyId) || (invoice === null || invoice === void 0 ? void 0 : invoice.currencyId);
|
|
2074
2046
|
// Payment hooks
|
|
2075
2047
|
var payDemoPay = usePay$1({
|
|
2076
2048
|
onPaymentSuccess: onPaymentSuccess,
|
|
@@ -2504,13 +2476,12 @@ var fetchStripeKey = function (plugin, token, apiHost, accountId) { return __awa
|
|
|
2504
2476
|
});
|
|
2505
2477
|
}); };
|
|
2506
2478
|
loadStripe.setLoadParameters({ advancedFraudSignals: false });
|
|
2507
|
-
var useStripePlugin = function (plugin, token, apiHost, accountId) {
|
|
2479
|
+
var useStripePlugin = function (plugin, token, apiHost, currencyId, accountId) {
|
|
2508
2480
|
var _a = useState(null), stripe = _a[0], setStripe = _a[1];
|
|
2509
2481
|
var showErrorNotification = useErrorNotification();
|
|
2510
2482
|
var options = {
|
|
2511
2483
|
mode: "setup",
|
|
2512
|
-
|
|
2513
|
-
currency: "usd",
|
|
2484
|
+
currency: currencyId,
|
|
2514
2485
|
setupFutureUsage: "off_session",
|
|
2515
2486
|
};
|
|
2516
2487
|
useEffect(function () {
|
|
@@ -2546,7 +2517,7 @@ function useSave(_a) {
|
|
|
2546
2517
|
var save = function (_a) {
|
|
2547
2518
|
var plugin = _a.plugin;
|
|
2548
2519
|
return __awaiter(_this, void 0, void 0, function () {
|
|
2549
|
-
var submitError, response, clientSecret, intentResponse, paymentMethodId, paymentMethodResponse
|
|
2520
|
+
var submitError, response, clientSecret, intentResponse, paymentMethodId, paymentMethodResponse;
|
|
2550
2521
|
var _b, _c;
|
|
2551
2522
|
return __generator(this, function (_d) {
|
|
2552
2523
|
switch (_d.label) {
|
|
@@ -2607,8 +2578,9 @@ function useSave(_a) {
|
|
|
2607
2578
|
});
|
|
2608
2579
|
return [3 /*break*/, 7];
|
|
2609
2580
|
case 5:
|
|
2610
|
-
|
|
2611
|
-
console.error(
|
|
2581
|
+
_d.sent();
|
|
2582
|
+
// console.error(error);
|
|
2583
|
+
console.log("fancy error right here");
|
|
2612
2584
|
return [3 /*break*/, 7];
|
|
2613
2585
|
case 6:
|
|
2614
2586
|
setIsSaving(false);
|
|
@@ -2700,7 +2672,7 @@ var PaymentOptionContainer = styled.div(templateObject_1$5 || (templateObject_1$
|
|
|
2700
2672
|
});
|
|
2701
2673
|
var templateObject_1$5;
|
|
2702
2674
|
|
|
2703
|
-
function useRemovePaymentMethod(paymentPlugins, token, apiHost, accountId) {
|
|
2675
|
+
function useRemovePaymentMethod(paymentPlugins, token, apiHost, entityId, accountId) {
|
|
2704
2676
|
var _this = this;
|
|
2705
2677
|
var queryClient = useQueryClient();
|
|
2706
2678
|
var showErrorNotification = useErrorNotification();
|
|
@@ -2724,7 +2696,7 @@ function useRemovePaymentMethod(paymentPlugins, token, apiHost, accountId) {
|
|
|
2724
2696
|
})
|
|
2725
2697
|
.then(function () {
|
|
2726
2698
|
showSuccessNotification("Payment method was removed", "Success");
|
|
2727
|
-
queryClient.setQueryData(QueryKeyFactory.default.accountPaymentMethodKey, null);
|
|
2699
|
+
queryClient.setQueryData(QueryKeyFactory.default.accountPaymentMethodKey(token, entityId), null);
|
|
2728
2700
|
})
|
|
2729
2701
|
.catch(function (error) {
|
|
2730
2702
|
showErrorNotification(error.message, "Error removing payment method");
|
|
@@ -2741,18 +2713,20 @@ function useRemovePaymentMethod(paymentPlugins, token, apiHost, accountId) {
|
|
|
2741
2713
|
|
|
2742
2714
|
var Panel = Collapse.Panel;
|
|
2743
2715
|
var PaymentForm = function (_a) {
|
|
2716
|
+
var _b;
|
|
2744
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;
|
|
2745
2718
|
// Local state
|
|
2746
|
-
var
|
|
2747
|
-
var
|
|
2719
|
+
var _c = useState(), selectedPaymentMethod = _c[0], setSelectedPaymentMethod = _c[1];
|
|
2720
|
+
var _d = useState(false), showPaymentMethodForm = _d[0], setShowPaymentMethodForm = _d[1];
|
|
2748
2721
|
var paying = !!(quote || invoice);
|
|
2722
|
+
var currencyId = (_b = ((quote === null || quote === void 0 ? void 0 : quote.currencyId) || (invoice === null || invoice === void 0 ? void 0 : invoice.currencyId))) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
2749
2723
|
// Hooks
|
|
2750
2724
|
var apiHost = useContext(BunnyContext).apiHost;
|
|
2751
2725
|
var token = useToken();
|
|
2752
|
-
var storedPaymentMethod = usePaymentMethod(graphQLClient).data;
|
|
2726
|
+
var storedPaymentMethod = usePaymentMethod(graphQLClient, entityId, overrideToken || token).data;
|
|
2753
2727
|
var isPaymentMethodFetched = storedPaymentMethod !== undefined;
|
|
2754
|
-
var
|
|
2755
|
-
var onClickRemove = useRemovePaymentMethod(paymentMethodAllowedPlugins || [], overrideToken || token, apiHost, accountId);
|
|
2728
|
+
var _e = usePaymentPlugins({ entityId: entityId, apiHost: apiHost, token: overrideToken || token }), paymentMethodAllowedPlugins = _e.paymentMethodAllowedPlugins, arePluginsFetched = _e.isFetched;
|
|
2729
|
+
var onClickRemove = useRemovePaymentMethod(paymentMethodAllowedPlugins || [], overrideToken || token, apiHost, entityId, accountId);
|
|
2756
2730
|
var queryClient = useQueryClient();
|
|
2757
2731
|
// Set default plugin
|
|
2758
2732
|
useEffect(function () {
|
|
@@ -2787,26 +2761,29 @@ var PaymentForm = function (_a) {
|
|
|
2787
2761
|
};
|
|
2788
2762
|
var handleSavePaymentMethod = function () {
|
|
2789
2763
|
queryClient.invalidateQueries({
|
|
2790
|
-
queryKey: QueryKeyFactory.default.accountPaymentMethodKey,
|
|
2764
|
+
queryKey: QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
|
|
2791
2765
|
});
|
|
2792
2766
|
onSavePaymentMethod === null || onSavePaymentMethod === void 0 ? void 0 : onSavePaymentMethod();
|
|
2793
2767
|
setShowPaymentMethodForm(false);
|
|
2794
2768
|
};
|
|
2769
|
+
if (!currencyId) {
|
|
2770
|
+
return jsx("div", { children: "No currency id found from quote or invoice" });
|
|
2771
|
+
}
|
|
2795
2772
|
return (jsx(PaymentContext.Provider, __assign({ value: {
|
|
2796
2773
|
onClickCancel: function () { return setShowPaymentMethodForm(false); },
|
|
2797
2774
|
accountId: accountId,
|
|
2798
2775
|
overrideToken: overrideToken,
|
|
2799
2776
|
storedPaymentMethod: storedPaymentMethod,
|
|
2800
2777
|
customCheckoutFunction: customCheckoutFunction,
|
|
2801
|
-
} }, { 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 }) }))) : (
|
|
2778
|
+
} }, { 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 }) }))) : (
|
|
2802
2779
|
//if not paying and payment method is saved, show Collapse
|
|
2803
2780
|
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 () {
|
|
2804
2781
|
setShowPaymentMethodForm(true);
|
|
2805
2782
|
}, 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") })))] }) })) })) })));
|
|
2806
2783
|
};
|
|
2807
2784
|
function StripeWrapper(_a) {
|
|
2808
|
-
var children = _a.children, plugin = _a.plugin, token = _a.token, apiHost = _a.apiHost, accountId = _a.accountId;
|
|
2809
|
-
var _b = useStripePlugin(plugin, token, apiHost, accountId), stripe = _b.stripe, options = _b.options;
|
|
2785
|
+
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;
|
|
2810
2787
|
return (jsx(Elements, __assign({ options: options, stripe: stripe }, { children: children })));
|
|
2811
2788
|
}
|
|
2812
2789
|
|
|
@@ -2847,7 +2824,7 @@ function ActualInvoice() {
|
|
|
2847
2824
|
var isMobile = useIsMobile(isInvoicePayable ? BreakpointNumbers.lg : undefined);
|
|
2848
2825
|
var onSuccess = function () {
|
|
2849
2826
|
queryClient.invalidateQueries({
|
|
2850
|
-
queryKey: QueryKeyFactory.default.transactionsKey(),
|
|
2827
|
+
queryKey: QueryKeyFactory.default.transactionsKey(token),
|
|
2851
2828
|
});
|
|
2852
2829
|
queryClient.invalidateQueries({
|
|
2853
2830
|
queryKey: QueryKeyFactory.default.createFormattedInvoiceKey(token, id),
|
|
@@ -2874,7 +2851,7 @@ var getFormattedQuote = function (_a) {
|
|
|
2874
2851
|
var response;
|
|
2875
2852
|
return __generator(this, function (_b) {
|
|
2876
2853
|
switch (_b.label) {
|
|
2877
|
-
case 0: return [4 /*yield*/, gqlRequest
|
|
2854
|
+
case 0: return [4 /*yield*/, gqlRequest({
|
|
2878
2855
|
query: MUTATION$6(),
|
|
2879
2856
|
token: token,
|
|
2880
2857
|
apiHost: apiHost,
|
|
@@ -3021,7 +2998,7 @@ var useSigningComplete = function (_a) {
|
|
|
3021
2998
|
useEffect(function () {
|
|
3022
2999
|
if (data && eventParam === "signing_complete") {
|
|
3023
3000
|
data.state = "ACCEPTED";
|
|
3024
|
-
queryClient.setQueryData(QueryKeyFactory.default.
|
|
3001
|
+
queryClient.setQueryData(QueryKeyFactory.default.createQuoteKey(token), data);
|
|
3025
3002
|
}
|
|
3026
3003
|
}, [data, eventParam, queryClient, token]);
|
|
3027
3004
|
};
|
|
@@ -3202,7 +3179,7 @@ var getQuotes = function (_a) {
|
|
|
3202
3179
|
var response;
|
|
3203
3180
|
return __generator(this, function (_b) {
|
|
3204
3181
|
switch (_b.label) {
|
|
3205
|
-
case 0: return [4 /*yield*/, gqlRequest
|
|
3182
|
+
case 0: return [4 /*yield*/, gqlRequest({
|
|
3206
3183
|
query: QUOTES_QUERY(filter),
|
|
3207
3184
|
token: token,
|
|
3208
3185
|
vars: {},
|
|
@@ -3644,13 +3621,13 @@ var PaymentMethod = function (_a) {
|
|
|
3644
3621
|
var showSuccessNotification = useSuccessNotification();
|
|
3645
3622
|
var handleAllErrorFormats = useAllErrorFormats(onTokenExpired);
|
|
3646
3623
|
var isMobile = useIsMobile();
|
|
3647
|
-
var data = usePaymentMethod(graphQLClient).data;
|
|
3648
|
-
var onClickRemove = useRemovePaymentMethod(paymentPlugins || [], token, apiHost);
|
|
3624
|
+
var data = usePaymentMethod(graphQLClient, entityId, token).data;
|
|
3625
|
+
var onClickRemove = useRemovePaymentMethod(paymentPlugins || [], token, apiHost, entityId);
|
|
3649
3626
|
// Local state
|
|
3650
3627
|
var _e = useState(false), showModal = _e[0], setShowModal = _e[1];
|
|
3651
3628
|
var onSuccess = function () {
|
|
3652
3629
|
queryClient.invalidateQueries({
|
|
3653
|
-
queryKey: QueryKeyFactory.default.accountPaymentMethodKey,
|
|
3630
|
+
queryKey: QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
|
|
3654
3631
|
});
|
|
3655
3632
|
setShowModal(false);
|
|
3656
3633
|
showSuccessNotification("Your payment method has been saved");
|
|
@@ -3695,7 +3672,7 @@ var quoteRecalculateTaxes = function (_a) {
|
|
|
3695
3672
|
switch (_d.label) {
|
|
3696
3673
|
case 0:
|
|
3697
3674
|
vars = { id: quoteId };
|
|
3698
|
-
return [4 /*yield*/, gqlRequest
|
|
3675
|
+
return [4 /*yield*/, gqlRequest({
|
|
3699
3676
|
query: QUOTE_RECALCULATE_TAXES,
|
|
3700
3677
|
token: token,
|
|
3701
3678
|
vars: vars,
|
|
@@ -3720,7 +3697,7 @@ var getTaxationRequiredAccountFields = function (_a) {
|
|
|
3720
3697
|
var _b, _c;
|
|
3721
3698
|
return __generator(this, function (_d) {
|
|
3722
3699
|
switch (_d.label) {
|
|
3723
|
-
case 0: return [4 /*yield*/, gqlRequest
|
|
3700
|
+
case 0: return [4 /*yield*/, gqlRequest({
|
|
3724
3701
|
query: MUTATION$5,
|
|
3725
3702
|
token: token,
|
|
3726
3703
|
apiHost: apiHost,
|
|
@@ -3756,7 +3733,7 @@ var accountUpdate = function (_a) {
|
|
|
3756
3733
|
switch (_c.label) {
|
|
3757
3734
|
case 0:
|
|
3758
3735
|
vars = { id: accountId, attributes: attributes };
|
|
3759
|
-
return [4 /*yield*/, gqlRequest
|
|
3736
|
+
return [4 /*yield*/, gqlRequest({
|
|
3760
3737
|
query: MUTATION$4,
|
|
3761
3738
|
token: token,
|
|
3762
3739
|
vars: vars,
|
|
@@ -3896,7 +3873,7 @@ var Checkout = function (_a) {
|
|
|
3896
3873
|
((taxationRequiredAccountFields === null || taxationRequiredAccountFields === void 0 ? void 0 : taxationRequiredAccountFields.length) || 0) > 0,
|
|
3897
3874
|
}), account = _g.data, isLoadingAccount = _g.isLoading;
|
|
3898
3875
|
useQuery({
|
|
3899
|
-
queryKey: queryKeyFactory.createQuoteTaxCalculateKey(quote === null || quote === void 0 ? void 0 : quote.id),
|
|
3876
|
+
queryKey: queryKeyFactory.createQuoteTaxCalculateKey(token, quote === null || quote === void 0 ? void 0 : quote.id),
|
|
3900
3877
|
queryFn: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
3901
3878
|
var updatedQuote;
|
|
3902
3879
|
return __generator(this, function (_a) {
|
|
@@ -3912,7 +3889,7 @@ var Checkout = function (_a) {
|
|
|
3912
3889
|
updatedQuote = _a.sent();
|
|
3913
3890
|
if (updatedQuote) {
|
|
3914
3891
|
queryClient.setQueryData(queryKeyFactory.createObjectKey("editingQuote", updatedQuote.id), updatedQuote);
|
|
3915
|
-
queryClient.setQueryData(queryKeyFactory.calculatedPricesKey(quantity, selectedPriceList === null || selectedPriceList === void 0 ? void 0 : selectedPriceList.id), updatedQuote);
|
|
3892
|
+
queryClient.setQueryData(queryKeyFactory.calculatedPricesKey(token, quantity, selectedPriceList === null || selectedPriceList === void 0 ? void 0 : selectedPriceList.id), updatedQuote);
|
|
3916
3893
|
}
|
|
3917
3894
|
_a.label = 2;
|
|
3918
3895
|
case 2: return [2 /*return*/, {}];
|
|
@@ -4049,8 +4026,8 @@ function InitialSignupForm(_a) {
|
|
|
4049
4026
|
|
|
4050
4027
|
var Title = Typography.Title, Text$4 = Typography.Text;
|
|
4051
4028
|
function PaymentSuccessDisplay(_a) {
|
|
4052
|
-
var amountPaid = _a.amountPaid, className = _a.className, companyName = _a.companyName, returnUrl = _a.returnUrl, style = _a.style;
|
|
4053
|
-
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,
|
|
4029
|
+
var amountPaid = _a.amountPaid, className = _a.className, companyName = _a.companyName, returnUrl = _a.returnUrl, style = _a.style, currencyId = _a.currencyId;
|
|
4030
|
+
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] })))] })));
|
|
4054
4031
|
}
|
|
4055
4032
|
|
|
4056
4033
|
var Text$3 = Typography.Text;
|
|
@@ -4076,7 +4053,7 @@ function Signup(_a) {
|
|
|
4076
4053
|
var _h = useState(false), proceedingToPayment = _h[0], setProceedingToPayment = _h[1];
|
|
4077
4054
|
var _j = useState(false), purchaseSucceeded = _j[0], setPurchaseSucceeded = _j[1];
|
|
4078
4055
|
var _k = useState(undefined), paymentMethodGraphQLClient = _k[0], setPaymentMethodGraphQLClient = _k[1];
|
|
4079
|
-
var paymentMethod = usePaymentMethod(paymentMethodGraphQLClient || graphQLClient).data;
|
|
4056
|
+
var paymentMethod = usePaymentMethod(paymentMethodGraphQLClient || graphQLClient, entityId, token).data;
|
|
4080
4057
|
var queryClient = useQueryClient();
|
|
4081
4058
|
// Queries
|
|
4082
4059
|
var priceListData = useQuery({
|
|
@@ -4111,7 +4088,7 @@ function Signup(_a) {
|
|
|
4111
4088
|
// We must invalidate the accountPaymentMethodKey query in order to clear payment methods from the provided api token,
|
|
4112
4089
|
// to instead use paymentMethods from portalSessionToken.
|
|
4113
4090
|
queryClient.invalidateQueries({
|
|
4114
|
-
queryKey: QueryKeyFactory.default.accountPaymentMethodKey,
|
|
4091
|
+
queryKey: QueryKeyFactory.default.accountPaymentMethodKey(token, entityId),
|
|
4115
4092
|
});
|
|
4116
4093
|
setProceedingToPayment(false);
|
|
4117
4094
|
setQuote(data.quote);
|
|
@@ -4170,7 +4147,7 @@ function Signup(_a) {
|
|
|
4170
4147
|
var children = _a.children, className = _a.className, style = _a.style;
|
|
4171
4148
|
return isCardEnabled ? (jsx(Card, __assign({ className: className, style: style }, { children: children }))) : (jsx("div", __assign({ className: className, style: style }, { children: children })));
|
|
4172
4149
|
};
|
|
4173
|
-
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
|
|
4150
|
+
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
|
|
4174
4151
|
? "items-center justify-center my-12"
|
|
4175
4152
|
: "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 }) })) }))] }))) })));
|
|
4176
4153
|
}
|
|
@@ -4183,7 +4160,7 @@ var getPlanChangeOptions = function (_a) {
|
|
|
4183
4160
|
var response, planChangeOptions;
|
|
4184
4161
|
return __generator(this, function (_b) {
|
|
4185
4162
|
switch (_b.label) {
|
|
4186
|
-
case 0: return [4 /*yield*/, gqlRequest
|
|
4163
|
+
case 0: return [4 /*yield*/, gqlRequest({
|
|
4187
4164
|
isInPreviewMode: isInPreviewMode,
|
|
4188
4165
|
query: PLAN_CHANGE_OPTIONS_QUERY,
|
|
4189
4166
|
vars: { subscriptionId: upgradingSubscription === null || upgradingSubscription === void 0 ? void 0 : upgradingSubscription.id },
|
|
@@ -4213,7 +4190,7 @@ var getSubscriptions = function (_a) {
|
|
|
4213
4190
|
var _b;
|
|
4214
4191
|
return __generator(this, function (_c) {
|
|
4215
4192
|
switch (_c.label) {
|
|
4216
|
-
case 0: return [4 /*yield*/, gqlRequest
|
|
4193
|
+
case 0: return [4 /*yield*/, gqlRequest({
|
|
4217
4194
|
isInPreviewMode: isInPreviewMode,
|
|
4218
4195
|
query: SUBSCRIPTIONS_QUERY,
|
|
4219
4196
|
token: token,
|
|
@@ -4322,7 +4299,7 @@ var getFeatureUsage = function (_a) {
|
|
|
4322
4299
|
vars = {
|
|
4323
4300
|
id: subscriptionChargeId,
|
|
4324
4301
|
};
|
|
4325
|
-
return [4 /*yield*/, gqlRequest
|
|
4302
|
+
return [4 /*yield*/, gqlRequest({
|
|
4326
4303
|
query: FEATURE_USAGE_MUTATION,
|
|
4327
4304
|
token: token,
|
|
4328
4305
|
vars: vars,
|
|
@@ -4777,12 +4754,12 @@ var Subscriptions = function (_a) {
|
|
|
4777
4754
|
var token = useToken();
|
|
4778
4755
|
// Queries
|
|
4779
4756
|
var _d = useQuery({
|
|
4780
|
-
queryKey: QueryKeyFactory.default.createTableKey("subscriptions"),
|
|
4757
|
+
queryKey: QueryKeyFactory.default.createTableKey(token, "subscriptions"),
|
|
4781
4758
|
queryFn: function () { return getSubscriptions({ entityId: entityId, token: token, apiHost: apiHost }); },
|
|
4782
4759
|
enabled: Boolean(entityId),
|
|
4783
4760
|
}), rawSubscriptions = _d.data, subscriptionsAreLoading = _d.isLoading;
|
|
4784
4761
|
var _e = useQuery({
|
|
4785
|
-
queryKey: QueryKeyFactory.default.planChangeOptionsKey(),
|
|
4762
|
+
queryKey: QueryKeyFactory.default.planChangeOptionsKey(token),
|
|
4786
4763
|
queryFn: function () { return getPlanChangeOptions({ token: token, apiHost: apiHost }); },
|
|
4787
4764
|
enabled: Boolean(onChangePlanClick),
|
|
4788
4765
|
}), planChangeOptions = _e.data, arePlanChangeOptionsLoading = _e.isLoading;
|
|
@@ -4812,7 +4789,7 @@ var billingDetailsUpdate = function (_a) {
|
|
|
4812
4789
|
switch (_c.label) {
|
|
4813
4790
|
case 0:
|
|
4814
4791
|
vars = { attributes: attributes };
|
|
4815
|
-
return [4 /*yield*/, gqlRequest
|
|
4792
|
+
return [4 /*yield*/, gqlRequest({
|
|
4816
4793
|
query: MUTATION,
|
|
4817
4794
|
token: token,
|
|
4818
4795
|
vars: vars,
|
|
@@ -4840,7 +4817,7 @@ var getBillingDetails = function (_a) {
|
|
|
4840
4817
|
var _b;
|
|
4841
4818
|
return __generator(this, function (_c) {
|
|
4842
4819
|
switch (_c.label) {
|
|
4843
|
-
case 0: return [4 /*yield*/, gqlRequest
|
|
4820
|
+
case 0: return [4 /*yield*/, gqlRequest({
|
|
4844
4821
|
query: billingDetailsQuery(),
|
|
4845
4822
|
token: token,
|
|
4846
4823
|
apiHost: apiHost,
|
|
@@ -4878,7 +4855,7 @@ var BillingDetails = function (_a) {
|
|
|
4878
4855
|
var values = Form.useWatch([], form);
|
|
4879
4856
|
// Queries
|
|
4880
4857
|
var _g = useQuery({
|
|
4881
|
-
queryKey:
|
|
4858
|
+
queryKey: QueryKeyFactory.default.billingDetailsKey(token, entityId),
|
|
4882
4859
|
queryFn: function () { return getBillingDetails({ token: token, apiHost: apiHost }); },
|
|
4883
4860
|
}), billingDetails = _g.data, isLoadingBillingDetails = _g.isLoading;
|
|
4884
4861
|
var _h = useMutation({
|
|
@@ -4902,7 +4879,7 @@ var BillingDetails = function (_a) {
|
|
|
4902
4879
|
})];
|
|
4903
4880
|
case 1:
|
|
4904
4881
|
updatedBillingDetails = _a.sent();
|
|
4905
|
-
queryClient.setQueryData(
|
|
4882
|
+
queryClient.setQueryData(QueryKeyFactory.default.billingDetailsKey(token, entityId), function (old) {
|
|
4906
4883
|
return __assign(__assign({}, old), updatedBillingDetails.billingDetails);
|
|
4907
4884
|
});
|
|
4908
4885
|
return [2 /*return*/, updatedBillingDetails];
|
|
@@ -4912,7 +4889,7 @@ var BillingDetails = function (_a) {
|
|
|
4912
4889
|
onSuccess: function () {
|
|
4913
4890
|
showSuccessNotification("Your account details have been saved");
|
|
4914
4891
|
queryClient.invalidateQueries({
|
|
4915
|
-
queryKey:
|
|
4892
|
+
queryKey: QueryKeyFactory.default.taxationRequiredAccountFieldsKey(token, entityId),
|
|
4916
4893
|
});
|
|
4917
4894
|
},
|
|
4918
4895
|
}), updateBillingDetails = _h.mutate, isUpdatingBillingDetails = _h.isPending;
|
|
@@ -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,3 +1,3 @@
|
|
|
1
1
|
import { PluginData } from "@bunnyapp/common";
|
|
2
|
-
declare function useRemovePaymentMethod(paymentPlugins: PluginData[], token: string, apiHost: string, accountId?: string): (data: any) => Promise<void>;
|
|
2
|
+
declare function useRemovePaymentMethod(paymentPlugins: PluginData[], token: string, apiHost: string, entityId: string, accountId?: string): (data: any) => Promise<void>;
|
|
3
3
|
export default useRemovePaymentMethod;
|
|
@@ -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,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLClient } from "graphql-request";
|
|
2
|
-
export declare const usePaymentMethod: (graphQLClient: GraphQLClient) => import("@tanstack/react-query/build/legacy/types").UseQueryResult<any, Error>;
|
|
2
|
+
export declare const usePaymentMethod: (graphQLClient: GraphQLClient, entityId: string, token: string) => import("@tanstack/react-query/build/legacy/types").UseQueryResult<any, Error>;
|
package/dist/index.d.ts
CHANGED
|
@@ -209,6 +209,6 @@ declare const BillingDetails: ({ entityId, isCardEnabled, shadow, className, hid
|
|
|
209
209
|
}) => boolean) | undefined;
|
|
210
210
|
}) => react_jsx_runtime.JSX.Element;
|
|
211
211
|
|
|
212
|
-
declare const usePaymentMethod: (graphQLClient: GraphQLClient) => _tanstack_react_query_build_legacy_types.UseQueryResult<any, Error>;
|
|
212
|
+
declare const usePaymentMethod: (graphQLClient: GraphQLClient, entityId: string, token: string) => _tanstack_react_query_build_legacy_types.UseQueryResult<any, Error>;
|
|
213
213
|
|
|
214
214
|
export { BillingDetails, BunnyProvider, Checkout, Invoice, PaymentMethod, Quote, Quotes, Signup, Subscriptions, Transactions, getQuoteAmountDue, usePaymentMethod };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bunnyapp/components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
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",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vite": "^5.4.11"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@bunnyapp/common": "^1.0.
|
|
65
|
+
"@bunnyapp/common": "^1.0.43",
|
|
66
66
|
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
|
67
67
|
"@fortawesome/free-brands-svg-icons": "^6.7.2",
|
|
68
68
|
"@fortawesome/free-regular-svg-icons": "^6.7.2",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type gqlRequestOptions = {
|
|
2
|
-
query: string;
|
|
3
|
-
vars?: Record<string, any>;
|
|
4
|
-
headers?: Record<string, string>;
|
|
5
|
-
token: string;
|
|
6
|
-
isInPreviewMode?: boolean;
|
|
7
|
-
apiHost: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const gqlRequest: ({ query, vars, headers, token, isInPreviewMode, apiHost, }: gqlRequestOptions) => Promise<unknown>;
|
|
10
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type gqlRequestOptions = {
|
|
2
|
-
query: string;
|
|
3
|
-
vars?: Record<string, any>;
|
|
4
|
-
headers?: Record<string, string>;
|
|
5
|
-
token: string;
|
|
6
|
-
isInPreviewMode?: boolean;
|
|
7
|
-
apiHost: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const gqlRequest: ({ query, vars, headers, token, isInPreviewMode, apiHost, }: gqlRequestOptions) => Promise<unknown>;
|
|
10
|
-
export {};
|