diff --git a/auth-web/package-lock.json b/auth-web/package-lock.json index 829a0ee74..28201335e 100644 --- a/auth-web/package-lock.json +++ b/auth-web/package-lock.json @@ -1,12 +1,12 @@ { "name": "auth-web", - "version": "2.6.99", + "version": "2.6.100", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "auth-web", - "version": "2.6.99", + "version": "2.6.100", "dependencies": { "@bcrs-shared-components/base-address": "2.0.3", "@bcrs-shared-components/bread-crumb": "1.0.8", diff --git a/auth-web/package.json b/auth-web/package.json index db56998f4..5770eb2bb 100644 --- a/auth-web/package.json +++ b/auth-web/package.json @@ -1,6 +1,6 @@ { "name": "auth-web", - "version": "2.6.99", + "version": "2.6.100", "appName": "Auth Web", "sbcName": "SBC Common Components", "private": true, diff --git a/auth-web/src/services/payment.services.ts b/auth-web/src/services/payment.services.ts index 21a3caafe..1d1730001 100644 --- a/auth-web/src/services/payment.services.ts +++ b/auth-web/src/services/payment.services.ts @@ -347,4 +347,14 @@ export default class PaymentService { const url = `${ConfigHelper.getPayAPIURL()}/eft-shortnames/${shortNameId}/payment` return axios.post(url, bodyParams) } + + static async isValidRedirectUrl (redirectUrl: string): AxiosPromise { + const body = { + redirectUrl: redirectUrl + } + const url = `${ConfigHelper.getPayAPIURL()}/valid-redirect-url` + // Using post here, easier to deal with urls, without having to deal with encoding / decoding. + const response = await axios.post(url, body) + return response?.data?.isValid + } } diff --git a/auth-web/src/views/pay/PaymentView.vue b/auth-web/src/views/pay/PaymentView.vue index 966b440af..14e073a5f 100644 --- a/auth-web/src/views/pay/PaymentView.vue +++ b/auth-web/src/views/pay/PaymentView.vue @@ -88,6 +88,7 @@ import ConfigHelper from '@/util/config-helper' import { Invoice } from '@/models/invoice' import { OrgPaymentDetails } from '@/models/Organization' import PaymentCard from '@/components/pay/PaymentCard.vue' +import PaymentService from '@/services/payment.services' import SbcSystemError from 'sbc-common-components/src/components/SbcSystemError.vue' import { mapActions } from 'pinia' import { useOrgStore } from '@/stores/org' @@ -137,7 +138,8 @@ export default class PaymentView extends Vue { if (this.isUserSignedIn && !!accountSettings) { // get the invoice and check for OB try { - const invoice: Invoice = await this.getInvoice({ invoiceId: this.paymentId, accountId: accountSettings?.id }) + const invoice = await this.getInvoice({ invoiceId: this.paymentId, accountId: accountSettings?.id }) + if (invoice?.paymentMethod === PaymentTypes.ONLINE_BANKING) { // get account data to show in the UI const paymentDetails: OrgPaymentDetails = await this.getOrgPayments(accountSettings?.id) @@ -165,7 +167,7 @@ export default class PaymentView extends Vue { await this.doCreateTransaction() } } catch (error) { - this.doHandleError(error) + await this.doHandleError(error) } } @@ -201,7 +203,7 @@ export default class PaymentView extends Vue { await this.updateInvoicePaymentMethodAsCreditCard({ paymentId: this.paymentId, accountId: accountSettings?.id }) await this.doCreateTransaction() } catch (error) { - this.doHandleError(error) + await this.doHandleError(error) } } @@ -238,11 +240,15 @@ export default class PaymentView extends Vue { this.goToUrl(this.returnUrl) } - private doHandleError (error) { + async doHandleError (error) { this.showLoading = false this.errorMessage = this.$t('payFailedMessage').toString() - if (error.response.data && error.response.data.type === 'INVALID_TRANSACTION') { - // Transaction is already completed. Show as a modal. + if (error.response.data && ['COMPLETED_PAYMENT', 'INVALID_TRANSACTION'].includes(error.response.data.type)) { + // Skip PAYBC, take directly to the "clients redirect url", this avoids transaction already done error. + const isValid = await PaymentService.isValidRedirectUrl(this.redirectUrlFixed) + if (!isValid) { + throw new Error('Invalid redirect url: ' + this.redirectUrlFixed) + } this.goToUrl(this.redirectUrlFixed) } else { this.showErrorModal = true