Skip to content

Commit

Permalink
fix(sb): handle error if bank order fails during url polling
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoB committed Apr 16, 2021
1 parent 2e9d293 commit 4a2d6ba
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ export default ({
order.extraAttributes.authorisationUrl
) {
return order
} else if (order.state === 'FAILED') {
return order
} else {
throw new Error('retrying to fetch for AuthUrl')
}
Expand Down Expand Up @@ -343,6 +345,18 @@ export default ({
AuthUrlCheck,
data.paymentId
)
if (order.state === 'FAILED') {
yield put(
actions.form.stopSubmit('brokerageTx', {
_error: 'Bank authroization failed, please try again.'
})
)
yield put(
actions.components.brokerage.setDWStep({
dwStep: BankDWStepType.ENTER_AMOUNT
})
)
}
if (
order.extraAttributes &&
'authorisationUrl' in order.extraAttributes &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,5 @@ export const FETCH_LIMITS_SUCCESS = '@EVENT.FETCH_LIMITS_SUCCESS'

export const UPDATE_SDD_TRANSACTION_FINISHED =
'@EVENT.UPDATE_SDD_TRANSACTION_FINISHED'

export const UPDATE_SB_ORDER = '@EVENT.UPDATE_SB_ORDER'
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,10 @@ export const fetchLimitsSuccess = (
export const updateSddTransactionFinished = () => ({
type: AT.UPDATE_SDD_TRANSACTION_FINISHED
})

export const updateSbOrder = (order: SBOrderType) => ({
type: AT.UPDATE_SB_ORDER,
payload: {
order
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ export function simpleBuyReducer(
sddTransactionFinished: true
}
}
case AT.UPDATE_SB_ORDER: {
return {
...state,
order: action.payload.order
}
}
case AT.SET_FIAT_CURRENCY:
return {
...state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ export default ({

if (order.attributes?.authorisationUrl) {
return order
} else if (order.state === 'FAILED') {
return order
} else {
throw new Error('retrying to fetch for AuthUrl')
}
Expand All @@ -440,17 +442,19 @@ export default ({
api.getSBOrder,
orderId
)

if (order.state === 'FINISHED') {
return order
} else if (order.state === 'FAILED') {
return order
} else {
throw new Error('retrying to fetch for FINISHED order')
}
}
const confirmSBOrder = function * (
payload: ReturnType<typeof A.confirmSBOrder>
) {
const { order, paymentMethodId } = payload
const { paymentMethodId } = payload
let { order } = payload
try {
if (!order) throw new Error(NO_ORDER_EXISTS)
yield put(actions.form.startSubmit('sbCheckoutConfirm'))
Expand Down Expand Up @@ -501,9 +505,17 @@ export default ({
OrderConfirmCheck,
confirmedOrder.id
)
// yield put(A.updateSbOrder(order))
}

// order = S.getSBOrder(yield select()) as SBOrderType
// console.log('order', order)
// debugger
yield put(actions.form.stopSubmit('sbCheckoutConfirm'))
// if (order.state === 'FAILED') {
// yield put(A.setStep({ step: 'CHECKOUT_CONFIRM', order }))
// yield put(actions.form.startSubmit('sbCheckoutConfirm'))
// return yield put(actions.form.stopSubmit('sbCheckoutConfirm', { _error: 'Order failed. Please try again.' }))
// }
if (order.paymentType === 'BANK_TRANSFER') {
yield put(A.setStep({ step: 'ORDER_SUMMARY', order: confirmedOrder }))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,13 @@ interface FetchLimitsSuccess {
}
type: typeof AT.FETCH_LIMITS_SUCCESS
}

interface UpdateSbOrder {
payload: {
order: SBOrderType
}
type: typeof AT.UPDATE_SB_ORDER
}
interface UpdateSddTransactionFinished {
type: typeof AT.UPDATE_SDD_TRANSACTION_FINISHED
}
Expand Down Expand Up @@ -552,3 +559,4 @@ export type SimpleBuyActionTypes =
| UpdatePaymentLoadingAction
| UpdatePaymentSuccessAction
| UpdateSddTransactionFinished
| UpdateSbOrder

0 comments on commit 4a2d6ba

Please sign in to comment.