Exemple #1
0
 // DynamoDb methods --------------------------------------------------------------------------------------
 public IActionResult AddUser([FromQuery]
                              string email,
                              string subplan,
                              string lastpaid,
                              string username,
                              string password,
                              string phoneno,
                              string lastaccessed)
 {
     _addUser.AddNewEntry(email, subplan, lastpaid, username, password, phoneno, lastaccessed);
     return(Ok());
 }
Exemple #2
0
        public IActionResult AddUser([FromQuery] string customerId, string email, string name, string plan)
        {
            try
            {
                _putItem.AddNewEntry(customerId, email, name, plan);
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }

            return(Ok());
        }
        public async Task <IActionResult> Webhook()
        {
            //using (Stream iStream = Request.InputStream)
            //{
            //    using (StreamReader reader = new StreamReader(iStream, Encoding.UTF8))   //you should use   Request.ContentEncoding
            //    {
            //        json = await reader.ReadToEndAsync();
            //    }
            //}
            var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();

            try
            {
                var stripeEvent = EventUtility.ParseEvent(json);
                if (stripeEvent.Type == Events.CustomerCreated)
                {
                    Customer cus           = stripeEvent.Data.Object as Customer;
                    var      customerId    = cus.Id;
                    var      customerName  = cus.Name;
                    var      customerEmail = cus.Email;
                    try
                    {
                        await _putItem.AddNewEntry(customerId, customerEmail, customerName, "No Plan");
                    }
                    catch (Exception e)
                    {
                        return(BadRequest());
                    }
                }
                else if (stripeEvent.Type == Events.CustomerSubscriptionUpdated || stripeEvent.Type == Events.CustomerSubscriptionCreated)
                {
                    Subscription sub    = stripeEvent.Data.Object as Subscription;
                    string       planId = sub.Items.Data[0].Plan.Id;
                    //if (sub.Items.Data[0].Price.Product != null)
                    //{
                    // planId = sub.Items.Data[0].Plan.Id;
                    //}
                    //else if (sub.Items.Data[0].Price.ProductId != null) {
                    //    planId = sub.Items.Data[0].Price.ProductId;
                    //}
                    string customerId = sub.CustomerId;
                    User   response   = new User();
                    try
                    {
                        response = await _updateItem.Update(customerId, planId);
                    }
                    catch (Exception e)
                    {
                        return(BadRequest());
                    }
                }
                else
                {
                    Console.WriteLine("Unhandled event type: {0}", stripeEvent.Type);
                }
                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }