예제 #1
0
    } // End of the OnAuthorization method

    /// <summary>
    /// Handle a non https request
    /// </summary>
    /// <param name="filterContext"></param>
    protected override void HandleNonHttpsRequest(AuthorizationContext filterContext)
    {
        // Get the current domain
        Domain domain = Tools.GetCurrentDomain();

        // Get the host
        string host = filterContext.HttpContext.Request.Url.Host;

        // Get website settings
        KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();
        string redirectHttps = webshopSettings.Get("REDIRECT-HTTPS");

        if (redirectHttps.ToLower() == "true")
        {
            // Modify the url
            UriBuilder uriBuilder = new UriBuilder(filterContext.HttpContext.Request.Url);
            uriBuilder.Scheme = "https";
            uriBuilder.Host = domain.web_address.Contains("www.") == true && uriBuilder.Host.Contains("www.") == false ? "www." + uriBuilder.Host : uriBuilder.Host;
            uriBuilder.Port = 443;

            // Redirect to https (301)
            filterContext.HttpContext.Response.RedirectPermanent(uriBuilder.Uri.AbsoluteUri);
        }
        else if (domain.web_address.Contains("www.") == true && host.Contains("www.") == false)
        {
            // Modify the url
            UriBuilder uriBuilder = new UriBuilder(filterContext.HttpContext.Request.Url);
            uriBuilder.Host = domain.web_address.Contains("www.") == true && uriBuilder.Host.Contains("www.") == false ? "www." + uriBuilder.Host : uriBuilder.Host;

            // Redirect to www (301)
            filterContext.HttpContext.Response.RedirectPermanent(uriBuilder.Uri.AbsoluteUri);
        }

    } // End of the HandleNonHttpsRequest method
예제 #2
0
    } // End of the GetMerchantId method

    /// <summary>
    /// Get the secret word for svea web pay
    /// </summary>
    /// <param name="type"> eg. HOSTED, INVOICE or PAYMENTPLAN</param>
    /// <param name="country">country code</param>
    /// <returns>The secret word as a string</returns>
    public string GetSecretWord(Webpay.Integration.CSharp.Util.Constant.PaymentType type, Webpay.Integration.CSharp.Util.Constant.CountryCode country)
    {
        // Get the webshop settings
        KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();

        // Return the secret word
        return(type == Webpay.Integration.CSharp.Util.Constant.PaymentType.HOSTED ? webshopSettings.Get("SVEA-SECRET-WORD") : "");
    } // End of the GetSecretWord method
예제 #3
0
    } // End of the GetClientNumber method

    /// <summary>
    /// Get the merchant id for svea web pay
    /// </summary>
    /// <param name="type"> eg. HOSTED, INVOICE or PAYMENTPLAN</param>
    /// <param name="country">country code</param>
    /// <returns>The merchant id as a string</returns>
    public string GetMerchantId(Webpay.Integration.CSharp.Util.Constant.PaymentType type, Webpay.Integration.CSharp.Util.Constant.CountryCode country)
    {
        // Get the company settings
        KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();

        // Return the merchant id
        return(type == Webpay.Integration.CSharp.Util.Constant.PaymentType.HOSTED ? webshopSettings.Get("SVEA-MERCHANT-ID") : "");
    } // End of the GetMerchantId method
예제 #4
0
    } // End of the SendNewsletter method

    /// <summary>
    /// Send an order confirmation
    /// </summary>
    /// <param name="toAddress">The address to send the email to</param>
    /// <param name="subject">The subject for the mail message</param>
    /// <param name="message">The mail message</param>
    public static bool SendOrderConfirmation(string toAddress, string subject, string message)
    {
        // Create the boolean to return
        bool successful = true;

        // Get the webshop settings
        KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();

        // Create variables
        string host = webshopSettings.Get("SEND-EMAIL-HOST");
        Int32 port = 0;
        Int32.TryParse(webshopSettings.Get("SEND-EMAIL-PORT"), out port);
        string emailAddress = webshopSettings.Get("SEND-EMAIL-ADDRESS");
        string password = webshopSettings.Get("SEND-EMAIL-PASSWORD");
        string useSSL = webshopSettings.Get("SEND-EMAIL-USE-SSL");

        // Order email
        string orderEmail = webshopSettings.Get("ORDER-EMAIL");

        // Create the SmtpClient instance
        SmtpClient smtp = new SmtpClient(host, port);
        smtp.Credentials = new NetworkCredential(emailAddress, password);

        // Check if we should enable SSL
        if (useSSL.ToLower() == "true")
        {
            smtp.EnableSsl = true;
        }

        // Try to send the mail message
        try
        {
            // Get the mail address
            MailAddress mailToAddress = new MailAddress(toAddress);

            // Create the mail message instance
            MailMessage mailMessage = new MailMessage(emailAddress, toAddress);

            // Create the mail message
            mailMessage.CC.Add(new MailAddress(orderEmail));
            mailMessage.Subject = subject;
            mailMessage.Body = message;
            mailMessage.IsBodyHtml = true;

            // Send the mail message
            smtp.Send(mailMessage);

        }
        catch (Exception ex)
        {
            string exceptionMessage = ex.Message;
            successful = false;
        }

        // Return the boolean
        return successful;

    } // End of the SendEmailToCustomer method
