@oneblink/apps-react 5.7.0-beta.4 → 5.7.0-beta.5

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.
@@ -1,6 +1,7 @@
1
1
  import { SubmissionTypes } from '@oneblink/types';
2
2
  import React from 'react';
3
- declare function PaymentForm({ onCompleted, onCancelled, }: {
3
+ declare function PaymentForm({ captchaSiteKey, onCompleted, onCancelled, }: {
4
+ captchaSiteKey: string;
4
5
  onCompleted: (result: {
5
6
  formSubmissionPayment: SubmissionTypes.FormSubmissionPayment;
6
7
  paymentReceiptUrl: string;
@@ -4,7 +4,7 @@ import WestpacQuickStreamPaymentForm from './WestpacQuickStreamPaymentForm';
4
4
  import useQuery from '../../hooks/useQuery';
5
5
  import useLoadDataState from '../../hooks/useLoadDataState';
6
6
  import OnLoading from '../renderer/OnLoading';
7
- function PaymentForm({ onCompleted, onCancelled, }) {
7
+ function PaymentForm({ captchaSiteKey, onCompleted, onCancelled, }) {
8
8
  const query = useQuery();
9
9
  const loadPaymentFormConfiguration = React.useCallback(async (abortSignal) => {
10
10
  const formSubmissionPaymentId = query.formSubmissionPaymentId;
@@ -27,11 +27,11 @@ function PaymentForm({ onCompleted, onCancelled, }) {
27
27
  abortSignal,
28
28
  });
29
29
  return {
30
- renderPaymentForm: () => (React.createElement(WestpacQuickStreamPaymentForm, { formSubmissionResult: formSubmissionResult, paymentSubmissionEvent: paymentSubmissionEvent, formSubmissionPaymentId: formSubmissionPaymentId, supplierBusinessCode: supplierBusinessCode, publishableApiKey: publishableApiKey, isTestMode: isTestMode, onCompleted: onCompleted, onCancelled: onCancelled })),
30
+ renderPaymentForm: () => (React.createElement(WestpacQuickStreamPaymentForm, { formSubmissionResult: formSubmissionResult, paymentSubmissionEvent: paymentSubmissionEvent, formSubmissionPaymentId: formSubmissionPaymentId, supplierBusinessCode: supplierBusinessCode, publishableApiKey: publishableApiKey, isTestMode: isTestMode, captchaSiteKey: captchaSiteKey, onCompleted: onCompleted, onCancelled: onCancelled })),
31
31
  };
32
32
  }
33
33
  }
34
- }, [onCancelled, onCompleted, query.formSubmissionPaymentId]);
34
+ }, [captchaSiteKey, onCancelled, onCompleted, query.formSubmissionPaymentId]);
35
35
  const [state] = useLoadDataState(loadPaymentFormConfiguration);
36
36
  switch (state.status) {
37
37
  case 'LOADING': {
@@ -1 +1 @@
1
- {"version":3,"file":"PaymentForm.js","sourceRoot":"","sources":["../../../src/components/payments/PaymentForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,6BAA6B,MAAM,iCAAiC,CAAA;AAC3E,OAAO,QAAQ,MAAM,sBAAsB,CAAA;AAC3C,OAAO,gBAAgB,MAAM,8BAA8B,CAAA;AAC3D,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAE7C,SAAS,WAAW,CAAC,EACnB,WAAW,EACX,WAAW,GAOZ;IACC,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;IAExB,MAAM,4BAA4B,GAAG,KAAK,CAAC,WAAW,CACpD,KAAK,EAAE,WAAwB,EAAE,EAAE;QACjC,MAAM,uBAAuB,GAAG,KAAK,CAAC,uBAAuB,CAAA;QAC7D,IAAI,OAAO,uBAAuB,KAAK,QAAQ,EAAE;YAC/C,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAA;SACF;QAED,MAAM,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,GACpD,MAAM,cAAc,CAAC,8BAA8B,EAAE,CAAA;QACvD,QAAQ,sBAAsB,CAAC,IAAI,EAAE;YACnC,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,aAAa,CAAC;YACnB,KAAK,mBAAmB,CAAC,CAAC;gBACxB,MAAM,IAAI,KAAK,CACb,IAAI,sBAAsB,CAAC,IAAI,wDAAwD,CACxF,CAAA;aACF;YACD,KAAK,sB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AE,CAAA;SACxC;KACF;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA","sourcesContent":["import { paymentService } from '@oneblink/apps'\nimport { SubmissionTypes } from '@oneblink/types'\nimport React from 'react'\nimport WestpacQuickStreamPaymentForm from './WestpacQuickStreamPaymentForm'\nimport useQuery from '../../hooks/useQuery'\nimport useLoadDataState from '../../hooks/useLoadDataState'\nimport OnLoading from '../renderer/OnLoading'\n\nfunction PaymentForm({\n onCompleted,\n onCancelled,\n}: {\n onCompleted: (result: {\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n paymentReceiptUrl: string\n }) => void\n onCancelled: (result: { paymentReceiptUrl: string }) => void\n}) {\n const query = useQuery()\n\n const loadPaymentFormConfiguration = React.useCallback(\n async (abortSignal: AbortSignal) => {\n const formSubmissionPaymentId = query.formSubmissionPaymentId\n if (typeof formSubmissionPaymentId !== 'string') {\n throw new Error(\n 'It looks like you are attempting to make an unknown payment.',\n )\n }\n\n const { formSubmissionResult, paymentSubmissionEvent } =\n await paymentService.getFormSubmissionResultPayment()\n switch (paymentSubmissionEvent.type) {\n case 'BPOINT':\n case 'CP_PAY':\n case 'NSW_GOV_PAY':\n case 'WESTPAC_QUICK_WEB': {\n throw new Error(\n `\"${paymentSubmissionEvent.type}\" payment events do not support a custom payment form.`,\n )\n }\n case 'WESTPAC_QUICK_STREAM': {\n const { supplierBusinessCode, publishableApiKey, isTestMode } =\n await paymentService.westpacQuickStream.getPaymentFormConfiguration(\n {\n formSubmissionPaymentId,\n formSubmissionResult,\n paymentSubmissionEvent,\n abortSignal,\n },\n )\n return {\n renderPaymentForm: () => (\n <WestpacQuickStreamPaymentForm\n formSubmissionResult={formSubmissionResult}\n paymentSubmissionEvent={paymentSubmissionEvent}\n formSubmissionPaymentId={formSubmissionPaymentId}\n supplierBusinessCode={supplierBusinessCode}\n publishableApiKey={publishableApiKey}\n isTestMode={isTestMode}\n onCompleted={onCompleted}\n onCancelled={onCancelled}\n />\n ),\n }\n }\n }\n },\n [onCancelled, onCompleted, query.formSubmissionPaymentId],\n )\n\n const [state] = useLoadDataState(loadPaymentFormConfiguration)\n\n switch (state.status) {\n case 'LOADING': {\n return (\n <section>\n <div className=\"cypress-loading has-text-centered\">\n <OnLoading className=\"has-text-centered\"></OnLoading>\n <span>Loading payment configuration...</span>\n </div>\n </section>\n )\n }\n case 'ERROR': {\n return (\n <section className=\"cypress-payment-form-loading-error-message\">\n <div className=\"ob-payment-form__error-icon-container has-text-centered has-margin-bottom-8\">\n <i className=\"ob-payment-form__error-icon material-icons has-text-danger icon-x-large\">\n error\n </i>\n </div>\n <p className=\"ob-payment-form__error-message has-text-centered has-margin-bottom-4\">\n {state.error.message}\n </p>\n </section>\n )\n }\n case 'SUCCESS': {\n return state.result.renderPaymentForm()\n }\n }\n}\n\nexport default React.memo(PaymentForm)\n"]}
1
+ {"version":3,"file":"PaymentForm.js","sourceRoot":"","sources":["../../../src/components/payments/PaymentForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,6BAA6B,MAAM,iCAAiC,CAAA;AAC3E,OAAO,QAAQ,MAAM,sBAAsB,CAAA;AAC3C,OAAO,gBAAgB,MAAM,8BAA8B,CAAA;AAC3D,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAE7C,SAAS,WAAW,CAAC,EACnB,cAAc,EACd,WAAW,EACX,WAAW,GAQZ;IACC,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;IAExB,MAAM,4BAA4B,GAAG,KAAK,CAAC,WAAW,CACpD,KAAK,EAAE,WAAwB,EAAE,EAAE;QACjC,MAAM,uBAAuB,GAAG,KAAK,CAAC,uBAAuB,CAAA;QAC7D,IAAI,OAAO,uBAAuB,KAAK,QAAQ,EAAE;YAC/C,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAA;SACF;QAED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,qEAA6C,CACzC,CACE,CACX,CAAA;SACF;QACD,KAAK,OAAO,CAAC,CAAC;YACZ,OAAO,CACL,iCAAS,SAAS,EAAC,4CAA4C;gBAC7D,6BAAK,SAAS,EAAC,6EAA6E;oBAC1F,2BAAG,SAAS,EAAC,yEAAyE,YAElF,CACA;gBACN,2BAAG,SAAS,EAAC,sEAAsE,IAChF,KAAK,CAAC,KAAK,CAAC,OAAO,CAClB,CACI,CACX,CAAA;SACF;QACD,KAAK,SAAS,CAAC,CAAC;YACd,OAAO,KAAK,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAA;SACxC;KACF;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA","sourcesContent":["import { paymentService } from '@oneblink/apps'\nimport { SubmissionTypes } from '@oneblink/types'\nimport React from 'react'\nimport WestpacQuickStreamPaymentForm from './WestpacQuickStreamPaymentForm'\nimport useQuery from '../../hooks/useQuery'\nimport useLoadDataState from '../../hooks/useLoadDataState'\nimport OnLoading from '../renderer/OnLoading'\n\nfunction PaymentForm({\n captchaSiteKey,\n onCompleted,\n onCancelled,\n}: {\n captchaSiteKey: string\n onCompleted: (result: {\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n paymentReceiptUrl: string\n }) => void\n onCancelled: (result: { paymentReceiptUrl: string }) => void\n}) {\n const query = useQuery()\n\n const loadPaymentFormConfiguration = React.useCallback(\n async (abortSignal: AbortSignal) => {\n const formSubmissionPaymentId = query.formSubmissionPaymentId\n if (typeof formSubmissionPaymentId !== 'string') {\n throw new Error(\n 'It looks like you are attempting to make an unknown payment.',\n )\n }\n\n const { formSubmissionResult, paymentSubmissionEvent } =\n await paymentService.getFormSubmissionResultPayment()\n switch (paymentSubmissionEvent.type) {\n case 'BPOINT':\n case 'CP_PAY':\n case 'NSW_GOV_PAY':\n case 'WESTPAC_QUICK_WEB': {\n throw new Error(\n `\"${paymentSubmissionEvent.type}\" payment events do not support a custom payment form.`,\n )\n }\n case 'WESTPAC_QUICK_STREAM': {\n const { supplierBusinessCode, publishableApiKey, isTestMode } =\n await paymentService.westpacQuickStream.getPaymentFormConfiguration(\n {\n formSubmissionPaymentId,\n formSubmissionResult,\n paymentSubmissionEvent,\n abortSignal,\n },\n )\n return {\n renderPaymentForm: () => (\n <WestpacQuickStreamPaymentForm\n formSubmissionResult={formSubmissionResult}\n paymentSubmissionEvent={paymentSubmissionEvent}\n formSubmissionPaymentId={formSubmissionPaymentId}\n supplierBusinessCode={supplierBusinessCode}\n publishableApiKey={publishableApiKey}\n isTestMode={isTestMode}\n captchaSiteKey={captchaSiteKey}\n onCompleted={onCompleted}\n onCancelled={onCancelled}\n />\n ),\n }\n }\n }\n },\n [captchaSiteKey, onCancelled, onCompleted, query.formSubmissionPaymentId],\n )\n\n const [state] = useLoadDataState(loadPaymentFormConfiguration)\n\n switch (state.status) {\n case 'LOADING': {\n return (\n <section>\n <div className=\"cypress-loading has-text-centered\">\n <OnLoading className=\"has-text-centered\"></OnLoading>\n <span>Loading payment configuration...</span>\n </div>\n </section>\n )\n }\n case 'ERROR': {\n return (\n <section className=\"cypress-payment-form-loading-error-message\">\n <div className=\"ob-payment-form__error-icon-container has-text-centered has-margin-bottom-8\">\n <i className=\"ob-payment-form__error-icon material-icons has-text-danger icon-x-large\">\n error\n </i>\n </div>\n <p className=\"ob-payment-form__error-message has-text-centered has-margin-bottom-4\">\n {state.error.message}\n </p>\n </section>\n )\n }\n case 'SUCCESS': {\n return state.result.renderPaymentForm()\n }\n }\n}\n\nexport default React.memo(PaymentForm)\n"]}
@@ -28,13 +28,14 @@ declare global {
28
28
  };
29
29
  }
30
30
  }
31
- declare function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmissionEvent, formSubmissionPaymentId, supplierBusinessCode, publishableApiKey, isTestMode, onCompleted, onCancelled, }: {
31
+ declare function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmissionEvent, formSubmissionPaymentId, supplierBusinessCode, publishableApiKey, isTestMode, captchaSiteKey, onCompleted, onCancelled, }: {
32
32
  formSubmissionResult: submissionService.FormSubmissionResult;
33
33
  paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent;
34
34
  formSubmissionPaymentId: string;
35
35
  supplierBusinessCode: string;
36
36
  publishableApiKey: string;
37
37
  isTestMode: boolean;
38
+ captchaSiteKey: string;
38
39
  onCompleted: (result: {
39
40
  formSubmissionPayment: SubmissionTypes.FormSubmissionPayment;
40
41
  paymentReceiptUrl: string;
@@ -1,21 +1,26 @@
1
1
  import { OneBlinkAppsError, paymentService, } from '@oneblink/apps';
2
2
  import clsx from 'clsx';
3
3
  import React from 'react';
4
+ import ReCAPTCHA from 'react-google-recaptcha';
4
5
  import OnLoading from '../renderer/OnLoading';
5
6
  import OneBlinkAppsErrorOriginalMessage from '../renderer/OneBlinkAppsErrorOriginalMessage';
6
7
  import Modal from '../renderer/Modal';
7
- function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmissionEvent, formSubmissionPaymentId, supplierBusinessCode, publishableApiKey, isTestMode, onCompleted, onCancelled, }) {
8
- const [{ isCompletingTransaction, completeTransactionError }, setCompleteTransactionState,] = React.useState({
8
+ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmissionEvent, formSubmissionPaymentId, supplierBusinessCode, publishableApiKey, isTestMode, captchaSiteKey, onCompleted, onCancelled, }) {
9
+ const [{ isCompletingTransaction, completeTransactionError, captchaToken, displayCaptchaRequired, }, setCompleteTransactionState,] = React.useState({
9
10
  isCompletingTransaction: false,
10
11
  completeTransactionError: null,
12
+ captchaToken: null,
13
+ displayCaptchaRequired: false,
11
14
  });
12
15
  const clearCompleteTransactionError = React.useCallback(() => {
13
- setCompleteTransactionState({
16
+ setCompleteTransactionState((currentState) => ({
17
+ ...currentState,
14
18
  isCompletingTransaction: false,
15
19
  completeTransactionError: null,
16
- });
20
+ }));
17
21
  }, []);
18
- const [{ isLoading, loadError }, setLoadState] = React.useState({
22
+ const [{ trustedFrame, isLoading, loadError }, setLoadState] = React.useState({
23
+ trustedFrame: null,
19
24
  isLoading: true,
20
25
  loadError: null,
21
26
  });
@@ -51,7 +56,7 @@ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmission
51
56
  window.QuickstreamAPI.init({
52
57
  publishableApiKey,
53
58
  });
54
- const trustedFrame = await new Promise((resolve, reject) => {
59
+ const newTrustedFrame = await new Promise((resolve, reject) => {
55
60
  window.QuickstreamAPI.creditCards.createTrustedFrame({
56
61
  config: {
57
62
  supplierBusinessCode,
@@ -80,40 +85,9 @@ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmission
80
85
  resolve(data.trustedFrame);
81
86
  });
82
87
  });
83
- const westpacQuickStreamForm = document.getElementById('westpac-quick-stream-form-id');
84
- westpacQuickStreamForm === null || westpacQuickStreamForm === void 0 ? void 0 : westpacQuickStreamForm.addEventListener('submit', (event) => {
85
- event.preventDefault();
86
- setCompleteTransactionState({
87
- isCompletingTransaction: true,
88
- completeTransactionError: null,
89
- });
90
- trustedFrame.submitForm((errors, data) => {
91
- if (errors) {
92
- console.log('Invalid payment form submission', errors);
93
- setCompleteTransactionState({
94
- isCompletingTransaction: false,
95
- completeTransactionError: null,
96
- });
97
- return;
98
- }
99
- paymentService.westpacQuickStream
100
- .completeTransaction({
101
- singleUseTokenId: data.singleUseToken.singleUseTokenId,
102
- formSubmissionResult,
103
- formSubmissionPaymentId,
104
- paymentSubmissionEvent,
105
- })
106
- .then(onCompleted)
107
- .catch((error) => {
108
- setCompleteTransactionState({
109
- isCompletingTransaction: false,
110
- completeTransactionError: error,
111
- });
112
- });
113
- });
114
- });
115
88
  if (!abortController.signal.aborted) {
116
89
  setLoadState({
90
+ trustedFrame: newTrustedFrame,
117
91
  isLoading: false,
118
92
  loadError: null,
119
93
  });
@@ -122,6 +96,7 @@ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmission
122
96
  catch (error) {
123
97
  if (!abortController.signal.aborted) {
124
98
  setLoadState({
99
+ trustedFrame: null,
125
100
  isLoading: false,
126
101
  loadError: error,
127
102
  });
@@ -133,14 +108,59 @@ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmission
133
108
  abortController.abort();
134
109
  document.body.removeChild(scriptEle);
135
110
  };
111
+ }, [isTestMode, publishableApiKey, supplierBusinessCode]);
112
+ const handleSubmit = React.useCallback(async () => {
113
+ if (!trustedFrame) {
114
+ return;
115
+ }
116
+ if (!captchaToken) {
117
+ setCompleteTransactionState({
118
+ captchaToken: null,
119
+ displayCaptchaRequired: true,
120
+ isCompletingTransaction: false,
121
+ completeTransactionError: null,
122
+ });
123
+ return;
124
+ }
125
+ setCompleteTransactionState((currentState) => ({
126
+ ...currentState,
127
+ isCompletingTransaction: true,
128
+ completeTransactionError: null,
129
+ }));
130
+ trustedFrame.submitForm((errors, data) => {
131
+ if (errors) {
132
+ console.log('Invalid payment form submission', errors);
133
+ setCompleteTransactionState((currentState) => ({
134
+ ...currentState,
135
+ isCompletingTransaction: false,
136
+ completeTransactionError: null,
137
+ }));
138
+ return;
139
+ }
140
+ paymentService.westpacQuickStream
141
+ .completeTransaction({
142
+ singleUseTokenId: data.singleUseToken.singleUseTokenId,
143
+ formSubmissionResult,
144
+ formSubmissionPaymentId,
145
+ paymentSubmissionEvent,
146
+ captchaToken,
147
+ })
148
+ .then(onCompleted)
149
+ .catch((error) => {
150
+ setCompleteTransactionState((currentState) => ({
151
+ ...currentState,
152
+ isCompletingTransaction: false,
153
+ completeTransactionError: error,
154
+ }));
155
+ });
156
+ });
136
157
  }, [
158
+ captchaToken,
137
159
  formSubmissionPaymentId,
138
160
  formSubmissionResult,
139
- isTestMode,
140
161
  onCompleted,
141
162
  paymentSubmissionEvent,
142
- publishableApiKey,
143
- supplierBusinessCode,
163
+ trustedFrame,
144
164
  ]);
145
165
  const [{ isCancellingTransaction, cancelError }, setCancelState] = React.useState({
146
166
  isCancellingTransaction: false,
@@ -182,9 +202,21 @@ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmission
182
202
  React.createElement("i", { className: "ob-payment-receipt__error-icon material-icons has-text-danger icon-x-large" }, "error")),
183
203
  React.createElement("p", { className: "ob-payment-receipt__error-message has-text-centered has-margin-bottom-4" }, loadError.message))),
184
204
  React.createElement("section", null,
185
- React.createElement("form", { id: "westpac-quick-stream-form-id" },
205
+ React.createElement("form", { onSubmit: (event) => {
206
+ event.preventDefault();
207
+ handleSubmit();
208
+ } },
186
209
  React.createElement("div", { "data-quickstream-api": "creditCardContainer" }),
187
210
  !isLoading && !loadError && (React.createElement(React.Fragment, null,
211
+ React.createElement(ReCAPTCHA, { sitekey: captchaSiteKey, onChange: (newValue) => {
212
+ setCompleteTransactionState((currentState) => ({
213
+ ...currentState,
214
+ captchaToken: newValue,
215
+ displayCaptchaRequired: newValue === null,
216
+ }));
217
+ }, className: "ob-input cypress-captcha-control" }),
218
+ displayCaptchaRequired && (React.createElement("div", { role: "alert", className: "has-margin-top-8" },
219
+ React.createElement("div", { className: "has-text-danger ob-error__text cypress-required cypress-validation-message" }, "Please complete the CAPTCHA successfully"))),
188
220
  React.createElement("button", { type: "button", disabled: isCompletingTransaction || isCancellingTransaction, onClick: handleCancel, className: clsx('button ob-button is-outlined', {
189
221
  'is-loading': isCancellingTransaction,
190
222
  }) }, "Cancel"),
@@ -192,14 +224,14 @@ function WestpacQuickStreamPaymentForm({ formSubmissionResult, paymentSubmission
192
224
  'is-loading': isCompletingTransaction,
193
225
  }) }, "Make Payment"))))),
194
226
  React.createElement(Modal, { isOpen: !!completeTransactionError, title: "Payment Issue", className: "cypress-payment-error-close-button", actions: React.createElement(React.Fragment, null,
195
- React.createElement("button", { type: "button", className: "button ob-button cypress-payment-error-close-button is-light", onClick: clearCompleteTransactionError, autoFocus: true }, "Okay")) },
227
+ React.createElement("button", { type: "button", className: "button ob-button cypress-payment-error-close-button is-primary", onClick: clearCompleteTransactionError, autoFocus: true }, "Okay")) },
196
228
  React.createElement(React.Fragment, null,
197
229
  React.createElement("div", null, completeTransactionError instanceof Error
198
230
  ? completeTransactionError.message
199
231
  : completeTransactionError),
200
232
  completeTransactionError instanceof OneBlinkAppsError && (React.createElement(OneBlinkAppsErrorOriginalMessage, { error: completeTransactionError.originalError })))),
201
233
  React.createElement(Modal, { isOpen: !!cancelError, title: "Cancel Issue", className: "cypress-cancel-error-close-button", actions: React.createElement(React.Fragment, null,
202
- React.createElement("button", { type: "button", className: "button ob-button cypress-cancel-error-close-button is-light", onClick: clearCancelError, autoFocus: true }, "Okay")) },
234
+ React.createElement("button", { type: "button", className: "button ob-button cypress-cancel-error-close-button is-primary", onClick: clearCancelError, autoFocus: true }, "Okay")) },
203
235
  React.createElement(React.Fragment, null,
204
236
  React.createElement("div", null, cancelError instanceof Error ? cancelError.message : cancelError),
205
237
  cancelError instanceof OneBlinkAppsError && (React.createElement(OneBlinkAppsErrorOriginalMessage, { error: cancelError.originalError }))))));
@@ -1 +1 @@
1
- {"version":3,"file":"WestpacQuickStreamPaymentForm.js","sourceRoot":"","sources":["../../../src/components/payments/WestpacQuickStreamPaymentForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,GAEf,MAAM,gBAAgB,CAAA;AAEvB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAC7C,OAAO,gCAAgC,MAAM,8CAA8C,CAAA;AAC3F,OAAO,KAAK,MAAM,mBAAmB,CAAA;AA4CrC,SAAS,6BAA6B,CAAC,EACrC,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,WAAW,GAaZ;IACC,MAAM,CACJ,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,EACrD,2BAA2B,EAC5B,GAAG,KAAK,CAAC,QAAQ,CAGf;QACD,uBAAuB,EAAE,KAAK;QA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AAgC,IAC/B,KAAK,EAAE,wBAAwB,CAAC,aAAa,GAC7C,CACH,CACA,CACG;QAER,oBAAC,KAAK,IACJ,MAAM,EAAE,CAAC,CAAC,WAAW,EACrB,KAAK,EAAC,cAAc,EACpB,SAAS,EAAC,mCAAmC,EAC7C,OAAO,EACL;gBACE,gCACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,6DAA6D,EACvE,OAAO,EAAE,gBAAgB,EACzB,SAAS,iBAGF,CACR;YAGL;gBACE,iCACG,WAAW,YAAY,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAC7D;gBACL,WAAW,YAAY,iBAAiB,IAAI,CAC3C,oBAAC,gCAAgC,IAC/B,KAAK,EAAE,WAAW,CAAC,aAAa,GAChC,CACH,CACA,CACG,CACP,CACJ,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA","sourcesContent":["import {\n OneBlinkAppsError,\n paymentService,\n submissionService,\n} from '@oneblink/apps'\nimport { SubmissionTypes, SubmissionEventTypes } from '@oneblink/types'\nimport clsx from 'clsx'\nimport React from 'react'\nimport OnLoading from '../renderer/OnLoading'\nimport OneBlinkAppsErrorOriginalMessage from '../renderer/OneBlinkAppsErrorOriginalMessage'\nimport Modal from '../renderer/Modal'\n\ninterface TrustedFrame {\n submitForm(\n callback: (\n errors:\n | Array<{\n fieldName: string\n messages: string[]\n }>\n | undefined,\n data: {\n singleUseToken: {\n singleUseTokenId: string\n }\n },\n ) => void,\n ): void\n}\n\ndeclare global {\n interface Window {\n QuickstreamAPI: {\n init(options: { publishableApiKey: string }): void\n creditCards: {\n createTrustedFrame(\n options: unknown,\n callback: (\n errors:\n | Array<{\n fieldName: string\n messages: string[]\n }>\n | undefined,\n data: {\n trustedFrame: TrustedFrame\n },\n ) => void,\n ): void\n }\n }\n }\n}\n\nfunction WestpacQuickStreamPaymentForm({\n formSubmissionResult,\n paymentSubmissionEvent,\n formSubmissionPaymentId,\n supplierBusinessCode,\n publishableApiKey,\n isTestMode,\n onCompleted,\n onCancelled,\n}: {\n formSubmissionResult: submissionService.FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent\n formSubmissionPaymentId: string\n supplierBusinessCode: string\n publishableApiKey: string\n isTestMode: boolean\n onCompleted: (result: {\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n paymentReceiptUrl: string\n }) => void\n onCancelled: (result: { paymentReceiptUrl: string }) => void\n}) {\n const [\n { isCompletingTransaction, completeTransactionError },\n setCompleteTransactionState,\n ] = React.useState<{\n isCompletingTransaction: boolean\n completeTransactionError: Error | null\n }>({\n isCompletingTransaction: false,\n completeTransactionError: null,\n })\n\n const clearCompleteTransactionError = React.useCallback(() => {\n setCompleteTransactionState({\n isCompletingTransaction: false,\n completeTransactionError: null,\n })\n }, [])\n\n const [{ isLoading, loadError }, setLoadState] = React.useState<{\n isLoading: boolean\n loadError: Error | null\n }>({\n isLoading: true,\n loadError: null,\n })\n\n React.useEffect(() => {\n const abortController = new AbortController()\n const scriptEle = document.createElement('script')\n scriptEle.type = 'text/javascript'\n scriptEle.async = true\n\n const run = async () => {\n try {\n scriptEle.src = isTestMode\n ? 'https://api.quickstream.support.qvalent.com/rest/v1/quickstream-api-1.0.min.js'\n : 'https://api.quickstream.westpac.com.au/rest/v1/quickstream-api-1.0.min.js'\n\n await new Promise((resolve, reject) => {\n try {\n scriptEle.addEventListener(\n 'load',\n () => {\n resolve(undefined)\n },\n {\n signal: abortController.signal,\n },\n )\n\n scriptEle.addEventListener(\n 'error',\n () => {\n reject(new Error(`Failed to load the script ${scriptEle.src}`))\n },\n {\n signal: abortController.signal,\n },\n )\n\n document.body.appendChild(scriptEle)\n } catch (error) {\n console.warn('Failed to load script', error)\n reject(error)\n }\n })\n\n window.QuickstreamAPI.init({\n publishableApiKey,\n })\n const trustedFrame = await new Promise<TrustedFrame>(\n (resolve, reject) => {\n window.QuickstreamAPI.creditCards.createTrustedFrame(\n {\n config: {\n supplierBusinessCode,\n threeDS2: true,\n },\n iframe: {\n width: '100%',\n height: '100%',\n style: {\n border: '1px solid #dedede',\n 'border-radius': '2px',\n 'margin-bottom': '0.75rem',\n 'min-height': '400px',\n padding: '1.5rem',\n width: '100%',\n 'background-color': 'white',\n },\n },\n showAcceptedCards: true,\n showRequiredIndicators: true,\n },\n (errors, data) => {\n if (errors) {\n reject(errors)\n return\n }\n resolve(data.trustedFrame)\n },\n )\n },\n )\n const westpacQuickStreamForm = document.getElementById(\n 'westpac-quick-stream-form-id',\n )\n westpacQuickStreamForm?.addEventListener('submit', (event) => {\n event.preventDefault()\n\n setCompleteTransactionState({\n isCompletingTransaction: true,\n completeTransactionError: null,\n })\n\n trustedFrame.submitForm((errors, data) => {\n if (errors) {\n console.log('Invalid payment form submission', errors)\n setCompleteTransactionState({\n isCompletingTransaction: false,\n completeTransactionError: null,\n })\n return\n }\n\n paymentService.westpacQuickStream\n .completeTransaction({\n singleUseTokenId: data.singleUseToken.singleUseTokenId,\n formSubmissionResult,\n formSubmissionPaymentId,\n paymentSubmissionEvent,\n })\n .then(onCompleted)\n .catch((error) => {\n setCompleteTransactionState({\n isCompletingTransaction: false,\n completeTransactionError: error,\n })\n })\n })\n })\n\n if (!abortController.signal.aborted) {\n setLoadState({\n isLoading: false,\n loadError: null,\n })\n }\n } catch (error) {\n if (!abortController.signal.aborted) {\n setLoadState({\n isLoading: false,\n loadError: error as Error,\n })\n }\n }\n }\n\n run()\n\n return () => {\n abortController.abort()\n document.body.removeChild(scriptEle)\n }\n }, [\n formSubmissionPaymentId,\n formSubmissionResult,\n isTestMode,\n onCompleted,\n paymentSubmissionEvent,\n publishableApiKey,\n supplierBusinessCode,\n ])\n\n const [{ isCancellingTransaction, cancelError }, setCancelState] =\n React.useState<{\n isCancellingTransaction: boolean\n cancelError: Error | null\n }>({\n isCancellingTransaction: false,\n cancelError: null,\n })\n\n const clearCancelError = React.useCallback(() => {\n setCancelState({\n isCancellingTransaction: false,\n cancelError: null,\n })\n }, [])\n\n const handleCancel = React.useCallback(async () => {\n setCancelState({\n isCancellingTransaction: true,\n cancelError: null,\n })\n try {\n const result = await paymentService.westpacQuickStream.cancelPayment({\n formSubmissionPaymentId,\n formSubmissionResult,\n })\n onCancelled(result)\n } catch (error) {\n console.warn('Failed to cancel payment', error)\n setCancelState({\n isCancellingTransaction: false,\n cancelError: error as Error,\n })\n }\n }, [formSubmissionPaymentId, formSubmissionResult, onCancelled])\n\n return (\n <>\n {isLoading && (\n <section>\n <div className=\"cypress-loading has-text-centered\">\n <OnLoading className=\"has-text-centered\"></OnLoading>\n <span>Building payment form...</span>\n </div>\n </section>\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 <i className=\"ob-payment-receipt__error-icon material-icons has-text-danger icon-x-large\">\n error\n </i>\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 <section>\n <form id=\"westpac-quick-stream-form-id\">\n <div data-quickstream-api=\"creditCardContainer\"></div>\n\n {!isLoading && !loadError && (\n <>\n <button\n type=\"button\"\n disabled={isCompletingTransaction || isCancellingTransaction}\n onClick={handleCancel}\n className={clsx('button ob-button is-outlined', {\n 'is-loading': isCancellingTransaction,\n })}\n >\n Cancel\n </button>\n <button\n type=\"submit\"\n disabled={isCompletingTransaction || isCancellingTransaction}\n className={clsx('button ob-button is-success', {\n 'is-loading': isCompletingTransaction,\n })}\n >\n Make Payment\n </button>\n </>\n )}\n </form>\n </section>\n\n <Modal\n isOpen={!!completeTransactionError}\n title=\"Payment Issue\"\n className=\"cypress-payment-error-close-button\"\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button cypress-payment-error-close-button is-light\"\n onClick={clearCompleteTransactionError}\n autoFocus\n >\n Okay\n </button>\n </>\n }\n >\n <>\n <div>\n {completeTransactionError instanceof Error\n ? completeTransactionError.message\n : completeTransactionError}\n </div>\n {completeTransactionError instanceof OneBlinkAppsError && (\n <OneBlinkAppsErrorOriginalMessage\n error={completeTransactionError.originalError}\n />\n )}\n </>\n </Modal>\n\n <Modal\n isOpen={!!cancelError}\n title=\"Cancel Issue\"\n className=\"cypress-cancel-error-close-button\"\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button cypress-cancel-error-close-button is-light\"\n onClick={clearCancelError}\n autoFocus\n >\n Okay\n </button>\n </>\n }\n >\n <>\n <div>\n {cancelError instanceof Error ? cancelError.message : cancelError}\n </div>\n {cancelError instanceof OneBlinkAppsError && (\n <OneBlinkAppsErrorOriginalMessage\n error={cancelError.originalError}\n />\n )}\n </>\n </Modal>\n </>\n )\n}\n\nexport default React.memo(WestpacQuickStreamPaymentForm)\n"]}
1
+ {"version":3,"file":"WestpacQuickStreamPaymentForm.js","sourceRoot":"","sources":["../../../src/components/payments/WestpacQuickStreamPaymentForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,GAEf,MAAM,gBAAgB,CAAA;AAEvB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAC9C,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAC7C,OAAO,gCAAgC,MAAM,8CAA8C,CAAA;AAC3F,OAAO,KAAK,MAAM,mBAAmB,CAAA;AA4CrC,SAAS,6BAA6B,CAAC,EACrC,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,WAAW,EACX,WAAW,GAcZ;IACC,MAAM,CACJ,EACE,uBAAuB,EACvB,wBAAwB,EACxB,YAAY,EACZ,sBAAsB,GACvB,EACD,2BAA2B,EAC5B,GAAG,KAAK,CAAC,QAAQ,CAKf;QACD,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,EACL;gBACE,gCACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,+DAA+D,EACzE,OAAO,EAAE,gBAAgB,EACzB,SAAS,iBAGF,CACR;YAGL;gBACE,iCACG,WAAW,YAAY,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAC7D;gBACL,WAAW,YAAY,iBAAiB,IAAI,CAC3C,oBAAC,gCAAgC,IAC/B,KAAK,EAAE,WAAW,CAAC,aAAa,GAChC,CACH,CACA,CACG,CACP,CACJ,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAA","sourcesContent":["import {\n OneBlinkAppsError,\n paymentService,\n submissionService,\n} from '@oneblink/apps'\nimport { SubmissionTypes, SubmissionEventTypes } from '@oneblink/types'\nimport clsx from 'clsx'\nimport React from 'react'\nimport ReCAPTCHA from 'react-google-recaptcha'\nimport OnLoading from '../renderer/OnLoading'\nimport OneBlinkAppsErrorOriginalMessage from '../renderer/OneBlinkAppsErrorOriginalMessage'\nimport Modal from '../renderer/Modal'\n\ninterface TrustedFrame {\n submitForm(\n callback: (\n errors:\n | Array<{\n fieldName: string\n messages: string[]\n }>\n | undefined,\n data: {\n singleUseToken: {\n singleUseTokenId: string\n }\n },\n ) => void,\n ): void\n}\n\ndeclare global {\n interface Window {\n QuickstreamAPI: {\n init(options: { publishableApiKey: string }): void\n creditCards: {\n createTrustedFrame(\n options: unknown,\n callback: (\n errors:\n | Array<{\n fieldName: string\n messages: string[]\n }>\n | undefined,\n data: {\n trustedFrame: TrustedFrame\n },\n ) => void,\n ): void\n }\n }\n }\n}\n\nfunction WestpacQuickStreamPaymentForm({\n formSubmissionResult,\n paymentSubmissionEvent,\n formSubmissionPaymentId,\n supplierBusinessCode,\n publishableApiKey,\n isTestMode,\n captchaSiteKey,\n onCompleted,\n onCancelled,\n}: {\n formSubmissionResult: submissionService.FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent\n formSubmissionPaymentId: string\n supplierBusinessCode: string\n publishableApiKey: string\n isTestMode: boolean\n captchaSiteKey: string\n onCompleted: (result: {\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n paymentReceiptUrl: string\n }) => void\n onCancelled: (result: { paymentReceiptUrl: string }) => void\n}) {\n const [\n {\n isCompletingTransaction,\n completeTransactionError,\n captchaToken,\n displayCaptchaRequired,\n },\n setCompleteTransactionState,\n ] = React.useState<{\n captchaToken: string | null\n displayCaptchaRequired: boolean\n isCompletingTransaction: boolean\n completeTransactionError: Error | null\n }>({\n isCompletingTransaction: false,\n completeTransactionError: null,\n captchaToken: null,\n displayCaptchaRequired: false,\n })\n\n const clearCompleteTransactionError = React.useCallback(() => {\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: false,\n completeTransactionError: null,\n }))\n }, [])\n\n const [{ trustedFrame, isLoading, loadError }, setLoadState] =\n React.useState<{\n trustedFrame: TrustedFrame | null\n isLoading: boolean\n loadError: Error | null\n }>({\n trustedFrame: null,\n isLoading: true,\n loadError: null,\n })\n\n React.useEffect(() => {\n const abortController = new AbortController()\n const scriptEle = document.createElement('script')\n scriptEle.type = 'text/javascript'\n scriptEle.async = true\n\n const run = async () => {\n try {\n scriptEle.src = isTestMode\n ? 'https://api.quickstream.support.qvalent.com/rest/v1/quickstream-api-1.0.min.js'\n : 'https://api.quickstream.westpac.com.au/rest/v1/quickstream-api-1.0.min.js'\n\n await new Promise((resolve, reject) => {\n try {\n scriptEle.addEventListener(\n 'load',\n () => {\n resolve(undefined)\n },\n {\n signal: abortController.signal,\n },\n )\n\n scriptEle.addEventListener(\n 'error',\n () => {\n reject(new Error(`Failed to load the script ${scriptEle.src}`))\n },\n {\n signal: abortController.signal,\n },\n )\n\n document.body.appendChild(scriptEle)\n } catch (error) {\n console.warn('Failed to load script', error)\n reject(error)\n }\n })\n\n window.QuickstreamAPI.init({\n publishableApiKey,\n })\n const newTrustedFrame = await new Promise<TrustedFrame>(\n (resolve, reject) => {\n window.QuickstreamAPI.creditCards.createTrustedFrame(\n {\n config: {\n supplierBusinessCode,\n threeDS2: true,\n },\n iframe: {\n width: '100%',\n height: '100%',\n style: {\n border: '1px solid #dedede',\n 'border-radius': '2px',\n 'margin-bottom': '0.75rem',\n 'min-height': '400px',\n padding: '1.5rem',\n width: '100%',\n 'background-color': 'white',\n },\n },\n showAcceptedCards: true,\n showRequiredIndicators: true,\n },\n (errors, data) => {\n if (errors) {\n reject(errors)\n return\n }\n resolve(data.trustedFrame)\n },\n )\n },\n )\n\n if (!abortController.signal.aborted) {\n setLoadState({\n trustedFrame: newTrustedFrame,\n isLoading: false,\n loadError: null,\n })\n }\n } catch (error) {\n if (!abortController.signal.aborted) {\n setLoadState({\n trustedFrame: null,\n isLoading: false,\n loadError: error as Error,\n })\n }\n }\n }\n\n run()\n\n return () => {\n abortController.abort()\n document.body.removeChild(scriptEle)\n }\n }, [isTestMode, publishableApiKey, supplierBusinessCode])\n\n const handleSubmit = React.useCallback(async () => {\n if (!trustedFrame) {\n return\n }\n\n if (!captchaToken) {\n setCompleteTransactionState({\n captchaToken: null,\n displayCaptchaRequired: true,\n isCompletingTransaction: false,\n completeTransactionError: null,\n })\n return\n }\n\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: true,\n completeTransactionError: null,\n }))\n\n trustedFrame.submitForm((errors, data) => {\n if (errors) {\n console.log('Invalid payment form submission', errors)\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: false,\n completeTransactionError: null,\n }))\n return\n }\n\n paymentService.westpacQuickStream\n .completeTransaction({\n singleUseTokenId: data.singleUseToken.singleUseTokenId,\n formSubmissionResult,\n formSubmissionPaymentId,\n paymentSubmissionEvent,\n captchaToken,\n })\n .then(onCompleted)\n .catch((error) => {\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n isCompletingTransaction: false,\n completeTransactionError: error,\n }))\n })\n })\n }, [\n captchaToken,\n formSubmissionPaymentId,\n formSubmissionResult,\n onCompleted,\n paymentSubmissionEvent,\n trustedFrame,\n ])\n\n const [{ isCancellingTransaction, cancelError }, setCancelState] =\n React.useState<{\n isCancellingTransaction: boolean\n cancelError: Error | null\n }>({\n isCancellingTransaction: false,\n cancelError: null,\n })\n\n const clearCancelError = React.useCallback(() => {\n setCancelState({\n isCancellingTransaction: false,\n cancelError: null,\n })\n }, [])\n\n const handleCancel = React.useCallback(async () => {\n setCancelState({\n isCancellingTransaction: true,\n cancelError: null,\n })\n try {\n const result = await paymentService.westpacQuickStream.cancelPayment({\n formSubmissionPaymentId,\n formSubmissionResult,\n })\n onCancelled(result)\n } catch (error) {\n console.warn('Failed to cancel payment', error)\n setCancelState({\n isCancellingTransaction: false,\n cancelError: error as Error,\n })\n }\n }, [formSubmissionPaymentId, formSubmissionResult, onCancelled])\n\n return (\n <>\n {isLoading && (\n <section>\n <div className=\"cypress-loading has-text-centered\">\n <OnLoading className=\"has-text-centered\"></OnLoading>\n <span>Building payment form...</span>\n </div>\n </section>\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 <i className=\"ob-payment-receipt__error-icon material-icons has-text-danger icon-x-large\">\n error\n </i>\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 <section>\n <form\n onSubmit={(event) => {\n event.preventDefault()\n handleSubmit()\n }}\n >\n <div data-quickstream-api=\"creditCardContainer\"></div>\n\n {!isLoading && !loadError && (\n <>\n <ReCAPTCHA\n sitekey={captchaSiteKey}\n onChange={(newValue) => {\n setCompleteTransactionState((currentState) => ({\n ...currentState,\n captchaToken: newValue,\n displayCaptchaRequired: newValue === null,\n }))\n }}\n className=\"ob-input cypress-captcha-control\"\n />\n {displayCaptchaRequired && (\n <div role=\"alert\" className=\"has-margin-top-8\">\n <div className=\"has-text-danger ob-error__text cypress-required cypress-validation-message\">\n Please complete the CAPTCHA successfully\n </div>\n </div>\n )}\n\n <button\n type=\"button\"\n disabled={isCompletingTransaction || isCancellingTransaction}\n onClick={handleCancel}\n className={clsx('button ob-button is-outlined', {\n 'is-loading': isCancellingTransaction,\n })}\n >\n Cancel\n </button>\n <button\n type=\"submit\"\n disabled={isCompletingTransaction || isCancellingTransaction}\n className={clsx('button ob-button is-success', {\n 'is-loading': isCompletingTransaction,\n })}\n >\n Make Payment\n </button>\n </>\n )}\n </form>\n </section>\n\n <Modal\n isOpen={!!completeTransactionError}\n title=\"Payment Issue\"\n className=\"cypress-payment-error-close-button\"\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button cypress-payment-error-close-button is-primary\"\n onClick={clearCompleteTransactionError}\n autoFocus\n >\n Okay\n </button>\n </>\n }\n >\n <>\n <div>\n {completeTransactionError instanceof Error\n ? completeTransactionError.message\n : completeTransactionError}\n </div>\n {completeTransactionError instanceof OneBlinkAppsError && (\n <OneBlinkAppsErrorOriginalMessage\n error={completeTransactionError.originalError}\n />\n )}\n </>\n </Modal>\n\n <Modal\n isOpen={!!cancelError}\n title=\"Cancel Issue\"\n className=\"cypress-cancel-error-close-button\"\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button cypress-cancel-error-close-button is-primary\"\n onClick={clearCancelError}\n autoFocus\n >\n Okay\n </button>\n </>\n }\n >\n <>\n <div>\n {cancelError instanceof Error ? cancelError.message : cancelError}\n </div>\n {cancelError instanceof OneBlinkAppsError && (\n <OneBlinkAppsErrorOriginalMessage\n error={cancelError.originalError}\n />\n )}\n </>\n </Modal>\n </>\n )\n}\n\nexport default React.memo(WestpacQuickStreamPaymentForm)\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oneblink/apps-react",
3
3
  "description": "Helper functions for OneBlink apps in ReactJS.",
4
- "version": "5.7.0-beta.4",
4
+ "version": "5.7.0-beta.5",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/apps-react/issues"
@@ -46,7 +46,7 @@
46
46
  "@mui/lab": "^5.0.0-alpha.152",
47
47
  "@mui/material": "^5.14.17",
48
48
  "@mui/x-date-pickers": "^6.18.0",
49
- "@oneblink/apps": "^9.0.0-beta.3",
49
+ "@oneblink/apps": "^9.0.0-beta.4",
50
50
  "@oneblink/release-cli": "^3.0.0",
51
51
  "@oneblink/types": "github:oneblink/types",
52
52
  "@types/blueimp-load-image": "^5.16.4",