-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Customer Center] Create CustomerCenterView
#3919
Merged
vegaro
merged 62 commits into
integration/customer_support_workflow
from
sdk-3433-supportview
Jun 28, 2024
Merged
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
3018b86
Create CustomerCenterView
vegaro 35f53cb
lint autofix
vegaro 2b1d692
linting cleanup
vegaro 7dd25b4
update email
vegaro 15e8152
fix compilation
vegaro b062981
Update RevenueCatUI/CustomerCenter/Data/CustomerCenterData.swift
vegaro 6c7aa97
rename areSubscriptionsFromApple
vegaro 68f0e4c
made error private
vegaro 81fe662
made state Published
vegaro 7e711f1
created CustomerCenterError and feedback on ManageSubscriptionsViewModel
vegaro b254d0b
remove init from CustomerCenterView
vegaro 327bbb7
use task instead of onAppear
vegaro 750ce43
Apply suggestions from code review
vegaro 04697cc
inits cleanup
vegaro f32c104
move handleAction to viewModel
vegaro 2eec857
more user-friendly name
vegaro b9e93e2
use morphology
vegaro 7993d68
actually remove it's not needed
vegaro 6c7feea
better wording
vegaro 01d9322
create HelpPathDetail
vegaro ef48028
fix some data types
vegaro 145113c
add docs
vegaro 717f4fd
mode is an enum
vegaro c17abbe
cleanup and availability
vegaro 3e7653d
add headers and renames
vegaro 5612874
remove promotionals
vegaro 1b00a49
improve loadHasSubscriptions logic
vegaro 33274d1
cleanup SubscriptionInformation
vegaro 60824c3
fix linter
vegaro cb65380
add return
vegaro a1461bf
fix availability
vegaro b7587cd
fix body public
vegaro 4cc7c44
fix colors
vegaro 71469be
clean up test config data
vegaro f1a99d5
publish on main thread
vegaro 90e8eda
remove button from view
vegaro c911bc5
fix date
vegaro f429f6d
remove contact support buttons
vegaro e285d64
remove unnecessary do catch
vegaro 1749c10
cleanup
vegaro 0fe1f0a
fix visionOS
vegaro fbfd704
make viewmodels MainActor
vegaro b07f8cf
CustomerCenterViewModelTests
vegaro 49704e7
Make Viewmodel testable
vegaro 6c25f9e
lint fix
vegaro 958b65d
check for availability
vegaro f75cfc0
fix macos
vegaro b1c0ac7
refundRequestStatusMessage
vegaro 9851c1f
CustomerCenterConfigTestData debug only
vegaro 72154ce
extracts strings
vegaro 9752176
add lines
vegaro 5115202
more strings
vegaro 1098378
remove LocalizedString
vegaro b5955d6
@jamesrb1 suggestions
vegaro 0bf3757
lint
vegaro 98bb9f2
&& (swift(>=5.9) && !os(visionOS))
vegaro c07bb1d
fix linter
vegaro 7955877
fix macros
vegaro 21b52f6
fix tests
vegaro 6a6b003
fix tests
vegaro 239f10a
change localization of date
vegaro 8f21718
fix pod lib lint
vegaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 57 additions & 2 deletions
59
RevenueCatUI/CustomerCenter/Data/CustomerCenterConfigData.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,63 @@ | ||
// | ||
// File.swift | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// CustomerCenterConfigData.swift | ||
// | ||
// | ||
// Created by Cesar de la Vega on 17/6/24. | ||
// Created by Cesar de la Vega on 28/5/24. | ||
// | ||
|
||
import Foundation | ||
import RevenueCat | ||
|
||
struct CustomerCenterConfigData { | ||
|
||
let id: String | ||
let paths: [HelpPath] | ||
let title: String | ||
|
||
enum HelpPathType: String { | ||
case missingPurchase = "MISSING_PURCHASE" | ||
case refundRequest = "REFUND_REQUEST" | ||
case changePlans = "CHANGE_PLANS" | ||
case cancel = "CANCEL" | ||
case unknown | ||
} | ||
|
||
enum HelpPathDetail { | ||
|
||
case promotionalOffer(PromotionalOffer) | ||
case feedbackSurvey(FeedbackSurvey) | ||
|
||
} | ||
|
||
struct HelpPath { | ||
|
||
let id: String | ||
let title: String | ||
let type: HelpPathType | ||
let detail: HelpPathDetail? | ||
|
||
} | ||
|
||
struct FeedbackSurvey { | ||
|
||
let title: String | ||
let options: [FeedbackSurveyOption] | ||
|
||
} | ||
|
||
struct FeedbackSurveyOption { | ||
|
||
let id: String | ||
let title: String | ||
|
||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
RevenueCatUI/CustomerCenter/Data/CustomerCenterConfigTestData.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// CustomerCenterConfigTestData.swift | ||
// | ||
// | ||
// Created by Cesar de la Vega on 28/5/24. | ||
// | ||
|
||
import Foundation | ||
import RevenueCat | ||
|
||
enum CustomerCenterConfigTestData { | ||
vegaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@available(iOS 14.0, *) | ||
static let customerCenterData = CustomerCenterConfigData( | ||
id: "customer_center_id", | ||
paths: [ | ||
.init( | ||
id: "1", | ||
title: "Didn't receive purchase", | ||
type: .missingPurchase, | ||
detail: nil | ||
), | ||
.init( | ||
id: "2", | ||
title: "Request a refund", | ||
type: .refundRequest, | ||
detail: nil | ||
), | ||
.init( | ||
id: "3", | ||
title: "Change plans", | ||
type: .changePlans, | ||
detail: nil | ||
), | ||
.init( | ||
id: "4", | ||
title: "Cancel subscription", | ||
type: .cancel, | ||
detail: .feedbackSurvey(.init( | ||
title: "Why are you cancelling?", | ||
options: [ | ||
.init( | ||
id: "1", | ||
title: "Too expensive" | ||
), | ||
.init( | ||
id: "2", | ||
title: "Don't use the app" | ||
), | ||
.init( | ||
id: "3", | ||
title: "Bought by mistake" | ||
) | ||
] | ||
)) | ||
) | ||
], | ||
title: "How can we help?" | ||
) | ||
|
||
static let subscriptionInformation: SubscriptionInformation = .init( | ||
title: "Basic", | ||
durationTitle: "Monthly", | ||
price: "$4.99 / month", | ||
nextRenewalString: "June 1st, 2024", | ||
willRenew: true, | ||
productIdentifier: "product_id", | ||
active: true | ||
) | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
RevenueCatUI/CustomerCenter/Data/CustomerCenterError.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// CustomerCenterError.swift | ||
// | ||
// | ||
// Created by Cesar de la Vega on 29/5/24. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Error produced when displaying the customer center. | ||
enum CustomerCenterError: Error { | ||
|
||
/// Could not find information for an active subscription. | ||
case couldNotFindSubscriptionInformation | ||
|
||
} | ||
|
||
extension CustomerCenterError: CustomNSError { | ||
|
||
var errorUserInfo: [String: Any] { | ||
return [ | ||
NSLocalizedDescriptionKey: self.description | ||
] | ||
} | ||
|
||
private var description: String { | ||
switch self { | ||
case .couldNotFindSubscriptionInformation: | ||
return "Could not find information for an active subscription." | ||
} | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
RevenueCatUI/CustomerCenter/Data/SubscriptionInformation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// SubscriptionInformation.swift | ||
// | ||
// | ||
// Created by Cesar de la Vega on 28/5/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct SubscriptionInformation { | ||
|
||
let title: String | ||
let durationTitle: String | ||
let price: String | ||
let nextRenewalString: String? | ||
let productIdentifier: String | ||
|
||
var renewalString: String { | ||
return active ? (willRenew ? "Renews" : "Expires") : "Expired" | ||
} | ||
|
||
private let willRenew: Bool | ||
private let active: Bool | ||
|
||
init(title: String, | ||
durationTitle: String, | ||
price: String, | ||
nextRenewalString: String?, | ||
willRenew: Bool, | ||
productIdentifier: String, | ||
active: Bool | ||
) { | ||
self.title = title | ||
self.durationTitle = durationTitle | ||
self.price = price | ||
self.nextRenewalString = nextRenewalString | ||
self.productIdentifier = productIdentifier | ||
self.willRenew = willRenew | ||
self.active = active | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
RevenueCatUI/CustomerCenter/ManageSubscriptionsButtonStyle.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// CustomButtonStyle.swift | ||
// | ||
// | ||
// Created by Cesar de la Vega on 28/5/24. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
@available(macOS, unavailable) | ||
@available(tvOS, unavailable) | ||
@available(watchOS, unavailable) | ||
struct ManageSubscriptionsButtonStyle: ButtonStyle { | ||
|
||
func makeBody(configuration: Configuration) -> some View { | ||
configuration.label | ||
.padding() | ||
.frame(width: 300) | ||
.background(Color.accentColor) | ||
.foregroundColor(.white) | ||
.cornerRadius(10) | ||
.scaleEffect(configuration.isPressed ? 0.95 : 1.0) | ||
.opacity(configuration.isPressed ? 0.8 : 1.0) | ||
.animation(.easeInOut(duration: 0.2), value: configuration.isPressed) | ||
} | ||
|
||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
@available(macOS, unavailable) | ||
@available(tvOS, unavailable) | ||
@available(watchOS, unavailable) | ||
struct CustomButtonStylePreview_Previews: PreviewProvider { | ||
|
||
static var previews: some View { | ||
Button("Didn't receive purchase") {} | ||
.buttonStyle(ManageSubscriptionsButtonStyle()) | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
RevenueCatUI/CustomerCenter/ManageSubscriptionsPurchaseType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// ManageSubscriptionsPurchaseType.swift | ||
// | ||
// | ||
// Created by Cesar de la Vega on 12/6/24. | ||
// | ||
|
||
import Foundation | ||
import RevenueCat | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
@available(macOS, unavailable) | ||
@available(tvOS, unavailable) | ||
@available(watchOS, unavailable) | ||
protocol ManageSubscriptionsPurchaseType: Sendable { | ||
|
||
@Sendable | ||
func customerInfo() async throws -> CustomerInfo | ||
|
||
@Sendable | ||
func products(_ productIdentifiers: [String]) async -> [StoreProduct] | ||
|
||
@Sendable | ||
func showManageSubscriptions() async throws | ||
|
||
@Sendable | ||
func beginRefundRequest(forProduct productID: String) async throws -> RefundRequestStatus | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I was using lowercase for these in the backend... I'm ok changing them to uppercase though 👍