예제 #5
0
    } // End of the SendEmailToCustomer method

    /// <summary>
    /// Send a newsletter to all the customers that want one
    /// </summary>
    /// <param name="toAddresses">The addresses to send the email to</param>
    /// <param name="subject">The subject for the mail message</param>
    /// <param name="message">The mail message</param>
    public static bool SendNewsletter(string toAddresses, string subject, string message)
    {
        // Create the boolean to return
        bool successful = true;

        // Get the webshop settings
        KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();

        // Create variables
        string host = webshopSettings.Get("SEND-EMAIL-HOST");
        Int32 port = 0;
        Int32.TryParse(webshopSettings.Get("SEND-EMAIL-PORT"), out port);
        string emailAddress = webshopSettings.Get("SEND-EMAIL-ADDRESS");
        string password = webshopSettings.Get("SEND-EMAIL-PASSWORD");
        string contactUsEmail = webshopSettings.Get("CONTACT-US-EMAIL");
        string useSSL = webshopSettings.Get("SEND-EMAIL-USE-SSL");

        // Replace semicolon with comma
        toAddresses = toAddresses.Replace(";", ",");

        // Create the SmtpClient instance
        SmtpClient smtp = new SmtpClient(host, port);
        smtp.Credentials = new NetworkCredential(emailAddress, password);

        // Check if we should enable SSL
        if (useSSL.ToLower() == "true")
        {
            smtp.EnableSsl = true;
        }

        // Try to send the mail message
        try
        {
            // Create the mail message instance
            MailMessage mailMessage = new MailMessage(emailAddress, contactUsEmail);

            // Create the mail message
            mailMessage.Subject = subject;
            mailMessage.Body = message;
            mailMessage.IsBodyHtml = true;
            mailMessage.Bcc.Add(toAddresses);

            // Send the mail message
            smtp.Send(mailMessage);

        }
        catch (Exception ex)
        {
            string exceptionMessage = ex.Message;
            successful = false;
        }

        // Return the boolean
        return successful;

    } // End of the SendNewsletter method
예제 #6
0
        public ActionResult login(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();

            ViewBag.CurrentDomain = currentDomain;

            // Get the data from the form
            string userName = collection["txtUserName"];
            string passWord = collection["txtPassword"];

            // Get the administrator
            Administrator administrator = Administrator.GetOneByUserName(userName);

            // Get the current language id for admins
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Get translated texts
            KeyStringList translatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC");

            // Check if the user name exists and if the password is correct
            if (administrator != null && Administrator.ValidatePassword(userName, passWord) == true)
            {
                // Get webshop settings
                KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();
                string        redirectHttps   = webshopSettings.Get("REDIRECT-HTTPS");

                // Create the administrator cookie
                HttpCookie adminCookie = new HttpCookie("Administrator");
                adminCookie.Value    = Tools.ProtectCookieValue(administrator.id.ToString(), "Administration");
                adminCookie.Expires  = DateTime.UtcNow.AddDays(1);
                adminCookie.HttpOnly = true;
                adminCookie.Secure   = redirectHttps.ToLower() == "true" ? true : false;
                Response.Cookies.Add(adminCookie);

                // Redirect the user to the default admin page
                return(RedirectToAction("index", "admin_default"));
            }
            else
            {
                // Create a new administrator
                Administrator admin = new Administrator();
                admin.admin_user_name = userName;

                // Set the form data
                ViewBag.Administrator   = admin;
                ViewBag.TranslatedTexts = translatedTexts;
                ViewBag.ErrorMessage    = "&#149; " + translatedTexts.Get("error_login");

                // Return the index view
                return(View("index"));
            }
        } // End of the post login method
