Skip to content

Commit

Permalink
Remove top level namespace enum
Browse files Browse the repository at this point in the history
So that it doesn't clash with the module name when being read as a
swift interface
  • Loading branch information
adamjcampbell committed Jul 21, 2020
1 parent 9700d5a commit 5723419
Showing 1 changed file with 27 additions and 31 deletions.
58 changes: 27 additions & 31 deletions Sources/Afterpay/Afterpay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,34 @@
import Foundation
import UIKit

public enum Afterpay {
/// Present Afterpay Checkout modally over the specified view controller loading your
/// generated checkout URL.
/// - Parameters:
/// - viewController: The viewController on which `UIViewController.present` will be called.
/// The Afterpay Checkout View Controller will be presented modally over this view controller
/// or it's closest parent that is able to handle the presentation.
/// - checkoutURL: The checkout URL to load generated via the /checkouts endpoint on the
/// Afterpay backend.
/// - animated: Pass true to animate the presentation; otherwise, pass false.
/// - completion: The block executed after the user has completed the checkout.
/// - result: The result of the user's completion (a success or cancellation).
public func presentCheckoutModally(
over viewController: UIViewController,
loading checkoutURL: URL,
animated: Bool = true,
completion: @escaping (_ result: CheckoutResult) -> Void
) {
var viewControllerToPresent: UIViewController = WebViewController(
checkoutUrl: checkoutURL,
completion: completion
)

/// Present Afterpay Checkout modally over the specified view controller loading your
/// generated checkout URL.
/// - Parameters:
/// - viewController: The viewController on which `UIViewController.present` will be called.
/// The Afterpay Checkout View Controller will be presented modally over this view controller
/// or it's closest parent that is able to handle the presentation.
/// - checkoutURL: The checkout URL to load generated via the /checkouts endpoint on the
/// Afterpay backend.
/// - animated: Pass true to animate the presentation; otherwise, pass false.
/// - completion: The block executed after the user has completed the checkout.
/// - result: The result of the user's completion (a success or cancellation).
public static func presentCheckoutModally(
over viewController: UIViewController,
loading checkoutURL: URL,
animated: Bool = true,
completion: @escaping (_ result: CheckoutResult) -> Void
) {
var viewControllerToPresent: UIViewController = WebViewController(
checkoutUrl: checkoutURL,
completion: completion
)

if #available(iOS 13.0, *) {
} else {
// Wrap the modal in a navigation controller to allow dismiss via a bar button item prior
// to popover modals in iOS13
viewControllerToPresent = UINavigationController(rootViewController: viewControllerToPresent)
}

viewController.present(viewControllerToPresent, animated: animated, completion: nil)
if #available(iOS 13.0, *) {
} else {
// Wrap the modal in a navigation controller to allow dismiss via a bar button item prior
// to popover modals in iOS13
viewControllerToPresent = UINavigationController(rootViewController: viewControllerToPresent)
}

viewController.present(viewControllerToPresent, animated: animated, completion: nil)
}

0 comments on commit 5723419

Please sign in to comment.