我正在使用stripe處理我的網站上的付款。爲了實現這一點,我想使用Stripe的嵌入式支付形式,稱爲結帳。目前缺乏文檔或最新的例子來幫助我。使用stripe的表單來處理ASP .NET中的付款MVC
在我有嵌入的形式,像這樣的觀點:
<div class="row">
<div class="container col-md-2 col-md-offset-5">
<h5>Upgrade your account</h5>
<form action="/Premium/Charge" method="POST">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="MYKEY"
data-amount="1000"
data-name="My Project Name"
data-description="Premium Account (€10)"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto"
data-zip-code="true"
data-currency="eur">
</script>
</form>
</div>
而我的控制器操作處理後:
[HttpPost]
[Authorize]
public ActionResult Charge(string stripeToken, string stripeEmail)
{
string apiKey = "MYKEY";
var client = new Stripe.StripeCustomerCreateOptions();
// our customer
client.Email = stripeEmail;
client.SourceToken = stripeToken;
// creating our charge
var charge = new Stripe.StripeChargeCreateOptions();
charge.Amount = 1000;
charge.Description = "Premium member charge";
charge.Currency = "EUR";
charge.SourceTokenOrExistingSourceId = stripeToken;
// calling stripe to make the charge, then update users profile
var chargeService = new Stripe.StripeChargeService();
Stripe.StripeCharge stripeCharge = new Stripe.StripeCharge();
// Error arises here
dynamic response = chargeService.Create(charge);
if (response.Paid)
{
// successful payment
ViewBag.Status = "success";
return View("Result");
}
ViewBag.Status = "unsuccesful";
return View("Result");
}
解決。
你能收集到所有的是傳遞參數編輯到表單,以確保它們實際上與請求一起傳遞?而不是隻是試圖使用它們? – korben
我使用您在視圖和操作方法簽名中具有的確切代碼進行了測試,並且都運行良好。你是否遺漏了該方法上的[HttpPost]裝飾器? –
我忘了將它實際包含在代碼片段中,它在它之上。有沒有方法可以檢查來自該控制器的響應是否成功? –