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

Unwrap receipt["receipt"]?["in_app"] in two steps to work around cast returning nil #283

Merged
merged 5 commits into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
* Add `fetchReceipt` method. Update `verifyReceipt` to use it ([#278](https://github.com/bizz84/SwiftyStoreKit/pull/278), related issues: [#272](https://github.com/bizz84/SwiftyStoreKit/issues/272), [#223](https://github.com/bizz84/SwiftyStoreKit/issues/223)).
* Update `fetchReceipt` and `ReceiptValidator` to use receipt as `Data` rather than `String`. This is consistent with `localReceiptData` ([#284](https://github.com/bizz84/SwiftyStoreKit/pull/284), see [#272](https://github.com/bizz84/SwiftyStoreKit/issues/272)).
* Remove `password` from `ReceiptValidator` protocol as this is specific to `AppleReceiptValidator` ([#281](https://github.com/bizz84/SwiftyStoreKit/pull/281/), see [#263](https://github.com/bizz84/SwiftyStoreKit/issues/263)). **Note**: This is an API breaking change.
* Unwrap `receipt["receipt"]?["in_app"]` in two steps (addresses casting problems) ([#283](https://github.com/bizz84/SwiftyStoreKit/pull/283), related issue [#256](https://github.com/bizz84/SwiftyStoreKit/issues/256)).


## [0.10.8](https://github.com/bizz84/SwiftyStoreKit/releases/tag/0.10.8) Update to swiftlint 0.22.0
Expand Down
14 changes: 10 additions & 4 deletions SwiftyStoreKit/InAppReceipt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ internal class InAppReceipt {
) -> VerifyPurchaseResult {

// Get receipts info for the product
let receipts = receipt["receipt"]?["in_app"] as? [ReceiptInfo]
let receiptsInfo = filterReceiptsInfo(receipts: receipts, withProductId: productId)
let nonCancelledReceiptsInfo = receiptsInfo.filter { receipt in receipt["cancellation_date"] == nil }
let receipts = getInAppReceipts(receipt: receipt)
let filteredReceiptsInfo = filterReceiptsInfo(receipts: receipts, withProductId: productId)
let nonCancelledReceiptsInfo = filteredReceiptsInfo.filter { receipt in receipt["cancellation_date"] == nil }

let receiptItems = nonCancelledReceiptsInfo.flatMap { ReceiptItem(receiptInfo: $0) }
// Verify that at least one receipt has the right product id
Expand Down Expand Up @@ -174,7 +174,7 @@ internal class InAppReceipt {
case .autoRenewable:
return (receipt["latest_receipt_info"] as? [ReceiptInfo], nil)
case .nonRenewing(let duration):
return (receipt["receipt"]?["in_app"] as? [ReceiptInfo], duration)
return (getInAppReceipts(receipt: receipt), duration)
}
}

Expand All @@ -186,6 +186,12 @@ internal class InAppReceipt {
}
return Date(millisecondsSince1970: requestDateString)
}

private class func getInAppReceipts(receipt: ReceiptInfo) -> [ReceiptInfo]? {

let appReceipt = receipt["receipt"] as? ReceiptInfo
return appReceipt?["in_app"] as? [ReceiptInfo]
}

/**
* Get all the receipts info for a specific product
Expand Down