/** * @Name: Checkout Utils * @Creation Date: November 03, 2017 * @Author: sbaireddy * @Version: 1.0 : */ import * as Constants from './constants'; import { Cart } from './modal/cart'; import { IProductInventory, IPackage, IZipMarket } from './modal/common'; /** Deafult Class representing the checkout utils for application. */ export default class CheckoutUtils { private COMPONENT_NAME: string = 'CheckoutUtils'; /** get isAccOnlyOrder */ static isAccOnlyOrder(cart: Cart): boolean { const METHOD_NAME: string = 'isAccOnlyOrder()'; console.log('Getting the isAccOnlyOrder.'); let isAccOnlyOrder: boolean = false; if (cart && cart.packages) { isAccOnlyOrder = true; for (const tempPackage of cart.packages) { if (tempPackage.packageType !== Constants.PACKAGE_TYPE_ACCESSORY) { isAccOnlyOrder = false; } } } return isAccOnlyOrder; } /** get updateUsableShipping */ static updateUsableShipping(usableShipping: any): any { const METHOD_NAME: string = 'updateUsableShipping()'; let shopifyShipMode: any = null; let overnightSelected: boolean = false; for (let shipMode of usableShipping.usableShippingMode) { shipMode.description = shipMode.description.replace(' � ', ' – '); if (shipMode.orderType === 'Shopify') { shopifyShipMode = shipMode; shipMode.defaultShippingEnabled = true; } else if (shipMode.orderType === 'Both' && shipMode.defaultShippingEnabled) { overnightSelected = true; } } if (overnightSelected) { for (const shipMode of usableShipping) { if (shipMode.orderType === 'Shopify') { shipMode.defaultShippingEnabled = false; } } } return usableShipping; } /** get isValidCustomerInfo */ static isValidCustomerInfo(cart: Cart, customerInfo: any): any { const METHOD_NAME: string = 'isValidCustomerInfo()'; console.log('Getting the isValidCustomerInfo.'); let isValidCustomerInfo: any = {}; isValidCustomerInfo.isValid = false; isValidCustomerInfo.section = 'Billing'; if (customerInfo && customerInfo.billingAddress) { const billingAddress: any = customerInfo.billingAddress; if (billingAddress.firstName && billingAddress.lastName && billingAddress.address1 && billingAddress.city && billingAddress.state && billingAddress.zipCode && billingAddress.phone1 && billingAddress.email1) { // isValidCustomerInfo = true; isValidCustomerInfo = this.checkPackageAddress(customerInfo); if (customerInfo.sameAsBilling === false && isValidCustomerInfo) { if (customerInfo.isValidShipping === false) { // check for BYos flow. if (cart.shippingInfo && cart.shippingInfo.address && cart.shippingInfo.address.addressId !== cart.customer.addressId) { isValidCustomerInfo.isValid = (cart.shippingInfo.address.addressId) ? true : customerInfo.isValidShipping; isValidCustomerInfo.section = 'Shipping'; } else { isValidCustomerInfo.isValid = customerInfo.isValidShipping; isValidCustomerInfo.section = 'Shipping'; } } } if (!customerInfo.validDealerCode) { isValidCustomerInfo.isValid = customerInfo.validDealerCode; isValidCustomerInfo.section = 'Billing'; } // isValidCustomerInfo = customerInfo.validDealerCode ? customerInfo.validDealerCode : (billingAddress.validDealerCode); } } else { if (cart.customer.creditProfile.accountNumber || cart.customer.creditType || cart.customer.addressId) { isValidCustomerInfo.isValid = true; isValidCustomerInfo.section = 'Billing'; } } return isValidCustomerInfo; } static checkPackageAddress(customerInfo: any): boolean { const addressValid: any = {} addressValid.isValid = true; addressValid.section = 'e911'; if (customerInfo && customerInfo.packages) { for (const pack of customerInfo.packages) { if (pack.e911Address) { if (pack.e911Address.e911sameAsBilling === false && !pack.e911Address.isValidE911) { addressValid.isValid = pack.e911Address.isValidE911; addressValid.section = 'e911'; return addressValid; } } if (pack.ppuAddress) { if (pack.ppuAddress.sameAsBilling === false && !pack.ppuAddress.isValidPPU) { // addressValid = (pack.ppuAddress.addressId) ? true : pack.ppuAddress.isValidPPU; // if (!addressValid) { addressValid.isValid = pack.ppuAddress.isValidPPU; addressValid.section = 'PPU'; return addressValid; // } } } if (pack.numberPorting) { if (pack.numberPorting.portPhoneNumber && !pack.numberPorting.isValidPorting) { addressValid.isValid = (pack.numberPorting.numberPortingId) ? true : pack.numberPorting.isValidPorting; if (!addressValid.isValid) { addressValid.isValid = false; addressValid.section = 'Porting'; return addressValid; } } } } } // if(customerInfo && !customerInfo.sameAsBilling){ // return addressValid = !customerInfo.sameAsBilling; // } return addressValid; } /** getDeviceNumberService */ static getDeviceNumberService(addressId: any, pack: IPackage, field: string, val: string): boolean { if (addressId && pack && field && val) { return (pack[field] && pack[field][val] && pack[field][val] !== addressId) ? false : true; } else { if (pack && field && val && field === 'numberPorting') {// check for BYOS order. return (pack[field] && pack[field][val]) ? true : false; } else { return (field === 'numberPorting') ? false : true; } } } static getDeviceServiceCustInfo(customerInfo: any, pack: IPackage, field: string): any { const add: any = {}; add.isNotSame = false; add.address = {}; if (customerInfo.packages && customerInfo.packages.length > 0) { for (const pk of customerInfo.packages) { if (pk.packageId === pack.packageId && pk.lineId === pack.lineId && !pack[field] && pk[field]) { if (pk[field]) { add.isNotSame = true; add.address = pk[field]; return add; } } else if (pk.packageId === pack.packageId && pk.lineId === pack.lineId && pack[field] && pk[field]) { if (pack[field].addressId !== pk[field].addressId) { add.isNotSame = true; add.address = pk[field]; return add; } } } } return add; } /** get createNpaNxx */ static createNpaNxx(cart: Cart): IZipMarket[] { let npaNxxList: IZipMarket[]; for (const packagee of cart.packages) { if (packagee.npaNxxType && packagee.npaNxxType.npa && packagee.npaNxxType.ngp && packagee.npaNxxType.marketCode) { npaNxxList = new Array(); let ngpNxx: any = { ngp: packagee.npaNxxType.ngp, city: '', state: '', nxx: packagee.npaNxxType.nxx }; npaNxxList.push({ npa: packagee.npaNxxType.npa, marketCode: packagee.npaNxxType.marketCode, marketName: null, ngpNxx: [ngpNxx], regionName: null }); break; } } return npaNxxList; } /** get createCartUpdateInput */ static createCartUpdateInput(cart: Cart, customerInfo: any, npaNxxList: IZipMarket[]): any { const METHOD_NAME: string = 'createCartUpdateInput()'; console.log('Getting the createCartUpdateInput.'); const inputData: any = {}; const billingAddressId: number = cart.customer && cart.customer.addressId ? cart.customer.addressId : null; // capturing the dealer code/web order#/retail store#/account password if (customerInfo.billingAddress) { const billingAddress: any = customerInfo.billingAddress; inputData.customer = this.createCustomerUpdateInput(cart, customerInfo); inputData.dealerCode = billingAddress.dealerCode ? billingAddress.dealerCode : null; inputData.webOrderId = billingAddress.webOrderId ? billingAddress.webOrderId : null; inputData.retailStoreId = billingAddress.retailStoreId ? billingAddress.retailStoreId : null; inputData.accountPassword = billingAddress.accountPassword ? billingAddress.accountPassword : null; } // verifying the shipping address changes if (customerInfo.shippingAddress) { inputData.shippingAddress = customerInfo.shippingAddress; } else if (customerInfo.sameAsBilling) { if (billingAddressId) { inputData.shippingAddress = { addressId: billingAddressId }; } else { inputData.shippingAddress = null; } } else { // setting same as billing address if (cart.shippingInfo && cart.shippingInfo.address) { if (billingAddressId === cart.shippingInfo.address.addressId) { inputData.shippingAddress = { addressId: cart.shippingInfo.address.addressId }; } } } // verifying the ppu/e911 address changes if (customerInfo.packages) { if (!npaNxxList) { npaNxxList = this.createNpaNxx(customerInfo) }; for (const packagee of cart.packages) { // setting same as billing address let updPackage: any; const updPackages = customerInfo.packages.filter((item) => { return packagee.packageId === item.packageId && packagee.lineId === item.lineId; }); if (updPackages && updPackages.length > 0) { updPackage = updPackages[0]; } if (updPackage) { updPackage.packageType = packagee.packageType; if (!updPackage.npaNxxType) { if (packagee.npaNxxType && packagee.npaNxxType.npa && packagee.npaNxxType.ngp && packagee.npaNxxType.marketCode) { updPackage.npaNxxType = packagee.npaNxxType; } else if (npaNxxList && npaNxxList.length > 0) { updPackage.npaNxxType = {} updPackage.npaNxxType.npa = npaNxxList[0].npa; updPackage.npaNxxType.marketCode = npaNxxList[0].marketCode; if (npaNxxList[0].ngpNxx) { updPackage.npaNxxType.ngp = npaNxxList[0].ngpNxx[0].ngp; if (npaNxxList[0].ngpNxx[0].nxx) { updPackage.npaNxxType.nxx = npaNxxList[0].ngpNxx[0].nxx; } } } } if (updPackage.ppuAddress && updPackage.ppuAddress.sameAsBilling) { if (billingAddressId) { updPackage.ppuAddress = { addressId: billingAddressId }; } else { updPackage.ppuAddress = null; } } if (updPackage.numberPorting && !updPackage.numberPorting.portPhoneNumber) { if (packagee.numberPorting && packagee.numberPorting.numberPortingId) { updPackage.numberPorting.numberPortingId = packagee.numberPorting.numberPortingId; } else { updPackage.numberPorting = null; } } if (updPackage.e911Address && updPackage.e911Address.e911sameAsBilling) { if (billingAddressId) { updPackage.e911Address = { addressId: billingAddressId }; } else { updPackage.e911Address = null; } } } else { customerInfo.packages.push(this.createDummyPackage(packagee, npaNxxList)); } } } else { customerInfo.packages = new Array(); for (const packagee of cart.packages) { customerInfo.packages.push(this.createDummyPackage(packagee, npaNxxList)); } } inputData.packages = customerInfo.packages ? customerInfo.packages : null; // tempararly removing nxx for update if (inputData.packages && inputData.packages.length > 0) { for (let packagee of inputData.packages) { if (packagee.npaNxxType) { packagee.npaNxxType.nxx = null; } } } return inputData; } /** get createCustomerUpdateInput */ static createCustomerUpdateInput(cart: Cart, customerInfo: any): any { if (customerInfo.billingAddress) { const billingAddress: any = customerInfo.billingAddress; const billing: any = {}; if (cart.customer && cart.customer && cart.customer.addressId) { billing.addressId = cart.customer.addressId; } //this will update the phone number if phonenumber field got changed in cutomer info page or billing address if (cart && cart.customer && cart.customer.phone1 && billingAddress.phone1 && cart.customer.phone1 !== billingAddress.phone1.split('-').join('')) { billing.phone1 = billingAddress.phone1; } if (cart.customer && cart.customer.creditProfile && cart.customer.creditProfile.accountNumber) { billing.email1 = billingAddress.email1; } else { if (cart.customer && cart.customer.firstName) { if (cart.customer.firstName !== billingAddress.firstName) { billing.firstName = billingAddress.firstName; } } else { billing.firstName = billingAddress.firstName; } if (cart.customer && cart.customer.middleName) { if (cart.customer.middleName !== billingAddress.middleName) { billing.middleName = billingAddress.middleName; } } else { billing.middleName = billingAddress.middleName; } if (cart.customer && cart.customer.lastName) { if (cart.customer.lastName !== billingAddress.lastName) { billing.lastName = billingAddress.lastName; } } else { billing.lastName = billingAddress.lastName; } // address if (cart.customer && cart.customer.address1) { if (cart.customer.address1 !== billingAddress.address1) { billing.address1 = billingAddress.address1; } } else { billing.address1 = billingAddress.address1; } if (cart.customer && cart.customer.address2) { if (cart.customer.address2 !== billingAddress.address2) { billing.address2 = billingAddress.address2; } } else { billing.address2 = billingAddress.address2; } if (cart.customer && cart.customer.city) { if (cart.customer.city !== billingAddress.city) { billing.city = billingAddress.city; } } else { billing.city = billingAddress.city; } if (cart.customer && cart.customer.state) { if (cart.customer.state !== billingAddress.state) { billing.state = billingAddress.state; } } else { billing.state = billingAddress.state; } if (cart.customer && cart.customer.zipCode) { if (cart.customer.zipCode !== billingAddress.zipCode) { billing.zipCode = billingAddress.zipCode; } } else { billing.zipCode = billingAddress.zipCode; } if (cart.customer && cart.customer.phone1) { if (cart.customer.phone1 !== billingAddress.phone1) { billing.phone1 = billingAddress.phone1; } } else { billing.phone1 = billingAddress.phone1; } if (cart.customer && cart.customer.email1) { if (cart.customer.email1 !== billingAddress.email1) { billing.email1 = billingAddress.email1; } } else { billing.email1 = billingAddress.email1; } } return billing; } return null; } /** createDummyPackage */ static createDummyPackage(packagee: IPackage, npaNxxList: IZipMarket[]): any { const METHOD_NAME: string = 'createDummyPackage()'; const pkg: any = { packageId: packagee.packageId, lineId: packagee.lineId, packageType: packagee.packageType }; if (packagee.packageType === Constants.PACKAGE_TYPE_VOICE || packagee.packageType === Constants.PACKAGE_TYPE_DATA) { if (packagee.npaNxxType && packagee.npaNxxType.npa && packagee.npaNxxType.ngp && packagee.npaNxxType.marketCode) { pkg.npaNxxType = packagee.npaNxxType; } else if (npaNxxList && npaNxxList.length > 0) { pkg.npaNxxType = {} pkg.npaNxxType.npa = npaNxxList[0].npa; pkg.npaNxxType.marketCode = npaNxxList[0].marketCode; if (npaNxxList[0].ngpNxx) { pkg.npaNxxType.ngp = npaNxxList[0].ngpNxx[0].ngp; if (npaNxxList[0].ngpNxx[0].nxx) { pkg.npaNxxType.nxx = npaNxxList[0].ngpNxx[0].nxx; } } } if (packagee.plan && packagee.plan.isLineLinkPlan) { pkg.acceptE911 = false; } } return pkg; } /** verify the line link plan */ static acceptE911Disclaimer(cart: Cart, inputData: any): boolean { const METHOD_NAME: string = 'acceptE911Disclaimer()'; let acceptE911Disclaimer: boolean = true; if (cart && cart.packages && inputData && inputData.packages) { for (const packagee of cart.packages) { if (packagee.plan && packagee.plan.isLineLinkPlan) { for (const item of inputData.packages) { if (packagee.packageId === item.packageId && packagee.lineId === item.lineId) { if (!item.acceptE911) { acceptE911Disclaimer = false; } break; } } } } } return acceptE911Disclaimer; } /** verify the line link plan */ static hasLineLinkPlan(cart: Cart): boolean { const METHOD_NAME: string = 'hasLineLinkPlan()'; let hasLineLinkPlan: boolean = false; if (cart && cart.packages) { for (const packagee of cart.packages) { if (packagee.plan && packagee.plan.isLineLinkPlan) { hasLineLinkPlan = true; break; } } } return hasLineLinkPlan; } /** verify the coverage check */ static hasServiceCoverage(cart: Cart): boolean { const METHOD_NAME: string = 'hasServiceCoverage()'; let hasServiceCoverage: boolean = true; if (cart && cart.packages) { for (const packagee of cart.packages) { if (packagee.packageType === Constants.PACKAGE_TYPE_VOICE || packagee.packageType === Constants.PACKAGE_TYPE_DATA) { if (!(packagee.npaNxxType && packagee.npaNxxType.npa && packagee.npaNxxType.ngp && packagee.npaNxxType.marketCode)) { console.log('No area code for package#' + packagee.packageId + '&line#' + packagee.lineId); hasServiceCoverage = false; break; } } } } return hasServiceCoverage; } /** verify the out of stock items */ static hasOutOfStockItems(products: IProductInventory[]): boolean { const METHOD_NAME: string = 'hasOutOfStockItems()'; let hasOutOfStockItems: boolean = false; if (products && products.length > 0) { for (const product of products) { if (product.inventoryStatus && product.inventoryStatus === Constants.OUTOFSTOCK_CODE) { hasOutOfStockItems = true; break; } } } return hasOutOfStockItems; } /** verify the pre-order items */ static hasPreorderItems(products: IProductInventory[]): boolean { const METHOD_NAME: string = 'hasPreorderItems()'; let hasPreorderItems: boolean = false; if (products && products.length > 0) { for (const product of products) { if (product.inventoryStatus && product.inventoryStatus === Constants.PREORDER_CODE) { hasPreorderItems = true; break; } } } return hasPreorderItems; } /** verify the back-order items */ static hasBackorderItems(products: IProductInventory[]): boolean { const METHOD_NAME: string = 'hasBackorderItems()'; let hasBackorderItems: boolean = false; if (products && products.length > 0) { for (const product of products) { if (product.inventoryStatus && product.inventoryStatus === Constants.BACKORDER_CODE) { hasBackorderItems = true; break; } } } return hasBackorderItems; } /** verify the back-order/pre-order items */ static hasMixedStatusItems(products: IProductInventory[]): boolean { const METHOD_NAME: string = 'hasMixedStatusItems()'; let hasMixedStatusItems: boolean = false; if (products && products.length > 0) { if (this.hasBackorderItems(products) || this.hasPreorderItems(products)) { hasMixedStatusItems = true; } } return hasMixedStatusItems; } /** canDisplayProduct */ static canDisplayProduct(cart: any, product: IProductInventory): boolean { const METHOD_NAME: string = 'canDisplayProduct()'; let canDisplayProduct: boolean = false; if (product.inventoryStatus === Constants.OUTOFSTOCK_CODE || product.inventoryStatus === Constants.PREORDER_CODE || product.inventoryStatus === Constants.BACKORDER_CODE) { if (cart && cart.packages) { for (const packagee of cart.packages) { if (packagee.device && packagee.device.deviceSKU === product.mfPartNumber) { canDisplayProduct = true; } if (packagee.accessories) { for (const accessory of packagee.accessories) { if (accessory.accessorySKU === product.mfPartNumber) { canDisplayProduct = true; } } } } } } return canDisplayProduct; } /** Validating the payment details */ static readyForSubmit(cart: any, payAndReviewInfo: any): boolean { const METHOD_NAME: string = 'readyForSubmit()'; let readyForSubmit: boolean = false; const securityCodeExists = (payAndReviewInfo.paymentMethod === Constants.PAYMENT_METHOD_WEBPAYMENT) ? true : payAndReviewInfo.securityCode; const CardNumberExists = (payAndReviewInfo.paymentMethod === Constants.PAYMENT_METHOD_WEBPAYMENT) ? true : payAndReviewInfo.cardNumber; if (cart && cart.customer) { // checking for existing for customer if customer is auto pay selected if (cart.customer.creditProfile && cart.customer.creditProfile.accountNumber && cart.customer.creditProfile.autoPayIndicator) { readyForSubmit = true; } else { if (payAndReviewInfo.cardType && CardNumberExists && payAndReviewInfo.expiration && securityCodeExists) { readyForSubmit = true; } } } return readyForSubmit; } /** get createOrderSubmitInput */ static createOrderSubmitInput(cart: any, payAndReviewInfo: any): any { const METHOD_NAME: string = 'createOrderSubmitInput()'; console.log('Creating the cart input data') const inputData: any = {}; if (cart && cart.customer && !cart.isShopifyOrder) { if (payAndReviewInfo.paymentMethod === Constants.PAYMENT_METHOD_WEBPAYMENT) { inputData.webPaymentID = payAndReviewInfo.webPaymentId; inputData.webTransactionID = payAndReviewInfo.transactionId; // inputData.account = payAndReviewInfo.cardNumber; // inputData.expire_month = payAndReviewInfo.expiration.substring(0, payAndReviewInfo.expiration.indexOf('/')); // inputData.expire_year = payAndReviewInfo.expiration.substring(payAndReviewInfo.expiration.indexOf('/') + 1); // fix for expiration date copy paste issue // payAndReviewInfo.expiration = payAndReviewInfo.expiration.replace('/',''); inputData.expire_month = payAndReviewInfo.expiration.substring(0, 2); inputData.expire_year = (payAndReviewInfo.expiration.indexOf('/') !== -1) ? payAndReviewInfo.expiration.substring(3, 7) : payAndReviewInfo.expiration.substring(2, 6); // if(inputData.expire_year.length == 2){ // let extraDigitsOfcurrentYear :any ; // extraDigitsOfcurrentYear = new Date().getFullYear().toString(); // inputData.expire_year = extraDigitsOfcurrentYear.slice(0,2) + inputData.expire_year; // } // inputData.cc_cvc = payAndReviewInfo.securityCode; inputData.cc_brand = (payAndReviewInfo.cardType === 'MASTERCARD') ? Constants.CARD_TYPE_MASTERCARD : (payAndReviewInfo.cardType === 'AMERICANEXPRESS') ? Constants.CARD_TYPE_AMERICAN : payAndReviewInfo.cardType; inputData.payMethodId = (payAndReviewInfo.cardType === 'MASTERCARD') ? Constants.CARD_TYPE_MASTERCARD : (payAndReviewInfo.cardType === 'AMERICANEXPRESS') ? Constants.CARD_TYPE_AMERICAN : payAndReviewInfo.cardType; inputData.payment_method = payAndReviewInfo.paymentMethod; } else { inputData.account = payAndReviewInfo.cardNumber; // inputData.expire_month = payAndReviewInfo.expiration.substring(0, payAndReviewInfo.expiration.indexOf('/')); // inputData.expire_year = payAndReviewInfo.expiration.substring(payAndReviewInfo.expiration.indexOf('/') + 1); // fix for expiration date copy paste issue // payAndReviewInfo.expiration = payAndReviewInfo.expiration.replace('/',''); // inputData.expire_month = payAndReviewInfo.expiration.substring(0,2); // inputData.expire_year = payAndReviewInfo.expiration.substring(2,6); // payAndReviewInfo.expiration = payAndReviewInfo.expiration.replace('/',''); inputData.expire_month = payAndReviewInfo.expiration.substring(0, 2); inputData.expire_year = (payAndReviewInfo.expiration.indexOf('/') !== -1) ? payAndReviewInfo.expiration.substring(3, 7) : payAndReviewInfo.expiration.substring(2, 6); // if(inputData.expire_year.length == 2){ // let extraDigitsOfcurrentYear :any ; // extraDigitsOfcurrentYear = new Date().getFullYear().toString(); // inputData.expire_year = extraDigitsOfcurrentYear.slice(0,2) + inputData.expire_year; // } inputData.cc_cvc = payAndReviewInfo.securityCode; inputData.cc_brand = (payAndReviewInfo.cardType === 'MASTERCARD') ? Constants.CARD_TYPE_MASTERCARD : payAndReviewInfo.cardType; inputData.payMethodId = (payAndReviewInfo.cardType === 'MASTERCARD') ? Constants.CARD_TYPE_MASTERCARD : payAndReviewInfo.cardType; inputData.payment_method = (payAndReviewInfo.cardType === 'MASTERCARD') ? Constants.CARD_TYPE_MASTERCARD : payAndReviewInfo.cardType; } if (payAndReviewInfo.eSignEmailAddr) { inputData.eSignEmailAddr = payAndReviewInfo.eSignEmailAddr; } if (!payAndReviewInfo.sameAsBilling) { inputData.coCCAddress1 = payAndReviewInfo.address1; if (payAndReviewInfo.address2) { inputData.coCCAddress2 = payAndReviewInfo.address2; } inputData.coCCCity = payAndReviewInfo.city; inputData.coCCState = payAndReviewInfo.state; inputData.coCCZip = payAndReviewInfo.zipCode; } if (cart.customer.creditProfile && cart.customer.creditProfile.accountNumber && cart.customer.creditProfile.autoPayIndicator) { console.log('customer is setup auto pay'); } else if (payAndReviewInfo.enrollAutopay) { inputData.useForEasyPay = true; inputData.useForSavePay = true; } else { inputData.useForEasyPay = false; inputData.useForSavePay = payAndReviewInfo.storeCardDetails; } } return inputData; } /** get createOrderSubmitByosInput */ static createOrderSubmitByosInput(cart: any, payAndReviewInfo: any): any { console.log('Creating the cart input data'); const paymentInfo: any = {}; paymentInfo.paymentType = 'BYOS'; paymentInfo.paymentMethod = 'CreditCard'; paymentInfo.cardNumber = payAndReviewInfo.encryptedCC ? payAndReviewInfo.encryptedCC : payAndReviewInfo.cardNumber; paymentInfo.cardType = (payAndReviewInfo.cardType === 'MASTERCARD') ? Constants.CARD_TYPE_MASTERCARD : payAndReviewInfo.cardType; paymentInfo.lastFour = payAndReviewInfo.cardNumber.substring(payAndReviewInfo.cardNumber.length - 4); paymentInfo.expMonth = payAndReviewInfo.expiration.substring(0, payAndReviewInfo.expiration.indexOf('/')); paymentInfo.expYear = payAndReviewInfo.expiration.substring(payAndReviewInfo.expiration.indexOf('/') + 1); paymentInfo.cvv = payAndReviewInfo.securityCode; paymentInfo.amount = cart.totalDepositDueToday ? cart.totalDepositDueToday : 0; if (cart && cart.customer) { const address: any = {}; address.firstName = cart.customer.firstName; address.middleName = cart.customer.middleName; address.lastName = cart.customer.lastName; if (!payAndReviewInfo.sameAsBilling) { address.address1 = payAndReviewInfo.address1; if (payAndReviewInfo.address2) { address.address2 = payAndReviewInfo.address2; } address.city = payAndReviewInfo.city; address.zipCode = payAndReviewInfo.zipCode; address.state = payAndReviewInfo.state; } else { address.address1 = cart.customer.address1; if (cart.customer.address2) { address.address2 = cart.customer.address2; } address.city = cart.customer.city; address.zipCode = cart.customer.zipCode; address.state = cart.customer.state; } paymentInfo.paymentAddress = address; } return paymentInfo; } /** get isBYOSOnlyOrder */ static isBYOSOnlyOrder(cart: Cart): boolean { // console.log('Getting the isBYOSOnlyOrder.') if (cart && cart.packages) { for (const packagee of cart.packages) { if (packagee && packagee.device && packagee.device.sim && packagee.device.sim !== 'N/A') { return true; } } } return false; } /** get card type */ static getCardType(firstChar: String): any { // console.log('Getting the getCardType.') let cardType: any = { cardType: 'VISA', securityCodeLength: 3, cardLength: 16 }; if (!firstChar || firstChar == '4') { cardType.cardType = 'VISA'; cardType.securityCodeLength = 3; cardType.cardLength = 16; } else if (firstChar == '5' || firstChar == '2') { cardType.cardType = 'MASTERCARD'; cardType.securityCodeLength = 3; cardType.cardLength = 16; } else if (firstChar == '3') { cardType.cardType = 'AMEX'; cardType.securityCodeLength = 4; cardType.cardLength = 15; } else if (firstChar == '6') { cardType.cardType = 'Discover'; cardType.securityCodeLength = 3; cardType.cardLength = 16; } return cardType; } }