paypal-sdk-rest 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07eb29c0bcc2e64cb6021ee41b2a8044c9ea614e
4
- data.tar.gz: 34af36098b7335cf1f2f7eb5d733bc8e38a5a024
3
+ metadata.gz: 96c5110387c529214199709d42f2583c1c9ec8bf
4
+ data.tar.gz: 8c258a28b2716cba02248cc8f9a822a207c35b6c
5
5
  SHA512:
6
- metadata.gz: acbaec588e900bcc9efd6d19dfa455e1402b5cb83c64e6358afb254d452ae472fb2cf1ceb4f42032699d789c41d6c85f8a0137dc31a72f649ea5c28fc0dfd95f
7
- data.tar.gz: c868cc58f3610e68cf142536500f18736752e598124a7b237307773799a6e280d3a22e8bda0d484d6ea7ee39b04b0abf9168d8ce324495ac4c7440ce2f6e0cd4
6
+ metadata.gz: c4da04b7606a4ce1fe30a0600aa2ef8521f696d7411c1158d0e0fc23553017d0325aa86a26e95a61fabe6692bca0fa303c3185be4a5c6486e0326fd0ffffecaa
7
+ data.tar.gz: d420deb8a02247e67d3648f502c246abb81fcde5eb5a7d7d3776c1e862b8b48cfeb336297870135c322d57714ae62dab044b9038f0d0e5a9b8e0172c4b0eb81d
data/README.md CHANGED
@@ -134,38 +134,25 @@ PayPal::SDK::REST.set_config(
134
134
 
135
135
  # Build Payment object
136
136
  @payment = Payment.new({
137
- :intent => "sale",
138
- :payer => {
139
- :payment_method => "credit_card",
140
- :funding_instruments => [{
141
- :credit_card => {
142
- :type => "visa",
143
- :number => "4567516310777851",
144
- :expire_month => "11",
145
- :expire_year => "2018",
146
- :cvv2 => "874",
147
- :first_name => "Joe",
148
- :last_name => "Shopper",
149
- :billing_address => {
150
- :line1 => "52 N Main ST",
151
- :city => "Johnstown",
152
- :state => "OH",
153
- :postal_code => "43210",
154
- :country_code => "US" }}}]},
155
- :transactions => [{
137
+ :intent => "sale",
138
+ :payer => {
139
+ :payment_method => "paypal" },
140
+ :redirect_urls => {
141
+ :return_url => "http://localhost:3000/payment/execute",
142
+ :cancel_url => "http://localhost:3000/" },
143
+ :transactions => [{
156
144
  :item_list => {
157
145
  :items => [{
158
146
  :name => "item",
159
147
  :sku => "item",
160
- :price => "1",
148
+ :price => "5",
161
149
  :currency => "USD",
162
150
  :quantity => 1 }]},
163
- :amount => {
164
- :total => "1.00",
165
- :currency => "USD" },
166
- :description => "This is the payment transaction description." }]})
151
+ :amount => {
152
+ :total => "5",
153
+ :currency => "USD" },
154
+ :description => "This is the payment transaction description." }]})
167
155
 
168
- # Create Payment and return the status(true or false)
169
156
  if @payment.create
170
157
  @payment.id # Payment Id
171
158
  else
@@ -186,8 +173,6 @@ payment_history.payments
186
173
 
187
174
  ## Execute Payment
188
175
 
