【发布时间】:2020-04-17 15:29:54
【问题描述】:
我需要您的帮助,我想将条带结帐与 .net 集成 我一步一步按照 Stripe 教程进行操作,但 Stripe Checkout 重定向不起作用。
这是我的代码:
<script src="https://js.stripe.com/v3/"></script>
<asp:Button runat="server" OnClick="btnPay_Click" Text="S'inscrire" CssClass="btn btn-submit" id="btnPay" />
<script>
var stripe = Stripe('pk_test_fuKFopc9GVK4QgRD4c3CDZng00OI6sMSyU');
var element = document.getElementById('btnPay');
element.addEventListener('click', function () {
stripe.redirectToCheckout({
// Make the id field from the Checkout Session creation API response
// available to this file, so you can provide it as parameter here
// instead of the {{CHECKOUT_SESSION_ID}} placeholder.
sessionId: '<%= sessionid%>'
}).then(function (result) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`.
});
});
</script>
还有我的服务器代码:
protected void btnPay_Click(object sender, EventArgs e)
{
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
StripeConfiguration.ApiKey = WebConfigurationManager.AppSettings["StripeSecretKey"];
var options = new SessionCreateOptions
{
CustomerEmail = "customer@hotmail.com",
PaymentMethodTypes = new List<string> {
"card",
},
LineItems = new List<SessionLineItemOptions> {
new SessionLineItemOptions {
Name = "TEST",
Description = "my Description",
Amount = 99,
Currency = "eur",
Quantity = 1,
},
},
SuccessUrl = "https://example.com/success?session_id={CHECKOUT_SESSION_ID}",
CancelUrl = "https://example.com/cancel",
};
var service = new SessionService();
Session session = service.Create(options);
重定向到 Checkout 不起作用 :( :( :(
【问题讨论】:
-
你在使用
clientIdMode="static"吗?您是否收到 JS 错误? -
请注意您的successurl 字面意思是
success?session_id={CHECKOUT_SESSION_ID} -
我看不到你的服务器端代码是如何被调用的,看起来你只是在调用 javascript 函数。看页面源码,
sessionid评价了吗?使用浏览器开发工具跟踪网络请求并查看发生了什么。 -
@Crowcoder “我不知道你的服务器端代码是如何被调用的” - 该按钮有一个
OnClick,尽管我同意似乎没有是客户端和服务器之间的任何“对话”。
标签: javascript c# stripe-payments