Skip to content

Commit

Permalink
cc payment redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
deetz99 committed Nov 8, 2024
1 parent f225958 commit 39afb13
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
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

0 comments on commit 39afb13

Please sign in to comment.