Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //: Playground - noun: a place where people can play
- import UIKit
- protocol AuthorizationService {
- func requestAuthorization(inViewController vc: UIViewController, onSuccess: (_ authorizedCode: String)->())
- }
- class MPINAuthorizationService: AuthorizationService {
- func requestAuthorization(inViewController vc: UIViewController, onSuccess: (_ authorizedCode: String)->()) {
- // Shows view which asks for MPIN to input
- // On Success, provide it through closure
- }
- }
- class TouchIdAuthorizationService: AuthorizationService {
- func requestAuthorization(inViewController vc: UIViewController, onSuccess: (_ authorizedCode: String)->()) {
- // Asks user to scan their fingerprint
- // On Success, Looks for MPIN in Keychain
- // If found use it, else look for password in Keychain
- // returns whatever it finds
- }
- }
- class PasswordAuthorizationService: AuthorizationService {
- func requestAuthorization(inViewController vc: UIViewController, onSuccess: (_ authorizedCode: String)->()) {
- // Ask user to input their password incase of GPRS Email
- // On Success, provide it through closure
- }
- }
- // ================= ********************** =====================
- protocol AuthorizationManagementService {
- func requestForAuthorization(onSuccess:(_ authorizationCode: String)->())
- }
- class AuthorizationManager {
- private var viewController: UIViewController!
- private var authService: AuthorizationService?
- init(viewController: UIViewController) {
- self.viewController = viewController
- }
- func requestForAuthorization(onSuccess:(_ authorizationCode: String)->()) {
- // determines which mode of authorization to be used
- // use that authorization method
- // provide info through delegate if authorization is success
- /*
- let shouldUseTouchId: Bool = false
- let isUserEmailType: Bool = true
- if shouldUseTouchId {
- authService = TouchIdAuthorizationService()
- }
- */
- }
- }
- // ================= ********************** ======================
- class SMSRequestService {
- func sendSMS(inViewController vc: UIViewController, onSuccess: ()->(), onError: ()->()) {
- // Sends sms and execute onSuccess callback
- // In case of error, execute onError callback
- }
- }
- class ApiRequestService {
- func sendRequest(toApi api: String, onSuccess: ()->(), onError: ()->()) {
- // Sends API Request and execute onSuccess callback
- // Incase of error, execute onError callback
- }
- }
- // =================== *********************** ========================
- protocol TransactionManagementService {
- func initiateTransaction()
- }
- class GPRSSchoolFeePaymentService: TransactionManagementService {
- func initiateTransaction() {
- }
- }
- class SMSSchoolFeePaymentService: TransactionManagementService {
- func initiateTransaction() {
- }
- }
- protocol SchoolFeePaymentPresentation {
- }
- class SchoolFeePaymentController: UIViewController {
- var presenter: SchoolFeePaymentPresenter!
- override func viewDidLoad() {
- super.viewDidLoad()
- presenter = SchoolFeePaymentPresenter()
- }
- @objc func onSubmitButtonTap() {
- presenter.submitFeePaymentRequest()
- }
- func displayConfirmationController(data: String) {
- // let controller = ...
- // controller.data = data
- // controller.onConfirmation = presenter.startPaymentProcedure()
- // self.present ...
- }
- }
- class SchoolFeePaymentPresenter {
- var authManager: AuthorizationManagementService? // Inject it as dependency
- var transactionManager: TransactionManagementService? // Inject it as dependency
- func submitFeePaymentRequest() {
- // Setup all values for confirmation
- // Setup Cashback if available
- // Setup other things whatever dude
- // Ask controller to show confirmation controller with provided data
- }
- func startPaymentProcedure() {
- // Requires Authorization
- authManager?.requestForAuthorization(onSuccess: { (authorizedCode) in
- // Authorized.....
- })
- // When authorized, decide which mode to use for payment
- // Use that actual mode for payment
- }
- func startTransactionProcedure() {
- transactionManager?.initiateTransaction()
- }
- }
- /*
- protocol SchoolFeePaymentTransactionService {
- func initiateTransaction(schoolName: String, amount: String, something: String)
- }
- class GPRSSchoolFeePaymentService: SchoolFeePaymentTransactionService {
- }
- class SMSSchoolFeePaymentService: SchoolFeePaymentTransactionService {
- }
- class SchoolFeePaymentPresenter {
- ...
- var transactionManager: SchoolFeePaymentTransactionService?
- ...
- }
- */
- /*
- Payment Process
- |- SMS Mode
- |- Authorization
- |- Sending SMS
- |- GPRS Mode
- |- Authorization
- |- Send request to API
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement