public async Task <ActionResult <int> > TryPayWithPaymentMethod(CreateServiceRequestModel model)
        {
            PaymentIntent paymentIntent;

            try
            {
                //TODO: optimize/consolidate TryPayWithPaymentMethod
                var customer = await _mediator.Send(new GetCustomerQuery(_user.ClaimID));

                var cart = await _mediator.Send(new GetCustomerCartQuery(customer.ID, model.MerchantID));

                var amount = cart.Total;

                paymentIntent = _stripe.CreatePaymentIntent(new PaymentIntentCreateOptions
                {
                    Amount        = Convert.ToInt64(amount) * 100,
                    Currency      = "usd",
                    PaymentMethod = model.Payment.StripePaymentMethodID,
                    Customer      = customer.StripeCustomerID,
                    // A PaymentIntent can be confirmed some time after creation,
                    // but here we want to confirm (collect payment) immediately.
                    Confirm = true,

                    // If the payment requires any follow-up actions from the
                    // customer, like two-factor authentication, Stripe will error
                    // and you will need to prompt them for a new payment method.
                    ErrorOnRequiresAction = true,
                });
            }
            catch (StripeException e)
            {
                return(StatusCode(501, e.StripeError.Message));
            }

            if (paymentIntent?.Status == "succeeded")
            {
                // Handle post-payment fulfillment
                return(await CreateServiceRequest(model));
            }
            else
            {
                // Any other status would be unexpected, so error
                return(StatusCode(500, new { error = "Invalid PaymentIntent status" }));
            }
        }
Exemple #2
0
        // Parámetros que se deben enviar en el body-request: CreateServiceRequestModel => UPCCode, FirstName, LastName, Names, Email, Career, Modality, ServiceTypeId, AttentionModeId, CampusId y CreationUser
        public IActionResult CreateServiceRequest([FromForm] CreateServiceRequestModel model)
        {
            try
            {
                byte[] file = null;
                using (var memoryStream = new MemoryStream())
                {
                    model.FileContent.CopyToAsync(memoryStream);
                    file = memoryStream.ToArray();
                }
                ServiceRequest serviceRequest = new ServiceRequest
                {
                    UPCCode         = model.UPCCode,
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    Names           = model.Names,
                    Email           = model.Email,
                    Career          = model.Career,
                    Modality        = model.Modality,
                    ServiceTypeId   = model.ServiceTypeId,
                    AttentionModeId = model.AttentionModeId,
                    CampusId        = model.CampusId,
                    RequestDetail   = model.RequestDetail,
                    FileName        = model.FileName,
                    FileContent     = file,
                    ServiceStatusId = 1,
                    BUserCode       = "b20200601",
                    CreationDate    = DateTime.Now,
                    CreationUser    = model.CreationUser
                };

                db.ServiceRequests.Add(serviceRequest);
                db.SaveChanges();
                return(Ok(
                           new
                {
                    status = true,
                    message = "OK"
                }));
            }
            catch (Exception ex)
            {
                return(this.NotFound(ex.Message));
            }
        }
 public async Task <ActionResult <int> > CreateServiceRequest(CreateServiceRequestModel model)
 {
     return(await _mediator.Send(new CreateServiceRequestCommand(model, _user.ClaimID)));
 }