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

21397 - Build in a refetch mechanism for PENDING_PAYMENT #766

Merged
merged 7 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "name-request",
"version": "5.5.1",
"version": "5.5.2",
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
"private": true,
"appName": "Name Request UI",
"sbcName": "SBC Common Components",
Expand Down Expand Up @@ -91,4 +91,4 @@
"overrides": {
"webpack": "5.78"
}
}
}
48 changes: 24 additions & 24 deletions src/components/dialogs/payment-complete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
import { Component, Mixins, Watch } from 'vue-property-decorator'
import { Action, Getter } from 'vuex-class'
import PaymentConfirm from '@/components/payment/payment-confirm.vue'
import { NameRequestPayment } from '@/modules/payment/models'

Check failure on line 56 in src/components/dialogs/payment-complete.vue

View workflow job for this annotation

GitHub Actions / namerequest-ci / linting-pnpm (21, 9)

'NameRequestPayment' is defined but never used

Check warning on line 56 in src/components/dialogs/payment-complete.vue

View workflow job for this annotation

GitHub Actions / namerequest-ci / linting-pnpm (21, 9)

'NameRequestPayment' is defined but never used
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
import errorModule from '@/modules/error'

Check failure on line 57 in src/components/dialogs/payment-complete.vue

View workflow job for this annotation

GitHub Actions / namerequest-ci / linting-pnpm (21, 9)

'errorModule' is defined but never used

Check warning on line 57 in src/components/dialogs/payment-complete.vue

View workflow job for this annotation

GitHub Actions / namerequest-ci / linting-pnpm (21, 9)

'errorModule' is defined but never used
import { PaymentStatus, SbcPaymentStatus } from '@/enums'
import { NrState, PaymentStatus, SbcPaymentStatus } from '@/enums'

Check failure on line 58 in src/components/dialogs/payment-complete.vue

View workflow job for this annotation

GitHub Actions / namerequest-ci / linting-pnpm (21, 9)

'PaymentStatus' is defined but never used

Check warning on line 58 in src/components/dialogs/payment-complete.vue

View workflow job for this annotation

GitHub Actions / namerequest-ci / linting-pnpm (21, 9)

'PaymentStatus' is defined but never used

Check failure on line 58 in src/components/dialogs/payment-complete.vue

View workflow job for this annotation

GitHub Actions / namerequest-ci / linting-pnpm (21, 9)

'SbcPaymentStatus' is defined but never used

Check warning on line 58 in src/components/dialogs/payment-complete.vue

View workflow job for this annotation

GitHub Actions / namerequest-ci / linting-pnpm (21, 9)

'SbcPaymentStatus' is defined but never used
import { CommonMixin, PaymentMixin, PaymentSessionMixin } from '@/mixins'
import { ActionBindingIF } from '@/interfaces/store-interfaces'
import { NameChoicesIF } from '@/interfaces'
Expand Down Expand Up @@ -85,6 +85,8 @@

/** Used to show loading state on button. */
loading = false
incompletePaymentRetries = 5
isRetrying = false

/** Whether this modal should be shown (per store property). */
get showModal (): boolean {
Expand All @@ -109,7 +111,20 @@
}

async fetchNr (): Promise<void> {
const nrData = await NamexServices.getNameRequest(true)
let nrData = await NamexServices.getNameRequest(true)
if (nrData.state === NrState.PENDING_PAYMENT && this.incompletePaymentRetries > 0) {
seeker25 marked this conversation as resolved.
Show resolved Hide resolved
this.incompletePaymentRetries--
this.isRetrying = true
setTimeout(async () => {
await this.fetchData()
}, 2000)
// Retry at least once before showing pending payment, this should cover most of the cases.
if (this.incompletePaymentRetries === 4) {
nrData = null
}
} else {
this.isRetrying = false
}
if (nrData) {
await this.loadExistingNameRequest(nrData)
}
Expand All @@ -122,33 +137,18 @@
const { sessionPaymentId, sessionNrId } = this
await this.fetchNr()
await this.fetchPaymentData(sessionPaymentId, +sessionNrId)
sessionStorage.removeItem('payment')
sessionStorage.removeItem('paymentInProgress')
sessionStorage.removeItem('paymentId')
sessionStorage.removeItem('paymentToken')
sessionStorage.removeItem('nrId')
if (!this.isRetrying) {
this.cleanUpSessionStorage()
}
}

cleanUpSessionStorage () {
['payment', 'paymentInProgress', 'paymentId', 'paymentToken', 'nrId'].forEach(key => sessionStorage.removeItem(key))
}

async fetchPaymentData (paymentId: number, nameReqId: number) {
if (nameReqId && paymentId) {
await this.fetchNrPayment(nameReqId, paymentId)
const { paymentStatus, sbcPaymentStatus } = this
if (sbcPaymentStatus === SbcPaymentStatus.COMPLETED && paymentStatus === PaymentStatus.CREATED) {
await this.setCompletePayment(nameReqId, paymentId, this.sessionPaymentAction)
}
}
}

async setCompletePayment (nrId: number, paymentId: number, action: string) {
const result: NameRequestPayment = await NamexServices.completePayment(nrId, paymentId, action)
const paymentSuccess = result?.paymentSuccess

if (paymentSuccess) {
this.$root.$emit('paymentComplete', true)
await this.toggleReceiptModal(true)
} else if (!paymentSuccess && result?.paymentErrors) {
// Setting the errors to state will update any subscribing components, like the main ErrorModal
await errorModule.setAppErrors(result.paymentErrors)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/mixins/payment-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,8 @@ export class PaymentMixin extends Mixins(ActionMixin) {
if (!paymentResponse) throw new Error('Got error from getNameRequestPayment()')

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { payment, sbcPayment = { receipts: [], status_code: '' }, statusCode, completionDate } = paymentResponse
// Note this was broken for a while. It was fixed by adding [0] to the response.
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
const { payment, sbcPayment = { receipts: [], status_code: '' }, statusCode, completionDate } = paymentResponse[0]
seeker25 marked this conversation as resolved.
Show resolved Hide resolved
seeker25 marked this conversation as resolved.
Show resolved Hide resolved

await this.setPayment(payment)
await this.setSbcPayment(sbcPayment)
Expand Down
Loading