【问题标题】:Get Paypal Express cart Price right before checkout在结帐前获取 Paypal Express 购物车价格
【发布时间】:2015-04-10 22:41:09
【问题描述】:

我正在使用 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

我也一直在尝试声明一个会话变量并在每次单击“添加到购物车”按钮时添加到它,但我看到了一个问题,因为我不知道这些物品会在贝宝购物车中停留多长时间并且如果会话变量会话超时并被清除,则他们将获得免费送货,因为运费已清空。他们有什么方法可以完成这项工作吗?

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

【问题讨论】:

    标签: asp.net vb.net paypal-sandbox paypal


    【解决方案1】:

    【讨论】:

    • 我已经查看过了,但没有看到任何有关获取购物车总数的信息,我只是想念它吗?我看到了 amount_x 变量,但这意味着每次用户单击添加到购物车按钮并添加所有值时,我都必须保持运行总计,不是吗?
    • 我还需要在结帐完成之前获取该值,以便我可以评估和应用运费,我可以在用户结帐后获得总金额并被重定向回我的页面,但此时点,我不知道我是否可以将运费添加到总价值中
    猜你喜欢
    • 1970-01-01
    • 2013-02-25
    • 2012-08-10
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多