2017-06-26 6 views
0

このスクリプトに基づいてコーディング/サーバー側からトークンを取得する方法を尋ねることはできますか? C#ストライプトークンをFormから取得する方法。サブスクリプト

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(); 
    } 

あなたは

+0

あなたは上記の機能を構築するために従わなかった何のドキュメント? – mjwills

+1

同じフォーム入力と同じですが、トークンに特に問題があるのですか、あるいはhtmlフォームの仕組みを知る必要がありますか? – Crowcoder

+0

@Crowcoderは返信してくれてありがとう、上記のコードに基づいてhtmlフォームの動作を知る必要があります。私はform.submitがvarフォームを送信すると仮定しました。サーバー側からフェッチする方法は?特にtoken.id。ありがとう! –

答えて

1

ここでは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"]); 
      } 
     } 
    } 
} 
関連する問題