Skip to content

Commit

Permalink
Revert "Rename to CustomerCenterActionDelegate"
Browse files Browse the repository at this point in the history
This reverts commit da03b7c.
  • Loading branch information
tonidero committed Jul 18, 2024
1 parent e3abcfa commit f3707f3
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 55 deletions.
8 changes: 4 additions & 4 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
1E473B682AC43254008B07F9 /* StoreMessageType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E473B672AC43254008B07F9 /* StoreMessageType.swift */; };
1E568B512ACC6A8300D3C12F /* StoreMessageTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E568B502ACC6A8300D3C12F /* StoreMessageTypeTests.swift */; };
1E5F8F6E2C4515430041EECD /* View+PresentCustomerCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E5F8F6D2C4515430041EECD /* View+PresentCustomerCenter.swift */; };
1E5F8F782C46BBD90041EECD /* CustomerCenterActionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E5F8F772C46BBD90041EECD /* CustomerCenterActionDelegate.swift */; };
1E5F8F782C46BBD90041EECD /* CustomerCenterActionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E5F8F772C46BBD90041EECD /* CustomerCenterActionHandler.swift */; };
1E99F81F2AC5917F0023E26E /* StoreMessagesHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E99F81D2AC5917F0023E26E /* StoreMessagesHelperTests.swift */; };
2C0B98CD2797070B00C5874F /* PromotionalOffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C0B98CC2797070B00C5874F /* PromotionalOffer.swift */; };
2C6CC1162B8D2B6900432E4D /* PurchasesSyncAttributesAndOfferingsIfNeededTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C6CC1152B8D2B6800432E4D /* PurchasesSyncAttributesAndOfferingsIfNeededTests.swift */; };
Expand Down Expand Up @@ -1050,7 +1050,7 @@
1E473B692AC46908008B07F9 /* MockStoreMessagesHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStoreMessagesHelper.swift; sourceTree = "<group>"; };
1E568B502ACC6A8300D3C12F /* StoreMessageTypeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreMessageTypeTests.swift; sourceTree = "<group>"; };
1E5F8F6D2C4515430041EECD /* View+PresentCustomerCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+PresentCustomerCenter.swift"; sourceTree = "<group>"; };
1E5F8F772C46BBD90041EECD /* CustomerCenterActionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerCenterActionDelegate.swift; sourceTree = "<group>"; };
1E5F8F772C46BBD90041EECD /* CustomerCenterActionHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerCenterActionHandler.swift; sourceTree = "<group>"; };
1E99F81D2AC5917F0023E26E /* StoreMessagesHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreMessagesHelperTests.swift; sourceTree = "<group>"; };
2C0B98CC2797070B00C5874F /* PromotionalOffer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromotionalOffer.swift; sourceTree = "<group>"; };
2C646C282A0EBD0300E5936E /* CI-Snapshots.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = "CI-Snapshots.xctestplan"; path = "Tests/TestPlans/CI-Snapshots.xctestplan"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2559,7 +2559,7 @@
353756542C382C2800A1B8D6 /* CustomerCenterError.swift */,
35C200AE2C39252D00B9778B /* FeedbackSurveyData.swift */,
353756552C382C2800A1B8D6 /* SubscriptionInformation.swift */,
1E5F8F772C46BBD90041EECD /* CustomerCenterActionDelegate.swift */,
1E5F8F772C46BBD90041EECD /* CustomerCenterActionHandler.swift */,
);
path = Data;
sourceTree = "<group>";
Expand Down Expand Up @@ -5165,7 +5165,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1E5F8F782C46BBD90041EECD /* CustomerCenterActionDelegate.swift in Sources */,
1E5F8F782C46BBD90041EECD /* CustomerCenterActionHandler.swift in Sources */,
887A60CC2C1D037000E1A461 /* PaywallFontProvider.swift in Sources */,
887A60B82C1D037000E1A461 /* Template1View.swift in Sources */,
887A60C62C1D037000E1A461 /* LoadingPaywallView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import RevenueCat

/// Allows to be notified of certain events the customer may perform during the Customer Center flow
public protocol CustomerCenterActionDelegate {
public protocol CustomerCenterActionHandler {

/// This will be called after a purchase of a promotional offer is completed.
func onPurchaseCompleted(_ customerInfo: CustomerInfo)
Expand Down Expand Up @@ -30,7 +30,7 @@ public protocol CustomerCenterActionDelegate {

// swiftlint:disable missing_docs

public extension CustomerCenterActionDelegate {
public extension CustomerCenterActionHandler {

func onPurchaseCompleted(_ customerInfo: CustomerInfo) {}
func onRestoreStarted() {}
Expand Down
14 changes: 7 additions & 7 deletions RevenueCatUI/CustomerCenter/View+PresentCustomerCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ extension View {
/// - Parameter isPresented: Binding indicating whether the customer center should be displayed
/// - Parameter onDismiss: Callback executed when the customer center wants to be dismissed.
/// Make sure you stop presenting the customer center when this is called
/// - Parameter customerCenterActionDelegate: Allows to listen to certain events during the customer center flow.
/// - Parameter customerCenterActionHandler: Allows to listen to certain events during the customer center flow.
/// - Parameter presentationMode: The desired presentation mode of the customer center. Defaults to `.sheet`.
public func presentCustomerCenter(
isPresented: Binding<Bool>,
customerCenterActionDelegate: CustomerCenterActionDelegate? = nil,
customerCenterActionHandler: CustomerCenterActionHandler? = nil,
presentationMode: CustomerCenterPresentationMode = .default,
onDismiss: @escaping () -> Void
) -> some View {
return self.modifier(PresentingCustomerCenterModifier(
isPresented: isPresented,
onDismiss: onDismiss,
myAppPurchaseLogic: nil,
customerCenterActionDelegate: customerCenterActionDelegate,
customerCenterActionHandler: customerCenterActionHandler,
presentationMode: presentationMode
))
}
Expand All @@ -78,22 +78,22 @@ extension View {
@available(visionOS, unavailable)
private struct PresentingCustomerCenterModifier: ViewModifier {

let customerCenterActionDelegate: CustomerCenterActionDelegate?
let customerCenterActionHandler: CustomerCenterActionHandler?
let presentationMode: CustomerCenterPresentationMode
let onDismiss: (() -> Void)

init(
isPresented: Binding<Bool>,
onDismiss: @escaping () -> Void,
myAppPurchaseLogic: MyAppPurchaseLogic?,
customerCenterActionDelegate: CustomerCenterActionDelegate?,
customerCenterActionHandler: CustomerCenterActionHandler?,
presentationMode: CustomerCenterPresentationMode,
purchaseHandler: PurchaseHandler? = nil
) {
self._isPresented = isPresented
self.presentationMode = presentationMode
self.onDismiss = onDismiss
self.customerCenterActionDelegate = customerCenterActionDelegate
self.customerCenterActionHandler = customerCenterActionHandler
self._purchaseHandler = .init(wrappedValue: purchaseHandler ??
PurchaseHandler.default(performPurchase: myAppPurchaseLogic?.performPurchase,
performRestore: myAppPurchaseLogic?.performRestore))
Expand Down Expand Up @@ -123,7 +123,7 @@ private struct PresentingCustomerCenterModifier: ViewModifier {
}

private func customerCenterView() -> some View {
CustomerCenterView(customerCenterActionDelegate: self.customerCenterActionDelegate)
CustomerCenterView(customerCenterActionHandler: self.customerCenterActionHandler)
.interactiveDismissDisabled(self.purchaseHandler.actionInProgress)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ import RevenueCat
}

private var customerInfoFetcher: CustomerInfoFetcher
internal let customerCenterActionDelegate: CustomerCenterActionDelegate?
internal let customerCenterActionHandler: CustomerCenterActionHandler?

private var error: Error?

convenience init(customerCenterActionDelegate: CustomerCenterActionDelegate?) {
self.init(customerCenterActionDelegate: customerCenterActionDelegate,
convenience init(customerCenterActionHandler: CustomerCenterActionHandler?) {
self.init(customerCenterActionHandler: customerCenterActionHandler,
customerInfoFetcher: {
guard Purchases.isConfigured else {
throw PaywallError.purchasesNotConfigured
Expand All @@ -63,11 +63,11 @@ import RevenueCat
})
}

init(customerCenterActionDelegate: CustomerCenterActionDelegate?,
init(customerCenterActionHandler: CustomerCenterActionHandler?,
customerInfoFetcher: @escaping CustomerInfoFetcher) {
self.state = .notLoaded
self.customerInfoFetcher = customerInfoFetcher
self.customerCenterActionDelegate = customerCenterActionDelegate
self.customerCenterActionHandler = customerCenterActionHandler
}

#if DEBUG
Expand All @@ -84,7 +84,7 @@ import RevenueCat
return try await Purchases.shared.customerInfo()
}
self.state = .success
self.customerCenterActionDelegate = nil
self.customerCenterActionHandler = nil
}

#endif
Expand Down Expand Up @@ -118,14 +118,14 @@ import RevenueCat
}

func performRestore() async -> RestorePurchasesAlert.AlertType {
self.customerCenterActionDelegate?.onRestoreStarted()
self.customerCenterActionHandler?.onRestoreStarted()
do {
let customerInfo = try await Purchases.shared.restorePurchases()
self.customerCenterActionDelegate?.onRestoreCompleted(customerInfo)
self.customerCenterActionHandler?.onRestoreCompleted(customerInfo)
let hasEntitlements = customerInfo.entitlements.active.count > 0
return hasEntitlements ? .purchasesRecovered : .purchasesNotFound
} catch {
self.customerCenterActionDelegate?.onRestoreFailed(error)
self.customerCenterActionHandler?.onRestoreFailed(error)
return .purchasesNotFound
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,33 @@ class ManageSubscriptionsViewModel: ObservableObject {
private(set) var refundRequestStatusMessage: String?

private let purchasesProvider: ManageSubscriptionsPurchaseType
private let customerCenterActionDelegate: CustomerCenterActionDelegate?
private let customerCenterActionHandler: CustomerCenterActionHandler?

private var error: Error?

convenience init(screen: CustomerCenterConfigData.Screen,
customerCenterActionDelegate: CustomerCenterActionDelegate?) {
customerCenterActionHandler: CustomerCenterActionHandler?) {
self.init(screen: screen,
purchasesProvider: ManageSubscriptionPurchases(),
customerCenterActionDelegate: customerCenterActionDelegate)
customerCenterActionHandler: customerCenterActionHandler)
}

init(screen: CustomerCenterConfigData.Screen,
purchasesProvider: ManageSubscriptionsPurchaseType,
customerCenterActionDelegate: CustomerCenterActionDelegate?) {
customerCenterActionHandler: CustomerCenterActionHandler?) {
self.state = .notLoaded
self.screen = screen
self.purchasesProvider = purchasesProvider
self.customerCenterActionDelegate = customerCenterActionDelegate
self.customerCenterActionHandler = customerCenterActionHandler
}

init(screen: CustomerCenterConfigData.Screen,
subscriptionInformation: SubscriptionInformation,
customerCenterActionDelegate: CustomerCenterActionDelegate?) {
customerCenterActionHandler: CustomerCenterActionHandler?) {
self.screen = screen
self.subscriptionInformation = subscriptionInformation
self.purchasesProvider = ManageSubscriptionPurchases()
self.customerCenterActionDelegate = customerCenterActionDelegate
self.customerCenterActionHandler = customerCenterActionHandler
state = .success
}

Expand Down Expand Up @@ -146,9 +146,9 @@ class ManageSubscriptionsViewModel: ObservableObject {
do {
guard let subscriptionInformation = self.subscriptionInformation else { return }
let productId = subscriptionInformation.productIdentifier
self.customerCenterActionDelegate?.onRefundRequestStarted(productId)
self.customerCenterActionHandler?.onRefundRequestStarted(productId)
let status = try await self.purchasesProvider.beginRefundRequest(forProduct: productId)
self.customerCenterActionDelegate?.onRefundRequestCompleted(status)
self.customerCenterActionHandler?.onRefundRequestCompleted(status)
switch status {
case .error:
self.refundRequestStatusMessage = String(localized: "Error when requesting refund, try again")
Expand All @@ -158,13 +158,13 @@ class ManageSubscriptionsViewModel: ObservableObject {
self.refundRequestStatusMessage = String(localized: "Refund canceled")
}
} catch {
self.customerCenterActionDelegate?.onRefundRequestCompleted(.error)
self.customerCenterActionHandler?.onRefundRequestCompleted(.error)
self.refundRequestStatusMessage =
String(localized: "An error occurred while processing the refund request.")
}
case .changePlans, .cancel:
do {
self.customerCenterActionDelegate?.onShowManageSubscriptions()
self.customerCenterActionHandler?.onShowManageSubscriptions()
try await purchasesProvider.showManageSubscriptions()
} catch {
self.state = .error(error)
Expand Down
6 changes: 3 additions & 3 deletions RevenueCatUI/CustomerCenter/Views/CustomerCenterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public struct CustomerCenterView: View {
@StateObject private var viewModel: CustomerCenterViewModel

/// Create a view to handle common customer support tasks
public init(customerCenterActionDelegate: CustomerCenterActionDelegate? = nil) {
public init(customerCenterActionHandler: CustomerCenterActionHandler? = nil) {
self._viewModel = .init(wrappedValue:
CustomerCenterViewModel(customerCenterActionDelegate: customerCenterActionDelegate))
CustomerCenterViewModel(customerCenterActionHandler: customerCenterActionHandler))
}

fileprivate init(viewModel: CustomerCenterViewModel) {
Expand Down Expand Up @@ -77,7 +77,7 @@ private extension CustomerCenterView {
if viewModel.subscriptionsAreFromApple,
let screen = configuration.screens[.management] {
ManageSubscriptionsView(screen: screen,
customerCenterActionDelegate: viewModel.customerCenterActionDelegate)
customerCenterActionHandler: viewModel.customerCenterActionHandler)
} else {
WrongPlatformView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ struct ManageSubscriptionsView: View {
private var viewModel: ManageSubscriptionsViewModel

init(screen: CustomerCenterConfigData.Screen,
customerCenterActionDelegate: CustomerCenterActionDelegate?) {
customerCenterActionHandler: CustomerCenterActionHandler?) {
let viewModel = ManageSubscriptionsViewModel(screen: screen,
customerCenterActionDelegate: customerCenterActionDelegate)
customerCenterActionHandler: customerCenterActionHandler)
self._viewModel = .init(wrappedValue: viewModel)
}

Expand Down Expand Up @@ -218,7 +218,7 @@ struct ManageSubscriptionsView_Previews: PreviewProvider {
let viewModel = ManageSubscriptionsViewModel(
screen: CustomerCenterConfigTestData.customerCenterData.screens[.management]!,
subscriptionInformation: CustomerCenterConfigTestData.subscriptionInformation,
customerCenterActionDelegate: nil)
customerCenterActionHandler: nil)
ManageSubscriptionsView(viewModel: viewModel)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CustomerCenterViewModelTests: TestCase {
}

func testInitialState() {
let viewModel = CustomerCenterViewModel(customerCenterActionDelegate: nil)
let viewModel = CustomerCenterViewModel(customerCenterActionHandler: nil)

expect(viewModel.state) == .notLoaded
expect(viewModel.hasSubscriptions) == false
Expand All @@ -46,7 +46,7 @@ class CustomerCenterViewModelTests: TestCase {
}

func testStateChangeToError() {
let viewModel = CustomerCenterViewModel(customerCenterActionDelegate: nil)
let viewModel = CustomerCenterViewModel(customerCenterActionHandler: nil)

viewModel.state = .error(error)

Expand All @@ -59,7 +59,7 @@ class CustomerCenterViewModelTests: TestCase {
}

func testIsLoaded() {
let viewModel = CustomerCenterViewModel(customerCenterActionDelegate: nil)
let viewModel = CustomerCenterViewModel(customerCenterActionHandler: nil)

expect(viewModel.isLoaded) == false

Expand All @@ -70,7 +70,7 @@ class CustomerCenterViewModelTests: TestCase {
}

func testLoadHasSubscriptionsApple() async {
let viewModel = CustomerCenterViewModel(customerCenterActionDelegate: nil,
let viewModel = CustomerCenterViewModel(customerCenterActionHandler: nil,
customerInfoFetcher: {
return await CustomerCenterViewModelTests.customerInfoWithAppleSubscriptions
})
Expand All @@ -83,7 +83,7 @@ class CustomerCenterViewModelTests: TestCase {
}

func testLoadHasSubscriptionsGoogle() async {
let viewModel = CustomerCenterViewModel(customerCenterActionDelegate: nil,
let viewModel = CustomerCenterViewModel(customerCenterActionHandler: nil,
customerInfoFetcher: {
return await CustomerCenterViewModelTests.customerInfoWithGoogleSubscriptions
})
Expand All @@ -96,7 +96,7 @@ class CustomerCenterViewModelTests: TestCase {
}

func testLoadHasSubscriptionsNonActive() async {
let viewModel = CustomerCenterViewModel(customerCenterActionDelegate: nil,
let viewModel = CustomerCenterViewModel(customerCenterActionHandler: nil,
customerInfoFetcher: {
return await CustomerCenterViewModelTests.customerInfoWithoutSubscriptions
})
Expand All @@ -109,7 +109,7 @@ class CustomerCenterViewModelTests: TestCase {
}

func testLoadHasSubscriptionsFailure() async {
let viewModel = CustomerCenterViewModel(customerCenterActionDelegate: nil,
let viewModel = CustomerCenterViewModel(customerCenterActionHandler: nil,
customerInfoFetcher: {
throw TestError(message: "An error occurred")
})
Expand Down
Loading

0 comments on commit f3707f3

Please sign in to comment.