Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
35 kB
1
Indexable
Never
import { LightningElement, track, api, wire } from 'lwc';
import getSalesOrderId1 from '@salesforce/apex/Apfy_PaymentPage.getSalesOrderId1';
import getSalesOrderId2 from '@salesforce/apex/Apfy_PaymentPage.getSalesOrderId2';
//===== This Call Apfy_PaymentPage PaymentPage To Call And handel Normal PayPal Credit Card Payment 
import callApexRestCallout from '@salesforce/apex/Apfy_PaymentPage.callApexRestCallout';

import createOrderDetails from '@salesforce/apex/Apfy_PaymentPage.createOrderDetails';
import getuserAddressDetails from '@salesforce/apex/Apfy_PaymentPage.getuserAddressDetails';
import handleSalesOrder from '@salesforce/apex/Apfy_PaymentPage.handleSalesOrder';
import fetchSourceCode from '@salesforce/apex/Apfy_PaymentPage.fetchSourceCode';
import applySorceCode from '@salesforce/apex/Apfy_PaymentPage.applySorceCode';
import getOrderDetails from '@salesforce/apex/Apfy_PaymentPage.getOrderDetails';
import creatEPayment from '@salesforce/apex/Apfy_PaymentPage.creatEPayment';

//=== This Start PayPal manger and Call Apex Class Apfy_paymentPaPalManger =========   this used for PayFlow ===========
import payPalMangerCallout from '@salesforce/apex/Apfy_paymentPaPalManger.payPalMangerCallout';
import handleSalesOrderManager from '@salesforce/apex/Apfy_paymentPaPalManger.handleSalesOrderManager';
import createPaymentManager from '@salesforce/apex/Apfy_paymentPaPalManger.createPaymentManager';
import payCreditcardApproved from '@salesforce/apex/Apfy_paymentPaPalManger.payCreditcardApproved';

import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import Id from '@salesforce/user/Id';
import { getRecord } from 'lightning/uiRecordApi';
import UserNameFld from '@salesforce/schema/User.Name';
export default class Jp_paymentPage extends NavigationMixin(LightningElement) {
    userId = Id;
    @track currentUserName;
    @track creditCardShow = true;
    @track getSalesOrderData;
    @track totalValueMembership;
    @track itemName;
    @api sorecordId;
    @track userAddressDetails;
    @track addressStreet;
    @track addressCity;
    @track addressState;
    @track addressPostalCode;
    @track expirationDate;
    @track changeValue;
    @track changelength;
    @track promoValue;
    @track cardNumberValues;//='4929241439504325';   //============= change This 
    @track expMonthValue;//='09';
    @track expYearValue;//='2029';
    @track cvvValue;//='123';
    @track zipCodeValue;
    pathArray = [];
    @track getOrderDetails;
    @track orderNumberForGetData;
    @track messageCardNamber;
    @track messageexpiryMonth;
    @track messageexpiryYear;
    @track messageCVV;
    @track isLoading =false;
    
    @track getDatAPI;
    @track linksToWork;
    @track payerActionLink;
    @track showDataCreateRecordlink;

    @track cardName; //== Card Holder name

    confirmationPageApiName = 'Confirmation__c';

    @wire(getRecord, { recordId: Id, fields: [UserNameFld] })
    userDetails({ error, data }) {
        if (data) {
            this.currentUserName = data.fields.Name.value;
            console.log('currentUserName====>>>>>' + this.currentUserName);
        } else if (error) {
            console.log('currentUserName====>>>>>' + JSON.stringify(error));
        }
    }
   
    connectedCallback(){
        this.sorecordId = sessionStorage.getItem('salesOrderId');
        console.log('Sales Order Id: ' + this.sorecordId);
    }

    @wire(getSalesOrderId1, { salesOrderId: '$sorecordId' })
    wiredContacts({ data, error }) {
        if (data) {
            this.getSalesOrderData = data;
            console.log('this.getSalesOrderData===>>>' + JSON.stringify(this.getSalesOrderData));
            this.totalValueMembership = this.getSalesOrderData[0].OrderApi__Total__c;
            this.itemName = this.getSalesOrderData[0].OrderApi__Item_Name__c
            //this.totalValueMembership = '120.00';
            console.log('this.totalValueMembership====>>>>>' + this.totalValueMembership);
        }
        else if (error) {
            this.getSalesOrderData = undefined;
            console.log('this.getSalesOrderData===>>>' + JSON.stringify(this.getSalesOrderData));
            console.log('this.Error===>>>' + JSON.stringify(error));
        }
    }
   
