@oneblink/apps-react 13.5.1-beta.4 → 13.6.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 +25 -158
- package/dist/PaymentReceipt.js.map +1 -1
- package/dist/apps/approvals-service.d.ts +102 -1
- package/dist/apps/approvals-service.js +137 -1
- package/dist/apps/approvals-service.js.map +1 -1
- package/dist/apps/payment-service.d.ts +39 -0
- package/dist/apps/payment-service.js +67 -6
- package/dist/apps/payment-service.js.map +1 -1
- package/dist/apps/services/api/payment.d.ts +5 -1
- package/dist/apps/services/api/payment.js.map +1 -1
- package/dist/apps/services/fetch.d.ts +3 -1
- package/dist/apps/services/fetch.js +16 -4
- package/dist/apps/services/fetch.js.map +1 -1
- package/dist/apps/services/payment-handoff.d.ts +47 -0
- package/dist/apps/services/payment-handoff.js +79 -0
- package/dist/apps/services/payment-handoff.js.map +1 -0
- package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.d.ts +35 -19
- package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js +41 -27
- package/dist/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.js.map +1 -1
- package/dist/apps/services/payment-submission-result.d.ts +5 -0
- package/dist/apps/services/payment-submission-result.js +11 -0
- package/dist/apps/services/payment-submission-result.js.map +1 -0
- package/dist/apps/submission-service.js +2 -1
- package/dist/apps/submission-service.js.map +1 -1
- package/dist/components/ErrorSnackbar.js +7 -1
- package/dist/components/ErrorSnackbar.js.map +1 -1
- package/dist/components/payments/ApprovalStepPaymentReceipt.d.ts +67 -0
- package/dist/components/payments/ApprovalStepPaymentReceipt.js +86 -0
- package/dist/components/payments/ApprovalStepPaymentReceipt.js.map +1 -0
- package/dist/components/payments/PaymentForm.d.ts +6 -0
- package/dist/components/payments/PaymentForm.js +36 -35
- package/dist/components/payments/PaymentForm.js.map +1 -1
- package/dist/components/payments/SessionPaymentForm.d.ts +23 -0
- package/dist/components/payments/SessionPaymentForm.js +49 -0
- package/dist/components/payments/SessionPaymentForm.js.map +1 -0
- package/dist/components/payments/SessionPaymentReceipt.d.ts +15 -0
- package/dist/components/payments/SessionPaymentReceipt.js +149 -0
- package/dist/components/payments/SessionPaymentReceipt.js.map +1 -0
- package/dist/components/payments/WestpacQuickStreamPaymentForm.d.ts +7 -11
- package/dist/components/payments/WestpacQuickStreamPaymentForm.js +25 -31
- package/dist/components/payments/WestpacQuickStreamPaymentForm.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/services/form-validation/getApproverEditableFormElementIds.js +3 -0
- package/dist/services/form-validation/getApproverEditableFormElementIds.js.map +1 -1
- package/dist/services/getFlowInstanceNodesWithMeta.js +22 -3
- package/dist/services/getFlowInstanceNodesWithMeta.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export declare function generateHeaders(): Promise<Record<string, string>>;
|
|
2
2
|
export declare class HTTPError extends Error {
|
|
3
3
|
status: number;
|
|
4
|
-
|
|
4
|
+
/** Machine-readable conflict from the API error payload, when present. */
|
|
5
|
+
conflict?: string;
|
|
6
|
+
constructor(statusCode: number, message: string, conflict?: string);
|
|
5
7
|
}
|
|
6
8
|
export declare const fetchWithError: typeof fetch;
|
|
7
9
|
export declare function fetchJSON<T>(url: string, options?: RequestInit): Promise<T>;
|
|
@@ -19,11 +19,22 @@ export async function generateHeaders() {
|
|
|
19
19
|
return headers;
|
|
20
20
|
}
|
|
21
21
|
export class HTTPError extends Error {
|
|
22
|
-
constructor(statusCode, message) {
|
|
22
|
+
constructor(statusCode, message, conflict) {
|
|
23
23
|
super(message);
|
|
24
24
|
this.status = statusCode;
|
|
25
|
+
this.conflict = conflict;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
28
|
+
function readErrorPayload(body) {
|
|
29
|
+
if (!body || typeof body !== 'object') {
|
|
30
|
+
return { message: '' };
|
|
31
|
+
}
|
|
32
|
+
const payload = body;
|
|
33
|
+
return {
|
|
34
|
+
message: typeof payload.message === 'string' ? payload.message : '',
|
|
35
|
+
conflict: typeof payload.conflict === 'string' ? payload.conflict : undefined,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
27
38
|
export const fetchWithError = async (url, options) => {
|
|
28
39
|
try {
|
|
29
40
|
return await fetch(url, options);
|
|
@@ -46,7 +57,8 @@ export async function fetchJSON(url, options) {
|
|
|
46
57
|
if (response.ok) {
|
|
47
58
|
return body;
|
|
48
59
|
}
|
|
49
|
-
|
|
60
|
+
const errorPayload = readErrorPayload(body);
|
|
61
|
+
throw new HTTPError(response.status, errorPayload.message, errorPayload.conflict);
|
|
50
62
|
}
|
|
51
63
|
export async function searchRequest(url, searchParameters, abortSignal) {
|
|
52
64
|
const queryStringParams = formatQueryString(searchParameters);
|
|
@@ -88,8 +100,8 @@ export async function deleteRequest(url, abortSignal) {
|
|
|
88
100
|
};
|
|
89
101
|
const res = await fetchWithError(url, opts);
|
|
90
102
|
if (!res.ok) {
|
|
91
|
-
const errorPayload = await res.json();
|
|
92
|
-
throw new HTTPError(res.status, errorPayload.message);
|
|
103
|
+
const errorPayload = readErrorPayload(await res.json());
|
|
104
|
+
throw new HTTPError(res.status, errorPayload.message, errorPayload.conflict);
|
|
93
105
|
}
|
|
94
106
|
}
|
|
95
107
|
//# sourceMappingURL=fetch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/apps/services/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,4BAA4B,CAAA;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,MAAM,OAAO,GAA2B;QACtC,cAAc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M,IAAI,GAAG;QACX,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,MAAM,eAAe,EAAE;QAChC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;QAC9B,MAAM,EAAE,WAAW;KACpB,CAAA;IAED,OAAO,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AAC7B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAW,EACX,WAAyB;IAEzB,MAAM,IAAI,GAAG;QACX,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE,MAAM,eAAe,EAAE;QAChC,MAAM,EAAE,WAAW;KACpB,CAAA;IAED,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC3C,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,YAAY,GAAG,gBAAgB,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;QACvD,MAAM,IAAI,SAAS,CACjB,GAAG,CAAC,MAAM,EACV,YAAY,CAAC,OAAO,EACpB,YAAY,CAAC,QAAQ,CACtB,CAAA;IACH,CAAC;AACH,CAAC","sourcesContent":["import OneBlinkAppsError from './errors/oneBlinkAppsError'\n\nimport { getIdToken } from './forms-key'\nimport { formatQueryString } from './query-string'\nimport { getUserToken } from './user-token'\n\nexport async function generateHeaders() {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n }\n\n // Check auth service for a token if user is logged in\n const idToken = await getIdToken()\n if (idToken) {\n headers.Authorization = `Bearer ${idToken}`\n }\n const userToken = getUserToken()\n if (userToken) {\n headers['X-OneBlink-User-Token'] = userToken\n }\n\n return headers\n}\n\nexport class HTTPError extends Error {\n status: number\n /** Machine-readable conflict from the API error payload, when present. */\n conflict?: string\n\n constructor(statusCode: number, message: string, conflict?: string) {\n super(message)\n this.status = statusCode\n this.conflict = conflict\n }\n}\n\nfunction readErrorPayload(body: unknown): {\n message: string\n conflict?: string\n} {\n if (!body || typeof body !== 'object') {\n return { message: '' }\n }\n const payload = body as { message?: unknown; conflict?: unknown }\n return {\n message: typeof payload.message === 'string' ? payload.message : '',\n conflict: typeof payload.conflict === 'string' ? payload.conflict : undefined,\n }\n}\n\nexport const fetchWithError: typeof fetch = async (url, options) => {\n try {\n return await fetch(url, options)\n } catch (error) {\n throw new OneBlinkAppsError(\n 'We encountered a network related issue. Please ensure you are connected to the internet before trying again. If the problem persists, contact your administrator.',\n {\n title: 'Connectivity Issues',\n originalError: error as Error,\n isOffline: true,\n },\n )\n }\n}\n\nexport async function fetchJSON<T>(\n url: string,\n options?: RequestInit,\n): Promise<T> {\n const response = await fetchWithError(url, options)\n\n if (response.status === 204) {\n // @ts-expect-error\n return\n }\n\n const body = await response.json()\n if (response.ok) {\n return body\n }\n\n const errorPayload = readErrorPayload(body)\n throw new HTTPError(\n response.status,\n errorPayload.message,\n errorPayload.conflict,\n )\n}\n\nexport async function searchRequest<T>(\n url: string,\n searchParameters: Record<string, unknown>,\n abortSignal?: AbortSignal,\n): Promise<T> {\n const queryStringParams = formatQueryString(searchParameters)\n const body = await getRequest<T>(`${url}?${queryStringParams}`, abortSignal)\n return body\n}\n\nexport async function getRequest<T>(\n url: string,\n abortSignal?: AbortSignal,\n): Promise<T> {\n const headers = await generateHeaders()\n headers['Cache-Control'] = 'no-store'\n return fetchJSON(url, {\n method: 'GET',\n headers,\n signal: abortSignal,\n })\n}\n\nexport async function postRequest<OutT>(\n url: string,\n resource?: unknown,\n abortSignal?: AbortSignal,\n): Promise<OutT> {\n const opts = {\n method: 'POST',\n headers: await generateHeaders(),\n body: JSON.stringify(resource),\n signal: abortSignal,\n }\n\n return fetchJSON(url, opts)\n}\n\nexport async function putRequest<OutT>(\n url: string,\n resource: unknown,\n abortSignal?: AbortSignal,\n): Promise<OutT> {\n const opts = {\n method: 'PUT',\n headers: await generateHeaders(),\n body: JSON.stringify(resource),\n signal: abortSignal,\n }\n\n return fetchJSON(url, opts)\n}\n\nexport async function deleteRequest(\n url: string,\n abortSignal?: AbortSignal,\n): Promise<void> {\n const opts = {\n method: 'DELETE',\n headers: await generateHeaders(),\n signal: abortSignal,\n }\n\n const res = await fetchWithError(url, opts)\n if (!res.ok) {\n const errorPayload = readErrorPayload(await res.json())\n throw new HTTPError(\n res.status,\n errorPayload.message,\n errorPayload.conflict,\n )\n }\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SubmissionEventTypes } from '@oneblink/types';
|
|
2
|
+
import { FormSubmissionResult } from '../types/submissions';
|
|
3
|
+
/**
|
|
4
|
+
* Payment providers whose payment form is rendered by the application itself
|
|
5
|
+
* (e.g. Westpac QuickStream). Every other provider redirects the user to a
|
|
6
|
+
* payment form hosted by the provider.
|
|
7
|
+
*/
|
|
8
|
+
export type InAppPaymentType = 'WESTPAC_QUICK_STREAM';
|
|
9
|
+
/**
|
|
10
|
+
* Everything an in-app payment form needs to take a payment. It is passed
|
|
11
|
+
* between the application that creates the payment and the page that renders
|
|
12
|
+
* the payment form as URL search parameters, so the page does not need to read
|
|
13
|
+
* the submission from local storage.
|
|
14
|
+
*/
|
|
15
|
+
export type PaymentFormSession = {
|
|
16
|
+
paymentType: InAppPaymentType;
|
|
17
|
+
formId: number;
|
|
18
|
+
formSubmissionPaymentId: string;
|
|
19
|
+
integrationEnvironmentId: string;
|
|
20
|
+
amount: number;
|
|
21
|
+
customerReferenceNumber: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* `true` if the payment provider renders its payment form inside the
|
|
25
|
+
* application instead of redirecting to a provider hosted form.
|
|
26
|
+
*/
|
|
27
|
+
export declare function paymentProviderRendersInApp(type: string): type is InAppPaymentType;
|
|
28
|
+
/**
|
|
29
|
+
* Get the URL the user should be sent to in order to pay. Hosted providers
|
|
30
|
+
* return the provider's hosted form URL. In-app providers return the
|
|
31
|
+
* application's payment form URL with the payment session appended.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getPaymentHandoff({ hostedFormUrl, paymentSubmissionEvent, formId, amount, customerReferenceNumber, }: {
|
|
34
|
+
hostedFormUrl: string;
|
|
35
|
+
paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent;
|
|
36
|
+
formId: number;
|
|
37
|
+
amount: number;
|
|
38
|
+
/** The resolved customer reference number. Falls back to the configured value. */
|
|
39
|
+
customerReferenceNumber?: string;
|
|
40
|
+
}): string;
|
|
41
|
+
/** Get the payment handoff URL for a form submission that requires a payment. */
|
|
42
|
+
export declare function getFormSubmissionPaymentHandoff(formSubmissionResult: FormSubmissionResult): string;
|
|
43
|
+
/**
|
|
44
|
+
* Read the payment session from the search parameters of an in-app payment form
|
|
45
|
+
* URL. Throws if the URL does not contain a complete session.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getPaymentFormSession(search: string | URLSearchParams): PaymentFormSession;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import OneBlinkAppsError from './errors/oneBlinkAppsError';
|
|
2
|
+
import replaceInjectablesWithSubmissionValues from './replaceInjectablesWithSubmissionValues';
|
|
3
|
+
/**
|
|
4
|
+
* `true` if the payment provider renders its payment form inside the
|
|
5
|
+
* application instead of redirecting to a provider hosted form.
|
|
6
|
+
*/
|
|
7
|
+
export function paymentProviderRendersInApp(type) {
|
|
8
|
+
return type === 'WESTPAC_QUICK_STREAM';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Get the URL the user should be sent to in order to pay. Hosted providers
|
|
12
|
+
* return the provider's hosted form URL. In-app providers return the
|
|
13
|
+
* application's payment form URL with the payment session appended.
|
|
14
|
+
*/
|
|
15
|
+
export function getPaymentHandoff({ hostedFormUrl, paymentSubmissionEvent, formId, amount, customerReferenceNumber, }) {
|
|
16
|
+
switch (paymentSubmissionEvent.type) {
|
|
17
|
+
case 'WESTPAC_QUICK_STREAM': {
|
|
18
|
+
const url = new URL(hostedFormUrl);
|
|
19
|
+
url.searchParams.set('paymentType', paymentSubmissionEvent.type);
|
|
20
|
+
url.searchParams.set('formId', String(formId));
|
|
21
|
+
url.searchParams.set('integrationEnvironmentId', paymentSubmissionEvent.configuration.environmentId);
|
|
22
|
+
url.searchParams.set('amount', String(amount));
|
|
23
|
+
url.searchParams.set('customerReferenceNumber', customerReferenceNumber ||
|
|
24
|
+
paymentSubmissionEvent.configuration.customerReferenceNumber);
|
|
25
|
+
return url.href;
|
|
26
|
+
}
|
|
27
|
+
default: {
|
|
28
|
+
return hostedFormUrl;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Get the payment handoff URL for a form submission that requires a payment. */
|
|
33
|
+
export function getFormSubmissionPaymentHandoff(formSubmissionResult) {
|
|
34
|
+
const payment = formSubmissionResult.payment;
|
|
35
|
+
if (!payment) {
|
|
36
|
+
throw new Error('"formSubmissionResult.payment" must have a value to create a payment handoff');
|
|
37
|
+
}
|
|
38
|
+
const { submissionEvent } = payment;
|
|
39
|
+
return getPaymentHandoff({
|
|
40
|
+
hostedFormUrl: payment.hostedFormUrl,
|
|
41
|
+
paymentSubmissionEvent: submissionEvent,
|
|
42
|
+
formId: formSubmissionResult.definition.id,
|
|
43
|
+
amount: payment.amount,
|
|
44
|
+
customerReferenceNumber: submissionEvent.type === 'WESTPAC_QUICK_STREAM'
|
|
45
|
+
? replaceInjectablesWithSubmissionValues(submissionEvent.configuration.customerReferenceNumber, formSubmissionResult).text
|
|
46
|
+
: undefined,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Read the payment session from the search parameters of an in-app payment form
|
|
51
|
+
* URL. Throws if the URL does not contain a complete session.
|
|
52
|
+
*/
|
|
53
|
+
export function getPaymentFormSession(search) {
|
|
54
|
+
const params = typeof search === 'string' ? new URLSearchParams(search) : search;
|
|
55
|
+
const paymentType = params.get('paymentType') || '';
|
|
56
|
+
const formId = Number(params.get('formId'));
|
|
57
|
+
const formSubmissionPaymentId = params.get('formSubmissionPaymentId') || '';
|
|
58
|
+
const integrationEnvironmentId = params.get('integrationEnvironmentId') || '';
|
|
59
|
+
const amount = Number(params.get('amount'));
|
|
60
|
+
const customerReferenceNumber = params.get('customerReferenceNumber') || '';
|
|
61
|
+
if (!paymentProviderRendersInApp(paymentType) ||
|
|
62
|
+
!formId ||
|
|
63
|
+
!formSubmissionPaymentId ||
|
|
64
|
+
!integrationEnvironmentId ||
|
|
65
|
+
!Number.isFinite(amount)) {
|
|
66
|
+
throw new OneBlinkAppsError('This payment link is missing details.', {
|
|
67
|
+
title: 'Invalid Payment Link',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
paymentType,
|
|
72
|
+
formId,
|
|
73
|
+
formSubmissionPaymentId,
|
|
74
|
+
integrationEnvironmentId,
|
|
75
|
+
amount,
|
|
76
|
+
customerReferenceNumber,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=payment-handoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-handoff.js","sourceRoot":"","sources":["../../../src/apps/services/payment-handoff.ts"],"names":[],"mappings":"AACA,OAAO,iBAAiB,MAAM,4BAA4B,CAAA;AAC1D,OAAO,sCAAsC,MAAM,0CAA0C,CAAA;AAyB7F;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CACzC,IAAY;IAEZ,OAAO,IAAI,KAAK,sBAAsB,CAAA;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,aAAa,EACb,sBAAsB,EACtB,MAAM,EACN,MAAM,EACN,uBAAuB,GAQxB;IACC,QAAQ,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACpC,KAAK,sBAAsB,CAAC,CAAC,CAAC;YAC5B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAA;YAClC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,EAAE,sBAAsB,CAAC,IAAI,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gC;IAEhC,MAAM,MAAM,GACV,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;IAEnE,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAA;IACnD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC3C,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,IAAI,EAAE,CAAA;IAC3E,MAAM,wBAAwB,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,IAAI,EAAE,CAAA;IAC7E,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC3C,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,IAAI,EAAE,CAAA;IAE3E,IACE,CAAC,2BAA2B,CAAC,WAAW,CAAC;QACzC,CAAC,MAAM;QACP,CAAC,uBAAuB;QACxB,CAAC,wBAAwB;QACzB,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EACxB,CAAC;QACD,MAAM,IAAI,iBAAiB,CAAC,uCAAuC,EAAE;YACnE,KAAK,EAAE,sBAAsB;SAC9B,CAAC,CAAA;IACJ,CAAC;IAED,OAAO;QACL,WAAW;QACX,MAAM;QACN,uBAAuB;QACvB,wBAAwB;QACxB,MAAM;QACN,uBAAuB;KACxB,CAAA;AACH,CAAC","sourcesContent":["import { SubmissionEventTypes } from '@oneblink/types'\nimport OneBlinkAppsError from './errors/oneBlinkAppsError'\nimport replaceInjectablesWithSubmissionValues from './replaceInjectablesWithSubmissionValues'\nimport { FormSubmissionResult } from '../types/submissions'\n\n/**\n * Payment providers whose payment form is rendered by the application itself\n * (e.g. Westpac QuickStream). Every other provider redirects the user to a\n * payment form hosted by the provider.\n */\nexport type InAppPaymentType = 'WESTPAC_QUICK_STREAM'\n\n/**\n * Everything an in-app payment form needs to take a payment. It is passed\n * between the application that creates the payment and the page that renders\n * the payment form as URL search parameters, so the page does not need to read\n * the submission from local storage.\n */\nexport type PaymentFormSession = {\n paymentType: InAppPaymentType\n formId: number\n formSubmissionPaymentId: string\n integrationEnvironmentId: string\n amount: number\n customerReferenceNumber: string\n}\n\n/**\n * `true` if the payment provider renders its payment form inside the\n * application instead of redirecting to a provider hosted form.\n */\nexport function paymentProviderRendersInApp(\n type: string,\n): type is InAppPaymentType {\n return type === 'WESTPAC_QUICK_STREAM'\n}\n\n/**\n * Get the URL the user should be sent to in order to pay. Hosted providers\n * return the provider's hosted form URL. In-app providers return the\n * application's payment form URL with the payment session appended.\n */\nexport function getPaymentHandoff({\n hostedFormUrl,\n paymentSubmissionEvent,\n formId,\n amount,\n customerReferenceNumber,\n}: {\n hostedFormUrl: string\n paymentSubmissionEvent: SubmissionEventTypes.FormPaymentEvent\n formId: number\n amount: number\n /** The resolved customer reference number. Falls back to the configured value. */\n customerReferenceNumber?: string\n}): string {\n switch (paymentSubmissionEvent.type) {\n case 'WESTPAC_QUICK_STREAM': {\n const url = new URL(hostedFormUrl)\n url.searchParams.set('paymentType', paymentSubmissionEvent.type)\n url.searchParams.set('formId', String(formId))\n url.searchParams.set(\n 'integrationEnvironmentId',\n paymentSubmissionEvent.configuration.environmentId,\n )\n url.searchParams.set('amount', String(amount))\n url.searchParams.set(\n 'customerReferenceNumber',\n customerReferenceNumber ||\n paymentSubmissionEvent.configuration.customerReferenceNumber,\n )\n return url.href\n }\n default: {\n return hostedFormUrl\n }\n }\n}\n\n/** Get the payment handoff URL for a form submission that requires a payment. */\nexport function getFormSubmissionPaymentHandoff(\n formSubmissionResult: FormSubmissionResult,\n): string {\n const payment = formSubmissionResult.payment\n if (!payment) {\n throw new Error(\n '\"formSubmissionResult.payment\" must have a value to create a payment handoff',\n )\n }\n\n const { submissionEvent } = payment\n return getPaymentHandoff({\n hostedFormUrl: payment.hostedFormUrl,\n paymentSubmissionEvent: submissionEvent,\n formId: formSubmissionResult.definition.id,\n amount: payment.amount,\n customerReferenceNumber:\n submissionEvent.type === 'WESTPAC_QUICK_STREAM'\n ? replaceInjectablesWithSubmissionValues(\n submissionEvent.configuration.customerReferenceNumber,\n formSubmissionResult,\n ).text\n : undefined,\n })\n}\n\n/**\n * Read the payment session from the search parameters of an in-app payment form\n * URL. Throws if the URL does not contain a complete session.\n */\nexport function getPaymentFormSession(\n search: string | URLSearchParams,\n): PaymentFormSession {\n const params =\n typeof search === 'string' ? new URLSearchParams(search) : search\n\n const paymentType = params.get('paymentType') || ''\n const formId = Number(params.get('formId'))\n const formSubmissionPaymentId = params.get('formSubmissionPaymentId') || ''\n const integrationEnvironmentId = params.get('integrationEnvironmentId') || ''\n const amount = Number(params.get('amount'))\n const customerReferenceNumber = params.get('customerReferenceNumber') || ''\n\n if (\n !paymentProviderRendersInApp(paymentType) ||\n !formId ||\n !formSubmissionPaymentId ||\n !integrationEnvironmentId ||\n !Number.isFinite(amount)\n ) {\n throw new OneBlinkAppsError('This payment link is missing details.', {\n title: 'Invalid Payment Link',\n })\n }\n\n return {\n paymentType,\n formId,\n formSubmissionPaymentId,\n integrationEnvironmentId,\n amount,\n customerReferenceNumber,\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { SubmissionEventTypes } from '@oneblink/types';
|
|
1
|
+
import { SubmissionEventTypes, SubmissionTypes } from '@oneblink/types';
|
|
2
2
|
import { PaymentProvider } from '../../types/payments';
|
|
3
3
|
import { FormSubmissionResult } from '../../types/submissions';
|
|
4
|
+
import { PaymentFormSession } from '../payment-handoff';
|
|
4
5
|
export default class WestpacQuickStreamPaymentProvider implements PaymentProvider<SubmissionEventTypes.WestpacQuickStreamSubmissionEvent> {
|
|
5
6
|
constructor(paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent, formSubmissionResult: FormSubmissionResult);
|
|
6
7
|
formSubmissionResult: FormSubmissionResult;
|
|
@@ -14,32 +15,47 @@ export default class WestpacQuickStreamPaymentProvider implements PaymentProvide
|
|
|
14
15
|
submissionResult: FormSubmissionResult;
|
|
15
16
|
}>;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Get the QuickStream configuration needed to render the card form for a
|
|
20
|
+
* payment session.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getPaymentFormConfiguration({ session, abortSignal, }: {
|
|
23
|
+
session: PaymentFormSession;
|
|
21
24
|
abortSignal: AbortSignal;
|
|
22
25
|
}): Promise<{
|
|
23
26
|
supplierBusinessCode: string;
|
|
24
27
|
publishableApiKey: string;
|
|
25
28
|
isTestMode: boolean;
|
|
26
29
|
}>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Complete the QuickStream transaction for a payment session.
|
|
32
|
+
*
|
|
33
|
+
* `recaptcha` is required for payments started from a form submission and
|
|
34
|
+
* omitted for payments started from an approval step.
|
|
35
|
+
*/
|
|
36
|
+
export declare function completeTransaction({ session, singleUseTokenId, recaptcha, abortSignal, }: {
|
|
37
|
+
session: PaymentFormSession;
|
|
31
38
|
singleUseTokenId: string;
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
recaptcha?: {
|
|
40
|
+
siteKey: string;
|
|
41
|
+
token: string;
|
|
42
|
+
};
|
|
34
43
|
abortSignal?: AbortSignal;
|
|
35
44
|
}): Promise<{
|
|
36
|
-
formSubmissionPayment:
|
|
37
|
-
paymentReceiptUrl: string;
|
|
45
|
+
formSubmissionPayment: SubmissionTypes.FormSubmissionPayment;
|
|
38
46
|
}>;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
/** Cancel the QuickStream payment for a payment session. */
|
|
48
|
+
export declare function cancelPayment({ session, abortSignal, }: {
|
|
49
|
+
session: PaymentFormSession;
|
|
42
50
|
abortSignal?: AbortSignal;
|
|
43
|
-
}): Promise<
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Get the receipt URL for a completed QuickStream transaction. The receipt page
|
|
54
|
+
* verifies the transaction using the query parameters added here.
|
|
55
|
+
*/
|
|
56
|
+
export declare function getCompletedPaymentReceiptUrl({ formSubmissionResult, formSubmissionPayment, }: {
|
|
57
|
+
formSubmissionResult: FormSubmissionResult;
|
|
58
|
+
formSubmissionPayment: SubmissionTypes.FormSubmissionPayment;
|
|
59
|
+
}): string;
|
|
60
|
+
/** Get the receipt URL for a cancelled QuickStream payment. */
|
|
61
|
+
export declare function getCancelledPaymentReceiptUrl(formSubmissionResult: FormSubmissionResult, formSubmissionPaymentId: string): string;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import replaceInjectablesWithSubmissionValues from '../replaceInjectablesWithSubmissionValues';
|
|
2
1
|
import OneBlinkAppsError from '../errors/oneBlinkAppsError';
|
|
3
2
|
import { generateAmountReceiptItem, generateCreditCardMaskReceiptItem, generateSubmissionIdReceiptItem, prepareReceiptItems, } from './receipt-items';
|
|
4
3
|
import { cancelWestpacQuickStreamPayment, completeWestpacQuickStreamTransaction, getCustomFormPaymentConfiguration, } from '../api/payment';
|
|
@@ -41,9 +40,13 @@ export default class WestpacQuickStreamPaymentProvider {
|
|
|
41
40
|
};
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Get the QuickStream configuration needed to render the card form for a
|
|
45
|
+
* payment session.
|
|
46
|
+
*/
|
|
47
|
+
export async function getPaymentFormConfiguration({ session, abortSignal, }) {
|
|
48
|
+
const { supplierBusinessCode, publishableApiKey, isTestMode } = await getCustomFormPaymentConfiguration(`/forms/${session.formId}/westpac-quick-stream-payment/${session.formSubmissionPaymentId}`, {
|
|
49
|
+
integrationEnvironmentId: session.integrationEnvironmentId,
|
|
47
50
|
}, abortSignal);
|
|
48
51
|
return {
|
|
49
52
|
supplierBusinessCode,
|
|
@@ -51,22 +54,38 @@ export async function getPaymentFormConfiguration({ formSubmissionResult, formSu
|
|
|
51
54
|
isTestMode,
|
|
52
55
|
};
|
|
53
56
|
}
|
|
54
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Complete the QuickStream transaction for a payment session.
|
|
59
|
+
*
|
|
60
|
+
* `recaptcha` is required for payments started from a form submission and
|
|
61
|
+
* omitted for payments started from an approval step.
|
|
62
|
+
*/
|
|
63
|
+
export async function completeTransaction({ session, singleUseTokenId, recaptcha, abortSignal, }) {
|
|
64
|
+
const { formSubmissionPayment } = await completeWestpacQuickStreamTransaction(session.formId, {
|
|
65
|
+
formSubmissionPaymentId: session.formSubmissionPaymentId,
|
|
66
|
+
singleUseTokenId,
|
|
67
|
+
integrationEnvironmentId: session.integrationEnvironmentId,
|
|
68
|
+
customerReferenceNumber: session.customerReferenceNumber,
|
|
69
|
+
principalAmount: session.amount,
|
|
70
|
+
recaptcha,
|
|
71
|
+
}, abortSignal);
|
|
72
|
+
return {
|
|
73
|
+
formSubmissionPayment,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Cancel the QuickStream payment for a payment session. */
|
|
77
|
+
export async function cancelPayment({ session, abortSignal, }) {
|
|
78
|
+
await cancelWestpacQuickStreamPayment(session.formId, session.formSubmissionPaymentId, abortSignal);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get the receipt URL for a completed QuickStream transaction. The receipt page
|
|
82
|
+
* verifies the transaction using the query parameters added here.
|
|
83
|
+
*/
|
|
84
|
+
export function getCompletedPaymentReceiptUrl({ formSubmissionResult, formSubmissionPayment, }) {
|
|
55
85
|
var _a, _b;
|
|
56
86
|
if (!formSubmissionResult.payment) {
|
|
57
|
-
throw new Error('"formSubmissionResult.payment" must have a value to
|
|
87
|
+
throw new Error('"formSubmissionResult.payment" must have a value to create a receipt URL');
|
|
58
88
|
}
|
|
59
|
-
const { formSubmissionPayment } = await completeWestpacQuickStreamTransaction(formSubmissionResult.definition.id, {
|
|
60
|
-
formSubmissionPaymentId,
|
|
61
|
-
singleUseTokenId,
|
|
62
|
-
integrationEnvironmentId: paymentSubmissionEvent.configuration.environmentId,
|
|
63
|
-
customerReferenceNumber: replaceInjectablesWithSubmissionValues(paymentSubmissionEvent.configuration.customerReferenceNumber, formSubmissionResult).text,
|
|
64
|
-
principalAmount: formSubmissionResult.payment.amount,
|
|
65
|
-
recaptcha: {
|
|
66
|
-
siteKey: captchaSiteKey,
|
|
67
|
-
token: captchaToken,
|
|
68
|
-
},
|
|
69
|
-
}, abortSignal);
|
|
70
89
|
const url = new URL(formSubmissionResult.payment.paymentReceiptUrl);
|
|
71
90
|
if (formSubmissionPayment.type === 'WESTPAC_QUICK_STREAM' &&
|
|
72
91
|
formSubmissionPayment.paymentTransaction) {
|
|
@@ -79,16 +98,13 @@ export async function completeTransaction({ formSubmissionPaymentId, formSubmiss
|
|
|
79
98
|
url.searchParams.append('maskedCardNumber4Digits', (_b = formSubmissionPayment.paymentTransaction.creditCard) === null || _b === void 0 ? void 0 : _b.maskedCardNumber4Digits);
|
|
80
99
|
}
|
|
81
100
|
}
|
|
82
|
-
return
|
|
83
|
-
formSubmissionPayment,
|
|
84
|
-
paymentReceiptUrl: url.href,
|
|
85
|
-
};
|
|
101
|
+
return url.href;
|
|
86
102
|
}
|
|
87
|
-
|
|
103
|
+
/** Get the receipt URL for a cancelled QuickStream payment. */
|
|
104
|
+
export function getCancelledPaymentReceiptUrl(formSubmissionResult, formSubmissionPaymentId) {
|
|
88
105
|
if (!formSubmissionResult.payment) {
|
|
89
|
-
throw new Error('"formSubmissionResult.payment" must have a value to
|
|
106
|
+
throw new Error('"formSubmissionResult.payment" must have a value to create a receipt URL');
|
|
90
107
|
}
|
|
91
|
-
await cancelWestpacQuickStreamPayment(formSubmissionResult.definition.id, formSubmissionPaymentId, abortSignal);
|
|
92
108
|
const url = new URL(formSubmissionResult.payment.paymentReceiptUrl);
|
|
93
109
|
if (formSubmissionResult.submissionId) {
|
|
94
110
|
url.searchParams.append('paymentReferenceNumber', formSubmissionResult.submissionId);
|
|
@@ -97,8 +113,6 @@ export async function cancelPayment({ formSubmissionPaymentId, formSubmissionRes
|
|
|
97
113
|
url.searchParams.append('totalAmount', formSubmissionResult.payment.amount.toString());
|
|
98
114
|
url.searchParams.append('summaryCode', '1');
|
|
99
115
|
url.searchParams.append('responseDescription', 'Payment Cancelled');
|
|
100
|
-
return
|
|
101
|
-
paymentReceiptUrl: url.href,
|
|
102
|
-
};
|
|
116
|
+
return url.href;
|
|
103
117
|
}
|
|
104
118
|
//# sourceMappingURL=WestpacQuickStreamPaymentProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WestpacQuickStreamPaymentProvider.js","sourceRoot":"","sources":["../../../../src/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.ts"],"names":[],"mappings":"AAGA,OAAO,sCAAsC,MAAM,2CAA2C,CAAA;AAC9F,OAAO,iBAAiB,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EACL,yBAAyB,EACzB,iCAAiC,EACjC,+BAA+B,EAC/B,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,+BAA+B,EAC/B,qCAAqC,EACrC,iCAAiC,GAClC,MAAM,gBAAgB,CAAA;AAEvB,MAAM,CAAC,OAAO,OAAO,iCAAiC;IACpD,YACE,sBAA8E,EAC9E,oBAA0C;QAE1C,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAA;QAChD,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,CAAA;IACtD,CAAC;IAKD,KAAK,CAAC,wBAAwB,CAAC,KAA8B;QAC3D,MAAM,EACJ,sBAAsB,EACtB,aAAa,EACb,uBAAuB,EACvB,WAAW,EACX,mBAAmB,EACnB,WAAW,GACZ,G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,CAAA;IACD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,CAAA;IAC3C,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,qBAAqB,EAAE,mBAAmB,CAAC,CAAA;IAEnE,OAAO;QACL,iBAAiB,EAAE,GAAG,CAAC,IAAI;KAC5B,CAAA;AACH,CAAC","sourcesContent":["import { SubmissionEventTypes } from '@oneblink/types'\nimport { PaymentProvider } from '../../types/payments'\nimport { FormSubmissionResult } from '../../types/submissions'\nimport replaceInjectablesWithSubmissionValues from '../replaceInjectablesWithSubmissionValues'\nimport OneBlinkAppsError from '../errors/oneBlinkAppsError'\nimport {\n generateAmountReceiptItem,\n generateCreditCardMaskReceiptItem,\n generateSubmissionIdReceiptItem,\n prepareReceiptItems,\n} from './receipt-items'\nimport {\n cancelWestpacQuickStreamPayment,\n completeWestpacQuickStreamTransaction,\n getCustomFormPaymentConfiguration,\n} from '../api/payment'\n\nexport default class WestpacQuickStreamPaymentProvider implements PaymentProvider<SubmissionEventTypes.WestpacQuickStreamSubmissionEvent> {\n constructor(\n paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent,\n formSubmissionResult: FormSubmissionResult,\n ) {\n this.formSubmissionResult = formSubmissionResult\n this.paymentSubmissionEvent = paymentSubmissionEvent\n }\n\n formSubmissionResult: FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent\n\n async verifyPaymentTransaction(query: Record<string, unknown>) {\n const {\n paymentReferenceNumber,\n receiptNumber,\n maskedCardNumber4Digits,\n summaryCode,\n responseDescription,\n totalAmount,\n } = query as {\n paymentReferenceNumber?: string\n receiptNumber?: string\n maskedCardNumber4Digits?: string\n summaryCode?: string\n responseDescription?: string\n totalAmount?: string\n }\n if (\n !paymentReferenceNumber ||\n !receiptNumber ||\n !summaryCode ||\n !responseDescription ||\n !totalAmount\n ) {\n throw new OneBlinkAppsError(\n 'Transactions can not be verified unless navigating here directly after a payment.',\n )\n }\n if (this.formSubmissionResult.submissionId !== paymentReferenceNumber) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for the incorrect payment.',\n )\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: receiptNumber,\n allowCopyToClipboard: true,\n },\n generateCreditCardMaskReceiptItem(maskedCardNumber4Digits),\n generateAmountReceiptItem(parseFloat(totalAmount)),\n ]),\n transaction: {\n isSuccess: summaryCode === '0',\n errorMessage: responseDescription,\n },\n submissionResult: this.formSubmissionResult,\n }\n }\n}\n\nexport async function getPaymentFormConfiguration({\n formSubmissionResult,\n formSubmissionPaymentId,\n paymentSubmissionEvent,\n abortSignal,\n}: {\n formSubmissionResult: FormSubmissionResult\n formSubmissionPaymentId: string\n paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent\n abortSignal: AbortSignal\n}): Promise<{\n supplierBusinessCode: string\n publishableApiKey: string\n isTestMode: boolean\n}> {\n const { supplierBusinessCode, publishableApiKey, isTestMode } =\n await getCustomFormPaymentConfiguration<{\n supplierBusinessCode: string\n publishableApiKey: string\n isTestMode: boolean\n }>(\n `/forms/${formSubmissionResult.definition.id}/westpac-quick-stream-payment/${formSubmissionPaymentId}`,\n {\n integrationEnvironmentId:\n paymentSubmissionEvent.configuration.environmentId,\n },\n abortSignal,\n )\n\n return {\n supplierBusinessCode,\n publishableApiKey,\n isTestMode,\n }\n}\n\nexport async function completeTransaction({\n formSubmissionPaymentId,\n formSubmissionResult,\n paymentSubmissionEvent,\n singleUseTokenId,\n captchaSiteKey,\n captchaToken,\n abortSignal,\n}: {\n formSubmissionPaymentId: string\n formSubmissionResult: FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent\n singleUseTokenId: string\n captchaSiteKey: string\n captchaToken: string\n abortSignal?: AbortSignal\n}) {\n if (!formSubmissionResult.payment) {\n throw new Error(\n '\"formSubmissionResult.payment\" must have a value to complete transactions',\n )\n }\n\n const { formSubmissionPayment } = await completeWestpacQuickStreamTransaction(\n formSubmissionResult.definition.id,\n {\n formSubmissionPaymentId,\n singleUseTokenId,\n integrationEnvironmentId:\n paymentSubmissionEvent.configuration.environmentId,\n customerReferenceNumber: replaceInjectablesWithSubmissionValues(\n paymentSubmissionEvent.configuration.customerReferenceNumber,\n formSubmissionResult,\n ).text,\n principalAmount: formSubmissionResult.payment.amount,\n recaptcha: {\n siteKey: captchaSiteKey,\n token: captchaToken,\n },\n },\n abortSignal,\n )\n\n const url = new URL(formSubmissionResult.payment.paymentReceiptUrl)\n if (\n formSubmissionPayment.type === 'WESTPAC_QUICK_STREAM' &&\n formSubmissionPayment.paymentTransaction\n ) {\n url.searchParams.append(\n 'paymentReferenceNumber',\n formSubmissionPayment.paymentTransaction.paymentReferenceNumber,\n )\n url.searchParams.append(\n 'receiptNumber',\n formSubmissionPayment.paymentTransaction.receiptNumber,\n )\n url.searchParams.append(\n 'totalAmount',\n formSubmissionPayment.paymentTransaction.totalAmount.amount.toString(),\n )\n url.searchParams.append(\n 'summaryCode',\n formSubmissionPayment.paymentTransaction.summaryCode,\n )\n url.searchParams.append(\n 'responseDescription',\n formSubmissionPayment.paymentTransaction.responseDescription,\n )\n if (\n formSubmissionPayment.paymentTransaction.creditCard\n ?.maskedCardNumber4Digits\n ) {\n url.searchParams.append(\n 'maskedCardNumber4Digits',\n formSubmissionPayment.paymentTransaction.creditCard\n ?.maskedCardNumber4Digits,\n )\n }\n }\n\n return {\n formSubmissionPayment,\n paymentReceiptUrl: url.href,\n }\n}\n\nexport async function cancelPayment({\n formSubmissionPaymentId,\n formSubmissionResult,\n abortSignal,\n}: {\n formSubmissionPaymentId: string\n formSubmissionResult: FormSubmissionResult\n abortSignal?: AbortSignal\n}) {\n if (!formSubmissionResult.payment) {\n throw new Error(\n '\"formSubmissionResult.payment\" must have a value to cancel payments',\n )\n }\n\n await cancelWestpacQuickStreamPayment(\n formSubmissionResult.definition.id,\n formSubmissionPaymentId,\n abortSignal,\n )\n\n const url = new URL(formSubmissionResult.payment.paymentReceiptUrl)\n if (formSubmissionResult.submissionId) {\n url.searchParams.append(\n 'paymentReferenceNumber',\n formSubmissionResult.submissionId,\n )\n }\n url.searchParams.append('receiptNumber', formSubmissionPaymentId)\n url.searchParams.append(\n 'totalAmount',\n formSubmissionResult.payment.amount.toString(),\n )\n url.searchParams.append('summaryCode', '1')\n url.searchParams.append('responseDescription', 'Payment Cancelled')\n\n return {\n paymentReceiptUrl: url.href,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"WestpacQuickStreamPaymentProvider.js","sourceRoot":"","sources":["../../../../src/apps/services/payment-providers/WestpacQuickStreamPaymentProvider.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EACL,yBAAyB,EACzB,iCAAiC,EACjC,+BAA+B,EAC/B,mBAAmB,GACpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,+BAA+B,EAC/B,qCAAqC,EACrC,iCAAiC,GAClC,MAAM,gBAAgB,CAAA;AAGvB,MAAM,CAAC,OAAO,OAAO,iCAAiC;IACpD,YACE,sBAA8E,EAC9E,oBAA0C;QAE1C,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAA;QAChD,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,CAAA;IACtD,CAAC;IAKD,KAAK,CAAC,wBAAwB,CAAC,KAA8B;QAC3D,MAAM,EACJ,sBAAsB,EACtB,aAAa,EACb,uBAAuB,EACvB,WAAW,EACX,mBAAmB,EACnB,WAAW,GACZ,GAAG,KAOH,CAAA;QACD,IACE,CAAC,sBAAsB;YACvB,CAAC,aAAa;YACd,CAAC,WAAW;YACZ,CAAC,mBAAmB;YACpB,CAAC,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AE,mBAAmB,CAAC,CAAA;IAEnE,OAAO,GAAG,CAAC,IAAI,CAAA;AACjB,CAAC","sourcesContent":["import { SubmissionEventTypes, SubmissionTypes } from '@oneblink/types'\nimport { PaymentProvider } from '../../types/payments'\nimport { FormSubmissionResult } from '../../types/submissions'\nimport OneBlinkAppsError from '../errors/oneBlinkAppsError'\nimport {\n generateAmountReceiptItem,\n generateCreditCardMaskReceiptItem,\n generateSubmissionIdReceiptItem,\n prepareReceiptItems,\n} from './receipt-items'\nimport {\n cancelWestpacQuickStreamPayment,\n completeWestpacQuickStreamTransaction,\n getCustomFormPaymentConfiguration,\n} from '../api/payment'\nimport { PaymentFormSession } from '../payment-handoff'\n\nexport default class WestpacQuickStreamPaymentProvider implements PaymentProvider<SubmissionEventTypes.WestpacQuickStreamSubmissionEvent> {\n constructor(\n paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent,\n formSubmissionResult: FormSubmissionResult,\n ) {\n this.formSubmissionResult = formSubmissionResult\n this.paymentSubmissionEvent = paymentSubmissionEvent\n }\n\n formSubmissionResult: FormSubmissionResult\n paymentSubmissionEvent: SubmissionEventTypes.WestpacQuickStreamSubmissionEvent\n\n async verifyPaymentTransaction(query: Record<string, unknown>) {\n const {\n paymentReferenceNumber,\n receiptNumber,\n maskedCardNumber4Digits,\n summaryCode,\n responseDescription,\n totalAmount,\n } = query as {\n paymentReferenceNumber?: string\n receiptNumber?: string\n maskedCardNumber4Digits?: string\n summaryCode?: string\n responseDescription?: string\n totalAmount?: string\n }\n if (\n !paymentReferenceNumber ||\n !receiptNumber ||\n !summaryCode ||\n !responseDescription ||\n !totalAmount\n ) {\n throw new OneBlinkAppsError(\n 'Transactions can not be verified unless navigating here directly after a payment.',\n )\n }\n if (this.formSubmissionResult.submissionId !== paymentReferenceNumber) {\n throw new OneBlinkAppsError(\n 'It looks like you are attempting to view a receipt for the incorrect payment.',\n )\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: receiptNumber,\n allowCopyToClipboard: true,\n },\n generateCreditCardMaskReceiptItem(maskedCardNumber4Digits),\n generateAmountReceiptItem(parseFloat(totalAmount)),\n ]),\n transaction: {\n isSuccess: summaryCode === '0',\n errorMessage: responseDescription,\n },\n submissionResult: this.formSubmissionResult,\n }\n }\n}\n\n/**\n * Get the QuickStream configuration needed to render the card form for a\n * payment session.\n */\nexport async function getPaymentFormConfiguration({\n session,\n abortSignal,\n}: {\n session: PaymentFormSession\n abortSignal: AbortSignal\n}): Promise<{\n supplierBusinessCode: string\n publishableApiKey: string\n isTestMode: boolean\n}> {\n const { supplierBusinessCode, publishableApiKey, isTestMode } =\n await getCustomFormPaymentConfiguration<{\n supplierBusinessCode: string\n publishableApiKey: string\n isTestMode: boolean\n }>(\n `/forms/${session.formId}/westpac-quick-stream-payment/${session.formSubmissionPaymentId}`,\n {\n integrationEnvironmentId: session.integrationEnvironmentId,\n },\n abortSignal,\n )\n\n return {\n supplierBusinessCode,\n publishableApiKey,\n isTestMode,\n }\n}\n\n/**\n * Complete the QuickStream transaction for a payment session.\n *\n * `recaptcha` is required for payments started from a form submission and\n * omitted for payments started from an approval step.\n */\nexport async function completeTransaction({\n session,\n singleUseTokenId,\n recaptcha,\n abortSignal,\n}: {\n session: PaymentFormSession\n singleUseTokenId: string\n recaptcha?: {\n siteKey: string\n token: string\n }\n abortSignal?: AbortSignal\n}): Promise<{\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n}> {\n const { formSubmissionPayment } = await completeWestpacQuickStreamTransaction(\n session.formId,\n {\n formSubmissionPaymentId: session.formSubmissionPaymentId,\n singleUseTokenId,\n integrationEnvironmentId: session.integrationEnvironmentId,\n customerReferenceNumber: session.customerReferenceNumber,\n principalAmount: session.amount,\n recaptcha,\n },\n abortSignal,\n )\n\n return {\n formSubmissionPayment,\n }\n}\n\n/** Cancel the QuickStream payment for a payment session. */\nexport async function cancelPayment({\n session,\n abortSignal,\n}: {\n session: PaymentFormSession\n abortSignal?: AbortSignal\n}): Promise<void> {\n await cancelWestpacQuickStreamPayment(\n session.formId,\n session.formSubmissionPaymentId,\n abortSignal,\n )\n}\n\n/**\n * Get the receipt URL for a completed QuickStream transaction. The receipt page\n * verifies the transaction using the query parameters added here.\n */\nexport function getCompletedPaymentReceiptUrl({\n formSubmissionResult,\n formSubmissionPayment,\n}: {\n formSubmissionResult: FormSubmissionResult\n formSubmissionPayment: SubmissionTypes.FormSubmissionPayment\n}): string {\n if (!formSubmissionResult.payment) {\n throw new Error(\n '\"formSubmissionResult.payment\" must have a value to create a receipt URL',\n )\n }\n\n const url = new URL(formSubmissionResult.payment.paymentReceiptUrl)\n if (\n formSubmissionPayment.type === 'WESTPAC_QUICK_STREAM' &&\n formSubmissionPayment.paymentTransaction\n ) {\n url.searchParams.append(\n 'paymentReferenceNumber',\n formSubmissionPayment.paymentTransaction.paymentReferenceNumber,\n )\n url.searchParams.append(\n 'receiptNumber',\n formSubmissionPayment.paymentTransaction.receiptNumber,\n )\n url.searchParams.append(\n 'totalAmount',\n formSubmissionPayment.paymentTransaction.totalAmount.amount.toString(),\n )\n url.searchParams.append(\n 'summaryCode',\n formSubmissionPayment.paymentTransaction.summaryCode,\n )\n url.searchParams.append(\n 'responseDescription',\n formSubmissionPayment.paymentTransaction.responseDescription,\n )\n if (\n formSubmissionPayment.paymentTransaction.creditCard\n ?.maskedCardNumber4Digits\n ) {\n url.searchParams.append(\n 'maskedCardNumber4Digits',\n formSubmissionPayment.paymentTransaction.creditCard\n ?.maskedCardNumber4Digits,\n )\n }\n }\n\n return url.href\n}\n\n/** Get the receipt URL for a cancelled QuickStream payment. */\nexport function getCancelledPaymentReceiptUrl(\n formSubmissionResult: FormSubmissionResult,\n formSubmissionPaymentId: string,\n): string {\n if (!formSubmissionResult.payment) {\n throw new Error(\n '\"formSubmissionResult.payment\" must have a value to create a receipt URL',\n )\n }\n\n const url = new URL(formSubmissionResult.payment.paymentReceiptUrl)\n if (formSubmissionResult.submissionId) {\n url.searchParams.append(\n 'paymentReferenceNumber',\n formSubmissionResult.submissionId,\n )\n }\n url.searchParams.append('receiptNumber', formSubmissionPaymentId)\n url.searchParams.append(\n 'totalAmount',\n formSubmissionResult.payment.amount.toString(),\n )\n url.searchParams.append('summaryCode', '1')\n url.searchParams.append('responseDescription', 'Payment Cancelled')\n\n return url.href\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FormSubmissionResult } from '../types/submissions';
|
|
2
|
+
/** Read the payment stored for the receipt page. `null` when nothing is stored. */
|
|
3
|
+
export declare function retrieveFormSubmissionResult(): Promise<FormSubmissionResult | null>;
|
|
4
|
+
/** Store a payment so the receipt page can verify it after the provider redirects back. */
|
|
5
|
+
export declare function rememberPaymentSubmissionResult(formSubmissionResult: FormSubmissionResult): Promise<void>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import utilsService from './utils';
|
|
2
|
+
const PAYMENT_SUBMISSION_RESULT_KEY = 'PAYMENT_SUBMISSION_RESULT';
|
|
3
|
+
/** Read the payment stored for the receipt page. `null` when nothing is stored. */
|
|
4
|
+
export async function retrieveFormSubmissionResult() {
|
|
5
|
+
return await utilsService.getLocalForageItem(PAYMENT_SUBMISSION_RESULT_KEY);
|
|
6
|
+
}
|
|
7
|
+
/** Store a payment so the receipt page can verify it after the provider redirects back. */
|
|
8
|
+
export async function rememberPaymentSubmissionResult(formSubmissionResult) {
|
|
9
|
+
await utilsService.setLocalForageItem(PAYMENT_SUBMISSION_RESULT_KEY, formSubmissionResult);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=payment-submission-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-submission-result.js","sourceRoot":"","sources":["../../../src/apps/services/payment-submission-result.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,SAAS,CAAA;AAGlC,MAAM,6BAA6B,GAAG,2BAA2B,CAAA;AAEjE,mFAAmF;AACnF,MAAM,CAAC,KAAK,UAAU,4BAA4B;IAChD,OAAO,MAAM,YAAY,CAAC,kBAAkB,CAC1C,6BAA6B,CAC9B,CAAA;AACH,CAAC;AAED,2FAA2F;AAC3F,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,oBAA0C;IAE1C,MAAM,YAAY,CAAC,kBAAkB,CACnC,6BAA6B,EAC7B,oBAAoB,CACrB,CAAA;AACH,CAAC","sourcesContent":["import utilsService from './utils'\r\nimport { FormSubmissionResult } from '../types/submissions'\r\n\r\nconst PAYMENT_SUBMISSION_RESULT_KEY = 'PAYMENT_SUBMISSION_RESULT'\r\n\r\n/** Read the payment stored for the receipt page. `null` when nothing is stored. */\r\nexport async function retrieveFormSubmissionResult(): Promise<FormSubmissionResult | null> {\r\n return await utilsService.getLocalForageItem<FormSubmissionResult | null>(\r\n PAYMENT_SUBMISSION_RESULT_KEY,\r\n )\r\n}\r\n\r\n/** Store a payment so the receipt page can verify it after the provider redirects back. */\r\nexport async function rememberPaymentSubmissionResult(\r\n formSubmissionResult: FormSubmissionResult,\r\n): Promise<void> {\r\n await utilsService.setLocalForageItem(\r\n PAYMENT_SUBMISSION_RESULT_KEY,\r\n formSubmissionResult,\r\n )\r\n}\r\n"]}
|
|
@@ -2,6 +2,7 @@ import { isOffline } from './offline-service';
|
|
|
2
2
|
import { getFormsKeyId, isLoggedIn } from './auth-service';
|
|
3
3
|
import { registerPendingQueueListener, getPendingQueueSubmissions, updatePendingQueueSubmission, cancelEditingPendingQueueSubmission, deletePendingQueueSubmission, editPendingQueueSubmission, registerPendingQueueAttachmentProgressListener, registerPendingQueueProgressListener, executePendingQueueProgressListeners, removePendingQueueSubmission, } from './services/pending-queue';
|
|
4
4
|
import replaceInjectablesWithSubmissionValues from './services/replaceInjectablesWithSubmissionValues';
|
|
5
|
+
import { getFormSubmissionPaymentHandoff } from './services/payment-handoff';
|
|
5
6
|
import Sentry from './Sentry';
|
|
6
7
|
import prepareSubmissionData from './services/prepareSubmissionData';
|
|
7
8
|
import submitForm from './services/submit';
|
|
@@ -343,7 +344,7 @@ async function executePostSubmissionAction(submissionResult, { onRedirectToRelat
|
|
|
343
344
|
}
|
|
344
345
|
else if (submissionResult.payment) {
|
|
345
346
|
postSubmissionAction = 'URL';
|
|
346
|
-
redirectUrl = submissionResult
|
|
347
|
+
redirectUrl = getFormSubmissionPaymentHandoff(submissionResult);
|
|
347
348
|
}
|
|
348
349
|
else if (submissionResult.taskCompletion) {
|
|
349
350
|
postSubmissionAction = 'URL';
|