我正在使用条纹处理支付在我的网站上。为了实现这一点,我想使用Stripe的嵌入式支付表单,称为结帐。到目前为止,没有文档或者最新的例子来帮助我。
在视图中,我嵌入了如下形式:
<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");
}解决了。
发布于 2017-03-08 04:48:10
我正在使用这段代码进行测试,它的工作没有问题:
public class CreditCardController : Controller
{
public ActionResult Charge()
{
return View();
}
[HttpPost]
public ActionResult Charge(string stripeToken, string stripeEmail)
{
var myCharge = new StripeChargeCreateOptions();
// always set these properties
myCharge.Amount = 1000;
myCharge.Currency = "eur";
myCharge.ReceiptEmail = stripeEmail;
myCharge.Description = "Test Charge";
myCharge.SourceTokenOrExistingSourceId = stripeToken;
myCharge.Capture = true;
var chargeService = new StripeChargeService();
StripeCharge stripeCharge = chargeService.Create(myCharge);
return View();
}
}查看代码。键是Stripe文档中的演示键。我用的信用卡号码是4242424242424242。
<div class="row">
<div class="container col-md-2 col-md-offset-5">
<h5>Upgrade your account</h5>
<form action="/CreditCard/Charge" method="POST">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_6pRNASCoBOKtIshFeQd4XMUh"
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>
</div>发布于 2017-03-08 20:10:36
在您做出应该正常工作的动态响应之前,请删除该行。你向条形服务器提出了两个请求。
https://stackoverflow.com/questions/42660097
复制相似问题