Skip to content

Commit a8a1036

Browse files
committed
[in_app_purchase] Fixes StoreKit 2 date format does not match in_app_purchase_platform_interface
- As per `PurchaseDetails.transactionDate` api documentation, date should be `Milliseconds since epoch` but the migration to StoreKit2 probably mistakenly changed the date format to "yyyy-MM-dd HH:mm:ss". The issue originated in StoreKit2Translators.swift `extension Transaction convertToPigeon` which was using a magic hardcoded formatter dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" - Fixes both `SK2Transaction.purchaseDate` and `SK2Transaction.expirationDate` and ultimately `PurchaseDetails.transactionDate` Unfortunately it is not testable because the StoreKit 2 Transaction type has no visible initializers, probably thats why there are no tests for StoreKit2Translators.swift `extension Transaction convertToPigeon` Fixes flutter/flutter#175072
1 parent d060692 commit a8a1036

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.4.10
2+
3+
* Fixes StoreKit 2 date format does not match in_app_purchase_platform_interface PurchaseDetails.transactionDate format.
4+
Fixes both `SK2Transaction.purchaseDate` and `SK2Transaction.expirationDate`.
5+
16
## 0.4.9
27

38
* Add support for offer codes in StoreKit 2.

packages/in_app_purchase/in_app_purchase_storekit/darwin/in_app_purchase_storekit/Sources/in_app_purchase_storekit/StoreKit2/StoreKit2Translators.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,12 @@ extension Product.PurchaseResult {
194194
extension Transaction {
195195
func convertToPigeon(receipt: String?, status: SK2PurchaseStatusMessage) -> SK2TransactionMessage
196196
{
197-
198-
let dateFormatter = DateFormatter()
199-
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
200-
201197
return SK2TransactionMessage(
202198
id: Int64(id),
203199
originalId: Int64(originalID),
204200
productId: productID,
205-
purchaseDate: dateFormatter.string(from: purchaseDate),
206-
expirationDate: expirationDate.map { dateFormatter.string(from: $0) },
201+
purchaseDate: String(Int64(purchaseDate.timeIntervalSince1970 * 1000)),
202+
expirationDate: expirationDate.map { String(Int64($0.timeIntervalSince1970 * 1000)) },
207203
purchasedQuantity: Int64(purchasedQuantity),
208204
appAccountToken: appAccountToken?.uuidString,
209205
receiptData: receipt,

packages/in_app_purchase/in_app_purchase_storekit/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: in_app_purchase_storekit
22
description: An implementation for the iOS and macOS platforms of the Flutter `in_app_purchase` plugin. This uses the StoreKit Framework.
33
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_storekit
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
5-
version: 0.4.9
5+
version: 0.4.10
66

77
environment:
88
sdk: ^3.10.0

0 commit comments

Comments
 (0)