@oneblink/apps-react 13.5.1-beta.4 → 13.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/PaymentReceipt.js +25 -158
  2. package/dist/PaymentReceipt.js.map +1 -1
  3. package/dist/apps/approvals-service.d.ts +102 -1
  4. package/dist/apps/approvals-service.js +137 -1
  5. package/dist/apps/approvals-service.js.map +1 -1
  6. package/dist/apps/payment-service.d.ts +39 -0
  7. package/dist/apps/payment-service.js +67 -6
  8. package/dist/apps/payment-service.js.map +1 -1
  9. package/dist/apps/services/api/payment.d.ts +5 -1
  10. package/dist/apps/services/api/payment.js.map +1 -1
  11. package/dist/apps/services/fetch.d.ts +3 -1
  12. package/dist/apps/services/fetch.js +16 -4
  13. package/dist/apps/services/fetch.js.map +1 -1
  14. package/dist/apps/services/payment-handoff.d.ts +47 -0
  15. package/dist/apps/services/payment-handoff.js +79 -0
  16. package/dist/apps/services/payment-handoff.js.map +1 -0
  17. package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.d.ts +35 -19
  18. package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js +41 -27
  19. package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js.map +1 -1
  20. package/dist/apps/services/payment-submission-result.d.ts +5 -0
  21. package/dist/apps/services/payment-submission-result.js +11 -0
  22. package/dist/apps/services/payment-submission-result.js.map +1 -0
  23. package/dist/apps/submission-service.js +2 -1
  24. package/dist/apps/submission-service.js.map +1 -1
  25. package/dist/components/ErrorSnackbar.js +7 -1
  26. package/dist/components/ErrorSnackbar.js.map +1 -1
  27. package/dist/components/payments/ApprovalStepPaymentReceipt.d.ts +67 -0
  28. package/dist/components/payments/ApprovalStepPaymentReceipt.js +86 -0
  29. package/dist/components/payments/ApprovalStepPaymentReceipt.js.map +1 -0
  30. package/dist/components/payments/PaymentForm.d.ts +6 -0
  31. package/dist/components/payments/PaymentForm.js +36 -35
  32. package/dist/components/payments/PaymentForm.js.map +1 -1
  33. package/dist/components/payments/SessionPaymentForm.d.ts +23 -0
  34. package/dist/components/payments/SessionPaymentForm.js +49 -0
  35. package/dist/components/payments/SessionPaymentForm.js.map +1 -0
  36. package/dist/components/payments/SessionPaymentReceipt.d.ts +15 -0
  37. package/dist/components/payments/SessionPaymentReceipt.js +149 -0
  38. package/dist/components/payments/SessionPaymentReceipt.js.map +1 -0
  39. package/dist/components/payments/WestpacQuickStreamPaymentForm.d.ts +7 -11
  40. package/dist/components/payments/WestpacQuickStreamPaymentForm.js +25 -31
  41. package/dist/components/payments/WestpacQuickStreamPaymentForm.js.map +1 -1
  42. package/dist/index.d.ts +2 -0
  43. package/dist/index.js +2 -0
  44. package/dist/index.js.map +1 -1
  45. package/dist/services/form-validation/getApproverEditableFormElementIds.js +3 -0
  46. package/dist/services/form-validation/getApproverEditableFormElementIds.js.map +1 -1
  47. package/dist/services/getFlowInstanceNodesWithMeta.js +22 -3
  48. package/dist/services/getFlowInstanceNodesWithMeta.js.map +1 -1
  49. package/package.json +3 -3
@@ -1,170 +1,37 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as React from 'react';
3
3
  import { useHistory } from 'react-router-dom';