    changePromoCode(event) {
        this.promoValue = event.target.value;
        console.log('this.promoValue===>>>' + this.promoValue);

    }
  
    changedcardHolderName(event) {
        this.cardName = event.target.value;
        console.log('this.cardName===>>>' + this.cardName);

    }
    changedCardNamber(event) {
        this.cardNumberValues = event.target.value;
        console.log('this.cardNumberValues===>>>' + this.cardNumberValues);
    }
   
    changeYear(event) {
        this.expYearValue = event.target.value.slice(-2);
        console.log('this.expYearValue===>>>' + this.expYearValue);
    }
    changeMonth(event) {
        this.expMonthValue = event.target.value;
        console.log('this.expMonthValue===>>>' + this.expMonthValue);
    }
    changeCVV(event) {
        this.cvvValue = event.target.value;
        console.log('this.cvvValue===>>>' + this.cvvValue);
    }
    
    zipCode(event) {
        this.addressPostalCode = event.target.value;
        console.log('this.zipCodeValue===>>>' + this.addressPostalCode);
    }

   
    getOrderDetailsMethod() {
        console.log('this Start' + this.showDataCreateRecordlink);
        this.pathArray = this.showDataCreateRecordlink.split('/');
        console.log('pathArray New ==>>>' + this.pathArray);

        for (let i = 0; i < this.pathArray.length; i++) {
            console.log('After Split Values=====>>>>>' + this.pathArray[i]);
            this.orderNumberForGetData = this.pathArray[i];
        }

        console.log('this.orderNumberForGetData New ==>>>' + this.orderNumberForGetData);
        createOrderDetails({ ordernumber: this.orderNumberForGetData })
            .then((data) => {
                console.log('data===>>>' + JSON.stringify(data));
                this.getOrderDetails = JSON.parse(data);
                console.log('this.getOrderDetails==>>>' + JSON.stringify(this.getOrderDetails));

            })
            .catch((error) => {
                console.log('this.error===>>>' + JSON.stringify(error));
            });
    }

    navigateToPaypalPaymentPage() {
        console.log('navigateToPaypalPaymentPage===>>>');

        this[NavigationMixin.Navigate]({
            type: 'standard__webPage',
            attributes: {
                url: this.payerActionLink
            }
        }//,
            // true // Replaces the current page in your browser history with the URL
        );
    }

//============= Submit butto Start Here ====================================================================
    handleClick(event) {
        this.isLoading =true;
        console.log('Handle Click Start here==>>');
       
        var inputDate = this.template.querySelector(".yearCmp");
        console.log('inputDate'+inputDate);
        var dateValue = inputDate.value;
        console.log('dateValue'+dateValue);

        var currentYear= new Date().getFullYear(); 
        console.log('this.cardNumberValues=>'+this.cardNumberValues+'this.expYearValue==>'+this.expYearValue+'this.expMonthValue==>>'+this.expMonthValue+'this.cvvValue==>>>'+this.cvvValue);
        if(this.cardNumberValues != undefined && this.expYearValue!= undefined && this.expMonthValue != undefined && this.cvvValue != undefined){

            // if(currentYear>this.expYearValue){
            //     this.messageexpiryYear='Please Check year';
            //     this.isLoading =false;
            // }else{
                this.messageexpiryYear='';
    
            getuserAddressDetails({ userid: this.userId })
                .then((data) => {
                    this.userAddressDetails = data;  // Here we can get Address Data From User related Contact Details.
                    console.log(' this.userAddressDetails ==>>>>' + JSON.stringify(this.userAddressDetails));
                    this.addressStreet = this.userAddressDetails.MailingStreet;
                    this.addressCity = this.userAddressDetails.MailingCity;
                    this.addressState = this.userAddressDetails.MailingState;
                    this.addressPostalCode = this.userAddressDetails.MailingPostalCode;
    
                    console.log('Value Date====>>>' + this.expYearValue + '-' + this.expMonthValue);
                    //this.handleApexRestCallout();  // =============== This method To call And Execute Paypal Integration and payment through Direct Credit Card Not used in PayPal manger
                    this.handlePayPalMangerApexRestCallout();
                })
                .catch((error) => {
                    const evt = new ShowToastEvent({
                        title: 'Address Not Found',
                        message: 'Address is required to move forward for Payment',
                        variant: 'error',
                        mode: 'dismissable'
                    });
                    this.dispatchEvent(evt);
                    console.log('error ==>>>>' + JSON.stringify(error));
                    this.isLoading =false;
                });
    
            console.log('Value Date====>>>' + this.expYearValue + '-' + this.expMonthValue);
          //  }

        }else{
            const evt = new ShowToastEvent({
                title: 'Field Required',
                message: 'Please fill All details',
                variant: 'warning',
                mode: 'dismissable'
            });
            this.dispatchEvent(evt);
            console.log('Plese fill All details');
            this.isLoading =false;
        }
    }




