Skip to content

Commit

Permalink
Paywalls: removed presentedPaywallViewMode (#3109)
Browse files Browse the repository at this point in the history
We're going to track this in a different way in the future.
  • Loading branch information
NachoSoto committed Sep 7, 2023
1 parent ada7a9b commit f937e64
Show file tree
Hide file tree
Showing 23 changed files with 21 additions and 93 deletions.
6 changes: 3 additions & 3 deletions RevenueCatUI/Data/TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ extension TrialOrIntroEligibilityChecker {
extension PurchaseHandler {

static func mock() -> Self {
return self.init { _, _ in
return self.init { _ in
return (
transaction: nil,
customerInfo: TestData.customerInfo,
Expand All @@ -480,7 +480,7 @@ extension PurchaseHandler {
}

static func cancelling() -> Self {
return self.init { _, _ in
return self.init { _ in
return (
transaction: nil,
customerInfo: TestData.customerInfo,
Expand All @@ -496,7 +496,7 @@ extension PurchaseHandler {
return self.map { purchaseBlock in {
await Task.sleep(seconds: seconds)

return try await purchaseBlock($0, $1)
return try await purchaseBlock($0)
}
} restore: { restoreBlock in {
await Task.sleep(seconds: seconds)
Expand Down
9 changes: 4 additions & 5 deletions RevenueCatUI/Purchasing/PurchaseHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SwiftUI
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
final class PurchaseHandler: ObservableObject {

typealias PurchaseBlock = @Sendable (Package, PaywallViewMode) async throws -> PurchaseResultData
typealias PurchaseBlock = @Sendable (Package) async throws -> PurchaseResultData
typealias RestoreBlock = @Sendable () async throws -> CustomerInfo

private let purchaseBlock: PurchaseBlock
Expand All @@ -41,8 +41,7 @@ final class PurchaseHandler: ObservableObject {
fileprivate(set) var restored: Bool = false

convenience init(purchases: Purchases = .shared) {
self.init { package, mode in
purchases.cachePresentedPaywallMode(mode)
self.init { package in
return try await purchases.purchase(package: package)
} restorePurchases: {
return try await purchases.restorePurchases()
Expand All @@ -67,13 +66,13 @@ final class PurchaseHandler: ObservableObject {
extension PurchaseHandler {

@MainActor
func purchase(package: Package, with mode: PaywallViewMode) async throws -> PurchaseResultData {
func purchase(package: Package) async throws -> PurchaseResultData {
withAnimation(Constants.fastAnimation) {
self.actionInProgress = true
}
defer { self.actionInProgress = false }

let result = try await self.purchaseBlock(package, mode)
let result = try await self.purchaseBlock(package)

if !result.userCancelled {
withAnimation(Constants.defaultAnimation) {
Expand Down
2 changes: 1 addition & 1 deletion RevenueCatUI/Views/LoadingPaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private extension LoadingPaywallView {
)
})
static let purchaseHandler: PurchaseHandler = .init(
purchase: { _, _ in
purchase: { _ in
fatalError("Should not be able to purchase")
},
restorePurchases: {
Expand Down
3 changes: 1 addition & 2 deletions RevenueCatUI/Views/PurchaseButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ struct PurchaseButton: View {
AsyncButton {
guard !self.purchaseHandler.actionInProgress else { return }

_ = try await self.purchaseHandler.purchase(package: self.package.content,
with: self.mode)
_ = try await self.purchaseHandler.purchase(package: self.package.content)
} label: {
IntroEligibilityStateView(
textWithNoIntroOffer: self.package.localization.callToAction,
Expand Down
1 change: 0 additions & 1 deletion Sources/Identity/CustomerInfoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ private extension CustomerInfoManager {
let transactionData = PurchasedTransactionData(
appUserID: appUserID,
presentedOfferingID: nil,
presentedPaywallMode: nil,
unsyncedAttributes: [:],
storefront: await Storefront.currentStorefront,
source: Self.sourceForUnfinishedTransaction
Expand Down
9 changes: 2 additions & 7 deletions Sources/Logging/Strings/PurchaseStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ enum PurchaseStrings {
case transaction_poster_handling_transaction(transactionID: String,
productID: String,
transactionDate: Date,
offeringID: String?,
paywallMode: PaywallViewMode?)
offeringID: String?)
case caching_presented_offering_identifier(offeringID: String, productID: String)
case payment_queue_wrapper_delegate_call_sk1_enabled
case restorepurchases_called_with_allow_sharing_appstore_account_false
Expand Down Expand Up @@ -294,18 +293,14 @@ extension PurchaseStrings: LogMessage {
case let .sk2_transactions_update_received_transaction(productID):
return "StoreKit.Transaction.updates: received transaction for product '\(productID)'"

case let .transaction_poster_handling_transaction(transactionID, productID, date, offeringID, paywallMode):
case let .transaction_poster_handling_transaction(transactionID, productID, date, offeringID):
var message = "TransactionPoster: handling transaction '\(transactionID)' " +
"for product '\(productID)' (date: \(date))"

if let offeringIdentifier = offeringID {
message += " in Offering '\(offeringIdentifier)'"
}

if let paywallMode = paywallMode {
message += " with PaywallViewMode '\(paywallMode.identifier)'"
}

return message

case let .caching_presented_offering_identifier(offeringID, productID):
Expand Down
7 changes: 0 additions & 7 deletions Sources/Networking/Operations/PostReceiptDataOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ final class PostReceiptDataOperation: CacheableNetworkOperation {
let isRestore: Bool
let productData: ProductRequestData?
let presentedOfferingIdentifier: String?
let presentedPaywallMode: PaywallViewMode?
let observerMode: Bool
let initiationSource: ProductRequestData.InitiationSource
let subscriberAttributesByKey: SubscriberAttribute.Dictionary?
Expand Down Expand Up @@ -73,7 +72,6 @@ final class PostReceiptDataOperation: CacheableNetworkOperation {
\(configuration.appUserID)-\(postData.isRestore)-\(postData.receiptData.hashString)
-\(postData.productData?.cacheKey ?? "")
-\(postData.presentedOfferingIdentifier ?? "")-\(postData.observerMode)
-\(postData.presentedPaywallMode?.identifier ?? "")
-\(postData.subscriberAttributesByKey?.debugDescription ?? "")
"""

Expand Down Expand Up @@ -148,7 +146,6 @@ extension PostReceiptDataOperation.PostData {
isRestore: data.source.isRestore,
productData: productData,
presentedOfferingIdentifier: data.presentedOfferingID,
presentedPaywallMode: data.presentedPaywallMode,
observerMode: observerMode,
initiationSource: data.source.initiationSource,
subscriberAttributesByKey: data.unsyncedAttributes,
Expand Down Expand Up @@ -200,7 +197,6 @@ extension PostReceiptDataOperation.PostData: Encodable {
case attributes
case aadAttributionToken
case presentedOfferingIdentifier
case presentedPaywallMode
case testReceiptIdentifier = "test_receipt_identifier"

}
Expand All @@ -221,9 +217,6 @@ extension PostReceiptDataOperation.PostData: Encodable {
try container.encodeIfPresent(self.presentedOfferingIdentifier,
forKey: .presentedOfferingIdentifier)

try container.encodeIfPresent(self.presentedPaywallMode?.identifier,
forKey: .presentedPaywallMode)

try container.encodeIfPresent(
self.subscriberAttributesByKey
.map(SubscriberAttribute.map)
Expand Down
6 changes: 0 additions & 6 deletions Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1027,12 +1027,6 @@ public extension Purchases {

#endif

/// Used by the `RevenueCatUI` framework to keep track of what ``PaywallViewMode``
/// was used during a purchase.
func cachePresentedPaywallMode(_ mode: PaywallViewMode) {
self.purchasesOrchestrator.cachePresentedPaywallMode(mode)
}

}

// swiftlint:enable missing_docs
Expand Down
16 changes: 0 additions & 16 deletions Sources/Purchasing/Purchases/PurchasesOrchestrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ final class PurchasesOrchestrator {

private let _allowSharingAppStoreAccount: Atomic<Bool?> = nil
private let presentedOfferingIDsByProductID: Atomic<[String: String]> = .init([:])
private let presentedPaywallMode: Atomic<PaywallViewMode?> = nil
private let purchaseCompleteCallbacksByProductID: Atomic<[String: PurchaseCompletedBlock]> = .init([:])

private var appUserID: String { self.currentUserProvider.currentAppUserID }
Expand Down Expand Up @@ -547,10 +546,6 @@ final class PurchasesOrchestrator {
self.presentedOfferingIDsByProductID.modify { $0[productIdentifier] = identifier }
}

func cachePresentedPaywallMode(_ mode: PaywallViewMode) {
self.presentedPaywallMode.value = mode
}

#if os(iOS) || os(macOS) || VISION_OS

@available(watchOS, unavailable)
Expand Down Expand Up @@ -878,7 +873,6 @@ extension PurchasesOrchestrator: StoreKit2TransactionListenerDelegate {
data: .init(
appUserID: self.appUserID,
presentedOfferingID: nil,
presentedPaywallMode: nil,
unsyncedAttributes: subscriberAttributes,
aadAttributionToken: adServicesToken,
storefront: storefront,
Expand Down Expand Up @@ -984,7 +978,6 @@ private extension PurchasesOrchestrator {
}
}

// swiftlint:disable:next function_body_length
func syncPurchases(receiptRefreshPolicy: ReceiptRefreshPolicy,
isRestore: Bool,
initiationSource: ProductRequestData.InitiationSource,
Expand Down Expand Up @@ -1036,7 +1029,6 @@ private extension PurchasesOrchestrator {
transactionData: .init(
appUserID: currentAppUserID,
presentedOfferingID: nil,
presentedPaywallMode: nil,
unsyncedAttributes: unsyncedAttributes,
storefront: productRequestData?.storefront,
source: .init(isRestore: isRestore, initiationSource: initiationSource)
Expand Down Expand Up @@ -1085,7 +1077,6 @@ private extension PurchasesOrchestrator {
storefront: StorefrontType?,
restored: Bool) {
let offeringID = self.getAndRemovePresentedOfferingIdentifier(for: purchasedTransaction)
let paywallMode = self.getAndRemovePresentedPaywallMode()
let unsyncedAttributes = self.unsyncedAttributes
let adServicesToken = self.attribution.unsyncedAdServicesToken

Expand All @@ -1094,7 +1085,6 @@ private extension PurchasesOrchestrator {
data: .init(
appUserID: self.appUserID,
presentedOfferingID: offeringID,
presentedPaywallMode: paywallMode,
unsyncedAttributes: unsyncedAttributes,
aadAttributionToken: adServicesToken,
storefront: storefront,
Expand Down Expand Up @@ -1153,10 +1143,6 @@ private extension PurchasesOrchestrator {
return self.getAndRemovePresentedOfferingIdentifier(for: transaction.productIdentifier)
}

func getAndRemovePresentedPaywallMode() -> PaywallViewMode? {
return self.presentedPaywallMode.getAndSet(nil)
}

/// Computes a `ProductRequestData` for an active subscription found in the receipt,
/// or `nil` if there is any issue fetching it.
func createProductRequestData(
Expand Down Expand Up @@ -1221,7 +1207,6 @@ extension PurchasesOrchestrator {
) async throws -> CustomerInfo {
let storefront = await Storefront.currentStorefront
let offeringID = self.getAndRemovePresentedOfferingIdentifier(for: transaction)
let paywallMode = self.getAndRemovePresentedPaywallMode()
let unsyncedAttributes = self.unsyncedAttributes
let adServicesToken = self.attribution.unsyncedAdServicesToken

Expand All @@ -1230,7 +1215,6 @@ extension PurchasesOrchestrator {
data: .init(
appUserID: self.appUserID,
presentedOfferingID: offeringID,
presentedPaywallMode: paywallMode,
unsyncedAttributes: unsyncedAttributes,
aadAttributionToken: adServicesToken,
storefront: storefront,
Expand Down
4 changes: 1 addition & 3 deletions Sources/Purchasing/Purchases/TransactionPoster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct PurchasedTransactionData {

var appUserID: String
var presentedOfferingID: String?
var presentedPaywallMode: PaywallViewMode?
var unsyncedAttributes: SubscriberAttribute.Dictionary?
var aadAttributionToken: String?
var storefront: StorefrontType?
Expand Down Expand Up @@ -86,8 +85,7 @@ final class TransactionPoster: TransactionPosterType {
transactionID: transaction.transactionIdentifier,
productID: transaction.productIdentifier,
transactionDate: transaction.purchaseDate,
offeringID: data.presentedOfferingID,
paywallMode: data.presentedPaywallMode
offeringID: data.presentedOfferingID
))

self.receiptFetcher.receiptData(
Expand Down
24 changes: 2 additions & 22 deletions Tests/BackendIntegrationTests/StoreKitIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class StoreKit1IntegrationTests: BaseStoreKitIntegrationTests {
transactionID: transaction.transactionIdentifier,
productID: package.storeProduct.productIdentifier,
transactionDate: transaction.purchaseDate,
offeringID: package.offeringIdentifier,
paywallMode: nil
offeringID: package.offeringIdentifier
)
)
}
Expand Down Expand Up @@ -98,26 +97,7 @@ class StoreKit1IntegrationTests: BaseStoreKitIntegrationTests {
transactionID: transaction.transactionIdentifier,
productID: package.storeProduct.productIdentifier,
transactionDate: transaction.purchaseDate,
offeringID: package.offeringIdentifier,
paywallMode: nil
)
)
}

func testPurchasingPackageWithPaywallViewMode() async throws {
Purchases.shared.cachePresentedPaywallMode(.fullScreen)

let transaction = try await XCTAsyncUnwrap(try await self.purchaseMonthlyOffering().transaction)

let package = try await self.monthlyPackage

self.logger.verifyMessageWasLogged(
Strings.purchase.transaction_poster_handling_transaction(
transactionID: transaction.transactionIdentifier,
productID: package.storeProduct.productIdentifier,
transactionDate: transaction.purchaseDate,
offeringID: package.offeringIdentifier,
paywallMode: .fullScreen
offeringID: package.offeringIdentifier
)
)
}
Expand Down
3 changes: 1 addition & 2 deletions Tests/RevenueCatUITests/PaywallFooterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class PaywallFooterTests: TestCase {
.addToHierarchy()

Task {
_ = try await Self.purchaseHandler.purchase(package: Self.package,
with: .fullScreen)
_ = try await Self.purchaseHandler.purchase(package: Self.package)
}

expect(customerInfo).toEventually(be(TestData.customerInfo))
Expand Down
3 changes: 1 addition & 2 deletions Tests/RevenueCatUITests/PresentIfNeededTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class PresentIfNeededTests: TestCase {
.addToHierarchy()

Task {
_ = try await Self.purchaseHandler.purchase(package: Self.package,
with: .fullScreen)
_ = try await Self.purchaseHandler.purchase(package: Self.package)
}

expect(customerInfo).toEventually(be(TestData.customerInfo))
Expand Down
6 changes: 2 additions & 4 deletions Tests/RevenueCatUITests/PurchaseCompletedHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class PurchaseCompletedHandlerTests: TestCase {
.addToHierarchy()

Task {
_ = try await Self.purchaseHandler.purchase(package: Self.package,
with: .fullScreen)
_ = try await Self.purchaseHandler.purchase(package: Self.package)
purchased = true
}

Expand All @@ -65,8 +64,7 @@ class PurchaseCompletedHandlerTests: TestCase {
.addToHierarchy()

Task {
_ = try await Self.purchaseHandler.purchase(package: Self.package,
with: .fullScreen)
_ = try await Self.purchaseHandler.purchase(package: Self.package)
}

expect(customerInfo).toEventually(be(TestData.customerInfo))
Expand Down
4 changes: 2 additions & 2 deletions Tests/RevenueCatUITests/Purchasing/PurchaseHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PurchaseHandlerTests: TestCase {
func testPurchaseSetsCustomerInfo() async throws {
let handler: PurchaseHandler = .mock()

_ = try await handler.purchase(package: TestData.packageWithIntroOffer, with: .fullScreen)
_ = try await handler.purchase(package: TestData.packageWithIntroOffer)

expect(handler.purchasedCustomerInfo) === TestData.customerInfo
expect(handler.purchased) == true
Expand All @@ -44,7 +44,7 @@ class PurchaseHandlerTests: TestCase {
func testCancellingPurchase() async throws {
let handler: PurchaseHandler = .cancelling()

_ = try await handler.purchase(package: TestData.packageWithIntroOffer, with: .fullScreen)
_ = try await handler.purchase(package: TestData.packageWithIntroOffer)
expect(handler.purchasedCustomerInfo).to(beNil())
expect(handler.purchased) == false
expect(handler.actionInProgress) == false
Expand Down
3 changes: 1 addition & 2 deletions Tests/RevenueCatUITests/Templates/Template2ViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class Template2ViewTests: BaseSnapshotTest {
let view = Self.createPaywall(offering: Self.offering.withLocalImages,
purchaseHandler: handler)
.task {
_ = try? await handler.purchase(package: TestData.annualPackage,
with: .fullScreen)
_ = try? await handler.purchase(package: TestData.annualPackage)
}

view.snapshot(size: Self.fullScreenSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ class BackendPostReceiptDataTests: BaseBackendPostReceiptDataTests {

let productIdentifier = "a_great_product"
let offeringIdentifier = "a_offering"
let paywallMode: PaywallViewMode = .fullScreen
let price: Decimal = 10.98
let group = "sub_group"

Expand All @@ -372,7 +371,6 @@ class BackendPostReceiptDataTests: BaseBackendPostReceiptDataTests {
transactionData: .init(
appUserID: Self.userID,
presentedOfferingID: offeringIdentifier,
presentedPaywallMode: paywallMode,
unsyncedAttributes: nil,
storefront: nil,
source: .init(isRestore: false, initiationSource: .purchase)
Expand Down
Loading

0 comments on commit f937e64

Please sign in to comment.