PayPal Checkout v2 SDK .NET problem with PayPalHttp.HttpResponse

I'm having a problem in the last part of a transaction setup flow: the client side correctly calls my backend which makes a call to PayPal to create the order and receives a response with status code 200.

The error occurs when the http response is returned to the client, here we realize that the json that was created by the paypal class is incomplete! There are no closing parentheses that invalidate the json. "} ] }"

I asked the paypal team for assistance but it is not helping me. They continue to go around the problem, saying that the bees always return the complete json to me, but I know this too, because in debug mode the result gives me a link that correctly sends me back to the paypal payment.

This makes me understand that in reality the flow that I created is complete but the PayPalHttp.HttpResponse class creates an incorrect body.

I am attaching the code.

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

This is the incomplete 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": "[email protected]",
        "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: the project is in VB.NET 4.6.1 (web forms)

Answers:

Answer

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

What is response here?

And can you debug the value further in, within PayPalClient.client().Execute(request)

PayPal sends JSON over the network. So it seems you are receiving JSON, which is converted into an Object, and then you are calling a function on that object that gives back JSON.

I am not sure why that particular function is giving bad JSON at the moment you call it, but I do know that the original JSON from PayPal is probably complete.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.