Braintree通过发货地址与请求

时间:2015-11-06 15:34:09

标签: vb.net braintree braintree-data

我在使用braintree时是VB.net的新手,它工作正常,现在我需要通过付款请求传递送货详情。我怎么能这样做

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

1 个答案:

答案 0 :(得分:2)

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

您可以在TransactionRequest对象中指定ShippingAddress,将送货地址添加为交易的一部分。 ShippingAddress将被创建为AddressRequest个对象。您可以看到完整的.NET示例,其中包括创建送货地址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联系。