예제 #7
0
    } // End of the GetPassword method

    /// <summary>
    /// Get the client number for svea web pay
    /// </summary>
    /// <param name="type"> eg. HOSTED, INVOICE or PAYMENTPLAN</param>
    /// <param name="country">country code</param>
    /// <returns>The client number as an int</returns>
    public int GetClientNumber(Webpay.Integration.CSharp.Util.Constant.PaymentType type, Webpay.Integration.CSharp.Util.Constant.CountryCode country)
    {
        // Get the webshop settings
        KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();

        switch (country)
        {
        case Webpay.Integration.CSharp.Util.Constant.CountryCode.SE:
            if (type == Webpay.Integration.CSharp.Util.Constant.PaymentType.INVOICE)
            {
                return(Convert.ToInt32(webshopSettings.Get("SVEA-SE-INVOICE-CLIENT-NUMBER")));
            }
            if (type == Webpay.Integration.CSharp.Util.Constant.PaymentType.PAYMENTPLAN)
            {
                return(59999);
            }
            break;

        case Webpay.Integration.CSharp.Util.Constant.CountryCode.NO:
            if (type == Webpay.Integration.CSharp.Util.Constant.PaymentType.INVOICE)
            {
                return(Convert.ToInt32(webshopSettings.Get("SVEA-NO-INVOICE-CLIENT-NUMBER")));
            }
            if (type == Webpay.Integration.CSharp.Util.Constant.PaymentType.PAYMENTPLAN)
            {
                return(32503);
            }
            break;

        case Webpay.Integration.CSharp.Util.Constant.CountryCode.FI:
            if (type == Webpay.Integration.CSharp.Util.Constant.PaymentType.INVOICE)
            {
                return(Convert.ToInt32(webshopSettings.Get("SVEA-FI-INVOICE-CLIENT-NUMBER")));
            }
            if (type == Webpay.Integration.CSharp.Util.Constant.PaymentType.PAYMENTPLAN)
            {
                return(27136);
            }
            break;

        case Webpay.Integration.CSharp.Util.Constant.CountryCode.DK:
            if (type == Webpay.Integration.CSharp.Util.Constant.PaymentType.INVOICE)
            {
                return(Convert.ToInt32(webshopSettings.Get("SVEA-DK-INVOICE-CLIENT-NUMBER")));
            }
            if (type == Webpay.Integration.CSharp.Util.Constant.PaymentType.PAYMENTPLAN)
            {
                return(64008);
            }
            break;
        }
        return(0);
    } // End of the GetClientNumber method
예제 #8
0
    } // End of the GetSecretWord method

    /// <summary>
    /// Get the end point for svea web pay
    /// </summary>
    /// <param name="type"> eg. HOSTED, INVOICE or PAYMENTPLAN</param>
    /// <returns>The end point url as a string</returns>
    public string GetEndPoint(Webpay.Integration.CSharp.Util.Constant.PaymentType type)
    {
        // Get the webshop settings
        KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();

        // Get the test value
        string sveaTest = webshopSettings.Get("SVEA-TEST");

        // Check if we are in the test mode or the production mode
        if (sveaTest.ToLower() == "true")
        {
            return(type == Webpay.Integration.CSharp.Util.Constant.PaymentType.HOSTED ? Webpay.Integration.CSharp.Config.SveaConfig.GetTestPayPageUrl() : Webpay.Integration.CSharp.Config.SveaConfig.GetTestWebserviceUrl());
        }
        else
        {
            return(type == Webpay.Integration.CSharp.Util.Constant.PaymentType.HOSTED ? Webpay.Integration.CSharp.Config.SveaConfig.GetProdPayPageUrl() : Webpay.Integration.CSharp.Config.SveaConfig.GetProdWebserviceUrl());
        }
    } // End of the GetEndPoint method
예제 #9
0
        public ActionResult log_in_as(Int32 id = 0, string returnUrl = "")
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get webshop settings
            KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();
            string redirectHttps = webshopSettings.Get("REDIRECT-HTTPS");

            // Create the customer cookie
            HttpCookie customerCookie = new HttpCookie("CustomerCookie");
            customerCookie.Value = Tools.ProtectCookieValue(id.ToString(), "CustomerLogin");
            customerCookie.Expires = DateTime.UtcNow.AddDays(1);
            customerCookie.HttpOnly = true;
            customerCookie.Secure = redirectHttps.ToLower() == "true" ? true : false;
            Response.Cookies.Add(customerCookie);

            // Redirect the user to the start page
            return RedirectToAction("index", "home");

        } // End of the log_in_as method
        public ActionResult index(FormCollection collection)
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query paramaters
            ViewBag.QueryParams = new QueryParams(Request);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("~/Views/admin_default/index.cshtml");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Update all the webshop settings
            foreach(string key in collection.Keys)
            {
                // Get the value
                string value = collection[key];
                value = value.Length > 100 ? value.Substring(0, 100) : value;

                // Update the value for the key
                WebshopSetting.Update(key, collection[key]);
            }

            // Return the default view
            return RedirectToAction("index", "admin_default");

        } // End of the index method
예제 #11
0
        public ActionResult layout(string id = "")
        {
            // Create a new cookie
            HttpCookie aCookie = new HttpCookie("LayoutType");
            aCookie.Value = id;

            // Get webshop settings
            KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();
            string redirectHttps = webshopSettings.Get("REDIRECT-HTTPS");

            // Set the expiration and add the cookie
            aCookie.Expires = DateTime.UtcNow.AddDays(1);
            aCookie.HttpOnly = true;
            aCookie.Secure = redirectHttps.ToLower() == "true" ? true : false;
            Response.Cookies.Add(aCookie);

            // Redirect the user to the new url
            return Redirect("/");

        } // End of the layout method
        public ActionResult index()
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query paramaters
            ViewBag.QueryParams = new QueryParams(Request);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("~/Views/admin_default/index.cshtml");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Get the default admin language
            Int32 adminLanguageId = currentDomain.back_end_language;

            // Add data to the view
            ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC");
            ViewBag.WebshopSettings = WebshopSetting.GetAllFromCache();

            // Return the view
            return View();

        } // End of the index method
