首页 > 解决方案 > 如何使用 Asp.Net Core MVC 将订单的总金额发送到 Stripe Api

问题描述

我有一个在 Visual Studio 中开发的购物车项目我正在实现条带网关,但我不确定如何将订单的总金额发送到 Stripe,所有在线示例都显示输入的金额而不是收集购物的总数购物车从项目列表中,然后将总数发送到条带:

订单总计发送到 Stripe

条带结帐没有总数

  <div class="caption">
            <div class="row">
                <div class="col-md-6 col-xs-6">
                    <h3>Shopping Cart Payment</h3>
                </div>
                <div class="col-md-6 col-xs-6 price">
                    <h3>                       
                        @Model.Total.ToString("c")
                    </h3>
                                        </div>
                                    </div>
                                    <p></p>
                                    <div class="row">
                                        <div class="col-md-6">
                                            <a class="btn btn-primary btn-product"><span class="glyphicon glyphicon-thumbs-up"></span> Like</a>
                                        </div>
                                        <div class="col-md-6">

                                            <button id="pay-button" type="submit" class="btn btn-success  btn-product"><span class="glyphicon glyphicon-shopping-cart"></span> Pay with Card</button>

这是我在条带控制器中调用结帐的方法:

 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,
}

我的疑问是如何将我的订单总金额过帐到 Stripe 以供客户使用信用卡付款?

标签: javascriptasp.net-mvcasp.net-corestripe-paymentsgateway

解决方案


推荐阅读