Example #1
0
    } // End of the CancelTransactionTest method

    /// <summary>
    /// Cancel an authorized production transaction
    /// </summary>
    public static Dictionary<string, string> CancelTransactionProduction(Order order, KeyStringList settings)
    {
        // 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 data
        Int64 accountNumber = 0;
        Int64.TryParse(settings.Get("PAYEX-ACCOUNT-NUMBER"), out accountNumber);
        Int32 transactionNumber = 0;
        Int32.TryParse(order.payment_token, out transactionNumber);

        // Create the hash
        string hash = GetMD5Hash(accountNumber.ToString() + transactionNumber.ToString() + settings.Get("PAYEX-ENCRYPTION-KEY"));

        // Get the transaction information
        string xmlResponse = pxOrder.Cancel2(accountNumber, transactionNumber, hash);

        // Parse the xml response
        XmlDocument doc = new XmlDocument();

        try
        {
            // Load the xml document
            doc.LoadXml(xmlResponse);

            // Get data from the xml response paramName
            responseData.Add("error_code", ParseXmlNode(doc, "/payex/status/errorCode"));
            responseData.Add("description", ParseXmlNode(doc, "/payex/status/description"));
            responseData.Add("parameter_name", ParseXmlNode(doc, "/payex/paramName"));
            responseData.Add("transaction_status", ParseXmlNode(doc, "/payex/transactionStatus"));
            responseData.Add("transaction_number", ParseXmlNode(doc, "/payex/transactionNumber"));
        }
        catch (Exception ex)
        {
            responseData.Add("exception", ex.Message);
        }

        // Return the response data
        return responseData;

    } // End of the CancelTransactionProduction method
Example #2
0
    } // End of the CaptureTransactionTest method

    /// <summary>
    /// Capture an authorized production transaction
    /// </summary>
    private static Dictionary<string, string> CaptureTransactionProduction(Order order, KeyStringList settings)
    {
        // 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);

        // Get the data
        Int64 accountNumber = 0;
        Int64.TryParse(settings.Get("PAYEX-ACCOUNT-NUMBER"), out accountNumber);
        Int32 transactionNumber = 0;
        Int32.TryParse(order.payment_token, out transactionNumber);
        Int64 amount = (Int64)Math.Round(order.total_sum * 100, MidpointRounding.AwayFromZero);
        Int32 vatAmount = (Int32)Math.Round(order.vat_sum * 100, MidpointRounding.AwayFromZero);
        string additionalValues = "";

        // Create the hash
        string hash = GetMD5Hash(accountNumber.ToString() + transactionNumber.ToString() + amount.ToString() + order.id.ToString()
            + vatAmount.ToString() + additionalValues + settings.Get("PAYEX-ENCRYPTION-KEY"));

        // Get the transaction information
        string xmlResponse = pxOrder.Capture5(accountNumber, transactionNumber, amount, order.id.ToString(), vatAmount, additionalValues, hash);

        // Parse the xml response
        XmlDocument doc = new XmlDocument();

        try
        {
            // Load the xml document
            doc.LoadXml(xmlResponse);

            // Get data from the xml response
            responseData.Add("error_code", ParseXmlNode(doc, "/payex/status/errorCode"));
            responseData.Add("description", ParseXmlNode(doc, "/payex/status/description"));
            responseData.Add("parameter_name", ParseXmlNode(doc, "/payex/paramName"));
            responseData.Add("transaction_status", ParseXmlNode(doc, "/payex/transactionStatus"));
            responseData.Add("transaction_number", ParseXmlNode(doc, "/payex/transactionNumber"));
            responseData.Add("transaction_number_original", ParseXmlNode(doc, "/payex/originalTransactionNumber"));
        }
        catch (Exception ex)
        {
            responseData.Add("exception", ex.Message);
        }

        // Return the response data
        return responseData;

    } // End of the CaptureTransactionProduction method
Example #3
0
    } // 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
