簡體   English   中英

C#如何從Form.Submit中檢索Stripe Token

[英]C# how to retrieve Stripe Token from the Form.Submit

我可以問一下如何根據此腳本從編碼/服務器端檢索令牌嗎?

    function stripeTokenHandler(token) {
        // Insert the token ID into the form so it gets submitted to the server
        var form = document.getElementById('payment-form');
        var hiddenInput = document.createElement('input');
        hiddenInput.setAttribute('type', 'hidden');
        hiddenInput.setAttribute('name', 'stripeToken');
        hiddenInput.setAttribute('value', token.id);
        form.appendChild(hiddenInput);

        // Submit the form
        form.submit();
    }

謝謝

這是使用javascript提交Web表單並訪問服務器上的表單集合的基本示例。 我已經假設條帶標記值是硬編碼的,我假設您已經覆蓋了那部分。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication11.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <button onclick="stripeTokenHandler('some token value');">Submit Me</button>
    </div>
    </form>
</body>
    <script>
        function stripeTokenHandler(token) {
            var form = document.getElementById('form1');
            var hiddenInput = document.createElement('input');
            hiddenInput.setAttribute('type', 'hidden');
            hiddenInput.setAttribute('name', 'stripetoken');
            hiddenInput.setAttribute('value', token);
            form.appendChild(hiddenInput);

            // Submit the form
            form.submit();
        }
    </script>
</html>

背后的代碼:

using System;
using System.Diagnostics;

namespace WebApplication11
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                //any form inputs can be obtained with Request.Form[]
                Debug.WriteLine(Request.Form["stripetoken"]);
            }
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM