public ApiResponse ChangePlan(ChangePlanRequest postedModel) { var stripeApi = new StripeApi(); var expirationSplit = postedModel.Expiration.Split('/'); try { if (string.IsNullOrWhiteSpace(Account.StripeCustomerId) || stripeApi.GetCustomer(Account.StripeCustomerId) == null) { var response = stripeApi.StartMonthly(Account.Id.ToString(), LoggedInUser.Email, postedModel.PlanId, postedModel.CardNumber, expirationSplit[0], expirationSplit[1], postedModel.Cvc); Account.StripeCustomerId = response; } else { var response = stripeApi.UpdateMonthly(Account.StripeCustomerId, postedModel.PlanId, postedModel.CardNumber, expirationSplit[0], expirationSplit[1], postedModel.Cvc); } } catch (StripeException exception) { return(new ApiResponse(exception.StripeError.Message)); } Account.ActivePlanId = postedModel.PlanId; RavenSession.SaveChanges(); return(new ApiResponse(success: "Credit card added and your plan was changed successfuly, thanks for using Movid HEP.")); }
public CurrentAccountStatusViewModel GetCurrent() { if (string.IsNullOrWhiteSpace(Account.StripeCustomerId)) { var freeVm = new CurrentAccountStatusViewModel() { PlanName = "Free Trial", Price = 0, StartedOn = Account.CreatedDate, Quantity = 1, TrialLength = 30, StartDate = Account.CreatedDate }; return(freeVm); } var customer = new StripeApi().GetCustomer(Account.StripeCustomerId); var vm = new CurrentAccountStatusViewModel() { PlanName = customer.StripeSubscription.StripePlan.Name, Id = customer.StripeSubscription.StripePlan.Id, Price = customer.StripeSubscription.StripePlan.AmountInCents.Value * .01, StartedOn = customer.StripeSubscription.PeriodStart.Value, Quantity = customer.StripeSubscription.Quantity, StartDate = Account.CreatedDate, TrialLength = 30 }; return(vm); }
public List <PlanViewModel> GetSubscriptionOptions(string group) { var stripePlans = new StripeApi().GetPlans(); if (group.ToLower() == "upgrade") { stripePlans = stripePlans.Where(x => x.Id != "Free"); } return(stripePlans.Select(stripePlan => new PlanViewModel(stripePlan)).OrderBy(x => x.Ordinal).ToList()); }
private async Task <bool> ProcessStep21(IDbConnection c, IDbTransaction t, EnrollmentData enroll) { var dbTeamPlayer = GetTeamPlayer(c, t, enroll.IdTeam); // Calculate the amount of selected options (from teamData.enrollmentData) // To do that, get the aplicable workflow to this player and team var(total, selectedOptionsTotal) = GetPaymentAmounts(c, t, GetUserId(), enroll.IdTeam, enroll.IdTournament, dbTeamPlayer.EnrollmentData); if (selectedOptionsTotal > 0) { // Total before fees is more than 0, process charge. var amount = total; Audit.Information(this, "{0}: Players.Enrollment: Payment: {0}", GetUserId(), amount); // We get the card token from the client var cardToken = enroll.PaymentGatewayResult; if (cardToken == null) { throw new Exception("Error.NoCardToken"); } var orgSecrets = GetOrgWithSecrets(c, t); if (orgSecrets.PaymentGetawayType != "paypal") // Stripe { // Now, call the payment gateway with the card token and amount. var charge = await StripeApi.SendCharge(orgSecrets.PaymentKey, cardToken, orgSecrets.PaymentCurrency, amount, orgSecrets.PaymentDescription); if (!charge.Paid) { throw new Exception("Error.PaymentFailed"); } dbTeamPlayer.EnrollmentPaymentData = charge.Id; // Add user event for payment LogPaymentEvent(c, t, charge, enroll.IdPlayer, enroll.IdTeam, enroll.IdTournament); } else { // Paypal has already process the payment. var ev = new UserEvent { IdCreator = GetUserId(), IdUser = GetUserId(), TimeStamp = DateTime.Now, Description = Localization.Get("Pago de inscripciĆ³n", null), Type = (int)UserEventType.PlayerPaymentSuccess, Data1 = enroll.PaymentGatewayResult, Data2 = amount.ToString("N2"), Data3 = enroll.IdTeam.ToString() }; c.Insert(ev, t); } // Notify org admins there is a new enrollment pending verification var(userName, teamName, tournamentName) = GetPlayerTeamTournament(c, t, GetUserId(), dbTeamPlayer.IdTeam, enroll.IdTournament); mNotifications.NotifyAdminsGenericEmail(Request, c, t, GetUserId(), Localization.Get("Nuevo pago de jugador", null), Localization.Get("El jugador '{0}' ha hecho un pago de inscripciĆ³n de {1:0.00} {2} en el equipo '{3}', torneo '{4}'", null, userName, amount, orgSecrets.PaymentCurrency, teamName, tournamentName), null); } // Set player status as paid. If amount before fees was 0, we still do this to move to next step. dbTeamPlayer.Status |= (int)TeamPlayerStatusFlags.Paid; dbTeamPlayer.EnrollmentStep = 100; dbTeamPlayer.EnrollmentDate = DateTime.Now; c.Update(dbTeamPlayer, t); return(true); }