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
data/spec/spec_helper.rb CHANGED
@@ -1,37 +1,106 @@
1
- require 'bundler/setup'
2
-
3
- if ENV['COVERAGE']
4
- require 'simplecov'
5
- require 'coveralls'
6
- Coveralls.wear!
7
- SimpleCov.start do
8
- add_filter "/spec/"
1
+ require_relative "../lib/lib.rb"
2
+ require 'pp'
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
35
  end
10
- end
11
36
 
12
- Bundler.require :default, :test
13
- PayPal::SDK::Core::Config.load(File.expand_path('../config/paypal.yml', __FILE__), 'test')
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
14
45
 
15
- require 'paypal-sdk-rest'
46
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
47
+ # have no way to turn it off -- the option exists only for backwards
48
+ # compatibility in RSpec 3). It causes shared context metadata to be
49
+ # inherited by the metadata hash of host groups and examples, rather than
50
+ # triggering implicit auto-inclusion in groups with matching metadata.
51
+ config.shared_context_metadata_behavior = :apply_to_host_groups
16
52
 
17
- include PayPal::SDK::REST
18
- include PayPal::SDK::Core::Logging
53
+ # The settings below are suggested to provide a good initial experience
54
+ # with RSpec, but feel free to customize to your heart's content.
55
+ =begin
56
+ # This allows you to limit a spec run to individual examples or groups
57
+ # you care about by tagging them with `:focus` metadata. When nothing
58
+ # is tagged with `:focus`, all examples get run. RSpec also provides
59
+ # aliases for `it`, `describe`, and `context` that include `:focus`
60
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
61
+ config.filter_run_when_matching :focus
19
62
 
20
- require 'logger'
21
- PayPal::SDK.load('spec/config/paypal.yml', 'test')
22
- PayPal::SDK.logger = Logger.new(STDERR)
63
+ # Allows RSpec to persist some state between runs in order to support
64
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
65
+ # you configure your source control system to ignore this file.
66
+ config.example_status_persistence_file_path = "spec/examples.txt"
23
67
 
24
- Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f }
68
+ # Limits the available syntax to the non-monkey patched syntax that is
69
+ # recommended. For more details, see:
70
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
71
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
72
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
73
+ config.disable_monkey_patching!
25
74
 
26
- # Set logger for http
27
- http_log = File.open(File.expand_path('../log/http.log', __FILE__), "w")
28
- Payment.api.http.set_debug_output(http_log)
75
+ # This setting enables warnings. It's recommended, but in some cases may
76
+ # be too noisy due to issues in dependencies.
77
+ config.warnings = true
29
78
 
30
- RSpec.configure do |config|
31
- config.filter_run_excluding :integration => true
32
- config.filter_run_excluding :disabled => true
33
- config.include SampleData
34
- # config.include PayPal::SDK::REST::DataTypes
35
- end
79
+ # Many RSpec users commonly either run the entire suite or an individual
80
+ # file, and it's useful to allow more verbose output when running an
81
+ # individual spec file.
82
+ if config.files_to_run.one?
83
+ # Use the documentation formatter for detailed output,
84
+ # unless a formatter has already been configured
85
+ # (e.g. via a command-line flag).
86
+ config.default_formatter = 'doc'
87
+ end
88
+
89
+ # Print the 10 slowest examples and example groups at the
90
+ # end of the spec run, to help surface which specs are running
91
+ # particularly slow.
92
+ config.profile_examples = 10
36
93
 
