private void BuyAService(UserService servicoToHire, HireServiceModel payer) { var customer = CreateOrRetrieveAccountCustomer(payer); var finalPrice = PriceManager.FinalPrice(servicoToHire); var valueToPay = Int32.Parse(finalPrice.ToString() .Replace(",", string.Empty) .Replace(".", string.Empty)); // Recebendo o dinheiro. var chargeOptions = new StripeChargeCreateOptions() { Amount = valueToPay, Currency = "brl", Description = servicoToHire.Name, CustomerId = customer.Id, TransferGroup = "{ORDER10}", }; var chargeService = new StripeChargeService(); PaymentsCustomer payment = new PaymentsCustomer { Customer = customer, Amount = valueToPay, PayDay = DateTime.Now }; IlevusDBContext db = IlevusDBContext.Create(); db.GetPaymentsCustomerCollection().InsertOne(payment); }
public void MakePayment(HireServiceModel model, IlevusUserManager userManager) { UserManager = userManager; IlevusUser professionalUser = RetrieveUserByService(model.service.Id); UserService servicoToHire = professionalUser.Professional.Services.FirstOrDefault(x => x.Id == model.service.Id); BuyAService(servicoToHire, model); // Verificando se o profissional ja tem conta no stripe. se nao tem se cria. AccountPayment accountStripe = CreateORetrieveStripeAccount(professionalUser); TransferToProfessional(servicoToHire.Price, accountStripe); }
private AccountCustomer CreateOrRetrieveAccountCustomer(HireServiceModel model) { if (model.user.AccountCustumer == null) { var customerOptions = new StripeCustomerCreateOptions() { Email = model.user.Email, SourceToken = model.stripe.Id }; var customerService = new StripeCustomerService(); StripeCustomer customer = customerService.Create(customerOptions); model.user.AccountCustumer = Mapper.Map <AccountCustomer>(customer); UserManager.Update(model.user); } return(model.user.AccountCustumer); }
public async Task <IHttpActionResult> HireService(HireServiceModel model) { var db = IlevusDBContext.Create(); try { var user = await UserManager.FindByNameAsync(User.Identity.Name); if (user == null) { return(BadRequest("You must be logged in.")); } model.user = user; StripeManager.Instance.MakePayment(model, UserManager); return(Ok()); } catch (Exception e) { return(InternalServerError(e)); } }