Javascript 如何使用Asp.Net Core MVC将订单总额发送到条带Api
我在Visual Studio中开发了一个购物车项目我正在实现stripe gateway,但我不确定如何将订单总额发送到stripe,所有在线示例都显示键入的金额,而不是从项目列表中收集购物车总额,然后将总额发送到stripe: 及 我尝试了以下方法:Javascript 如何使用Asp.Net Core MVC将订单总额发送到条带Api,javascript,asp.net-mvc,asp.net-core,stripe-payments,gateway,Javascript,Asp.net Mvc,Asp.net Core,Stripe Payments,Gateway,我在Visual Studio中开发了一个购物车项目我正在实现stripe gateway,但我不确定如何将订单总额发送到stripe,所有在线示例都显示键入的金额,而不是从项目列表中收集购物车总额,然后将总额发送到stripe: 及 我尝试了以下方法: var amount = _appDbContext.ShoppingCartItems.Where(c => c.ShoppingCartId == ShoppingCartId) .Sele
var amount = _appDbContext.ShoppingCartItems.Where(c => c.ShoppingCartId == ShoppingCartId)
.Select(c => c.Pie.Price * c.Amount).Sum();
return total;
[HttpPost]
[ValidateAntiForgeryToken()]
public ActionResult Custom(CustomViewModel customViewModel, string token)
{
customViewModel.PaymentFormHidden = false;
var chargeOptions = new ChargeCreateOptions()
{
//required
**Amount = amount,
Currency = "euro",
Source = token,
}
我的疑问是,如何发布我的订单总额,以便客户使用信用卡支付?您能否编辑您的问题,将代码示例减少到演示问题所需的最低限度?另外,请添加一些您尝试过的东西,以及它们是如何工作的。我刚刚编辑了问题,现在清楚了吗?我没有使用stripe中的嵌入表单,而是使用自定义表单。这看起来非常接近,开发人员。货币应设置为“欧元”而不是“欧元”,金额应为美分。如果这里的
total
是51.85,那么您将传递int 5185作为金额。@w1zeman1p我想传递一个函数或lambda表达式来处理所有shoppingcart,通常人们会给出如下示例:很好,我的意思是金额需要设置为整数值。可以从db调用或其他函数返回。
public ActionResult Custom()
{
string stripePublishableKey = ConfigurationManager.AppSettings["stripePublishableKey"];
var model = new CustomViewModel() { StripePublishableKey = stripePublishableKey, PaymentFormHidden = true };
return View(model);
}
[HttpPost]
[ValidateAntiForgeryToken()]
public ActionResult Custom(CustomViewModel customViewModel, string token, int amount)
{
customViewModel.PaymentFormHidden = false;
var chargeOptions = new ChargeCreateOptions()
{
//required
**Amount = amount,**// how to add the total for the order here?**
Currency = "euro",
Source = token,
}
var amount = _appDbContext.ShoppingCartItems.Where(c => c.ShoppingCartId == ShoppingCartId)
.Select(c => c.Pie.Price * c.Amount).Sum();
return total;
[HttpPost]
[ValidateAntiForgeryToken()]
public ActionResult Custom(CustomViewModel customViewModel, string token)
{
customViewModel.PaymentFormHidden = false;
var chargeOptions = new ChargeCreateOptions()
{
//required
**Amount = amount,
Currency = "euro",
Source = token,
}