Last active
February 6, 2020 08:54
-
-
Save mxcl/c7cf26ca4e19f37cafcece9f5fc3a777 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct AppleReceiptValidationResponse: Decodable { | |
let status: Int | |
let environment: String | |
struct Receipt: Decodable { | |
let receipt_type: String | |
let adam_id: Int | |
let app_item_id: Int | |
let bundle_id: String | |
let application_version: String | |
let download_id: Int | |
let version_external_identifier: Int | |
let receipt_creation_date_ms: Date | |
let request_date_ms: Date | |
let original_purchase_date_ms: Date | |
let original_application_version: String | |
struct InApp: Decodable { | |
let quantity: String | |
let product_id: String | |
let transaction_id: String | |
let original_transaction_id: String | |
let purchase_date_ms: Date | |
let original_purchase_date_ms: Date | |
let expires_date_ms: Date | |
let web_order_line_item_id: String | |
let is_trial_period: String | |
let is_in_intro_offer_period: String | |
} | |
let in_app: [InApp] | |
} | |
let receipt: Receipt | |
struct LatestReceiptInfo: Decodable { | |
let quantity: String | |
let product_id: String | |
let transaction_id: String | |
let original_transaction_id: String | |
let purchase_date_ms: Date | |
let original_purchase_date_ms: Date | |
let expires_date_ms: Date | |
let web_order_line_item_id: String | |
let is_trial_period: String | |
let is_in_intro_offer_period: String | |
} | |
let latest_receipt_info: [LatestReceiptInfo] | |
let latest_receipt: String | |
struct PendingRenewalInfo: Decodable { | |
let expiration_intent: String | |
let auto_renew_product_id: String | |
let original_transaction_id: String | |
let is_in_billing_retry_period: String | |
let product_id: String | |
let auto_renew_status: String | |
} | |
let pending_renewal_info: [PendingRenewalInfo] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the dates come back contained in Strings representing the milliseconds | |
// since the UNIX epoch so we need a custom date decoding strategy | |
let decoder = JSONDecoder() | |
decoder.dateDecodingStrategy = .custom { decoder in | |
let container = try decoder.singleValueContainer() | |
let dateString = try container.decode(String.self) | |
guard let ms = TimeInterval(dateString) else { | |
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Expected String containing Int") | |
} | |
return Date(timeIntervalSince1970: ms / 1000) | |
} | |
print(try decoder.decode(AppleReceiptValidationResponse.self, from: $0.data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment