paypal-sdk-rest 1.7.6 → 2.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +4 -14
  3. data/README.md +45 -255
  4. data/lib/lib.rb +88 -0
  5. data/lib/paypal/core/access_token.rb +20 -0
  6. data/lib/paypal/core/paypal_environment.rb +38 -0
  7. data/lib/paypal/core/paypal_http_client.rb +51 -0
  8. data/lib/paypal/core/token_requests.rb +40 -0
  9. data/lib/paypal/core/version.rb +3 -0
  10. data/lib/v1/billing_agreements/agreement_bill_balance_request.rb +35 -0
  11. data/lib/v1/billing_agreements/agreement_cancel_request.rb +35 -0
  12. data/lib/v1/billing_agreements/agreement_create_request.rb +33 -0
  13. data/lib/v1/billing_agreements/agreement_execute_request.rb +31 -0
  14. data/lib/v1/billing_agreements/agreement_get_request.rb +31 -0
  15. data/lib/v1/billing_agreements/agreement_re_activate_request.rb +35 -0
  16. data/lib/v1/billing_agreements/agreement_set_balance_request.rb +35 -0
  17. data/lib/v1/billing_agreements/agreement_suspend_request.rb +35 -0
  18. data/lib/v1/billing_agreements/agreement_transactions_request.rb +41 -0
  19. data/lib/v1/billing_agreements/agreement_update_request.rb +35 -0
  20. data/lib/v1/billing_plans/plan_create_request.rb +33 -0
  21. data/lib/v1/billing_plans/plan_get_request.rb +31 -0
  22. data/lib/v1/billing_plans/plan_list_request.rb +49 -0
  23. data/lib/v1/billing_plans/plan_update_request.rb +35 -0
  24. data/lib/v1/identity/user_consent.rb +45 -0
  25. data/lib/v1/identity/userinfo_get_request.rb +33 -0
  26. data/lib/v1/invoices/invoice_cancel_request.rb +35 -0
  27. data/lib/v1/invoices/invoice_create_request.rb +33 -0
  28. data/lib/v1/invoices/invoice_delete_external_payment_request.rb +33 -0
  29. data/lib/v1/invoices/invoice_delete_external_refund_request.rb +33 -0
  30. data/lib/v1/invoices/invoice_delete_request.rb +31 -0
  31. data/lib/v1/invoices/invoice_get_request.rb +31 -0
  32. data/lib/v1/invoices/invoice_list_request.rb +44 -0
  33. data/lib/v1/invoices/invoice_next_invoice_number_request.rb +29 -0
  34. data/lib/v1/invoices/invoice_qr_code_request.rb +46 -0
  35. data/lib/v1/invoices/invoice_record_payment_request.rb +35 -0
  36. data/lib/v1/invoices/invoice_record_refund_request.rb +35 -0
  37. data/lib/v1/invoices/invoice_remind_request.rb +35 -0
  38. data/lib/v1/invoices/invoice_search_request.rb +33 -0
  39. data/lib/v1/invoices/invoice_send_request.rb +36 -0
  40. data/lib/v1/invoices/invoice_update_request.rb +40 -0
  41. data/lib/v1/invoices/template_create_request.rb +33 -0
  42. data/lib/v1/invoices/template_delete_request.rb +31 -0
  43. data/lib/v1/invoices/template_get_request.rb +31 -0
  44. data/lib/v1/invoices/template_list_request.rb +34 -0
  45. data/lib/v1/invoices/template_update_request.rb +35 -0
  46. data/lib/v1/orders/orders_cancel_request.rb +31 -0
  47. data/lib/v1/orders/orders_create_request.rb +33 -0
  48. data/lib/v1/orders/orders_get_request.rb +31 -0
  49. data/lib/v1/orders/orders_pay_request.rb +35 -0
  50. data/lib/v1/payment_experience/web_profile_create_request.rb +33 -0
  51. data/lib/v1/payment_experience/web_profile_delete_request.rb +31 -0
  52. data/lib/v1/payment_experience/web_profile_get_request.rb +31 -0
  53. data/lib/v1/payment_experience/web_profile_list_request.rb +29 -0
  54. data/lib/v1/payment_experience/web_profile_partial_update_request.rb +35 -0
  55. data/lib/v1/payment_experience/web_profile_update_request.rb +35 -0
  56. data/lib/v1/payments/authorization_capture_request.rb +35 -0
  57. data/lib/v1/payments/authorization_get_request.rb +31 -0
  58. data/lib/v1/payments/authorization_reauthorize_request.rb +35 -0
  59. data/lib/v1/payments/authorization_void_request.rb +31 -0
  60. data/lib/v1/payments/capture_get_request.rb +31 -0
  61. data/lib/v1/payments/capture_refund_request.rb +35 -0
  62. data/lib/v1/payments/order_authorize_request.rb +35 -0
  63. data/lib/v1/payments/order_capture_request.rb +35 -0
  64. data/lib/v1/payments/order_get_request.rb +31 -0
  65. data/lib/v1/payments/order_void_request.rb +31 -0
  66. data/lib/v1/payments/payment_create_request.rb +33 -0
  67. data/lib/v1/payments/payment_execute_request.rb +35 -0
  68. data/lib/v1/payments/payment_get_request.rb +31 -0
  69. data/lib/v1/payments/payment_list_request.rb +69 -0
  70. data/lib/v1/payments/payment_update_request.rb +35 -0
  71. data/lib/v1/payments/refund_get_request.rb +31 -0
  72. data/lib/v1/payments/sale_get_request.rb +31 -0
  73. data/lib/v1/payments/sale_refund_request.rb +35 -0
  74. data/lib/v1/sync/search_get_request.rb +99 -0
  75. data/lib/v1/vault/credit_card_create_request.rb +33 -0
  76. data/lib/v1/vault/credit_card_delete_request.rb +31 -0
  77. data/lib/v1/vault/credit_card_get_request.rb +31 -0
  78. data/lib/v1/vault/credit_card_list_request.rb +79 -0
  79. data/lib/v1/vault/credit_card_update_request.rb +35 -0
  80. data/lib/v1/webhooks/available_event_type_list_request.rb +29 -0
  81. data/lib/v1/webhooks/event_get_request.rb +31 -0
  82. data/lib/v1/webhooks/event_list_request.rb +54 -0
  83. data/lib/v1/webhooks/event_resend_request.rb +35 -0
  84. data/lib/v1/webhooks/simulate_event_request.rb +33 -0
  85. data/lib/v1/webhooks/webhook_create_request.rb +33 -0
  86. data/lib/v1/webhooks/webhook_delete_request.rb +31 -0
  87. data/lib/v1/webhooks/webhook_get_request.rb +31 -0
  88. data/lib/v1/webhooks/webhook_list_event_subscriptions_request.rb +31 -0
  89. data/lib/v1/webhooks/webhook_list_request.rb +34 -0
  90. data/lib/v1/webhooks/webhook_update_request.rb +35 -0
  91. data/lib/v1/webhooks/webhook_verify_signature_request.rb +33 -0
  92. data/spec/integration/test_harness.rb +25 -0
  93. data/spec/integration/v1/billing_agreements/agreement_create_spec.rb +63 -0
  94. data/spec/integration/v1/billing_plans/plan_create_spec.rb +12 -0
  95. data/spec/integration/v1/billing_plans/plan_get_spec.rb +16 -0
  96. data/spec/integration/v1/billing_plans/plan_helper.rb +71 -0
  97. data/spec/integration/v1/billing_plans/plan_list_spec.rb +16 -0
  98. data/spec/integration/v1/billing_plans/plan_update_spec.rb +19 -0
  99. data/spec/integration/v1/identity/userinfo_get_spec.rb +65 -0
  100. data/spec/integration/v1/invoices/invoice_cancel_spec.rb +23 -0
  101. data/spec/integration/v1/invoices/invoice_create_spec.rb +15 -0
  102. data/spec/integration/v1/invoices/invoice_delete_external_payment_spec.rb +23 -0
  103. data/spec/integration/v1/invoices/invoice_delete_external_refund_spec.rb +21 -0
  104. data/spec/integration/v1/invoices/invoice_delete_spec.rb +16 -0
  105. data/spec/integration/v1/invoices/invoice_get_spec.rb +18 -0
  106. data/spec/integration/v1/invoices/invoice_helper.rb +171 -0
  107. data/spec/integration/v1/invoices/invoice_list_spec.rb +20 -0
  108. data/spec/integration/v1/invoices/invoice_next_invoice_number_spec.rb +14 -0
  109. data/spec/integration/v1/invoices/invoice_qr_code_spec.rb +18 -0
  110. data/spec/integration/v1/invoices/invoice_record_payment_spec.rb +14 -0
  111. data/spec/integration/v1/invoices/invoice_record_refund_spec.rb +14 -0
  112. data/spec/integration/v1/invoices/invoice_remind_spec.rb +22 -0
  113. data/spec/integration/v1/invoices/invoice_search_spec.rb +20 -0
  114. data/spec/integration/v1/invoices/invoice_send_spec.rb +15 -0
  115. data/spec/integration/v1/invoices/invoice_update_spec.rb +26 -0
  116. data/spec/integration/v1/invoices/template_create_spec.rb +14 -0
  117. data/spec/integration/v1/invoices/template_delete_spec.rb +15 -0
  118. data/spec/integration/v1/invoices/template_get_spec.rb +18 -0
  119. data/spec/integration/v1/invoices/template_list_spec.rb +15 -0
  120. data/spec/integration/v1/invoices/template_update_spec.rb +62 -0
  121. data/spec/integration/v1/orders/orders_cancel_spec.rb +15 -0
  122. data/spec/integration/v1/orders/orders_create_spec.rb +17 -0
  123. data/spec/integration/v1/orders/orders_get_spec.rb +18 -0
  124. data/spec/integration/v1/orders/orders_helper.rb +36 -0
  125. data/spec/integration/v1/orders/orders_pay_spec.rb +19 -0
  126. data/spec/integration/v1/payment_experience/pe_helper.rb +35 -0
  127. data/spec/integration/v1/payment_experience/web_profile_create_spec.rb +20 -0
  128. data/spec/integration/v1/payment_experience/web_profile_delete_spec.rb +15 -0
  129. data/spec/integration/v1/payment_experience/web_profile_get_spec.rb +17 -0
  130. data/spec/integration/v1/payment_experience/web_profile_list_spec.rb +18 -0
  131. data/spec/integration/v1/payment_experience/web_profile_partial_update_spec.rb +32 -0
  132. data/spec/integration/v1/payment_experience/web_profile_update_spec.rb +44 -0
  133. data/spec/integration/v1/payments/authorization_capture_spec.rb +17 -0
  134. data/spec/integration/v1/payments/authorization_get_spec.rb +18 -0
  135. data/spec/integration/v1/payments/authorization_reauthorize_spec.rb +26 -0
  136. data/spec/integration/v1/payments/authorization_void_spec.rb +19 -0
  137. data/spec/integration/v1/payments/capture_get_spec.rb +20 -0
  138. data/spec/integration/v1/payments/capture_refund_spec.rb +27 -0
  139. data/spec/integration/v1/payments/order_authorize_spec.rb +20 -0
  140. data/spec/integration/v1/payments/order_capture_spec.rb +21 -0
  141. data/spec/integration/v1/payments/order_get_spec.rb +14 -0
  142. data/spec/integration/v1/payments/order_void_spec.rb +14 -0
  143. data/spec/integration/v1/payments/payment_create_spec.rb +13 -0
  144. data/spec/integration/v1/payments/payment_execute_spec.rb +19 -0
  145. data/spec/integration/v1/payments/payment_get_spec.rb +17 -0
  146. data/spec/integration/v1/payments/payment_list_spec.rb +16 -0
  147. data/spec/integration/v1/payments/payment_update_spec.rb +28 -0
  148. data/spec/integration/v1/payments/payments_helper.rb +72 -0
  149. data/spec/integration/v1/payments/refund_get_spec.rb +19 -0
  150. data/spec/integration/v1/payments/sale_get_spec.rb +18 -0
  151. data/spec/integration/v1/payments/sale_refund_spec.rb +18 -0
  152. data/spec/integration/v1/sync/search_get_spec.rb +34 -0
  153. data/spec/integration/v1/vault/credit_card_create_spec.rb +16 -0
  154. data/spec/integration/v1/vault/credit_card_delete_spec.rb +16 -0
  155. data/spec/integration/v1/vault/credit_card_get_spec.rb +17 -0
  156. data/spec/integration/v1/vault/credit_card_list_spec.rb +18 -0
  157. data/spec/integration/v1/vault/credit_card_update_spec.rb +26 -0
  158. data/spec/integration/v1/vault/vault_helper.rb +28 -0
  159. data/spec/integration/v1/webhooks/available_event_type_list_spec.rb +16 -0
  160. data/spec/integration/v1/webhooks/webhook_create_spec.rb +12 -0
  161. data/spec/integration/v1/webhooks/webhook_delete_spec.rb +13 -0
  162. data/spec/integration/v1/webhooks/webhook_get_spec.rb +16 -0
  163. data/spec/integration/v1/webhooks/webhook_helper.rb +43 -0
  164. data/spec/integration/v1/webhooks/webhook_list_event_subscriptions_spec.rb +16 -0
  165. data/spec/integration/v1/webhooks/webhook_list_spec.rb +15 -0
  166. data/spec/integration/v1/webhooks/webhook_update_spec.rb +29 -0
  167. data/spec/integration/v1/webhooks/webhook_verify_signature_spec.rb +20 -0
  168. data/spec/spec_helper.rb +97 -28
  169. data/spec/unit/paypal_http_client_spec.rb +264 -0
  170. metadata +257 -127
  171. data/Rakefile +0 -15
  172. data/data/DigiCertHighAssuranceEVRootCA.pem +0 -23
  173. data/data/DigiCertSHA2ExtendedValidationServerCA.pem +0 -28
  174. data/data/paypal.crt +0 -171
  175. data/lib/generators/paypal/sdk/USAGE +0 -3
  176. data/lib/generators/paypal/sdk/install_generator.rb +0 -17
  177. data/lib/generators/paypal/sdk/templates/paypal.rb +0 -2
  178. data/lib/generators/paypal/sdk/templates/paypal.yml +0 -29
  179. data/lib/paypal-sdk/core/api/base.rb +0 -169
  180. data/lib/paypal-sdk/core/api/data_types/array_with_block.rb +0 -44
  181. data/lib/paypal-sdk/core/api/data_types/base.rb +0 -225
  182. data/lib/paypal-sdk/core/api/data_types/enum.rb +0 -26
  183. data/lib/paypal-sdk/core/api/data_types/simple_types.rb +0 -52
  184. data/lib/paypal-sdk/core/api/ipn.rb +0 -66
  185. data/lib/paypal-sdk/core/api/rest.rb +0 -177
  186. data/lib/paypal-sdk/core/api.rb +0 -20
  187. data/lib/paypal-sdk/core/authentication.rb +0 -66
  188. data/lib/paypal-sdk/core/config.rb +0 -253
  189. data/lib/paypal-sdk/core/credential/base.rb +0 -27
  190. data/lib/paypal-sdk/core/credential/certificate.rb +0 -32
  191. data/lib/paypal-sdk/core/credential/signature.rb +0 -22
  192. data/lib/paypal-sdk/core/credential/third_party/subject.rb +0 -25
  193. data/lib/paypal-sdk/core/credential/third_party/token.rb +0 -39
  194. data/lib/paypal-sdk/core/credential.rb +0 -16
  195. data/lib/paypal-sdk/core/exceptions.rb +0 -112
  196. data/lib/paypal-sdk/core/logging.rb +0 -50
  197. data/lib/paypal-sdk/core/openid_connect/api.rb +0 -50
  198. data/lib/paypal-sdk/core/openid_connect/data_types.rb +0 -73
  199. data/lib/paypal-sdk/core/openid_connect/get_api.rb +0 -28
  200. data/lib/paypal-sdk/core/openid_connect/request_data_type.rb +0 -52
  201. data/lib/paypal-sdk/core/openid_connect/set_api.rb +0 -36
  202. data/lib/paypal-sdk/core/openid_connect.rb +0 -140
  203. data/lib/paypal-sdk/core/util/http_helper.rb +0 -171
  204. data/lib/paypal-sdk/core/util/oauth_signature.rb +0 -64
  205. data/lib/paypal-sdk/core/util/ordered_hash.rb +0 -165
  206. data/lib/paypal-sdk/core/util.rb +0 -11
  207. data/lib/paypal-sdk/rest/api.rb +0 -23
  208. data/lib/paypal-sdk/rest/data_types.rb +0 -2597
  209. data/lib/paypal-sdk/rest/error_hash.rb +0 -39
  210. data/lib/paypal-sdk/rest/get_api.rb +0 -20
  211. data/lib/paypal-sdk/rest/request_data_type.rb +0 -53
  212. data/lib/paypal-sdk/rest/set_api.rb +0 -42
  213. data/lib/paypal-sdk/rest/version.rb +0 -7
  214. data/lib/paypal-sdk/rest.rb +0 -39
  215. data/lib/paypal-sdk-core.rb +0 -38
  216. data/lib/paypal-sdk-rest.rb +0 -2
  217. data/spec/README.md +0 -22
  218. data/spec/config/cacert.pem +0 -171
  219. data/spec/config/cert_key.pem +0 -33
  220. data/spec/config/paypal.yml +0 -35
  221. data/spec/config/sample_data.yml +0 -3
  222. data/spec/core/api/data_type_spec.rb +0 -289
  223. data/spec/core/api/rest_spec.rb +0 -211
  224. data/spec/core/config_spec.rb +0 -192
  225. data/spec/core/logging_spec.rb +0 -28
  226. data/spec/core/openid_connect_spec.rb +0 -153
  227. data/spec/invoice_examples_spec.rb +0 -38
  228. data/spec/payments_examples_spec.rb +0 -437
  229. data/spec/payouts_examples_spec.rb +0 -74
  230. data/spec/rest/data_types_spec.rb +0 -62
  231. data/spec/rest/error_hash_spec.rb +0 -83
  232. data/spec/subscription_examples_spec.rb +0 -227
  233. data/spec/support/sample_data.rb +0 -5
  234. data/spec/web_profile_examples_spec.rb +0 -106
  235. data/spec/webhooks_examples_spec.rb +0 -93
@@ -1,32 +0,0 @@
1
- module PayPal::SDK::Core
2
- module Credential
3
-
4
- # Certificate class for SSL Certificate authentication
5
- class Certificate < Base
6
-
7
- attr_reader :cert_path
8
-
9
- def initialize(config)
10
- super
11
- @cert_path = config.cert_path
12
- end
13
-
14
- # Return SSL certificate
15
- def cert
16
- @cert ||= OpenSSL::X509::Certificate.new(cert_content)
17
- end
18
-
19
- # Return SSL certificate key
20
- def key
21
- @key = OpenSSL::PKey::RSA.new(cert_content)
22
- end
23
-
24
- private
25
- # Return certificate content from the configured file.
26
- def cert_content
27
- @cert_content ||= File.read(cert_path)
28
- end
29
-
30
- end
31
- end
32
- end
@@ -1,22 +0,0 @@
1
- module PayPal::SDK::Core
2
- module Credential
3
- class Signature < Base
4
-
5
- attr_accessor :signature
6
-
7
- # Initialize configuration
8
- # === Argument
9
- # * <tt>config</tt> -- Configuration object
10
- def initialize(config)
11
- super
12
- self.signature = config.signature
13
- end
14
-
15
- # Return properties for authentication
16
- def properties
17
- super.merge({ :signature => signature })
18
- end
19
-
20
- end
21
- end
22
- end
@@ -1,25 +0,0 @@
1
- module PayPal::SDK::Core
2
- module Credential
3
- module ThirdParty
4
- class Subject
5
-
6
- attr_accessor :subject, :credential
7
-
8
- # Initialize configuration
9
- # === Arguments
10
- # * <tt>credential</tt> -- Credential object
11
- # * <tt>config</tt> -- Configuration object
12
- def initialize(credential, config)
13
- @credential = credential
14
- @subject = config.subject
15
- end
16
-
17
- # Return properties for authentication.
18
- def properties
19
- credential.properties.merge( :subject => subject )
20
- end
21
-
22
- end
23
- end
24
- end
25
- end
@@ -1,39 +0,0 @@
1
- module PayPal::SDK::Core
2
- module Credential
3
- module ThirdParty
4
- class Token
5
-
6
- attr_accessor :token, :token_secret, :credential, :url
7
-
8
- # Initialize Token credentials
9
- # === Arguments
10
- # * <tt>credential</tt> -- Credential Object
11
- # * <tt>config</tt> -- Configuration object
12
- # * <tt>url</tt> -- Request url
13
- def initialize(credential, config, url)
14
- @credential = credential
15
- @token = config.token
16
- @token_secret = config.token_secret
17
- @url = url
18
- end
19
-
20
- RemoveProperties = [ :username, :password, :signature ]
21
-
22
- # Return credential properties for authentication.
23
- def properties
24
- credential_properties = credential.properties
25
- credential_properties.delete_if{|k,v| RemoveProperties.include? k }
26
- credential_properties.merge( :authorization => oauth_authentication )
27
- end
28
-
29
- private
30
- # Return OAuth authentication string.
31
- def oauth_authentication
32
- Util::OauthSignature.new(credential.username, credential.password, token, token_secret, url).
33
- authorization_string
34
- end
35
-
36
- end
37
- end
38
- end
39
- end
@@ -1,16 +0,0 @@
1
- module PayPal
2
- module SDK
3
- module Core
4
- module Credential
5
- autoload :Base, "paypal-sdk/core/credential/base"
6
- autoload :Certificate, "paypal-sdk/core/credential/certificate"
7
- autoload :Signature, "paypal-sdk/core/credential/signature"
8
-
9
- module ThirdParty
10
- autoload :Token, "paypal-sdk/core/credential/third_party/token"
11
- autoload :Subject, "paypal-sdk/core/credential/third_party/subject"
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,112 +0,0 @@
1
- require 'json'
2
- require 'pp'
3
-
4
- module PayPal::SDK::Core
5
- module Exceptions
6
- class ConnectionError < StandardError # :nodoc:
7
- attr_reader :response
8
-
9
- def initialize(response, message = nil)
10
- @response = response
11
- @message = message
12
- end
13
-
14
- def to_s
15
- begin
16
- response_body = JSON.parse(response.body)
17
- debug_id = response["paypal-debug-id"]
18
- debug_id = response["correlation-id"] if debug_id.to_s == ''
19
- debug_id = response_body["debug_id"] if debug_id.to_s == ''
20
- rescue
21
- end
22
- message = "Failed."
23
- message << " Response code = #{response.code}." if response.respond_to?(:code)
24
- message << " Response message = #{response.message}." if response.respond_to?(:message)
25
- message << " Response debug ID = #{debug_id}." if debug_id
26
- message
27
- end
28
- end
29
-
30
- # Raised when a Timeout::Error occurs.
31
- class TimeoutError < ConnectionError
32
- def initialize(message)
33
- @message = message
34
- end
35
- def to_s; @message ;end
36
- end
37
-
38
- # Raised when a OpenSSL::SSL::SSLError occurs.
39
- class SSLError < ConnectionError
40
- def initialize(message)
41
- @message = message
42
- end
43
- def to_s; @message ;end
44
- end
45
-
46
- # 3xx Redirection
47
- class Redirection < ConnectionError # :nodoc:
48
- def to_s
49
- response['Location'] ? "#{super} => #{response['Location']}" : super
50
- end
51
- end
52
-
53
- class MissingParam < ArgumentError # :nodoc:
54
- end
55
-
56
- class MissingConfig < StandardError # :nodoc:
57
- end
58
-
59
- # 4xx Client Error
60
- class ClientError < ConnectionError # :nodoc:
61
- end
62
-
63
- # 400 Bad Request
64
- class BadRequest < ClientError # :nodoc:
65
- end
66
-
67
- # 401 Unauthorized
68
- class UnauthorizedAccess < ClientError # :nodoc:
69
- end
70
-
71
- # 403 Forbidden
72
- class ForbiddenAccess < ClientError # :nodoc:
73
- end
74
-
75
- # 404 Not Found
76
- class ResourceNotFound < ClientError # :nodoc:
77
- end
78
-
79
- # 409 Conflict
80
- class ResourceConflict < ClientError # :nodoc:
81
- end
82
-
83
- # 410 Gone
84
- class ResourceGone < ClientError # :nodoc:
85
- end
86
-
87
- # 422 Unprocessable Entity
88
- class ResourceInvalid < ClientError # :nodoc:
89
- end
90
-
91
- # 5xx Server Error
92
- class ServerError < ConnectionError # :nodoc:
93
- end
94
-
95
- # 405 Method Not Allowed
96
- class MethodNotAllowed < ClientError # :nodoc:
97
- def allowed_methods
98
- @response['Allow'].split(',').map { |verb| verb.strip.downcase.to_sym }
99
- end
100
- end
101
-
102
- # API error: returned as 200 + "error" key in response.
103
- class UnsuccessfulApiCall < RuntimeError
104
- attr_reader :api_error
105
-
106
- def initialize(api_error)
107
- super(api_error['message'])
108
- @api_error = api_error
109
- end
110
- end
111
- end
112
- end
@@ -1,50 +0,0 @@
1
- require 'logger'
2
-
3
- module PayPal::SDK::Core
4
-
5
- # Include Logging module to provide logger functionality.
6
- # == Configure logger
7
- # Logging.logger = Logger.new(STDERR)
8
- #
9
- # == Example
10
- # include Logger
11
- # logger.info "Debug message"
12
- module Logging
13
-
14
- # Get logger object
15
- def logger
16
- @logger ||= Logging.logger
17
- end
18
-
19
- def log_event(message, &block)
20
- start_time = Time.now
21
- block.call
22
- ensure
23
- logger.info sprintf("[%.3fs] %s", Time.now - start_time, message)
24
- end
25
-
26
- class << self
27
-
28
- # Get or Create configured logger based on the default environment configuration
29
- def logger
30
- @logger ||= Logger.new(STDERR)
31
- end
32
-
33
- # Set logger directly and clear the loggers cache.
34
- # === Attributes
35
- # * <tt>logger</tt> -- Logger object
36
- # === Example
37
- # Logging.logger = Logger.new(STDERR)
38
- def logger=(logger)
39
- @logger = logger
40
- if Config.config.mode.eql? 'live' and @logger.level == Logger::DEBUG
41
- @logger.warn "DEBUG log level not allowed in sandbox mode for security of confidential information. Changing log level to INFO..."
42
- @logger.level = Logger::INFO
43
- end
44
- end
45
-
46
- end
47
- end
48
-
49
- end
50
-
@@ -1,50 +0,0 @@
1
- require 'multi_json'
2
- require 'paypal-sdk/rest/version'
3
-
4
- module PayPal::SDK
5
- module Core
6
- module OpenIDConnect
7
- class API < Core::API::Base
8
-
9
- DEFAULT_OPENID_ENDPOINT = {
10
- :sandbox => "https://api.sandbox.paypal.com",
11
- :live => "https://api.paypal.com" }
12
-
13
- def initialize(environment = nil, options = {})
14
- super("", environment, options)
15
- end
16
-
17
- def service_endpoint
18
- self.config.openid_endpoint || DEFAULT_OPENID_ENDPOINT[self.api_mode] || DEFAULT_OPENID_ENDPOINT[:sandbox]
19
- end
20
-
21
- def format_request(payload)
22
- payload[:uri].path = url_join(payload[:uri].path, payload[:action])
23
- payload[:body] = encode_www_form(payload[:params]) if payload[:params]
24
- payload[:header] = {"Content-Type" => "application/x-www-form-urlencoded" }.merge(payload[:header])
25
- payload
26
- end
27
-
28
- def format_response(payload)
29
- payload[:data] =
30
- if payload[:response].code >= "200" and payload[:response].code <= "299"
31
- MultiJson.load(payload[:response].body)
32
- elsif payload[:response].content_type == "application/json"
33
- { "error" => MultiJson.load(payload[:response].body) }
34
- else
35
- { "error" => { "name" => payload[:response].code, "message" => payload[:response].message,
36
- "developer_msg" => payload[:response] } }
37
- end
38
- payload
39
- end
40
-
41
- class << self
42
- def user_agent
43
- @user_agent ||= "PayPalSDK/openid-connect-ruby #{PayPal::SDK::REST::VERSION} (#{sdk_library_details})"
44
- end
45
- end
46
-
47
- end
48
- end
49
- end
50
- end
@@ -1,73 +0,0 @@
1
- require 'paypal-sdk-core'
2
-
3
- module PayPal::SDK::Core
4
- module OpenIDConnect
5
- module DataTypes
6
- class Base < PayPal::SDK::Core::API::DataTypes::Base
7
- end
8
-
9
- class Address < Base
10
- def self.load_members
11
- object_of :street_address, String
12
- object_of :locality, String
13
- object_of :region, String
14
- object_of :postal_code, String
15
- object_of :country, String
16
- end
17
- end
18
-
19
- class Userinfo < Base
20
- def self.load_members
21
- object_of :user_id, String
22
- object_of :sub, String
23
- object_of :name, String
24
- object_of :given_name, String
25
- object_of :family_name, String
26
- object_of :middle_name, String
27
- object_of :picture, String
28
- object_of :email, String
29
- object_of :email_verified, Boolean
30
- object_of :gender, String
31
- object_of :birthday, String
32
- object_of :zoneinfo, String
33
- object_of :locale, String
34
- object_of :language, String
35
- object_of :verified, Boolean
36
- object_of :phone_number, String
37
- object_of :address, Address
38
- object_of :verified_account, Boolean
39
- object_of :account_type, String
40
- object_of :account_creation_date, String
41
- object_of :age_range, String
42
- object_of :payer_id, String
43
- end
44
- end
45
-
46
- class Tokeninfo < Base
47
- def self.load_members
48
- object_of :scope, String
49
- object_of :access_token, String
50
- object_of :refresh_token, String
51
- object_of :token_type, String
52
- object_of :id_token, String
53
- object_of :expires_in, Integer
54
- end
55
- end
56
-
57
- class Error < Base
58
- def self.load_members
59
- object_of :error, String
60
- object_of :error_description, String
61
- object_of :error_uri, String
62
- end
63
- end
64
-
65
-
66
- constants.each do |data_type_klass|
67
- data_type_klass = const_get(data_type_klass)
68
- data_type_klass.load_members if defined? data_type_klass.load_members
69
- end
70
-
71
- end
72
- end
73
- end
@@ -1,28 +0,0 @@
1
- module PayPal::SDK
2
- module Core
3
- module OpenIDConnect
4
- module GetAPI
5
- # Get API object
6
- # === Example
7
- # Payment.api
8
- # payment.api
9
- def api
10
- @api || parent_api
11
- end
12
-
13
- # Parent API object
14
- def parent_api
15
- superclass.respond_to?(:api) ? superclass.api : RequestDataType.api
16
- end
17
-
18
- def client_id
19
- api.config.openid_client_id || api.config.client_id
20
- end
21
-
22
- def client_secret
23
- api.config.openid_client_secret || api.config.client_secret
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,52 +0,0 @@
1
- module PayPal::SDK
2
- module Core
3
- module OpenIDConnect
4
- module RequestDataType
5
-
6
- # Get a local API object or Class level API object
7
- def api
8
- @api || self.class.api
9
- end
10
-
11
- class << self
12
- # Global API object
13
- # === Example
14
- # RequestDataType.api
15
- def api
16
- @api ||= API.new({})
17
- end
18
-
19
- def client_id
20
- api.config.openid_client_id || api.config.client_id
21
- end
22
-
23
- def client_secret
24
- api.config.openid_client_secret || api.config.client_secret
25
- end
26
-
27
- # Setter for RequestDataType.api
28
- # === Example
29
- # RequestDataType.set_config(..)
30
- include SetAPI
31
-
32
- # Configure depended module, when RequestDataType is include.
33
- # === Example
34
- # class Payment < DataTypes
35
- # include RequestDataType
36
- # end
37
- # Payment.set_config(..)
38
- # payment.set_config(..)
39
- # Payment.api
40
- # payment.api
41
- def included(klass)
42
- klass.class_eval do
43
- extend GetAPI
44
- extend SetAPI
45
- include SetAPI
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,36 +0,0 @@
1
- module PayPal::SDK
2
- module Core
3
- module OpenIDConnect
4
- module SetAPI
5
- # Set new api
6
- # === Examples
7
- # payment.set_config(:development)
8
- # payment.set_config(:client_id => "XYZ", :client_secret => "SECRET")
9
- # payment.set_config
10
- # payment.api = API.new(:development)
11
- def set_config(*args)
12
- if args[0].is_a?(API)
13
- @api = args[0]
14
- else
15
- @api ||= API.new({})
16
- @api.set_config(*args) # Just override the configuration and Not
17
- @api
18
- end
19
- end
20
- alias_method :config=, :set_config
21
- alias_method :set_api, :set_config
22
- alias_method :api=, :set_config
23
-
24
- # Override client id
25
- def client_id=(client_id)
26
- set_config(:client_id => client_id)
27
- end
28
-
29
- # Override client secret
30
- def client_secret=(client_secret)
31
- set_config(:client_secret => client_secret)
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,140 +0,0 @@
1
-
2
- module PayPal::SDK
3
- module Core
4
- module OpenIDConnect
5
- autoload :API, "paypal-sdk/core/openid_connect/api"
6
- autoload :SetAPI, "paypal-sdk/core/openid_connect/set_api"
7
- autoload :GetAPI, "paypal-sdk/core/openid_connect/get_api"
8
- autoload :RequestDataType, "paypal-sdk/core/openid_connect/request_data_type"
9
- autoload :DataTypes, "paypal-sdk/core/openid_connect/data_types"
10
-
11
- include DataTypes
12
-
13
- class << self
14
- def api
15
- RequestDataType.api
16
- end
17
-
18
- def set_config(*args)
19
- RequestDataType.set_config(*args)
20
- end
21
- alias_method :config=, :set_config
22
-
23
- AUTHORIZATION_URL = "paypal.com/signin/authorize"
24
- ENDSESSION_URL = "paypal.com/webapps/auth/protocol/openidconnect/v1/endsession"
25
- DEFAULT_SCOPE = "openid"
26
-
27
- def authorize_url(params = {})
28
- uri = URI(url_for_mode(AUTHORIZATION_URL))
29
- uri.query = api.encode_www_form({
30
- :response_type => "code",
31
- :scope => DEFAULT_SCOPE,
32
- :client_id => RequestDataType.client_id,
33
- :redirect_uri => api.config.openid_redirect_uri
34
- }.merge(params))
35
- uri.to_s
36
- end
37
-
38
- def logout_url(params = {})
39
- uri = URI(url_for_mode(ENDSESSION_URL))
40
- uri.query = api.encode_www_form({
41
- :logout => "true",
42
- :redirect_uri => api.config.openid_redirect_uri
43
- }.merge(params))
44
- uri.to_s
45
- end
46
-
47
- private
48
-
49
- def url_for_mode(url)
50
- "https://www.#{"sandbox." if api.api_mode == :sandbox}#{url}"
51
- end
52
- end
53
-
54
- module DataTypes
55
- class Tokeninfo < Base
56
- include RequestDataType
57
- PATH = "v1/identity/openidconnect/tokenservice"
58
- FP_PATH = "v1/oauth2/token"
59
-
60
- class << self
61
-
62
- def basic_auth_header(options)
63
- credentials = options[:client_id].to_s + ":" + options[:client_secret].to_s
64
- encoded = Base64.encode64(credentials.force_encoding('UTF-8')).gsub!(/\n/, "")
65
- "Basic #{encoded}"
66
- end
67
-
68
- def create_from_authorization_code(options, http_header = {})
69
- options = { :code => options } if options.is_a? String
70
- options = options.merge( :grant_type => "authorization_code" )
71
- Tokeninfo.new(api.post(PATH, with_credentials(options), http_header))
72
- end
73
- alias_method :create, :create_from_authorization_code
74
-
75
- def create_from_refresh_token(options, http_header = {})
76
- options = { :refresh_token => options } if options.is_a? String
77
- options = options.merge( :grant_type => "refresh_token" )
78
- http_header = http_header.merge( { "Content-Type" => "application/x-www-form-urlencoded", "Authorization" => basic_auth_header(with_credentials(options)) } )
79
- Tokeninfo.new(api.post(PATH, options, http_header))
80
- end
81
- alias_method :refresh, :create_from_refresh_token
82
-
83
- def create_from_future_payment_auth_code(options, http_header = {})
84
- options = { :code => options } if options.is_a? String
85
- options = options.merge( { :grant_type => "authorization_code", :response_type => "token", :redirect_uri => "urn:ietf:wg:oauth:2.0:oob" } )
86
- http_header = http_header.merge( { "Content-Type" => "application/x-www-form-urlencoded", "Authorization" => basic_auth_header(with_credentials(options)) } )
87
- Tokeninfo.new(api.post(FP_PATH, options, http_header))
88
- end
89
- alias_method :token_hash, :create_from_future_payment_auth_code
90
- alias_method :create_fp, :create_from_future_payment_auth_code
91
-
92
- def with_credentials(options = {})
93
- options = options.dup
94
- [ :client_id, :client_secret ].each do |key|
95
- options[key] = self.send(key) unless options[key] or options[key.to_s]
96
- end
97
- options
98
- end
99
-
100
- def authorize_url(options = {})
101
- OpenIDConnect.authorize_url(options)
102
- end
103
- end
104
-
105
- def refresh(options = {})
106
- tokeninfo = self.class.refresh({
107
- :refresh_token => self.refresh_token}.merge(options))
108
- self.merge!(tokeninfo.to_hash)
109
- end
110
-
111
- def userinfo(options = {})
112
- Userinfo.get({ :access_token => self.access_token }.merge(options))
113
- end
114
-
115
- def logout_url(options = {})
116
- OpenIDConnect.logout_url({ :id_token => self.id_token }.merge(options))
117
- end
118
-
119
- end
120
-
121
- class Userinfo < Base
122
- include RequestDataType
123
- PATH = "v1/identity/openidconnect/userinfo"
124
-
125
- class << self
126
- def get_userinfo(options = {}, http_header = {})
127
- options = { :access_token => options } if options.is_a? String
128
- options = options.merge( :schema => "openid" ) unless options[:schema] or options["schema"]
129
- Userinfo.new(api.post(PATH, options, http_header))
130
- end
131
- alias_method :get, :get_userinfo
132
- end
133
- end
134
- end
135
- end
136
- end
137
-
138
- # Alias for the Core::OpenIDConnect constant
139
- OpenIDConnect = Core::OpenIDConnect
140
- end