我有一个有效的expressCheckout流程,一切正常,直到我尝试将金额乘以给定的汇率。
以下是2个版本(第1版,没有汇率的工作版本,第2版是非工作版本,实施汇率:
工作版
Imports PayPal.PayPalAPIInterfaceService.Model
导入PayPal.PayPalAPIInterfaceService 进口PayPal.Manager
部分班级paypalExpressCheckout 继承System.Web.UI.Page
Dim currentPreSale As New PreSale
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Session("ShoppingCartDT") Is Nothing Then
currentPreSale = Session("currentPreSale")
Dim request As New SetExpressCheckoutRequestType
populateRequestObject(request)
'Invoke the API
Dim wrapper As New SetExpressCheckoutReq
wrapper.SetExpressCheckoutRequest = request
Dim service As New PayPalAPIInterfaceServiceService
Dim setECResponse As SetExpressCheckoutResponseType = service.SetExpressCheckout(wrapper)
'Check for API return status
Dim CurrContext As HttpContext = HttpContext.Current
CurrContext.Items.Add("paymentDetails", request.SetExpressCheckoutRequestDetails.PaymentDetails)
setKeyResponseObjects(service, setECResponse)
Else
End If
End Sub
Private Sub SetShippingAddress(ByRef shippingAddress As AddressType)
Dim selectedCountry As New Country
Dim currentUser As User = Session("currentUser")
selectedCountry.GetCountryDetails(currentPreSale.DeliveryCountryId.ToString())
shippingAddress.Name = currentUser.FirstName & " " & currentUser.LastName
shippingAddress.Street1 = currentPreSale.DeliveryAddress
shippingAddress.Street2 = ""
shippingAddress.CityName = ""
shippingAddress.StateOrProvince = ""
shippingAddress.Country = [Enum].Parse(GetType(CountryCodeType), selectedCountry.CountryCode)
shippingAddress.Phone = currentUser.Phone & ""
shippingAddress.PostalCode = ""
End Sub
Private Sub populateRequestObject(ByRef request As SetExpressCheckoutRequestType)
Dim deliveryAddress As New Address
Dim currentUser As User = Session("currentUser")
Dim selectedCurrency As New Currency
selectedCurrency.GetCurrencyDetails(currentPreSale.CurrencyId.ToString())
'Dim userDetails As New UserDetails
Dim currency As CurrencyCodeType = selectedCurrency.PayPalCurrencyCode
Dim ecDetails As New SetExpressCheckoutRequestDetailsType
Dim paymentDetails As New PaymentDetailsType
Dim orderTotal As Double = 0
Dim itemTotal As Double = 0
Dim shippingValue As Double = currentPreSale.ShippingTotal
Dim HandlingTotal As Double = 0
Dim TaxTotal As Double = 0
Dim shipAddress As New AddressType
Dim dataTableCarrinho As DataTable
Dim dataRowCarrinho As DataRow
If currentPreSale.ShippingTotal > 0 Then
SetShippingAddress(shipAddress)
End If
'userDetails.Get_ItemDetails(Session("userId").ToString())
ecDetails.ReturnURL = ConfigurationManager.AppSettings("appURL") & "doExpressCheckoutPayment.aspx"
ecDetails.CancelURL = ConfigurationManager.AppSettings("appCurrentServer") & Page.GetRouteUrl("paypalCancel" & UCase(Left(Session("language"), 2)), New With {.lang = Left(Session("language"), 2)})
ecDetails.BuyerEmail = currentUser.Email
ecDetails.ReqConfirmShipping = 0
ecDetails.AddressOverride = 0
If CDec(currentPreSale.ShippingTotal) > 0 Then
ecDetails.NoShipping = 0
Else
ecDetails.NoShipping = 1
End If
'Payment Details
If (shippingValue > 0) Then
paymentDetails.ShippingTotal = New BasicAmountType(currency, currentPreSale.ShippingTotal)
End If
paymentDetails.OrderDescription = "KTB Order"
paymentDetails.PaymentAction = PaymentActionCodeType.SALE
orderTotal += shippingValue
'Lista de Items - GUY preencher
dataTableCarrinho = Session("ShoppingCartDT")
For Each dataRowCarrinho In dataTableCarrinho.Rows
Dim currentProduct As New Product
currentProduct.GetProductDetails(dataRowCarrinho("ProductId").ToString(), Session("LanguageId").ToString())
Dim itemDetails As New PaymentDetailsItemType
itemDetails.Name = currentProduct.Title
'itemDetails.Amount = New BasicAmountType(currency, dataRowCarrinho("Price").ToString())
itemDetails.Amount = New BasicAmountType(currency, CDec(dataRowCarrinho("Price")))
itemDetails.Quantity = CInt(dataRowCarrinho("Quantity"))
itemDetails.Tax = New BasicAmountType(currency, 0)
itemDetails.Description = ""
itemDetails.ItemCategory = ItemCategoryType.PHYSICAL
paymentDetails.PaymentDetailsItem.Add(itemDetails)
orderTotal += CDec(dataRowCarrinho("Price")) * CInt(dataRowCarrinho("Quantity"))
itemTotal += CDec(dataRowCarrinho("Price")) * CInt(dataRowCarrinho("Quantity"))
Next
'ExceptionUtility.LogInfo("orderTotal = " & orderTotal)
'ExceptionUtility.LogInfo("itemTotal = " & itemTotal)
'ExceptionUtility.LogInfo("shippingTotal = " & (currentPreSale.ShippingTotal * currentPreSale.ExchangeRate))
'paymentDetails.ItemTotal = New BasicAmountType(currency, CDec(currentPreSale.ProductTotal * currentPreSale.ExchangeRate))
'paymentDetails.OrderTotal = New BasicAmountType(currency, CDec((currentPreSale.ProductTotal + currentPreSale.ShippingTotal) * currentPreSale.ExchangeRate))
paymentDetails.ItemTotal = New BasicAmountType(currency, itemTotal)
paymentDetails.OrderTotal = New BasicAmountType(currency, orderTotal)
ecDetails.PaymentDetails.Add(paymentDetails)
ecDetails.PaymentDetails(0).ShipToAddress = shipAddress
request.SetExpressCheckoutRequestDetails = ecDetails
End Sub
Private Sub setKeyResponseObjects(ByVal service As PayPalAPIInterfaceServiceService, ByVal setECResponse As SetExpressCheckoutResponseType)
Dim keyResponseParameters As New Dictionary(Of String, String)
keyResponseParameters.Add("API Status", setECResponse.Ack.ToString())
Dim CurrContext As HttpContext = HttpContext.Current
If (setECResponse.Ack.Equals(AckCodeType.FAILURE) Or ((Not IsNothing(setECResponse.Errors)) And setECResponse.Errors.Count > 0)) Then
ExceptionUtility.LogInfo(setECResponse.Errors.Item(0).LongMessage)
CurrContext.Items.Add("Response_error", setECResponse.Errors)
CurrContext.Items.Add("Response_redirectURL", Nothing)
Else
CurrContext.Items.Add("Response_error", Nothing)
keyResponseParameters.Add("EC token", setECResponse.Token)
Dim paypalUrl As String = ConfigManager.Instance.GetProperty("paypalUrl").ToString()
CurrContext.Items.Add("Response_redirectURL", paypalUrl + "_express-checkout&token=" + setECResponse.Token)
End If
CurrContext.Items.Add("Response_keyResponseObject", keyResponseParameters)
CurrContext.Items.Add("Response_apiName", "SetExpressCheckout")
CurrContext.Items.Add("Response_requestPayload", service.getLastRequest())
CurrContext.Items.Add("Response_responsePayload", service.getLastResponse())
Response.Redirect(CurrContext.Items.Item("Response_redirectURL"))
'Server.Transfer("APIResponse.aspx")
Dim a As String = ""
End Sub
结束班
非工作版
Imports PayPal.PayPalAPIInterfaceService.Model
导入PayPal.PayPalAPIInterfaceService 进口PayPal.Manager
部分班级paypalExpressCheckout 继承System.Web.UI.Page
Dim currentPreSale As New PreSale
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Session("ShoppingCartDT") Is Nothing Then
currentPreSale = Session("currentPreSale")
Dim request As New SetExpressCheckoutRequestType
populateRequestObject(request)
'Invoke the API
Dim wrapper As New SetExpressCheckoutReq
wrapper.SetExpressCheckoutRequest = request
Dim service As New PayPalAPIInterfaceServiceService
Dim setECResponse As SetExpressCheckoutResponseType = service.SetExpressCheckout(wrapper)
'Check for API return status
Dim CurrContext As HttpContext = HttpContext.Current
CurrContext.Items.Add("paymentDetails", request.SetExpressCheckoutRequestDetails.PaymentDetails)
setKeyResponseObjects(service, setECResponse)
Else
End If
End Sub
Private Sub SetShippingAddress(ByRef shippingAddress As AddressType)
Dim selectedCountry As New Country
Dim currentUser As User = Session("currentUser")
selectedCountry.GetCountryDetails(currentPreSale.DeliveryCountryId.ToString())
shippingAddress.Name = currentUser.FirstName & " " & currentUser.LastName
shippingAddress.Street1 = currentPreSale.DeliveryAddress
shippingAddress.Street2 = ""
shippingAddress.CityName = ""
shippingAddress.StateOrProvince = ""
shippingAddress.Country = [Enum].Parse(GetType(CountryCodeType), selectedCountry.CountryCode)
shippingAddress.Phone = currentUser.Phone & ""
shippingAddress.PostalCode = ""
End Sub
Private Sub populateRequestObject(ByRef request As SetExpressCheckoutRequestType)
Dim deliveryAddress As New Address
Dim currentUser As User = Session("currentUser")
Dim selectedCurrency As New Currency
selectedCurrency.GetCurrencyDetails(currentPreSale.CurrencyId.ToString())
'Dim userDetails As New UserDetails
Dim currency As CurrencyCodeType = selectedCurrency.PayPalCurrencyCode
Dim ecDetails As New SetExpressCheckoutRequestDetailsType
Dim paymentDetails As New PaymentDetailsType
Dim orderTotal As Double = 0
Dim itemTotal As Double = 0
Dim shippingValue As Double = currentPreSale.ShippingTotal
Dim HandlingTotal As Double = 0
Dim TaxTotal As Double = 0
Dim shipAddress As New AddressType
Dim dataTableCarrinho As DataTable
Dim dataRowCarrinho As DataRow
If currentPreSale.ShippingTotal > 0 Then
SetShippingAddress(shipAddress)
End If
'userDetails.Get_ItemDetails(Session("userId").ToString())
ecDetails.ReturnURL = ConfigurationManager.AppSettings("appURL") & "doExpressCheckoutPayment.aspx"
ecDetails.CancelURL = ConfigurationManager.AppSettings("appCurrentServer") & Page.GetRouteUrl("paypalCancel" & UCase(Left(Session("language"), 2)), New With {.lang = Left(Session("language"), 2)})
ecDetails.BuyerEmail = currentUser.Email
ecDetails.ReqConfirmShipping = 0
ecDetails.AddressOverride = 0
If CDec(currentPreSale.ShippingTotal) > 0 Then
ecDetails.NoShipping = 0
Else
ecDetails.NoShipping = 1
End If
'Payment Details
If (shippingValue > 0) Then
paymentDetails.ShippingTotal = New BasicAmountType(currency, currentPreSale.ShippingTotal * currentPreSale.ExchangeRate)
End If
paymentDetails.OrderDescription = "KTB Order"
paymentDetails.PaymentAction = PaymentActionCodeType.SALE
orderTotal += shippingValue * currentPreSale.ExchangeRate
'Lista de Items - GUY preencher
dataTableCarrinho = Session("ShoppingCartDT")
For Each dataRowCarrinho In dataTableCarrinho.Rows
Dim currentProduct As New Product
currentProduct.GetProductDetails(dataRowCarrinho("ProductId").ToString(), Session("LanguageId").ToString())
Dim itemDetails As New PaymentDetailsItemType
itemDetails.Name = currentProduct.Title
'itemDetails.Amount = New BasicAmountType(currency, dataRowCarrinho("Price").ToString())
itemDetails.Amount = New BasicAmountType(currency, CDec(dataRowCarrinho("Price") * currentPreSale.ExchangeRate))
itemDetails.Quantity = CInt(dataRowCarrinho("Quantity"))
itemDetails.Tax = New BasicAmountType(currency, 0)
itemDetails.Description = ""
itemDetails.ItemCategory = ItemCategoryType.PHYSICAL
paymentDetails.PaymentDetailsItem.Add(itemDetails)
orderTotal += CDec(dataRowCarrinho("Price")) * CInt(dataRowCarrinho("Quantity") * currentPreSale.ExchangeRate)
itemTotal += CDec(dataRowCarrinho("Price")) * CInt(dataRowCarrinho("Quantity") * currentPreSale.ExchangeRate)
Next
'ExceptionUtility.LogInfo("orderTotal = " & orderTotal)
'ExceptionUtility.LogInfo("itemTotal = " & itemTotal)
'ExceptionUtility.LogInfo("shippingTotal = " & (currentPreSale.ShippingTotal * currentPreSale.ExchangeRate))
'paymentDetails.ItemTotal = New BasicAmountType(currency, CDec(currentPreSale.ProductTotal * currentPreSale.ExchangeRate))
'paymentDetails.OrderTotal = New BasicAmountType(currency, CDec((currentPreSale.ProductTotal + currentPreSale.ShippingTotal) * currentPreSale.ExchangeRate))
paymentDetails.ItemTotal = New BasicAmountType(currency, itemTotal)
paymentDetails.OrderTotal = New BasicAmountType(currency, orderTotal)
ecDetails.PaymentDetails.Add(paymentDetails)
ecDetails.PaymentDetails(0).ShipToAddress = shipAddress
request.SetExpressCheckoutRequestDetails = ecDetails
End Sub
Private Sub setKeyResponseObjects(ByVal service As PayPalAPIInterfaceServiceService, ByVal setECResponse As SetExpressCheckoutResponseType)
Dim keyResponseParameters As New Dictionary(Of String, String)
keyResponseParameters.Add("API Status", setECResponse.Ack.ToString())
Dim CurrContext As HttpContext = HttpContext.Current
If (setECResponse.Ack.Equals(AckCodeType.FAILURE) Or ((Not IsNothing(setECResponse.Errors)) And setECResponse.Errors.Count > 0)) Then
ExceptionUtility.LogInfo(setECResponse.Errors.Item(0).LongMessage)
CurrContext.Items.Add("Response_error", setECResponse.Errors)
CurrContext.Items.Add("Response_redirectURL", Nothing)
Else
CurrContext.Items.Add("Response_error", Nothing)
keyResponseParameters.Add("EC token", setECResponse.Token)
Dim paypalUrl As String = ConfigManager.Instance.GetProperty("paypalUrl").ToString()
CurrContext.Items.Add("Response_redirectURL", paypalUrl + "_express-checkout&token=" + setECResponse.Token)
End If
CurrContext.Items.Add("Response_keyResponseObject", keyResponseParameters)
CurrContext.Items.Add("Response_apiName", "SetExpressCheckout")
CurrContext.Items.Add("Response_requestPayload", service.getLastRequest())
CurrContext.Items.Add("Response_responsePayload", service.getLastResponse())
Response.Redirect(CurrContext.Items.Item("Response_redirectURL"))
'Server.Transfer("APIResponse.aspx")
Dim a As String = ""
End Sub
结束班
它不断向我发出以下错误:
项目金额无效。
任何人都知道发生了什么以及如何解决这个问题?
THX