37
- WebMock.allow_net_connect!
94
+ # Run specs in random order to surface order dependencies. If you find an
95
+ # order dependency and want to debug it, you can fix the order by providing
96
+ # the seed, which is printed after each run.
97
+ # --seed 1234
98
+ config.order = :random
99
+
100
+ # Seed global randomization in this process using the `--seed` CLI option.
101
+ # Setting this allows you to use `--seed` to deterministically reproduce
102
+ # test failures related to randomization by passing the same `--seed` value
103
+ # as the one that triggered the failure.
104
+ Kernel.srand config.seed
105
+ =end
106
+ end
@@ -0,0 +1,264 @@
1
+ require_relative '../../lib/paypal/core/version'
2
+ require 'webmock/rspec'
3
+
4
+ include WebMock::API
5
+
6
+ describe PayPal::PayPalHttpClient do
7
+ before do
8
+ WebMock.disable!
9
+ @environment = PayPal::SandboxEnvironment.new('clientId', 'clientSecret')
10
+ @httpClient = PayPal::PayPalHttpClient.new(@environment)
11
+ end
12
+
13
+ # Helpers
14
+ def stubAccessToken
15
+ access_token_json = JSON.generate({
16
+ :access_token => "simple-access-token",
17
+ :expires_in => 3600,
18
+ :token_type => 'Bearer',
19
+ })
20
+
21
+ stub_request(:any, @environment.base_url + "/v1/oauth2/token").
22
+ to_return(body: access_token_json, status: 200,
23
+ headers: {'content-type' => "application/json"})
24
+ end
25
+
26
+ def stubRefreshToken
27
+ access_token_json = JSON.generate({
28
+ :access_token => "refresh-access-token",
29
+ :expires_in => 3600,
30
+ :token_type => 'Bearer',
31
+ })
32
+
33
+ stub_request(:any, @environment.base_url + "/v1/oauth2/token")
34
+ .to_return(body: access_token_json, status: 200, headers: {'content-type' => "application/json"})
35
+ end
36
+
37
+ describe 'execute' do
38
+ before(:each) do
39
+ WebMock.enable!
40
+ end
41
+
42
+ it 'fetches access token if not yet fetched' do
43
+ access_token_stub = stubAccessToken
44
+
45
+ return_json = JSON.generate({
46
+ :some_key => "some_value",
47
+ })
48
+
49
+ stub_request(:get, @environment.base_url + "/path")
50
+ .to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
51
+
52
+ req = OpenStruct.new({:verb => "GET", :path => "/path"})
53
+
54
+ resp = @httpClient.execute(req)
55
+
56
+ expect(resp.status_code).to eq(200)
57
+ expect(resp.result.some_key).to eq("some_value")
58
+ assert_requested(access_token_stub)
59
+ end
60
+
61
+ it 'does not fetch access token if not expired and valid' do
62
+ access_token_stub = stubAccessToken
63
+
64
+ return_json = JSON.generate({
65
+ :some_key => "some_value",
66
+ })
67
+
68
+ response_stub = stub_request(:any, @environment.base_url)
69
+ .to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
70
+
71
+ req = OpenStruct.new({:verb => "GET", :path => "/"})
72
+
73
+ resp = @httpClient.execute(req)
74
+
75
+ expect(resp.status_code).to eq(200)
76
+ expect(resp.result[:some_key]).to eq("some_value")
77
+
78
+ resp = @httpClient.execute(req)
79
+
80
+ assert_requested(access_token_stub, times: 1)
81
+ assert_requested(response_stub, times: 2)
82
+ end
83
+
84
+ it 'fetches access token if expired' do
85
+ expired_access_token_json = JSON.generate({
86
+ :access_token => "expired-access-token",
87
+ :expires_in => -1,
88
+ :token_type => 'Bearer',
89
+ })
90
+
91
+ access_token_json = JSON.generate({
92
+ :access_token => "simple-access-token",
93
+ :expires_in => 3600,
94
+ :token_type => 'Bearer',
95
+ })
96
+
97
+ access_token_stub = stub_request(:any, @environment.base_url + "/v1/oauth2/token")
98
+ .to_return(body: expired_access_token_json, status: 200, headers: {'content-type' => "application/json"})
99
+ .times(1)
100
+ .then
101
+ .to_return(body: access_token_json, status: 200, headers: {'content-type' => "application/json"})
102
+
103
+ return_json = JSON.generate({
104
+ :some_key => "some_value",
105
+ })
106
+
107
+ response_stub = stub_request(:any, @environment.base_url)
108
+ .to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
109
+
110
+ req = OpenStruct.new({:verb => "GET", :path => "/"})
111
+
112
+ resp = @httpClient.execute(req)
113
+
114
+ expect(resp.status_code).to eq(200)
115
+ expect(resp.result[:some_key]).to eq("some_value")
116
+
117
+ resp = @httpClient.execute(req)
118
+
119
+ assert_requested(access_token_stub, times: 2)
120
+ assert_requested(response_stub, times: 2)
121
+ end
122
+
123
+ it 'fetches access token with refresh token not yet fetched' do
124
+ @httpClient = PayPal::PayPalHttpClient.new(@environment, "refresh-token")
125
+ refresh_token_stub = stubRefreshToken
126
+
127
+ return_json = JSON.generate({
128
+ :some_key => "some_value",
129
+ })
130
+
131
+ stub_request(:any, @environment.base_url)
132
+ .to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
133
+
134
+ req = OpenStruct.new({:verb => "GET", :path => "/"})
135
+
136
+ resp = @httpClient.execute(req)
137
+
138
+ expect(resp.status_code).to eq(200)
139
+ expect(resp.result[:some_key]).to eq("some_value")
140
+ assert_requested(refresh_token_stub)
141
+ end
142
+
143
+ it 'fetches access token with refresh token if expired' do
144
+ @httpClient = PayPal::PayPalHttpClient.new(@environment, "refresh-token")
145
+
146
+ expired_access_token_json = JSON.generate({
147
+ :access_token => "expired-access-token",
148
+ :expires_in => -1,
149
+ :token_type => 'Bearer',
150
+ })
151
+
152
+ access_token_json = JSON.generate({
153
+ :access_token => "refresh-access-token",
154
+ :expires_in => 3600,
155
+ :token_type => 'Bearer',
156
+ })
157
+
158
+ access_token_stub = stub_request(:any, @environment.base_url + "/v1/oauth2/token")
159
+ .to_return(body: expired_access_token_json, status: 200, headers: {'content-type' => "application/json"})
160
+ .times(1)
161
+ .then
162
+ .to_return(body: access_token_json, status: 200, headers: {'content-type' => "application/json"})
163
+
164
+ return_json = JSON.generate({
165
+ :some_key => "some_value",
166
+ })
167
+
168
+ response_stub = stub_request(:any, @environment.base_url)
169
+ .to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
170
+
171
+ req = OpenStruct.new({:verb => "GET", :path => "/"})
172
+
173
+ resp = @httpClient.execute(req)
174
+
175
+ expect(resp.status_code).to eq(200)
176
+ expect(resp.result[:some_key]).to eq("some_value")
177
+
178
+ resp = @httpClient.execute(req)
179
+
180
+ assert_requested(access_token_stub, times: 2)
181
+ assert_requested(response_stub, times: 2)
182
+ end
183
+
184
+ it 'does not fetch access token if authorization header already present' do
185
+ @httpClient = PayPal::PayPalHttpClient.new(@environment)
186
+
187
+ return_json = JSON.generate({
188
+ :some_key => "some_value",
189
+ })
190
+
191
+ stub_request(:get, @environment.base_url + "/path")
192
+ .to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
193
+
194
+ req = OpenStruct.new({:verb => "GET", :path => "/path", :headers => {'Authorization' => 'custom-header-value'}})
195
+
196
+ resp = @httpClient.execute(req)
197
+
198
+ expect(resp.status_code).to eq(200)
199
+ expect(resp.result[:some_key]).to eq("some_value")
200
+
201
+ expect(WebMock).to have_requested(:get, @environment.base_url + '/path')
202
+ .with(headers: {'Authorization' => "custom-header-value"})
203
+ end
204
+
205
+ it 'sets Authorization header with access token value' do
206
+ access_token_stub = stubAccessToken
207
+
208
+ return_json = JSON.generate({
209
+ :some_key => "some_value",
210
+ })
211
+
212
+ stub_request(:get, @environment.base_url + "/path")
213
+ .to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
214
+
215
+ req = OpenStruct.new({:verb => "GET", :path => "/path"})
216
+
217
+ resp = @httpClient.execute(req)
218
+
219
+ expect(resp.status_code).to eq(200)
220
+ expect(resp.result.some_key).to eq("some_value")
221
+ assert_requested(access_token_stub)
222
+
223
+ expect(WebMock).to have_requested(:get, @environment.base_url + '/path')
224
+ .with(headers: {'Authorization' => "Bearer simple-access-token"})
225
+ end
226
+
227
+ it 'sets User-Agent header properly' do
228
+ access_token_stub = stubAccessToken
229
+
230
+ return_json = JSON.generate({
231
+ :some_key => "some_value",
232
+ })
233
+
234
+ request_stub = stub_request(:any, @environment.base_url)
235
+ .to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
236
+
237
+ resp = @httpClient.execute(OpenStruct.new({:verb => "GET", :path => "/"}))
238
+
239
+ user_agent_regex = /^PayPalSDK\/rest-sdk-ruby #{PayPal::VERSION} \(paypal-sdk-core .*; ruby [\d\.?]*p\d+-.*;OpenSSL.*\)$/
240
+ expect(WebMock).to have_requested(:get, @environment.base_url)
241
+ .with(headers: {'User-Agent' => user_agent_regex})
242
+ end
243
+
244
+ it 'sets Accept-Encoding header to gzip' do
245
+ access_token_stub = stubAccessToken
246
+
247
+ return_json = JSON.generate({
248
+ :some_key => "some_value",
249
+ })
250
+
251
+ request_stub = stub_request(:any, @environment.base_url)
252
+ .to_return(body: return_json, status: 200, headers: {'content-type' => "application/json"})
253
+
254
+ req = OpenStruct.new({:verb => "GET", :path => "/"})
255
+
256
+ resp = @httpClient.execute(req)
257
+
258
+ expect(resp.status_code).to eq(200)
259
+ expect(resp.result[:some_key]).to eq("some_value")
260
+ expect(WebMock).to have_requested(:get, @environment.base_url)
261
+ .with(headers: {'Accept-Encoding' => 'gzip'})
262
+ end
263
+ end
264
+ end