Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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]
}
// 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
You can’t perform that action at this time.