public static DataAccessResponseType ProcessSuccessfulStripeChargeEvent(string stripeCustomerId, string stripeChargeId, string stripeCardId, string StripeInvoiceId, string StripeEventId) { var response = new DataAccessResponseType(); //Get all owners for the account: var accountOwnerEmails = AccountManager.GetAccountOwnerEmails(stripeCustomerId); //Get the account //var account = AccountManager.GetAccountByStripeCustomerID(stripeCustomerID, false); var account = AccountManager.GetAccount(stripeCustomerId); //Get the associated Stripe Invoice: var stripeManager = new StripeManager(); var stripeCharge = stripeManager.GetCharge(stripeChargeId); var stripeCard = stripeManager.GetCard(stripeCustomerId, account.StripeCardID); //<-- in case card is updated we use the latest stripe card ID //Generate dollar amount var chargeTotalAmount = Sahara.Core.Common.Methods.Billing.ConvertStripeAmountToDollars(stripeCharge.Amount.ToString()); //For HTML invoice or charge details string var htmlPaymentDetailsString = string.Empty; if (!String.IsNullOrEmpty(StripeInvoiceId)) { //Charge has in invoice associated var stripeInvoice = stripeManager.GetInvoice(StripeInvoiceId); //Generate HTML invoice htmlPaymentDetailsString = Sahara.Core.Common.Methods.Billing.GenerateStripeHTMLInvoice(stripeInvoice); } else { //Generate HTML charge details (No associated invoice exists) htmlPaymentDetailsString = Sahara.Core.Common.Methods.Billing.GenerateStripeHTMLChargeDetails(stripeCharge); } //email all account owners a copy of the associated charge/invoice details EmailManager.Send( accountOwnerEmails, Settings.Endpoints.Emails.FromBilling, Settings.Copy.EmailMessages.AccountCharged.FromName, String.Format(Settings.Copy.EmailMessages.AccountCharged.Subject), String.Format(Settings.Copy.EmailMessages.AccountCharged.Body, account.AccountName, stripeCard.CardBrand, stripeCard.Last4, chargeTotalAmount, htmlPaymentDetailsString), true); //Clear Billing Issues Marker From Account //????/ response.isSuccess = true; return(response); }
public static Invoice GetInvoice(string stripeInvoiceId) { var invoice = new Invoice(); #region (Plan A) Check Redis Cache First #endregion #region (Plan B) Call Stripe API, Transform Data & Store in Redis Cache if (!String.IsNullOrEmpty(stripeInvoiceId)) { var stripeManager = new StripeManager(); var stripeInvoice = stripeManager.GetInvoice(stripeInvoiceId); invoice = Transformations.TransformStripeInvoiceToInvoice(stripeInvoice); } #endregion return(invoice); }