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

Apple receipt field app_item_id type mismatch #44

Closed
kokteyldev opened this issue Oct 20, 2017 · 3 comments · Fixed by #51
Closed

Apple receipt field app_item_id type mismatch #44

kokteyldev opened this issue Oct 20, 2017 · 3 comments · Fixed by #51

Comments

@kokteyldev
Copy link

kokteyldev commented Oct 20, 2017

As stated here Apple Receipt Fields "app_item_id" field should be a string but in the library it is mapped to int64. This causes an error during json decoding.

EDIT:
Apparently Apple is giving out different responses some has app_item_id as string and some has it as a number. In this case a custom type that implements Unmarshaler interface would be better suited for this. Something like the following:

	Receipt struct {
		ReceiptType                string        `json:"receipt_type"`
		AdamID                     int64         `json:"adam_id"`
		AppItemID                  NumericString `json:"app_item_id"`
		BundleID                   string        `json:"bundle_id"`
		ApplicationVersion         string        `json:"application_version"`
		DownloadID                 int64         `json:"download_id"`
		OriginalApplicationVersion string        `json:"original_application_version"`
		InApp                      []InApp       `json:"in_app"`
		RequestDate
		OriginalPurchaseDate
	}

        func (n NumericString) UnmarshalJSON(data []byte) error {
	        n = NumericString(string(data))
	        return nil
        }
@jun06t
Copy link
Contributor

jun06t commented Dec 21, 2017

"app_item_id" field is string

I guess your receipt is iOS 6 style.
This library supports the receipt style for iOS7 or above.
However this library doesn't enforce our receipt definition on you, because I implemented the response as interface{}

https://github.com/dogenzaka/go-iap/blob/8266e878ac53f89fbd6528323a34ecc0f783a149/appstore/validator.go#L109-L126

So you can use your original receipt definition to solve it.

@wasedaigo
Copy link

wasedaigo commented Feb 6, 2018

I got an error in production. my phone is iOS11.
For now, I turned off the validation
It seemed to work fine with sandbox and beta... I am confused

Failed ValidateIosReceipt: json: cannot unmarshal string into Go struct field Receipt.app_item_id of type int64

@wasedaigo
Copy link

wasedaigo commented Feb 9, 2018

@jun06t Great fix! But would you mind explaining the background of this issue a bit? Did Apple change anything recently?

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

Successfully merging a pull request may close this issue.

3 participants