Skip to content

Commit

Permalink
Improve how the routing should be stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hernandez committed Aug 8, 2024
1 parent 0190115 commit 87c0c36
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/classes/liteCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,33 @@ export class LiteCheckout implements LiteCheckoutConstructor {
const result3ds = await this.process3ds.verifyTransactionStatus()
const resultCheckout = await this.resumeCheckout(result3ds)
this.process3ds.setPayload(resultCheckout)
if (resultCheckout && 'is_route_finished' in resultCheckout && 'provider' in resultCheckout && resultCheckout.provider === 'tonder') {
return resultCheckout
}
return this.handle3dsRedirect(resultCheckout)
}

async resumeCheckout(response: any) {
if (["Failed", "Declined", "Cancelled"].includes(response?.status)) {
// Stop the routing process if the transaction is either hard declined or successful
if (response?.decline?.error_type === "Hard") {
return response
}

if (["Success", "Authorized"].includes(response?.transaction_status)) {
return response;
}

if (response) {
const routerItems = {
checkout_id: response.checkout?.id,
checkout_id: response?.checkout?.id,
};
const routerResponse = await this.handleCheckoutRouter(
routerItems
);
return routerResponse
try {
const routerResponse = await this.handleCheckoutRouter(
routerItems
);
return routerResponse
}catch (error){
// throw error
}
return response
}
return response
}

async handle3dsRedirect(response: ErrorResponse | StartCheckoutResponse | false | undefined) {
Expand Down

0 comments on commit 87c0c36

Please sign in to comment.