    //=========================== This is help with Integrate PayPal Manger payment using API_FULL_TRANSACTION API ========================
    pnrefValue = [];
    handlePayPalMangerApexRestCallout() {
        console.log('PayFLow API Call ===>>>>' + this.cardNumberValues.substr(-4));
//==============  Send To verification card Data In Paypal manger ===========================
        payPalMangerCallout({
            salesOrderId: this.sorecordId,
            itemName: this.itemName,
            totalValueMembership: this.totalValueMembership,
            cardnumber: this.cardNumberValues,
            cardYear: this.expYearValue,
            cardMonth: this.expMonthValue,
            cardcvv: this.cvvValue,
            creditCardName: this.cardName,  //this.currentUserName
            addressLine1: this.addressStreet,
            city: this.addressCity,
            state: this.addressState,
            postalCode: this.addressPostalCode
        })
            .then((data) => {
                this.getDatAPI = data;
                if (this.getDatAPI[0] == 'RESULT=0' && this.getDatAPI[2] == 'RESPMSG=Approved') {
                    console.log('this.getDatAPI==RESULT=0=Approved>>>' + JSON.stringify(this.getDatAPI));
                    this.pnrefValue = this.getDatAPI[1].split('=');
                    this.paymentTokenId = this.pnrefValue[1];
                    console.log('==this.paymentTokenId=>>>' + this.paymentTokenId);
                    this.isLoading = false;
                /*    const evt = new ShowToastEvent({
                        title: 'Success',
                        message: 'Credit Card Authorization Complete',
                        variant: 'success',
                        mode: 'dismissable'
                    });
                    this.dispatchEvent(evt);
                    */

                    this.handleApprovedPayPalManger();

                } else if (this.getDatAPI[0] == 'RESULT=12' && this.getDatAPI[2] == 'RESPMSG=Declined') {
                    console.log('this.getDatAPI==Error-268>>>' + JSON.stringify(this.getDatAPI));
                    this.isLoading = false;

                    const evt = new ShowToastEvent({
                        title: 'Error',
                        message: 'We are not Authorized your card, Please Enter Appropriate card details.' + '  ' + JSON.stringify(this.getDatAPI),
                        variant: 'error',
                        mode: 'dismissable'
                    });
                    this.dispatchEvent(evt);
                    console.log('error ==>>>>' + JSON.stringify(error));


                } else {
                    console.log('this.getDatAPI==Error>282>>' + JSON.stringify(this.getDatAPI));
                    this.isLoading = false;
                    const evt = new ShowToastEvent({
                        title: 'Error',
                        message: 'Internal Error Occured ' + JSON.stringify(this.getDatAPI),
                        variant: 'error',
                        mode: 'dismissable'
                    });
                    this.dispatchEvent(evt);
                    console.log('error ==>>>>' + JSON.stringify(error));
                }
                    // console.log('this.getDatAPI===PNREF>>>' + JSON.stringify(this.getDatAPI[1]));
                    // console.log('Call Sales Order Update===>>>');
                    // this.pnrefValue = this.getDatAPI[1].split('=');
                    // this.paymentTokenId = this.pnrefValue[1];
                    // console.log('==this.paymentTokenId=>>>'+this.paymentTokenId);

            })
            .catch((error) => {
                this.isLoading = false;
                const evt = new ShowToastEvent({
                    title: 'Error',
                    message: error.body.message+'  '+JSON.stringify(this.getDatAPI),
                    variant: 'error',
                    mode: 'dismissable'
                });
                this.dispatchEvent(evt);
                console.log('error ==>>>>' + JSON.stringify(error));
            });
    }

    // ========== Sales API Callout After Approval of credit card Payment Process Start comes unsder PayPal Flow _Manager  ======================================

    @track getDatAPI2;
    handleApprovedPayPalManger() {

        this.isLoading = true;
        payCreditcardApproved({
            salesOrderId: this.sorecordId,
            pnref: this.paymentTokenId,
            totalValueMembership: this.totalValueMembership,
            cardnumber: this.cardNumberValues,
            cardYear: this.expYearValue,
            cardMonth: this.expMonthValue,
            cardcvv: this.cvvValue,
            creditCardName: this.cardName,  //this.currentUserName,
            addressLine1: this.addressStreet,
            city: this.addressCity,
            state: this.addressState,
            postalCode: this.addressPostalCode
        })
            .then((data) => {

                this.getDatAPI2 = data;
                console.log(' payCreditcardApproved =  data===>>>>' + JSON.stringify(this.getDatAPI2));

                if (this.getDatAPI2[0] == 'RESULT=0' && this.getDatAPI2[2] == 'RESPMSG=Approved') {
                    this.pnrefValue = this.getDatAPI2[1].split('=');
                    this.paymentTokenId = this.pnrefValue[1];
                    console.log('==this.paymentTokenId=>>>' + this.paymentTokenId);

                    const evt = new ShowToastEvent({
                        title: 'Success',
                        message: 'Payment Complete',
                        variant: 'success',
                        mode: 'dismissable'
                    });
                    this.dispatchEvent(evt);
                  
                 this.handleSalesOrderMethodPayPalManger();
                } else {
                    console.log('this.getDatAPI2==Error>>>' + JSON.stringify(this.getDatAPI2));
                    this.isLoading = false;
                    const evt = new ShowToastEvent({
                        title: 'Error',
                        message: 'Internal Error Occured ' + JSON.stringify(this.getDatAPI2[2]),
                        variant: 'error',
                        mode: 'dismissable'
                    });
                    this.dispatchEvent(evt);
                    console.log('error ==>>>>' + JSON.stringify(error));
                }
            })
            .catch((error) => {
                console.log(' payCreditcardApproved =  error===>>>>' + JSON.stringify(error));
                const evt = new ShowToastEvent({
                    title: Error,
                    message: error.body.message+'  '+JSON.stringify(this.getDatAPI2),
                    variant: 'error',
                    mode: 'dismissable'
                });
                this.dispatchEvent(evt);
                this.isLoading = false;
            });
    }




    //===== Handle Sales Order In PayPal Manger===========================================   
    handleSalesOrderMethodPayPalManger() {
        this.isLoading = true;
        handleSalesOrderManager({ salesorderid: this.sorecordId, lastfourdigit: this.cardNumberValues, cardtype: this.cardType })
            .then((data) => {
                console.log('handleSalesOrderManager==>>>' + JSON.stringify(data));
                //setTimeout(this.createEPaymentMethodPayPalManger(), 3000);
                this.createEPaymentMethodPayPalManger();

            })
            .catch((error) => {
                console.log(' handleSalesOrder =  error===>>>>' + JSON.stringify(error));
                const evt = new ShowToastEvent({
                    title: Error,
                    message: error.body.message,
                    variant: 'error',
                    mode: 'dismissable'
                });
                this.dispatchEvent(evt);
                this.isLoading = false;
            });
    }

