PayPal Checkout v2 SDK .NET problem with PayPalHttp.HttpResp



我在事务设置流程的最后部分遇到了一个问题:客户端正确地调用我的后端,该后端调用PayPal来创建订单并接收具有状态代码200的响应。

当http响应返回到客户端时会发生错误,在这里我们意识到贝宝类创建的json是不完整的!没有使json无效的右括号。"}]}">

我向贝宝团队寻求帮助,但它对我没有帮助。他们继续绕过这个问题,说蜜蜂总是向我返回完整的json,但我也知道这一点,因为在调试模式下,结果会给我一个链接,正确地将我发送回贝宝支付。

这让我明白,实际上我创建的流是完整的,但PayPalHttp.HttpResponse类创建了一个不正确的主体。

我正在附上代码。

Public Shared Async Function CreateOrder(ByVal Optional debug As Boolean = False) As Task(Of PayPalHttp.HttpResponse)
Dim result As New Order
Dim request = New OrdersCreateRequest()
request.Prefer("return=representation")
Dim newRequest As New OrderActionRequest
request.RequestBody(BuildRequestBody(dicNameValue))

Dim response = Await PayPalClient.client().Execute(request)
If debug Then
result = response.Result(Of Order)()
Console.WriteLine("Status: {0}", result.Status)
Console.WriteLine("Order Id: {0}", result.Id)
Console.WriteLine("Links:")
For Each link As LinkDescription In result.Links
Console.WriteLine(vbTab & "{0}: {1}" & vbTab & "Call Type: {2}", link.Rel, link.Href, link.Method)
Next
/*--- HERE THE PROBLEM ----*/
Dim json As String = PayPalClient.ObjectToJSONString(result)
Console.WriteLine("Response JSON: {0}", json)
/*----------*/
Dim amount As AmountWithBreakdown = result.PurchaseUnits(0).AmountWithBreakdown
Console.WriteLine("Total Amount: {0} {1}", amount.CurrencyCode, amount.Value)
End If
Return response
End Function

这是不完整的json:

{
"create_time": "2020-03-18T14:28:56Z",
"id": "2LW612087K897524T",
"intent": "CAPTURE",
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/2LW612087K897524T",
"method": "GET",
"rel": "self"
},
{
"href": "https://www.sandbox.paypal.com/checkoutnow?token=2LW612087K897524T",
"method": "GET",
"rel": "approve"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/2LW612087K897524T",
"method": "PATCH",
"rel": "update"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/2LW612087K897524T/capture",
"method": "POST",
"rel": "capture"
}
],
"purchase_units": [
{
"amount": {
"breakdown": {
"handling": {
"currency_code": "USD",
"value": "10.00"
},
"item_total": {
"currency_code": "USD",
"value": "180.00"
},
"shipping": {
"currency_code": "USD",
"value": "30.00"
},
"shipping_discount": {
"currency_code": "USD",
"value": "10.00"
},
"tax_total": {
"currency_code": "USD",
"value": "20.00"
}
},
"currency_code": "USD",
"value": "230.00"
},
"custom_id": "CUST-HighFashions",
"description": "Sporting Goods",
"items": [
{
"category": "PHYSICAL_GOODS",
"description": "Green XL",
"name": "T-shirt",
"quantity": "1",
"sku": "sku01",
"tax": {
"currency_code": "USD",
"value": "10.00"
},
"unit_amount": {
"currency_code": "USD",
"value": "90.00"
}
},
{
"category": "PHYSICAL_GOODS",
"description": "Running, Size 10.5",
"name": "Shoes",
"quantity": "2",
"sku": "sku02",
"tax": {
"currency_code": "USD",
"value": "5.00"
},
"unit_amount": {
"currency_code": "USD",
"value": "45.00"
}
}
],
"payee": {
"email_address": "sb-bzfcs1123474@business.example.com",
"merchant_id": "55J4WA53G7WRL"
},
"reference_id": "PUHF",
"shipping": {
"address": {
"address_line_1": "123 Townsend St",
"address_line_2": "Floor 6",
"admin_area_1": "CA",
"admin_area_2": "San Francisco",
"country_code": "US",
"postal_code": "94107"
},
"name": {
"full_name": "John Doe"
}
},

PS:该项目在VB.NET 4.6.1(web表单(中

Dim response=Await PayPalClient.client((.Execute(request(

这里的response是什么?

您可以在PayPalClient.client().Execute(request)中进一步调试该值吗

PayPal通过网络发送JSON。因此,您似乎正在接收JSON,它被转换为Object,然后您正在调用该对象上的一个函数,该函数将返回JSON。

我不确定为什么这个特定函数在您调用它的时候给出了糟糕的JSON,但我知道PayPal的原始JSON可能是完整的。

相关内容

  • 没有找到相关文章

最新更新