Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strata - UI: cc payment redirect #287

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion strr-base-web/app/composables/useNavigate.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -14,5 +17,12 @@ export const useNavigate = () => {
window.open(redirectURL, target)
}

return { redirect }
async function handlePaymentRedirect (paymentToken: number, redirectPath: string): Promise<void> {
const returnUrl = encodeURIComponent(window.location.origin + localePath(redirectPath))
const payUrl = config.paymentPortalUrl + paymentToken + '/' + returnUrl

await navigateTo(payUrl, { external: true })
}

return { redirect, handlePaymentRedirect }
}
10 changes: 7 additions & 3 deletions strr-strata-web/app/pages/application.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion strr-strata-web/app/stores/strataApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ export const useStrrStrataApplicationStore = defineStore('strr/strataApplication

console.info('submitting application: ', body)

return await postApplication<StrataApplicationPayload, StrataApplicationResp>(body)
const res = await postApplication<StrataApplicationPayload, StrataApplicationResp>(body) as StrataApplicationResp

const paymentToken = res.header.paymentToken
const filingId = res.header.applicationNumber
const applicationStatus = res.header.status

return { paymentToken, filingId, applicationStatus }
}

return {
Expand Down