paypal-sdk-rest 1.4.9 → 1.7.5

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.
@@ -13,7 +13,7 @@ module PayPal
13
13
  def []=(key, value)
14
14
  value =
15
15
  if value.is_a? Hash
16
- ErrorHash.convert(hash)
16
+ ErrorHash.convert(value)
17
17
  elsif value.is_a? Array and value[0].is_a? Hash
18
18
  value.map{|array_value| ErrorHash.convert(array_value) }
19
19
  else
@@ -1,7 +1,7 @@
1
1
  module PayPal
2
2
  module SDK
3
3
  module REST
4
- VERSION = "1.4.9"
4
+ VERSION = "1.7.4"
5
5
  end
6
6
  end
7
7
  end
@@ -56,6 +56,106 @@ describe PayPal::SDK::Core::API::DataTypes::Base do
56
56
  expect(test_type.fromCurrency.amount).to eql "50.0"
57
57
  end
58
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
+
59
159
  it "should allow block with initializer" do
60
160
  test_type = TestType.new do
61
161
  fromCurrency do
@@ -76,10 +76,11 @@ describe PayPal::SDK::Core::API::REST do
76
76
  }.to raise_error PayPal::SDK::Core::Exceptions::UnauthorizedAccess
77
77
  end
78
78
 
79
- xit "Should handle expired token" do
79
+ it "Should handle expired token" do
80
80
  old_token = @api.token
81
81
  @api.token_hash[:expires_in] = 0
82
- expect(@api.token).not_to eql old_token
82
+ new_token = @api.token
83
+ expect(@api.token_hash[:expires_in]).not_to eql 0
83
84
  end
84
85
 
85
86
  it "Get token" do
@@ -144,4 +145,67 @@ describe PayPal::SDK::Core::API::REST do
144
145
  expect(response["error"]["name"]).to eql "VALIDATION_ERROR"
145
146
  end
146
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
147
211
  end
@@ -1,4 +1,6 @@
1
1
  require 'spec_helper'
2
+ require 'json'
3
+ require 'webmock/rspec'
2
4
 
3
5
  describe "Payments" do
4
6
 
@@ -49,6 +51,18 @@ describe "Payments" do
49
51
  "currency" => "USD" },
50
52
  "description" => "This is the payment transaction description." } ] }
51
53
 
54
+ ProcessorErrorResponse = {
55
+ "name" => "INSTRUMENT_DECLINED",
56
+ "message" => "The instrument presented was either declined by the processor or bank, or it can't be used for this payment.",
57
+ "information_link" => "https://developer.paypal.com/docs/api/#INSTRUMENT_DECLINED",
58
+ "debug_id" => "20dcd4f71107c",
59
+ "another_thing" => {
60
+ "avs_code" => "Y",
61
+ "cvv_code" => "N",
62
+ "response_code" => "0051"
63
+ }
64
+ }
65
+
52
66
  it "Validate user-agent", :unit => true do
53
67
  expect(PayPal::SDK::REST::API.user_agent).to match "PayPalSDK/PayPal-Ruby-SDK"
54
68
  end
@@ -62,6 +76,40 @@ describe "Payments" do
62
76
  PayPal::SDK::REST.set_config(backup_config)
63
77
  expect(PayPal::SDK::REST.api.config.client_id).not_to eql "XYZ"
64
78
  end
79
+
80
+ it "Create - does not return true when error not provided in response" do
81
+ oauth_response = {
82
+ :scope => "https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*",
83
+ :nonce => "2016-10-04T18:00:00ZP3PcGAv5XAncoc8Zt4MF5cRLlaEBW3OAoLEhMIFk--g",
84
+ :access_token => "A101.tp_sF5GHqWnnqEQA13Ua5ABnIhRWgd-G9LhRnJdgOvJHc_L08zlfD9WgPF4I3kre.mShauuOGxWyw8ikViItmxkWmX78",
85
+ :token_type => "Bearer",
86
+ :app_id => "APP-80W284485P519543T",
87
+ :expires_in => 30695
88
+ }
89
+
90
+ response_headers = {
91
+ "date" => ["Fri, 09 Sep 2016 17:44:23 GMT"],
92
+ "server" => ["Apache"],
93
+ "proxy_server_info" => ["host=dcg12javapapi8768.dcg12.slc.paypalinc.com;threadId=1177"],
94
+ "paypal-debug-id" => ["20dcd4f71107c", "20dcd4f71107c"],
95
+ "correlation-id" => ["20dcd4f71107c"],
96
+ "content-language" => ["*"],
97
+ "connection" => ["close", "close"],
98
+ "set-cookie" => ["X-PP-SILOVER=name%3DLIVE3.API.1%26silo_version%3D880%26app%3Dplatformapiserv%26TIME%3D4160016983%26HTTP_X_PP_AZ_LOCATOR%3Ddcg12.slc; Expires=Fri, 09 Sep 2016 18:14:25 GMT; domain=.paypal.com; path=/; Secure; HttpOnly", "X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT"],
99
+ "vary" => ["Authorization"],
100
+ "content-length" => ["335"],
101
+ "content-type"=>["application/json"]
102
+ }
103
+
104
+ stub_request(:post, "https://api.sandbox.paypal.com/v1/oauth2/token")
105
+ .to_return(:body => oauth_response.to_json)
106
+
107
+ stub_request(:post, "https://api.sandbox.paypal.com/v1/payments/payment")
108
+ .to_return(:body => ProcessorErrorResponse.to_json, :status => 400, :headers => response_headers)
109
+
110
+ payment = Payment.new(PaymentAttributes)
111
+ expect(payment.create).to be_falsey
112
+ end
65
113
  end