예제 #13
0
    } // End of the GetUsername method

    /// <summary>
    /// Get the password for svea web pay
    /// </summary>
    /// <param name="type"> eg. HOSTED, INVOICE or PAYMENTPLAN</param>
    /// <param name="country">country code</param>
    /// <returns>The password as a string</returns>
    public string GetPassword(Webpay.Integration.CSharp.Util.Constant.PaymentType type, Webpay.Integration.CSharp.Util.Constant.CountryCode country)
    {
        // Get the webshop settings
        KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();

        if (type == Webpay.Integration.CSharp.Util.Constant.PaymentType.INVOICE || type == Webpay.Integration.CSharp.Util.Constant.PaymentType.PAYMENTPLAN)
        {
            switch (country)
            {
            case Webpay.Integration.CSharp.Util.Constant.CountryCode.SE:
                return(webshopSettings.Get("SVEA-SE-PASSWORD"));

            case Webpay.Integration.CSharp.Util.Constant.CountryCode.NO:
                return(webshopSettings.Get("SVEA-NO-PASSWORD"));

            case Webpay.Integration.CSharp.Util.Constant.CountryCode.FI:
                return(webshopSettings.Get("SVEA-FI-PASSWORD"));

            case Webpay.Integration.CSharp.Util.Constant.CountryCode.DK:
                return(webshopSettings.Get("SVEA-DK-PASSWORD"));
            }
        }
        return("");
    } // End of the GetPassword method
예제 #14
0
        public async Task <HttpResponseMessage> payson_notification(Int32 id = 0)
        {
            // Read the content
            string content = await Request.Content.ReadAsStringAsync();

            // Check for errors
            if (content == null || content == "")
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The content is null or empty"));
            }

            // Get the webshop settings
            KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();

            // Get the order
            Order order = Order.GetOneById(id);

            // Make sure that the orde exists
            if (order == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The order does not exist"));
            }

            // Get credentials
            string userId     = webshopSettings.Get("PAYSON-AGENT-ID");
            string md5Key     = webshopSettings.Get("PAYSON-MD5-KEY");
            bool   paysonTest = false;

            bool.TryParse(webshopSettings.Get("PAYSON-TEST"), out paysonTest);

            // Create the payson api
            PaysonIntegration.PaysonApi paysonApi = new PaysonIntegration.PaysonApi(userId, md5Key, null, paysonTest);

            // Validate the content
            PaysonIntegration.Response.ValidateResponse validateResponse = paysonApi.MakeValidateIpnContentRequest(content);

            // Check if the validation was successful
            if (validateResponse.Success)
            {
                // Get the data
                PaysonIntegration.Utils.PaymentType?  paymentType   = validateResponse.ProcessedIpnMessage.PaymentType;
                PaysonIntegration.Utils.PaymentStatus?paymentStatus = validateResponse.ProcessedIpnMessage.PaymentStatus;
                PaysonIntegration.Utils.InvoiceStatus?invoiceStatus = validateResponse.ProcessedIpnMessage.InvoiceStatus;

                // Check the payment type and payment status
                if (paymentType == PaysonIntegration.Utils.PaymentType.Direct && paymentStatus == PaysonIntegration.Utils.PaymentStatus.Completed)
                {
                    // Update the order status
                    Order.UpdatePaymentStatus(id, "payment_status_paid");

                    // Add customer files
                    CustomerFile.AddCustomerFiles(order);
                }
                else if (paymentType == PaysonIntegration.Utils.PaymentType.Invoice && invoiceStatus == PaysonIntegration.Utils.InvoiceStatus.OrderCreated)
                {
                    // Update the order status
                    Order.UpdatePaymentStatus(id, "payment_status_invoice_approved");

                    // Add customer files
                    CustomerFile.AddCustomerFiles(order);
                }
            }

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been processed"));
        } // End of the payson_notification method