4
- import { paymentService, submissionService, localisationService, } from './apps';
5
- import useIsMounted from './hooks/useIsMounted';
6
- import useQuery from './hooks/useQuery';
7
- import Modal from './components/renderer/Modal';
8
- import OnLoading from './components/renderer/OnLoading';
9
- import { Receipt, ReceiptList, ReceiptListItem, ReceiptButton, } from './components/receipts';
10
- import MaterialIcon from './components/MaterialIcon';
11
- import QuillHTML from './components/QuillHTML';
12
- import DownloadableFiles from './components/downloadable-files';
13
- import replaceInjectablesWithSubmissionValues from './apps/services/replaceInjectablesWithSubmissionValues';
14
- const { handlePaymentQuerystring, handlePaymentSubmissionEvent } = paymentService;
4
+ import { paymentService, submissionService } from './apps';
5
+ import SessionPaymentReceipt from './components/payments/SessionPaymentReceipt';
6
+ const { handlePaymentSubmissionEvent } = paymentService;
15
7
  function PaymentReceipt({ onDone, onCancel, }) {
16
- const isMounted = useIsMounted();
17
- const query = useQuery();
18
8
  const history = useHistory();
19
- const [{ isLoading, loadError, transaction, submissionResult, receiptItems, schedulingBooking, }, setLoadState,] = React.useState({
20
- isLoading: true,
21
- loadError: null,
22
- transaction: null,
23
- submissionResult: null,
24
- receiptItems: null,
25
- schedulingBooking: null,
26
- });
27
- const [{ isRunningPostSubmissionAction, postSubmissionError }, setPostSubmissionState,] = React.useState({
28
- isRunningPostSubmissionAction: false,
29
- postSubmissionError: null,
30
- });
31
- const clearPostSubmissionError = React.useCallback(() => {
32
- setPostSubmissionState((currentState) => ({
33
- ...currentState,
34
- postSubmissionError: null,
35
- }));
36
- }, []);
37
- const [{ isRetrying, retryError }, setRetryState] = React.useState({
38
- isRetrying: false,
39
- retryError: null,
40
- });
41
- const clearRetryError = React.useCallback(() => {
42
- setRetryState((currentState) => ({
43
- ...currentState,
44
- retryError: null,
45
- }));
46
- }, []);
47
- React.useEffect(() => {
48
- let ignore = false;
49
- const getTransaction = async () => {
50
- var _a;
51
- let newError = null;
52
- let newTransaction = null;
53
- let newSubmissionResult = null;
54
- let newReceiptItems = null;
55
- let newSchedulingBooking = null;
56
- try {
57
- const result = await handlePaymentQuerystring(query);
58
- newTransaction = result.transaction;
59
- newSubmissionResult = result.submissionResult;
60
- newReceiptItems = result.receiptItems;
61
- newSchedulingBooking = (_a = result.schedulingBooking) !== null && _a !== void 0 ? _a : null;
62
- }
63
- catch (error) {
64
- console.warn('Error while attempting to load transaction', error);
65
- newError = error;
66
- }
67
- if (!ignore) {
68
- setLoadState({
69
- isLoading: false,
70
- loadError: newError,
71
- transaction: newTransaction,
72
- submissionResult: newSubmissionResult,
73
- receiptItems: newReceiptItems,
74
- schedulingBooking: newSchedulingBooking,
75
- });
76
- }
77
- };
78
- getTransaction();
79
- return () => {
80
- ignore = true;
81
- };
82
- }, [query]);
83
- const executePostSubmissionAction = React.useCallback(async (action) => {
84
- if (!submissionResult || !isMounted.current) {
9
+ const handleDone = React.useCallback(async (submissionResult) => {
10
+ await onDone({ ...submissionResult, payment: null });
11
+ }, [onDone]);
12
+ const handleCancel = React.useCallback(async (submissionResult) => {
13
+ await onCancel({ ...submissionResult, payment: null });
14
+ }, [onCancel]);
15
+ const handleTryAgain = React.useCallback(async (submissionResult) => {
16
+ if (!submissionResult.payment) {
85
17
  return;
86
18
  }
87
- setPostSubmissionState({
88
- isRunningPostSubmissionAction: true,
89
- postSubmissionError: null,
19
+ const payment = await handlePaymentSubmissionEvent({
20
+ formSubmissionResult: submissionResult,
21
+ paymentReceiptUrl: submissionResult.payment.paymentReceiptUrl,
22
+ paymentFormUrl: submissionResult.payment.paymentFormUrl,
90
23
  });
91
- let newError = null;
92
- try {
93
- await action({ ...submissionResult, payment: null });
94
- }
95
- catch (error) {
96
- console.warn('Error while running post submission action', error);
97
- newError = error;
98
- }
99
- if (isMounted.current) {
100
- setPostSubmissionState({
101
- isRunningPostSubmissionAction: false,
102
- postSubmissionError: newError,
103
- });
104
- }
105
- }, [isMounted, submissionResult]);
106
- const handleDone = React.useCallback(async () => {
107
- executePostSubmissionAction(onDone);
108
- }, [executePostSubmissionAction, onDone]);
109
- const handleCancel = React.useCallback(() => {
110
- executePostSubmissionAction(onCancel);
111
- }, [executePostSubmissionAction, onCancel]);
112
- const handleTryAgain = React.useCallback(async () => {
113
- if (!submissionResult || !submissionResult.payment) {
24
+ // The API has decided that no payment is required on try again
25
+ if (!payment) {
26
+ await onDone({ ...submissionResult, payment: null });
114
27
  return;
115
28
  }
116
- if (isMounted.current) {
117
- setRetryState({
118
- isRetrying: true,
119
- retryError: null,
120
- });
121
- }
122
- let newError = null;
123
- try {
124
- const payment = await handlePaymentSubmissionEvent({
125
- formSubmissionResult: submissionResult,
126
- paymentReceiptUrl: submissionResult.payment.paymentReceiptUrl,
127
- paymentFormUrl: submissionResult.payment.paymentFormUrl,
128
- });
129
- // The API has decided that no payment is required on try again
130
- if (!payment) {
131
- // Do the success path
132
- handleDone();
133
- }
134
- else {
135
- await submissionService.executePostSubmissionAction({ ...submissionResult, payment }, {
136
- onRedirectToRelativeUrl: (url) => history.push(url),
137
- onRedirectToAbsoluteUrl: (url) => window.location.assign(url),
138
- });
139
- }
140
- }
141
- catch (error) {
142
- console.warn('Error while attempting to retry transaction', error);
143
- newError = error;
144
- }
145
- if (isMounted.current) {
146
- setRetryState({
147
- isRetrying: false,
148
- retryError: newError,
149
- });
150
- }
151
- }, [history, isMounted, submissionResult, handleDone]);
152
- const postSubmissionSuccessHtml = React.useMemo(() => {
153
- var _a;
154
- const html = (_a = submissionResult === null || submissionResult === void 0 ? void 0 : submissionResult.definition.postSubmissionReceipt) === null || _a === void 0 ? void 0 : _a.html;
155
- if (!(transaction === null || transaction === void 0 ? void 0 : transaction.isSuccess) || !submissionResult || !html) {
156
- return undefined;
157
- }
158
- return replaceInjectablesWithSubmissionValues(html, submissionResult).text;
159
- }, [submissionResult, transaction === null || transaction === void 0 ? void 0 : transaction.isSuccess]);
160
- return (_jsxs("div", { children: [isLoading && (_jsx("section", { children: _jsxs("div", { className: "cypress-loading has-text-centered", children: [_jsx(OnLoading, { className: "has-text-centered" }), _jsx("span", { children: "Retrieving transaction details..." })] }) })), transaction && (_jsxs(Receipt, { className: "ob-payment-receipt", containerClassName: "ob-payment-receipt__container", children: [_jsxs(ReceiptList, { successIconClassName: "ob-payment-receipt__success-icon", warningIconClassName: "ob-payment-receipt__warning-icon", warningMessageClassName: "ob-payment-receipt__warning-message cypress-payment-receipt-warning-message", warningMessage: transaction.isSuccess
161
- ? undefined
162
- : transaction.errorMessage || undefined, hideSuccessIcon: !!postSubmissionSuccessHtml, children: [postSubmissionSuccessHtml && (_jsx("div", { className: "ob-list__item ob-payment-receipt__success-message", children: _jsx("div", { className: "ob-list__content-wrapper", children: _jsx("div", { className: "ob-list__content", children: _jsx(QuillHTML, { html: postSubmissionSuccessHtml, className: "cypress-payment-receipt-success-message" }) }) }) })), receiptItems &&
163
- receiptItems.length &&
164
- receiptItems.map((receiptItem, i) => {
165
- var _a, _b;
166
- return (_jsx(ReceiptListItem, { className: (_a = receiptItem.className) !== null && _a !== void 0 ? _a : '', valueClassName: (_b = receiptItem.valueClassName) !== null && _b !== void 0 ? _b : '', icon: receiptItem.icon, label: receiptItem.label, value: receiptItem.value, allowCopyToClipboard: receiptItem.allowCopyToClipboard }, i));
167
- }), schedulingBooking && transaction.isSuccess && (_jsxs(_Fragment, { children: [schedulingBooking.location && (_jsx(ReceiptListItem, { className: "ob-scheduling-receipt__location", valueClassName: "cypress-scheduling-receipt-location", icon: "location_on", label: "Location", value: schedulingBooking.location })), _jsx(ReceiptListItem, { className: "ob-scheduling-receipt__start-time", valueClassName: "cypress-scheduling-receipt-start-time", icon: "schedule", label: "Start Time", value: localisationService.formatDatetimeLong(schedulingBooking.startTime) }), _jsx(ReceiptListItem, { className: "ob-scheduling-receipt__end-time", valueClassName: "cypress-scheduling-receipt-end-time", icon: "schedule", label: "End Time", value: localisationService.formatDatetimeLong(schedulingBooking.endTime) })] })), _jsx(ReceiptListItem, { className: "ob-payment-receipt__warning", valueClassName: "cypress-payment-receipt-warning", label: "Warning", value: "Please do not click back in your browser, doing so will cause issues with your payment." })] }), submissionResult && transaction.isSuccess && (_jsx(DownloadableFiles, { formSubmissionResult: submissionResult, layout: "LIST" })), _jsx("div", { className: "buttons", children: transaction.isSuccess ? (_jsx(ReceiptButton, { className: "is-primary ob-payment-receipt__button ob-payment-receipt__okay-button cypress-payment-receipt-okay-button", label: "Done", isLoading: isRunningPostSubmissionAction, onClick: handleDone })) : (_jsxs(_Fragment, { children: [_jsx(ReceiptButton, { className: "ob-payment-receipt__button ob-payment-receipt__cancel-button cypress-payment-receipt-cancel-button", label: "Cancel", isDisabled: isRetrying, isLoading: isRunningPostSubmissionAction, onClick: handleCancel }), _jsx(ReceiptButton, { className: "is-primary ob-payment-receipt__button ob-payment-receipt__try-again-button cypress-payment-receipt-try-again-button", label: "Try Again", isDisabled: isRunningPostSubmissionAction, isLoading: isRetrying, onClick: handleTryAgain })] })) })] })), loadError && (_jsxs("section", { className: "cypress-payment-receipt-loading-error-message", children: [_jsx("div", { className: "ob-payment-receipt__error-icon-container has-text-centered has-margin-bottom-8", children: _jsx(MaterialIcon, { className: "ob-payment-receipt__error-icon has-text-danger icon-x-large", children: "error" }) }), _jsx("p", { className: "ob-payment-receipt__error-message has-text-centered has-margin-bottom-4", children: loadError.message })] })), retryError && (_jsx(Modal, { isOpen: true, title: retryError.title || 'Whoops...', bodyClassName: "cypress-payment-receipt-retry-error-message", actions: _jsx("button", { type: "button", className: "button ob-button is-primary cypress-payment-receipt-retry-error-okay-button", onClick: clearRetryError, autoFocus: true, children: "Okay" }), children: retryError.message })), postSubmissionError && (_jsx(Modal, { isOpen: true, title: postSubmissionError.title || 'Whoops...', bodyClassName: "cypress-payment-receipt-retry-error-message", actions: _jsx("button", { type: "button", className: "button ob-button is-primary cypress-payment-receipt-retry-error-okay-button", onClick: clearPostSubmissionError, autoFocus: true, children: "Okay" }), children: postSubmissionError.message }))] }));
29
+ await submissionService.executePostSubmissionAction({ ...submissionResult, payment }, {
30
+ onRedirectToRelativeUrl: (url) => history.push(url),
31
+ onRedirectToAbsoluteUrl: (url) => window.location.assign(url),
32
+ });
33
+ }, [history, onDone]);
34
+ return (_jsx(SessionPaymentReceipt, { onDone: handleDone, onCancel: handleCancel, onTryAgain: handleTryAgain }));
168
35
  }
169
36
  /**
170
37
  * Component for rendering a OneBlink Form Payment Receipt. This component will
@@ -1 +1 @@
1
- {"version":3,"file":"PaymentReceipt.js","sourceRoot":"","sources":["../src/PaymentReceipt.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EACL,cAAc,EACd,i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AAS,EAAC,6DAA6D,sBAEtE,GACX,EACN,YAAG,SAAS,EAAC,yEAAyE,YACnF,SAAS,CAAC,OAAO,GAChB,IACI,CACX,EAEA,UAAU,IAAI,CACb,KAAC,KAAK,IACJ,MAAM,QACN,KAAK,EAAE,UAAU,CAAC,KAAK,IAAI,WAAW,EACtC,aAAa,EAAC,6CAA6C,EAC3D,OAAO,EACL,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,6EAA6E,EACvF,OAAO,EAAE,eAAe,EACxB,SAAS,2BAGF,YAGV,UAAU,CAAC,OAAO,GACb,CACT,EAEA,mBAAmB,IAAI,CACtB,KAAC,KAAK,IACJ,MAAM,QACN,KAAK,EAAE,mBAAmB,CAAC,KAAK,IAAI,WAAW,EAC/C,aAAa,EAAC,6CAA6C,EAC3D,OAAO,EACL,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,6EAA6E,EACvF,OAAO,EAAE,wBAAwB,EACjC,SAAS,2BAGF,YAGV,mBAAmB,CAAC,OAAO,GACtB,CACT,IACG,CACP,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAe,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { useHistory } from 'react-router-dom'\nimport {\n paymentService,\n submissionService,\n OneBlinkAppsError,\n schedulingService,\n localisationService,\n} from './apps'\nimport useIsMounted from './hooks/useIsMounted'\n\nimport useQuery from './hooks/useQuery'\nimport Modal from './components/renderer/Modal'\nimport OnLoading from './components/renderer/OnLoading'\nimport {\n Receipt,\n ReceiptList,\n ReceiptListItem,\n ReceiptButton,\n} from './components/receipts'\nimport MaterialIcon from './components/MaterialIcon'\nimport QuillHTML from './components/QuillHTML'\nimport DownloadableFiles from './components/downloadable-files'\nimport replaceInjectablesWithSubmissionValues from './apps/services/replaceInjectablesWithSubmissionValues'\n\nconst { handlePaymentQuerystring, handlePaymentSubmissionEvent } =\n paymentService\n\nfunction PaymentReceipt({\n onDone,\n onCancel,\n}: {\n /**\n * The function to call when the user clicks 'Done'. See\n * [FormSubmissionResult](https://oneblink.github.io/apps/modules/submissionService.html#FormSubmissionResult)\n * for the structure of the argument.\n */\n onDone: (\n submissionResult: submissionService.FormSubmissionResult,\n ) => Promise<void>\n /**\n * The function to call when the user clicks 'Cancel'. See\n * [FormSubmissionResult](https://oneblink.github.io/apps/modules/submissionService.html#FormSubmissionResult)\n * for the structure of the argument.\n */\n onCancel: (\n submissionResult: submissionService.FormSubmissionResult,\n ) => Promise<void>\n}) {\n const isMounted = useIsMounted()\n const query = useQuery()\n const history = useHistory()\n\n const [\n {\n isLoading,\n loadError,\n transaction,\n submissionResult,\n receiptItems,\n schedulingBooking,\n },\n setLoadState,\n ] = React.useState<{\n isLoading: boolean\n loadError: Error | null\n transaction: paymentService.HandlePaymentResult['transaction'] | null\n submissionResult: submissionService.FormSubmissionResult | null\n receiptItems: paymentService.PaymentReceiptItem[] | null\n schedulingBooking: schedulingService.SchedulingBooking | null\n }>({\n isLoading: true,\n loadError: null,\n transaction: null,\n submissionResult: null,\n receiptItems: null,\n schedulingBooking: null,\n })\n const [\n { isRunningPostSubmissionAction, postSubmissionError },\n setPostSubmissionState,\n ] = React.useState<{\n isRunningPostSubmissionAction: boolean\n postSubmissionError: OneBlinkAppsError | null\n }>({\n isRunningPostSubmissionAction: false,\n postSubmissionError: null,\n })\n const clearPostSubmissionError = React.useCallback(() => {\n setPostSubmissionState((currentState) => ({\n ...currentState,\n postSubmissionError: null,\n }))\n }, [])\n const [{ isRetrying, retryError }, setRetryState] = React.useState<{\n isRetrying: boolean\n retryError: OneBlinkAppsError | null\n }>({\n isRetrying: false,\n retryError: null,\n })\n const clearRetryError = React.useCallback(() => {\n setRetryState((currentState) => ({\n ...currentState,\n retryError: null,\n }))\n }, [])\n\n React.useEffect(() => {\n let ignore = false\n\n const getTransaction = async () => {\n let newError = null\n let newTransaction = null\n let newSubmissionResult = null\n let newReceiptItems = null\n let newSchedulingBooking = null\n try {\n const result = await handlePaymentQuerystring(query)\n newTransaction = result.transaction\n newSubmissionResult = result.submissionResult\n newReceiptItems = result.receiptItems\n newSchedulingBooking = result.schedulingBooking ?? null\n } catch (error) {\n console.warn('Error while attempting to load transaction', error)\n newError = error as Error\n }\n\n if (!ignore) {\n setLoadState({\n isLoading: false,\n loadError: newError,\n transaction: newTransaction,\n submissionResult: newSubmissionResult,\n receiptItems: newReceiptItems,\n schedulingBooking: newSchedulingBooking,\n })\n }\n }\n getTransaction()\n\n return () => {\n ignore = true\n }\n }, [query])\n\n const executePostSubmissionAction = React.useCallback(\n async (\n action: (\n submissionRresult: submissionService.FormSubmissionResult,\n ) => Promise<void>,\n ) => {\n if (!submissionResult || !isMounted.current) {\n return\n }\n\n setPostSubmissionState({\n isRunningPostSubmissionAction: true,\n postSubmissionError: null,\n })\n\n let newError = null\n try {\n await action({ ...submissionResult, payment: null })\n } catch (error) {\n console.warn('Error while running post submission action', error)\n newError = error as OneBlinkAppsError\n }\n\n if (isMounted.current) {\n setPostSubmissionState({\n isRunningPostSubmissionAction: false,\n postSubmissionError: newError,\n })\n }\n },\n [isMounted, submissionResult],\n )\n\n const handleDone = React.useCallback(async () => {\n executePostSubmissionAction(onDone)\n }, [executePostSubmissionAction, onDone])\n\n const handleCancel = React.useCallback(() => {\n executePostSubmissionAction(onCancel)\n }, [executePostSubmissionAction, onCancel])\n\n const handleTryAgain = React.useCallback(async () => {\n if (!submissionResult || !submissionResult.payment) {\n return\n }\n\n if (isMounted.current) {\n setRetryState({\n isRetrying: true,\n retryError: null,\n })\n }\n\n let newError = null\n try {\n const payment = await handlePaymentSubmissionEvent({\n formSubmissionResult: submissionResult,\n paymentReceiptUrl: submissionResult.payment.paymentReceiptUrl,\n paymentFormUrl: submissionResult.payment.paymentFormUrl,\n })\n // The API has decided that no payment is required on try again\n if (!payment) {\n // Do the success path\n handleDone()\n } else {\n await submissionService.executePostSubmissionAction(\n { ...submissionResult, payment },\n {\n onRedirectToRelativeUrl: (url) => history.push(url),\n onRedirectToAbsoluteUrl: (url) => window.location.assign(url),\n },\n )\n }\n } catch (error) {\n console.warn('Error while attempting to retry transaction', error)\n newError = error as OneBlinkAppsError\n }\n\n if (isMounted.current) {\n setRetryState({\n isRetrying: false,\n retryError: newError,\n })\n }\n }, [history, isMounted, submissionResult, handleDone])\n\n const postSubmissionSuccessHtml = React.useMemo(() => {\n const html = submissionResult?.definition.postSubmissionReceipt?.html\n if (!transaction?.isSuccess || !submissionResult || !html) {\n return undefined\n }\n\n return replaceInjectablesWithSubmissionValues(html, submissionResult).text\n }, [submissionResult, transaction?.isSuccess])\n\n return (\n <div>\n {isLoading && (\n <section>\n <div className=\"cypress-loading has-text-centered\">\n <OnLoading className=\"has-text-centered\"></OnLoading>\n <span>Retrieving transaction details...</span>\n </div>\n </section>\n )}\n\n {transaction && (\n <Receipt\n className=\"ob-payment-receipt\"\n containerClassName=\"ob-payment-receipt__container\"\n >\n <ReceiptList\n successIconClassName=\"ob-payment-receipt__success-icon\"\n warningIconClassName=\"ob-payment-receipt__warning-icon\"\n warningMessageClassName=\"ob-payment-receipt__warning-message cypress-payment-receipt-warning-message\"\n warningMessage={\n transaction.isSuccess\n ? undefined\n : transaction.errorMessage || undefined\n }\n hideSuccessIcon={!!postSubmissionSuccessHtml}\n >\n {postSubmissionSuccessHtml && (\n <div className=\"ob-list__item ob-payment-receipt__success-message\">\n <div className=\"ob-list__content-wrapper\">\n <div className=\"ob-list__content\">\n <QuillHTML\n html={postSubmissionSuccessHtml}\n className=\"cypress-payment-receipt-success-message\"\n />\n </div>\n </div>\n </div>\n )}\n {receiptItems &&\n receiptItems.length &&\n receiptItems.map((receiptItem, i) => {\n return (\n <ReceiptListItem\n key={i}\n className={receiptItem.className ?? ''}\n valueClassName={receiptItem.valueClassName ?? ''}\n icon={receiptItem.icon}\n label={receiptItem.label}\n value={receiptItem.value}\n allowCopyToClipboard={receiptItem.allowCopyToClipboard}\n />\n )\n })}\n {schedulingBooking && transaction.isSuccess && (\n <>\n {schedulingBooking.location && (\n <ReceiptListItem\n className=\"ob-scheduling-receipt__location\"\n valueClassName=\"cypress-scheduling-receipt-location\"\n icon=\"location_on\"\n label=\"Location\"\n value={schedulingBooking.location}\n />\n )}\n\n <ReceiptListItem\n className=\"ob-scheduling-receipt__start-time\"\n valueClassName=\"cypress-scheduling-receipt-start-time\"\n icon=\"schedule\"\n label=\"Start Time\"\n value={localisationService.formatDatetimeLong(\n schedulingBooking.startTime,\n )}\n />\n\n <ReceiptListItem\n className=\"ob-scheduling-receipt__end-time\"\n valueClassName=\"cypress-scheduling-receipt-end-time\"\n icon=\"schedule\"\n label=\"End Time\"\n value={localisationService.formatDatetimeLong(\n schedulingBooking.endTime,\n )}\n />\n </>\n )}\n <ReceiptListItem\n className=\"ob-payment-receipt__warning\"\n valueClassName=\"cypress-payment-receipt-warning\"\n label=\"Warning\"\n value=\"Please do not click back in your browser, doing so will cause issues with your payment.\"\n />\n </ReceiptList>\n\n {submissionResult && transaction.isSuccess && (\n <DownloadableFiles\n formSubmissionResult={submissionResult}\n layout=\"LIST\"\n />\n )}\n\n <div className=\"buttons\">\n {transaction.isSuccess ? (\n <ReceiptButton\n className=\"is-primary ob-payment-receipt__button ob-payment-receipt__okay-button cypress-payment-receipt-okay-button\"\n label=\"Done\"\n isLoading={isRunningPostSubmissionAction}\n onClick={handleDone}\n />\n ) : (\n <>\n <ReceiptButton\n className=\"ob-payment-receipt__button ob-payment-receipt__cancel-button cypress-payment-receipt-cancel-button\"\n label=\"Cancel\"\n isDisabled={isRetrying}\n isLoading={isRunningPostSubmissionAction}\n onClick={handleCancel}\n />\n <ReceiptButton\n className=\"is-primary ob-payment-receipt__button ob-payment-receipt__try-again-button cypress-payment-receipt-try-again-button\"\n label=\"Try Again\"\n isDisabled={isRunningPostSubmissionAction}\n isLoading={isRetrying}\n onClick={handleTryAgain}\n />\n </>\n )}\n </div>\n </Receipt>\n )}\n\n {loadError && (\n <section className=\"cypress-payment-receipt-loading-error-message\">\n <div className=\"ob-payment-receipt__error-icon-container has-text-centered has-margin-bottom-8\">\n <MaterialIcon className=\"ob-payment-receipt__error-icon has-text-danger icon-x-large\">\n error\n </MaterialIcon>\n </div>\n <p className=\"ob-payment-receipt__error-message has-text-centered has-margin-bottom-4\">\n {loadError.message}\n </p>\n </section>\n )}\n\n {retryError && (\n <Modal\n isOpen\n title={retryError.title || 'Whoops...'}\n bodyClassName=\"cypress-payment-receipt-retry-error-message\"\n actions={\n <button\n type=\"button\"\n className=\"button ob-button is-primary cypress-payment-receipt-retry-error-okay-button\"\n onClick={clearRetryError}\n autoFocus\n >\n Okay\n </button>\n }\n >\n {retryError.message}\n </Modal>\n )}\n\n {postSubmissionError && (\n <Modal\n isOpen\n title={postSubmissionError.title || 'Whoops...'}\n bodyClassName=\"cypress-payment-receipt-retry-error-message\"\n actions={\n <button\n type=\"button\"\n className=\"button ob-button is-primary cypress-payment-receipt-retry-error-okay-button\"\n onClick={clearPostSubmissionError}\n autoFocus\n >\n Okay\n </button>\n }\n >\n {postSubmissionError.message}\n </Modal>\n )}\n </div>\n )\n}\n\n/**\n * Component for rendering a OneBlink Form Payment Receipt. This component will\n * payment receipt but it is up to the developer to implement what happens when\n * the user clicks 'Done'.\n *\n * It is also recommended to import the `css` from this library as well.\n *\n * ```js\n * import { PaymentReceipt } from '@oneblink/apps-react'\n * import '@oneblink/apps-react/dist/styles.css'\n * ```\n *\n * #### Example\n *\n * ```tsx\n * import React from 'react'\n * import ReactDOM from 'react-dom'\n * import { PaymentReceipt } from '@oneblink/apps-react'\n * import '@oneblink/apps-react/dist/styles.css'\n *\n * function ReceiptContainer() {\n * const handleDone = React.useCallback(async () => {\n * console.log('All done!')\n * }, [])\n * const handleCancel = React.useCallback(async () => {\n * console.log('Cancelled!')\n * }, [])\n *\n * return <PaymentReceipt onDone={handleDone} onCancel={handleCancel} />\n * }\n *\n * function App() {\n * return (\n * <IsOfflineContextProvider>\n * <ReceiptContainer />\n * </IsOfflineContextProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport default React.memo(PaymentReceipt)\n"]}
1
+ {"version":3,"file":"PaymentReceipt.js","sourceRoot":"","sources":["../src/PaymentReceipt.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAC1D,OAAO,qBAAqB,MAAM,6CAA6C,CAAA;AAE/E,MAAM,EAAE,4BAA4B,EAAE,GAAG,cAAc,CAAA;AAEvD,SAAS,cAAc,CAAC,EACtB,MAAM,EACN,QAAQ,GAkBT;IACC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;IAE5B,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAClC,KAAK,EAAE,gBAAwD,EAAE,EAAE;QACjE,MAAM,MAAM,CAAC,EAAE,GAAG,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IACtD,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAA;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CACpC,KAAK,EAAE,gBAAwD,EAAE,EAAE;QACjE,MAAM,QAAQ,CAAC,EAAE,GAAG,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IACxD,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAA;IAED,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CACtC,KAAK,EAAE,gBAAwD,EAAE,EAAE;QACjE,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;YAC9B,OAAM;QACR,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,4BAA4B,CAAC;YACjD,oBAAoB,EAAE,gBAAgB;YACtC,iBAAiB,EAAE,gBAAgB,CAAC,OAAO,CAAC,iBAAiB;YAC7D,cAAc,EAAE,gBAAgB,CAAC,OAAO,CAAC,cAAc;SACxD,CAAC,CAAA;QACF,+DAA+D;QAC/D,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,MAAM,CAAC,EAAE,GAAG,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;YACpD,OAAM;QACR,CAAC;QAED,MAAM,iBAAiB,CAAC,2BAA2B,CACjD,EAAE,GAAG,gBAAgB,EAAE,OAAO,EAAE,EAChC;YACE,uBAAuB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;YACnD,uBAAuB,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC;SAC9D,CACF,CAAA;IACH,CAAC,EACD,CAAC,OAAO,EAAE,MAAM,CAAC,CAClB,CAAA;IAED,OAAO,CACL,KAAC,qBAAqB,IACpB,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,cAAc,GAC1B,CACH,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAe,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { useHistory } from 'react-router-dom'\nimport { paymentService, submissionService } from './apps'\nimport SessionPaymentReceipt from './components/payments/SessionPaymentReceipt'\n\nconst { handlePaymentSubmissionEvent } = paymentService\n\nfunction PaymentReceipt({\n onDone,\n onCancel,\n}: {\n /**\n * The function to call when the user clicks 'Done'. See\n * [FormSubmissionResult](https://oneblink.github.io/apps/modules/submissionService.html#FormSubmissionResult)\n * for the structure of the argument.\n */\n onDone: (\n submissionResult: submissionService.FormSubmissionResult,\n ) => Promise<void>\n /**\n * The function to call when the user clicks 'Cancel'. See\n * [FormSubmissionResult](https://oneblink.github.io/apps/modules/submissionService.html#FormSubmissionResult)\n * for the structure of the argument.\n */\n onCancel: (\n submissionResult: submissionService.FormSubmissionResult,\n ) => Promise<void>\n}) {\n const history = useHistory()\n\n const handleDone = React.useCallback(\n async (submissionResult: submissionService.FormSubmissionResult) => {\n await onDone({ ...submissionResult, payment: null })\n },\n [onDone],\n )\n\n const handleCancel = React.useCallback(\n async (submissionResult: submissionService.FormSubmissionResult) => {\n await onCancel({ ...submissionResult, payment: null })\n },\n [onCancel],\n )\n\n const handleTryAgain = React.useCallback(\n async (submissionResult: submissionService.FormSubmissionResult) => {\n if (!submissionResult.payment) {\n return\n }\n\n const payment = await handlePaymentSubmissionEvent({\n formSubmissionResult: submissionResult,\n paymentReceiptUrl: submissionResult.payment.paymentReceiptUrl,\n paymentFormUrl: submissionResult.payment.paymentFormUrl,\n })\n // The API has decided that no payment is required on try again\n if (!payment) {\n await onDone({ ...submissionResult, payment: null })\n return\n }\n\n await submissionService.executePostSubmissionAction(\n { ...submissionResult, payment },\n {\n onRedirectToRelativeUrl: (url) => history.push(url),\n onRedirectToAbsoluteUrl: (url) => window.location.assign(url),\n },\n )\n },\n [history, onDone],\n )\n\n return (\n <SessionPaymentReceipt\n onDone={handleDone}\n onCancel={handleCancel}\n onTryAgain={handleTryAgain}\n />\n )\n}\n\n/**\n * Component for rendering a OneBlink Form Payment Receipt. This component will\n * payment receipt but it is up to the developer to implement what happens when\n * the user clicks 'Done'.\n *\n * It is also recommended to import the `css` from this library as well.\n *\n * ```js\n * import { PaymentReceipt } from '@oneblink/apps-react'\n * import '@oneblink/apps-react/dist/styles.css'\n * ```\n *\n * #### Example\n *\n * ```tsx\n * import React from 'react'\n * import ReactDOM from 'react-dom'\n * import { PaymentReceipt } from '@oneblink/apps-react'\n * import '@oneblink/apps-react/dist/styles.css'\n *\n * function ReceiptContainer() {\n * const handleDone = React.useCallback(async () => {\n * console.log('All done!')\n * }, [])\n * const handleCancel = React.useCallback(async () => {\n * console.log('Cancelled!')\n * }, [])\n *\n * return <PaymentReceipt onDone={handleDone} onCancel={handleCancel} />\n * }\n *\n * function App() {\n * return (\n * <IsOfflineContextProvider>\n * <ReceiptContainer />\n * </IsOfflineContextProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport default React.memo(PaymentReceipt)\n"]}
@@ -1,4 +1,4 @@
1
- import { SubmissionTypes, ApprovalTypes, FormTypes } from '@oneblink/types';
1
+ import { SubmissionTypes, ApprovalTypes, FormTypes, SubmissionEventTypes } from '@oneblink/types';
2
2
  export { getFlowInstanceNodesWithMeta } from '../services/getFlowInstanceNodesWithMeta';
3
3
  export type FormSubmissionApprovalsResponse = {
4
4
  approvals: Array<{
@@ -6,6 +6,8 @@ export type FormSubmissionApprovalsResponse = {
6
6
  formApprovalFlowInstance: ApprovalTypes.FormApprovalFlowInstance;
7
7
  formSubmissionMeta: SubmissionTypes.FormSubmissionMeta;
8
8
  latestSuccessfulFormSubmissionPayment: SubmissionTypes.FormSubmissionPayment | undefined;
9
+ /** True while this approval has a checkout that has not finished. */
10
+ paymentInProgress?: boolean;
9
11
  }>;
10
12
  };
11
13
  export type FormApprovalFlowInstanceHistory = {
@@ -14,6 +16,7 @@ export type FormApprovalFlowInstanceHistory = {
14
16
  formSubmissionMetaEdits: SubmissionTypes.FormSubmissionMetaEdit[];
15
17
  formSubmissionApprovals: ApprovalTypes.FormSubmissionApproval[];
16
18
  successfulFormSubmissionPayment?: SubmissionTypes.FormSubmissionPayment;
19
+ approvalStepPayments?: SubmissionTypes.FormSubmissionPayment[];
17
20
  };
18
21
  export type FormSubmissionApprovalResponse = {
19
22
  formSubmissionMeta: SubmissionTypes.FormSubmissionMeta;
@@ -77,6 +80,104 @@ export declare function getFormSubmissionApprovals(formsAppId: number, abortSign
77
80
  * @returns
78
81
  */
79
82
  export declare function getFormSubmissionApproval(formSubmissionApprovalId: string, abortSignal?: AbortSignal): Promise<FormSubmissionApprovalResponse>;
83
+ /**
84
+ * Conflict code on the error thrown when an approval step already has a
85
+ * checkout in progress.
86
+ *
87
+ * #### Example
88
+ *
89
+ * ```js
90
+ * import {
91
+ * approvalsService,
92
+ * OneBlinkAppsError,
93
+ * } from '@oneblink/apps-react'
94
+ *
95
+ * try {
96
+ * await approvalsService.createApprovalStepPayment(
97
+ * formSubmissionApprovalId,
98
+ * {
99
+ * redirectUrl,
100
+ * paymentFormUrl,
101
+ * form,
102
+ * submissionId,
103
+ * },
104
+ * )
105
+ * } catch (error) {
106
+ * if (
107
+ * error instanceof OneBlinkAppsError &&
108
+ * error.conflict === approvalsService.PAYMENT_IN_PROGRESS_CONFLICT
109
+ * ) {
110
+ * console.log('A payment is already in progress')
111
+ * }
112
+ * }
113
+ * ```
114
+ */
115
+ export declare const PAYMENT_IN_PROGRESS_CONFLICT = "PAYMENT_IN_PROGRESS";
116
+ /**
117
+ * Create a payment for an approval step. Returns the details needed to send the
118
+ * user to the payment provider. When the provider redirects to `redirectUrl`,
119
+ * the receipt for this payment can be displayed. Throws an `OneBlinkAppsError`
120
+ * with `conflict` set to `PAYMENT_IN_PROGRESS_CONFLICT` when a checkout for
121
+ * this step is already in progress.
122
+ *
123
+ * #### Example
124
+ *
125
+ * ```js
126
+ * const payment = await approvalsService.createApprovalStepPayment(
127
+ * 'd27966cc-128d-48a2-b681-6ad52012e113',
128
+ * {
129
+ * redirectUrl:
130
+ * 'https://approvals.example/approvals/d27966cc-128d-48a2-b681-6ad52012e113/payment-receipt',
131
+ * paymentFormUrl:
132
+ * 'https://approvals.example/approvals/d27966cc-128d-48a2-b681-6ad52012e113/payment',
133
+ * form,
134
+ * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',
135
+ * },
136
+ * )
137
+ * ```
138
+ *
139
+ * @param formSubmissionApprovalId
140
+ * @param options
141
+ * @param options.redirectUrl The URL the payment provider redirects to when the
142
+ * payment finishes.
143
+ * @param options.paymentFormUrl The in-app payment page. Required for providers
144
+ * that render their payment form in the app.
145
+ * @param options.form The form definition for this approval.
146
+ * @param options.submissionId The submission this approval belongs to.
147
+ * @param options.replacePendingPayment Cancel a checkout that is already in
148
+ * progress so this payment can start. Leave unset to reject that checkout.
149
+ * @param abortSignal
150
+ * @returns
151
+ */
152
+ export declare function createApprovalStepPayment(formSubmissionApprovalId: string, options: {
153
+ redirectUrl: string;
154
+ paymentFormUrl?: string;
155
+ form: FormTypes.Form;
156
+ submissionId: string;
157
+ replacePendingPayment?: boolean;
158
+ }, abortSignal?: AbortSignal): Promise<{
159
+ hostedFormUrl: string;
160
+ amount: number;
161
+ paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent;
162
+ customerReferenceNumber?: string;
163
+ }>;
164
+ /**
165
+ * Skip the payment for an approval step and continue the approval flow.
166
+ *
167
+ * #### Example
168
+ *
169
+ * ```js
170
+ * const formSubmissionApproval =
171
+ * await approvalsService.skipApprovalStepPayment(
172
+ * 'd27966cc-128d-48a2-b681-6ad52012e113',
173
+ * )
174
+ * ```
175
+ *
176
+ * @param formSubmissionApprovalId
177
+ * @param abortSignal
178
+ * @returns
179
+ */
180
+ export declare function skipApprovalStepPayment(formSubmissionApprovalId: string, abortSignal?: AbortSignal): Promise<ApprovalTypes.FormSubmissionApproval>;
80
181
  /**
81
182
  * Update a single FormSubmissionApproval assigned to the current user.
82
183
  *
@@ -1,8 +1,9 @@
1
1
  import OneBlinkAppsError from './services/errors/oneBlinkAppsError';
2
2
  import { isOffline } from './offline-service';
3
- import { deleteRequest, getRequest, putRequest, searchRequest, postRequest, } from './services/fetch';
3
+ import { deleteRequest, getRequest, putRequest, searchRequest, postRequest, HTTPError, } from './services/fetch';
4
4
  import tenants from './tenants';
5
5
  import Sentry from './Sentry';
6
+ import { rememberPaymentSubmissionResult } from './services/payment-submission-result';
6
7
  export { getFlowInstanceNodesWithMeta } from '../services/getFlowInstanceNodesWithMeta';
7
8
  /**
8
9
  * Get an Object containing FormSubmissionApprovals assigned to the current user
@@ -137,6 +138,141 @@ export async function getFormSubmissionApproval(formSubmissionApprovalId, abortS
137
138
  }
138
139
  }
139
140
  }
141
+ /**
142
+ * Conflict code on the error thrown when an approval step already has a
143
+ * checkout in progress.
144
+ *
145
+ * #### Example
146
+ *
147
+ * ```js
148
+ * import {
149
+ * approvalsService,
150
+ * OneBlinkAppsError,
151
+ * } from '@oneblink/apps-react'
152
+ *
153
+ * try {
154
+ * await approvalsService.createApprovalStepPayment(
155
+ * formSubmissionApprovalId,
156
+ * {
157
+ * redirectUrl,
158
+ * paymentFormUrl,
159
+ * form,
160
+ * submissionId,
161
+ * },
162
+ * )
163
+ * } catch (error) {
164
+ * if (
165
+ * error instanceof OneBlinkAppsError &&
166
+ * error.conflict === approvalsService.PAYMENT_IN_PROGRESS_CONFLICT
167
+ * ) {
168
+ * console.log('A payment is already in progress')
169
+ * }
170
+ * }
171
+ * ```
172
+ */
173
+ export const PAYMENT_IN_PROGRESS_CONFLICT = 'PAYMENT_IN_PROGRESS';
174
+ /**
175
+ * Create a payment for an approval step. Returns the details needed to send the
176
+ * user to the payment provider. When the provider redirects to `redirectUrl`,
177
+ * the receipt for this payment can be displayed. Throws an `OneBlinkAppsError`
178
+ * with `conflict` set to `PAYMENT_IN_PROGRESS_CONFLICT` when a checkout for
179
+ * this step is already in progress.
180
+ *
181
+ * #### Example
182
+ *
183
+ * ```js
184
+ * const payment = await approvalsService.createApprovalStepPayment(
185
+ * 'd27966cc-128d-48a2-b681-6ad52012e113',
186
+ * {
187
+ * redirectUrl:
188
+ * 'https://approvals.example/approvals/d27966cc-128d-48a2-b681-6ad52012e113/payment-receipt',
189
+ * paymentFormUrl:
190
+ * 'https://approvals.example/approvals/d27966cc-128d-48a2-b681-6ad52012e113/payment',
191
+ * form,
192
+ * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',
193
+ * },
194
+ * )
195
+ * ```
196
+ *
197
+ * @param formSubmissionApprovalId
198
+ * @param options
199
+ * @param options.redirectUrl The URL the payment provider redirects to when the
200
+ * payment finishes.
201
+ * @param options.paymentFormUrl The in-app payment page. Required for providers
202
+ * that render their payment form in the app.
203
+ * @param options.form The form definition for this approval.
204
+ * @param options.submissionId The submission this approval belongs to.
205
+ * @param options.replacePendingPayment Cancel a checkout that is already in
206
+ * progress so this payment can start. Leave unset to reject that checkout.
207
+ * @param abortSignal
208
+ * @returns
209
+ */
210
+ export async function createApprovalStepPayment(formSubmissionApprovalId, options, abortSignal) {
211
+ const { redirectUrl, paymentFormUrl, form, submissionId, replacePendingPayment, } = options;
212
+ let result;
213
+ try {
214
+ result = await postRequest(`${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/payment`, {
215
+ redirectUrl,
216
+ paymentFormUrl,
217
+ replacePendingPayment,
218
+ }, abortSignal);
219
+ }
220
+ catch (error) {
221
+ if (error instanceof HTTPError &&
222
+ error.status === 409 &&
223
+ error.conflict === PAYMENT_IN_PROGRESS_CONFLICT) {
224
+ throw new OneBlinkAppsError('A payment is already in progress for this step. Finish or cancel that payment before starting another.', {
225
+ httpStatusCode: error.status,
226
+ conflict: PAYMENT_IN_PROGRESS_CONFLICT,
227
+ originalError: error,
228
+ });
229
+ }
230
+ throw error;
231
+ }
232
+ await rememberPaymentSubmissionResult({
233
+ submission: {},
234
+ // The post-submission receipt is written for the original submitter.
235
+ // This result has no submission to fill its injectables.
236
+ definition: {
237
+ ...form,
238
+ postSubmissionReceipt: undefined,
239
+ },
240
+ preFillFormDataId: null,
241
+ submissionId,
242
+ submissionTimestamp: new Date().toISOString(),
243
+ payment: {
244
+ amount: result.amount,
245
+ paymentReceiptUrl: redirectUrl,
246
+ paymentFormUrl,
247
+ hostedFormUrl: result.hostedFormUrl,
248
+ submissionEvent: result.paymentSubmissionEvent,
249
+ },
250
+ scheduling: null,
251
+ isInPendingQueue: false,
252
+ isOffline: false,
253
+ isUploadingAttachments: false,
254
+ });
255
+ return result;
256
+ }
257
+ /**
258
+ * Skip the payment for an approval step and continue the approval flow.
259
+ *
260
+ * #### Example
261
+ *
262
+ * ```js
263
+ * const formSubmissionApproval =
264
+ * await approvalsService.skipApprovalStepPayment(
265
+ * 'd27966cc-128d-48a2-b681-6ad52012e113',
266
+ * )
267
+ * ```
268
+ *
269
+ * @param formSubmissionApprovalId
270
+ * @param abortSignal
271
+ * @returns
272
+ */
273
+ export async function skipApprovalStepPayment(formSubmissionApprovalId, abortSignal) {
274
+ return await postRequest(`${tenants.current.apiOrigin}/form-submission-approvals/${formSubmissionApprovalId}/skip-payment`, {}, abortSignal);
275
+ }
140
276
  /**
141
277
  * Update a single FormSubmissionApproval assigned to the current user.
142
278
  *