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 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 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"
}
}
}
2 changes: 1 addition & 1 deletion src/components/advanced-search/advanced-search-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
v-for="(applicant, index) in item.applicants"
:key="`applicant-${index}`"
>
{{ applicant.lastName }}, {{ applicant.firstName }} {{applicant.middleName}}
{{ applicant.lastName }}, {{ applicant.firstName }} {{ applicant.middleName }}
</span>
</td>
<td>
Expand Down
50 changes: 24 additions & 26 deletions src/components/dialogs/payment-complete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
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'
import errorModule from '@/modules/error'
import { PaymentStatus, SbcPaymentStatus } from '@/enums'
import { NrState } from '@/enums'
import { CommonMixin, PaymentMixin, PaymentSessionMixin } from '@/mixins'
import { ActionBindingIF } from '@/interfaces/store-interfaces'
import { NameChoicesIF } from '@/interfaces'
Expand Down Expand Up @@ -85,6 +83,8 @@ export default class PaymentCompleteDialog extends Mixins(

/** 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 +109,20 @@ export default class PaymentCompleteDialog extends Mixins(
}

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 +135,18 @@ export default class PaymentCompleteDialog extends Mixins(
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
2 changes: 0 additions & 2 deletions src/interfaces/store-interfaces/action-interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ActionContext } from 'vuex'

// Interface to define a Vuex Action
export interface ActionIF {
(x: any, y?: any | null): void
Expand Down
4 changes: 3 additions & 1 deletion src/mixins/payment-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,9 @@ 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 is broken the true response should be paymentResponse[0]
// but this is called by many different pathways will need to fix in the future.
const { payment, sbcPayment = { receipts: [], status_code: '' } } = paymentResponse

await this.setPayment(payment)
await this.setSbcPayment(sbcPayment)
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/analyze-pending.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { createLocalVue, mount } from '@vue/test-utils'
import { createLocalVue } from '@vue/test-utils'
import Vuetify from 'vuetify'
import AnalyzePending from '@/components/new-request/analyze-pending.vue'
// import newReqModule from '@/store/new-request-module'

const localVue = createLocalVue()
const vuetify = new Vuetify()

localVue.use(Vuetify)

Expand Down
Loading