Skip to content

Commit

Permalink
IOS-2657 Support dynamic payment id and url form api
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatovv committed Apr 11, 2024
1 parent e3640e1 commit 37397e3
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 34 deletions.
6 changes: 0 additions & 6 deletions Anytype/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1487,12 +1487,6 @@ internal enum Loc {
/// Custom conditions of Membership. If you have any questions, please contact support.
internal static let subtitle = Loc.tr("Localizable", "Membership.Custom.Subtitle", fallback: "Custom conditions of Membership. If you have any questions, please contact support.")
}
internal enum CustomTierEmail {
/// Custom membership tier request, Account id: %@
internal static func subject(_ p1: Any) -> String {
return Loc.tr("Localizable", "Membership.CustomTierEmail.Subject", String(describing: p1), fallback: "Custom membership tier request, Account id: %@")
}
}
internal enum Email {
/// Please specify your request:
/// - highlight if you represent an educational, governmental, or non-profit organization
Expand Down
1 change: 0 additions & 1 deletion Anytype/Resources/Strings/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,6 @@
- highlight if you represent an educational, governmental, or non-profit organization
- tell us more about your organization: number of employees and future Anytype users, markets you're working on, etc.,
- provide additional details about how your organization uses Anytype";
"Membership.CustomTierEmail.Subject" = "Custom membership tier request, Account id: %@";


"Membership.Banner.Title1" = "Build the Vision Together";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,7 @@ final class MembershipCoordinatorModel: ObservableObject {
}

func onTierSelected(tier: MembershipTier) {
switch tier.type {
case .custom:
let mailLink = MailUrl(
to: "[email protected]",
subject: Loc.Membership.CustomTierEmail.subject(accountManager.account.id),
body: ""
)
emailUrl = mailLink.url

case .explorer, .builder, .coCreator:
showTier = tier
}
showTier = tier
}

func onEmailDataSubmit(data: EmailVerificationData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ public extension MembershipTierPaymentType {

extension StripePaymentInfo {
static var mockInfo: StripePaymentInfo {
StripePaymentInfo(periodType: .years, periodValue: 1, priceInCents: 10000)
StripePaymentInfo(periodType: .years, periodValue: 1, priceInCents: 10000, paymentUrl: URL(string: "https://anytype.io")!)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Services

struct MembershipTierSelectionView: View {
@StateObject private var model: MembershipTierSelectionViewModel
@Environment(\.openURL) private var openURL


init(
userMembership: MembershipStatus,
Expand Down Expand Up @@ -45,8 +47,10 @@ struct MembershipTierSelectionView: View {
}
case .appStore(let product):
MembershipNameSheetView(tier: model.tierToDisplay, anyName: model.userMembership.anyName, product: product, onSuccessfulPurchase: model.onSuccessfulPurchase)
case .external:
EmptyView() // TBD in future updates
case .external(let info):
StandardButton("More info", style: .primaryLarge) {
openURL(info.paymentUrl)
}.padding()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,13 @@ final class MembershipService: MembershipServiceProtocol {
type: MembershipTierType,
tier: Anytype_Model_MembershipTierData
) async -> MembershipTierPaymentType? {
switch type {
case .explorer:
return .email
case .builder:
let productId = "Membership.Subscription.Builder" // TODO: Get from middleware

guard type != .explorer else { return .email }

if tier.iosProductID.isNotEmpty {
do {
let product = try await Product.products(for: [productId])
let product = try await Product.products(for: [tier.iosProductID])
guard let product = product.first else {
anytypeAssertionFailure("Not found product for id \(productId)")
anytypeAssertionFailure("Not found product for id \(tier.iosProductID)")
return nil
}

Expand All @@ -138,14 +135,14 @@ final class MembershipService: MembershipServiceProtocol {
anytypeAssertionFailure("Get products error", info: ["error": error.localizedDescription])
return nil
}
case .coCreator, .custom:
} else {
let info = StripePaymentInfo(
periodType: tier.periodType,
periodValue: tier.periodValue,
priceInCents: tier.priceStripeUsdCents
priceInCents: tier.priceStripeUsdCents,
paymentUrl: URL(string: tier.iosManageURL) ?? URL(string: "https://download.anytype.io")! // TODO: Update with actual link
)
return .external(info: info)

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ public struct StripePaymentInfo: Hashable, Equatable {
public let periodType: MemberhipTierPaymentPeriodType
public let periodValue: UInt32
public let priceInCents: UInt32
public let paymentUrl: URL

public init(periodType: MemberhipTierPaymentPeriodType, periodValue: UInt32, priceInCents: UInt32) {
public init(
periodType: MemberhipTierPaymentPeriodType,
periodValue: UInt32,
priceInCents: UInt32,
paymentUrl: URL
) {
self.periodType = periodType
self.periodValue = periodValue
self.priceInCents = priceInCents
self.paymentUrl = paymentUrl
}
}

Expand Down

0 comments on commit 37397e3

Please sign in to comment.