    //======= Create EPayment Page Manger ==========================================================================
    createEPaymentMethodPayPalManger() {
        createPaymentManager({
            userid: this.userId,
            salesorderid: this.sorecordId,
            total: this.totalValueMembership,
            gatewaytranid: this.gatewayTranId,
            paymenttokenid: this.paymentTokenId,
            lastfourdigit: this.cardNumberValues.substr(-4),
            expyear: this.expYearValue,
            expmonth: this.expMonthValue,
            street: this.addressStreet,
            city: this.addressCity,
            state: this.addressState,
            postalCode: this.addressPostalCode,
            cardtype: this.cardType
        }).then((data) => {
            console.log('creatEPayment===>>>' + JSON.stringify(data));
            // ==== Move forward to success Page ================================                                
            this[NavigationMixin.Navigate]({
                type: 'comm__namedPage',
                attributes: {
                    name: this.confirmationPageApiName
                }
            });

        })
            .catch((error) => {
                const evt = new ShowToastEvent({
                    title: Error,
                    message: error.body.message,
                    variant: 'error',
                    mode: 'dismissable'
                });
                this.dispatchEvent(evt);
                this.isLoading = false;
                console.log('error ==>>>>' + JSON.stringify(error));
            });

    }



































//===================   This Will Call To payPal Credit card integration Not a PayPal Manger   ============================================    
    @track errorDetails;
    @track ErrorDetailsDescription;
    @track errorIssueValue;

    handleApexRestCallout() {
        console.log('Paypal Start ====>>>');
        callApexRestCallout({
            // salesOrderId: this.sorecordId,
            salesOrderId: this.sorecordId,
            itemName: this.itemName,
            totalValueMembership: this.totalValueMembership,
            cardnumber: this.cardNumberValues,
            cardYear: this.expYearValue,
            cardMonth: this.expMonthValue,
            cardcvv : this.cvvValue,
            creditCardName: this.currentUserName,  // ======= This Changed To get Card Holder name - Variable Look in Code--------------------------------------
            addressLine1: this.addressStreet,
            addressLine2: '',
            city: this.addressCity,
            state: this.addressState,
            postalCode: this.addressPostalCode
        })
            .then((data) => {
                this.getDatAPI = JSON.parse(data);
                console.log('this.getDatAPI===>>>' + JSON.stringify(this.getDatAPI));

                if (this.getDatAPI.name == 'UNPROCESSABLE_ENTITY') {
                    console.log('Error show =UNPROCESSABLE_ENTITY==>>>');
                    //console.log('Error show ===>>>'+JSON.stringify(this.getDatAPI.details));
                    this.errorDetails = this.getDatAPI.details;
                    this.ErrorDetailsDescription = this.errorDetails[0].description;
                    this.errorIssueValue = this.errorDetails[0].issue;
                    console.log('this.errorDetails==>>>' + JSON.stringify(this.errorDetails) + '===' + this.ErrorDetailsDescription);

                    const evt = new ShowToastEvent({
                        title: this.errorIssueValue,
                        message: this.ErrorDetailsDescription,
                        variant: 'error',
                        mode: 'dismissable'
                    });
                    this.dispatchEvent(evt);
                    this.isLoading =false;

                } else if (this.getDatAPI.name == 'INTERNAL_SERVER_ERROR') {
                    console.log('Error show =INTERNAL_SERVER_ERROR==>>>');
                    //console.log('Error show ===>>>'+JSON.stringify(this.getDatAPI.details));
                    this.errorDetails = this.getDatAPI.details;
                    console.log('this.errorDetails==>>>' + JSON.stringify(this.errorDetails));
                    this.ErrorDetailsDescription = this.errorDetails[0].description;
                    this.errorIssueValue = this.errorDetails[0].issue;

                    const evt = new ShowToastEvent({
                        title: this.errorIssueValue,
                        message: this.ErrorDetailsDescription,
                        variant: 'error',
                        mode: 'dismissable'
                    });
                    this.dispatchEvent(evt);
                    this.isLoading =false;

                } else if (this.getDatAPI.name == 'INVALID_REQUEST') {
                    console.log('Error show =INVALID_REQUEST==>>>');
                    //console.log('Error show ===>>>'+JSON.stringify(this.getDatAPI.details));
                    this.errorDetails = this.getDatAPI.name;
                    console.log('this.errorDetails==>>>' + JSON.stringify(this.errorDetails));
                    this.ErrorDetailsDescription = this.errorDetails.message;
                    this.errorIssueValue = this.errorDetails[0].issue;

                    const evt = new ShowToastEvent({
                        title: this.errorIssueValue,
                        message: this.ErrorDetailsDescription,
                        variant: 'error',
                        mode: 'dismissable'
                    });
                    this.dispatchEvent(evt);
                    this.isLoading =false;

                } else if (this.getDatAPI.status == 'COMPLETED') {
                    console.log('Completed Process Here==>>>');
                        this.gatewayTranId = this.getDatAPI.id ;
                        this.paymentSourceValue = this.getDatAPI.payment_source;
                        this.cardValues = this.paymentSourceValue.card;
                        this.cardType = this.cardValues.brand;
                        this.lastFourDigit = this.cardValues.last_digits;

                        this.purchaseunitsValues = this.getDatAPI.purchase_units;
                        this.purchasePayments = this.purchaseunitsValues[0].payments;
                        this.capturesValues = this.purchasePayments.captures; 
                        this.capturePaymentId = this.capturesValues[0].id; 
                        this.paymentTokenId = this.capturePaymentId;

                    console.log('purchaseunitsValues==>>>' + JSON.stringify(this.purchaseunitsValues));
                        console.log('purchasePayments==>>>'+JSON.stringify(this.purchasePayments));
                        console.log('capturesValues==>>>'+JSON.stringify(this.capturesValues));
                        console.log('capturePaymentId==>>>'+JSON.stringify(this.capturePaymentId));
                        console.log('cardValues==>>>'+JSON.stringify(this.cardValues));
                        console.log('paymentSourceValue==>>>'+JSON.stringify(this.paymentSourceValue));
                        console.log('gatewayTranId==>>>'+JSON.stringify(this.gatewayTranId));
                        console.log('paymentTokenId==>>>'+JSON.stringify(this.paymentTokenId));
                        console.log('lastFourDigit==>>>'+JSON.stringify(this.lastFourDigit));
                        console.log('cardType==>>>'+JSON.stringify(this.cardType));
                        
                    
                    //  this.isLoading =false;    
                    // this.handleTimeOutMethod();
                  this.handleSalesOrderMethod();
                  
                }
            }) .catch((error) => {
                if(error.body.message =='Read timed out'){
                    this.handleTimeOutMethod();
                }
                console.log(' Call API Paypal =  error===>>>>' + JSON.stringify(error));
                const evt = new ShowToastEvent({
                    title: Error,
                    message: error.body.message,
                    variant: 'error',
                    mode: 'dismissable'
                });
                this.dispatchEvent(evt);
                this.isLoading =false;
            });
    }



//////============================================================================================================================================


