public GetCustomerResponse GetCustomerInformation(string customerId) { var response = new GetCustomerResponse(); var customerService = new StripeCustomerService(); try { StripeCustomer stripeCustomer = customerService.Get(customerId); MapStripeCustomerTo(stripeCustomer, response); response.Success = true; } catch (StripeException ex) { response.Success = false; response.Message = ex.Message; return(response); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
private void MapStripeCustomerTo(StripeCustomer stripeCustomer, GetCustomerResponse response) { if (response == null) { return; } response.Email = CleanUpStripeEmail(stripeCustomer.Email); response.Id = stripeCustomer.Id; response.Description = stripeCustomer.Description; if (stripeCustomer.StripeSubscription != null) { response.PlanId = stripeCustomer.StripeSubscription.StripePlan.Id; response.PlanName = stripeCustomer.StripeSubscription.StripePlan.Name; decimal planAmount = (decimal)stripeCustomer.StripeSubscription.StripePlan.AmountInCents; planAmount = planAmount / 100; response.PlanAmount = planAmount; response.PlanStatus = stripeCustomer.StripeSubscription.Status; } if (stripeCustomer.StripeNextRecurringCharge != null) { decimal nextCharge = (decimal)stripeCustomer.StripeNextRecurringCharge.AmountInCents; nextCharge = nextCharge / 100; string nextStatus = "Next charge " + nextCharge.ToString("C") + " on " + stripeCustomer.StripeNextRecurringCharge.Date; response.NextCharge = nextStatus; } if (stripeCustomer.StripeCard == null) { response.HasCard = false; } else { response.HasCard = true; } }
private void MapStripeCustomerTo(StripeCustomer stripeCustomer, GetCustomerResponse response) { if (response == null) return; response.Email = CleanUpStripeEmail(stripeCustomer.Email); response.Id = stripeCustomer.Id; response.Description = stripeCustomer.Description; if (stripeCustomer.StripeSubscription != null) { response.PlanId = stripeCustomer.StripeSubscription.StripePlan.Id; response.PlanName = stripeCustomer.StripeSubscription.StripePlan.Name; decimal planAmount = (decimal)stripeCustomer.StripeSubscription.StripePlan.AmountInCents; planAmount = planAmount / 100; response.PlanAmount = planAmount; response.PlanStatus = stripeCustomer.StripeSubscription.Status; } if (stripeCustomer.StripeNextRecurringCharge != null) { decimal nextCharge = (decimal)stripeCustomer.StripeNextRecurringCharge.AmountInCents; nextCharge = nextCharge / 100; string nextStatus = "Next charge " + nextCharge.ToString("C") + " on " + stripeCustomer.StripeNextRecurringCharge.Date; response.NextCharge = nextStatus; } if (stripeCustomer.StripeCard == null) { response.HasCard = false; } else { response.HasCard = true; } }
public GetCustomerResponse GetCustomerInformation(string customerId) { var response = new GetCustomerResponse(); var customerService = new StripeCustomerService(); try { StripeCustomer stripeCustomer = customerService.Get(customerId); MapStripeCustomerTo(stripeCustomer, response); response.Success = true; } catch (StripeException ex) { response.Success = false; response.Message = ex.Message; return response; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return response; }