public TransactionModel getTransaction(string urlvalues, PaymentModel pm)
 {
     TransactionModel tm = new TransactionModel();
     string apiobject = "transactions";
     string response = GetPMAPIResponse(_PayMillPaymentSettings.apiUrl + apiobject + urlvalues, _PayMillPaymentSettings.privateKey);
     if (response != "noresponse" && response.Substring(0, 5) != "ERROR")
     {
         JObject jObject = JObject.Parse(response);
         JToken thedata = jObject["data"];
         tm.id = thedata["id"].ToString().Replace("\"", "");
         tm.amount = thedata["amount"].ToString().Replace("\"", "");
         tm.origin_amount = thedata["origin_amount"].ToString().Replace("\"", "");
         tm.currency = thedata["currency"].ToString().Replace("\"", "");
         tm.status = thedata["status"].ToString().Replace("\"", "");
         tm.description = thedata["description"].ToString().Replace("\"", "");
         tm.livemode = thedata["livemode"].ToString().Replace("\"", "");
         tm.created_at = thedata["created_at"].ToString().Replace("\"", "");
         tm.updated_at = thedata["updated_at"].ToString().Replace("\"", "");
         tm.response_code = thedata["response_code"].ToString().Replace("\"", "");
         tm.payment = pm;
     }
     return tm;
 }
        /// <summary>
        /// Process a payment
        /// </summary>
        /// <param name="processPaymentRequest">Payment info required for an order processing</param>
        /// <returns>Process payment result</returns>
        public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var result = new ProcessPaymentResult();
            try
            {
                result.AllowStoringCreditCardNumber = false;
                var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId);
                var order = _orderService.GetOrderByGuid(processPaymentRequest.OrderGuid);
                string currency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
                PaymentModel pm = new PaymentModel();
                pm = getPayment("?token=" + processPaymentRequest.CustomValues["paymenttoken"]);
                string paymentid = pm.id;
                string amount = processPaymentRequest.OrderTotal.ToString();
                amount = Regex.Replace(amount, @"[^\d]", "");

                //string urlappend = "?payment=" + payment + "&amount=" + amount + "&currency=" + currency + "&description=" + description;
                string urlbuilder = "?payment=" + paymentid + "&amount=" + amount + "&currency=" + currency + "&description=Order from Store ID: " + processPaymentRequest.StoreId.ToString() + " PaymentID: " + pm.id;
                TransactionModel trans = new TransactionModel();
                //_logger.InsertLog(Core.Domain.Logging.LogLevel.Information, "url for transaction", urlbuilder);
                trans = getTransaction(urlbuilder, pm);
                string responsecode = trans.response_code;
                string transactionid = trans.id;
                //set the transaction variables
                if (responsecode == "20000")
                {
                    //successful response
                    result.AuthorizationTransactionCode = transactionid;
                    result.AuthorizationTransactionResult = responsecode;
                    result.NewPaymentStatus = PaymentStatus.Paid;
                    //_logger.InsertLog(Core.Domain.Logging.LogLevel.Information, "success at paymill proceessorder" + responsecode + urlbuilder + paymentid, trans.status + urlbuilder + paymentid, null);
                }
                else
                {
                    //failed transaction
                    _logger.InsertLog(Core.Domain.Logging.LogLevel.Information, "failure at paymill proceessorder" + responsecode, trans.status, null);
                    result.AddError(getErrorcodes(responsecode, trans.status));
                }
            }
            catch (Exception ex)
            {
                _logger.InsertLog(Core.Domain.Logging.LogLevel.Error, ex.Message, ex.ToString());
                result.AddError(ex.ToString());
            }
            return result;
        }
        public PaymentModel getPayment(string urlvalues)
        {
            PaymentModel pmodel = new PaymentModel();
            try
            {
                string apiobject = "payments";
                string response = GetPMAPIResponse(_PayMillPaymentSettings.apiUrl + apiobject + urlvalues, _PayMillPaymentSettings.privateKey);
                if (response != "noresponse" && response.Substring(0, 5) != "ERROR")
                {
                    JObject jObject = JObject.Parse(response);
                    JToken thedata = jObject["data"];
                    pmodel.id = thedata["id"].ToString().Replace("\"", "");
                    pmodel.type = thedata["type"].ToString().Replace("\"", "");
                    pmodel.client = thedata["client"].ToString().Replace("\"", "");
                    pmodel.card_type = thedata["card_type"].ToString().Replace("\"", "");
                    pmodel.country = thedata["country"].ToString().Replace("\"", "");
                    pmodel.expire_month = thedata["expire_month"].ToString().Replace("\"", "");
                    pmodel.expire_year = thedata["expire_year"].ToString().Replace("\"", "");
                    pmodel.card_holder = thedata["card_holder"].ToString().Replace("\"", "");
                    pmodel.last4 = thedata["last4"].ToString().Replace("\"", "");
                    pmodel.created_at = thedata["created_at"].ToString().Replace("\"", "");
                    pmodel.updated_at = thedata["updated_at"].ToString().Replace("\"", "");
                }
                //_logger.InsertLog(Core.Domain.Logging.LogLevel.Information, "getpayment successful " + response, "getpayment successful" + response, null);
            }
            catch (Exception ex)
            {
                pmodel = null;
                _logger.InsertLog(Core.Domain.Logging.LogLevel.Error, ex.Message + " error in getpayment", ex.ToString(), null);
            }

            return pmodel;
        }