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
@@ -0,0 +1,12 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './plan_helper'
3
+
4
+ include PayPal::V1::BillingPlans
5
+
6
+ describe PlanCreateRequest do
7
+ it 'successfully makes a request' do
8
+ resp = PlanHelper::create_plan
9
+ expect(resp.status_code).to eq(201)
10
+ expect(resp.result).not_to be_nil
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './plan_helper'
3
+
4
+ include PayPal::V1::BillingPlans
5
+
6
+ describe PlanGetRequest do
7
+ it 'successfully makes a request' do
8
+ create_response = PlanHelper::create_plan
9
+
10
+ get_response = PlanHelper::get_plan(create_response.result.id)
11
+
12
+ expect(get_response.status_code).to eq(200)
13
+ expect(get_response.result).not_to be_nil
14
+ expect(get_response.result.id).to eq(create_response.result.id)
15
+ end
16
+ end
@@ -0,0 +1,71 @@
1
+ require_relative '../../test_harness'
2
+
3
+ include PayPal::V1::BillingPlans
4
+
5
+ module PlanHelper
6
+ class << self
7
+ def activate_plan(plan_id)
8
+ request_body = [
9
+ {
10
+ :op => 'replace',
11
+ :path => '/',
12
+ :value => {
13
+ :state => 'ACTIVE',
14
+ },
15
+ },
16
+ ]
17
+
18
+ activate_request = PlanUpdateRequest.new(plan_id)
19
+ activate_request.request_body(request_body)
20
+
21
+ TestHarness::client.execute(activate_request)
22
+ end
23
+
24
+ def create_plan
25
+ request_body = {
26
+ "payment_definitions": [{
27
+ "amount": {
28
+ "value": "100",
29
+ "currency": "USD",
30
+ },
31
+ "frequency": "MONTH",
32
+ "cycles": "12",
33
+ "frequency_interval": "2",
34
+ "type": "REGULAR",
35
+ "name": "Regular Payments",
36
+ "charge_models": [{
37
+ "type": "SHIPPING",
38
+ "amount": {
39
+ "value": "10",
40
+ "currency": "USD",
41
+ },
42
+ }, {
43
+ "type": "TAX",
44
+ "amount": {
45
+ "value": "12",
46
+ "currency": "USD",
47
+ },
48
+ }],
49
+ }],
50
+ "merchant_preferences": {
51
+ "return_url": "http://localhost:3000/subscription/success",
52
+ "cancel_url": "http://localhost:3000/subscription/cancel",
53
+ },
54
+ "name": "T-Shirt of the Month Club Plan",
55
+ "description": "Template creation.",
56
+ "type": "fixed",
57
+ }
58
+
59
+ request = PlanCreateRequest.new()
60
+ request.request_body(request_body)
61
+
62
+ TestHarness::client.execute(request)
63
+ end
64
+
65
+ def get_plan(plan_id)
66
+ request = PlanGetRequest.new(plan_id)
67
+
68
+ TestHarness::client.execute(request)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,16 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './plan_helper'
3
+
4
+ include PayPal::V1::BillingPlans
5
+
6
+ describe PlanListRequest do
7
+ it 'successfully makes a request' do
8
+ PlanHelper::create_plan
9
+
10
+ request = PlanListRequest.new()
11
+
12
+ resp = TestHarness::client.execute(request)
13
+ expect(resp.status_code).to eq(200)
14
+ expect(resp.result).not_to be_nil
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './plan_helper'
3
+
4
+ include PayPal::V1::BillingPlans
5
+
6
+ describe PlanUpdateRequest do
7
+ it 'successfully makes a request' do
8
+ create_response = PlanHelper::create_plan
9
+ plan_id = create_response.result.id
10
+
11
+ activate_response = PlanHelper::activate_plan(plan_id)
12
+
13
+ expect(activate_response.status_code).to eq(200)
14
+
15
+ get_response = PlanHelper::get_plan(plan_id)
16
+
17
+ expect(get_response.result.state).to eq('ACTIVE')
18
+ end
19
+ end
@@ -0,0 +1,65 @@
1
+ require_relative '../../test_harness'
2
+ require 'uri'
3
+ require 'cgi'
4
+
5
+ include PayPal::V1::Identity
6
+
7
+ describe UserinfoGetRequest do
8
+
9
+ it 'builds user consent url' do
10
+ builder = UserConsent.new(TestHarness::environment)
11
+ builder.response_type('code')
12
+ builder.scope('profile+email+openid+address')
13
+ builder.redirect_uri('http://example.com')
14
+ builder.state('some-state')
15
+ builder.nonce('some-nonce')
16
+
17
+ url = builder.build
18
+
19
+ parsed = URI(url)
20
+
21
+ expect(parsed.scheme).to eq('https')
22
+ expect(parsed.host).to eq('sandbox.paypal.com')
23
+ expect(parsed.path).to eq('/signin/authorize')
24
+
25
+ query = CGI::parse(parsed.query)
26
+ expect(query['response_type'][0]).to eq('code')
27
+ expect(query['scope'][0]).to eq('profile email openid address')
28
+ expect(query['redirect_uri'][0]).to eq('http://example.com')
29
+ expect(query['state'][0]).to eq('some-state')
30
+ expect(query['nonce'][0]).to eq('some-nonce')
31
+ end
32
+
33
+ it 'gets refresh token from code', :skip => 'This test is an example of how to obtain user consent' do
34
+ builder = UserConsent.new(TestHarness::environment)
35
+ builder.redirect_uri(CGI::escape('http://requestbin.fullcontact.com/15a7bhu1'))
36
+ builder.response_type('code')
37
+ builder.scope('profile+email+openid+address')
38
+
39
+ url = builder.build
40
+
41
+ # Fetched from visiting the `url` and signing in w/ PayPal account
42
+ code = 'C21AAHkGGpGk-g8ZbMuKwTtisc6mkv18Tplrvu9RZR-_zmNQS0xthson09WpKA8vYi4G7ESo3fu694FXm3sxVRclBwg24b1MA'
43
+
44
+ environment = TestHarness::environment
45
+ refresh_token_request = PayPal::RefreshTokenRequest.new(environment, code)
46
+ token_response = TestHarness::exec(refresh_token_request)
47
+
48
+ expect(token_response.status_code).to eq(200)
49
+ expect(token_response.result).not_to be_nil
50
+ end
51
+
52
+ it 'gets user info' do
53
+ # Fetched using the above example
54
+ refresh_token = 'R23AAEWf7GghkOpcrCXhiDkS2IpGPR-r_jMIez_gcTzrstXCsro0ZC2P8xEnv5lm4A8h2QXFhMhIcKI8Ak5lP8kIyZzCxqjg_JbX8QI7KJoXrbn57U19_tlfs-Z-seXHtK74OeGhJyGxfRTBLbOIw'
55
+
56
+ scoped_http_client = PayPal::PayPalHttpClient.new(TestHarness::environment, refresh_token)
57
+
58
+ request = UserinfoGetRequest.new()
59
+ request.schema('openid')
60
+
61
+ resp = scoped_http_client.execute(request)
62
+ expect(resp.status_code).to eq(200)
63
+ expect(resp.result).not_to be_nil
64
+ end
65
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+ require 'json'
4
+
5
+ include PayPal::V1::Invoices
6
+
7
+ describe InvoiceCancelRequest do
8
+ it 'successfully makes a request' do
9
+ create_response = InvoiceHelper::create_invoice
10
+ InvoiceHelper::send_invoice(create_response.result.id)
11
+
12
+ request = InvoiceCancelRequest.new(create_response.result.id)
13
+ request.request_body({
14
+ :subject => 'Past Due',
15
+ :note => 'nevermind',
16
+ :send_to_merchant => true,
17
+ :send_to_payer => true,
18
+ })
19
+
20
+ resp = TestHarness::client.execute(request)
21
+ expect(resp.status_code).to eq(204)
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+ require 'json'
4
+
5
+ include PayPal::V1::Invoices
6
+
7
+ describe InvoiceCreateRequest do
8
+ it 'successfully makes a request' do
9
+ invoice_create_response = InvoiceHelper::create_invoice
10
+
11
+ expect(invoice_create_response.status_code).to eq(201)
12
+ expect(invoice_create_response.result).not_to be_nil
13
+ expect(invoice_create_response.result.merchant_info.first_name).to eq('Dennis')
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+
4
+ include PayPal::V1::Invoices
5
+
6
+ describe InvoiceDeleteExternalPaymentRequest do
7
+ it 'successfully makes a request' do
8
+ create_response = InvoiceHelper::create_invoice
9
+ id = create_response.result.id
10
+ InvoiceHelper::record_payment(id)
11
+
12
+ get_response = InvoiceHelper::get_invoice(id)
13
+
14
+ txn_id = get_response.result.payments[0].transaction_id
15
+ request = InvoiceDeleteExternalPaymentRequest.new(id, txn_id)
16
+
17
+ resp = TestHarness::client.execute(request)
18
+ expect(resp.status_code).to eq(204)
19
+
20
+ get_response = InvoiceHelper::get_invoice(id)
21
+ expect(get_response.result.payments).to be_nil
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+
4
+ include PayPal::V1::Invoices
5
+
6
+ describe InvoiceDeleteExternalRefundRequest do
7
+ it 'successfully makes a request' do
8
+ create_response = InvoiceHelper::create_invoice
9
+ id = create_response.result.id
10
+
11
+ InvoiceHelper::record_refund(id)
12
+
13
+ get_response = InvoiceHelper::get_invoice(id)
14
+ refund_id = get_response.result.refunds[0].transaction_id
15
+
16
+ request = InvoiceDeleteExternalRefundRequest.new(id, refund_id)
17
+
18
+ resp = TestHarness::client.execute(request)
19
+ expect(resp.status_code).to eq(204)
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+ require 'json'
4
+
5
+ include PayPal::V1::Invoices
6
+
7
+ describe InvoiceDeleteRequest do
8
+ it 'successfully makes a request' do
9
+ create_response = InvoiceHelper::create_invoice
10
+
11
+ request = InvoiceDeleteRequest.new(create_response.result.id)
12
+
13
+ resp = TestHarness::client.execute(request)
14
+ expect(resp.status_code).to eq(204)
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+
4
+ include PayPal::V1::Invoices
5
+
6
+ describe InvoiceGetRequest do
7
+ it 'successfully makes a request' do
8
+ create_response = InvoiceHelper::create_invoice
9
+
10
+ request = InvoiceGetRequest.new(create_response.result.id)
11
+
12
+ resp = TestHarness::client.execute(request)
13
+ expect(resp.status_code).to eq(200)
14
+ expect(resp.result).not_to be_nil
15
+
16
+ expect(resp.result.id).to eq(create_response.result.id)
17
+ end
18
+ end
@@ -0,0 +1,171 @@
1
+ require_relative '../../test_harness'
2
+
3
+ include PayPal::V1::Invoices
4
+
5
+ module InvoiceHelper
6
+ class << self
7
+ def create_invoice
8
+ body = {
9
+ "merchant_info": {
10
+ "email": "team-dx-clients-facilitator@getbraintree.com",
11
+ "first_name": "Dennis",
12
+ "last_name": "Doctor",
13
+ "business_name": "Medical Professionals, LLC",
14
+ "phone": {
15
+ "country_code": "001",
16
+ "national_number": "5032141716",
17
+ },
18
+ "address": {
19
+ "line1": "1234 Main St.",
20
+ "city": "Portland",
21
+ "state": "OR",
22
+ "postal_code": "97217",
23
+ "country_code": "US",
24
+ },
25
+ },
26
+ "billing_info": [{
27
+ "email": "example@example.com",
28
+ }],
29
+ "items": [{
30
+ "name": "Sutures",
31
+ "quantity": 100.0,
32
+ "unit_price": {
33
+ "currency": "USD",
34
+ "value": 5,
35
+ },
36
+ }],
37
+ "note": "Medical Invoice 16 Jul, 2013 PST",
38
+ "payment_term": {
39
+ "term_type": "NET_45",
40
+ },
41
+ "shipping_info": {
42
+ "first_name": "Sally",
43
+ "last_name": "Patient",
44
+ "business_name": "Not applicable",
45
+ "phone": {
46
+ "country_code": "001",
47
+ "national_number": "5039871234",
48
+ },
49
+ "address": {
50
+ "line1": "1234 Broad St.",
51
+ "city": "Portland",
52
+ "state": "OR",
53
+ "postal_code": "97216",
54
+ "country_code": "US",
55
+ },
56
+ },
57
+ "tax_inclusive": false,
58
+ "total_amount": {
59
+ "currency": "USD",
60
+ "value": "500.00",
61
+ },
62
+ }
63
+
64
+ TestHarness::exec(InvoiceCreateRequest.new, body)
65
+ end
66
+
67
+ def get_invoice(id)
68
+ TestHarness::exec(InvoiceGetRequest.new(id))
69
+ end
70
+
71
+ def send_invoice(id)
72
+ req = InvoiceSendRequest.new(id)
73
+ req.notify_merchant(true)
74
+
75
+ TestHarness::exec(req)
76
+ end
77
+
78
+ def record_payment(id)
79
+ send_invoice(id)
80
+
81
+ request = InvoiceRecordPaymentRequest.new(id)
82
+ request.request_body({
83
+ :method => 'CASH',
84
+ :date => '2017-07-11 00:01:00 PST',
85
+ :amount => {
86
+ :value => '10',
87
+ :currency => 'USD',
88
+ },
89
+ })
90
+
91
+ TestHarness::exec(request)
92
+ end
93
+
94
+ def record_refund(id)
95
+ record_payment(id)
96
+
97
+ req = InvoiceRecordRefundRequest.new(id)
98
+ body = {
99
+ :amount => {
100
+ :value => '10',
101
+ :currency => 'USD',
102
+ },
103
+ }
104
+
105
+ TestHarness::exec(req, body)
106
+ end
107
+
108
+ def create_template
109
+ body = {
110
+ "name": "Hours Template_ruby#{Random.new.rand(1000000)}",
111
+ "default": true,
112
+ "unit_of_measure": "Hours",
113
+ "template_data": {
114
+ "items": [
115
+ {
116
+ "name": "Nutri Bullet",
117
+ "quantity": 1,
118
+ "unit_price": {
119
+ "currency": "USD",
120
+ "value": "50.00",
121
+ },
122
+ },
123
+ ],
124
+ "merchant_info": {
125
+ "email": "team-dx-clients-facilitator@getbraintree.com",
126
+ },
127
+ "tax_calculated_after_discount": false,
128
+ "tax_inclusive": false,
129
+ "note": "Thank you for your business.",
130
+ "logo_url": "https://pics.paypal.com/v1/images/redDot.jpeg",
131
+ "allow_tip": true,
132
+ },
133
+ "settings": [
134
+ {
135
+ "field_name": "items.date",
136
+ "display_preference": {
137
+ "hidden": true,
138
+ },
139
+ },
140
+ {
141
+ "field_name": "custom",
142
+ "display_preference": {
143
+ "hidden": true,
144
+ },
145
+ },
146
+ ],
147
+ }
148
+
149
+ TestHarness::exec(TemplateCreateRequest.new, body)
150
+ end
151
+
152
+ def get_template(id)
153
+ TestHarness::exec(TemplateGetRequest.new(id))
154
+ end
155
+
156
+ def delete_templates
157
+ list_resp = TestHarness::exec(TemplateListRequest.new)
158
+
159
+ puts "Deleting #{list_resp.result.templates.count} templates"
160
+
161
+ list_resp.result.templates.each do |template|
162
+ begin
163
+ TestHarness::exec(TemplateDeleteRequest.new(template.template_id))
164
+ puts "deleted #{template.template_id}"
165
+ rescue Exception => e
166
+ puts "Could not delete #{template.template_id}"
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,20 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+
4
+ include PayPal::V1::Invoices
5
+
6
+ describe InvoiceListRequest do
7
+ it 'successfully makes a request' do
8
+ InvoiceHelper::create_invoice
9
+
10
+ request = InvoiceListRequest.new
11
+ request.page(8)
12
+ request.page_size(7)
13
+ request.total_count_required(true)
14
+
15
+ resp = TestHarness::client.execute(request)
16
+ expect(resp.status_code).to eq(200)
17
+ expect(resp.result).not_to be_nil
18
+ expect(resp.result.total_count > 0).to be(true)
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require_relative '../../test_harness'
2
+ require 'json'
3
+
4
+ include PayPal::V1::Invoices
5
+
6
+ describe InvoiceNextInvoiceNumberRequest do
7
+ it 'successfully makes a request' do
8
+ request = InvoiceNextInvoiceNumberRequest.new()
9
+
10
+ resp = TestHarness::client.execute(request)
11
+ expect(resp.status_code).to eq(200)
12
+ expect(resp.result).not_to be_nil
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+
4
+ include PayPal::V1::Invoices
5
+
6
+ describe InvoiceQrCodeRequest do
7
+ it 'successfully makes a request' do
8
+ create_response = InvoiceHelper::create_invoice
9
+
10
+ request = InvoiceQrCodeRequest.new(create_response.result.id)
11
+ request.height(300)
12
+ request.width(200)
13
+
14
+ resp = TestHarness::client.execute(request)
15
+ expect(resp.status_code).to eq(200)
16
+ expect(resp.result).not_to be_nil
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+ require 'json'
4
+
5
+ include PayPal::V1::Invoices
6
+
7
+ describe InvoiceRecordPaymentRequest do
8
+ it 'successfully makes a request' do
9
+ create_response = InvoiceHelper::create_invoice
10
+ record_response = InvoiceHelper::record_payment(create_response.result.id)
11
+
12
+ expect(record_response.status_code).to eq(204)
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+ require 'json'
4
+
5
+ include PayPal::V1::Invoices
6
+
7
+ describe InvoiceRecordRefundRequest do
8
+ it 'successfully makes a request' do
9
+ create_response = InvoiceHelper::create_invoice
10
+ refund_response = InvoiceHelper::record_refund(create_response.result.id)
11
+
12
+ expect(refund_response.status_code).to eq(204)
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+
4
+ include PayPal::V1::Invoices
5
+
6
+ describe InvoiceRemindRequest do
7
+ it 'successfully makes a request' do
8
+ create_response = InvoiceHelper::create_invoice
9
+ id = create_response.result.id
10
+ InvoiceHelper::send_invoice(id)
11
+
12
+ request = InvoiceRemindRequest.new(id)
13
+ request.request_body({
14
+ :subject => 'PAST DUE',
15
+ :note => 'pony up!',
16
+ :send_to_merchant => true,
17
+ })
18
+
19
+ resp = TestHarness::client.execute(request)
20
+ expect(resp.status_code).to eq(202)
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+
4
+ include PayPal::V1::Invoices
5
+
6
+ describe InvoiceSearchRequest do
7
+ it 'successfully makes a request' do
8
+ create_response = InvoiceHelper::create_invoice
9
+
10
+ request = InvoiceSearchRequest.new()
11
+ request.request_body({
12
+ :number => create_response.result.number,
13
+ })
14
+
15
+ resp = TestHarness::client.execute(request)
16
+ expect(resp.status_code).to eq(200)
17
+ expect(resp.result).not_to be_nil
18
+ expect(resp.result.invoices[0].id).to eq(create_response.result.id)
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+ require 'json'
4
+
5
+ include PayPal::V1::Invoices
6
+
7
+ describe InvoiceSendRequest do
8
+ it 'successfully makes a request' do
9
+ create_response = InvoiceHelper::create_invoice
10
+
11
+ send_response = InvoiceHelper::send_invoice(create_response.result.id)
12
+
13
+ expect(send_response.status_code).to eq(202)
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../../test_harness'
2
+ require_relative './invoice_helper'
3
+ require 'json'
4
+
5
+ include PayPal::V1::Invoices
6
+
7
+ describe InvoiceUpdateRequest do
8
+ it 'successfully makes a request' do
9
+ create_response = InvoiceHelper::create_invoice
10
+
11
+ request = InvoiceUpdateRequest.new(create_response.result.id)
12
+ request.notify_merchant(false)
13
+ request.request_body({
14
+ :merchant_info => {
15
+ :email => 'team-dx-clients-facilitator@getbraintree.com',
16
+ },
17
+ :terms => 'Consider this invoice updated',
18
+ })
19
+
20
+ resp = TestHarness::client.execute(request)
21
+ expect(resp.status_code).to eq(200)
22
+ expect(resp.result).not_to be_nil
23
+ expect(resp.result.merchant_info.email).to eq('team-dx-clients-facilitator@getbraintree.com')
24
+ expect(resp.result.terms).to eq('Consider this invoice updated')
25
+ end
26
+ end