예제 #15
0
        } // End of the UpdatePaymentStatus method

        /// <summary>
        /// Respond to an updated order status
        /// </summary>
        /// <param name="order"></param>
        /// <param name="paymentOption"></param>
        /// <param name="orderStatus"></param>
        /// <returns></returns>
        private string UpdateOrderStatus(Order order, PaymentOption paymentOption, string orderStatus)
        {
            // Create the string to return
            string error_message = "";

            // Get the current domain
            Domain domain = Tools.GetCurrentDomain();

            // Get webshop settings
            KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();

            // Check the order status
            if (orderStatus == "order_status_delivered")
            {
                if(paymentOption.connection == 102) // Payson invoice
                {
                    // Get credentials
                    string paysonEmail = webshopSettings.Get("PAYSON-EMAIL");
                    string userId = webshopSettings.Get("PAYSON-AGENT-ID");
                    string md5Key = webshopSettings.Get("PAYSON-MD5-KEY");
                    bool paysonTest = false;
                    bool.TryParse(webshopSettings.Get("PAYSON-TEST"), out paysonTest);

                    // Create the api
                    PaysonIntegration.PaysonApi paysonApi = new PaysonIntegration.PaysonApi(userId, md5Key, null, paysonTest);

                    // Update the order
                    PaysonIntegration.Data.PaymentUpdateData paymentUpdateData = new PaysonIntegration.Data.PaymentUpdateData(order.payment_token, PaysonIntegration.Utils.PaymentUpdateAction.ShipOrder);
                    PaysonIntegration.Response.PaymentUpdateResponse paymentUpdateResponse = paysonApi.MakePaymentUpdateRequest(paymentUpdateData);

                    // Check if the response is successful
                    if (paymentUpdateResponse != null && paymentUpdateResponse.Success == false)
                    {
                        // Set error messages
                        foreach (string key in paymentUpdateResponse.ErrorMessages)
                        {
                            error_message += "&#149; " + "Payson: " + paymentUpdateResponse.ErrorMessages[key] + "<br/>";
                        }
                    }
                }
                else if(paymentOption.connection == 301) // Svea invoice
                {
                    // Get the order rows
                    List<OrderRow> orderRows = OrderRow.GetByOrderId(order.id);

                    // Create the payment configuration
                    SveaSettings sveaConfiguration = new SveaSettings();

                    // Create the order builder
                    Webpay.Integration.CSharp.Order.Handle.DeliverOrderBuilder inoviceBuilder = Webpay.Integration.CSharp.WebpayConnection.DeliverOrder(sveaConfiguration);

                    // Add order rows
                    for (int i = 0; i < orderRows.Count; i++)
                    {
                        // Get the unit
                        Unit unit = Unit.GetOneById(orderRows[i].unit_id, domain.back_end_language);

                        // Create an order item
                        Webpay.Integration.CSharp.Order.Row.OrderRowBuilder orderItem = new Webpay.Integration.CSharp.Order.Row.OrderRowBuilder();
                        orderItem.SetArticleNumber(orderRows[i].product_code);
                        orderItem.SetName(orderRows[i].product_name);
                        orderItem.SetQuantity(orderRows[i].quantity);
                        orderItem.SetUnit(unit.unit_code);
                        orderItem.SetAmountExVat(orderRows[i].unit_price);
                        orderItem.SetVatPercent(orderRows[i].vat_percent * 100);

                        // Add the order item
                        inoviceBuilder.AddOrderRow(orderItem);
                    }

                    // Get the order id
                    Int64 sveaOrderId = 0;
                    Int64.TryParse(order.payment_token, out sveaOrderId);

                    // Set invoice values
                    inoviceBuilder.SetOrderId(sveaOrderId);
                    inoviceBuilder.SetNumberOfCreditDays(15);
                    inoviceBuilder.SetInvoiceDistributionType(Webpay.Integration.CSharp.Util.Constant.InvoiceDistributionType.POST);
                    inoviceBuilder.SetCountryCode(SveaSettings.GetSveaCountryCode(order.country_code));

                    // Make the request to send the invoice
                    Webpay.Integration.CSharp.WebpayWS.DeliverOrderEuResponse deliverOrderResponse = inoviceBuilder.DeliverInvoiceOrder().DoRequest();
                    
                    // Check if the response is successful
                    if (deliverOrderResponse.Accepted == false)
                    {
                        // Set error messages
                        error_message += "&#149; " + "Svea code: " + deliverOrderResponse.ResultCode.ToString() + "<br/>";
                        error_message += "&#149; " + "Svea message: " + deliverOrderResponse.ErrorMessage + "<br/>";
                    }
                }
                else if (paymentOption.connection >= 400 && paymentOption.connection <= 499) // Payex
                {
                    // Check the transaction
                    Dictionary<string, string> payexResponse = PayExManager.CheckTransaction(order, webshopSettings);

                    // Get response variables
                    string error_code = payexResponse.ContainsKey("error_code") == true ? payexResponse["error_code"] : "";
                    string description = payexResponse.ContainsKey("description") == true ? payexResponse["description"] : "";
                    string parameter_name = payexResponse.ContainsKey("parameter_name") == true ? payexResponse["parameter_name"] : "";
                    string transaction_status = payexResponse.ContainsKey("transaction_status") == true ? payexResponse["transaction_status"] : "";
                    string transaction_number = payexResponse.ContainsKey("transaction_number") == true ? payexResponse["transaction_number"] : "";

                    // Check if the response was successful
                    if (error_code.ToUpper() == "OK")
                    {
                        if(transaction_status == "3") // Authorize
                        {
                            // Capture the transaction
                            payexResponse = PayExManager.CaptureTransaction(order);

                            // Get response variables
                            error_code = payexResponse.ContainsKey("error_code") == true ? payexResponse["error_code"] : "";
                            description = payexResponse.ContainsKey("description") == true ? payexResponse["description"] : "";
                            parameter_name = payexResponse.ContainsKey("parameter_name") == true ? payexResponse["parameter_name"] : "";
                            transaction_status = payexResponse.ContainsKey("transaction_status") == true ? payexResponse["transaction_status"] : "";
                            transaction_number = payexResponse.ContainsKey("transaction_number") == true ? payexResponse["transaction_number"] : "";
                            string transaction_number_original = payexResponse.ContainsKey("transaction_number_original") == true ? payexResponse["transaction_number_original"] : "";

                            if(error_code.ToUpper() != "OK" || transaction_status != "6")
                            {
                                // Set error messages
                                error_message += "&#149; " + "Payex code: " + error_code + "<br/>";
                                error_message += "&#149; " + "Payex message: " + description + "<br/>";
                                error_message += "&#149; " + "Payex parameter: " + parameter_name + "<br/>";
                                error_message += "&#149; " + "Payex status: " + transaction_status + "<br/>";
                                error_message += "&#149; " + "Payex number (original): " + transaction_number + "<br/>";
                            }
                            else
                            {
                                // Update the transaction number for the order
                                Order.SetPaymentToken(order.id, transaction_number);
                            }
                        }
                    }
                    else
                    {
                        // Set error messages
                        error_message += "&#149; " + "Payex code: " + error_code + "<br/>";
                        error_message += "&#149; " + "Payex message: " + description + "<br/>";
                        error_message += "&#149; " + "Payex parameter: " + parameter_name + "<br/>";
                        error_message += "&#149; " + "Payex status: " + transaction_status + "<br/>";
                        error_message += "&#149; " + "Payex number: " + transaction_number + "<br/>";
                    }
                }
            }
            else if (orderStatus == "order_status_cancelled")
            {
                if(paymentOption.connection >= 100 && paymentOption.connection <= 199) // Payson
                {
                    // Get credentials
                    string paysonEmail = webshopSettings.Get("PAYSON-EMAIL");
                    string userId = webshopSettings.Get("PAYSON-AGENT-ID");
                    string md5Key = webshopSettings.Get("PAYSON-MD5-KEY");
                    bool paysonTest = false;
                    bool.TryParse(webshopSettings.Get("PAYSON-TEST"), out paysonTest);

                    // Create the api
                    PaysonIntegration.PaysonApi paysonApi = new PaysonIntegration.PaysonApi(userId, md5Key, null, paysonTest);

                    // Get details about the payment status
                    PaysonIntegration.Response.PaymentDetailsResponse paysonResponse = paysonApi.MakePaymentDetailsRequest(new PaysonIntegration.Data.PaymentDetailsData(order.payment_token));

                    // Get the type and status of the payment
                    PaysonIntegration.Utils.PaymentType? paymentType = paysonResponse.PaymentDetails.PaymentType;
                    PaysonIntegration.Utils.PaymentStatus? paymentStatus = paysonResponse.PaymentDetails.PaymentStatus;
                    PaysonIntegration.Utils.InvoiceStatus? invoiceStatus = paysonResponse.PaymentDetails.InvoiceStatus;

                    // Payment update
                    PaysonIntegration.Data.PaymentUpdateData paymentUpdateData = null;
                    PaysonIntegration.Response.PaymentUpdateResponse paymentUpdateResponse = null;

                    if (paymentType == PaysonIntegration.Utils.PaymentType.Direct && paymentStatus == PaysonIntegration.Utils.PaymentStatus.Completed)
                    {
                        // Refund the payment
                        paymentUpdateData = new PaysonIntegration.Data.PaymentUpdateData(order.payment_token, PaysonIntegration.Utils.PaymentUpdateAction.Refund);
                        paymentUpdateResponse = paysonApi.MakePaymentUpdateRequest(paymentUpdateData);
                    }
                    else if (paymentType == PaysonIntegration.Utils.PaymentType.Invoice && invoiceStatus == PaysonIntegration.Utils.InvoiceStatus.OrderCreated)
                    {
                        // Cancel the order
                        paymentUpdateData = new PaysonIntegration.Data.PaymentUpdateData(order.payment_token, PaysonIntegration.Utils.PaymentUpdateAction.CancelOrder);
                        paymentUpdateResponse = paysonApi.MakePaymentUpdateRequest(paymentUpdateData);
                    }
                    else if (paymentType == PaysonIntegration.Utils.PaymentType.Invoice && (invoiceStatus == PaysonIntegration.Utils.InvoiceStatus.Shipped 
                        || invoiceStatus == PaysonIntegration.Utils.InvoiceStatus.Done))
                    {
                        // Credit the order
                        paymentUpdateData = new PaysonIntegration.Data.PaymentUpdateData(order.payment_token, PaysonIntegration.Utils.PaymentUpdateAction.CreditOrder);
                        paymentUpdateResponse = paysonApi.MakePaymentUpdateRequest(paymentUpdateData);
                    }

                    // Check if there was any errors
                    if (paymentUpdateResponse != null && paymentUpdateResponse.Success == false)
                    {
                        // Set error messages
                        foreach (string key in paymentUpdateResponse.ErrorMessages)
                        {
                            error_message += "&#149; " + "Payson: " + paymentUpdateResponse.ErrorMessages[key] + "<br/>";
                        }
                    }
                }
                else if(paymentOption.connection == 201) // PayPal
                {
                    // Get credentials
                    string paypalClientId = webshopSettings.Get("PAYPAL-CLIENT-ID");
                    string paypalClientSecret = webshopSettings.Get("PAYPAL-CLIENT-SECRET");
                    string paypalMode = webshopSettings.Get("PAYPAL-MODE");
                    Dictionary<string, string> config = new Dictionary<string, string> { { "mode", paypalMode } };

                    try
                    {
                        // Create the credential token
                        PayPal.OAuthTokenCredential tokenCredential = new PayPal.OAuthTokenCredential(paypalClientId, paypalClientSecret, config);

                        // Create the api context
                        PayPal.APIContext paypalContext = new PayPal.APIContext(tokenCredential.GetAccessToken());
                        paypalContext.Config = config;

                        // Look up the sale
                        PayPal.Api.Payments.Sale sale = PayPal.Api.Payments.Sale.Get(paypalContext, order.payment_token);

                        if (sale.state == "completed")
                        {
                            // Refund the payment
                            paypalContext.HTTPHeaders = null;
                            PayPal.Api.Payments.Refund refund = sale.Refund(paypalContext, new PayPal.Api.Payments.Refund());

                            if(refund.state != "completed")
                            {
                                error_message += "&#149; " + "PayPal: " + refund.state;
                            }
                        }
                        else
                        {
                            error_message += "&#149; " + "PayPal: " + sale.state;
                        }
                    }
                    catch (Exception ex)
                    {
                        error_message += "&#149; PayPal: " + ex.Message;
                    }
                }
                else if(paymentOption.connection == 301) // Svea invoice
                {
                    // Create the payment configuration
                    SveaSettings sveaConfiguration = new SveaSettings();

                    // Get the order id
                    Int64 sveaOrderId = 0;
                    Int64.TryParse(order.payment_token, out sveaOrderId);

                    // Cancel the order
                    Webpay.Integration.CSharp.Order.Handle.CloseOrderBuilder closeOrder = Webpay.Integration.CSharp.WebpayConnection.CloseOrder(sveaConfiguration);
                    closeOrder.SetOrderId(sveaOrderId);
                    closeOrder.SetCountryCode(SveaSettings.GetSveaCountryCode(order.country_code));
                    Webpay.Integration.CSharp.WebpayWS.CloseOrderEuResponse closeOrderResponse = closeOrder.CloseInvoiceOrder().DoRequest();

                    // Check if the response is successful
                    if (closeOrderResponse.Accepted == false)
                    {
                        // Set error messages
                        error_message += "&#149; " + "Svea code: " + closeOrderResponse.ResultCode.ToString() + "<br/>";
                        error_message += "&#149; " + "Svea message: " + closeOrderResponse.ErrorMessage + "<br/>";
                    }
                }
                else if(paymentOption.connection >= 400 && paymentOption.connection <= 499) // Payex
                {
                    // Check the transaction
                    Dictionary<string, string> payexResponse = PayExManager.CheckTransaction(order, webshopSettings);

                    // Get response variables
                    string error_code = payexResponse.ContainsKey("error_code") == true ? payexResponse["error_code"] : "";
                    string description = payexResponse.ContainsKey("description") == true ? payexResponse["description"] : "";
                    string parameter_name = payexResponse.ContainsKey("parameter_name") == true ? payexResponse["parameter_name"] : "";
                    string transaction_status = payexResponse.ContainsKey("transaction_status") == true ? payexResponse["transaction_status"] : "";
                    string transaction_number = payexResponse.ContainsKey("transaction_number") == true ? payexResponse["transaction_number"] : "";

                    // Check if the response was successful
                    if(error_code.ToUpper() == "OK")
                    {
                        // Check if we should cancel or credit the order
                        if(transaction_status == "3") // Authorize
                        {
                            // Cancel the transaction
                            payexResponse = PayExManager.CancelTransaction(order, webshopSettings);

                            // Get response variables
                            error_code = payexResponse.ContainsKey("error_code") == true ? payexResponse["error_code"] : "";
                            description = payexResponse.ContainsKey("description") == true ? payexResponse["description"] : "";
                            parameter_name = payexResponse.ContainsKey("parameter_name") == true ? payexResponse["parameter_name"] : "";
                            transaction_status = payexResponse.ContainsKey("transaction_status") == true ? payexResponse["transaction_status"] : "";
                            transaction_number = payexResponse.ContainsKey("transaction_number") == true ? payexResponse["transaction_number"] : "";

                            if(error_code.ToUpper() != "OK" || transaction_status != "4")
                            {
                                // Set error messages
                                error_message += "&#149; " + "Payex code: " + error_code + "<br/>";
                                error_message += "&#149; " + "Payex message: " + description + "<br/>";
                                error_message += "&#149; " + "Payex parameter: " + parameter_name + "<br/>";
                                error_message += "&#149; " + "Payex status: " + transaction_status + "<br/>";
                                error_message += "&#149; " + "Payex number: " + transaction_number + "<br/>";
                            }
                        }
                        else if(transaction_status == "0" || transaction_status == "6") // Sale or capture
                        {
                            // Get the order rows
                            List<OrderRow> orderRows = OrderRow.GetByOrderId(order.id);

                            // Credit the transaction
                            payexResponse = PayExManager.CreditTransaction(order, orderRows, webshopSettings);

                            // Get response variables
                            error_code = payexResponse.ContainsKey("error_code") == true ? payexResponse["error_code"] : "";
                            description = payexResponse.ContainsKey("description") == true ? payexResponse["description"] : "";
                            parameter_name = payexResponse.ContainsKey("parameter_name") == true ? payexResponse["parameter_name"] : "";
                            transaction_status = payexResponse.ContainsKey("transaction_status") == true ? payexResponse["transaction_status"] : "";
                            transaction_number = payexResponse.ContainsKey("transaction_number") == true ? payexResponse["transaction_number"] : "";

                            if (error_code.ToUpper() != "OK" || transaction_status != "2")
                            {
                                // Set error messages
                                error_message += "&#149; " + "Payex code: " + error_code + "<br/>";
                                error_message += "&#149; " + "Payex message: " + description + "<br/>";
                                error_message += "&#149; " + "Payex parameter: " + parameter_name + "<br/>";
                                error_message += "&#149; " + "Payex status: " + transaction_status + "<br/>";
                                error_message += "&#149; " + "Payex number: " + transaction_number + "<br/>";
                            }
                        }
                    }
                    else
                    {
                        // Set error messages
                        error_message += "&#149; " + "Payex code: " + error_code + "<br/>";
                        error_message += "&#149; " + "Payex message: " + description + "<br/>";
                        error_message += "&#149; " + "Payex parameter: " + parameter_name + "<br/>";
                        error_message += "&#149; " + "Payex status: " + transaction_status + "<br/>";
                        error_message += "&#149; " + "Payex number: " + transaction_number + "<br/>";
                    }
                }
            }

            // Return the error message
            return error_message;

        } // End of the UpdateOrderStatus method
