diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPConstants.swift b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPConstants.swift index fa6239745..f4811cba8 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPConstants.swift +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPConstants.swift @@ -19,6 +19,13 @@ enum IAPConstants { static let IAPSDKLibraryVersions = "SK1-SK2" static let eventsForReceipt: Set = [.purchased, .subscribe, .startTrial] static let dedupableEvents: Set = [.purchased, .subscribe, .startTrial] + static let verifiableEvents: Set = [ + .purchased, + .subscribe, + .startTrial, + .purchaseRestored, + .subscribeRestore, + ] static let manuallyLoggedDedupableEventsKey = "com.facebook.sdk:ManualDedupableEventsKey" static let implicitlyLoggedDedupableEventsKey = "com.facebook.sdk:ImplicitDedupableEventsKey" } diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPEvent.swift b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPEvent.swift index 99e34eab6..b796ea5ab 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPEvent.swift +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPEvent.swift @@ -34,4 +34,8 @@ struct IAPEvent: Equatable { var shouldAppendReceipt: Bool { storeKitVersion == .version1 && IAPConstants.eventsForReceipt.contains(eventName) } + + var isClientSideVerifiable: Bool { + storeKitVersion == .version2 && IAPConstants.verifiableEvents.contains(eventName) + } } diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPEventResolver.swift b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPEventResolver.swift index 2a4d4e385..68b6e90f2 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPEventResolver.swift +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPEventResolver.swift @@ -168,7 +168,7 @@ extension IAPEventResolver { productTitle: product.displayName, productDescription: product.description, amount: transaction?.price ?? product.price, - quantity: transaction?.purchasedQuantity ?? 0, + quantity: transaction?.purchasedQuantity ?? 1, currency: currency ?? product.priceFormatStyle.currencyCode, transactionID: transactionID, originalTransactionID: originalTransactionID, diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPTransactionLogger.swift b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPTransactionLogger.swift index 49aeaa5d4..05d08f740 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPTransactionLogger.swift +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPTransactionLogger.swift @@ -95,7 +95,7 @@ extension IAPTransactionLogger { } else { parameters[.inAppPurchaseType] = IAPType.product.rawValue } - if event.storeKitVersion == .version2 { + if event.isClientSideVerifiable { parameters[.validationResult] = event.validationResult?.rawValue ?? IAPValidationResult.unverified.rawValue } if event.shouldAppendReceipt, let receipt = fetchDeviceReceipt() { diff --git a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/IAP/IAPTests/IAPEventResolverTests.swift b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/IAP/IAPTests/IAPEventResolverTests.swift index 6ddb4f853..449b96c8f 100644 --- a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/IAP/IAPTests/IAPEventResolverTests.swift +++ b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/IAP/IAPTests/IAPEventResolverTests.swift @@ -459,7 +459,7 @@ extension IAPEventResolverTests { productTitle: product.displayName, productDescription: product.description, amount: 0.99, - quantity: 0, + quantity: 1, currency: "USD", transactionID: nil, originalTransactionID: nil, @@ -494,7 +494,7 @@ extension IAPEventResolverTests { productTitle: product.displayName, productDescription: product.description, amount: 3, - quantity: 0, + quantity: 1, currency: "USD", transactionID: nil, originalTransactionID: nil, diff --git a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/IAP/IAPTests/IAPTransactionLoggerTests.swift b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/IAP/IAPTests/IAPTransactionLoggerTests.swift index 272d20ca5..d0c211889 100644 --- a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/IAP/IAPTests/IAPTransactionLoggerTests.swift +++ b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/IAP/IAPTests/IAPTransactionLoggerTests.swift @@ -962,7 +962,7 @@ extension IAPTransactionLoggerTests { return self.eventLogger.capturedEventName == .purchaseFailed && self.eventLogger.capturedValueToSum == 0.99 && capturedParameters[.contentID] as? String == product.id && - capturedParameters[.numItems] as? Int == 0 && + capturedParameters[.numItems] as? Int == 1 && (capturedParameters[.transactionDate] as? String)?.isEmpty == true && (capturedParameters[.productTitle] as? String)?.isEmpty == true && (capturedParameters[.description] as? String)?.isEmpty == true && @@ -992,7 +992,7 @@ extension IAPTransactionLoggerTests { return self.eventLogger.capturedEventName == .subscribeFailed && self.eventLogger.capturedValueToSum == 2.0 && capturedParameters[.contentID] as? String == product.id && - capturedParameters[.numItems] as? Int == 0 && + capturedParameters[.numItems] as? Int == 1 && (capturedParameters[.transactionDate] as? String)?.isEmpty == true && (capturedParameters[.productTitle] as? String)?.isEmpty == true && (capturedParameters[.description] as? String)?.isEmpty == true &&