/** * @Component Name: PayReviewComponent * @Module: Checkout * @Module Functionality : To display the pay and review section * @Creation Date: August 12,2017 * @Author: sbaireddy * @Version: 1.0 */ import { Component, ViewChild, Input, OnInit, OnDestroy } from '@angular/core'; import { NgForm } from '@angular/forms'; import { Router } from '@angular/router'; import * as Constants from '../../shared/constants' import Utils from '../../shared/utils'; import CartUtils from '../../shared/cart.utils'; import CheckoutUtils from '../../shared/checkout.utils'; import { User } from '../../shared/modal/user'; import { Cart } from '../../shared/modal/cart'; import { Customer } from '../../shared/modal/customer'; import { IRealtimeInventory, IProductInventory, IDormantProperties, IOrderBlock } from '../../shared/modal/common'; import { SharedService } from '../../shared/shared.service'; import { CartService } from '../../services/cart.service'; import { UserService } from '../../services/user.service'; import { CustomerService } from '../../services/customer.service'; import { CheckoutService } from '../../services/checkout.service'; import { LookupService } from '../../services/lookup.service'; @Component({ selector: 'pay-review-cmp', moduleId: module.id, templateUrl: 'pay-review.component.html', styleUrls: ['pay-review.component.css'] }) export class PayReviewComponent implements OnInit, OnDestroy { private COMPONENT_NAME: string = 'PayReviewComponent'; storeId: number; // update storeid reviewModel: any = {}; paymentModel: any = {}; paymentForm: NgForm; otpAuthForm: NgForm; serviceAgreement: string; readServiceAgreement: boolean = false; editEmailAdress: boolean = true; emailAddress: string; reviewed: boolean = false; user: User; cart: any; customer: Customer; isFinanceOrder: boolean = false; autoPayIndicator: boolean = false; isAALOrder: boolean = false; isExchangeOrder: boolean = false; KarmaTestResult: any = {}; realTimeInventory: IRealtimeInventory; @ViewChild('outOfStockModel') outOfStockModel: any; @ViewChild('preorderModel') preorderModel: any; @ViewChild('backOrderModel') backOrderModel: any; @ViewChild('fraudRejectModel') fraudRejectModel: any; @ViewChild('fraudReviewModel') fraudReviewModel: any; @ViewChild('actFailureModel') actFailureModel: any; ccAuthCounter: number = 0; returnCart: Cart; showFraudReviewModel: boolean = false; showFraudRejectModel: boolean = false; showActFailureModel: boolean = false; errorMessage: string; hasActLineLevelerror: boolean = false; actErrorMessage: string; dormantProperties: IDormantProperties; authorizedUserSelector: String; auFirstName: String; auLastName: String; brpAuIndicator: String; constructor( public router: Router, public sharedService: SharedService, public cartService: CartService, public userService: UserService, public customerService: CustomerService, public checkoutService: CheckoutService, public lookupService: LookupService) { } /** * This function is used to initialize the directive/component after Angular * first displays the data-bound properties.It is invoked only once when the * directive is instantiated.Here it is initializing cart information * @return {void} */ ngOnInit(): void { const METHOD_NAME: string = 'ngOnInit()'; this.sharedService.updateErrorMessage(null); this.reviewModel.language = Constants.ENGLISH; this.sharedService.storeId.subscribe((val: number) => { this.storeId = val; }); this.dormantProperties = this.sharedService.getDormantProperties(); this.checkoutService.setCustomerInfo(null); // clearing the customer info this.user = this.userService.getUser(); this.cart = this.cartService.getCart(); this.errorMessage = this.sharedService.showErrorDownPaymentAdjusted(this.cart.isDownPaymentAdjusted); if (this.cart && this.cart.packages) { // clearing order details from local storage this.sharedService.showSpinner(true); // spinner this.cartService.getCartSummary(this.storeId, this.cart.orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.cart = Object.assign(this.cart, result); if (this.cart && this.cart.paymentInfo && this.cart.paymentInfo.ccAuthCounter) { this.ccAuthCounter = this.cart.paymentInfo.ccAuthCounter; } // incase of browser refresh when there is a fraud review case if (this.cart.status === Constants.ORDER_STATUS_P2) { this.showFraudReviewModel = true; // incase of browser refresh when there is a fraud review case if (CartUtils.hasTaxCalculated(this.cart)) { this.cart.taxRate = CartUtils.getTaxRate(this.cart); } } for (const item of this.cart.packages) { if (item) { item.showPackage = false; } } if (this.cart && this.cart.packages && this.cart.packages.length > 0) { this.cart.packages[0].showPackage = true; } this.isFinanceOrder = CartUtils.isFinanceOrder(this.cart); (this.isFinanceOrder && !this.cart.financeInfo) ? this.showOrderFinance() : ''; if(this.cart.status != Constants.ORDER_STATUS_P && this.cart.status != Constants.ORDER_STATUS_P20 ) { this.sharedService.showErrorMessage('_ERR_ORDER_SUBMIT_' + this.cart.status, false); } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error) }); // getting the customer information this.getCustomerProfile(this.cart.orderId); // getting service agreement this.getServiceAgreement(); } } /** * Cleanup just before Angular destroys the directive/component. * Unsubscribe Observables and detach event handlers to avoid memory leaks. * @return {void} */ ngOnDestroy(): void { const METHOD_NAME: string = 'ngOnDestroy()'; this.cart = null; this.user = null; this.reviewModel = null; this.paymentModel = null; this.customer = null; this.KarmaTestResult = null; this.realTimeInventory = null; } resetAUFirstLastName(event: any) { if (event) { this.auFirstName = ''; this.auLastName = ''; } } /** * This function is used to get the customer profile through * getCustomerProfile function of customer service. * @param {number} orderId - order id to refer the order details * @return {void} */ getCustomerProfile(orderId: number): void { const METHOD_NAME: string = 'getCustomerProfile()'; console.log('PayReviewComponent.getCustomerProfile()'); this.sharedService.showSpinner(true); // spinner this.customerService.getCustomerProfile(this.storeId, orderId, null).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.customer = result; if (this.customer.brpAuDetails.length === 1 && this.customer.brpAuDetails !== undefined) { this.authorizedUserSelector = this.customer.brpAuDetails[0].role; } this.brpAuIndicator = this.customer.brpAuIndicator; if (result) { this.isExchangeOrder = (this.cart && this.cart.refType === Constants.REF_TYPE_EXCHANGE) ? true : false; if (!this.isExchangeOrder && result.creditProfile) { this.isAALOrder = result.creditProfile.accountNumber ? true : false; if (this.isAALOrder) { this.paymentArrangement(); } } if (result && !result.subscribers && this.cart.customer && this.cart.customer.subscribers) { result.subscribers = this.cart.customer.subscribers; } } // we are loosing the subscribers list for AAL flow if we dont merge the customer and result this.cart.customer = Object.assign(this.cart.customer, result); // this.cart.customer = result; // for existing customer before entering the card details discount to show. this.paymentModel.enrollAutopay = result.creditProfile.autoPayIndicator; this.reviewModel.equipmentEmail = this.customer.email1; this.cartService.setCart(this.cart); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error) }); } /** * This function is used to get the order finance details. * @param {number} orderId - orderId of the user. * @returns void */ showOrderFinance(): void { const METHOD_NAME: string = 'showOrderFinance()'; console.log('PayReviewComponent.showOrderFinance()>>Start.'); this.sharedService.showSpinner(true); // spinner this.cartService.getCartFinance(this.storeId, this.cart.orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner if (this.cart) { this.cart.financeInfo = result; this.cartService.setCart(this.cart); } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); console.error('error=>' + error) }); } /** * This function is used update the email address with customer information * @return {void} */ updateEmailAddress(): void { const METHOD_NAME: string = 'updateEmailAddress()'; console.log('Updating the customer email address'); if (this.reviewModel.email1) { const billing: any = { addressId: this.customer.addressId, email1: this.reviewModel.email1 }; const inputData: any = { billingAddress: billing }; this.sharedService.showSpinner(true); // spinner this.checkoutService.updateCustomerInfo(this.storeId, this.cart.orderId, inputData).subscribe(result => { this.KarmaTestResult = result; this.sharedService.showSpinner(false); // spinner this.customer.email1 = this.reviewModel.email1; // console.log("Success"); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error); }); } else { this.sharedService.showErrorMessage('_ERR_INVALID_EMAIL', false); } } /** * This function is used to get the service agreement through * getServiceAgreement function of checkout service * @return {void} */ getServiceAgreement(): void { const METHOD_NAME: string = 'getServiceAgreement()'; console.log('PayReviewComponent.getServiceAgreement()'); this.reviewed = false; // on change of Service agreement default the review terms to false always. this.sharedService.showSpinner(true); // spinner this.checkoutService.getServiceAgreement( this.storeId, this.cart.orderId, this.reviewModel.language, this.autoPayIndicator, this.readServiceAgreement ).subscribe(result => { this.KarmaTestResult = result; this.sharedService.showSpinner(false); // spinner if (result.serviceAgreement !== 'null') { this.serviceAgreement = result.serviceAgreement; } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error); }); } /** * This function is used update the email address with customer information * @return {void} */ paymentArrangement(): void { const METHOD_NAME: string = 'paymentArrangement()'; console.log('Payment Arrangement for AAL customer'); const inputData: any = { orderId: this.cart.orderId, billingAccountId: this.customer.creditProfile.accountNumber }; this.sharedService.showSpinner(true); // spinner this.customerService.paymentArrangement(this.storeId, this.cart.orderId, inputData).subscribe(result => { this.KarmaTestResult = result; this.sharedService.showSpinner(false); // spinner }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error); }); } /** * This function is used to check the real time inventory throught * realTimeInventory function of checkout service to display the item status asIN/OUT stock, PRE/BACK orders. * @return {void} */ checkRealtimeInventory(): void { const METHOD_NAME: string = 'checkRealtimeInventory()'; this.sharedService.showSpinner(true); // spinner this.checkoutService.realTimeInventory(this.storeId, this.cart.orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.realTimeInventory = result; this.cart.realTimeInventory = result; if (CheckoutUtils.hasOutOfStockItems(result.products)) { this.outOfStockModel.show(); } else if (CheckoutUtils.hasPreorderItems(result.products)) { this.preorderModel.show(); } else if (CheckoutUtils.hasBackorderItems(result.products)) { this.backOrderModel.show(); } else { this.submitOrder(this.cart.orderId); } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error); }); } /** * This function is used to place the order from pay and review page * via submitOrder function of chekcout service.And then navigate to order confirmation page. * @param {number} orderId - order id to refer the order details * @return {void} */ submitOrder(orderId: number): void { const METHOD_NAME: string = 'submitOrder()'; this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Placing the order from Pay and Review'); let inputData: any = CheckoutUtils.createOrderSubmitInput(this.cart, this.paymentModel); inputData.language = this.reviewModel.language; // this.isExchangeOrder = true; // inputData = (this.isExchangeOrder) ? Object.assign(inputData, this.sharedService.notificationModel) : inputData; inputData.auRole = this.authorizedUserSelector; inputData.auFirstName = this.auFirstName; inputData.auLastName = this.auLastName; if (this.isFinanceOrder && this.reviewModel.equipmentEmail) { inputData.eSignEmailAddr = this.reviewModel.equipmentEmail; } this.returnCart = this.cartService.getReturnCart(); let modifiedCustomerCart: any; if (this.returnCart) { inputData = Object.assign(inputData, this.sharedService.notificationModel); let customer: any = (this.lookupService.getOrder()) ? this.lookupService.getOrder().customer : (this.cartService.getCart()) ? this.cartService.getCart().customer : ''; if (customer) { this.returnCart.customer = customer; modifiedCustomerCart = this.returnCart; modifiedCustomerCart['customerInfo'] = modifiedCustomerCart['customer']; modifiedCustomerCart.originalOrderId = this.lookupService.getOrder().fullOrderId; delete modifiedCustomerCart['customer']; if(modifiedCustomerCart.customerInfo.email2) inputData.returnTrackingEmail = modifiedCustomerCart.customerInfo.email2; else inputData.returnTrackingEmail = modifiedCustomerCart.customerInfo.email1; modifiedCustomerCart.languagePreference = inputData.languagePref; } this.cartService.createResendShippingLabel(this.storeId, this.cart.orderId, modifiedCustomerCart).subscribe(result => { if (this.returnCart && result && result.shippingInfo && result.shippingInfo.returnTracking) { inputData.returnShippingTracking = result.shippingInfo.returnTracking // this.returnCart = modifiedCustomerCart; this.sharedService.generateMemo(this.storeId, modifiedCustomerCart, result.shippingInfo.returnTracking, null); } this.submitFinalOrder(inputData); // calling the submit order after getting the return tracking number its required for tracking number in exchange order. }, error => { this.submitFinalOrder(inputData); // calling the submit order if return shipping label fails in exchange order. }); } else { this.submitFinalOrder(inputData); // calling the submit order if its not a exchange order. } } /** * This function is used to place the order from pay and review page * via submitOrder function of chekcout service.And then navigate to order confirmation page. * @param {number} orderId - order id to refer the order details * @return {void} */ submitFinalOrder(inputData): void { const METHOD_NAME: string = 'submitOrder()'; this.sharedService.addLogging(this.COMPONENT_NAME, METHOD_NAME, 'Placing the order from Pay and Review'); let isAALOrder: boolean = CartUtils.isAALOrder(this.cart); this.sharedService.showSpinner(true); // spinner this.checkoutService.submitOrder(this.storeId, this.cart.orderId, isAALOrder, inputData).subscribe(result => { this.sharedService.showSpinner(false); // spinner if (result.serviceStatus && result.serviceStatus.code === 100) { this.router.navigate(['checkout/confirm']); } else { this.sharedService.showErrorMessage('_ERR_GENERIC', false); } }, error => { this.sharedService.showSpinner(false); // spinner // this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error) this.showBlockMessage(error); // showing error block model }); } /** * @param {any} errors * @returns void */ showBlockMessage(submitError: any): void { if (submitError && submitError.indexOf(Constants.ORDER_SOFT_REJECT) > -1) { // retry with diffrent credit card# this.sharedService.showErrorMessage('_ERR_PAYMENT_CARD_RETRY', false); } else if (submitError && submitError.indexOf(Constants.ORDER_HARD_REJECT) > -1) { // fruad reject case this.fraudRejectModel.show(); this.showFraudRejectModel = true; if (this.isAALOrder) { this.postFraudRejectMemo(); } } else if (submitError && submitError.indexOf(Constants.ORDER_FRAUD_REVIEW) > -1) { // fruad review case this.showFraudReviewModel = true; } else if (submitError && submitError.indexOf(Constants.EIP_DISCLOSURECREATE_ERROR) > -1) { // eip disclosure error this.sharedService.showErrorMessage(submitError, true); } else { // clearing order details from local storage this.sharedService.showSpinner(true); // spinner this.cartService.getCartSummary(this.storeId, this.cart.orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.cart = Object.assign(this.cart, result); // this.cartService.setCart(this.cart); if (this.cart.status === Constants.ORDER_STATUS_P1 || this.cart.status === Constants.ORDER_STATUS_P2 || this.cart.status === Constants.ORDER_STATUS_P3 || this.cart.status === Constants.ORDER_STATUS_P4 || this.cart.status === Constants.ORDER_STATUS_P5 || this.cart.status === Constants.ORDER_STATUS_P6 || this.cart.status === Constants.ORDER_STATUS_P7 || this.cart.status === Constants.ORDER_STATUS_P8 || this.cart.status === Constants.ORDER_STATUS_P9 || this.cart.status === Constants.ORDER_STATUS_P10 || this.cart.status === Constants.ORDER_STATUS_P11 || this.cart.status === Constants.ORDER_STATUS_P12 || this.cart.status === Constants.ORDER_STATUS_P13 || this.cart.status === Constants.ORDER_STATUS_P17 || this.cart.status === Constants.ORDER_STATUS_X) { if (this.cart.status === Constants.ORDER_STATUS_P10) { // order submit queue this.router.navigate(['checkout/confirm']); } else if (this.cart.status === Constants.ORDER_STATUS_P20) {// retry with diffrent credit card# this.sharedService.showErrorMessage('_ERR_PAYMENT_CARD_RETRY', false); } else { if (this.cart.status === Constants.ORDER_STATUS_P2) {// fruad review case this.showFraudReviewModel = true; } else if (this.cart.status === Constants.ORDER_STATUS_P17) { this.showFraudRejectModel = true; if (this.isAALOrder) { this.postFraudRejectMemo(); } } else { this.sharedService.showErrorMessage('_ERR_ORDER_SUBMIT_' + this.cart.status, false); } } } else { this.sharedService.showErrorMessage(submitError, true); } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error) }); } } /** This function is used to create tenetative Ban for customer. * @returns void */ submitByos(orderId: number): void { const METHOD_NAME: string = 'createTentativeBan()'; const creditProfile = this.customer.creditProfile; if (creditProfile.accountNumber || creditProfile.tentativeBAN) { this.finalizeByos(orderId); } else { let inputData: any = { orderId: orderId, altCustomerId: this.customer.altCustomerId, creditType: this.customer.creditType }; this.sharedService.showSpinner(true); // spinner this.customerService.createTentativeBan(this.storeId, inputData).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.customer = result; this.cart.customer = result; this.finalizeByos(orderId); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } } /** * This function is used to submit the Byos and then navigate to confirmation page * @param {number} orderId - order id to refer the order details * @return {void} */ finalizeByos(orderId: number): void { const METHOD_NAME: string = 'submitByos()'; let inputData: any = Object.assign({}, this.cart); inputData.lastModifiedBy = this.user.logonId ? this.user.logonId.toLowerCase() : 'wcsadmin'; inputData['customerInfo'] = inputData.customer; if (inputData.customerInfo && inputData.customerInfo.phone2) { inputData.customerInfo.phone1 = inputData.customerInfo.phone2; } if (inputData.customer) { inputData.customer = null; } if (inputData.orders) { inputData.orders = null; } if (!inputData.dealerCode) { inputData.dealerCode = this.user.dealerCode; inputData.dealerCode = (inputData.dealerCode.length === 8) ? (inputData.dealerCode.substr(1)) : inputData.dealerCode; } // creating dummy shipping address for payment/activation SIM card if (!inputData.shippingInfo) { inputData.shippingInfo = { address: { firstName: this.cart.customer.firstName, middleName: this.cart.customer.middleName, lastName: this.cart.customer.lastName, address1: this.cart.customer.address1, address2: this.cart.customer.address2, city: this.cart.customer.city, state: this.cart.customer.state, zipCode: this.cart.customer.zipCode, phone1: this.cart.customer.phone1 } }; } inputData.paymentInfo = CheckoutUtils.createOrderSubmitByosInput(this.cart, this.paymentModel); // invoking the checkout BYOS submmit service let isAALOrder: boolean = CartUtils.isAALOrder(this.cart); this.sharedService.showSpinner(true); // spinner this.checkoutService.submitByos(this.storeId, orderId,isAALOrder, inputData).subscribe(result => { this.sharedService.showSpinner(false); // spinner if (result) { if (result.errorCode && result.errorCode === 2003) { this.ccAuthCounter += 1; inputData = { paymentInfo: { ccAuthCounter: this.ccAuthCounter }, orderNoteInfo: [{ subject: 'Card Validation failed', description: result.errorMessage }], lastModifiedBy: this.user.logonId.toLowerCase() } if (this.ccAuthCounter === 3) { inputData.status = 'X' }; } else { inputData = Object.assign({}, result); // capturing order block info if (result.orderBlockInfo && result.orderBlockInfo.length > 0) { this.hasActLineLevelerror = Utils.hasActLineLevelError(result.orderBlockInfo[0].description); if (result.orderBlockInfo[0].reasonCode === '6021' && result.orderBlockInfo[0].description) { this.actErrorMessage = Utils.formatActErrorMessage(result.orderBlockInfo[0].description); } } } this.sharedService.showSpinner(true); // spinner this.cartService.updateCartDetails(this.storeId, this.cart.orderId, inputData).subscribe(updateCartDetailsResult => { this.sharedService.showSpinner(false); // spinner if (this.cart) {// updating the status/payment info this.cart.status = updateCartDetailsResult.status; if (updateCartDetailsResult && updateCartDetailsResult.paymentInfo) { this.cart.paymentInfo = updateCartDetailsResult.paymentInfo; } this.cartService.setCart(this.cart); } // this.cart = Object.assign({}, this.cart, updateCartDetailsResult); // this.cartService.setCart(this.cart); if (this.cart.status === Constants.ORDER_STATUS_P14 || this.cart.status === Constants.ORDER_STATUS_P16 || this.cart.status === Constants.ORDER_STATUS_P17 || this.cart.status === Constants.ORDER_STATUS_P18 || this.cart.status === Constants.ORDER_STATUS_P19 || this.cart.status === Constants.ORDER_STATUS_X) { if (this.cart.status === Constants.ORDER_STATUS_X) { // fruad reject case this.fraudRejectModel.show(); if (this.isAALOrder) { this.postFraudRejectMemo(); } } else { this.sharedService.showErrorMessage('_ERR_ORDER_SUBMIT_' + this.cart.status, false); } } else if (this.cart.status === Constants.ORDER_STATUS_P15) { this.showActFailureModel = true; } else if (this.cart.status === Constants.ORDER_STATUS_P20) { this.sharedService.showErrorMessage('_ERR_PAYMENT_CARD_RETRY', false); } else { if (this.cart.status === Constants.ORDER_STATUS_C) { this.router.navigate(['checkout/confirm']); } else { this.sharedService.showErrorMessage('_ERR_GENERIC', false); } } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, null); console.error('error=>' + error); }); } else { this.sharedService.showErrorMessage('_ERR_PAYMENT_SERVICE', false); } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); }); } /** * This function is used to validate all the information in pay and review page * before submitting the order, It will display error messages if anything found. * @return {void} */ finalizeOrder(): void { const METHOD_NAME: string = 'finalizeOrder()'; this.cart = this.cartService.getCart(); if (this.checkForReadServiceAgreement()) { if (this.cart.isShopifyOrder) { if (this.reviewed) { this.checkRealtimeInventory(); } else { this.sharedService.showErrorMessage('_REVIEW_TERMS_CONDITIONS', false); } } else if (this.reviewed && CheckoutUtils.readyForSubmit(this.cart, this.paymentModel)) { if (CheckoutUtils.isBYOSOnlyOrder(this.cart)) { this.submitByos(this.cart.orderId); } else if (!this.isExchangeOrder && !this.cart.customer.otpVerified && this.cart.customer.creditProfile.accountNumber) { this.sharedService.showErrorMessage('_MISSING_OTP_VERIFICATION', false); } else if (this.paymentModel.securityCode && this.paymentModel.securityCode.length !== Number(this.paymentModel.securityCodeLength)) { this.sharedService.showErrorMessage('_ERR_CVV_INVALID', false); } else if (this.checkForEIPDeviceEmail()) { if ((!this.paymentModel.sameAsBilling) && (this.paymentModel.address1 === '' || this.paymentModel.address1 === undefined || this.paymentModel.city === '' || this.paymentModel.city === undefined || this.paymentModel.zipCode === '' || this.paymentModel.zipCode === undefined || this.paymentModel.state === '')) { this.sharedService.showErrorMessage('_MISSING_ADDRESS_FIELDS', false); } else if (CheckoutUtils.readyForSubmit(this.cart, this.paymentModel)) { this.checkRealtimeInventory(); } } } else { if (!this.reviewed) { this.sharedService.showErrorMessage('_REVIEW_TERMS_CONDITIONS', false); } else { if (!this.paymentModel.cardNumber || !this.paymentModel.expiration || !this.paymentModel.securityCode) { if (!this.isExchangeOrder && !this.cart.customer.otpVerified && this.cart.customer.creditProfile.accountNumber) { this.sharedService.showErrorMessage('_MISSING_OTP_VERIFICATION', false); } else { this.sharedService.showErrorMessage('_MISSING_CARD_DETAILS', false); } } else { this.sharedService.showErrorMessage('_MISSING_PAYMENT_DETAILS', false); } } } } } /** * This function is used to post SAMSON memo for fraud reject * @return {boolean} */ postFraudRejectMemo(): void { const METHOD_NAME: string = 'writeFraudRejectMemo()'; // writting memo into samson let inputData: any = { orderId: this.cart.fullOrderId }; inputData.accountNumber = this.customer.creditProfile.accountNumber; inputData.dealerCode = this.cart.dealerCode ? this.cart.dealerCode : this.user.dealerCode; if (inputData.dealerCode && inputData.dealerCode.length > 7) { inputData.dealerCode = inputData.dealerCode.substring(1); } let memoText: string = Constants.SAMSON_MEMO_TEXT_FRAUD_REJECT; inputData.memoText = memoText.replace('', this.cart.fullOrderId); inputData.memoCode = Constants.SAMSON_MEMO_CODE_FRAUD_REJECT; inputData.memoCodeValue = Constants.SAMSON_MEMO_CODE_TEXT_FRAUD_REJECT; inputData.orderCreateDate = this.cart.createdByDate; this.sharedService.showSpinner(true); // spinner this.customerService.generateMemo(this.storeId, this.cart.orderId, inputData).subscribe(result => { this.sharedService.showSpinner(false); // spinner console.log('Memo has created successfully in billing system.'); }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage('_ERR_CREATE_SAMSON_MEMO', false); // console.error('error=>' + error); }); } /** * This function is used to validate EIP email address * @return {boolean} */ checkForEIPDeviceEmail(): boolean { const METHOD_NAME: string = 'checkForEIPDeviceEmail()'; let email: boolean = !this.isFinanceOrder ? true : false; if (this.isFinanceOrder) { if (this.reviewModel.equipmentEmail && !this.reviewModel.confirmemail) { this.reviewModel.confirmemail = this.reviewModel.equipmentEmail; } if (this.reviewModel.equipmentEmail && this.reviewModel.confirmemail) { if (this.reviewModel.equipmentEmail.toUpperCase() === this.reviewModel.confirmemail.toUpperCase()) { this.paymentModel.eSignEmailAddr = this.reviewModel.equipmentEmail; this.cart.esigEmail = this.reviewModel.equipmentEmail; email = true; } else { this.sharedService.showErrorMessage('_ERR_EQUIPMENT_EMAILS_ARE_NOT_SAME', false); } } else { this.sharedService.showErrorMessage('_ERR_GENERIC', false); } } return email; } /** * This function is used to confirm the user is read the agreement * @return {boolean} */ checkForReadServiceAgreement(): boolean { const METHOD_NAME: string = 'checkForReadServiceAgreement()'; if (!this.readServiceAgreement) { if (!this.customer.email1) { this.sharedService.showErrorMessage('_MISSING_REVIEW_EMAIL', false); return false; } } return true; } /** * This function is used to update the service agreement based on the autopay enrollment * @param {any} paymentModel - Contains the boolean value for autopay enrollment * @return {void} */ cardDetailChange(paymentModel: any): void { const METHOD_NAME: string = 'cardDetailChange()'; this.paymentModel = paymentModel; if (this.autoPayIndicator !== paymentModel.enrollAutopay) { this.autoPayIndicator = paymentModel.enrollAutopay; this.getServiceAgreement(); } } /** * This function is returning a boolean value for displaying the product * @param {IProductInventory} product - Contains the product information * @return {boolean} */ canDisplayProduct(product: IProductInventory): boolean { const METHOD_NAME: string = 'canDisplayProduct()'; return CheckoutUtils.canDisplayProduct(this.cart, product); } /** * This function is used to get the product name from the package * @param {string} mfPartNumber - Contains the product mfpartnumber * @return {string} */ getProductName(mfPartNumber: string): string { const METHOD_NAME: string = 'getProductName()'; let productName: string = ''; if (this.cart && this.cart.packages) { for (const packagee of this.cart.packages) { if (packagee.device && packagee.device.deviceSKU === mfPartNumber) { productName = packagee.device.manufacturer + ' ' + packagee.device.name; break; } if (packagee.accessories) { for (const accessory of packagee.accessories) { if (accessory.accessorySKU === mfPartNumber) { productName = accessory.manufacturer + ' ' + accessory.name; break; } } } } } return productName; } /** * This function is used to proceed order submit * @return {void} */ proceedForSubmit(): void { const METHOD_NAME: string = 'proceedForSubmit()'; this.submitOrder(this.cart.orderId); } /** * This function is used to resubmitting order again * @return {void} */ resubmitOrder(): void { this.showFraudReviewModel = false; this.fraudReviewModel.hide(); this.sharedService.showSpinner(true); // spinner this.cartService.getCartSummary(this.storeId, this.cart.orderId).subscribe(result => { this.sharedService.showSpinner(false); // spinner this.cart = Object.assign(this.cart, result); if (this.cart.status === Constants.ORDER_STATUS_C || this.cart.status === Constants.ORDER_STATUS_S || this.cart.status === Constants.ORDER_STATUS_P6 || this.cart.status === Constants.ORDER_STATUS_P10) { this.router.navigate(['checkout/confirm']); } else if (this.cart.status === Constants.ORDER_STATUS_X) { this.fraudRejectModel.show(); } else { this.submitOrder(this.cart.orderId); } }, error => { this.sharedService.showSpinner(false); // spinner this.sharedService.showErrorMessage(error, true); // console.error('error=>' + error) }); } /** * @returns void */ startNewOrder(): void { this.showFraudReviewModel = false; this.showFraudRejectModel = false; this.showActFailureModel = false; this.fraudRejectModel.hide(); this.fraudReviewModel.hide(); this.sharedService.showClearAll(true); this.sharedService.setAppDefault(); this.sharedService.clearSessionStorage(false); // this.sharedService.showMinicart(this.showMinicart =! this.showMinicart); this.router.navigate(['home/search']); } /** * @returns void */ redirectToCoverage(): void { this.fraudRejectModel.hide(); this.sharedService.showClearAll(true); this.sharedService.setAppDefault(); this.sharedService.clearSessionStorage(false); // this.sharedService.showMinicart(this.showMinicart =! this.showMinicart); this.router.navigate(['/home/coverage']); } get canDisableSubmit(): boolean { const METHOD_NAME: string = 'canDisableSubmit()'; if ((this.paymentForm && !this.paymentForm.valid) || (this.otpAuthForm && !this.otpAuthForm.valid) || !this.reviewed || (this.isFinanceOrder && this.authorizedUserSelector === undefined && this.brpAuIndicator ==='AU') || !(this.cart && (this.cart.status === 'P' || this.cart.status === 'P20'))) { return true; } return false; } }