Braintree 通过 Request 传递送货地址

Braintree passing shipping address with Request

我是 VB.net 的新手,在使用 braintree 时它工作正常,现在我需要在付款请求中传递运输详细信息。我该怎么做

If Request.Form("payment_method_nonce") <> "" Then
    Dim strStatus As String = ""    
    Dim gateway As New Braintree.BraintreeGateway    
    With gateway
        .Environment = Braintree.Environment.SANDBOX
        .PublicKey = "*********"
        .PrivateKey = "*************"
        .MerchantId = "*************"
    End With

    Dim transactionRequest As New Braintree.TransactionRequest    
    With transactionRequest
        .Amount = 100
        .PaymentMethodNonce = Request.Form("payment_method_nonce")
    End With

    Dim result As Braintree.Result(Of Braintree.Transaction) = gateway.Transaction.Sale(transactionRequest)
    If result.Errors Is Nothing Then
        If result.Target.Status.ToString = Braintree.TransactionStatus.AUTHORIZED.ToString Then
            strStatus = "Payment is " & result.Target.Status.ToString
            Dim result1 As Braintree.Result(Of Braintree.Transaction) = gateway.Transaction.SubmitForSettlement(result.Target.Id)
            strStatus = strStatus & " And Now its " & result1.Target.Status.ToString
            Label1.Text = "Paid"
        Else
            strStatus = result.Target.Status.ToString
        End If
    Else
        strStatus = result.Message.ToString
        Label1.Text = "Not Paid"
    End If
    status.Text = strStatus
End If

完全披露:我是 Braintree 的一名开发人员。

您可以通过指定 ShippingAddress in your TransactionRequest object. ShippingAddress would be created as an AddressRequest object. You can see a full .NET example which includes creating a shipping address on our developers site 将送货地址添加为交易的一部分。

至于如何使用 VB.net 执行此操作,根据您的代码片段,您应该可以这样做:

Dim shippingAddressRequest As New Braintree.AddressRequest    
With shippingAddressRequest
    .FirstName = "John"
    .LastName = "Smith"
    .StreetAddress = "123 Example St."
    .Locality = "Chicago"
    .Region = "IL"
    .PostalCode = "60601"
    .CountryCodeAlpha2 = "US"
End With

然后把你的transactionRequest修改成这样:

Dim transactionRequest As New Braintree.TransactionRequest   
With transactionRequest
    .Amount = 100
    .PaymentMethodNonce = Request.Form("payment_method_nonce")
    .ShippingAddress = shippingAddressRequest
End With

如果您需要与此相关的任何其他帮助,我建议联系 Braintree support