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

feat(ad-hoc): public api update #99

Merged
merged 10 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example/Example/Sources/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
// MARK: - Private Methods

private func configureProcessOut() {
let configuration = ProcessOutApiConfiguration.test(
let configuration = ProcessOutConfiguration.test(
projectId: Constants.projectId,
privateKey: Constants.projectPrivateKey,
// swiftlint:disable force_unwrapping
apiBaseUrl: URL(string: Constants.apiBaseUrl)!,
checkoutBaseUrl: URL(string: Constants.checkoutBaseUrl)!
// swiftlint:enable force_unwrapping
)
ProcessOutApi.configure(configuration: configuration)
ProcessOut.configure(configuration: configuration)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ final class AlternativePaymentMethodsBuilder {

func build() -> UIViewController {
let interactor = AlternativePaymentMethodsInteractor(
gatewayConfigurationsRepository: ProcessOutApi.shared.gatewayConfigurations,
invoicesService: ProcessOutApi.shared.invoices,
gatewayConfigurationsRepository: ProcessOut.shared.gatewayConfigurations,
invoicesService: ProcessOut.shared.invoices,
filter: filter
)
let router = AlternativePaymentMethodsRouter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ final class CardPaymentBuilder {
let router = CardPaymentRouter()
let viewModel = CardPaymentViewModel(
router: router,
invoicesService: ProcessOutApi.shared.invoices,
cardsService: ProcessOutApi.shared.cards,
invoicesService: ProcessOut.shared.invoices,
cardsService: ProcessOut.shared.cards,
threeDSService: threeDSService
)
let viewController = CardPaymentViewController(viewModel: viewModel)
Expand Down
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ let package = Package(
dependencies: [],
// Having DocC in sources may cause build failures so excluded until issue is resolved by Apple. See
// https://forums.swift.org/t/xcode-and-swift-package-manager/44704 for details.
exclude: ["ProcessOut.docc"]
exclude: ["ProcessOut.docc"],
swiftSettings: [
.unsafeFlags(["-Xfrontend", "-module-interface-preserve-types-as-written"])
]
)
]
)
1 change: 1 addition & 0 deletions ProcessOut.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '12.0'
s.ios.resource_bundle = { 'ProcessOut' => 'Sources/ProcessOut/Resources/**/*' }
s.source_files = 'Sources/ProcessOut/**/*.swift'
s.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-Xfrontend -module-interface-preserve-types-as-written' }
end
6 changes: 3 additions & 3 deletions Scripts/UpdateVersion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ fi
echo $VERSION > Version.resolved

# Generates ProcessOut+Version.swift
cat > "Sources/ProcessOut/Sources/Generated/ProcessOutApiType+Version.swift" <<- EOF
cat > "Sources/ProcessOut/Sources/Generated/ProcessOut+Version.swift" <<- EOF
//
// ProcessOutApiType+Version.swift
// ProcessOut+Version.swift
//
// This file was generated by UpdateVersion.sh
// Do not edit this file directly.
//

extension ProcessOutApiType {
extension ProcessOut {

/// The current version of this library, value is "${VERSION}".
public static var version: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Version 3 is not backward compatible with previous versions, although migration
straightforward. There are some changes that should be addressed when migrating:

1. Instead of `ProcessOut.Setup(projectId: String)` there is new method that should be used to configure
SDK ``ProcessOutApi/configure(configuration:)``.
SDK ``ProcessOut/configure(configuration:)``.

2. `ProcessOut` was renamed to ``ProcessOutLegacyApi`` to avoid shadowing module name as it may cause issues. For more
information, see [Swift Issue](https://github.com/apple/swift/issues/56573).
Expand Down
9 changes: 4 additions & 5 deletions Sources/ProcessOut/ProcessOut.docc/ProcessOut.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Before using ProcessOut SDK make sure to configure it.
```swift
import ProcessOut

let configuration = ProcessOutApiConfiguration.production(projectId: "your_project_id")
ProcessOutApi.configure(configuration: configuration)
let configuration = ProcessOutConfiguration.production(projectId: "your_project_id")
ProcessOut.configure(configuration: configuration)
```

## Topics
Expand All @@ -17,9 +17,8 @@ ProcessOutApi.configure(configuration: configuration)

- <doc:MigratingFromProcessOut2>
- <doc:Localizations>
- ``ProcessOutApi``
- ``ProcessOutApiConfiguration``
- ``ProcessOutApiType``
- ``ProcessOut/ProcessOut``
- ``ProcessOutConfiguration``

### Errors

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
//
// ProcessOutApiConfiguration.swift
// ProcessOutConfiguration.swift
// ProcessOut
//
// Created by Andrii Vysotskyi on 10.10.2022.
//

import Foundation

@available(*, deprecated, renamed: "ProcessOutConfiguration")
public typealias ProcessOutApiConfiguration = ProcessOutConfiguration

/// Defines configuration parameters that are used to create API singleton. In order to create instance
/// of this structure one should use ``ProcessOutApiConfiguration/production(projectId:isDebug:)``
/// of this structure one should use ``ProcessOutConfiguration/production(projectId:isDebug:)``
/// method.
public struct ProcessOutApiConfiguration {
public struct ProcessOutConfiguration {

/// Project id.
public let projectId: String
Expand All @@ -33,15 +36,15 @@ public struct ProcessOutApiConfiguration {
let checkoutBaseUrl: URL
}

extension ProcessOutApiConfiguration {
extension ProcessOutConfiguration {

/// Creates production configuration.
public static func production(projectId: String, isDebug: Bool = false) -> Self {
// swiftlint:disable force_unwrapping
let apiBaseUrl = URL(string: "https://api.processout.com")!
let checkoutBaseUrl = URL(string: "https://checkout.processout.com")!
// swiftlint:enable force_unwrapping
return ProcessOutApiConfiguration(
return ProcessOutConfiguration(
projectId: projectId,
isDebug: isDebug,
privateKey: nil,
Expand All @@ -53,7 +56,7 @@ extension ProcessOutApiConfiguration {
/// Creates test configuration.
@_spi(PO)
public static func test(projectId: String, privateKey: String?, apiBaseUrl: URL, checkoutBaseUrl: URL) -> Self {
ProcessOutApiConfiguration(
ProcessOutConfiguration(
projectId: projectId,
isDebug: true,
privateKey: privateKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ProcessOutApi.swift
// ProcessOut.swift
// ProcessOut
//
// Created by Andrii Vysotskyi on 07.10.2022.
Expand All @@ -8,58 +8,58 @@
import Foundation
import UIKit

@available(*, deprecated, renamed: "ProcessOut")
public typealias ProcessOutApi = ProcessOut

/// Provides access to shared api instance and a way to configure it.
public enum ProcessOutApi {
public final class ProcessOut {

/// Shared instance.
public private(set) static var shared: ProcessOutApiType! // swiftlint:disable:this implicitly_unwrapped_optional
public private(set) static var shared: ProcessOut! // swiftlint:disable:this implicitly_unwrapped_optional

/// Configures ``ProcessOutApi/shared`` instance.
/// Configures ``ProcessOut/shared`` instance.
/// - NOTE: Method must be called from main thread. Only the first invocation takes effect, all
/// subsequent calls to this method are ignored.
public static func configure(configuration: ProcessOutApiConfiguration) {
public static func configure(configuration: ProcessOutConfiguration) {
assert(Thread.isMainThread, "Method must be called only from main thread")
if let shared {
shared.logger.info("ProcessOutApi can be configured only once, ignored")
shared.logger.info("ProcessOut can be configured only once, ignored")
return
}
shared = SharedProcessOutApi(configuration: configuration)
shared.logger.debug("Did complete ProcessOutApi configuration")
}
}

private final class SharedProcessOutApi: ProcessOutApiType {

init(configuration: ProcessOutApiConfiguration) {
self.configuration = configuration
shared = ProcessOut(configuration: configuration)
shared.logger.debug("Did complete ProcessOut configuration")
}

// MARK: - ProcessOutApiType
// MARK: - ProcessOutType

let configuration: ProcessOutApiConfiguration
/// Current configuration.
public let configuration: ProcessOutConfiguration

private(set) lazy var gatewayConfigurations: POGatewayConfigurationsRepository = {
/// Returns gateway configurations repository.
public private(set) lazy var gatewayConfigurations: POGatewayConfigurationsRepository = {
HttpGatewayConfigurationsRepository(connector: httpConnector, failureMapper: failureMapper)
}()

private(set) lazy var invoices: POInvoicesService = {
/// Returns invoices service.
public private(set) lazy var invoices: POInvoicesService = {
let repository = HttpInvoicesRepository(connector: httpConnector, failureMapper: failureMapper)
return DefaultInvoicesService(repository: repository, threeDSService: threeDSService)
}()

private(set) lazy var images: POImagesRepository = {
/// Images repository.
public private(set) lazy var images: POImagesRepository = {
UrlSessionImagesRepository(session: .shared)
}()

private(set) lazy var alternativePaymentMethods: POAlternativePaymentMethodsService = {
/// Returns alternative payment methods service.
public private(set) lazy var alternativePaymentMethods: POAlternativePaymentMethodsService = {
DefaultAlternativePaymentMethodsService(
projectId: configuration.projectId, baseUrl: configuration.checkoutBaseUrl, logger: serviceLogger
)
}()

private(set) lazy var logger: POLogger = createLogger(for: Constants.applicationLoggerCategory)

private(set) lazy var cards: POCardsService = {
/// Returns cards repository.
public private(set) lazy var cards: POCardsService = {
let requestMapper = DefaultApplePayCardTokenizationRequestMapper(
decoder: JSONDecoder(), logger: repositoryLogger
)
Expand All @@ -70,11 +70,15 @@ private final class SharedProcessOutApi: ProcessOutApiType {
return service
}()

private(set) lazy var customerTokens: POCustomerTokensService = {
/// Returns customer tokens service.
public private(set) lazy var customerTokens: POCustomerTokensService = {
let repository = HttpCustomerTokensRepository(connector: httpConnector, failureMapper: failureMapper)
return DefaultCustomerTokensService(repository: repository, threeDSService: threeDSService)
}()

/// Logger with application category.
public private(set) lazy var logger: POLogger = createLogger(for: Constants.applicationLoggerCategory)

// MARK: - Private Nested Types

private enum Constants {
Expand All @@ -95,7 +99,7 @@ private final class SharedProcessOutApi: ProcessOutApiType {
baseUrl: configuration.apiBaseUrl,
projectId: configuration.projectId,
privateKey: configuration.privateKey,
version: Self.version
version: ProcessOut.version
)
let connector = ProcessOutHttpConnectorBuilder()
.with(configuration: connectorConfiguration)
Expand All @@ -117,6 +121,10 @@ private final class SharedProcessOutApi: ProcessOutApiType {

// MARK: - Private Methods

private init(configuration: ProcessOutConfiguration) {
self.configuration = configuration
}

private func createLogger(for category: String) -> POLogger {
let destinations: [LoggerDestination] = [
SystemLoggerDestination(subsystem: Constants.systemLoggerSubsystem, category: category)
Expand All @@ -125,3 +133,6 @@ private final class SharedProcessOutApi: ProcessOutApiType {
return POLogger(destinations: destinations, minimumLevel: minimumLevel)
}
}

@available(*, deprecated, message: "Use ProcessOut directly")
extension ProcessOut: ProcessOutApiType { }
14 changes: 12 additions & 2 deletions Sources/ProcessOut/Sources/Api/ProcessOutApiType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import Foundation

// todo(andrii-vysotskyi): remove suffix before releasing version 4.0.0
@available(*, deprecated)
public protocol ProcessOutApiType {

/// Current configuration.
var configuration: ProcessOutApiConfiguration { get }
var configuration: ProcessOutConfiguration { get }

/// Returns gateway configurations repository.
var gatewayConfigurations: POGatewayConfigurationsRepository { get }
Expand All @@ -34,3 +34,13 @@ public protocol ProcessOutApiType {
/// Logger with application category.
var logger: POLogger { get }
}

@available(*, deprecated)
extension ProcessOutApiType {

/// The current version of this library.
@available(*, deprecated, message: "Use ProcessOut.version instead")
public static var version: String {
ProcessOut.version
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//
// ProcessOutApiType+Version.swift
// ProcessOut+Version.swift
//
// This file was generated by UpdateVersion.sh
// Do not edit this file directly.
//

extension ProcessOutApiType {
extension ProcessOut {

/// The current version of this library, value is "3.5.0".
public static var version: String {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ProcessOut/Sources/Legacy/APMTokenReturn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

@available(*, deprecated, message: "Use ProcessOutApi.shared.customerTokens.assignCustomerToken() instead.")
@available(*, deprecated, message: "Use ProcessOut.shared.customerTokens.assignCustomerToken() instead.")
public final class APMTokenReturn {

public enum APMReturnType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Jeremy Lejoux on 17/06/2019.
//

@available(*, deprecated, message: "Use ProcessOutApi.shared.invoices.authorizeInvoice() instead.")
@available(*, deprecated, message: "Use ProcessOut.shared.invoices.authorizeInvoice() instead.")
public final class AuthorizationRequest: Codable {

var invoiceID: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

@available(*, deprecated, message: "Use ProcessOutApi.shared.gatewayConfigurations instead.")
@available(*, deprecated, message: "Use ProcessOut.shared.gatewayConfigurations instead.")
public class GatewayConfiguration: Decodable {

enum CodingKeys: String, CodingKey {
Expand Down
Loading