Example #1
0
        public async Task Consume(ConsumeContext <UserCreatedEvent> context)
        {
            var user = await _paymentContext.Users.FindAsync(context.Message.UserId);

            if (user == null)
            {
                var customer = _stripeService.CreateCustomer(context.Message.Email);
                user = new User()
                {
                    UserId       = context.Message.UserId,
                    StripeUserId = customer.Id
                };
                await _paymentContext.Users.AddAsync(user);

                await _paymentContext.SaveChangesAsync();
            }
        }
Example #2
0
        public IActionResult UpdateBillingInfo(string StripeToken)
        {
            //FIRST: check if Stripe customer exists,
            // If true: get stripe customer ID, send token, and store bank_id in DB
            // If false: Create stripe customer and send token (one call), then store bank_id in DB

            var tenantID   = CookieHandler.GetCurrentUserID(Request.Cookies["AuthToken"]);
            var isTypeBank = true; //hardcoded type
            var isVerified = false;

            if (isTypeBank)
            {
                isVerified = false;
            }

            if (StripeToken == null)
            {
                return(Json(new { success = false, error = "No Stripe Token provided." }));
            }

            var currentTenant = Methods.Methods.GetTenant(tenantID);

            //Check if Stripe customer doesnt exist, create one. Else, update customer in Stripe.
            if (currentTenant.StripeID == "" || currentTenant.StripeID == null)
            {
                if (StripeService.CreateCustomer(currentTenant, StripeToken, isVerified))
                {
                    return(Json(new { success = true }));
                }
                return(Json(new { success = false, error = "Could not create Stripe customer." }));
            }
            else
            {
                var tenant = Methods.Methods.GetTenant(tenantID);
                StripeService.UpdateCustomer(tenant.TenantID, tenant.StripeID, StripeToken, isVerified);

                return(Json(new { success = true, isVerified = isVerified, hasBillingInfo = true }));
            }
        }