Skip to content

Conversation

StefanPrintezis
Copy link

@StefanPrintezis StefanPrintezis commented Jun 23, 2025

Summary

This PR fixes an inconsistency in the AppTransaction model where the property was named receiptType instead of environment, which doesn't match Apple's official API documentation.

Changes Made

  • Renamed property: Changed receiptType to environment in AppTransaction.swift to match Apple's official documentation
  • Updated all references: Modified all code that referenced receiptType to use environment instead
  • Fixed JSON encoding/decoding: Updated CodingKeys and serialization logic to use environment
  • Updated test files: Modified test assertions to use the new property name
  • Updated test data: Changed JSON test file to use "environment" key instead of "receiptType"
  • Added backward compatibility: The decoder now accepts both environment and receiptType fields to maintain compatibility with existing signed JWT tokens in test data

Files Changed

  • Sources/AppStoreServerLibrary/Models/AppTransaction.swift - Main property rename and backward compatibility
  • Sources/AppStoreServerLibrary/SignedDataVerifier.swift - Updated reference in verification logic
  • Tests/AppStoreServerLibraryTests/XcodeSignedDataVerifierTests.swift - Updated test assertions
  • Tests/AppStoreServerLibraryTests/SignedModelTests.swift - Updated test assertions
  • Tests/AppStoreServerLibraryTests/resources/models/appTransaction.json - Updated test data

Why This Change

The library was inconsistent with Apple's official API. Other models in the same library (like JWSTransactionDecodedPayload) correctly use environment, but AppTransaction was using receiptType. This creates confusion and inconsistency for developers using the library.

Backward Compatibility

The change includes backward compatibility to handle existing signed JWT tokens that may still contain the old receiptType field name, ensuring existing integrations continue to work while new code can use the correct environment property name.

Testing

All tests pass, including the Xcode signed data tests that use pre-signed JWT tokens with the old field name.

@StefanPrintezis StefanPrintezis marked this pull request as ready for review June 23, 2025 14:58
riyazpanjwani
riyazpanjwani previously approved these changes Jun 23, 2025
@riyazpanjwani riyazpanjwani self-requested a review June 23, 2025 20:30
@riyazpanjwani riyazpanjwani dismissed their stale review June 23, 2025 20:31

Need to talk to Alex about this.

@StefanPrintezis
Copy link
Author

I had some more issues decoding some payloads using this model, maybe I'm missing something since I'm having trouble finding docs that mention receipt_type at all. Is this model deprecated or should it not exist in favor of e.g. JWSTransactionDecodedPayload.swift?

@alexanderjordanbaker
Copy link
Collaborator

@StefanPrintezis The docs you are reviewing are the docs for the StoreKit object, they aren't the docs for the JSON format for AppTransaction. receiptType is the appropriate JSON name for this field, and the example JSON in the unit tests is accurate to our understanding. If you encounter an issue decoding an AppTransaction let us know. Note an AppTransaction is a different object than an in-app transaction, which corresponds to JWSTransactionDecodedPayload

@riyazpanjwani riyazpanjwani removed their request for review June 26, 2025 18:50
@StefanPrintezis
Copy link
Author

StefanPrintezis commented Jun 27, 2025

I think the confusion arrises since we're linking to the StoreKit AppTransaction in the model file.
https://github.com/apple/app-store-server-library-swift/pull/93/files#diff-31aeaa6dc4f061305feeefd147a4f8d7ccf9a56904f63803e780e301b4bb8b97L8

///[AppTransaction](https://developer.apple.com/documentation/storekit/apptransaction)
public struct AppTransaction: DecodedSignedData, Decodable, Encodable, Hashable, Sendable {

@alexanderjordanbaker
Copy link
Collaborator

Yes, but the StoreKit docs, for any type, do not state the jsonRepresentation is equivalent to the Swift fields https://developer.apple.com/documentation/storekit/apptransaction/jsonrepresentation

@StefanPrintezis
Copy link
Author

StefanPrintezis commented Jun 27, 2025

The jsonRepresentation is UTF-8 string data that contains the same information as the properties of the AppTransaction. You can use this JSON data to decode the app transaction information into your own data type instead of using AppTransaction properties directly.

https://developer.apple.com/documentation/storekit/apptransaction/jsonrepresentation

Is the json structure documented somewhere? There is some room for interpretation that led me to believe the properties are the same

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 this pull request may close these issues.

3 participants