在结账前获取Paypal Express购物车价格



我正在使用贝宝快速结账,当用户决定结账时,我正在尝试获取购物车中的总价值。我的运费将基于总价,尽管我在贝宝账户设置中填写了运费计算,但运费不会显示在结账屏幕上。如何在结账时立即获取购物车的总价格,以便添加运费?到目前为止,我所拥有的只是用户结账后的值,这些值会返回到我的网站,但现在添加运费已经太晚了。

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

我也一直试图声明一个会话变量,并在每次单击"添加到购物车"按钮时将其添加到其中,但我看到了一个问题,因为我不知道这些项目将在贝宝购物车中停留多久,如果会话变量会话超时并被清除,那么它们将在运费清除后获得免费运费。他们有办法做到这一点吗?

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

相关内容

  • 没有找到相关文章

最新更新