    @track gatewayTranId;
    @track paymentTokenId;
    @track lastFourDigit
    @track cardType;
    @track paymentSourceValue;
    @track cardValues;
    @track purchaseunitsValues;
    @track purchasePayments;
    @track capturesValues
    @track capturePaymentId;
   
   

handleTimeOutMethod(){    
    callApexRestCallout({
        // salesOrderId: this.sorecordId,
        salesOrderId: this.sorecordId,
        itemName: this.itemName,
        totalValueMembership: this.totalValueMembership,
        cardnumber: this.cardNumberValues,
        cardYear: this.expYearValue,
        cardMonth: this.expMonthValue,
        cardcvv : this.cvvValue,
        creditCardName: this.currentUserName,
        addressLine1: this.addressStreet,
        addressLine2: '',
        city: this.addressCity,
        state: this.addressState,
        postalCode: this.addressPostalCode
    }).then((data) => {                  
                    this.getDatAPI = JSON.parse(data);
                    console.log('this.getDatAPI===>>>' + JSON.stringify(this.getDatAPI));
    
                    if (this.getDatAPI.name == 'UNPROCESSABLE_ENTITY') {
                        console.log('Error show =UNPROCESSABLE_ENTITY==>>>');
                        this.errorDetails =  this.getDatAPI.details;
                        this.errorIssueValue = this.errorDetails[0].issue;

                        if(this.errorIssueValue == 'ORDER_ALREADY_CAPTURED'){
                            console.log('log  ORDER_ALREADY_CAPTURED===>>>' );
                            this.handleSalesOrderMethod();  
                        }
                    }                    
                })
                .catch((error) => {
                    this.isLoading =false;
                    console.log('error ==>>>>' + JSON.stringify(error));
                });
    }


