Skip to content

Commit

Permalink
Revert "Revert "23942 - If transaction is already completed jump dire…
Browse files Browse the repository at this point in the history
…ctly to redirect url"" (#3122)
  • Loading branch information
seeker25 authored Oct 24, 2024
1 parent 3df62a8 commit 5f45e93
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
10 changes: 10 additions & 0 deletions auth-web/src/services/payment.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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
}
}
21 changes: 14 additions & 7 deletions auth-web/src/views/pay/PaymentView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -165,7 +167,7 @@ export default class PaymentView extends Vue {
await this.doCreateTransaction()
}
} catch (error) {
this.doHandleError(error)
await this.doHandleError(error)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -238,13 +240,18 @@ 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) {
this.errorMessage = this.$t('payFailedMessage').toString()
throw new Error('Invalid redirect url: ' + this.redirectUrlFixed)
}
this.goToUrl(this.redirectUrlFixed)
} else {
this.errorMessage = this.$t('payFailedMessage').toString()
this.showErrorModal = true
}
}
Expand Down

0 comments on commit 5f45e93

Please sign in to comment.