From 6fec862fbf2671a0c49e9861a0c653e75352bb55 Mon Sep 17 00:00:00 2001 From: CarlNation Date: Mon, 15 Jul 2024 10:21:36 -0400 Subject: [PATCH] CSR-2130 flag applePay for backend CSR-2130 flag applePay for backend --- src/constants/payment-method-constants.js | 1 + .../payment-pia-return/payment-pia-return.vue | 55 ++++++++++++------- src/layouts/payment/payment.vue | 34 +++++++++++- src/store/index.js | 1 + 4 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/constants/payment-method-constants.js b/src/constants/payment-method-constants.js index 8e01c2794..4f4c83e1a 100644 --- a/src/constants/payment-method-constants.js +++ b/src/constants/payment-method-constants.js @@ -6,4 +6,5 @@ export const paymentMethods = { AFTERPAY: "Afterpay", PAY_NOW: "PayNow", INSURANCE: "Insurance", + APPLE_PAY: "ApplePay", }; diff --git a/src/layouts/payment-pia-return/payment-pia-return.vue b/src/layouts/payment-pia-return/payment-pia-return.vue index 490405595..3d5231e36 100644 --- a/src/layouts/payment-pia-return/payment-pia-return.vue +++ b/src/layouts/payment-pia-return/payment-pia-return.vue @@ -26,6 +26,7 @@ export default { console.log("Error during payment: " + piaError); const paymentPageNavScenario = store.getters.order.payment.piaType === paymentMethods.CREDIT_CARD || + store.getters.order.payment.piaType === paymentMethods.APPLE_PAY || store.getters.order.payment.piaType === paymentMethods.AFTERPAY; if (paymentPageNavScenario) { this.$router.navigateWithoutSaving( @@ -45,13 +46,41 @@ export default { ); } } else { - const card_expirationMonth = getQuerystringParameter( - queryStrings.CARD_EXPIRATION_MONTH - ); - if (card_expirationMonth) { - await this.processCreditCardResponse(); - } else { - await this.processPaypalResponse(); + switch (store.getters.order.payment.piaType) { + case paymentMethods.CREDIT_CARD: + case paymentMethods.APPLE_PAY: + case paymentMethods.AFTERPAY: + await this.processCreditCardResponse(); + break; + case paymentMethods.PAYPAL: + await this.processPaypalResponse(); + break; + default: { + // If we're here, the payment-method did not get properly set in + // payment.vue method handleIFrameContentWindowMessage, we will look and see if + // if we can default it to credit card. The payment method type is most likely still + // set to PayNow originally set in payment-method.vue + const lastFour = getQuerystringParameter(queryStrings.LAST_FOUR); + if (lastFour) { + console.log(new Date() + ": Payment method credit card selected by default"); + this.dispatchStoreAction( + storeActions.SAVE_PAYMENT_METHOD_CHOICE, + paymentMethods.CREDIT_CARD, + false + ); + await this.processCreditCardResponse(); + } + else { + var msg = "Unknown Pia type: " + store.getters.order.payment.piaType; + console.log(msg); + this.$router.navigateWithoutSaving( + this.navigationScenarios.PIA_ERROR, + this.$route, + {}, + { [routerParams.DISPLAY_PIA_ALERT]: true } + ); + } + } } } }, @@ -60,12 +89,6 @@ export default { return true; }, async processPaypalResponse() { - await this.dispatchStoreAction( - storeActions.SAVE_PAYMENT_METHOD_CHOICE, - paymentMethods.PAYPAL, - false - ); - const token = getQuerystringParameter(queryStrings.TOKEN); const payerId = getQuerystringParameter(queryStrings.PAYERID); @@ -79,12 +102,6 @@ export default { await this.saveAndSubmitWorkOrder(); }, async processCreditCardResponse() { - await this.dispatchStoreAction( - storeActions.SAVE_PAYMENT_METHOD_CHOICE, - paymentMethods.CREDIT_CARD, - false - ); - const subscriptionID = getQuerystringParameter(queryStrings.SUBSCRIPTIONID); const referralSeqNum = getQuerystringParameter(queryStrings.REFERRAL_SEQ_NUM); diff --git a/src/layouts/payment/payment.vue b/src/layouts/payment/payment.vue index 2d596a8b2..14cc738d9 100644 --- a/src/layouts/payment/payment.vue +++ b/src/layouts/payment/payment.vue @@ -669,12 +669,15 @@ export default { if (iframe.contentWindow) { if (isApplePayAvailable) { iframe.contentWindow.postMessage("hybrid-with-applepay", "*"); + console.log(new Date() + ": Sent applepay"); } if (this.paymentType == "cc") { iframe.contentWindow.postMessage("CreditCardChosen", "*"); + console.log(new Date() + ": Sent creditcard"); } else if (this.paymentType == "ap") { iframe.contentWindow.postMessage("afterpay", "*"); + console.log(new Date() + ": Sent afterpay"); } } }; @@ -698,10 +701,37 @@ export default { this.backButtonAction(); } if (event.data.indexOf("creditCardSubmit") > -1) { + console.log(new Date() + ": Payment method credit card selected"); + this.dispatchStoreAction( + storeActions.SAVE_PAYMENT_METHOD_CHOICE, + paymentMethods.CREDIT_CARD, + false + ); this.setUIBlock(true); } - if (event.data.indexOf("hybrid") > -1) { - this.setUIBlock(true); + if (event.data.indexOf("afterpayPaymentReceived") > -1) { + console.log(new Date() + ": Payment method afterpay selected"); + this.dispatchStoreAction( + storeActions.SAVE_PAYMENT_METHOD_CHOICE, + paymentMethods.AFTERPAY, + false + ); + } + if (event.data.indexOf("applepayOpened") > -1) { + console.log(new Date() + ": Payment method applepay selected"); + this.dispatchStoreAction( + storeActions.SAVE_PAYMENT_METHOD_CHOICE, + paymentMethods.APPLE_PAY, + false + ); + } + if (event.data.indexOf("showLoaderForPaypal") > -1) { + console.log(new Date() + ": Payment method paypal selected"); + this.dispatchStoreAction( + storeActions.SAVE_PAYMENT_METHOD_CHOICE, + paymentMethods.PAYPAL, + false + ); } } }, diff --git a/src/store/index.js b/src/store/index.js index c449a61c5..5a8782ccd 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1778,6 +1778,7 @@ export const actions = { order.payment.piaType == paymentMethods.CREDIT_CARD ? true : false, isPaypal: order.payment.piaType == paymentMethods.PAYPAL ? true : false, isAfterPay: order.payment.piaType == paymentMethods.AFTERPAY ? true : false, + isApplePay: order.payment.piaType == paymentMethods.APPLE_PAY ? true : false, paypalToken: order.payment.paypalToken, nextGenSettledAmount: order.payment.nextGenSettledAmount, ccToken: {