189
- Only for [Payment](https://github.com/paypal/rest-api-sdk-ruby/blob/master/samples/payment/create_with_paypal.rb) with `payment_method` as `"paypal"`
190
-
191
176
  ```ruby
192
177
  payment = Payment.find("PAY-57363176S1057143SKE2HO3A")
193
178
 
@@ -273,6 +258,10 @@ rescue ResourceNotFound => err
273
258
  logger.error @payout.error.inspect
274
259
  end
275
260
  ```
261
+
262
+ ## Direct Credit Card Support
263
+ [Braintree Direct](https://www.braintreepayments.com/products/braintree-direct) is PayPal's preferred integration solution for accepting direct credit card payments in your mobile app or website. Braintree, a PayPal service, is the easiest way to accept credit cards, PayPal, and many other payment methods.
264
+
276
265
  ## License
277
266
  Code released under [SDK LICENSE](LICENSE)
278
267
 
@@ -14,7 +14,6 @@ module PayPal::SDK::Core
14
14
  DEFAULT_REST_END_POINTS = {
15
15
  :sandbox => "https://api.sandbox.paypal.com",
16
16
  :live => "https://api.paypal.com",
17
- :security_test_sandbox => "https://test-api.sandbox.paypal.com"
18
17
  }
19
18
  TOKEN_REQUEST_PARAMS = "grant_type=client_credentials"
20
19
 
@@ -140,7 +139,9 @@ module PayPal::SDK::Core
140
139
  def format_response(payload)
141
140
  response = payload[:response]
142
141
  payload[:data] =
143
- if response.code >= "200" and response.code <= "299"
142
+ if response.body && response.body.strip == ""
143
+ {}
144
+ elsif response.code >= "200" and response.code <= "299"
144
145
  response.body && response.content_type == "application/json" ? MultiJson.load(response.body) : {}
145
146
  elsif response.content_type == "application/json"
146
147
  { "error" => flat_hash(MultiJson.load(response.body)) }
@@ -84,6 +84,10 @@ module PayPal::SDK::Core
84
84
  class ResourceGone < ClientError # :nodoc:
85
85
  end
86
86
 
87
+ # 422 Unprocessable Entity
88
+ class ResourceInvalid < ClientError # :nodoc:
89
+ end
90
+
87
91
  # 5xx Server Error
88
92
  class ServerError < ConnectionError # :nodoc:
89
93
  end
@@ -1594,17 +1594,15 @@ module PayPal::SDK
1594
1594
  WebhookEvent.find(webhook_event_id)
1595
1595
  end
1596
1596
 
1597
- class << self
1598
- def find(resource_id)
1599
- raise ArgumentError.new("webhook_event_id required") if resource_id.to_s.strip.empty?
1600
- path = "v1/notifications/webhooks-events/#{resource_id}"
1601
- self.new(api.get(path))
1602
- end
1597
+ def find(resource_id)
1598
+ raise ArgumentError.new("webhook_event_id required") if resource_id.to_s.strip.empty?
1599
+ path = "v1/notifications/webhooks-events/#{resource_id}"
1600
+ self.new(api.get(path))
1601
+ end
1603
1602
 
1604
- def all(options = {})
1605
- path = "v1/notifications/webhooks-events"
1606
- WebhookEventList.new(api.get(path, options))
1607
- end
1603
+ def all(options = {})
1604
+ path = "v1/notifications/webhooks-events"
1605
+ WebhookEventList.new(api.get(path, options))
1608
1606
  end
1609
1607
  end
1610
1608
  end
@@ -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.6.0"
4
+ VERSION = "1.6.1"
5
5
  end
6
6
  end
7
7
  end
@@ -144,4 +144,67 @@ describe PayPal::SDK::Core::API::REST do
144
144
  expect(response["error"]["name"]).to eql "VALIDATION_ERROR"
145
145
  end
146
146
  end
147
+
148
+ describe "format response" do
149
+ before :each do
150
+ @response = instance_double(Net::HTTPResponse)
151
+ allow(@response).to receive(:code) { "200" }
152
+ allow(@response).to receive(:content_type) { "application/json" }
153
+ end
154
+
155
+ it "parses empty object JSON correctly" do
156
+ allow(@response).to receive(:body) { "{}" }
157
+ payload = {
158
+ :response => @response
159
+ }
160
+
161
+ formatted_response = @api.format_response(payload)
162
+ expect(formatted_response).to_not be_nil
163
+ expect(formatted_response[:data]).to eq({})
164
+ end
165
+
166
+ it "parses empty string JSON correctly" do
167
+ allow(@response).to receive(:body) { '""' }
168
+ payload = {
169
+ :response => @response
170
+ }
171
+
172
+ formatted_response = @api.format_response(payload)
173
+ expect(formatted_response).to_not be_nil
174
+ expect(formatted_response[:data]).to eq("")
175
+ end
176
+
177
+ it "parses whitespace body correctly" do
178
+ allow(@response).to receive(:body) { ' ' }
179
+ payload = {
180
+ :response => @response
181
+ }
182
+
183
+ formatted_response = @api.format_response(payload)
184
+ expect(formatted_response).to_not be_nil
185
+ expect(formatted_response[:data]).to eq({})
186
+ end
187
+
188
+ it "parses nil body correctly" do
189
+ allow(@response).to receive(:body) { nil }
190
+ payload = {
191
+ :response => @response
192
+ }
193
+
194
+ formatted_response = @api.format_response(payload)
195
+ expect(formatted_response).to_not be_nil
196
+ expect(formatted_response[:data]).to eq({})
197
+ end
198
+
199
+ it "parses with whitespace around JSON correctly" do
200
+ allow(@response).to receive(:body) { ' { "test": "value" } ' }
201
+ payload = {
202
+ :response => @response
203
+ }
204
+
205
+ formatted_response = @api.format_response(payload)
206
+ expect(formatted_response).to_not be_nil
207
+ expect(formatted_response[:data]).to eq({ "test" => "value" })
208
+ end
209
+ end
147
210
  end
@@ -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
@@ -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.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - PayPal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-02 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -124,6 +124,7 @@ files:
124
124
  - spec/payments_examples_spec.rb
125
125
  - spec/payouts_examples_spec.rb
126
126
  - spec/rest/data_types_spec.rb
127
+ - spec/rest/error_hash_spec.rb
127
128
  - spec/spec_helper.rb
128
129
  - spec/subscription_examples_spec.rb
129
130
  - spec/support/sample_data.rb
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
150
  version: '0'
150
151
  requirements: []
151
152
  rubyforge_project:
152
- rubygems_version: 2.6.7
153
+ rubygems_version: 2.6.11
153
154
  signing_key:
154
155
  specification_version: 4
155
156
  summary: The PayPal REST SDK provides Ruby APIs to create, process and manage payment.
@@ -170,6 +171,7 @@ test_files:
170
171
  - spec/payments_examples_spec.rb
171
172
  - spec/payouts_examples_spec.rb
172
173
  - spec/rest/data_types_spec.rb
174
+ - spec/rest/error_hash_spec.rb
173
175
  - spec/spec_helper.rb
174
176
  - spec/subscription_examples_spec.rb
175
177
  - spec/support/sample_data.rb