Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. //: Playground - noun: a place where people can play
  2.  
  3. import UIKit
  4.  
  5. protocol AuthorizationService {
  6.  
  7. func requestAuthorization(inViewController vc: UIViewController, onSuccess: (_ authorizedCode: String)->())
  8. }
  9.  
  10. class MPINAuthorizationService: AuthorizationService {
  11.  
  12. func requestAuthorization(inViewController vc: UIViewController, onSuccess: (_ authorizedCode: String)->()) {
  13.  
  14. // Shows view which asks for MPIN to input
  15.  
  16. // On Success, provide it through closure
  17. }
  18. }
  19.  
  20. class TouchIdAuthorizationService: AuthorizationService {
  21.  
  22. func requestAuthorization(inViewController vc: UIViewController, onSuccess: (_ authorizedCode: String)->()) {
  23.  
  24. // Asks user to scan their fingerprint
  25.  
  26. // On Success, Looks for MPIN in Keychain
  27.  
  28. // If found use it, else look for password in Keychain
  29.  
  30. // returns whatever it finds
  31. }
  32. }
  33.  
  34. class PasswordAuthorizationService: AuthorizationService {
  35.  
  36. func requestAuthorization(inViewController vc: UIViewController, onSuccess: (_ authorizedCode: String)->()) {
  37.  
  38. // Ask user to input their password incase of GPRS Email
  39.  
  40. // On Success, provide it through closure
  41. }
  42. }
  43.  
  44. // ================= ********************** =====================
  45.  
  46. protocol AuthorizationManagementService {
  47.  
  48. func requestForAuthorization(onSuccess:(_ authorizationCode: String)->())
  49. }
  50.  
  51. class AuthorizationManager {
  52.  
  53. private var viewController: UIViewController!
  54. private var authService: AuthorizationService?
  55.  
  56. init(viewController: UIViewController) {
  57. self.viewController = viewController
  58. }
  59.  
  60. func requestForAuthorization(onSuccess:(_ authorizationCode: String)->()) {
  61.  
  62. // determines which mode of authorization to be used
  63.  
  64. // use that authorization method
  65.  
  66. // provide info through delegate if authorization is success
  67.  
  68. /*
  69. let shouldUseTouchId: Bool = false
  70. let isUserEmailType: Bool = true
  71.  
  72. if shouldUseTouchId {
  73. authService = TouchIdAuthorizationService()
  74. }
  75. */
  76. }
  77. }
  78.  
  79.  
  80. // ================= ********************** ======================
  81.  
  82. class SMSRequestService {
  83.  
  84. func sendSMS(inViewController vc: UIViewController, onSuccess: ()->(), onError: ()->()) {
  85.  
  86. // Sends sms and execute onSuccess callback
  87.  
  88. // In case of error, execute onError callback
  89. }
  90. }
  91.  
  92. class ApiRequestService {
  93.  
  94. func sendRequest(toApi api: String, onSuccess: ()->(), onError: ()->()) {
  95.  
  96. // Sends API Request and execute onSuccess callback
  97.  
  98. // Incase of error, execute onError callback
  99. }
  100. }
  101.  
  102. // =================== *********************** ========================
  103.  
  104. protocol TransactionManagementService {
  105.  
  106. func initiateTransaction()
  107. }
  108.  
  109. class GPRSSchoolFeePaymentService: TransactionManagementService {
  110.  
  111. func initiateTransaction() {
  112.  
  113. }
  114. }
  115.  
  116. class SMSSchoolFeePaymentService: TransactionManagementService {
  117.  
  118. func initiateTransaction() {
  119.  
  120. }
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. protocol SchoolFeePaymentPresentation {
  130.  
  131. }
  132.  
  133. class SchoolFeePaymentController: UIViewController {
  134.  
  135. var presenter: SchoolFeePaymentPresenter!
  136.  
  137. override func viewDidLoad() {
  138. super.viewDidLoad()
  139.  
  140. presenter = SchoolFeePaymentPresenter()
  141. }
  142.  
  143. @objc func onSubmitButtonTap() {
  144. presenter.submitFeePaymentRequest()
  145. }
  146.  
  147. func displayConfirmationController(data: String) {
  148.  
  149. // let controller = ...
  150.  
  151. // controller.data = data
  152.  
  153. // controller.onConfirmation = presenter.startPaymentProcedure()
  154.  
  155. // self.present ...
  156. }
  157. }
  158.  
  159.  
  160. class SchoolFeePaymentPresenter {
  161.  
  162. var authManager: AuthorizationManagementService? // Inject it as dependency
  163. var transactionManager: TransactionManagementService? // Inject it as dependency
  164.  
  165. func submitFeePaymentRequest() {
  166.  
  167. // Setup all values for confirmation
  168.  
  169. // Setup Cashback if available
  170.  
  171. // Setup other things whatever dude
  172.  
  173. // Ask controller to show confirmation controller with provided data
  174. }
  175.  
  176. func startPaymentProcedure() {
  177.  
  178. // Requires Authorization
  179. authManager?.requestForAuthorization(onSuccess: { (authorizedCode) in
  180.  
  181. // Authorized.....
  182.  
  183. })
  184.  
  185. // When authorized, decide which mode to use for payment
  186.  
  187. // Use that actual mode for payment
  188. }
  189.  
  190. func startTransactionProcedure() {
  191.  
  192. transactionManager?.initiateTransaction()
  193. }
  194.  
  195. }
  196.  
  197.  
  198.  
  199. /*
  200.  
  201. protocol SchoolFeePaymentTransactionService {
  202. func initiateTransaction(schoolName: String, amount: String, something: String)
  203. }
  204.  
  205. class GPRSSchoolFeePaymentService: SchoolFeePaymentTransactionService {
  206.  
  207. }
  208.  
  209. class SMSSchoolFeePaymentService: SchoolFeePaymentTransactionService {
  210.  
  211.  
  212. }
  213.  
  214. class SchoolFeePaymentPresenter {
  215.  
  216. ...
  217. var transactionManager: SchoolFeePaymentTransactionService?
  218.  
  219. ...
  220.  
  221. }
  222.  
  223.  
  224.  
  225. */
  226.  
  227.  
  228.  
  229.  
  230. /*
  231. Payment Process
  232. |- SMS Mode
  233. |- Authorization
  234. |- Sending SMS
  235.  
  236. |- GPRS Mode
  237. |- Authorization
  238. |- Send request to API
  239. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement