Skip to content
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

Plans in Site Creation: Create functionality to add domain with a plan to a cart #21667

Merged
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def wordpress_ui
end

def wordpress_kit
pod 'WordPressKit', '~> 8.5'
# pod 'WordPressKit', '~> 8.5'
# pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: ''
# pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: ''
pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: 'task/21636-create-functionality-to-add-domain-with-a-plan-to-a-cart'
# pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: ''
# pod 'WordPressKit', path: '../WordPressKit-iOS'
end
Expand Down
15 changes: 10 additions & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ PODS:
- WordPressKit (~> 8.0-beta)
- WordPressShared (~> 2.1-beta)
- WordPressUI (~> 1.7-beta)
- WordPressKit (8.5.2):
- WordPressKit (8.6.0-beta.1):
- Alamofire (~> 4.8.0)
- NSObject-SafeExpectations (~> 0.0.4)
- UIDeviceIdentifier (~> 2.0)
Expand Down Expand Up @@ -126,7 +126,7 @@ DEPENDENCIES:
- SwiftLint (~> 0.50)
- WordPress-Editor-iOS (~> 1.19.9)
- WordPressAuthenticator (~> 7.0)
- WordPressKit (~> 8.5)
- WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, branch `task/21636-create-functionality-to-add-domain-with-a-plan-to-a-cart`)
- WordPressShared (~> 2.2)
- WordPressUI (~> 1.15)
- WPMediaPicker (>= 1.8.10, ~> 1.8)
Expand Down Expand Up @@ -165,7 +165,6 @@ SPEC REPOS:
- UIDeviceIdentifier
- WordPress-Aztec-iOS
- WordPress-Editor-iOS
- WordPressKit
- WordPressShared
- WordPressUI
- WPMediaPicker
Expand All @@ -185,6 +184,9 @@ EXTERNAL SOURCES:
:tag: 0.2.0
Gutenberg:
:podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.105.0.podspec
WordPressKit:
:branch: task/21636-create-functionality-to-add-domain-with-a-plan-to-a-cart
:git: https://github.com/wordpress-mobile/WordPressKit-iOS.git

CHECKOUT OPTIONS:
FSInteractiveMap:
Expand All @@ -194,6 +196,9 @@ CHECKOUT OPTIONS:
:git: https://github.com/wordpress-mobile/gutenberg-mobile.git
:submodules: true
:tag: v1.100.2
WordPressKit:
:commit: ca3aeed2b57f7a8c3b467037bad299ac25ab00f3
:git: https://github.com/wordpress-mobile/WordPressKit-iOS.git

SPEC CHECKSUMS:
Alamofire: 3ec537f71edc9804815215393ae2b1a8ea33a844
Expand Down Expand Up @@ -227,7 +232,7 @@ SPEC CHECKSUMS:
WordPress-Aztec-iOS: fbebd569c61baa252b3f5058c0a2a9a6ada686bb
WordPress-Editor-iOS: bda9f7f942212589b890329a0cb22547311749ef
WordPressAuthenticator: 132ccf00a41443e0ebd792d9a36ff5697a8f5414
WordPressKit: 2fb06e93da3e8e7bea518188bfbf4d462ba103f9
WordPressKit: 6ec0634dcafdd902c552563bc695b357a2a9861f
WordPressShared: 87f3ee89b0a3e83106106f13a8b71605fb8eb6d2
WordPressUI: a491454affda3b0fb812812e637dc5e8f8f6bd06
WPMediaPicker: 332812329cbdc672cdb385b8ac3a389f668d3012
Expand All @@ -241,6 +246,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced

PODFILE CHECKSUM: 6923d1ced869ffdb698231230e921bacec62ca10
PODFILE CHECKSUM: 3f155151d0255376507fa06b26be7e1ae714b71d

COCOAPODS: 1.12.1
6 changes: 3 additions & 3 deletions WordPress/Classes/Utility/Analytics/WPAnalytics+Domains.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ extension WPAnalytics {
RemoteFeatureFlag.plansInSiteCreation.enabled()
}

static func domainsProperties(for blog: Blog, origin: DomainPurchaseWebViewViewOrigin? = .menu) -> [AnyHashable: Any] {
static func domainsProperties(for blog: Blog, origin: SiteCreationWebViewViewOrigin? = .menu) -> [AnyHashable: Any] {
domainsProperties(usingCredit: blog.canRegisterDomainWithPaidPlan, origin: origin)
}

static func domainsProperties(
usingCredit: Bool,
origin: DomainPurchaseWebViewViewOrigin?
origin: SiteCreationWebViewViewOrigin?
) -> [AnyHashable: Any] {
var dict: [AnyHashable: Any] = ["using_credit": usingCredit.stringLiteral]
if Self.domainPurchasingEnabled,
Expand All @@ -24,7 +24,7 @@ extension WPAnalytics {
}
}

enum DomainPurchaseWebViewViewOrigin: String {
enum SiteCreationWebViewViewOrigin: String {
case siteCreation = "site_creation"
case menu
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,23 @@ class RegisterDomainDetailsServiceProxy: RegisterDomainDetailsServiceProxyProtoc
success: @escaping (CartResponseProtocol) -> Void,
failure: @escaping (Error) -> Void) {

transactionsServiceRemote.createTemporaryDomainShoppingCart(siteID: siteID,
domainSuggestion: domainSuggestion,
privacyProtectionEnabled: privacyProtectionEnabled,
success: success,
failure: failure)
transactionsServiceRemote.createShoppingCart(siteID: siteID,
products: [.domain(domainSuggestion, privacyProtectionEnabled)],
temporary: true,
success: success,
failure: failure)
}

func createPersistentDomainShoppingCart(siteID: Int,
domainSuggestion: DomainSuggestion,
privacyProtectionEnabled: Bool,
success: @escaping (CartResponseProtocol) -> Void,
failure: @escaping (Error) -> Void) {

transactionsServiceRemote.createPersistentDomainShoppingCart(siteID: siteID,
domainSuggestion: domainSuggestion,
privacyProtectionEnabled: privacyProtectionEnabled,
success: success,
failure: failure)
transactionsServiceRemote.createShoppingCart(siteID: siteID,
products: [.domain(domainSuggestion, privacyProtectionEnabled)],
temporary: false,
success: success,
failure: failure)
}

func redeemCartUsingCredits(cart: CartResponseProtocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit
import AutomatticTracks
import Sentry

final class DomainPurchasingWebFlowController {
final class SiteCreationPurchasingWebFlowController {

// MARK: - Constants

Expand All @@ -20,14 +20,14 @@ final class DomainPurchasingWebFlowController {
weak private var presentingViewController: UIViewController?

/// The service that interacts with the Backend API.
private let shoppingCartService: RegisterDomainDetailsServiceProxyProtocol
private let shoppingCartService: ShoppingCartServiceProtocol

/// Provides an API to capture errors.
private let crashLogger: CrashLogging

/// The domain purchasing web view can be presented from multiple sources.
/// This property represents this source, and it's used mostly for analytics.
private let origin: DomainPurchaseWebViewViewOrigin?
private let origin: SiteCreationWebViewViewOrigin?

// MARK: - Execution Variables

Expand All @@ -40,9 +40,9 @@ final class DomainPurchasingWebFlowController {
// MARK: - Init

init(viewController: UIViewController,
shoppingCartService: RegisterDomainDetailsServiceProxyProtocol = RegisterDomainDetailsServiceProxy(),
shoppingCartService: ShoppingCartServiceProtocol = ShoppingCartService(),
crashLogger: CrashLogging = .main,
origin: DomainPurchaseWebViewViewOrigin? = nil) {
origin: SiteCreationWebViewViewOrigin? = nil) {
self.presentingViewController = viewController
self.shoppingCartService = shoppingCartService
self.crashLogger = crashLogger
Expand All @@ -51,11 +51,11 @@ final class DomainPurchasingWebFlowController {

// MARK: - API

func purchase(domain: FullyQuotedDomainSuggestion, site: Blog, completion: CompletionHandler? = nil) {
purchase(domain: domain.remoteSuggestion(), site: site, completion: completion)
func purchase(domain: FullyQuotedDomainSuggestion, planId: Int, site: Blog, completion: CompletionHandler? = nil) {
purchase(domain: domain.remoteSuggestion(), planId: planId, site: site, completion: completion)
}

func purchase(domain: DomainSuggestion, site: Blog, completion: CompletionHandler? = nil) {
func purchase(domain: DomainSuggestion, planId: Int, site: Blog, completion: CompletionHandler? = nil) {
let middleware = self.middleware(for: completion, domain: domain, site: site)
guard let presentingViewController else {
middleware(.failure(.internal("The presentingViewController is deallocated")))
Expand All @@ -65,7 +65,7 @@ final class DomainPurchasingWebFlowController {
middleware(.failure(.invalidInput))
return
}
self.createCartAndPresentWebView(domain: domain, in: presentingViewController, completion: middleware)
self.createCartAndPresentWebView(domain: domain, planId: planId, in: presentingViewController, completion: middleware)
}

// MARK: - Private: Completion Middleware
Expand All @@ -86,7 +86,7 @@ final class DomainPurchasingWebFlowController {
}

/// Logs the error in case the domain purchasing resulted in a failure.
private func handleError(result: Result<String, DomainPurchasingError>, domain: DomainSuggestion, site: Blog) {
private func handleError(result: Result<String, SiteCreationPurchasingError>, domain: DomainSuggestion, site: Blog) {
guard case let .failure(error) = result, !error.trusted else {
return
}
Expand All @@ -95,7 +95,7 @@ final class DomainPurchasingWebFlowController {
}

/// Tracks domain purchasing analytics when it completes.
private func trackCompletionEvents(result: Result<String, DomainPurchasingError>, domain: DomainSuggestion, site: Blog) {
private func trackCompletionEvents(result: Result<String, SiteCreationPurchasingError>, domain: DomainSuggestion, site: Blog) {
guard case .success = result else {
return
}
Expand All @@ -104,11 +104,12 @@ final class DomainPurchasingWebFlowController {

// MARK: - Private: Doman Purchasing

private func createCartAndPresentWebView(domain: Domain, in presentingViewController: UIViewController, completion: CompletionHandler? = nil) {
self.shoppingCartService.createPersistentDomainShoppingCart(
private func createCartAndPresentWebView(domain: Domain, planId: Int, in presentingViewController: UIViewController, completion: CompletionHandler? = nil) {
self.shoppingCartService.createSiteCreationShoppingCart(
siteID: domain.siteID,
domainSuggestion: domain.underlyingDomain,
privacyProtectionEnabled: domain.supportsPrivacy,
planId: planId,
success: { [weak self] _ in
self?.presentWebViewForCurrentSite(domain: domain, in: presentingViewController, completion: completion)
}) { error in
Expand All @@ -126,7 +127,7 @@ final class DomainPurchasingWebFlowController {
//
// This was last checked by @diegoreymendez on 2021-09-22.
//
var result: Result<String, DomainPurchasingError>?
var result: Result<String, SiteCreationPurchasingError>?
let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(
url: domain.hostURL,
source: origin?.rawValue ?? ""
Expand All @@ -152,10 +153,10 @@ final class DomainPurchasingWebFlowController {
if let presentedViewController = self.presentedViewController {
presentedViewController.setViewControllers([webViewController], animated: false)
} else {
let navController = DomainPurchasingNavigationController(rootViewController: webViewController)
let navController = SiteCreationPurchasingNavigationController(rootViewController: webViewController)
navController.onDismiss = {
let result = result ?? .failure(.canceled)
self.completeDomainPurchasing(result: result, completion: completion)
self.completeSiteCreationPurchasing(result: result, completion: completion)
}
presentingViewController.present(navController, animated: true)
self.presentedViewController = navController
Expand All @@ -165,7 +166,7 @@ final class DomainPurchasingWebFlowController {
}

/// Calls the completion handler with the result and clean up observation properties.
private func completeDomainPurchasing(result: Result<String, DomainPurchasingError>, completion: CompletionHandler? = nil) {
private func completeSiteCreationPurchasing(result: Result<String, SiteCreationPurchasingError>, completion: CompletionHandler? = nil) {
self.cleanupExecutionVariables()
completion?(result)
}
Expand Down Expand Up @@ -202,11 +203,11 @@ final class DomainPurchasingWebFlowController {
_ newURL: URL,
oldURL: URL?,
domain: Domain,
completion: (Result<String, DomainPurchasingError>) -> Void
completion: (Result<String, SiteCreationPurchasingError>) -> Void
) {
let canOpenNewURL = newURL.absoluteString.starts(with: Constants.checkoutWebAddress)
guard canOpenNewURL else {
let error = DomainPurchasingError.unsupportedRedirect(fromURL: oldURL, toURL: newURL)
let error = SiteCreationPurchasingError.unsupportedRedirect(fromURL: oldURL, toURL: newURL)
completion(.failure(error))
return
}
Expand Down Expand Up @@ -242,17 +243,17 @@ final class DomainPurchasingWebFlowController {
}

/// Metadata to attach when capturing errors.
private func userInfoForError(_ error: DomainPurchasingError, domain: DomainSuggestion, site: Blog) -> [String: Any] {
private func userInfoForError(_ error: SiteCreationPurchasingError, domain: DomainSuggestion, site: Blog) -> [String: Any] {
var userInfo = userInfo(domain: domain, site: site)
userInfo = userInfo.merging(error.errorUserInfo) { $1 }
return userInfo
}

// MARK: - Types

typealias CompletionHandler = (Result<String, DomainPurchasingError>) -> Void
typealias CompletionHandler = (Result<String, SiteCreationPurchasingError>) -> Void

enum DomainPurchasingError: LocalizedError {
enum SiteCreationPurchasingError: LocalizedError {
case invalidInput
case canceled
case unsupportedRedirect(fromURL: URL?, toURL: URL)
Expand Down Expand Up @@ -281,7 +282,7 @@ final class DomainPurchasingWebFlowController {

// MARK: - Analytics Helpers

private extension DomainPurchasingWebFlowController {
private extension SiteCreationPurchasingWebFlowController {

func trackDomainCheckoutWebViewViewed(blog: Blog) {
let properties = WPAnalytics.domainsProperties(for: blog, origin: origin)
Expand All @@ -296,14 +297,14 @@ private extension DomainPurchasingWebFlowController {

// MARK: - Subtypes Extensions

extension DomainPurchasingWebFlowController.Domain {
extension SiteCreationPurchasingWebFlowController.Domain {

init?(domain: DomainSuggestion, site: Blog) {
guard let siteID = site.dotComID?.intValue,
let homeURLString = site.homeURL,
let homeURL = URL(string: homeURLString as String),
let hostURLString = homeURL.host,
let hostURL = URL(string: DomainPurchasingWebFlowController.Constants.checkoutWebAddress + "/\(hostURLString)")
let hostURL = URL(string: SiteCreationPurchasingWebFlowController.Constants.checkoutWebAddress + "/\(hostURLString)")
else {
return nil
}
Expand All @@ -315,7 +316,7 @@ extension DomainPurchasingWebFlowController.Domain {
}
}

extension DomainPurchasingWebFlowController.DomainPurchasingError: CustomNSError, CustomDebugStringConvertible {
extension SiteCreationPurchasingWebFlowController.SiteCreationPurchasingError: CustomNSError, CustomDebugStringConvertible {

/// Untrusted errors should be monitored and requires our attention.
var trusted: Bool {
Expand Down Expand Up @@ -382,7 +383,7 @@ extension DomainPurchasingWebFlowController.DomainPurchasingError: CustomNSError
///
/// This way, we guarantee that `onDismiss` will be called whether the screen was dismissed by tapping "X" button, using the swipe down gesture,
/// or even if the system decided to dismiss the screen.
private class DomainPurchasingNavigationController: UINavigationController {
private class SiteCreationPurchasingNavigationController: UINavigationController {

var onDismiss: (() -> Void)?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ final class SiteAssemblyContentView: UIView {
if let isFreeDomain = isFreeDomain {
return !isFreeDomain
}
return siteCreator.shouldShowDomainCheckout
return siteCreator.shouldShowCheckout
}

// MARK: SiteAssemblyContentView
Expand Down
Loading