示例#1
0
        /// <summary>
        /// Returns charge description.
        /// </summary>
        /// <param name="options">Payment type.</param>
        /// <param name="amount">Charge amount.</param>
        /// <returns>Charge description.</returns>
        private string GetChargeDescription(Ifly.Payments.PaymentOptions options, int?amount = null)
        {
            string terminology = Ifly.Resources.Frontpage.ResourceManager.GetString(string.Format(
                                                                                        "Account_Payment_{0}_{1}", Enum.GetName(typeof(SubscriptionType), options.Subscription), Enum.GetName(typeof(SubscriptionDuration), options.Duration)), Ifly.Resources.Frontpage.Culture);

            return(amount.HasValue ? string.Format(terminology, (int)(amount.Value / 100)) : terminology);
        }
示例#2
0
        public ActionResult ReadyToCharge()
        {
            Ifly.Payments.PaymentOptions options = null;
            SubscriptionType             subscriptionType = SubscriptionType.Basic;
            string stripeToken = string.Empty, errorCode = string.Empty;
            SubscriptionDuration duration = SubscriptionDuration.OneMonth;

            if (Enum.TryParse <SubscriptionType>(Request["SubscriptionType"], out subscriptionType) && !string.IsNullOrEmpty(stripeToken = Request["stripeToken"]))
            {
                Enum.TryParse <SubscriptionDuration>(Request["Duration"], out duration);

                options = new Ifly.Payments.PaymentOptions(subscriptionType, duration);

                try
                {
                    Resolver.Resolve <Payments.IPaymentProcessor>().TryCreateCharge(Ifly.ApplicationContext.Current.User.Id,
                                                                                    options, stripeToken, GetChargeDescription(options, null));

                    // Updating subscription type for all user presentations.
                    UpdatePresentationSubscriptionType(Ifly.ApplicationContext.Current.User.Id, subscriptionType);
                }
                catch (Ifly.Payments.ChargeException ex)
                {
                    errorCode = Enum.GetName(typeof(Ifly.Payments.ChargeException.ChargeFailureReason), ex.Reason);

                    Logging.Logger.Current.Write(ex.DiagnosticsData.ToString(), Logging.MessageLevel.Error);

                    MessageQueueManager.Current.GetQueue(MessageQueueType.Email).AddMessages(new Message[] { new Message()
                                                                                                             {
                                                                                                                 Id      = Guid.NewGuid().ToString(),
                                                                                                                 Subject = string.Format("Charge failed ({0})", Guid.NewGuid()),
                                                                                                                 Body    = ex.DiagnosticsData.ToString()
                                                                                                             } });
                }
            }

            return(Redirect(string.Concat("/account", !string.IsNullOrEmpty(errorCode) ?
                                          string.Format("?payment:error={0}", errorCode) : "?payment:success=1")));
        }