使用asp.net的Braintree Dropin-空白付款方式随机数

时间:2018-10-28 20:48:45

标签: braintree nonce

希望有人可以提供帮助。我有一个用asp.net(vb)构建的braintree付款页面,该页面以前可以与TSL 1.0 / 1.1一起使用。随着对TSL1.2的更改和更新的api,我不再能够使用该代码。我收到“无法确定付款方式”错误,似乎payment_method_nonce为空。代码在下面,任何帮助将不胜感激。

    <asp:Panel runat="server" ID="pnlPay" Visible =" false">
        <div id="braintree-dropin"></div>
        <asp:Button runat="server" ID="btnSubmit" Text="Pay now"/>
        <asp:Label runat="server" ID="lblResult" Visible="false" Text=""></asp:Label>
        <input id="nonce" name="payment_method_nonce" type="hidden" />
    </asp:Panel>

<script src="https://js.braintreegateway.com/web/dropin/1.13.0/js/dropin.min.js"></script>
<script>
    var client_token = "<%=ProcessorToken %>";
    var form = document.querySelector('#form1');

    braintree.dropin.create({
        authorization: client_token,
        container: '#braintree-dropin',
    }, function (createErr, instance) {
        form.addEventListener('#btnSubmit', function (event) {
            event.preventDefault();

            instance.requestPaymentMethod(function (err, payload) {
                if (err) {
                    console.log('Error', err);
                    return;
                }

                // Add the nonce to the form and submit
                document.querySelector('#nonce').value = payload.nonce;
                form.submit();
            });
        });
    });
</script>



Private _gateway As BraintreeGateway
Protected ProcessorToken As String
Protected PaymentNonce As String

Public ReadOnly Property Gateway() As BraintreeGateway
    Get
        If _gateway Is Nothing Then

            If ConfigurationManager.AppSettings("braintreeSystem") = "Prod" Then
                _gateway = New BraintreeGateway() With {
                .Environment = Braintree.Environment.PRODUCTION,
                .MerchantId = ConfigurationManager.AppSettings("braintreeMerchantID"),
                .PublicKey = ConfigurationManager.AppSettings("braintreePublicKey"),
                .PrivateKey = ConfigurationManager.AppSettings("braintreePrivateKey")
            }
            Else
                _gateway = New BraintreeGateway() With {
                .Environment = Braintree.Environment.SANDBOX,
                .MerchantId = ConfigurationManager.AppSettings("TESTbraintreeMerchantID"),
                .PublicKey = ConfigurationManager.AppSettings("TESTbraintreePublicKey"),
                .PrivateKey = ConfigurationManager.AppSettings("TESTbraintreePrivateKey")
            }
            End If
        End If
        Return _gateway
    End Get
End Property

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ' Set up the Braintree processor client token
    Try
        ProcessorToken = Gateway.ClientToken.Generate()

        If Not IsPostBack Then
            BindData()
        Else
            Validate()
            Pay()
        End If
    Catch ex As Exception
        MessageBoxShow(ex.Message)
    End Try
End Sub

谢谢

史蒂夫

0 个答案:

没有答案