Handle cancellation and payment errors.

This commit is contained in:
Chloe Herd 2026-01-12 13:26:38 -05:00
parent cc4f65c5ac
commit fa5ff6b58b
2 changed files with 37 additions and 14 deletions

View file

@ -111,7 +111,7 @@ export default {
next(async (vm) => {
vm.setCmsContent(resultMap.cmsContent);
if(hasExistingPiaError) {
if (hasExistingPiaError) {
vm.hasPaymentFailureError = true;
}
});
@ -405,18 +405,32 @@ export default {
console.log(`Result =`);
console.log(result);
const stringToLog = `ADYEN PAYMENT NOT AUTHORIZED. Code = ${result?.resultCode}. Id = ${this.sessionId}`;
const wasPaymentCancelled = result?.resultCode === "Cancelled";
await global.$logger.logError(stringToLog);
if (!wasPaymentCancelled) {
const stringToLog = `ADYEN PAYMENT NOT AUTHORIZED. Code = ${result?.resultCode}. Id = ${this.sessionId}`;
this.hasPaymentFailureError = true;
await global.$logger.logError(stringToLog);
this.hasPaymentFailureError = true;
}
this.dropinComponent?.update();
},
handleError(error) {
const stringToLog = `ADYEN ERROR. Name = ${error.name}. Details = ${error.message}.`;
async handleError(error) {
console.log(error);
global.$logger.logError(stringToLog);
const wasPaymentCancelled = error?.name === "CANCEL";
if (!wasPaymentCancelled) {
const stringToLog = `ADYEN ERROR. Name = ${error.name}. Details = ${error.message}.`;
await global.$logger.logError(stringToLog);
this.hasPaymentFailureError = true;
}
this.dropinComponent?.update();
},
async saveAndSubmitWorkOrder() {

View file

@ -19,7 +19,16 @@ export async function adyenReturnBeforeEnter(to, from) {
try {
result = await finalizeAdyenPayment(sessionId, redirectResult);
} catch (error) {
} catch (unexpectedResult) {
// If user cancelled payment, handle without error message
if (unexpectedResult.code === "Cancelled") {
return {
name: routeData.PAYMENT_ADYEN.name,
replace: true,
};
}
// Otherwise, failure scenario.
// Payment fails, so return user to payment-adyen screen to try again or pay later.
return {
name: routeData.PAYMENT_ADYEN.name,
@ -108,7 +117,7 @@ function finalizeAdyenPayment(sessionId, redirectResult) {
console.log(`Payment failed`);
console.log(result);
reject({
paymentFailure: true,
code: result?.resultCode,
message: "Payment failed from Adyen",
});
},
@ -116,7 +125,7 @@ function finalizeAdyenPayment(sessionId, redirectResult) {
console.log(`Error occured`);
console.log(error);
reject({
paymentFailure: false,
code: "Error",
message: "Error from Adyen",
});
},