【发布时间】:2019-08-19 10:58:28
【问题描述】:
我正在尝试发起对 Stripe 脚本的以下调用,该脚本通过示例 HTML 表单中的 POST 请求页面 /Members/Charge.aspx。我需要在使用 Site.Master 页面的现有 aspx 子页面上执行此操作(因此它位于 asp 内容占位符之间,因此我不能使用表单 method="post" 等。
除了从现有的 ASP 内容子页面之外,我如何执行以下操作?
这是来自 Stripe 的示例代码:
<form action="/Members/Charge" method="post">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= stripePublishableKey %>"
data-amount="500"
data-name="Stripe.com"
data-description="Sample Charge"
data-image="/images/home.jpg"
data-locale="auto"
data-zip-code="true">
</script>
</form>
我需要它是这样的:
<div class="col">
<h5 style="font-weight:bold">Payment Method</h5>
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= stripePublishableKey %>"
data-amount="500"
data-name="Stripe.com"
data-description="Sample Charge"
data-image="/images/home.jpg"
data-locale="auto"
data-zip-code="true">
</script>
</div>
在我的 asp:Content 标签之间的 aspx 子页面中,但是由于我无法使用该行:,如何重定向到我的收费页面?
<form action="/Members/Charge" method="post">
然后重定向到“charge”页面,即交易成功页面,page_load 上有以下代码,实际提交交易
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["stripeToken"] != null)
{
var customers = new CustomerService();
var charges = new ChargeService();
var customer = customers.Create(new CustomerCreateOptions
{
Email = Request.Form["stripeEmail"],
SourceToken = Request.Form["stripeToken"]
});
var charge = charges.Create(new ChargeCreateOptions
{
Amount = 500,
Description = "Sample Charge",
Currency = "usd",
CustomerId = customer.Id
});
Console.WriteLine(charge);
}
}
【问题讨论】:
-
我假设您确实需要使用表单标签来使其工作,为什么不使用空操作将其发布到当前 URL,即当前页面?
-
然后发布到“收费”页面 - 我编辑了我的问题以包含它,谢谢
-
你说你不能使用表单标签的方式让我很困惑。看起来您已经在脚本之前添加了一个 h5 标记,因此您可以将整个内容包装在 form 标记中。在您的评论中,您提到如果您使用没有操作 URL 的表单标签,它将发布到收费页面,那么这不是您想要实现的目标吗?在我看来,您没有遇到任何问题,或者您没有解释实际问题
-
我不能这样做,因为我在 asp:content 标签之间的 asp.net 子页面上,所以你不能在其中放置表单标签
-
好的,我现在明白了,不可能使用两种形式,因此一种可能的解决方案是将孩子包装在 iframe 中
标签: javascript c# html asp.net stripe-payments