Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json: cannot unmarshal string into Go value of type int #18

Closed
jurij opened this issue Oct 23, 2016 · 3 comments
Closed

json: cannot unmarshal string into Go value of type int #18

jurij opened this issue Oct 23, 2016 · 3 comments

Comments

@jurij
Copy link

jurij commented Oct 23, 2016

Hello,

is it out of date? Am I missing something?

--- FAIL: Test (4.55s)
panic: json: cannot unmarshal string into Go value of type int [recovered]
        panic: json: cannot unmarshal string into Go value of type int

...
package paypal

import (
    "log"
    "os"

    "github.com/logpacker/PayPal-Go-SDK"
)

func run() {
    c, err := paypalsdk.NewClient(
        "...",
        "...",
        paypalsdk.APIBaseLive,
    )
    if err != nil {
        panic(err)
    }
    c.SetLog(os.Stdout)
    _, err = c.GetAccessToken()
    if err != nil {
        panic(err)
    }

    payments, err := c.GetPayments()
    if err != nil {
        panic(err) // here
    }
    log.Println(payments)
}

@plutov
Copy link
Owner

plutov commented Oct 24, 2016

I don't see this error, how did you run tests? Because I have executed tests and don't have any errors

@jurij
Copy link
Author

jurij commented Oct 24, 2016

I used my own test to call the run() function.

I checked the raw result of PayPals API.
Quantity is somehow a string.
I managed to make it work, I had to change this:

        Item struct {
-               Quantity    int    `json:"quantity"`
+               Quantity    string `json:"quantity"`

I cant tell you, why its returning a string for me.

This Item was not created by myself, its something I bought some time ago:

"item_list":{  
    "items":[  
    {  
        "name":"...",
        "price":"22.99",
        "currency":"GBP",
        "quantity":"1"
    }
],

However, I cant use PayPals API. I thought I could load ALL payments, which is not the case (Thanks PayPal...). Looks like I have to use NVP/SOAP.

@plutov
Copy link
Owner

plutov commented Oct 24, 2016

I fixed it, so now this value is decoded correctly.

@plutov plutov closed this as completed Oct 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants