Guest User

Untitled

a guest
Oct 21st, 2017
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. Array
  2. (
  3. [max_number_of_payments] => 100
  4. [starting_date] => 2015-03-01T00:00:21.000-08:00
  5. [pin_type] => NOT_REQUIRED
  6. [max_amount_per_payment] => 20.00
  7. [currency_code] => USD
  8. [sender_email] => guy.louzon-buyer@gmail.com
  9. [verify_sign] => AFcWxV21C7fd0v3bYYYRCpSSRl31AiHQSQchSGUInXdtl6zomfkZ7H4C
  10. [test_ipn] => 1
  11. [date_of_month] => 0
  12. [current_number_of_payments] => 0
  13. [preapproval_key] => PA-2M0807730Y425554F
  14. [ending_date] => 2015-12-31T23:59:21.000-08:00
  15. [approved] => true
  16. [transaction_type] => Adaptive Payment PREAPPROVAL
  17. [day_of_week] => NO_DAY_SPECIFIED
  18. [status] => ACTIVE
  19. [current_total_amount_of_all_payments] => 0.00
  20. [current_period_attempts] => 0
  21. [charset] => windows-1252
  22. [payment_period] => 0
  23. [notify_version] => UNVERSIONED
  24. [max_total_amount_of_all_payments] => 2000.00
  25. )
  26.  
  27. func profileController() -> PayPalProfileSharingViewController {
  28. PayPalMobile.preconnectWithEnvironment(PayPalEnvironmentSandbox)//PayPalEnvironmentNoNetwork)
  29. let scope: Set<String> = Set([kPayPalOAuth2ScopeEmail, kPayPalOAuth2ScopeFuturePayments])
  30. let controller = PayPalProfileSharingViewController(scopeValues: scope, configuration: self.paypalConfiguration!, delegate: self)
  31. return controller!
  32. }
  33.  
  34. func payPalProfileSharingViewController(profileSharingViewController: PayPalProfileSharingViewController, userDidLogInWithAuthorization profileSharingAuthorization: [NSObject : AnyObject]) {
  35. self.processAuthorization(profileSharingAuthorization)
  36. }
  37.  
  38. func userDidCancelPayPalProfileSharingViewController(profileSharingViewController: PayPalProfileSharingViewController) {
  39. self.delegate?.didFailPayPalConsent()
  40. }
  41.  
  42. func processAuthorization(authorization: [NSObject: AnyObject]) {
  43. if let authCode = authorization["response"]?["code"] as? String {
  44. self.delegate?.didSucceedPayPalConsent(authCode)
  45. }
  46. else {
  47. self.delegate?.didFailPayPalConsent()
  48. }
  49. }
  50.  
  51. func payPalProfileSharingViewController(profileSharingViewController: PayPalProfileSharingViewController, userDidLogInWithAuthorization profileSharingAuthorization: [NSObject : AnyObject]) {
  52. self.processAuthorization(profileSharingAuthorization)
  53.  
  54. func generateAccessToken(authCode : String ,block : completionHandler){
  55. let parameters = ["grant_type" : "authorization_code", "response_type" :"token","redirect_uri" : "urn:ietf:wg:oauth:2.0:oob","code":authCode]
  56. let username = AppConstants().kPayPalUserName //APP_ID
  57. let password = AppConstants().kPayPalSecret
  58.  
  59. let credentialData = "(username):(password)".data(using: String.Encoding.utf8)!
  60. let base64Credentials = credentialData.base64EncodedString(options: [])
  61. let headers = ["Authorization": "Basic (base64Credentials)"]
  62. let customerURL = AppConstants().kPayPalUrl
  63. Alamofire.request(customerURL,
  64. method: .post,
  65. parameters: parameters,
  66. encoding: URLEncoding.default,
  67. headers:headers)
  68. .validate()
  69. .responseJSON { response in
  70. switch response.result {
  71. case .success(let value):
  72. KVNProgress.dismiss(completion: {
  73. block?(true, value as! Dictionary<String, Any>) // get the accessToken
  74. })
  75.  
  76. // BasicFunctions.displayAlert("Success", needDismiss: false, title: "Task Created Successfully")
  77. case .failure(let responseError):
  78.  
  79.  
  80. KVNProgress.dismiss(completion: {
  81. if (responseError != nil) {
  82. BasicFunctions.displayAlert(SERVER_ERROR)
  83. // let json = JSONSerialization
  84. // block!(false,responseError as! Dictionary<String, Any>)
  85. }else{
  86. BasicFunctions.displayAlert(SERVER_ERROR)
  87. }
  88. })
  89.  
  90. }
  91. }
  92. }
  93.  
  94. func getUserProfileInfo(accessToken : String,block : completionHandler){
  95.  
  96. KVNProgress.show()
  97. let parameters = ["":""]
  98.  
  99.  
  100. let headers = ["Authorization": "Bearer " + accessToken]
  101.  
  102. let customerURL = "https://api.sandbox.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid"
  103.  
  104.  
  105. Alamofire.request(customerURL, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON { (response) in
  106. switch response.result {
  107. case .success(let value):
  108. KVNProgress.dismiss(completion: {
  109. block?(true, value as! Dictionary<String, Any>)
  110. })
  111.  
  112. // BasicFunctions.displayAlert("Success", needDismiss: false, title: "Task Created Successfully")
  113. case .failure(let responseError):
  114.  
  115.  
  116. KVNProgress.dismiss(completion: {
  117. if (responseError != nil) {
  118. BasicFunctions.displayAlert(SERVER_ERROR)
  119. // let json = JSONSerialization
  120. // block!(false,responseError as! Dictionary<String, Any>)
  121. }else{
  122. BasicFunctions.displayAlert(SERVER_ERROR)
  123. }
  124. })
  125.  
  126. }
  127. }
  128. }
Add Comment
Please, Sign In to add comment