Skip to content

Commit

Permalink
Only verify verifiable events
Browse files Browse the repository at this point in the history
Summary: To be consistent with the legacy implementation, we should only send a validation result for events that are validated (i.e. purchases, subscriptions, and restored events). We also update the default quantity to be 1 when the transaction is nil because we cannot have a purchase for a quantity of 0.

Reviewed By: jjiang10

Differential Revision: D65005873

fbshipit-source-id: bd31adf9622357e68135ae1fd6fe09c7f7e6d477
  • Loading branch information
ryantobinmeta authored and facebook-github-bot committed Oct 26, 2024
1 parent 2a76af3 commit bda4393
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ enum IAPConstants {
static let IAPSDKLibraryVersions = "SK1-SK2"
static let eventsForReceipt: Set<AppEvents.Name> = [.purchased, .subscribe, .startTrial]
static let dedupableEvents: Set<AppEvents.Name> = [.purchased, .subscribe, .startTrial]
static let verifiableEvents: Set<AppEvents.Name> = [
.purchased,
.subscribe,
.startTrial,
.purchaseRestored,
.subscribeRestore,
]
static let manuallyLoggedDedupableEventsKey = "com.facebook.sdk:ManualDedupableEventsKey"
static let implicitlyLoggedDedupableEventsKey = "com.facebook.sdk:ImplicitDedupableEventsKey"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -494,7 +494,7 @@ extension IAPEventResolverTests {
productTitle: product.displayName,
productDescription: product.description,
amount: 3,
quantity: 0,
quantity: 1,
currency: "USD",
transactionID: nil,
originalTransactionID: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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 &&
Expand Down

0 comments on commit bda4393

Please sign in to comment.