} // End of the CreateOrderTest method /// <summary> /// Create a production order /// </summary> private static Dictionary<string, string> CreateOrderProduction(Order order, List<OrderRow> orderRows, Domain domain, KeyStringList settings, KeyStringList tt, string paymentType) { // Create the dictionary to return Dictionary<string, string> responseData = new Dictionary<string, string>(10); // Create the PayEx order Annytab.Webshop.Payex.Production.PxOrder pxOrder = new Annytab.Webshop.Payex.Production.PxOrder(); // Get the currency Currency orderCurrency = Currency.GetOneById(order.currency_code); // Calculate the decimal multiplier Int32 decimalMultiplier = (Int32)Math.Pow(10, orderCurrency.decimals); // Add the data long accountNumber = 0; long.TryParse(settings.Get("PAYEX-ACCOUNT-NUMBER"), out accountNumber); string purchaseOperation = "SALE"; if (paymentType == "INVOICE") { purchaseOperation = "AUTHORIZATION"; } Int64 price = (Int64)Math.Round((order.total_sum - order.gift_cards_amount) * 100, MidpointRounding.AwayFromZero); string priceArgList = ""; string currency = order.currency_code; Int32 vat = 0; string orderID = order.id.ToString(); string productNumber = tt.Get("order").ToUpper() + "# " + order.id; string description = domain.webshop_name; string clientIPAddress = Tools.GetUserIP(); string clientIdentifier = ""; string externalID = ""; string returnUrl = domain.web_address + "/order/payex_confirmation/" + order.id.ToString(); string view = paymentType; string agreementRef = ""; string cancelUrl = domain.web_address + "/order/confirmation/" + order.id.ToString(); string clientLanguage = order.language_code.ToLower() + "-" + order.country_code.ToUpper(); // Set additional values string additionalValues = "USECSS=RESPONSIVEDESIGN"; // Change to PayEx Payment Gateway 2.0 if the payment type is CREDITCARD if (paymentType == "CREDITCARD") { additionalValues = "RESPONSIVE=1"; } // Create the md5 hash string hash = GetMD5Hash(accountNumber.ToString() + purchaseOperation + price.ToString() + priceArgList + currency + vat + orderID.ToString() + productNumber + description + clientIPAddress + clientIdentifier + additionalValues + externalID + returnUrl + view + agreementRef + cancelUrl + clientLanguage + settings.Get("PAYEX-ENCRYPTION-KEY")); // Initialize the order string xmlResponse = pxOrder.Initialize8(accountNumber, purchaseOperation, price, priceArgList, currency, vat, orderID, productNumber, description, clientIPAddress, clientIdentifier, additionalValues, externalID, returnUrl, view, agreementRef, cancelUrl, clientLanguage, hash); // Create the xml document XmlDocument doc = new XmlDocument(); try { // Load the xml document doc.LoadXml(xmlResponse); // Add data from the xml responseData.Add("error_code", ParseXmlNode(doc, "/payex/status/errorCode")); responseData.Add("description", ParseXmlNode(doc, "/payex/status/description")); responseData.Add("order_ref", ParseXmlNode(doc, "/payex/orderRef")); responseData.Add("redirect_url", ParseXmlNode(doc, "/payex/redirectUrl")); } catch (Exception ex) { responseData.Add("exception", ex.Message); } // Check if the response data contains the order reference if (responseData.ContainsKey("order_ref") == false) { return responseData; } // Sum of order rows decimal payexSum = 0; // Add order rows for (int i = 0; i < orderRows.Count; i++) { // Calculate values Int32 quantity = (Int32)orderRows[i].quantity; decimal priceValue = Math.Round(orderRows[i].unit_price * quantity * 100, MidpointRounding.AwayFromZero) / 100; decimal vatValue = priceValue * orderRows[i].vat_percent; decimal orderValue = Math.Round((priceValue + vatValue) * 100, MidpointRounding.AwayFromZero) / 100; Int64 amount = (Int64)Math.Round((priceValue + vatValue) * 100, MidpointRounding.AwayFromZero); Int32 vatPrice = (Int32)Math.Round(vatValue * 100, MidpointRounding.AwayFromZero); Int32 vatPercent = (Int32)Math.Round(orderRows[i].vat_percent * 100, MidpointRounding.AwayFromZero); hash = GetMD5Hash(accountNumber.ToString() + responseData["order_ref"] + orderRows[i].product_code + orderRows[i].product_name + quantity.ToString() + amount.ToString() + vatPrice.ToString() + vatPercent.ToString() + settings.Get("PAYEX-ENCRYPTION-KEY")); // Add the order row string error = pxOrder.AddSingleOrderLine2(accountNumber, responseData["order_ref"], orderRows[i].product_code, orderRows[i].product_name, "", "", "", "", quantity, amount, vatPrice, vatPercent, hash); // Add to the payex sum payexSum += orderValue; } // Calculate the rounding amount decimal rounding = Math.Round((order.total_sum - payexSum) * 100, MidpointRounding.AwayFromZero) / 100; // Add the rounding if (rounding != 0) { Int64 roundingAmount = (Int64)Math.Round(rounding * 100, MidpointRounding.AwayFromZero); hash = GetMD5Hash(accountNumber.ToString() + responseData["order_ref"] + "rd" + tt.Get("rounding") + "1" + roundingAmount.ToString() + "0" + "0" + settings.Get("PAYEX-ENCRYPTION-KEY")); string errorMessage = pxOrder.AddSingleOrderLine2(accountNumber, responseData["order_ref"], "rd", tt.Get("rounding"), "", "", "", "", 1, roundingAmount, 0, 0, hash); } // Add the gift cards amount if (order.gift_cards_amount > 0) { decimal amount = order.gift_cards_amount > payexSum ? payexSum : order.gift_cards_amount; Int64 giftCardsAmount = (Int64)Math.Round(amount * -1 * 100, MidpointRounding.AwayFromZero); hash = GetMD5Hash(accountNumber.ToString() + responseData["order_ref"] + "gc" + tt.Get("gift_cards") + "1" + giftCardsAmount.ToString() + "0" + "0" + settings.Get("PAYEX-ENCRYPTION-KEY")); string errorMessage = pxOrder.AddSingleOrderLine2(accountNumber, responseData["order_ref"], "gc", tt.Get("gift_cards"), "", "", "", "", 1, giftCardsAmount, 0, 0, hash); } // Check if we should create an invoice if (paymentType == "INVOICE") { if (order.customer_type == 0) { responseData = CreateInvoiceCorporate(responseData["order_ref"], order, domain, settings, tt); } else if (order.customer_type == 1) { responseData = CreateInvoicePrivate(responseData["order_ref"], order, domain, settings, tt); } } // Return the response data return responseData; } // End of the CreateOrderProduction method