예제 #16
0
    } // End of the SendEmailToHost method

    /// <summary>
    /// Send an email to the customer service
    /// </summary>
    /// <param name="customerAddress">The customer address</param>
    /// <param name="subject">The subject for the mail message</param>
    /// <param name="message">The message</param>
    public static bool SendEmailToCustomerService(string customerAddress, string subject, string message)
    {
        // Create the boolean to return
        bool successful = true;

        // Get the company settings
        KeyStringList webshopSettings = WebshopSetting.GetAllFromCache();

        // Create variables
        string host = webshopSettings.Get("SEND-EMAIL-HOST");
        Int32 port = 0;
        Int32.TryParse(webshopSettings.Get("SEND-EMAIL-PORT"), out port);
        string emailAddress = webshopSettings.Get("SEND-EMAIL-ADDRESS");
        string password = webshopSettings.Get("SEND-EMAIL-PASSWORD");
        string toAddress = webshopSettings.Get("CUSTOMER-SERVICE-EMAIL");
        string useSSL = webshopSettings.Get("SEND-EMAIL-USE-SSL");

        // Get the customer email
        MailAddress copyAddress = AnnytabDataValidation.IsEmailAddressValid(customerAddress);

        // Create the SmtpClient instance
        SmtpClient smtp = new SmtpClient(host, port);
        smtp.Credentials = new NetworkCredential(emailAddress, password);

        // Check if we should enable SSL
        if (useSSL.ToLower() == "true")
        {
            smtp.EnableSsl = true;
        }

        // Try to send the mail message
        try
        {
            // Create the mail message instance
            MailMessage mailMessage = new MailMessage(emailAddress, toAddress);

            // Add a carbon copy to the customer
            if (copyAddress != null)
            {
                mailMessage.CC.Add(copyAddress);
            }

            // Create the mail message
            mailMessage.Subject = subject;
            mailMessage.Body = message;
            mailMessage.IsBodyHtml = true;

            // Send the mail message
            smtp.Send(mailMessage);

        }
        catch (Exception ex)
        {
            string exceptionMessage = ex.Message;
            successful = false;
        }

        // Return the boolean
        return successful;

    } // End of the SendEmailToCustomerService method