66
114
 
67
115
  describe "Payment", :integration => true do
@@ -87,7 +135,6 @@ describe "Payments" do
87
135
  expect(new_payment.error).to be_nil
88
136
 
89
137
  expect(payment.id).to eql new_payment.id
90
-
91
138
  end
92
139
 
93
140
  it "Create with token" do
@@ -2,6 +2,25 @@ require "spec_helper"
2
2
 
3
3
  describe "Payouts", :integration => true do
4
4
 
5
+ PayoutVenmoAttributes = {
6
+ :sender_batch_header => {
7
+ :sender_batch_id => SecureRandom.hex(8)
8
+ },
9
+ :items => [
10
+ {
11
+ :recipient_type => 'PHONE',
12
+ :amount => {
13
+ :value => '1.0',
14
+ :currency => 'USD'
15
+ },
16
+ :note => 'Thanks for your patronage!',
17
+ :sender_item_id => '2014031400023',
18
+ :receiver => '5551232368',
19
+ :recipient_wallet => 'VENMO'
20
+ }
21
+ ]
22
+ }
23
+
5
24
  PayoutAttributes = {
6
25
  :sender_batch_header => {
7
26
  :sender_batch_id => SecureRandom.hex(8),
@@ -21,6 +40,12 @@ describe "Payouts", :integration => true do
21
40
  ]
22
41
  }
23
42
 
43
+ it "create venmo payout" do
44
+ $payout = PayPal::SDK::REST::Payout.new(PayoutVenmoAttributes)
45
+ $payout_batch = $payout.create
46
+ expect($payout_batch).to be_truthy
47
+ end
48
+
24
49
  it "create payout sync" do
25
50
  $payout = PayPal::SDK::REST::Payout.new(PayoutAttributes)
26
51
  $payout_batch = $payout.create(true)
@@ -0,0 +1,83 @@
1
+ module PayPal::SDK::REST
2
+ describe ErrorHash do
3
+ it 'converts Hashes to ErrorHashes' do
4
+ hash = ErrorHash.convert({
5
+ nested_hash: { bing: 'bong' },
6
+ empty_array: [],
7
+ array_with_hashes: [
8
+ { foo: 'boo' },
9
+ { biz: 'boz' }
10
+ ],
11
+ array_without_hashes: [1, 2, 3],
12
+ nilly: nil,
13
+ stringy: 'cheese'
14
+ })
15
+
16
+ expect(hash).to be_a(ErrorHash)
17
+ expect(hash.nested_hash).to be_a(ErrorHash)
18
+ expect(hash.empty_array).to eq([])
19
+ expect(hash.array_with_hashes[0]).to be_a(ErrorHash)
20
+ expect(hash.array_with_hashes[1]).to be_a(ErrorHash)
21
+ expect(hash.array_without_hashes).to eq([1, 2, 3])
22
+ expect(hash.nilly).to be_nil
23
+ expect(hash.stringy).to eq('cheese')
24
+ end
25
+
26
+ it 'can access string keys as properties, strings, or symbols' do
27
+ hash = ErrorHash.convert({ 'foo' => 5 })
28
+ hash['boo'] = 'grue'
29
+
30
+ expect(hash.foo).to eq(5)
31
+ expect(hash['foo']).to eq(5)
32
+ expect(hash[:foo]).to eq(5)
33
+ expect(hash.boo).to eq('grue')
34
+ expect(hash['boo']).to eq('grue')
35
+ expect(hash[:boo]).to eq('grue')
36
+ end
37
+
38
+ it 'can access symbol keys as properties, strings, or symbols' do
39
+ hash = ErrorHash.convert({ :foo => 5 })
40
+ hash[:boo] = 'grue'
41
+
42
+ expect(hash.foo).to eq(5)
43
+ expect(hash['foo']).to eq(5)
44
+ expect(hash[:foo]).to eq(5)
45
+ expect(hash.boo).to eq('grue')
46
+ expect(hash['boo']).to eq('grue')
47
+ expect(hash[:boo]).to eq('grue')
48
+ end
49
+
50
+ it 'converts Hashes to ErrorHashes on assignment' do
51
+ hash = ErrorHash.new
52
+ hash['foo'] = { bing: 'bong' }
53
+
54
+ expect(hash['foo']).to be_a(ErrorHash)
55
+ expect(hash['foo'].bing).to eq('bong')
56
+ end
57
+
58
+ it 'converts Hashes inside of Arrays to ErrorHashes on assignment' do
59
+ hash = ErrorHash.new
60
+ hash['foo'] = [{ bing: 'bong' }]
61
+
62
+ expect(hash['foo'][0]).to be_a(ErrorHash)
63
+ expect(hash['foo'][0].bing).to eq('bong')
64
+ end
65
+
66
+ it "doesn't convert Hashes inside of Arrays if the first element of the array isn't a Hash" do
67
+ hash = ErrorHash.new
68
+ hash['foo'] = [100, { bing: 'bong' }]
69
+
70
+ expect(hash['foo'][1]).to be_a(Hash)
71
+ expect(hash['foo'][1]).not_to be_a(ErrorHash)
72
+ end
73
+
74
+ it 'gets and sets numbers and strings' do
75
+ hash = ErrorHash.new
76
+ hash['foo'] = 123
77
+ hash['boo'] = 'baa'
78
+
79
+ expect(hash['foo']).to eq(123)
80
+ expect(hash['boo']).to eq('baa')
81
+ end
82
+ end
83
+ end
data/spec/spec_helper.rb CHANGED
@@ -33,3 +33,5 @@ RSpec.configure do |config|
33
33
  config.include SampleData