Example #4
0
    } // End of the CompleteOrderTest method

    /// <summary>
    /// Complete a production order
    /// </summary>
    private static Dictionary<string, string> CompleteOrderProduction(string orderReference, KeyStringList settings)
    {
        // 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 account number
        Int64 accountNumber = 0;
        Int64.TryParse(settings.Get("PAYEX-ACCOUNT-NUMBER"), out accountNumber);

        // Create the hash
        string hash = GetMD5Hash(accountNumber.ToString() + orderReference + settings.Get("PAYEX-ENCRYPTION-KEY"));

        // Get the transaction information
        string xmlResponse = pxOrder.Complete(accountNumber, orderReference, hash);

        // Parse the xml response
        XmlDocument doc = new XmlDocument();

        try
        {
            // Load the xml document
            doc.LoadXml(xmlResponse);

            // Get data from the xml response
            responseData.Add("error_code", ParseXmlNode(doc, "/payex/status/errorCode"));
            responseData.Add("description", ParseXmlNode(doc, "/payex/status/description"));
            responseData.Add("transaction_status", ParseXmlNode(doc, "/payex/transactionStatus"));
            responseData.Add("transaction_number", ParseXmlNode(doc, "/payex/transactionNumber"));
            responseData.Add("already_completed", ParseXmlNode(doc, "/payex/alreadyCompleted"));
            responseData.Add("order_id", ParseXmlNode(doc, "/payex/orderId"));
            responseData.Add("payment_method", ParseXmlNode(doc, "/payex/paymentMethod"));
        }
        catch (Exception ex)
        {
            responseData.Add("exception", ex.Message);
        }

        // Return the response data
        return responseData;

    } // End of the CompleteOrderProduction method
Example #5
0
    } // End of the CreateInvoiceCorporateTest method

    /// <summary>
    /// Create a production invoice for a company
    /// </summary>
    private static Dictionary<string, string> CreateInvoiceCorporateProduction(string orderReference, Order order, Domain domain, KeyStringList settings, KeyStringList tt)
    {
        // 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 data that we need
        Int64 accountNumber = 0;
        Int64.TryParse(settings.Get("PAYEX-ACCOUNT-NUMBER"), out accountNumber);
        string orderRef = orderReference;

        string companyRef = order.customer_id.ToString();
        string companyName = order.invoice_name;
        string streetAddress = order.invoice_address_1;
        string coAddress = "";
        string postalCode = order.invoice_post_code.Replace(" ", "");
        string city = order.invoice_city;
        string country = order.country_code;
        string organizationNumber = order.customer_org_number;
        string phoneNumber = order.customer_mobile_phone;
        string email = order.customer_email;
        string productCode = "";
        string creditCheckRef = "";
        Int32 mediaDistribution = 11;
        string invoiceDate = "";
        Int16 invoiceDueDays = 0;
        Int32 invoiceNumber = 0;
        string invoiceLayout = "";
        string invoiceText = tt.Get("order") + " " + order.id.ToString() + " - " + domain.webshop_name;

        // Create the md5 hash
        string hash = GetMD5Hash(accountNumber.ToString() + orderRef + companyRef + companyName + streetAddress + coAddress
            + postalCode + city + country + organizationNumber + phoneNumber + email + productCode + creditCheckRef + mediaDistribution.ToString()
            + invoiceText + invoiceDate + invoiceDueDays.ToString() + invoiceNumber + invoiceLayout + settings.Get("PAYEX-ENCRYPTION-KEY"));

        // Create the invoice
        string xmlResponse = pxOrder.PurchaseInvoiceCorporate(accountNumber, orderRef, companyRef, companyName, streetAddress, coAddress,
            postalCode, city, country, organizationNumber, phoneNumber, email, productCode, creditCheckRef, mediaDistribution, invoiceText,
            invoiceDate, invoiceDueDays, invoiceNumber, invoiceLayout, 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("transaction_status", ParseXmlNode(doc, "/payex/transactionStatus"));
            responseData.Add("transaction_number", ParseXmlNode(doc, "/payex/transactionNumber"));

        }
        catch (Exception ex)
        {
            responseData.Add("exception", ex.Message);
        }

        // Return the response data
        return responseData;

    } // End of the CreateInvoiceCorporateProduction method