布伦特里Web窗体和数据加密的价值 [英] Braintree with Web Forms and data-encrypted-value

查看:174
本文介绍了布伦特里Web窗体和数据加密的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用布伦特里对支付API在我的身边,虽然他们有出色的文档,我试图从形式(而不是从领域在所有接受任何值)收到值时,我卡住了。

I am trying to use Braintree's API for payments on my side, and although they have excellent documentation, I am stuck when trying to receive the values from the form (not receiving any values from the fields at all).

在code是如下:

HTML

        <p>
            <asp:Label ID="Label1" runat="server" Text="Credit Card Number"></asp:Label><br />
            <asp:TextBox data-encrypted-name="number" ID="CardNumberTextBox" AutoCompleteType="Disabled" MaxLength="20" Width="350" runat="server"></asp:TextBox>
        </p>
        <p>
            <asp:Label ID="Label2" runat="server" Text="CVV"></asp:Label><br />
            <asp:TextBox ID="CVVTextbox" AutoCompleteType="Disabled" MaxLength="4" Width="50" data-encrypted-name="cvv" runat="server"></asp:TextBox>
        </p>
        <p>
            <asp:Label ID="Label3" runat="server" Text="Expiration (MM/YYYY)"></asp:Label><br />
            <asp:TextBox ID="MonthTextbox" AutoCompleteType="Disabled" MaxLength="2" data-encrypted-name="month" Width="50" runat="server"></asp:TextBox>
            / 
        <asp:TextBox ID="YearTextbox" AutoCompleteType="Disabled" MaxLength="4" data-encrypted-name="year" Width="50" runat="server"></asp:TextBox>
        </p>
        <input type="submit" id="SubmitButton" onserverclick="SubmitButton_Click"  runat="server" />

由于我在母版页的主要形式,我修改页面加载它的属性。

Since I have the main form in the master page, I modify its properties on page load:

code-背后:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Form.Action = "./default.aspx"
        Form.Method = "POST"
        Form.ID = "braitree"


    End Sub

    Protected Sub SubmitButton_Click(sender As Object, e As EventArgs)

        Dim number As String = Request.Form("number").ToString
        Dim cvv As String = Request.Form("cvv").ToString
        Dim month As String = Request.Form("month").ToString
        Dim year As String = Request.Form("year").ToString

        Dim gateway As New Braintree.BraintreeGateway

        With gateway
            .Environment = Braintree.Environment.SANDBOX
            .PublicKey = "xxx"
            .PrivateKey = "xxx"
            .MerchantId = "xxx"
        End With

        Dim transactionRequest As New TransactionRequest

        With transactionRequest
            .Amount = 100D
            .CreditCard = New TransactionCreditCardRequest
            With .CreditCard
                .Number = number
                .CVV = cvv
                .ExpirationMonth = month
                .ExpirationYear = year
            End With
        End With

        Dim result As Result(Of Transaction) = gateway.Transaction.Sale(transactionRequest)

    End Sub

当我在突破和拓展的第一个的Request.Form ,我注意到它的不可以包含数据-encrypted名值,但 ID 的HTML生成的名称值。

When I break at and expand the first Request.Form, I notice that it does not contain the data-encrypted-name values but the HTML-generated name values of ID.

注意:这也是当我更换 HTML 控制 ASP 控制情况

Note: This also happens when I replace the ASP controls with HTML controls.

这有什么,我很想念至于应该如何获得数据加密的名称

Is there anything that I am missing as to how it should receive the data-encrypted-name?

推荐答案

这个问题的解决很简单,其实。看来,我的一些控制,其中的请求对象干扰。一个空的项目测试,看看这个问题的确是在我的身边,我创建了一个新的母版页。

The solution to this was simple, actually. It seems that some of my control where interfering with the Request object. After testing with an empty project to see that the problem was indeed on my side, I created a new master page.

在默认情况下,形式缠的ContentPlaceHolder 所以我设置其属性通过布伦特里的文档的指示,复制的javascript调用和​​声明如下这一点,在我的 Default.aspx的的HTML如下:

By default, the form is wrapped around the ContentPlaceholder so I set the its attributes as instructed by Braintree's documentation, copied the javascript call and declarations below that, and in my default.aspx, the HTML is as follows:

        <p>
          <label>Card Number</label>
          <input type="text" size="20" autocomplete="off" data-encrypted-name="number" />
        </p>
        <p>
          <label>CVV</label>
          <input type="text" size="4" autocomplete="off" data-encrypted-name="cvv" />
        </p>
        <p>
          <label>Expiration (MM/YYYY)</label>
          <input type="text" size="2" data-encrypted-name="month" /> / <input type="text" size="4" data-encrypted-name="year" />
        </p>
        <input type="submit" id="submit" onserverclick="SubmitButton_Click" runat="server"/>

注意 =服务器 onserverclick 属性上的输入。我还没有实际测试过这是否会与正常的asp防治工作。

Notice the runat="server" and onserverclick attributes on the input. I haven't actually tested this if it will work with normal asp control.

这是现在的工作,所以我移动到艰难的部分:)

That works now, so I am moving to the tough part :)

编辑:这适用于ASP控制还

This works with asp controls also!

这篇关于布伦特里Web窗体和数据加密的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