private string PerformPaypalInStorePaymentCheckout()
        {
            try
            {
                var items = invoice.ItemsInvoice;

                if (items.Count > 0)
                {
                    Payment.PaymentGateway pg = new Payment.PaymentGateway();
                    var merchant = pg.GetMerchant(invoice.MerchantId);

                    if (merchant != null)
                    {
                        ReceiverList receiverList = new ReceiverList();
                        //RDNation as a reciever
                        Receiver recRDNation = new Receiver(invoice.FinancialData.BasePriceForItems + invoice.FinancialData.ShippingCost);
                        if (invoice.Mode == PaymentMode.Live)
                            recRDNation.email = ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN;
                        else if (invoice.Mode == PaymentMode.Test)
                            recRDNation.email = ServerConfig.PAYPAL_SELLER_DEBUG_ADDRESS;
                        if (ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN != merchant.PaypalEmail)
                            recRDNation.primary = true;
                        //if we modify this invoiceID, 
                        //you need to modify this code here: 
                        recRDNation.invoiceId = invoice.InvoiceId.ToString().Replace("-", "") + ": Payment to " + merchant.ShopName;
                        recRDNation.paymentType = PaymentTypeEnum.GOODS.ToString();
                        receiverList.receiver.Add(recRDNation);
                        if (ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN != merchant.PaypalEmail)
                        {
                            Receiver recLeague = new Receiver(invoice.FinancialData.PriceSubtractingRDNationFees);
                            recLeague.amount = invoice.FinancialData.PriceSubtractingRDNationFees;
                            if (invoice.Mode == PaymentMode.Live)
                                recLeague.email = merchant.PaypalEmail;
                            else if (invoice.Mode == PaymentMode.Test)
                                recLeague.email = "*****@*****.**";
                            recLeague.primary = false;
                            //if we modify this invoiceID, 
                            //you need to modify this code here: 
                            recLeague.invoiceId = invoice.InvoiceId.ToString().Replace("-", "") + ": Payment to " + merchant.ShopName;
                            recLeague.paymentType = PaymentTypeEnum.GOODS.ToString();
                            receiverList.receiver.Add(recLeague);
                        }

                        PayRequest req = new PayRequest(new RequestEnvelope("en_US"), ActionTypeEnum.PAY.ToString(), ServerConfig.STORE_MERCHANT_CART_URL + merchant.MerchantId.ToString().Replace("-", ""), invoice.Currency, receiverList, ServerConfig.STORE_MERCHANT_RECEIPT_URL + invoice.InvoiceId.ToString().Replace("-", ""));
                        if (ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN != merchant.PaypalEmail)
                            req.feesPayer = FeesPayerEnum.PRIMARYRECEIVER.ToString();
                        req.memo = "Payment to " + merchant.ShopName + ": " + invoice.InvoiceId.ToString().Replace("-", "");
                        req.reverseAllParallelPaymentsOnError = false;
                        if (invoice.Mode == PaymentMode.Live)
                            req.ipnNotificationUrl = ServerConfig.PAYPAL_IPN_HANDLER;
                        else if (invoice.Mode == PaymentMode.Test)
                            req.ipnNotificationUrl = ServerConfig.PAYPAL_IPN_HANDLER_DEBUG;

                        // All set. Fire the request            
                        AdaptivePaymentsService service = new AdaptivePaymentsService();
                        PayResponse resp = service.Pay(req);

                        // Display response values. 
                        Dictionary<string, string> keyResponseParams = new Dictionary<string, string>();
                        string redirectUrl = null;
                        if (!(resp.responseEnvelope.ack == AckCode.FAILURE) &&
                            !(resp.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
                        {
                            EmailServer.EmailServer.SendEmail(ServerConfig.DEFAULT_EMAIL, ServerConfig.DEFAULT_EMAIL_FROM_NAME, ServerConfig.DEFAULT_ADMIN_EMAIL_ADMIN, "Paypal Store Item Waiting To be Purchased", invoice.InvoiceId + " Amount:" + invoice.FinancialData.BasePriceForItems + ":" + merchant.PaypalEmail);

                            if (invoice.Mode == PaymentMode.Live)
                                redirectUrl = PaypalPaymentFactory.GetBaseUrl(PaypalPaymentFactory.PaypalMode.live);
                            else if (invoice.Mode == PaymentMode.Test)
                                redirectUrl = PaypalPaymentFactory.GetBaseUrl(PaypalPaymentFactory.PaypalMode.test);

                            redirectUrl += "?cmd=_ap-payment&paykey=" + resp.payKey;
                            keyResponseParams.Add("Pay key", resp.payKey);
                            keyResponseParams.Add("Payment execution status", resp.paymentExecStatus);
                            if (resp.defaultFundingPlan != null && resp.defaultFundingPlan.senderFees != null)
                            {
                                keyResponseParams.Add("Sender fees", resp.defaultFundingPlan.senderFees.amount +
                                                            resp.defaultFundingPlan.senderFees.code);
                            }

                            //Selenium Test Case
                            keyResponseParams.Add("Acknowledgement", resp.responseEnvelope.ack.ToString());
                            return redirectUrl;
                        }
                        else
                        {

                            throw new Exception("Failure Payment " + merchant.PaypalEmail + ":" + invoice.InvoiceId + ":" + resp.error.FirstOrDefault().message);
                        }

                    }
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return String.Empty;
        }