结帐前立即获取 Paypal Express 购物车价格

Get Paypal Express cart Price right before checkout

我正在使用 paypal 快速结账,我正在尝试获取用户决定结账时购物车中的总价值。我的运费将基于总价,虽然我在我的贝宝账户设置中填写了运费计算,但结账屏幕上没有显示运费。我如何在结帐时立即获取购物车总价,以便我可以添加运费?到目前为止,我所拥有的只是用户结帐后的值,并且它们返回到我的网站,但此时添加运费为时已晚。

Dim authToken As String = "sdf5414FdsfDFS5eEF52s336DFLLJUhhbuzek64"
    Dim txToken As String = Request.QueryString("tx")
    txToken = "4GGSES84eEWSS" 
    Dim strRequest As String = "cmd=_notify-synch&tx=" & txToken & "&at=" & authToken

    'Dim Payerinfo As New PayerInfo
    'Dim trans As New Transaction
    'Dim tra As New PayPal.PayPalAPIInterfaceService.Model.GetTransactionDetailsReq




    'post back to either sandbox or live
    Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
    Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr"
    Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest)
    'req.Headers = valHeader
    'Set values for the request back
    req.Method = "POST"
    req.ContentType = "application/x-www-form-urlencoded"
    req.ContentLength = strRequest.Length

    'Send the request to PayPal and get the response
    Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
    streamOut.Write(strRequest)
    streamOut.Close()
    Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
    Dim strResponse As String = streamIn.ReadToEnd()
    streamIn.Close()

    If Not String.IsNullOrEmpty(strResponse) Then

        Dim results As New Dictionary(Of String, String)
        Dim reader As New StringReader(strResponse)
        Dim line As String = reader.ReadLine()
        If line = "SUCCESS" Then
            'FormView1.Visible = False
            While True
                Dim aLine As String
                aLine = reader.ReadLine
                If aLine IsNot Nothing Then
                    Dim strArr() As String
                    strArr = aLine.Split("=")
                    results.Add(strArr(0), strArr(1))
                Else
                    Exit While
                End If
            End While

            ' Displays all the keys for results, helps to see what the keys are named for writing to text file

            For Each kvp As KeyValuePair(Of String, String) In results
                Dim v1 As String = kvp.Key
                Dim v2 As String = kvp.Value
                Response.Write(v1.ToString _
                        + ":  " + v2 + "<br /> ")
            Next

        End If

我也一直在尝试声明一个会话变量,并在每次单击“添加到购物车”按钮时将其添加到其中,但我看到了一个问题,因为我不知道这些项目将在 paypal 中保留多长时间购物车,如果会话变量会话超时并被清除,他们将收到免费送货,因为运费已清零。他们有办法做到这一点吗?

Protected Sub AddToCartBtn_Click(sender As Object, e As EventArgs)
Session("CartAmount")     

 Dim itemNumber As String = str2
    Dim itemAmount As String = price
    Dim currencyCode As String = "USD"
    Dim addItem As Integer = 1

    Dim ppHref As StringBuilder = New StringBuilder()
    ppHref.Append("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_cart")
    ppHref.Append("&business=" + business)
    ppHref.Append("&item_name=" + itemName)
    ppHref.Append("&item_number=" + itemNumber)
    ppHref.Append("&amount=" + itemAmount)
    ppHref.Append("&currency_code=" + currencyCode)   
Session("CartAmount") = (cartTotal + Session("CartAmount"))
End Sub

您可以通过以下 url 参考中提供的变量传递购物车值, https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/#id08A6HF080O3