-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Customer Center] Create
CustomerCenterView
(#3919)
Base branch is `integration/customer_support_workflow` so we don't merge into `main` yet Borrows a lot from #3865 Creates a new `CustomerCenterView` that can be used as a customer support workflow starting point. All details can be found in https://linear.app/revenuecat/project/sdk-support-workflow-cf7f6a1d5340/overview --------- Co-authored-by: Will Taylor <wtaylor151@gmail.com> Co-authored-by: James Borthwick <109382862+jamesrb1@users.noreply.github.com>
- Loading branch information
1 parent
0ef63a7
commit 5fcbe86
Showing
20 changed files
with
1,965 additions
and
2 deletions.
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 { | ||
|
||
@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.