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

23942 - If transaction is already completed jump directly to redirect url #3087

Merged
merged 5 commits into from
Oct 23, 2024
Merged
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
4 changes: 2 additions & 2 deletions auth-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion auth-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auth-web",
"version": "2.6.99",
"version": "2.6.100",
"appName": "Auth Web",
"sbcName": "SBC Common Components",
"private": true,
Expand Down
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
}
}
18 changes: 12 additions & 6 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,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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

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
Expand Down
Loading