@oneblink/apps-react 11.1.2-beta.2 → 11.2.0-beta.1
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/PaymentReceipt.js +12 -8
- package/dist/PaymentReceipt.js.map +1 -1
- package/dist/apps/payment-service.d.ts +2 -7
- package/dist/apps/payment-service.js +17 -14
- package/dist/apps/payment-service.js.map +1 -1
- package/dist/apps/scheduling-service.js +0 -1
- package/dist/apps/scheduling-service.js.map +1 -1
- package/dist/apps/services/api/payment.d.ts +8 -4
- package/dist/apps/services/api/payment.js +5 -6
- package/dist/apps/services/api/payment.js.map +1 -1
- package/dist/apps/services/payment-providers/BPOINTPaymentProvider.d.ts +1 -13
- package/dist/apps/services/payment-providers/BPOINTPaymentProvider.js +0 -14
- package/dist/apps/services/payment-providers/BPOINTPaymentProvider.js.map +1 -1
- package/dist/apps/services/payment-providers/CPPayPaymentProvider.d.ts +1 -11
- package/dist/apps/services/payment-providers/CPPayPaymentProvider.js +0 -9
- package/dist/apps/services/payment-providers/CPPayPaymentProvider.js.map +1 -1
- package/dist/apps/services/payment-providers/NSWGovPayPaymentProvider.d.ts +1 -14
- package/dist/apps/services/payment-providers/NSWGovPayPaymentProvider.js +0 -15
- package/dist/apps/services/payment-providers/NSWGovPayPaymentProvider.js.map +1 -1
- package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.d.ts +1 -5
- package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js +0 -12
- package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js.map +1 -1
- package/dist/apps/services/submit.js +7 -8
- package/dist/apps/services/submit.js.map +1 -1
- package/dist/apps/types/payments.d.ts +0 -10
- package/dist/apps/types/payments.js.map +1 -1
- package/dist/form-elements/FormElementCalculation.js +22 -193
- package/dist/form-elements/FormElementCalculation.js.map +1 -1
- package/package.json +2 -4
package/dist/PaymentReceipt.js
CHANGED
|
@@ -111,7 +111,6 @@ function PaymentReceipt({ onDone, onCancel, }) {
|
|
|
111
111
|
if (!submissionResult || !submissionResult.payment) {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
|
-
const paymentSubmissionEvent = submissionResult.payment.submissionEvent;
|
|
115
114
|
if (isMounted.current) {
|
|
116
115
|
setRetryState({
|
|
117
116
|
isRetrying: true,
|
|
@@ -121,16 +120,21 @@ function PaymentReceipt({ onDone, onCancel, }) {
|
|
|
121
120
|
let newError = null;
|
|
122
121
|
try {
|
|
123
122
|
const payment = await handlePaymentSubmissionEvent({
|
|
124
|
-
amount: submissionResult.payment.amount,
|
|
125
123
|
formSubmissionResult: submissionResult,
|
|
126
|
-
paymentSubmissionEvent,
|
|
127
124
|
paymentReceiptUrl: submissionResult.payment.paymentReceiptUrl,
|
|
128
125
|
paymentFormUrl: submissionResult.payment.paymentFormUrl,
|
|
129
126
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
// The API has decided that no payment is required on try again
|
|
128
|
+
if (!payment) {
|
|
129
|
+
// Do the success path
|
|
130
|
+
handleDone();
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
await submissionService.executePostSubmissionAction({ ...submissionResult, payment }, {
|
|
134
|
+
onRedirectToRelativeUrl: (url) => history.push(url),
|
|
135
|
+
onRedirectToAbsoluteUrl: (url) => window.location.assign(url),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
134
138
|
}
|
|
135
139
|
catch (error) {
|
|
136
140
|
console.warn('Error while attempting to retry transaction', error);
|
|
@@ -142,7 +146,7 @@ function PaymentReceipt({ onDone, onCancel, }) {
|
|
|
142
146
|
retryError: newError,
|
|
143
147
|
});
|
|
144
148
|
}
|
|
145
|
-
}, [history, isMounted, submissionResult]);
|
|
149
|
+
}, [history, isMounted, submissionResult, handleDone]);
|
|
146
150
|
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
|
|
147
151
|
? undefined
|
|
148
152
|
: transaction.errorMessage || undefined, children: [receiptItems &&
|
|
@@ -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,iBAAiB,EAGjB,mBAAmB,GACpB,MAAM,QAAQ,CAAA;AACf,OAAO,YAAY,MAAM,sBAAsB,CAAA;AAE/C,OAAO,QAAQ,MAAM,kBAAkB,CAAA;AACvC,OAAO,KAAK,MAAM,6BAA6B,CAAA;AAC/C,OAAO,SAAS,MAAM,iCAAiC,CAAA;AACvD,OAAO,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,aAAa,GACd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,YAAY,MAAM,2BAA2B,CAAA;AACpD,OAAO,iBAAiB,MAAM,iCAAiC,CAAA;AAE/D,MAAM,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,GAC9D,cAAc,CAAA;AAEhB,SAAS,cAAc,CAAC,EACtB,MAAM,EACN,QAAQ,GAkBT;IACC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;IACxB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;IAE5B,MAAM,CACJ,EACE,SAAS,EACT,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,Y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,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 DownloadableFiles from './components/downloadable-files'\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 const paymentSubmissionEvent = submissionResult.payment.submissionEvent\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 amount: submissionResult.payment.amount,\n formSubmissionResult: submissionResult,\n paymentSubmissionEvent,\n paymentReceiptUrl: submissionResult.payment.paymentReceiptUrl,\n paymentFormUrl: submissionResult.payment.paymentFormUrl,\n })\n await submissionService.executePostSubmissionAction({ ...submissionResult, payment }, {\n onRedirectToRelativeUrl: (url) => history.push(url),\n onRedirectToAbsoluteUrl: (url) => window.location.assign(url),\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])\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 >\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,EACL,cAAc,EACd,iBAAiB,EAGjB,mBAAmB,GACpB,MAAM,QAAQ,CAAA;AACf,OAAO,YAAY,MAAM,sBAAsB,CAAA;AAE/C,OAAO,QAAQ,MAAM,kBAAkB,CAAA;AACvC,OAAO,KAAK,MAAM,6BAA6B,CAAA;AAC/C,OAAO,SAAS,MAAM,iCAAiC,CAAA;AACvD,OAAO,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,aAAa,GACd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,YAAY,MAAM,2BAA2B,CAAA;AACpD,OAAO,iBAAiB,MAAM,iCAAiC,CAAA;AAE/D,MAAM,EAAE,wBAAwB,E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AA6D,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 DownloadableFiles from './components/downloadable-files'\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 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 >\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"]}
|
|
@@ -25,10 +25,7 @@ export { HandlePaymentResult, PaymentReceiptItem, westpacQuickStream };
|
|
|
25
25
|
* @returns
|
|
26
26
|
*/
|
|
27
27
|
export declare function handlePaymentQuerystring(query: Record<string, unknown>): Promise<HandlePaymentResult>;
|
|
28
|
-
export declare function checkForPaymentSubmissionEvent(formSubmission: FormSubmission, submissionTimestamp: string):
|
|
29
|
-
paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent;
|
|
30
|
-
amount: number;
|
|
31
|
-
} | undefined;
|
|
28
|
+
export declare function checkForPaymentSubmissionEvent(formSubmission: FormSubmission, submissionTimestamp: string): SubmissionEventTypes.FormPaymentEvent | undefined;
|
|
32
29
|
/**
|
|
33
30
|
* Handle a submission result with a payment submission event. Will throw an
|
|
34
31
|
* error if a transaction has already been made using this submission result.
|
|
@@ -72,10 +69,8 @@ export declare function checkForPaymentSubmissionEvent(formSubmission: FormSubmi
|
|
|
72
69
|
* @param options
|
|
73
70
|
* @returns
|
|
74
71
|
*/
|
|
75
|
-
export declare function handlePaymentSubmissionEvent({
|
|
76
|
-
amount: number;
|
|
72
|
+
export declare function handlePaymentSubmissionEvent({ formSubmissionResult, paymentReceiptUrl, paymentFormUrl, }: {
|
|
77
73
|
formSubmissionResult: FormSubmissionResult;
|
|
78
|
-
paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent;
|
|
79
74
|
paymentReceiptUrl: string;
|
|
80
75
|
paymentFormUrl: string | undefined;
|
|
81
76
|
}): Promise<FormSubmissionResult['payment']>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { paymentService } from '@oneblink/sdk-core';
|
|
2
2
|
import OneBlinkAppsError from './services/errors/oneBlinkAppsError';
|
|
3
|
-
import {
|
|
3
|
+
import { createPaymentConfiguration } from './services/api/payment';
|
|
4
4
|
import utilsService from './services/utils';
|
|
5
5
|
import BPOINTPaymentProvider from './services/payment-providers/BPOINTPaymentProvider';
|
|
6
6
|
import CPPayPaymentProvider from './services/payment-providers/CPPayPaymentProvider';
|
|
@@ -83,8 +83,9 @@ export function checkForPaymentSubmissionEvent(formSubmission, submissionTimesta
|
|
|
83
83
|
});
|
|
84
84
|
if (result) {
|
|
85
85
|
console.log('Form has a payment submission event with amount', result);
|
|
86
|
+
return result.paymentSubmissionEvent;
|
|
86
87
|
}
|
|
87
|
-
return
|
|
88
|
+
return undefined;
|
|
88
89
|
}
|
|
89
90
|
/**
|
|
90
91
|
* Handle a submission result with a payment submission event. Will throw an
|
|
@@ -129,23 +130,25 @@ export function checkForPaymentSubmissionEvent(formSubmission, submissionTimesta
|
|
|
129
130
|
* @param options
|
|
130
131
|
* @returns
|
|
131
132
|
*/
|
|
132
|
-
export async function handlePaymentSubmissionEvent({
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
export async function handlePaymentSubmissionEvent({ formSubmissionResult, paymentReceiptUrl, paymentFormUrl, }) {
|
|
134
|
+
if (!formSubmissionResult.submissionId) {
|
|
135
|
+
throw new OneBlinkAppsError('It looks like you are attempting to make a payment for an unknown submission.');
|
|
136
|
+
}
|
|
137
|
+
const paymentConfiguration = await createPaymentConfiguration(formSubmissionResult.submissionId, { redirectUrl: paymentReceiptUrl, paymentFormUrl });
|
|
138
|
+
if (!paymentConfiguration) {
|
|
139
|
+
await utilsService.setLocalForageItem(KEY, {
|
|
140
|
+
...formSubmissionResult,
|
|
141
|
+
scheduling: null,
|
|
142
|
+
payment: null,
|
|
143
|
+
});
|
|
144
|
+
return null;
|
|
136
145
|
}
|
|
137
|
-
const paymentConfiguration = await generatePaymentConfiguration(paymentProvider, {
|
|
138
|
-
amount,
|
|
139
|
-
redirectUrl: paymentReceiptUrl,
|
|
140
|
-
submissionId: formSubmissionResult.submissionId,
|
|
141
|
-
paymentFormUrl,
|
|
142
|
-
});
|
|
143
146
|
const payment = {
|
|
144
|
-
submissionEvent: paymentSubmissionEvent,
|
|
147
|
+
submissionEvent: paymentConfiguration.paymentSubmissionEvent,
|
|
145
148
|
paymentReceiptUrl,
|
|
146
149
|
hostedFormUrl: paymentConfiguration.hostedFormUrl,
|
|
147
150
|
paymentFormUrl,
|
|
148
|
-
amount,
|
|
151
|
+
amount: paymentConfiguration.amount,
|
|
149
152
|
};
|
|
150
153
|
console.log('Created Payment configuration to start transaction', payment);
|
|
151
154
|
await utilsService.setLocalForageItem(KEY, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment-service.js","sourceRoot":"","sources":["../../src/apps/payment-service.ts"],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AAM,IAAI,iBAAiB,CACzB,oFAAoF,CACrF,CAAA;IACH,CAAC;IACD,IAAI,CAAC,CAAA,MAAA,oBAAoB,CAAC,OAAO,0CAAE,eAAe,CAAA,EAAE,CAAC;QACnD,MAAM,IAAI,iBAAiB,CACzB,yFAAyF,CAC1F,CAAA;IACH,CAAC;IAED,OAAO;QACL,oBAAoB;QACpB,sBAAsB,EAAE,MAAA,oBAAoB,CAAC,OAAO,0CAAE,eAAe;KACtE,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,0CAA0C,CACxD,qBAA4D;IAE5D,OAAO,cAAc,CAAC,0CAA0C,CAC9D,qBAAqB,EACrB,2BAA2B,CAC5B,CAAA;AACH,CAAC","sourcesContent":["import { paymentService } from '@oneblink/sdk-core'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport { generatePaymentConfiguration } from './services/api/payment'\nimport utilsService from './services/utils'\nimport { SubmissionEventTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormSubmission, FormSubmissionResult } from './types/submissions'\nimport {\n HandlePaymentResult,\n PaymentProvider,\n PaymentReceiptItem,\n} from './types/payments'\nimport BPOINTPaymentProvider from './services/payment-providers/BPOINTPaymentProvider'\nimport CPPayPaymentProvider from './services/payment-providers/CPPayPaymentProvider'\nimport NSWGovPayPaymentProvider from './services/payment-providers/NSWGovPayPaymentProvider'\nimport WestpacQuickStreamPaymentProvider, * as westpacQuickStream from './services/payment-providers/WestpacQuickStreamPaymentProvider'\nimport {\n addDaysToDate,\n endOfDay,\n parseDayOnlyDate,\n startOfDay,\n replaceSubmissionFormatters,\n} from './localisation-service'\nimport {\n getSchedulingBooking,\n removeSchedulingBooking,\n} from './services/schedulingHandlers'\n\nconst KEY = 'PAYMENT_SUBMISSION_RESULT'\n\nexport { HandlePaymentResult, PaymentReceiptItem, westpacQuickStream }\n\nfunction getPaymentProvider(\n formSubmissionResult: FormSubmissionResult,\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent,\n): PaymentProvider<SubmissionEventTypes.FormPaymentEvent> {\n switch (paymentSubmissionEvent.type) {\n case 'BPOINT': {\n return new BPOINTPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'CP_PAY': {\n return new CPPayPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'NSW_GOV_PAY': {\n return new NSWGovPayPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'WESTPAC_QUICK_STREAM': {\n return new WestpacQuickStreamPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n }\n}\n\n/**\n * Pass in query string parameters after a redirect back to your app after a\n * payment is processed. This function will handle all payment submission events\n * supported by OneBlink. Will return a Transaction and the submission result\n * that was returned from `handlePaymentSubmissionEvent()` before redirecting to\n * `payment.hostedFormUrl`.\n *\n * #### Example\n *\n * ```js\n * import queryString from 'query-string'\n *\n * const query = queryString.parse(window.location.search)\n * const { transaction, submissionResult } =\n * await paymentService.handlePaymentQuerystring(query)\n * ```\n *\n * @param query\n * @returns\n */\nexport async function handlePaymentQuerystring(\n query: Record<string, unknown>,\n): Promise<HandlePaymentResult> {\n const submissionResult =\n await utilsService.getLocalForageItem<FormSubmissionResult | null>(KEY)\n // If the current transaction does not match the submission\n // we will display message to user indicating\n // they are looking for the wrong transaction receipt.\n if (!submissionResult) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for an unknown payment.',\n )\n }\n if (!submissionResult.payment || !submissionResult.payment.submissionEvent) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for a misconfigured payment.',\n )\n }\n const paymentProvider = getPaymentProvider(\n submissionResult,\n submissionResult.payment.submissionEvent,\n )\n if (!paymentProvider) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for an unsupported payment.',\n )\n }\n\n const verifiedPaymentTransaction =\n await paymentProvider.verifyPaymentTransaction(query)\n\n const schedulingBooking = await getSchedulingBooking(\n verifiedPaymentTransaction.submissionResult.submissionId,\n )\n if (schedulingBooking && verifiedPaymentTransaction.transaction.isSuccess) {\n await removeSchedulingBooking(schedulingBooking.submissionId)\n }\n\n return {\n ...verifiedPaymentTransaction,\n schedulingBooking,\n }\n}\n\nexport function checkForPaymentSubmissionEvent(\n formSubmission: FormSubmission,\n submissionTimestamp: string,\n):\n | {\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n amount: number\n }\n | undefined {\n const result = paymentService.checkForPaymentEvent({\n definition: formSubmission.definition,\n submission: formSubmission.submission,\n submissionTimestamp,\n parseDayOnlyDate,\n addDaysToDate,\n startOfDay,\n endOfDay,\n })\n if (result) {\n console.log('Form has a payment submission event with amount', result)\n }\n return result\n}\n\n/**\n * Handle a submission result with a payment submission event. Will throw an\n * error if a transaction has already been made using this submission result.\n * Will return `undefined` if the submission does not have an amount. Will\n * return the submission result passed in with a `payment` property if the\n * submission requires processing.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionResult = {\n * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * submissionTimestamp: '2020-07-29T01:03:26.573Z'\n * formsAppId: 1,\n * submission: {\n * form: 'data',\n * goes: 'here',\n * amount: 1.50,\n * }\n * definition: OneBlinkForm,\n * payment: null,\n * }\n * const paymentSubmissionEvent = {\n * type: 'CP_PAY',\n * configuration: {\n * elementId: '12663efc-4c6a-4e72-8505-559edfe3e92e',\n * gatewayId: '6658c5c4-e0db-483b-8af7-6a6464fe772c',\n * },\n * }\n * const paymentReceiptUrl = `${window.location.origin}/payment-receipt`\n * const paymentSubmissionResult = await paymentService.handlePaymentSubmissionEvent({\n * formSubmissionResult,\n * paymentSubmissionEvent,\n * paymentReceiptUrl,\n * })\n * if (paymentSubmissionResult) {\n * window.location.href = paymentSubmissionResult.payment.hostedFormUrl\n * }\n * ```\n *\n * @param options\n * @returns\n */\nexport async function handlePaymentSubmissionEvent({\n amount,\n formSubmissionResult,\n paymentSubmissionEvent,\n paymentReceiptUrl,\n paymentFormUrl,\n}: {\n amount: number\n formSubmissionResult: FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n paymentReceiptUrl: string\n paymentFormUrl: string | undefined\n}): Promise<FormSubmissionResult['payment']> {\n const paymentProvider = getPaymentProvider(\n formSubmissionResult,\n paymentSubmissionEvent,\n )\n if (!paymentProvider) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to make a payment using an unsupported payment method.',\n )\n }\n\n const paymentConfiguration = await generatePaymentConfiguration(\n paymentProvider,\n {\n amount,\n redirectUrl: paymentReceiptUrl,\n submissionId: formSubmissionResult.submissionId,\n paymentFormUrl,\n },\n )\n\n const payment = {\n submissionEvent: paymentSubmissionEvent,\n paymentReceiptUrl,\n hostedFormUrl: paymentConfiguration.hostedFormUrl,\n paymentFormUrl,\n amount,\n }\n console.log('Created Payment configuration to start transaction', payment)\n\n await utilsService.setLocalForageItem(KEY, {\n ...formSubmissionResult,\n scheduling: null,\n payment,\n })\n\n return payment\n}\n\nexport async function getFormSubmissionResultPayment(): Promise<{\n formSubmissionResult: FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n}> {\n const formSubmissionResult =\n await utilsService.getLocalForageItem<FormSubmissionResult | null>(KEY)\n\n if (!formSubmissionResult) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to complete a transaction for an unknown payment.',\n )\n }\n if (!formSubmissionResult.payment?.submissionEvent) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to complete a transaction for a misconfigured payment.',\n )\n }\n\n return {\n formSubmissionResult,\n paymentSubmissionEvent: formSubmissionResult.payment?.submissionEvent,\n }\n}\n\n/**\n * Retrieve an array of detail items from a form submission payment.\n *\n * #### Example\n *\n * ```js\n * const detailItems =\n * paymentService.getDisplayDetailsFromFormSubmissionPayment(\n * formSubmissionPayment,\n * )\n * ```\n *\n * @param formSubmissionPayment\n * @returns\n */\nexport function getDisplayDetailsFromFormSubmissionPayment(\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment,\n) {\n return paymentService.getDisplayDetailsFromFormSubmissionPayment(\n formSubmissionPayment,\n replaceSubmissionFormatters,\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"payment-service.js","sourceRoot":"","sources":["../../src/apps/payment-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAA;AACnE,OAAO,YAAY,MAAM,kBAAkB,CAAA;AAQ3C,OAAO,qBAAqB,MAAM,oDAAoD,CAAA;AACtF,OAAO,oBAAoB,MAAM,mDAAmD,CAAA;AACpF,OAAO,wBAAwB,MAAM,uDAAuD,CAAA;AAC5F,OAAO,iCAAiC,EAAE,KAAK,kBAAkB,MAAM,gEAAgE,CAAA;AACvI,OAAO,EACL,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,2BAA2B,GAC5B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,+BAA+B,CAAA;AAEtC,MAAM,GAAG,GAAG,2BAA2B,CAAA;AAEvC,OAAO,EAA2C,kBAAkB,EAAE,CAAA;AAEtE,SAAS,kBAAkB,CACzB,oBAA0C,EAC1C,sBAA6D;IAE7D,QAAQ,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACpC,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,IAAI,qBAAqB,CAC9B,sBAAsB,EACtB,oBAAoB,CACrB,CAAA;QACH,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,OAAO,IAAI,oBAAoB,CAC7B,sBAAsB,EACtB,oBAAoB,CACrB,CAAA;QACH,CAAC;QACD,KAAK,aAAa,CAAC,CAAC,CAAC;YACnB,OAAO,IAAI,w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A;IACD,OAAO,CAAC,GAAG,CAAC,oDAAoD,EAAE,OAAO,CAAC,CAAA;IAE1E,MAAM,YAAY,CAAC,kBAAkB,CAAC,GAAG,EAAE;QACzC,GAAG,oBAAoB;QACvB,UAAU,EAAE,IAAI;QAChB,OAAO;KACR,CAAC,CAAA;IAEF,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,8BAA8B;;IAIlD,MAAM,oBAAoB,GACxB,MAAM,YAAY,CAAC,kBAAkB,CAA8B,GAAG,CAAC,CAAA;IAEzE,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,MAAM,IAAI,iBAAiB,CACzB,oFAAoF,CACrF,CAAA;IACH,CAAC;IACD,IAAI,CAAC,CAAA,MAAA,oBAAoB,CAAC,OAAO,0CAAE,eAAe,CAAA,EAAE,CAAC;QACnD,MAAM,IAAI,iBAAiB,CACzB,yFAAyF,CAC1F,CAAA;IACH,CAAC;IAED,OAAO;QACL,oBAAoB;QACpB,sBAAsB,EAAE,MAAA,oBAAoB,CAAC,OAAO,0CAAE,eAAe;KACtE,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,0CAA0C,CACxD,qBAA4D;IAE5D,OAAO,cAAc,CAAC,0CAA0C,CAC9D,qBAAqB,EACrB,2BAA2B,CAC5B,CAAA;AACH,CAAC","sourcesContent":["import { paymentService } from '@oneblink/sdk-core'\nimport OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport { createPaymentConfiguration } from './services/api/payment'\nimport utilsService from './services/utils'\nimport { SubmissionEventTypes, SubmissionTypes } from '@oneblink/types'\nimport { FormSubmission, FormSubmissionResult } from './types/submissions'\nimport {\n HandlePaymentResult,\n PaymentProvider,\n PaymentReceiptItem,\n} from './types/payments'\nimport BPOINTPaymentProvider from './services/payment-providers/BPOINTPaymentProvider'\nimport CPPayPaymentProvider from './services/payment-providers/CPPayPaymentProvider'\nimport NSWGovPayPaymentProvider from './services/payment-providers/NSWGovPayPaymentProvider'\nimport WestpacQuickStreamPaymentProvider, * as westpacQuickStream from './services/payment-providers/WestpacQuickStreamPaymentProvider'\nimport {\n addDaysToDate,\n endOfDay,\n parseDayOnlyDate,\n startOfDay,\n replaceSubmissionFormatters,\n} from './localisation-service'\nimport {\n getSchedulingBooking,\n removeSchedulingBooking,\n} from './services/schedulingHandlers'\n\nconst KEY = 'PAYMENT_SUBMISSION_RESULT'\n\nexport { HandlePaymentResult, PaymentReceiptItem, westpacQuickStream }\n\nfunction getPaymentProvider(\n formSubmissionResult: FormSubmissionResult,\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent,\n): PaymentProvider<SubmissionEventTypes.FormPaymentEvent> {\n switch (paymentSubmissionEvent.type) {\n case 'BPOINT': {\n return new BPOINTPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'CP_PAY': {\n return new CPPayPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'NSW_GOV_PAY': {\n return new NSWGovPayPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n case 'WESTPAC_QUICK_STREAM': {\n return new WestpacQuickStreamPaymentProvider(\n paymentSubmissionEvent,\n formSubmissionResult,\n )\n }\n }\n}\n\n/**\n * Pass in query string parameters after a redirect back to your app after a\n * payment is processed. This function will handle all payment submission events\n * supported by OneBlink. Will return a Transaction and the submission result\n * that was returned from `handlePaymentSubmissionEvent()` before redirecting to\n * `payment.hostedFormUrl`.\n *\n * #### Example\n *\n * ```js\n * import queryString from 'query-string'\n *\n * const query = queryString.parse(window.location.search)\n * const { transaction, submissionResult } =\n * await paymentService.handlePaymentQuerystring(query)\n * ```\n *\n * @param query\n * @returns\n */\nexport async function handlePaymentQuerystring(\n query: Record<string, unknown>,\n): Promise<HandlePaymentResult> {\n const submissionResult =\n await utilsService.getLocalForageItem<FormSubmissionResult | null>(KEY)\n // If the current transaction does not match the submission\n // we will display message to user indicating\n // they are looking for the wrong transaction receipt.\n if (!submissionResult) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for an unknown payment.',\n )\n }\n if (!submissionResult.payment || !submissionResult.payment.submissionEvent) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for a misconfigured payment.',\n )\n }\n const paymentProvider = getPaymentProvider(\n submissionResult,\n submissionResult.payment.submissionEvent,\n )\n if (!paymentProvider) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for an unsupported payment.',\n )\n }\n\n const verifiedPaymentTransaction =\n await paymentProvider.verifyPaymentTransaction(query)\n\n const schedulingBooking = await getSchedulingBooking(\n verifiedPaymentTransaction.submissionResult.submissionId,\n )\n if (schedulingBooking && verifiedPaymentTransaction.transaction.isSuccess) {\n await removeSchedulingBooking(schedulingBooking.submissionId)\n }\n\n return {\n ...verifiedPaymentTransaction,\n schedulingBooking,\n }\n}\n\nexport function checkForPaymentSubmissionEvent(\n formSubmission: FormSubmission,\n submissionTimestamp: string,\n): SubmissionEventTypes.FormPaymentEvent | undefined {\n const result = paymentService.checkForPaymentEvent({\n definition: formSubmission.definition,\n submission: formSubmission.submission,\n submissionTimestamp,\n parseDayOnlyDate,\n addDaysToDate,\n startOfDay,\n endOfDay,\n })\n if (result) {\n console.log('Form has a payment submission event with amount', result)\n return result.paymentSubmissionEvent\n }\n return undefined\n}\n\n/**\n * Handle a submission result with a payment submission event. Will throw an\n * error if a transaction has already been made using this submission result.\n * Will return `undefined` if the submission does not have an amount. Will\n * return the submission result passed in with a `payment` property if the\n * submission requires processing.\n *\n * #### Example\n *\n * ```js\n * const formSubmissionResult = {\n * submissionId: '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * submissionTimestamp: '2020-07-29T01:03:26.573Z'\n * formsAppId: 1,\n * submission: {\n * form: 'data',\n * goes: 'here',\n * amount: 1.50,\n * }\n * definition: OneBlinkForm,\n * payment: null,\n * }\n * const paymentSubmissionEvent = {\n * type: 'CP_PAY',\n * configuration: {\n * elementId: '12663efc-4c6a-4e72-8505-559edfe3e92e',\n * gatewayId: '6658c5c4-e0db-483b-8af7-6a6464fe772c',\n * },\n * }\n * const paymentReceiptUrl = `${window.location.origin}/payment-receipt`\n * const paymentSubmissionResult = await paymentService.handlePaymentSubmissionEvent({\n * formSubmissionResult,\n * paymentSubmissionEvent,\n * paymentReceiptUrl,\n * })\n * if (paymentSubmissionResult) {\n * window.location.href = paymentSubmissionResult.payment.hostedFormUrl\n * }\n * ```\n *\n * @param options\n * @returns\n */\nexport async function handlePaymentSubmissionEvent({\n formSubmissionResult,\n paymentReceiptUrl,\n paymentFormUrl,\n}: {\n formSubmissionResult: FormSubmissionResult\n paymentReceiptUrl: string\n paymentFormUrl: string | undefined\n}): Promise<FormSubmissionResult['payment']> {\n if (!formSubmissionResult.submissionId) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to make a payment for an unknown submission.',\n )\n }\n const paymentConfiguration = await createPaymentConfiguration(\n formSubmissionResult.submissionId,\n { redirectUrl: paymentReceiptUrl, paymentFormUrl },\n )\n\n if (!paymentConfiguration) {\n await utilsService.setLocalForageItem(KEY, {\n ...formSubmissionResult,\n scheduling: null,\n payment: null,\n })\n return null\n }\n\n const payment = {\n submissionEvent: paymentConfiguration.paymentSubmissionEvent,\n paymentReceiptUrl,\n hostedFormUrl: paymentConfiguration.hostedFormUrl,\n paymentFormUrl,\n amount: paymentConfiguration.amount,\n }\n console.log('Created Payment configuration to start transaction', payment)\n\n await utilsService.setLocalForageItem(KEY, {\n ...formSubmissionResult,\n scheduling: null,\n payment,\n })\n\n return payment\n}\n\nexport async function getFormSubmissionResultPayment(): Promise<{\n formSubmissionResult: FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n}> {\n const formSubmissionResult =\n await utilsService.getLocalForageItem<FormSubmissionResult | null>(KEY)\n\n if (!formSubmissionResult) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to complete a transaction for an unknown payment.',\n )\n }\n if (!formSubmissionResult.payment?.submissionEvent) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to complete a transaction for a misconfigured payment.',\n )\n }\n\n return {\n formSubmissionResult,\n paymentSubmissionEvent: formSubmissionResult.payment?.submissionEvent,\n }\n}\n\n/**\n * Retrieve an array of detail items from a form submission payment.\n *\n * #### Example\n *\n * ```js\n * const detailItems =\n * paymentService.getDisplayDetailsFromFormSubmissionPayment(\n * formSubmissionPayment,\n * )\n * ```\n *\n * @param formSubmissionPayment\n * @returns\n */\nexport function getDisplayDetailsFromFormSubmissionPayment(\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment,\n) {\n return paymentService.getDisplayDetailsFromFormSubmissionPayment(\n formSubmissionPayment,\n replaceSubmissionFormatters,\n )\n}\n"]}
|
|
@@ -11,7 +11,6 @@ async function getPaymentConfiguration({ paymentReceiptUrl, paymentFormUrl, prev
|
|
|
11
11
|
const paymentSubmissionEventConfiguration = checkForPaymentSubmissionEvent(formSubmissionResult, (_a = formSubmissionResult.submissionTimestamp) !== null && _a !== void 0 ? _a : new Date().toISOString());
|
|
12
12
|
if (paymentSubmissionEventConfiguration) {
|
|
13
13
|
return await handlePaymentSubmissionEvent({
|
|
14
|
-
...paymentSubmissionEventConfiguration,
|
|
15
14
|
formSubmissionResult,
|
|
16
15
|
paymentReceiptUrl,
|
|
17
16
|
paymentFormUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduling-service.js","sourceRoot":"","sources":["../../src/apps/scheduling-service.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,iCAAiC,EAAE,MAAM,2BAA2B,CAAA;AAC7E,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAEL,6BAA6B,EAC7B,gCAAgC,EAChC,oBAAoB,GACrB,MAAM,+BAA+B,CAAA;AAEtC,KAAK,UAAU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;QAChC,OAAO,aAAa,KAAK,QAAQ;QACjC,OAAO,SAAS,KAAK,QAAQ;QAC7B,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,SAAS,KAAK,QAAQ;QAC7B,OAAO,QAAQ,KAAK,QAAQ;QAC5B,OAAO,QAAQ,KAAK,QAAQ;QAC5B,CAAC,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,KAAK,SAAS,CAAC,EAC5E,CAAC;QACD,MAAM,IAAI,iBAAiB,CACzB,uFAAuF,CACxF,CAAA;IACH,CAAC;IAED,MAAM,OAAO,GAAG;QACd,aAAa;QACb,YAAY;QACZ,SAAS,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;QAC/C,OAAO,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QAC3C,SAAS;QACT,QAAQ;QACR,QAAQ;QACR,kBAAkB;KACnB,CAAA;IACD,OAAO,CAAC,GAAG,CAAC,uCAAuC,EAAE,OAAO,CAAC,CAAA;IAE7D,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,KAAK,UAAU,4BAA4B,CACzC,YAAoB,EACpB,WAAwB;IAaxB,MAAM,OAAO,GAAG,MAAM,iCAAiC,CACrD,YAAY,EACZ,WAAW,CACZ,CAAA;IAED,OAAO;QACL,GAAG,OAAO;QACV,KAAK,CAAC,kBAAkB,CAAC,iBAAoC;YAC3D,OAAO,MAAM,iCAAiC,CAC5C,YAAY,EACZ,iBAAiB,CAClB,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED,OAAO,EAEL,2BAA2B,EAC3B,wCAAwC,EACxC,iCAAiC,EACjC,4BAA4B,EAC5B,iCAAiC,GAClC,CAAA","sourcesContent":["import OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport { createNylasExistingBookingSession } from './services/api/scheduling'\nimport {\n checkForPaymentSubmissionEvent,\n handlePaymentSubmissionEvent,\n} from './payment-service'\nimport { FormSubmissionResult } from './types/submissions'\nimport {\n SchedulingBooking,\n getSchedulingSubmissionResult,\n removeSchedulingSubmissionResult,\n setSchedulingBooking,\n} from './services/schedulingHandlers'\n\nasync function getPaymentConfiguration({\n paymentReceiptUrl,\n paymentFormUrl,\n preventPayment,\n formSubmissionResult,\n schedulingBooking,\n}: {\n paymentReceiptUrl: string | undefined\n paymentFormUrl: string | undefined\n preventPayment: boolean\n formSubmissionResult: FormSubmissionResult\n schedulingBooking: SchedulingBooking\n}) {\n if (preventPayment || !paymentReceiptUrl) {\n return null\n }\n\n await setSchedulingBooking(schedulingBooking)\n const paymentSubmissionEventConfiguration = checkForPaymentSubmissionEvent(\n formSubmissionResult,\n formSubmissionResult.submissionTimestamp ?? new Date().toISOString(),\n )\n if (paymentSubmissionEventConfiguration) {\n return await handlePaymentSubmissionEvent({\n ...paymentSubmissionEventConfiguration,\n formSubmissionResult,\n paymentReceiptUrl,\n paymentFormUrl,\n })\n }\n\n return null\n}\n\nasync function getSchedulingFormSubmissionResult(\n submissionId: string,\n schedulingBooking: SchedulingBooking,\n) {\n const schedulingSubmissionResultConfiguration =\n await getSchedulingSubmissionResult()\n // If the current transaction does not match the submission\n // we will display message to user indicating\n // they are looking for the wrong transaction receipt.\n if (!schedulingSubmissionResultConfiguration) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a scheduling receipt for an unknown booking.',\n )\n }\n\n const {\n formSubmissionResult,\n paymentReceiptUrl,\n paymentFormUrl,\n preventPayment,\n } = schedulingSubmissionResultConfiguration\n if (\n !formSubmissionResult ||\n !formSubmissionResult.scheduling ||\n !formSubmissionResult.scheduling.submissionEvent\n ) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a scheduling receipt for a misconfigured booking.',\n )\n }\n\n if (formSubmissionResult.submissionId !== submissionId) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a scheduling receipt for the incorrect booking.',\n )\n }\n\n formSubmissionResult.payment = await getPaymentConfiguration({\n paymentFormUrl,\n paymentReceiptUrl,\n preventPayment,\n formSubmissionResult,\n schedulingBooking,\n })\n\n await removeSchedulingSubmissionResult()\n\n return formSubmissionResult\n}\n\n/**\n * Pass in query string parameters after a redirect back to your app after a\n * booking is processed. Will return a SchedulingBooking and the submission\n * result from the original submission before redirecting to\n * `scheduling.bookingUrl`. If the booking has been rescheduled, the submission\n * result will not be returned.\n *\n * #### Example\n *\n * ```js\n * import queryString from 'query-string'\n *\n * const query = queryString.parse(window.location.search)\n *\n * const { booking, formSubmissionResult } =\n * await schedulingService.handleSchedulingQuerystring(query)\n * ```\n *\n * @param options\n * @returns\n */\nasync function handleSchedulingQuerystring({\n start_time,\n end_time,\n location,\n submissionId,\n isReschedule,\n}: Record<string, unknown>): Promise<{\n booking: SchedulingBooking\n formSubmissionResult?: FormSubmissionResult\n}> {\n if (\n typeof submissionId !== 'string' ||\n typeof start_time !== 'string' ||\n typeof end_time !== 'string' ||\n typeof location !== 'string'\n ) {\n throw new OneBlinkAppsError(\n 'Scheduling receipts cannot be displayed unless navigating here directly after a booking.',\n )\n }\n const booking: SchedulingBooking = {\n submissionId,\n startTime: new Date(parseInt(start_time) * 1000),\n endTime: new Date(parseInt(end_time) * 1000),\n location,\n isReschedule: isReschedule === 'true',\n }\n console.log('Parsed booking result', booking)\n\n if (isReschedule) {\n return {\n booking,\n }\n }\n\n const formSubmissionResult = await getSchedulingFormSubmissionResult(\n submissionId,\n booking,\n )\n\n return {\n formSubmissionResult,\n booking,\n }\n}\n\n/**\n * Pass in query string parameters after navigation to your app via a valid\n * cancellation link.\n *\n * #### Example\n *\n * ```js\n * import queryString from 'query-string'\n *\n * const query = queryString.parse(window.location.search)\n *\n * const bookingToCancel =\n * await schedulingService.handleCancelSchedulingBookingQuerystring(query)\n * ```\n *\n * @param options\n * @returns\n */\nfunction handleCancelSchedulingBookingQuerystring({\n nylasEditHash,\n submissionId,\n startTime,\n endTime,\n eventName,\n location,\n timezone,\n cancellationPolicy,\n}: Record<string, unknown>): {\n /** The nylas edit hash associated with the booking */\n nylasEditHash: string\n /** The unique identifier for the submission associated with the booking */\n submissionId: string\n /** The start time of the booking */\n startTime: Date\n /** The end time of the booking */\n endTime: Date\n /** The event name */\n eventName: string\n /** The location of the event */\n location: string\n /** The timezone the booking was booked in */\n timezone: string\n /**\n * The policy to display to users when asked why they are cancelling the\n * booking\n */\n cancellationPolicy?: string\n} {\n if (\n typeof submissionId !== 'string' ||\n typeof nylasEditHash !== 'string' ||\n typeof startTime !== 'string' ||\n typeof endTime !== 'string' ||\n typeof eventName !== 'string' ||\n typeof location !== 'string' ||\n typeof timezone !== 'string' ||\n (typeof cancellationPolicy !== 'string' && cancellationPolicy !== undefined)\n ) {\n throw new OneBlinkAppsError(\n 'Scheduling bookings cannot be cancelled unless navigating here from the correct link.',\n )\n }\n\n const booking = {\n nylasEditHash,\n submissionId,\n startTime: new Date(parseInt(startTime) * 1000),\n endTime: new Date(parseInt(endTime) * 1000),\n eventName,\n location,\n timezone,\n cancellationPolicy,\n }\n console.log('Parsed scheduling booking cancel data', booking)\n\n return booking\n}\n\n/**\n * Create a Nylas Session\n *\n * #### Example\n *\n * ```js\n * const {\n * sessionId,\n * configurationId,\n * bookingRef,\n * name,\n * email,\n * formSubmissionResult,\n * } = await schedulingService.createNylasNewBookingSession(\n * '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * )\n * // use sessionId and configurationId/bookingRef to create or modify nylas bookings\n * // use formSubmissionResult to execute post submission action for form\n * ```\n *\n * @param submissionId\n * @param abortSignal\n * @returns\n */\nasync function createNylasNewBookingSession(\n submissionId: string,\n abortSignal: AbortSignal,\n): Promise<\n Awaited<ReturnType<typeof createNylasExistingBookingSession>> & {\n /**\n * A callback function run after the booking has been confirmed to prevent\n * the user from making another booking against this form submission and\n * execute post submission action.\n */\n onBookingConfirmed: (\n schedulingBooking: SchedulingBooking,\n ) => Promise<FormSubmissionResult>\n }\n> {\n const session = await createNylasExistingBookingSession(\n submissionId,\n abortSignal,\n )\n\n return {\n ...session,\n async onBookingConfirmed(schedulingBooking: SchedulingBooking) {\n return await getSchedulingFormSubmissionResult(\n submissionId,\n schedulingBooking,\n )\n },\n }\n}\n\nexport {\n SchedulingBooking,\n handleSchedulingQuerystring,\n handleCancelSchedulingBookingQuerystring,\n createNylasExistingBookingSession,\n createNylasNewBookingSession,\n getSchedulingFormSubmissionResult,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"scheduling-service.js","sourceRoot":"","sources":["../../src/apps/scheduling-service.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,iCAAiC,EAAE,MAAM,2BAA2B,CAAA;AAC7E,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAEL,6BAA6B,EAC7B,gCAAgC,EAChC,oBAAoB,GACrB,MAAM,+BAA+B,CAAA;AAEtC,KAAK,UAAU,uBAAuB,CAAC,EACrC,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,iBAAiB,GAOlB;;IACC,IAAI,cAAc,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,oBAAoB,CAAC,iBAAiB,CAAC,CAAA;IAC7C,MAAM,mCAAmC,GAAG,8BAA8B,CACxE,oBAAoB,EACpB,MAAA,oBAAoB,CAAC,mBAAmB,mCAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CACrE,CAAA;IACD,IAAI,mCAAmC,EAAE,CAAC;QACxC,OAAO,MAAM,4BAA4B,CAAC;YACxC,oBAAoB;YACpB,iBAAiB;YACjB,cAAc;SACf,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED,KAAK,UAAU,iCAAiC,CAC9C,YAAoB,EACpB,iBAAoC;IAEp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CAAA;IACD,OAAO,CAAC,GAAG,CAAC,uCAAuC,EAAE,OAAO,CAAC,CAAA;IAE7D,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,KAAK,UAAU,4BAA4B,CACzC,YAAoB,EACpB,WAAwB;IAaxB,MAAM,OAAO,GAAG,MAAM,iCAAiC,CACrD,YAAY,EACZ,WAAW,CACZ,CAAA;IAED,OAAO;QACL,GAAG,OAAO;QACV,KAAK,CAAC,kBAAkB,CAAC,iBAAoC;YAC3D,OAAO,MAAM,iCAAiC,CAC5C,YAAY,EACZ,iBAAiB,CAClB,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED,OAAO,EAEL,2BAA2B,EAC3B,wCAAwC,EACxC,iCAAiC,EACjC,4BAA4B,EAC5B,iCAAiC,GAClC,CAAA","sourcesContent":["import OneBlinkAppsError from './services/errors/oneBlinkAppsError'\nimport { createNylasExistingBookingSession } from './services/api/scheduling'\nimport {\n checkForPaymentSubmissionEvent,\n handlePaymentSubmissionEvent,\n} from './payment-service'\nimport { FormSubmissionResult } from './types/submissions'\nimport {\n SchedulingBooking,\n getSchedulingSubmissionResult,\n removeSchedulingSubmissionResult,\n setSchedulingBooking,\n} from './services/schedulingHandlers'\n\nasync function getPaymentConfiguration({\n paymentReceiptUrl,\n paymentFormUrl,\n preventPayment,\n formSubmissionResult,\n schedulingBooking,\n}: {\n paymentReceiptUrl: string | undefined\n paymentFormUrl: string | undefined\n preventPayment: boolean\n formSubmissionResult: FormSubmissionResult\n schedulingBooking: SchedulingBooking\n}) {\n if (preventPayment || !paymentReceiptUrl) {\n return null\n }\n\n await setSchedulingBooking(schedulingBooking)\n const paymentSubmissionEventConfiguration = checkForPaymentSubmissionEvent(\n formSubmissionResult,\n formSubmissionResult.submissionTimestamp ?? new Date().toISOString(),\n )\n if (paymentSubmissionEventConfiguration) {\n return await handlePaymentSubmissionEvent({\n formSubmissionResult,\n paymentReceiptUrl,\n paymentFormUrl,\n })\n }\n\n return null\n}\n\nasync function getSchedulingFormSubmissionResult(\n submissionId: string,\n schedulingBooking: SchedulingBooking,\n) {\n const schedulingSubmissionResultConfiguration =\n await getSchedulingSubmissionResult()\n // If the current transaction does not match the submission\n // we will display message to user indicating\n // they are looking for the wrong transaction receipt.\n if (!schedulingSubmissionResultConfiguration) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a scheduling receipt for an unknown booking.',\n )\n }\n\n const {\n formSubmissionResult,\n paymentReceiptUrl,\n paymentFormUrl,\n preventPayment,\n } = schedulingSubmissionResultConfiguration\n if (\n !formSubmissionResult ||\n !formSubmissionResult.scheduling ||\n !formSubmissionResult.scheduling.submissionEvent\n ) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a scheduling receipt for a misconfigured booking.',\n )\n }\n\n if (formSubmissionResult.submissionId !== submissionId) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a scheduling receipt for the incorrect booking.',\n )\n }\n\n formSubmissionResult.payment = await getPaymentConfiguration({\n paymentFormUrl,\n paymentReceiptUrl,\n preventPayment,\n formSubmissionResult,\n schedulingBooking,\n })\n\n await removeSchedulingSubmissionResult()\n\n return formSubmissionResult\n}\n\n/**\n * Pass in query string parameters after a redirect back to your app after a\n * booking is processed. Will return a SchedulingBooking and the submission\n * result from the original submission before redirecting to\n * `scheduling.bookingUrl`. If the booking has been rescheduled, the submission\n * result will not be returned.\n *\n * #### Example\n *\n * ```js\n * import queryString from 'query-string'\n *\n * const query = queryString.parse(window.location.search)\n *\n * const { booking, formSubmissionResult } =\n * await schedulingService.handleSchedulingQuerystring(query)\n * ```\n *\n * @param options\n * @returns\n */\nasync function handleSchedulingQuerystring({\n start_time,\n end_time,\n location,\n submissionId,\n isReschedule,\n}: Record<string, unknown>): Promise<{\n booking: SchedulingBooking\n formSubmissionResult?: FormSubmissionResult\n}> {\n if (\n typeof submissionId !== 'string' ||\n typeof start_time !== 'string' ||\n typeof end_time !== 'string' ||\n typeof location !== 'string'\n ) {\n throw new OneBlinkAppsError(\n 'Scheduling receipts cannot be displayed unless navigating here directly after a booking.',\n )\n }\n const booking: SchedulingBooking = {\n submissionId,\n startTime: new Date(parseInt(start_time) * 1000),\n endTime: new Date(parseInt(end_time) * 1000),\n location,\n isReschedule: isReschedule === 'true',\n }\n console.log('Parsed booking result', booking)\n\n if (isReschedule) {\n return {\n booking,\n }\n }\n\n const formSubmissionResult = await getSchedulingFormSubmissionResult(\n submissionId,\n booking,\n )\n\n return {\n formSubmissionResult,\n booking,\n }\n}\n\n/**\n * Pass in query string parameters after navigation to your app via a valid\n * cancellation link.\n *\n * #### Example\n *\n * ```js\n * import queryString from 'query-string'\n *\n * const query = queryString.parse(window.location.search)\n *\n * const bookingToCancel =\n * await schedulingService.handleCancelSchedulingBookingQuerystring(query)\n * ```\n *\n * @param options\n * @returns\n */\nfunction handleCancelSchedulingBookingQuerystring({\n nylasEditHash,\n submissionId,\n startTime,\n endTime,\n eventName,\n location,\n timezone,\n cancellationPolicy,\n}: Record<string, unknown>): {\n /** The nylas edit hash associated with the booking */\n nylasEditHash: string\n /** The unique identifier for the submission associated with the booking */\n submissionId: string\n /** The start time of the booking */\n startTime: Date\n /** The end time of the booking */\n endTime: Date\n /** The event name */\n eventName: string\n /** The location of the event */\n location: string\n /** The timezone the booking was booked in */\n timezone: string\n /**\n * The policy to display to users when asked why they are cancelling the\n * booking\n */\n cancellationPolicy?: string\n} {\n if (\n typeof submissionId !== 'string' ||\n typeof nylasEditHash !== 'string' ||\n typeof startTime !== 'string' ||\n typeof endTime !== 'string' ||\n typeof eventName !== 'string' ||\n typeof location !== 'string' ||\n typeof timezone !== 'string' ||\n (typeof cancellationPolicy !== 'string' && cancellationPolicy !== undefined)\n ) {\n throw new OneBlinkAppsError(\n 'Scheduling bookings cannot be cancelled unless navigating here from the correct link.',\n )\n }\n\n const booking = {\n nylasEditHash,\n submissionId,\n startTime: new Date(parseInt(startTime) * 1000),\n endTime: new Date(parseInt(endTime) * 1000),\n eventName,\n location,\n timezone,\n cancellationPolicy,\n }\n console.log('Parsed scheduling booking cancel data', booking)\n\n return booking\n}\n\n/**\n * Create a Nylas Session\n *\n * #### Example\n *\n * ```js\n * const {\n * sessionId,\n * configurationId,\n * bookingRef,\n * name,\n * email,\n * formSubmissionResult,\n * } = await schedulingService.createNylasNewBookingSession(\n * '89c6e98e-f56f-45fc-84fe-c4fc62331d34',\n * )\n * // use sessionId and configurationId/bookingRef to create or modify nylas bookings\n * // use formSubmissionResult to execute post submission action for form\n * ```\n *\n * @param submissionId\n * @param abortSignal\n * @returns\n */\nasync function createNylasNewBookingSession(\n submissionId: string,\n abortSignal: AbortSignal,\n): Promise<\n Awaited<ReturnType<typeof createNylasExistingBookingSession>> & {\n /**\n * A callback function run after the booking has been confirmed to prevent\n * the user from making another booking against this form submission and\n * execute post submission action.\n */\n onBookingConfirmed: (\n schedulingBooking: SchedulingBooking,\n ) => Promise<FormSubmissionResult>\n }\n> {\n const session = await createNylasExistingBookingSession(\n submissionId,\n abortSignal,\n )\n\n return {\n ...session,\n async onBookingConfirmed(schedulingBooking: SchedulingBooking) {\n return await getSchedulingFormSubmissionResult(\n submissionId,\n schedulingBooking,\n )\n },\n }\n}\n\nexport {\n SchedulingBooking,\n handleSchedulingQuerystring,\n handleCancelSchedulingBookingQuerystring,\n createNylasExistingBookingSession,\n createNylasNewBookingSession,\n getSchedulingFormSubmissionResult,\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SubmissionEventTypes, SubmissionTypes } from '@oneblink/types';
|
|
2
|
-
import { BasePaymentConfigurationPayload, PaymentProvider } from '../../types/payments';
|
|
3
2
|
import { NewFormSubmission } from '../../submission-service';
|
|
4
3
|
declare function getCustomFormPaymentConfiguration<T>(path: string, { integrationEnvironmentId, }: {
|
|
5
4
|
integrationEnvironmentId: string;
|
|
@@ -15,9 +14,14 @@ declare function completeWestpacQuickStreamTransaction(formId: number, payload:
|
|
|
15
14
|
formSubmissionPayment: SubmissionTypes.FormSubmissionPayment;
|
|
16
15
|
}>;
|
|
17
16
|
declare function cancelWestpacQuickStreamPayment(formId: number, formSubmissionPaymentId: string, abortSignal?: AbortSignal): Promise<void>;
|
|
18
|
-
declare function
|
|
17
|
+
declare function createPaymentConfiguration(submissionId: string, payload: {
|
|
18
|
+
redirectUrl: string;
|
|
19
|
+
paymentFormUrl: string | undefined;
|
|
20
|
+
}): Promise<{
|
|
19
21
|
hostedFormUrl: string;
|
|
20
|
-
|
|
22
|
+
paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent;
|
|
23
|
+
amount: number;
|
|
24
|
+
} | undefined>;
|
|
21
25
|
declare const verifyPaymentTransaction: <T>(path: string, payload: unknown) => Promise<T>;
|
|
22
26
|
declare const acknowledgeCPPayTransaction: (formId: number, payload: unknown) => Promise<void>;
|
|
23
|
-
export {
|
|
27
|
+
export { acknowledgeCPPayTransaction, verifyPaymentTransaction, getCustomFormPaymentConfiguration, completeWestpacQuickStreamTransaction, cancelWestpacQuickStreamPayment, createPaymentConfiguration, };
|
|
@@ -119,11 +119,10 @@ async function cancelWestpacQuickStreamPayment(formId, formSubmissionPaymentId,
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
function
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return postRequest(url, payload).catch((error) => {
|
|
122
|
+
async function createPaymentConfiguration(submissionId, payload) {
|
|
123
|
+
const url = `${tenants.current.apiOrigin}/form-submission-meta/${submissionId}/payment`;
|
|
124
|
+
console.log('Attempting to get payment configuration', url);
|
|
125
|
+
return await postRequest(url, payload).catch((error) => {
|
|
127
126
|
Sentry.captureException(error);
|
|
128
127
|
console.warn('Error occurred while attempting to generate configuration for payment', error);
|
|
129
128
|
switch (error.status) {
|
|
@@ -231,5 +230,5 @@ const acknowledgeCPPayTransaction = async (formId, payload) => {
|
|
|
231
230
|
}
|
|
232
231
|
});
|
|
233
232
|
};
|
|
234
|
-
export {
|
|
233
|
+
export { acknowledgeCPPayTransaction, verifyPaymentTransaction, getCustomFormPaymentConfiguration, completeWestpacQuickStreamTransaction, cancelWestpacQuickStreamPayment, createPaymentConfiguration, };
|
|
235
234
|
//# sourceMappingURL=payment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../../src/apps/services/api/payment.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,iBAAiB,MAAM,6BAA6B,CAAA;AAC3D,OAAO,OAAO,MAAM,eAAe,CAAA;AACnC,OAAO,MAAM,MAAM,cAAc,CAAA;AAKjC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAGjD,KAAK,UAAU,iCAAiC,CAC9C,IAAY,EACZ,EACE,wBAAwB,GAGzB,EACD,WAAyB;IAEzB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACpD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,0BAA0B,EAAE,wBAAwB,CAAC,CAAA;IAE7E,OAAO,CAAC,GAAG,CAAC,yCAAyC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;IAEhE,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,CAAI,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;IACnD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,GAAgB,CAAA;QAC9B,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;QAC9B,OAAO,CAAC,IAAI,CACV,uEAAuE,EACvE,KAAK,CACN,CAAA;QACD,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;YACrB,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CAC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CACN,CAAA;QACD,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;YACrB,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CACzB,4FAA4F,EAC5F;oBACE,aAAa,EAAE,KAAK;oBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;oBAC5B,aAAa,EAAE,IAAI;iBACpB,CACF,CAAA;YACH,CAAC;YACD,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CACzB,iIAAiI,EACjI;oBACE,aAAa,EAAE,KAAK;oBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;oBAC5B,qBAAqB,EAAE,IAAI;iBAC5B,CACF,CAAA;YACH,CAAC;YACD,KAAK,GAAG,CAAC;YACT,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CACzB,2LAA2L,EAC3L;oBACE,aAAa,EAAE,KAAK;oBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,IAAI,iBAAiB,CACzB,gFAAgF,EAChF;oBACE,aAAa,EAAE,KAAK;oBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,wBAAwB,EACxB,iCAAiC,EACjC,qCAAqC,EACrC,+BAA+B,GAChC,CAAA","sourcesContent":["import { SubmissionEventTypes, SubmissionTypes } from '@oneblink/types'\nimport { HTTPError, deleteRequest, getRequest, postRequest } from '../fetch'\nimport OneBlinkAppsError from '../errors/oneBlinkAppsError'\nimport tenants from '../../tenants'\nimport Sentry from '../../Sentry'\nimport {\n BasePaymentConfigurationPayload,\n PaymentProvider,\n} from '../../types/payments'\nimport { isOffline } from '../../offline-service'\nimport { NewFormSubmission } from '../../submission-service'\n\nasync function getCustomFormPaymentConfiguration<T>(\n path: string,\n {\n integrationEnvironmentId,\n }: {\n integrationEnvironmentId: string\n },\n abortSignal?: AbortSignal,\n) {\n const url = new URL(path, tenants.current.apiOrigin)\n url.searchParams.append('integrationEnvironmentId', integrationEnvironmentId)\n\n console.log('Attempting to get payment configuration', url.href)\n\n try {\n return await getRequest<T>(url.href, abortSignal)\n } catch (err) {\n const error = err as HTTPError\n Sentry.captureException(error)\n console.warn(\n 'Error occurred while attempting to retrieve configuration for payment',\n error,\n )\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot retrieve payment configuration until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access retrieve payment configuration. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the payment configuration. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\nasync function completeWestpacQuickStreamTransaction(\n formId: number,\n payload: {\n formSubmissionPaymentId: string\n singleUseTokenId: string\n integrationEnvironmentId: string\n customerReferenceNumber: string\n principalAmount: number\n recaptcha: NonNullable<NewFormSubmission['recaptchas']>[number]\n },\n abortSignal?: AbortSignal,\n) {\n const url = `${tenants.current.apiOrigin}/forms/${formId}/westpac-quick-stream-transaction`\n console.log('Attempting to complete Westpac QuickStream transaction', url)\n try {\n return await postRequest<{\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n }>(url, payload, abortSignal)\n } catch (err) {\n const error = err as HTTPError\n Sentry.captureException(error)\n console.warn(\n 'Error occurred while attempting to generate configuration for payment',\n error,\n )\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot complete transactions until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access complete transactions. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the configuration required to complete a transaction. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\nasync function cancelWestpacQuickStreamPayment(\n formId: number,\n formSubmissionPaymentId: string,\n abortSignal?: AbortSignal,\n) {\n try {\n const url = `${tenants.current.apiOrigin}/forms/${formId}/westpac-quick-stream-payment/${formSubmissionPaymentId}`\n console.log('Attempting to cancel Westpac QuickStream payment', url)\n return await deleteRequest(url, abortSignal)\n } catch (error) {\n Sentry.captureException(error)\n\n const httpError = error as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline, please connect to the internet to continue',\n {\n originalError: httpError,\n isOffline: true,\n },\n )\n }\n switch (httpError.status) {\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the form you are looking for. Please contact support if the problem persists.',\n {\n originalError: httpError,\n title: 'Unknown Form',\n httpStatusCode: httpError.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: httpError,\n httpStatusCode: httpError.status,\n },\n )\n }\n }\n }\n}\n\nfunction generatePaymentConfiguration(\n paymentProvider: PaymentProvider<SubmissionEventTypes.FormPaymentEvent>,\n basePayload: BasePaymentConfigurationPayload,\n): Promise<{ hostedFormUrl: string }> {\n const { path, payload } =\n paymentProvider.preparePaymentConfiguration(basePayload)\n const url = `${tenants.current.apiOrigin}${path}`\n console.log('Attempting to generate payment configuration', url)\n return postRequest<{ hostedFormUrl: string }>(url, payload).catch((error) => {\n Sentry.captureException(error)\n console.warn(\n 'Error occurred while attempting to generate configuration for payment',\n error,\n )\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot make payments until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access make payments. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the configuration required to make a payment. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n })\n}\n\nconst verifyPaymentTransaction = <T>(\n path: string,\n payload: unknown,\n): Promise<T> => {\n const url = `${tenants.current.apiOrigin}${path}`\n console.log('Attempting to verify payment transaction', url)\n return postRequest<T>(url, payload).catch((error) => {\n Sentry.captureException(error)\n console.warn(\n 'Error occurred while attempting to verify a transaction',\n error,\n )\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot verify a transaction until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to verify your transactions. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the configuration required to verify your transaction. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n })\n}\n\nconst acknowledgeCPPayTransaction = async (\n formId: number,\n payload: unknown,\n): Promise<void> => {\n const url = `${tenants.current.apiOrigin}/forms/${formId}/cp-pay-acknowledge`\n console.log('Attempting to acknowledge CP Pay transaction', url)\n await postRequest(url, payload).catch((error) => {\n Sentry.captureException(error)\n console.warn(\n 'Error occurred while attempting to acknowledge a CP Pay transaction',\n error,\n )\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot acknowledge a transaction until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to acknowledge your transactions. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the configuration required to acknowledge your transaction. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n })\n}\n\nexport {\n generatePaymentConfiguration,\n acknowledgeCPPayTransaction,\n verifyPaymentTransaction,\n getCustomFormPaymentConfiguration,\n completeWestpacQuickStreamTransaction,\n cancelWestpacQuickStreamPayment,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../../src/apps/services/api/payment.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAA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I;iBAC5B,CACF,CAAA;YACH,CAAC;YACD,KAAK,GAAG,CAAC;YACT,KAAK,GAAG,CAAC,CAAC,CAAC;gBACT,MAAM,IAAI,iBAAiB,CACzB,2LAA2L,EAC3L;oBACE,aAAa,EAAE,KAAK;oBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,IAAI,iBAAiB,CACzB,gFAAgF,EAChF;oBACE,aAAa,EAAE,KAAK;oBACpB,cAAc,EAAE,KAAK,CAAC,MAAM;iBAC7B,CACF,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,iCAAiC,EACjC,qCAAqC,EACrC,+BAA+B,EAC/B,0BAA0B,GAC3B,CAAA","sourcesContent":["import { SubmissionEventTypes, SubmissionTypes } from '@oneblink/types'\nimport { HTTPError, deleteRequest, getRequest, postRequest } from '../fetch'\nimport OneBlinkAppsError from '../errors/oneBlinkAppsError'\nimport tenants from '../../tenants'\nimport Sentry from '../../Sentry'\nimport { isOffline } from '../../offline-service'\nimport { NewFormSubmission } from '../../submission-service'\n\nasync function getCustomFormPaymentConfiguration<T>(\n path: string,\n {\n integrationEnvironmentId,\n }: {\n integrationEnvironmentId: string\n },\n abortSignal?: AbortSignal,\n) {\n const url = new URL(path, tenants.current.apiOrigin)\n url.searchParams.append('integrationEnvironmentId', integrationEnvironmentId)\n\n console.log('Attempting to get payment configuration', url.href)\n\n try {\n return await getRequest<T>(url.href, abortSignal)\n } catch (err) {\n const error = err as HTTPError\n Sentry.captureException(error)\n console.warn(\n 'Error occurred while attempting to retrieve configuration for payment',\n error,\n )\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot retrieve payment configuration until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access retrieve payment configuration. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the payment configuration. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\nasync function completeWestpacQuickStreamTransaction(\n formId: number,\n payload: {\n formSubmissionPaymentId: string\n singleUseTokenId: string\n integrationEnvironmentId: string\n customerReferenceNumber: string\n principalAmount: number\n recaptcha: NonNullable<NewFormSubmission['recaptchas']>[number]\n },\n abortSignal?: AbortSignal,\n) {\n const url = `${tenants.current.apiOrigin}/forms/${formId}/westpac-quick-stream-transaction`\n console.log('Attempting to complete Westpac QuickStream transaction', url)\n try {\n return await postRequest<{\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n }>(url, payload, abortSignal)\n } catch (err) {\n const error = err as HTTPError\n Sentry.captureException(error)\n console.warn(\n 'Error occurred while attempting to generate configuration for payment',\n error,\n )\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot complete transactions until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access complete transactions. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the configuration required to complete a transaction. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n}\n\nasync function cancelWestpacQuickStreamPayment(\n formId: number,\n formSubmissionPaymentId: string,\n abortSignal?: AbortSignal,\n) {\n try {\n const url = `${tenants.current.apiOrigin}/forms/${formId}/westpac-quick-stream-payment/${formSubmissionPaymentId}`\n console.log('Attempting to cancel Westpac QuickStream payment', url)\n return await deleteRequest(url, abortSignal)\n } catch (error) {\n Sentry.captureException(error)\n\n const httpError = error as HTTPError\n if (isOffline()) {\n throw new OneBlinkAppsError(\n 'You are currently offline, please connect to the internet to continue',\n {\n originalError: httpError,\n isOffline: true,\n },\n )\n }\n switch (httpError.status) {\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the form you are looking for. Please contact support if the problem persists.',\n {\n originalError: httpError,\n title: 'Unknown Form',\n httpStatusCode: httpError.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: httpError,\n httpStatusCode: httpError.status,\n },\n )\n }\n }\n }\n}\n\nasync function createPaymentConfiguration(\n submissionId: string,\n payload: { redirectUrl: string; paymentFormUrl: string | undefined },\n) {\n const url = `${tenants.current.apiOrigin}/form-submission-meta/${submissionId}/payment`\n console.log('Attempting to get payment configuration', url)\n return await postRequest<\n | {\n hostedFormUrl: string\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n amount: number\n }\n | undefined\n >(url, payload).catch((error) => {\n Sentry.captureException(error)\n console.warn(\n 'Error occurred while attempting to generate configuration for payment',\n error,\n )\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot make payments until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access make payments. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the configuration required to make a payment. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n })\n}\n\nconst verifyPaymentTransaction = <T>(\n path: string,\n payload: unknown,\n): Promise<T> => {\n const url = `${tenants.current.apiOrigin}${path}`\n console.log('Attempting to verify payment transaction', url)\n return postRequest<T>(url, payload).catch((error) => {\n Sentry.captureException(error)\n console.warn(\n 'Error occurred while attempting to verify a transaction',\n error,\n )\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot verify a transaction until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to verify your transactions. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the configuration required to verify your transaction. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n })\n}\n\nconst acknowledgeCPPayTransaction = async (\n formId: number,\n payload: unknown,\n): Promise<void> => {\n const url = `${tenants.current.apiOrigin}/forms/${formId}/cp-pay-acknowledge`\n console.log('Attempting to acknowledge CP Pay transaction', url)\n await postRequest(url, payload).catch((error) => {\n Sentry.captureException(error)\n console.warn(\n 'Error occurred while attempting to acknowledge a CP Pay transaction',\n error,\n )\n switch (error.status) {\n case 401: {\n throw new OneBlinkAppsError(\n 'You cannot acknowledge a transaction until you have logged in. Please login and try again.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresLogin: true,\n },\n )\n }\n case 403: {\n throw new OneBlinkAppsError(\n 'You do not have access to acknowledge your transactions. Please contact your administrator to gain the correct level of access.',\n {\n originalError: error,\n httpStatusCode: error.status,\n requiresAccessRequest: true,\n },\n )\n }\n case 400:\n case 404: {\n throw new OneBlinkAppsError(\n 'We could not find the configuration required to acknowledge your transaction. Please contact your administrator to ensure your application configuration has been completed successfully.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n })\n}\n\nexport {\n acknowledgeCPPayTransaction,\n verifyPaymentTransaction,\n getCustomFormPaymentConfiguration,\n completeWestpacQuickStreamTransaction,\n cancelWestpacQuickStreamPayment,\n createPaymentConfiguration,\n}\n"]}
|
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
import { SubmissionEventTypes } from '@oneblink/types';
|
|
2
|
-
import {
|
|
2
|
+
import { PaymentProvider } from '../../types/payments';
|
|
3
3
|
import { FormSubmissionResult } from '../../types/submissions';
|
|
4
4
|
declare class BPOINTPaymentProvider implements PaymentProvider<SubmissionEventTypes.BPOINTSubmissionEvent> {
|
|
5
5
|
constructor(paymentSubmissionEvent: SubmissionEventTypes.BPOINTSubmissionEvent, formSubmissionResult: FormSubmissionResult);
|
|
6
6
|
paymentSubmissionEvent: SubmissionEventTypes.BPOINTSubmissionEvent;
|
|
7
7
|
formSubmissionResult: FormSubmissionResult;
|
|
8
|
-
preparePaymentConfiguration(basePayload: BasePaymentConfigurationPayload): {
|
|
9
|
-
path: string;
|
|
10
|
-
payload: {
|
|
11
|
-
integrationEnvironmentId: string;
|
|
12
|
-
crn2: string | undefined;
|
|
13
|
-
crn3: string | undefined;
|
|
14
|
-
amount: number;
|
|
15
|
-
redirectUrl: string;
|
|
16
|
-
submissionId: string | null;
|
|
17
|
-
paymentFormUrl?: string;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
8
|
verifyPaymentTransaction(query: Record<string, unknown>): Promise<{
|
|
21
9
|
receiptItems: import("../../types/payments").PaymentReceiptItem[];
|
|
22
10
|
transaction: {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import replaceInjectablesWithSubmissionValues from '../replaceInjectablesWithSubmissionValues';
|
|
2
1
|
import OneBlinkAppsError from '../errors/oneBlinkAppsError';
|
|
3
2
|
import { verifyPaymentTransaction } from '../api/payment';
|
|
4
3
|
import { generateAmountReceiptItem, generateCreditCardMaskReceiptItem, generateSubmissionIdReceiptItem, prepareReceiptItems, } from './receipt-items';
|
|
@@ -7,19 +6,6 @@ class BPOINTPaymentProvider {
|
|
|
7
6
|
this.paymentSubmissionEvent = paymentSubmissionEvent;
|
|
8
7
|
this.formSubmissionResult = formSubmissionResult;
|
|
9
8
|
}
|
|
10
|
-
preparePaymentConfiguration(basePayload) {
|
|
11
|
-
return {
|
|
12
|
-
path: `/forms/${this.formSubmissionResult.definition.id}/bpoint-payment`,
|
|
13
|
-
payload: {
|
|
14
|
-
...basePayload,
|
|
15
|
-
integrationEnvironmentId: this.paymentSubmissionEvent.configuration.environmentId,
|
|
16
|
-
crn2: this.paymentSubmissionEvent.configuration.crn2 &&
|
|
17
|
-
replaceInjectablesWithSubmissionValues(this.paymentSubmissionEvent.configuration.crn2, this.formSubmissionResult).text,
|
|
18
|
-
crn3: this.paymentSubmissionEvent.configuration.crn3 &&
|
|
19
|
-
replaceInjectablesWithSubmissionValues(this.paymentSubmissionEvent.configuration.crn3, this.formSubmissionResult).text,
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
9
|
async verifyPaymentTransaction(query) {
|
|
24
10
|
var _a;
|
|
25
11
|
const { ResultKey: transactionToken } = query;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BPOINTPaymentProvider.js","sourceRoot":"","sources":["../../../../src/apps/services/payment-providers/BPOINTPaymentProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BPOINTPaymentProvider.js","sourceRoot":"","sources":["../../../../src/apps/services/payment-providers/BPOINTPaymentProvider.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EACL,yBAAyB,EACzB,iCAAiC,EACjC,+BAA+B,EAC/B,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AAExB,MAAM,qBAAqB;IACzB,YACE,sBAAkE,EAClE,oBAA0C;QAE1C,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,CAAA;QACpD,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAA;IAClD,CAAC;IAKD,KAAK,CAAC,wBAAwB,CAAC,KAA8B;;QAC3D,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAA;QAC7C,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,MAAM,IAAI,iBAAiB,CACzB,mFAAmF,CACpF,CAAA;QACH,CAAC;QACD,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAUhD,UAAU,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,EAAE,sBAAsB,EACvE;YACE,gBAAgB;YAChB,wBAAwB,EACtB,IAAI,CAAC,sBAAsB,CAAC,aAAa,CAAC,aAAa;SAC1D,CACF,CAAA;QACD,IAAI,IAAI,CAAC,oBAAoB,CAAC,YAAY,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;YAChE,MAAM,IAAI,iBAAiB,CACzB,+EAA+E,CAChF,CAAA;QACH,CAAC;QACD,OAAO;YACL,YAAY,EAAE,mBAAmB,CAAC;gBAChC,+BAA+B,CAAC,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC;gBACvE;oBACE,SAAS,EAAE,oCAAoC;oBAC/C,cAAc,EAAE,wCAAwC;oBACxD,IAAI,EAAE,eAAe;oBACrB,KAAK,EAAE,gBAAgB;oBACvB,KAAK,EAAE,WAAW,CAAC,aAAa;oBAChC,oBAAoB,EAAE,IAAI;iBAC3B;gBACD,iCAAiC,CAC/B,MAAA,WAAW,CAAC,WAAW,0CAAE,gBAAgB,CAC1C;gBACD,yBAAyB,CAAC,WAAW,CAAC,MAAM,GAAG,GAAG,CAAC;aACpD,CAAC;YACF,WAAW,EAAE;gBACX,SAAS,EAAE,WAAW,CAAC,YAAY,KAAK,GAAG;gBAC3C,YAAY,EAAE,WAAW,CAAC,YAAY;aACvC;YACD,gBAAgB,EAAE,IAAI,CAAC,oBAAoB;SAC5C,CAAA;IACH,CAAC;CACF;AAED,eAAe,qBAAqB,CAAA","sourcesContent":["import { SubmissionEventTypes } from '@oneblink/types'\nimport { PaymentProvider } from '../../types/payments'\nimport { FormSubmissionResult } from '../../types/submissions'\nimport OneBlinkAppsError from '../errors/oneBlinkAppsError'\nimport { verifyPaymentTransaction } from '../api/payment'\nimport {\n generateAmountReceiptItem,\n generateCreditCardMaskReceiptItem,\n generateSubmissionIdReceiptItem,\n prepareReceiptItems,\n} from './receipt-items'\n\nclass BPOINTPaymentProvider implements PaymentProvider<SubmissionEventTypes.BPOINTSubmissionEvent> {\n constructor(\n paymentSubmissionEvent: SubmissionEventTypes.BPOINTSubmissionEvent,\n formSubmissionResult: FormSubmissionResult,\n ) {\n this.paymentSubmissionEvent = paymentSubmissionEvent\n this.formSubmissionResult = formSubmissionResult\n }\n\n paymentSubmissionEvent: SubmissionEventTypes.BPOINTSubmissionEvent\n formSubmissionResult: FormSubmissionResult\n\n async verifyPaymentTransaction(query: Record<string, unknown>) {\n const { ResultKey: transactionToken } = query\n if (!transactionToken) {\n throw new OneBlinkAppsError(\n 'Transactions can not be verified unless navigating here directly after a payment.',\n )\n }\n const transaction = await verifyPaymentTransaction<{\n ResponseCode: string\n ResponseText: string\n ReceiptNumber: string\n CardDetails?: {\n MaskedCardNumber?: string\n }\n Amount: number\n Crn1: string | null\n }>(\n `/forms/${this.formSubmissionResult.definition.id}/bpoint-verification`,\n {\n transactionToken,\n integrationEnvironmentId:\n this.paymentSubmissionEvent.configuration.environmentId,\n },\n )\n if (this.formSubmissionResult.submissionId !== transaction.Crn1) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for the incorrect payment.',\n )\n }\n return {\n receiptItems: prepareReceiptItems([\n generateSubmissionIdReceiptItem(this.formSubmissionResult.submissionId),\n {\n className: 'ob-payment-receipt__transaction-id',\n valueClassName: 'cypress-payment-receipt-transaction-id',\n icon: 'shopping_cart',\n label: 'Receipt Number',\n value: transaction.ReceiptNumber,\n allowCopyToClipboard: true,\n },\n generateCreditCardMaskReceiptItem(\n transaction.CardDetails?.MaskedCardNumber,\n ),\n generateAmountReceiptItem(transaction.Amount / 100),\n ]),\n transaction: {\n isSuccess: transaction.ResponseCode === '0',\n errorMessage: transaction.ResponseText,\n },\n submissionResult: this.formSubmissionResult,\n }\n }\n}\n\nexport default BPOINTPaymentProvider\n"]}
|