diff --git a/strr-base-web/app/composables/useNavigate.ts b/strr-base-web/app/composables/useNavigate.ts index 97397c02..1aa63f2f 100644 --- a/strr-base-web/app/composables/useNavigate.ts +++ b/strr-base-web/app/composables/useNavigate.ts @@ -1,5 +1,8 @@ export const useNavigate = () => { const accountStore = useConnectAccountStore() + const localePath = useLocalePath() + const config = useRuntimeConfig().public + function redirect (url: string, params?: { [key: string]: string }, target = '_self') { // get account id and set in params const redirectURL = new URL(url) @@ -14,5 +17,12 @@ export const useNavigate = () => { window.open(redirectURL, target) } - return { redirect } + async function handlePaymentRedirect (paymentToken: number, redirectPath: string): Promise { + const returnUrl = encodeURIComponent(window.location.origin + localePath(redirectPath)) + const payUrl = config.paymentPortalUrl + paymentToken + '/' + returnUrl + + await navigateTo(payUrl, { external: true }) + } + + return { redirect, handlePaymentRedirect } } diff --git a/strr-strata-web/app/pages/application.vue b/strr-strata-web/app/pages/application.vue index c601e6c1..fd29376f 100644 --- a/strr-strata-web/app/pages/application.vue +++ b/strr-strata-web/app/pages/application.vue @@ -4,6 +4,7 @@ import { ConnectStepper, FormReviewConfirm } from '#components' const { t } = useI18n() const localePath = useLocalePath() const strrModal = useStrrModals() +const { handlePaymentRedirect } = useNavigate() const { validateContact } = useStrrContactStore() const { validateStrataBusiness } = useStrrStrataBusinessStore() @@ -112,9 +113,12 @@ const handleStrataSubmit = async () => { // if all steps valid, submit form with store function if (isApplicationValid) { - const response = await submitStrataApplication() - if (response) { - return navigateTo(localePath(`/strata-hotel/dashboard/${response.header.applicationNumber}`)) + const { paymentToken, filingId, applicationStatus } = await submitStrataApplication() + const redirectPath = `/strata-hotel/dashboard/${filingId}` + if (applicationStatus === ApplicationStatus.PAID) { + await navigateTo(localePath(redirectPath)) + } else { + handlePaymentRedirect(paymentToken, redirectPath) } } else { stepperRef.value?.buttonRefs[activeStepIndex.value]?.focus() // move focus to stepper on form validation errors diff --git a/strr-strata-web/app/stores/strataApplication.ts b/strr-strata-web/app/stores/strataApplication.ts index 0ffc689f..df2a59d9 100644 --- a/strr-strata-web/app/stores/strataApplication.ts +++ b/strr-strata-web/app/stores/strataApplication.ts @@ -71,7 +71,13 @@ export const useStrrStrataApplicationStore = defineStore('strr/strataApplication console.info('submitting application: ', body) - return await postApplication(body) + const res = await postApplication(body) as StrataApplicationResp + + const paymentToken = res.header.paymentToken + const filingId = res.header.applicationNumber + const applicationStatus = res.header.status + + return { paymentToken, filingId, applicationStatus } } return {