34
34
  # config.include PayPal::SDK::REST::DataTypes
35
35
  end
36
+
37
+ WebMock.allow_net_connect!
@@ -15,6 +15,14 @@ describe "Webhooks" do
15
15
  ]
16
16
  }
17
17
 
18
+ describe "PayPal::SDK::Core::API::DataTypes::WebhookEvent" do
19
+ describe "get event by id via .find" do
20
+ it "exists" do
21
+ expect(WebhookEvent).to respond_to(:find)
22
+ end
23
+ end
24
+ end
25
+
18
26
  describe "Notifications", :integration => true do
19
27
  it "create webhook" do
20
28
  $webhook = PayPal::SDK::REST::Webhook.new(webhookAttributes)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypal-sdk-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.9
4
+ version: 1.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - PayPal
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2023-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -52,22 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
- - !ruby/object:Gem::Dependency
56
- name: uuidtools
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.1'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.1'
69
- description: The PayPal REST SDK provides Ruby APIs to create, process and manage
70
- payment.
55
+ description: "[Deprecated] The PayPal REST SDK provides Ruby APIs to create, process
56
+ and manage payment."
71
57
  email:
72
58
  - DL-PP-RUBY-SDK@paypal.com
73
59
  executables: []
@@ -133,11 +119,10 @@ files:
133
119
  - spec/core/logging_spec.rb
134
120
  - spec/core/openid_connect_spec.rb
135
121
  - spec/invoice_examples_spec.rb
136
- - spec/log/http.log
137
- - spec/log/rest_http.log
138
122
  - spec/payments_examples_spec.rb
139
123
  - spec/payouts_examples_spec.rb
140
124
  - spec/rest/data_types_spec.rb
125
+ - spec/rest/error_hash_spec.rb
141
126
  - spec/spec_helper.rb
142
127
  - spec/subscription_examples_spec.rb
143
128
  - spec/support/sample_data.rb
@@ -147,7 +132,7 @@ homepage: https://developer.paypal.com
147
132
  licenses:
148
133
  - PayPal SDK License
149
134
  metadata: {}
150
- post_install_message:
135
+ post_install_message:
151
136
  rdoc_options: []
152
137
  require_paths:
153
138
  - lib
@@ -162,11 +147,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
147
  - !ruby/object:Gem::Version
163
148
  version: '0'
164
149
  requirements: []
165
- rubyforge_project:
166
- rubygems_version: 2.5.1
167
- signing_key:
150
+ rubygems_version: 3.4.10
151
+ signing_key:
168
152
  specification_version: 4
169
- summary: The PayPal REST SDK provides Ruby APIs to create, process and manage payment.
153
+ summary: Deprecated.
170
154
  test_files:
171
155
  - spec/README.md
172
156
  - spec/config/cacert.pem
@@ -179,11 +163,10 @@ test_files:
179
163
  - spec/core/logging_spec.rb
180
164
  - spec/core/openid_connect_spec.rb
181
165
  - spec/invoice_examples_spec.rb
182
- - spec/log/http.log
183
- - spec/log/rest_http.log
184
166
  - spec/payments_examples_spec.rb
185
167
  - spec/payouts_examples_spec.rb
186
168
  - spec/rest/data_types_spec.rb
169
+ - spec/rest/error_hash_spec.rb
187
170
  - spec/spec_helper.rb
188
171
  - spec/subscription_examples_spec.rb
189
172
  - spec/support/sample_data.rb
data/spec/log/http.log DELETED
File without changes
File without changes