 //===== Handle Sales Order ===========================================   
    handleSalesOrderMethod() {       
        handleSalesOrder({ salesorderid: this.sorecordId, lastfourdigit: this.cardNumberValues, cardtype: this.cardType })
            .then((data) => {
                this.createEPaymentMethod();
                console.log(' this.handleSalesOrder===>>>>' + JSON.stringify(this.sorecordId));
            })
            .catch((error) => {
                console.log(' handleSalesOrder =  error===>>>>' + JSON.stringify(error));
                const evt = new ShowToastEvent({
                    title: Error,
                    message: error.body.message,
                    variant: 'error',
                    mode: 'dismissable'
                });
                this.dispatchEvent(evt);
                this.isLoading =false;
            });
            //this.createEPaymentMethod();
        
    }

    createEPaymentMethod(){
        creatEPayment({
            userid: this.userId,
            salesorderid: this.sorecordId,
            total : this.totalValueMembership,
            gatewaytranid : this.gatewayTranId,
            paymenttokenid : this.paymentTokenId,
            lastfourdigit : this.lastFourDigit,
            expyear : this.expYearValue,
            expmonth : this.expMonthValue,
            street: this.addressStreet,
            city: this.addressCity,
            state: this.addressState,
            postalCode: this.addressPostalCode,
            cardtype : this.cardType
        }).then((data) => {
                console.log('creatEPayment===>>>' + JSON.stringify(data));
            // ==== Move forward to success Page ================================                                
                this[NavigationMixin.Navigate]({          
                    type: 'comm__namedPage',
                    attributes: {
                        name: this.confirmationPageApiName
                    }
                });
             
            })
            .catch((error) => {
                const evt = new ShowToastEvent({
                    title: Error,
                    message: error.body.message,
                    variant: 'error',
                    mode: 'dismissable'
                });
                this.dispatchEvent(evt);
                this.isLoading =false;
                console.log('error ==>>>>' + JSON.stringify(error));
            });

    }


    @track updatePromoCodeSalesOrder;
    handleApplyCode() {
        this.isLoading =true;
        console.log('handleApplyCode===>>>>');

        //============= Check Source Cde Here ===================================
        fetchSourceCode({
            sourceCode : this.promoValue
            }).then((data) => {
                console.log(' fetchSourceCode =  data===>>>>' + JSON.stringify(data));
                    if(data != null){
                        //============ Apply SOurce Code Here ===============================================
                            applySorceCode({ salesorderid: this.sorecordId, promocode: this.promoValue })
                            .then((data) => {
                                console.log(' this.data=handleApplyCode==>>>>' + JSON.stringify(data));
                                this.updatePromoCodeSalesOrder = data;
                                if (this.updatePromoCodeSalesOrder != null) {
                                    getSalesOrderId2({ salesOrderId: this.sorecordId })
                                        .then((data) => {
                                            this.getSalesOrderData = data;
                                            console.log('this.getSalesOrderData===>>>' + JSON.stringify(this.getSalesOrderData));
                                            this.totalValueMembership = this.updatePromoCodeSalesOrder.OrderApi__Total__c;
                                            this.itemName = this.getSalesOrderData[0].OrderApi__Item_Name__c;
                                            this.isLoading =false;
                                        })
                                        .catch((error) => {
                                            const evt = new ShowToastEvent({
                                                title: Error,
                                                message: error.body.message,
                                                variant: 'error',
                                                mode: 'dismissable'
                                            });
                                            this.dispatchEvent(evt);
                                            this.isLoading =false;
                                            console.log(' handleSalesOrder =  error===>>>>' + JSON.stringify(error));
                                        });
                                }
                            })
                            .catch((error) => {
                                const evt = new ShowToastEvent({
                                    title: Error,
                                    message: error.body.message,
                                    variant: 'error',
                                    mode: 'dismissable'
                                });
                                this.dispatchEvent(evt);
                                this.isLoading =false;
                                console.log(' handleSalesOrder =  error===>>>>' + JSON.stringify(error));
                            });
                    }else{
                        const evt = new ShowToastEvent({
                            title: 'Info',
                            message: 'Please Enter Valid Promo Code',
                            variant: 'Info',
                            mode: 'dismissable'
                        });
                        this.dispatchEvent(evt);
                        this.isLoading =false;
                    }

                       
            })
            .catch((error) => {
                const evt = new ShowToastEvent({
                    title: Error,
                    message: error.body.message,
                    variant: 'error',
                    mode: 'dismissable'
                });
                this.dispatchEvent(evt);
                this.isLoading =false;
                console.log(' handleSalesOrder =  error===>>>>' + JSON.stringify(error));
            });

     }

 }