Exemplo n.º 1
0
        /// <summary>
        /// Get all countries from Billing API, wrapping with a process cache.
        /// </summary>
        /// <param name="httpContextBase">HttpContext to cache in</param>
        /// <param name="service">Billing API endpoint</param>
        /// <returns>All countries</returns>
        public static List<OrderServiceReferences.AtomiaBillingPublicService.Country> GetAllCountries(System.Web.HttpContextBase httpContextBase, OrderServiceReferences.AtomiaBillingPublicService.AtomiaBillingPublicService service)
        {
            List<OrderServiceReferences.AtomiaBillingPublicService.Country> countryList = null;

            if (httpContextBase.Application["AllCountries"] == null)
            {
                countryList = service.GetCountries().ToList();
                httpContextBase.Application["AllCountries"] = countryList;
            }
            else
            {
                countryList = (List<OrderServiceReferences.AtomiaBillingPublicService.Country>) httpContextBase.Application["AllCountries"];
            }

            return countryList;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the payment transaction.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="order">The order.</param>
        /// <param name="paidAmount">The paid amount.</param>
        /// <param name="returnUrl">The return URL.</param>
        /// <param name="transaction">The transaction.</param>
        /// <returns>Success of creation.</returns>
        public static string CreatePaymentTransaction(Controller controller, OrderServiceReferences.AtomiaBillingPublicService.PublicOrder order, decimal paidAmount, string returnUrl, PublicPaymentTransaction transaction)
        {
            // set the return URL, if redirection outside our application is required
            List<string> tmpList = returnUrl.TrimStart('/').Split('/').ToList();
            var currentUrl = controller.Url.RequestContext.HttpContext.Request.Url;
            string appUrl = currentUrl == null
                                ? controller.HttpContext.Application["OrderApplicationRawURL"].ToString()
                                : string.Format("{0}://{1}/", currentUrl.Scheme, currentUrl.Authority);

            if (appUrl.EndsWith(tmpList[0]))
            {
                tmpList.RemoveAt(0);
            }

            returnUrl = string.Empty;
            for (int i = 0; i < tmpList.Count; i++)
            {
                if (i < tmpList.Count - 1)
                {
                    returnUrl += tmpList[i] + '/';
                }
                else
                {
                    returnUrl += tmpList[i];
                }
            }

            transaction.ReturnUrl = appUrl.TrimEnd(new[] { '/' }) + '/' + returnUrl.TrimStart(new[] { '/' });

            var service = GeneralHelper.GetPublicOrderService(controller.HttpContext.ApplicationInstance.Context);
            PublicPaymentTransaction returnedTransaction = service.MakePayment(transaction);

            if (returnedTransaction.Status.ToUpper() == "IN_PROGRESS" && !string.IsNullOrEmpty(returnedTransaction.RedirectUrl))
            {
                return returnedTransaction.RedirectUrl;
            }

            if (returnedTransaction.Status.ToUpper() == "OK")
            {
                return string.Empty;
            }

            return returnedTransaction.Status.ToUpper() == "FRAUD_DETECTED"
                   || returnedTransaction.Status.ToUpper() == "FAILED"
                       ? controller.Url.Action("PaymentFailed")
                       : transaction.ReturnUrl;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the payment transaction.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="order">The order.</param>
        /// <param name="paidAmount">The paid amount.</param>
        /// <param name="paymentMethod">The payment method.</param>
        /// <returns>Creation of transaction success</returns>
        private string CreatePaymentTransaction(Controller controller, OrderServiceReferences.AtomiaBillingPublicService.PublicOrder order, decimal paidAmount, string paymentMethod)
        {
            PublicPaymentTransaction transaction = PaymentHelper.FillPaymentTransactionForOrder(order, Request, paidAmount, paymentMethod);

            string action;

            if (paymentMethod == "CCPayment")
            {
                action = controller.Url.Action("Payment", new { controller = "PublicOrder" });

            }
            else
            {
                if (controller.HttpContext != null && controller.HttpContext.Application != null &&
                    controller.HttpContext.Application.AllKeys.Contains(paymentMethod + "PaymentReturnAction") &&
                    !string.IsNullOrEmpty((string)controller.HttpContext.Application[paymentMethod + "PaymentReturnAction"]))
                {
                    action = controller.Url.Action((string)controller.HttpContext.Application[paymentMethod + "PaymentReturnAction"], new { controller = "PublicOrder" });
                }
                else
                {
                    action = controller.Url.Action("Payment", new { controller = "PublicOrder" });
                }

                List<AttributeData> attributeDatas = transaction.Attributes.ToList();
                if (!attributeDatas.Any(item => item.Name == "CancelUrl"))
                {
                    attributeDatas.Add(
                        new AttributeData
                        {
                            Name = "CancelUrl",
                            Value = controller.Url.Action("Select", new { controller = "PublicOrder" })
                        });
                }
                else
                {
                    attributeDatas.First(item => item.Name == "CancelUrl").Value =
                        controller.Url.Action("Select", new { controller = "PublicOrder" });
                }
            }

            return PaymentHelper.CreatePaymentTransaction(controller, order, paidAmount, action, transaction);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fills the payment transaction for invoice.
        /// </summary>
        /// <param name="order">The order.</param>
        /// <param name="request">The request.</param>
        /// <param name="paidAmount">The paid amount.</param>
        /// <param name="paymentMethod">The payment method.</param>
        /// <returns>PaymentTransaction object</returns>
        public static PublicPaymentTransaction FillPaymentTransactionForOrder(OrderServiceReferences.AtomiaBillingPublicService.PublicOrder order, HttpRequestBase request, decimal paidAmount, string paymentMethod)
        {
            // Fill transaction
            var paymentTransaction = new PublicPaymentTransaction { GuiPluginName = paymentMethod };
            List<AttributeData> attrData = new List<AttributeData>();
            foreach (var key in GuiPaymentPluginRequestHelper.RequestToCustomAttributes(request))
            {
                attrData.Add(new AttributeData { Name = key.Key, Value = key.Value });
            }

            paymentTransaction.Attributes = attrData.ToArray();
            paymentTransaction.CurrencyCode = order.Currency;
            paymentTransaction.TransactionReference = order.Number;
            paymentTransaction.Amount = paidAmount;

            if (paymentTransaction.Amount <= decimal.Zero)
            {
                throw new Exception(String.Format("Total:{0}, paidAmmount:{1}, OrderNumber:{2}", order.Total, paidAmount, order.Number));
            }

            return paymentTransaction;
        }