public IActionResult Pay([FromBody] Payment paymentInfo) { try { if (paymentInfo == null) { throw new Exception("Please fill in all required fields."); } //set business key to receive payment. var key = _stripeService.SetKey(paymentInfo.BusinessEmail); //handle empty email address var customerEmail = paymentInfo.Buyer_Email == "" ? "*****@*****.**" : paymentInfo.Buyer_Email; //Create Card Object to create Token var newToken = _stripeService.CreateCardToken(paymentInfo); //Create Customer Object and Register it on Stripe Customer stripeCustomer = _stripeCustomerService.Create(newToken, paymentInfo, null); //Create local user Object and register on Application var zaraiiUser = _userService.CreateUpdateCustomer(newToken, paymentInfo, null, null, stripeCustomer.Id); var amountTotal = Convert.ToInt32(paymentInfo.Amount); //get company information var businessInfo = _companyService.GetCompany(paymentInfo.BusinessEmail); var businessName = _companyService.SetName(businessInfo); var businessAddress = _companyService.SetAddress(businessInfo); //Create Charge Object with details of Charge var options = _stripeChargesService.Options(amountTotal, paymentInfo.CurrencyId, customerEmail, stripeCustomer.Id, businessName, businessAddress); //and Create Method of this object is doing the payment execution. var payment = _stripeChargesService.CreateCharge(options); //Create local order _orderService.Create(zaraiiUser.Id, amountTotal.ToString(), DateTime.Now.ToString()); return(Json(new { status = "success", message = "Payment successfully completed.", objectValue = payment })); } catch (Exception e) { return(Json(new { status = "Error", message = _errorService.LogError(e) })); } }
public void SetStripeKey(string BusinessEmail) { var key = _stripeService.SetKey(BusinessEmail); //_stripeService.SetKey(key); }