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,289 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PayPal::SDK::Core::API::DataTypes::Base do
4
-
5
- DataType = PayPal::SDK::Core::API::DataTypes::Base
6
-
7
- class TestCurrency < DataType
8
-
9
- # Members
10
- object_of :amount, String
11
- object_of :desciption, String, :namespace => "ns"
12
- # Attributes
13
- add_attribute :currencyID, :namespace => "cc"
14
- end
15
-
16
- class TestType < DataType
17
- object_of :fromCurrency, TestCurrency
18
- array_of :toCurrency, TestCurrency
19
- object_of :firstname, String, :name => "first-name"
20
- end
21
-
22
- class TestSimpleType < DataType
23
- include PayPal::SDK::Core::API::DataTypes::SimpleTypes
24
- object_of :created_on, Date
25
- object_of :created_at, DateTime
26
- end
27
-
28
- class Message < DataType
29
- object_of :value, String
30
- end
31
-
32
- it "should allow content key" do
33
- message = Message.new("Testing message")
34
- expect(message.value).to eql "Testing message"
35
-
36
- message = Message.new(:value => "Testing message")
37
- expect(message.value).to eql "Testing message"
38
- end
39
-
40
- it "should create member object automatically" do
41
- test_type = TestType.new
42
- expect(test_type.fromCurrency).to be_a TestCurrency
43
- expect(test_type.toCurrency).to be_a Array
44
- expect(test_type.toCurrency[0]).to be_a TestCurrency
45
- expect(test_type.toCurrency[1]).to be_a TestCurrency
46
- expect(test_type.toCurrency[0].amount).to eql nil
47
- expect(test_type.fromCurrency.amount).to eql nil
48
- expect(test_type.fromCurrency.desciption).to eql nil
49
- expect(test_type.fromCurrency.currencyID).to eql nil
50
- end
51
-
52
- it "should convert the given data to configured type" do
53
- test_type = TestType.new( :fromCurrency => { :currencyID => "USD", :amount => "50.0"})
54
- expect(test_type.fromCurrency).to be_a TestCurrency
55
- expect(test_type.fromCurrency.currencyID).to eql "USD"
56
- expect(test_type.fromCurrency.amount).to eql "50.0"
57
- end
58
-
59
- it "invoice address loads all members of default address object" do
60
- invoice_address = InvoiceAddress.new(:line1 => "line1", :line2 => "line2", :phone => { :country_code => "123", :national_number => "1231231234", :extension => "123" }, :status => "status" )
61
- expect(invoice_address).to be_a InvoiceAddress
62
- expect(invoice_address.phone).to be_a Phone
63
- expect(invoice_address.line1).to eql "line1"
64
- expect(invoice_address.line2).to eql "line2"
65
- expect(invoice_address.status).to eql "status"
66
- expect(invoice_address.phone.country_code).to eql "123"
67
- expect(invoice_address.phone.national_number).to eql "1231231234"
68
- expect(invoice_address.phone.extension).to eql "123"
69
- end
70
-
71
- it "billing info converts an address to invoiceaddress automatically" do
72
- address = Address.new(:line1 => "line1", :line2 => "line2", :status => "status" )
73
- billing_info = BillingInfo.new({
74
- :first_name => "Sally",
75
- :last_name => "Patient",
76
- :business_name => "Not applicable",
77
- })
78
- billing_info.address = address
79
- expect(billing_info.address).to be_a Address
80
- expect(billing_info.invoice_address).to be_a InvoiceAddress
81
- end
82
-
83
- it "shipping info returns an Address even if set to InvoiceAddress for backwards compatibility" do
84
- address = InvoiceAddress.new(:line1 => "line1", :line2 => "line2", :status => "status", :phone => { :national_number => "1234567890" } )
85
- billing_info = BillingInfo.new({
86
- :first_name => "Sally",
87
- :last_name => "Patient",
88
- :business_name => "Not applicable",
89
- })
90
- billing_info.address = address
91
- expect(billing_info.address).to be_a Address
92
- expect(billing_info.invoice_address).to be_a InvoiceAddress
93
- expect(billing_info.invoice_address.phone.national_number).to eql "1234567890"
94
- end
95
-
96
- it "returns the address and invoice address types in the billing info" do
97
- billing_info = BillingInfo.new({
98
- "first_name" => "Sally",
99
- "last_name" => "Patient",
100
- "business_name" => "Not applicable",
101
- "address" => {
102
- "line1" => "line1Value",
103
- "phone" => { "country_code" => "123", "national_number" => "1234567890", "extension" => "456" },
104
- },
105
- })
106
- expect(billing_info.address).to be_a Address
107
- expect(billing_info.address.line1).to eql "line1Value"
108
- expect(billing_info.invoice_address).to be_a InvoiceAddress
109
- expect(billing_info.invoice_address.line1).to eql "line1Value"
110
- expect(billing_info.invoice_address.phone.country_code).to eql "123"
111
- expect(billing_info.invoice_address.phone.national_number).to eql "1234567890"
112
- expect(billing_info.invoice_address.phone.extension).to eql "456"
113
- end
114
-
115
- it "shipping info converts an address to invoiceaddress automatically" do
116
- address = Address.new(:line1 => "line1", :line2 => "line2", :status => "status" )
117
- shipping_info = ShippingInfo.new({
118
- "first_name" => "Sally",
119
- "last_name" => "Patient",
120
- "business_name" => "Not applicable",
121
- })
122
- shipping_info.address = address
123
- expect(shipping_info.address).to be_a Address
124
- expect(shipping_info.invoice_address).to be_a InvoiceAddress
125
- end
126
-
127
- it "shipping info returns an Address even if set to InvoiceAddress for backwards compatibility" do
128
- address = InvoiceAddress.new(:line1 => "line1", :line2 => "line2", :status => "status", :phone => { :national_number => "1234567890" } )
129
- shipping_info = ShippingInfo.new({
130
- "first_name" => "Sally",
131
- "last_name" => "Patient",
132
- "business_name" => "Not applicable",
133
- })
134
- shipping_info.address = address
135
- expect(shipping_info.address).to be_a Address
136
- expect(shipping_info.invoice_address).to be_a InvoiceAddress
137
- expect(shipping_info.invoice_address.phone.national_number).to eql "1234567890"
138
- end
139
-
140
- it "returns the address and invoice address types in the shipping info" do
141
- shipping_info = ShippingInfo.new({
142
- "first_name" => "Sally",
143
- "last_name" => "Patient",
144
- "business_name" => "Not applicable",
145
- "address" => {
146
- "line1" => "line1Value",
147
- "phone" => { "country_code" => "123", "national_number" => "1234567890", "extension" => "456" },
148
- },
149
- })
150
- expect(shipping_info.address).to be_a Address
151
- expect(shipping_info.address.line1).to eql "line1Value"
152
- expect(shipping_info.invoice_address).to be_a InvoiceAddress
153
- expect(shipping_info.invoice_address.line1).to eql "line1Value"
154
- expect(shipping_info.invoice_address.phone.country_code).to eql "123"
155
- expect(shipping_info.invoice_address.phone.national_number).to eql "1234567890"
156
- expect(shipping_info.invoice_address.phone.extension).to eql "456"
157
- end
158
-
159
- it "should allow block with initializer" do
160
- test_type = TestType.new do
161
- fromCurrency do
162
- self.currencyID = "USD"
163
- self.amount = "50.0"
164
- end
165
- end
166
- expect(test_type.fromCurrency.currencyID).to eql "USD"
167
- expect(test_type.fromCurrency.amount).to eql "50.0"
168
- end
169
-
170
- it "should allow block with member" do
171
- test_type = TestType.new
172
- test_type.fromCurrency do
173
- self.currencyID = "USD"
174
- self.amount = "50.0"
175
- end
176
- expect(test_type.fromCurrency.currencyID).to eql "USD"
177
- expect(test_type.fromCurrency.amount).to eql "50.0"
178
- end
179
-
180
- it "should assign value to attribute" do
181
- test_currency = TestCurrency.new( :@currencyID => "USD", :amount => "50" )
182
- expect(test_currency.currencyID).to eql "USD"
183
- end
184
-
185
- it "should allow configured Class object" do
186
- test_currency = TestCurrency.new( :currencyID => "USD", :amount => "50" )
187
- test_type = TestType.new( :fromCurrency => test_currency )
188
- expect(test_type.fromCurrency).to eql test_currency
189
- end
190
-
191
- it "should allow snakecase" do
192
- test_type = TestType.new( :from_currency => {} )
193
- expect(test_type.from_currency).to be_a TestCurrency
194
- expect(test_type.from_currency).to eql test_type.fromCurrency
195
- end
196
-
197
- it "should allow array" do
198
- test_type = TestType.new( :toCurrency => [{ :currencyID => "USD", :amount => "50.0" }] )
199
- expect(test_type.toCurrency).to be_a Array
200
- expect(test_type.toCurrency.first).to be_a TestCurrency
201
- expect(test_type.toCurrency.first.currencyID).to eql "USD"
202
- end
203
-
204
- it "should skip undefind members on initializer" do
205
- test_type = TestType.new( :notExist => "testing")
206
- expect do
207
- test_type.notExist
208
- end.to raise_error NoMethodError
209
- expect do
210
- test_type.notExist = "Value"
211
- end.to raise_error NoMethodError
212
- end
213
-
214
- it "should not convert empty hash" do
215
- test_type = TestType.new( :fromCurrency => {} )
216
- expect(test_type.to_hash).to eql({})
217
- end
218
-
219
- it "should not convert empty array" do
220
- test_type = TestType.new( :toCurrency => [] )
221
- expect(test_type.to_hash).to eql({})
222
- end
223
-
224
- it "should not convert array of empty hash" do
225
- test_type = TestType.new( :toCurrency => [ {} ] )
226
- expect(test_type.to_hash).to eql({})
227
- end
228
-
229
- it "should return empty hash" do
230
- test_type = TestType.new
231
- expect(test_type.to_hash).to eql({})
232
- end
233
-
234
- it "should convert to hash" do
235
- test_currency = TestCurrency.new(:amount => "500")
236
- expect(test_currency.to_hash).to eql("amount" => "500")
237
- end
238
-
239
- it "should convert to hash with key as symbol" do
240
- test_currency = TestCurrency.new(:amount => "500")
241
- expect(test_currency.to_hash(:symbol => true)).to eql(:amount => "500")
242
- end
243
-
244
- it "should convert attribute key with @" do
245
- test_currency = TestCurrency.new( :currencyID => "USD", :amount => "50" )
246
- expect(test_currency.to_hash["@currencyID"]).to eql "USD"
247
- end
248
-
249
- it "should convert attribute key without @" do
250
- test_currency = TestCurrency.new( :currencyID => "USD", :amount => "50" )
251
- expect(test_currency.to_hash(:attribute => false)["currencyID"]).to eql "USD"
252
- end
253
-
254
- it "should convert to hash with namespace" do
255
- test_currency = TestCurrency.new(:currencyID => "USD", :amount => "500", :desciption => "Testing" )
256
- hash = test_currency.to_hash
257
- expect(hash["amount"]).to eql "500"
258
- expect(hash["ns:desciption"]).to eql "Testing"
259
- expect(hash["@currencyID"]).to eql "USD"
260
- hash = test_currency.to_hash(:namespace => false)
261
- expect(hash["amount"]).to eql "500"
262
- expect(hash["desciption"]).to eql "Testing"
263
- expect(hash["@currencyID"]).to eql "USD"
264
- end
265
-
266
- it "should allow namespace" do
267
- test_currency = TestCurrency.new(:amount => "500", :"ns:desciption" => "Testing" )
268
- expect(test_currency.desciption).to eql "Testing"
269
- end
270
-
271
- it "should use name option in members" do
272
- test_type = TestType.new( :firstname => "FirstName")
273
- expect(test_type.to_hash).to eql({"first-name" => "FirstName" })
274
- end
275
-
276
- it "should allow date" do
277
- date_time = "2010-10-10T10:10:10"
278
- test_simple_type = TestSimpleType.new( :created_on => date_time, :created_at => date_time )
279
- expect(test_simple_type.created_on).to be_a Date
280
- expect(test_simple_type.created_at).to be_a DateTime
281
- end
282
-
283
- it "should allow date with value 0" do
284
- test_simple_type = TestSimpleType.new( :created_at => "0" )
285
- expect(test_simple_type.created_at).to be_a DateTime
286
- end
287
-
288
- end
289
-
@@ -1,211 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PayPal::SDK::Core::API::REST do
4
-
5
- module PayPalRest
6
- class API < PayPal::SDK::Core::API::REST
7
- end
8
- end
9
-
10
- def create_api(*args)
11
- api = PayPalRest::API.new(*args)
12
- @log_file ||= File.open("spec/log/rest_http.log", "w")
13
- api.http.set_debug_output(@log_file)
14
- api
15
- end
16
-
17
- before :all do
18
- @api = create_api("v1/payments/", :with_authentication)
19
- @vault_api = create_api("v1/vault/", :with_authentication)
20
- end
21
-
22
- describe "Configuration" do
23
- it "create api with prefix" do
24
- api = create_api("v1/payments")
25
- expect(api.uri.path).to eql "/v1/payments"
26
- end
27
-
28
- it "service endpoint for sandbox" do
29
- api = create_api
30
- expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
31
- expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
32
- api = create_api( :mode => "sandbox" )
33
- expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
34
- expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
35
- api = create_api( :mode => :sandbox )
36
- expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
37
- expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
38
- api = create_api( :mode => "invalid" )
39
- expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
40
- expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
41
- api = create_api( :mode => nil )
42
- expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
43
- expect(api.token_endpoint).to eql "https://api.sandbox.paypal.com"
44
- end
45
-
46
- it "service endpoint for live" do
47
- api = create_api( :mode => "live" )
48
- expect(api.service_endpoint).to eql "https://api.paypal.com"
49
- expect(api.token_endpoint).to eql "https://api.paypal.com"
50
- api = create_api( :mode => :live )
51
- expect(api.service_endpoint).to eql "https://api.paypal.com"
52
- expect(api.token_endpoint).to eql "https://api.paypal.com"
53
- end
54
-
55
- it "override service endpoint" do
56
- api = create_api( :rest_endpoint => "https://testing.api.paypal.com" )
57
- expect(api.service_endpoint).to eql "https://testing.api.paypal.com"
58
- expect(api.token_endpoint).to eql "https://testing.api.paypal.com"
59
- api = create_api( :endpoint => "https://testing.api.paypal.com" )
60
- expect(api.service_endpoint).to eql "https://testing.api.paypal.com"
61
- expect(api.token_endpoint).to eql "https://testing.api.paypal.com"
62
- end
63
-
64
- it "override token endpoint" do
65
- api = create_api( :rest_token_endpoint => "https://testing.api.paypal.com" )
66
- expect(api.service_endpoint).to eql "https://api.sandbox.paypal.com"
67
- expect(api.token_endpoint).to eql "https://testing.api.paypal.com"
68
- end
69
- end
70
-
71
- describe "Validation" do
72
- it "Invalid client_id and client_secret" do
73
- api = create_api(:with_authentication, :client_id => "XYZ", :client_secret => "ABC")
74
- expect {
75
- api.token
76
- }.to raise_error PayPal::SDK::Core::Exceptions::UnauthorizedAccess
77
- end
78
-
79
- it "Should handle expired token" do
80
- old_token = @api.token
81
- @api.token_hash[:expires_in] = 0
82
- new_token = @api.token
83
- expect(@api.token_hash[:expires_in]).not_to eql 0
84
- end
85
-
86
- it "Get token" do
87
- expect(@api.token).not_to be_nil
88
- end
89
- end
90
-
91
- describe "Success request", :integration => true do
92
-
93
- it "Create Payment" do
94
- response = @api.post("payment", {
95
- "intent" => "sale",
96
- "payer" => {
97
- "payment_method" => "credit_card",
98
- "funding_instruments" => [{
99
- "credit_card" => {
100
- "type" => "visa",
101
- "number" => "4567516310777851",
102
- "expire_month" => "11", "expire_year" => "2018",
103
- "first_name" => "Joe", "last_name" => "Shopper" }}]},
104
- "transactions" => [{
105
- "amount" => {
106
- "total" => "7.47",
107
- "currency" => "USD" }}]})
108
- expect(response["error"]).to be_nil
109
- end
110
-
111
- it "List Payments" do
112
- response = @api.get("payment", { "count" => 10 })
113
- expect(response["error"]).to be_nil
114
- expect(response["count"]).not_to be_nil
115
- end
116
-
117
- it "Execute Payment"
118
-
119
- it "Create FundingInstrument" do
120
- new_funding_instrument = @vault_api.post("credit-card", {
121
- "type" => "visa",
122
- "number" => "4111111111111111",
123
- "expire_month" => "11", "expire_year" => "2018",
124
- "cvv2" => "874",
125
- "first_name" => "Joe", "last_name" => "Shopper" })
126
- expect(new_funding_instrument["error"]).to be_nil
127
- expect(new_funding_instrument["id"]).not_to be_nil
128
-
129
- funding_instrument = @vault_api.get("credit-card/#{new_funding_instrument["id"]}")
130
- expect(funding_instrument["error"]).to be_nil
131
- expect(funding_instrument["id"]).to eql new_funding_instrument["id"]
132
- end
133
-
134
- end
135
-
136
- describe "Failure request", :integration => true do
137
- it "Invalid Resource ID" do
138
- expect {
139
- response = @api.get("payment/PAY-1234")
140
- }.to raise_error PayPal::SDK::Core::Exceptions::ResourceNotFound
141
- end
142
-
143
- it "Invalid parameters" do
144
- response = @api.post("payment")
145
- expect(response["error"]["name"]).to eql "VALIDATION_ERROR"
146
- end
147
- end
148
-
149
- describe "format response" do
150
- before :each do
151
- @response = instance_double(Net::HTTPResponse)
152
- allow(@response).to receive(:code) { "200" }
153
- allow(@response).to receive(:content_type) { "application/json" }
154
- end
155
-
156
- it "parses empty object JSON correctly" do
157
- allow(@response).to receive(:body) { "{}" }
158
- payload = {
159
- :response => @response
160
- }
161
-
162
- formatted_response = @api.format_response(payload)
163
- expect(formatted_response).to_not be_nil
164
- expect(formatted_response[:data]).to eq({})
165
- end
166
-
167
- it "parses empty string JSON correctly" do
168
- allow(@response).to receive(:body) { '""' }
169
- payload = {
170
- :response => @response
171
- }
172
-
173
- formatted_response = @api.format_response(payload)
174
- expect(formatted_response).to_not be_nil
175
- expect(formatted_response[:data]).to eq("")
176
- end
177
-
178
- it "parses whitespace body correctly" do
179
- allow(@response).to receive(:body) { ' ' }
180
- payload = {
181
- :response => @response
182
- }
183
-
184
- formatted_response = @api.format_response(payload)
185
- expect(formatted_response).to_not be_nil
186
- expect(formatted_response[:data]).to eq({})
187
- end
188
-
189
- it "parses nil body correctly" do
190
- allow(@response).to receive(:body) { nil }
191
- payload = {
192
- :response => @response
193
- }
194
-
195
- formatted_response = @api.format_response(payload)
196
- expect(formatted_response).to_not be_nil
197
- expect(formatted_response[:data]).to eq({})
198
- end
199
-
200
- it "parses with whitespace around JSON correctly" do
201
- allow(@response).to receive(:body) { ' { "test": "value" } ' }
202
- payload = {
203
- :response => @response
204
- }
205
-
206
- formatted_response = @api.format_response(payload)
207
- expect(formatted_response).to_not be_nil
208
- expect(formatted_response[:data]).to eq({ "test" => "value" })
209
- end
210
- end
211
- end
@@ -1,192 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PayPal::SDK::Core::Config do
4
-
5
- Config = PayPal::SDK::Core::Config
6
-
7
- it "load configuration file and default environment" do
8
- expect {
9
- Config.load("spec/config/paypal.yml", "test")
10
- expect(Config.default_environment).to eql "test"
11
- }.not_to raise_error
12
- end
13
-
14
- it "Set default environment" do
15
- begin
16
- backup_default_environment = Config.default_environment
17
- Config.default_environment = "new_env"
18
- expect(Config.default_environment).to eql "new_env"
19
- ensure
20
- Config.default_environment = backup_default_environment
21
- end
22
- end
23
-
24
- it "Set configurations" do
25
- begin
26
- backup_configurations = Config.configurations
27
- Config.configurations = { Config.default_environment => { :username => "direct", :password => "direct" } }
28
- expect(Config.config.username).to eql "direct"
29
- expect(Config.config.password).to eql "direct"
30
- expect(Config.config.signature).to be_nil
31
- ensure
32
- Config.configurations = backup_configurations
33
- end
34
- end
35
-
36
- it "Configure with parameters" do
37
- begin
38
- backup_configurations = Config.configurations
39
- Config.configurations = nil
40
- Config.configure( :username => "Testing" )
41
- expect(Config.config.username).to eql "Testing"
42
- expect(Config.config.app_id).to be_nil
43
- ensure
44
- Config.configurations = backup_configurations
45
- end
46
- end
47
-
48
- it "Configure with block" do
49
- begin
50
- backup_configurations = Config.configurations
51
- Config.configurations = nil
52
- Config.configure do |config|
53
- config.username = "Testing"
54
- end
55
- expect(Config.config.username).to eql "Testing"
56
- expect(Config.config.app_id).to be_nil
57
- ensure
58
- Config.configurations = backup_configurations
59
- end
60
- end
61
-
62
- it "Configure with default values" do
63
- begin
64
- backup_configurations = Config.configurations
65
- default_config = Config.config
66
- Config.configure do |config|
67
- config.username = "Testing"
68
- end
69
- expect(Config.config.username).to eql "Testing"
70
- expect(Config.config.app_id).not_to be_nil
71
- expect(Config.config.app_id).to eql default_config.app_id
72
- ensure
73
- Config.configurations = backup_configurations
74
- end
75
- end
76
-
77
- it "validate configuration" do
78
- config = Config.new( :username => "XYZ")
79
- expect {
80
- config.required!(:username)
81
- }.not_to raise_error
82
- expect {
83
- config.required!(:password)
84
- }.to raise_error "Required configuration(password)"
85
- expect {
86
- config.required!(:username, :password)
87
- }.to raise_error "Required configuration(password)"
88
- expect {
89
- config.required!(:password, :signature)
90
- }.to raise_error "Required configuration(password, signature)"
91
- end
92
-
93
- it "return default environment configuration" do
94
- expect(Config.config).to be_a Config
95
- end
96
-
97
- it "return configuration based on environment" do
98
- expect(Config.config(:development)).to be_a Config
99
- end
100
-
101
- it "override default configuration" do
102
- override_configuration = { :username => "test.example.com", :app_id => "test"}
103
- config = Config.config(override_configuration)
104
-
105
- expect(config.username).to eql(override_configuration[:username])
106
- expect(config.app_id).to eql(override_configuration[:app_id])
107
- end
108
-
109
- it "get cached config" do
110
- expect(Config.config(:test)).to eql Config.config(:test)
111
- expect(Config.config(:test)).not_to eql Config.config(:development)
112
- end
113
-
114
- it "should raise error on invalid environment" do
115
- expect {
116
- Config.config(:invalid_env)
117
- }.to raise_error "Configuration[invalid_env] NotFound"
118
- end
119
-
120
- it "set logger" do
121
- require 'logger'
122
- my_logger = Logger.new(STDERR)
123
- Config.logger = my_logger
124
- expect(Config.logger).to eql my_logger
125
- end
126
-
127
- it "Access PayPal::SDK methods" do
128
- expect(PayPal::SDK.configure).to eql PayPal::SDK::Core::Config.config
129
- expect(PayPal::SDK.logger).to eql PayPal::SDK::Core::Config.logger
130
- PayPal::SDK.logger = PayPal::SDK.logger
131
- expect(PayPal::SDK.logger).to eql PayPal::SDK::Core::Config.logger
132
- end
133
-
134
- describe "include Configuration" do
135
- class TestConfig
136
- include PayPal::SDK::Core::Configuration
137
- end
138
-
139
- it "Get default configuration" do
140
- test_object = TestConfig.new
141
- expect(test_object.config).to be_a Config
142
- end
143
-
144
- it "Change environment" do
145
- test_object = TestConfig.new
146
- test_object.set_config("test")
147
- expect(test_object.config).to eql Config.config("test")
148
- expect(test_object.config).not_to eql Config.config("development")
149
- end
150
-
151
- it "Override environment configuration" do
152
- test_object = TestConfig.new
153
- test_object.set_config("test", :username => "test")
154
- expect(test_object.config).not_to eql Config.config("test")
155
- end
156
-
157
- it "Override default/current configuration" do
158
- test_object = TestConfig.new
159
- test_object.set_config( :username => "test")
160
- expect(test_object.config.username).to eql "test"
161
- test_object.set_config( :password => "test")
162
- expect(test_object.config.password).to eql "test"
163
- expect(test_object.config.username).to eql "test"
164
- end
165
-
166
- it "Append ssl_options" do
167
- test_object = TestConfig.new
168
- test_object.set_config( :ssl_options => { :ca_file => "test_path" } )
169
- expect(test_object.config.ssl_options[:ca_file]).to eql "test_path"
170
- test_object.set_config( :ssl_options => { :verify_mode => 1 } )
171
- expect(test_object.config.ssl_options[:verify_mode]).to eql 1
172
- expect(test_object.config.ssl_options[:ca_file]).to eql "test_path"
173
- end
174
-
175
- it "Set configuration without loading configuration File" do
176
- backup_configurations = Config.configurations
177
- begin
178
- Config.configurations = nil
179
- test_object = TestConfig.new
180
- expect {
181
- test_object.config
182
- }.to raise_error
183
- test_object.set_config( :username => "test" )
184
- expect(test_object.config).to be_a Config
185
- ensure
186
- Config.configurations = backup_configurations
187
- end
188
- end
189
-
190
- end
191
-
192
- end