paypal-sdk-rest 1.4.7 → 1.4.8

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: 6caede99d228cdad852593c3f30716e8655bb0b4
4
- data.tar.gz: 60ed17097e21be9d538c49e60b93ed0af556c62f
3
+ metadata.gz: e01168b996d2cd17b84b6a61e05ae19af58d4691
4
+ data.tar.gz: 16f3f72b5c61e5c2b6745d7e2f43ec805b3a76d1
5
5
  SHA512:
6
- metadata.gz: 1c5029ab40c1bc6d42ef395fdc6ac1900e7f6e52c2d8e468e3d936d420c38a141be2e2de8b958df56a37b91ed12ad62959cf7d1121054fcba4de120f0a8a4f57
7
- data.tar.gz: bb6c7d3eead1be286fdf3c7d45dfd702ab52cc6a7b83cc89526a5769c69948ea72f0f4444ecb5905a33163b25bead559562d2aa19174339cddbbeee8ed61e00b
6
+ metadata.gz: 0452d37fb1b03f9b40ba21085567010cedab37451f74fc05217d4f76c5dd212aa96805a2d8718ec1eba81c6c720b4693a3b477e3d76dd0bfeaeaef1217edfb05
7
+ data.tar.gz: bc894c391a9e1eece74d1d43ed9032bede1a7065c2c88ba4564179ea0aacdc9235af17b5c295bef9cfbbccb4419eed6ddffe56744ed97ef84c83525e479d0241
data/Gemfile CHANGED
@@ -11,4 +11,4 @@ group :test do
11
11
  gem 'rspec'
12
12
  end
13
13
 
14
- gem 'releasinator', '~> 0.4'
14
+ gem 'releasinator', '~> 0.6'
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- ## PayPal REST API Ruby SDK [![Build Status](https://travis-ci.org/paypal/PayPal-Ruby-SDK.svg?branch=master)](https://travis-ci.org/paypal/PayPal-Ruby-SDK)
1
+ ## PayPal REST API Ruby SDK [![Build Status](https://travis-ci.org/paypal/PayPal-Ruby-SDK.svg?branch=master)](https://travis-ci.org/paypal/PayPal-Ruby-SDK) [![Coverage Status](https://coveralls.io/repos/github/paypal/PayPal-Ruby-SDK/badge.svg?branch=master)](https://coveralls.io/github/paypal/PayPal-Ruby-SDK?branch=master)
2
+
2
3
 
3
4
  The PayPal REST SDK provides Ruby APIs to create, process and manage payment.
4
5
 
@@ -276,4 +277,4 @@ end
276
277
  Code released under [SDK LICENSE](LICENSE)
277
278
 
278
279
  ## Contributions
279
- Pull requests and new issues are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
280
+ Pull requests and new issues are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
data/Rakefile CHANGED
@@ -1,5 +1,11 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ # release will instead be declared by the releasinator
4
+ Rake::Task["release"].clear
5
+
6
+ spec = Gem::Specification.find_by_name 'releasinator'
7
+ load "#{spec.gem_dir}/lib/tasks/releasinator.rake"
8
+
3
9
  desc "Run tests"
4
10
  task :rspec do
5
11
  cmd = "bundle exec rspec -f d"
@@ -7,6 +13,3 @@ task :rspec do
7
13
  end
8
14
 
9
15
  task :default => :rspec
10
-
11
- spec = Gem::Specification.find_by_name 'releasinator'
12
- load "#{spec.gem_dir}/lib/tasks/releasinator.rake"
@@ -94,5 +94,15 @@ module PayPal::SDK::Core
94
94
  @response['Allow'].split(',').map { |verb| verb.strip.downcase.to_sym }
95
95
  end
96
96
  end
97
+
98
+ # API error: returned as 200 + "error" key in response.
99
+ class UnsuccessfulApiCall < RuntimeError
100
+ attr_reader :api_error
101
+
102
+ def initialize(api_error)
103
+ super(api_error['message'])
104
+ @api_error = api_error
105
+ end
106
+ end
97
107
  end
98
108
  end
@@ -33,9 +33,21 @@ module PayPal::SDK
33
33
  super
34
34
  end
35
35
 
36
+ def raise_error!
37
+ raise Core::Exceptions::UnsuccessfulApiCall, error if error
38
+ end
39
+
36
40
  def self.load_members
37
41
  end
38
42
 
43
+ def self.raise_on_api_error(*methods)
44
+ methods.each do |symbol|
45
+ define_method("#{symbol}!") {|*arg|
46
+ raise_error! unless send(symbol, *arg)
47
+ }
48
+ end
49
+ end
50
+
39
51
  class Number < Float
40
52
  end
41
53
  end
@@ -92,6 +104,20 @@ module PayPal::SDK
92
104
  success?
93
105
  end
94
106
 
107
+ raise_on_api_error :create, :update, :execute
108
+
109
+ def approval_url(immediate = false)
110
+ link = links.detect { |l| l.rel == 'approval_url' }
111
+ return nil unless link
112
+ link.href + (immediate ? '&useraction=commit' : '')
113
+ end
114
+
115
+ def token
116
+ url = approval_url
117
+ return nil unless url
118
+ CGI.parse(URI.parse(url).query)['token'].first
119
+ end
120
+
95
121
  class << self
96
122
  def find(resource_id)
97
123
  raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
@@ -245,6 +271,8 @@ module PayPal::SDK
245
271
  success?
246
272
  end
247
273
 
274
+ raise_on_api_error :create
275
+
248
276
  class << self
249
277
 
250
278
  def exch_token(auth_code)
@@ -334,6 +362,8 @@ module PayPal::SDK
334
362
  self.merge!(response)
335
363
  success?
336
364
  end
365
+
366
+ raise_on_api_error :create, :update, :delete
337
367
  end
338
368
 
339
369
  class Address < Base
@@ -446,6 +476,8 @@ module PayPal::SDK
446
476
  self.merge!(response)
447
477
  success?
448
478
  end
479
+
480
+ raise_on_api_error :create, :update, :delete
449
481
  end
450
482
 
451
483
  class ExtendedBankAccount < BankAccount
@@ -839,6 +871,8 @@ module PayPal::SDK
839
871
  self.merge!(response)
840
872
  success?
841
873
  end
874
+
875
+ raise_on_api_error :capture, :void, :reauthorize
842
876
  end
843
877
 
844
878
  class Order < Base
@@ -888,6 +922,8 @@ module PayPal::SDK
888
922
  response = api.post(path, self.to_hash, http_header)
889
923
  Authorization.new(response)
890
924
  end
925
+
926
+ raise_on_api_error :capture, :void, :authorize
891
927
  end
892
928
 
893
929
  class Capture < Base
@@ -1095,6 +1131,7 @@ module PayPal::SDK
1095
1131
  array_of :items, InvoiceItem
1096
1132
  object_of :invoice_date, String
1097
1133
  object_of :payment_term, PaymentTerm
1134
+ object_of :reference, String
1098
1135
  object_of :discount, Cost
1099
1136
  object_of :shipping_cost, ShippingCost
1100
1137
  object_of :custom, CustomAmount
@@ -1173,6 +1210,10 @@ module PayPal::SDK
1173
1210
  success?
1174
1211
  end
1175
1212
 
1213
+ raise_on_api_error :create, :send_invoice, :remind, :cancel,
1214
+ :record_payment, :record_refund, :update, :delete
1215
+
1216
+
1176
1217
  #
1177
1218
  class << self
1178
1219
  def search(options, access_token = nil)
@@ -1287,7 +1328,8 @@ module PayPal::SDK
1287
1328
  end
1288
1329
 
1289
1330
  def get_expected_sig(transmission_id, timestamp, webhook_id, event_body)
1290
- crc = Zlib::crc32(event_body).to_s
1331
+ utf8_encoded_event_body = event_body.encode("UTF-8")
1332
+ crc = Zlib::crc32(utf8_encoded_event_body).to_s
1291
1333
  transmission_id + "|" + timestamp + "|" + webhook_id + "|" + crc
1292
1334
  end
1293
1335
 
@@ -1383,6 +1425,8 @@ module PayPal::SDK
1383
1425
  success?
1384
1426
  end
1385
1427
 
1428
+ raise_on_api_error :update, :delete
1429
+
1386
1430
  class << self
1387
1431
  def get(webhook_id)
1388
1432
  raise ArgumentError.new("webhook_id required") if webhook_id.to_s.strip.empty?
@@ -1772,6 +1816,8 @@ module PayPal::SDK
1772
1816
  success?
1773
1817
  end
1774
1818
 
1819
+ raise_on_api_error :create, :update
1820
+
1775
1821
  class << self
1776
1822
  def find(resource_id)
1777
1823
  raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
@@ -1989,6 +2035,9 @@ module PayPal::SDK
1989
2035
  success?
1990
2036
  end
1991
2037
 
2038
+ raise_on_api_error :create, :execute, :update, :suspend, :re_activate,
2039
+ :cancel, :bill_balance, :set_balance
2040
+
1992
2041
  class << self
1993
2042
  def transactions(agreement_id, start_date, end_date, options = {})
1994
2043
  path = "v1/payments/billing-agreements/#{agreement_id}/transactions" #?start-date=#{start_date}&end-date=#{end_date}"
@@ -2095,6 +2144,8 @@ module PayPal::SDK
2095
2144
  success?
2096
2145
  end
2097
2146
 
2147
+ raise_on_api_error :update, :partial_update, :delete
2148
+
2098
2149
  class << self
2099
2150
  def find(resource_id)
2100
2151
  raise ArgumentError.new("id required") if resource_id.to_s.strip.empty?
@@ -1,7 +1,7 @@
1
1
  module PayPal
2
2
  module SDK
3
3
  module REST
4
- VERSION = "1.4.7"
4
+ VERSION = "1.4.8"
5
5
  end
6
6
  end
7
7
  end
@@ -24,6 +24,21 @@ describe "Payments" do
24
24
  "currency" => "USD" },
25
25
  "description" => "This is the payment transaction description." } ] }
26
26
 
27
+ PaymentAttributesPayPal = {
28
+ "intent" => "sale",
29
+ "payer" => {
30
+ "payment_method" => "paypal"
31
+ },
32
+ "redirect_urls" => {
33
+ "return_url" => 'https://localhost/return',
34
+ "cancel_url" => 'https://localhost/cancel',
35
+ },
36
+ "transactions" => [ {
37
+ "amount" => {
38
+ "total" => "1.00",
39
+ "currency" => "USD" },
40
+ "description" => "This is the payment transaction description." } ] }
41
+
27
42
  FuturePaymentAttributes = {
28
43
  "intent" => "authorize",
29
44
  "payer" => {
@@ -56,6 +71,8 @@ describe "Payments" do
56
71
  payment.create
57
72
  expect(payment.error).to be_nil
58
73
  expect(payment.id).not_to be_nil
74
+ expect(payment.approval_url).to be_nil
75
+ expect(payment.token).to be_nil
59
76
  end
60
77
 
61
78
  it "Create with request_id" do
@@ -91,6 +108,18 @@ describe "Payments" do
91
108
  expect(payment.id).not_to be_nil
92
109
  end
93
110
 
111
+ it "Create with redirect urls" do
112
+ payment = Payment.new(PaymentAttributesPayPal)
113
+ # Create
114
+ payment.create
115
+ expect(payment.error).to be_nil
116
+ expect(payment.id).not_to be_nil
117
+ expect(payment.approval_url).to include('webscr?cmd=_express-checkout')
118
+ expect(payment.approval_url).not_to include('useraction=commit')
119
+ expect(payment.approval_url(true)).to eq payment.approval_url + '&useraction=commit'
120
+ expect(payment.token).to match /^EC-[A-Z0-9]+$/
121
+ end
122
+
94
123
  it "List" do
95
124
  payment_history = Payment.all( "count" => 5 )
96
125
  expect(payment_history.error).to be_nil
@@ -163,7 +192,7 @@ describe "Payments" do
163
192
 
164
193
  it "Create a payment" do
165
194
  # put your PAYPAL-CLIENT-METADATA-ID
166
- correlation_id = ''
195
+ correlation_id = ''
167
196
  @future_payment = FuturePayment.new(FuturePaymentAttributes.merge( :token => access_token ))
168
197
  @future_payment.create(correlation_id)
169
198
  expect(@future_payment.error).to be_nil
@@ -0,0 +1,62 @@
1
+ module PayPal::SDK::REST::DataTypes
2
+ describe Base do
3
+ let(:error_object) {
4
+ {
5
+ "name" => "INVALID_EXPERIENCE_PROFILE_ID",
6
+ "message" => "The requested experience profile ID was not found",
7
+ "information_link" => "https://developer.paypal.com/docs/api/#INVALID_EXPERIENCE_PROFILE_ID",
8
+ "debug_id" => "1562931a79fd2"
9
+ }
10
+ }
11
+
12
+ context '#raise_error!' do
13
+ context 'when there is error' do
14
+ subject { described_class.new(error: error_object) }
15
+
16
+ it 'raises error on request with all API information' do
17
+ expect { subject.raise_error! }
18
+ .to raise_error { |err|
19
+ expect(err).to be_a(PayPal::SDK::Core::Exceptions::UnsuccessfulApiCall)
20
+ expect(err.message).to eq("The requested experience profile ID was not found")
21
+ expect(err.api_error).to eq(error_object)
22
+ }
23
+ end
24
+ end
25
+
26
+ context 'when there is no error' do
27
+ subject { described_class.new(error: nil) }
28
+
29
+ it { expect { subject.raise_error! }.not_to raise_error }
30
+ end
31
+ end
32
+
33
+ context '.raise_on_api_error' do
34
+ let(:klass) {
35
+ Class.new(described_class) do
36
+ def some_call
37
+ end
38
+
39
+ raise_on_api_error :some_call
40
+ end
41
+ }
42
+
43
+ subject { klass.new }
44
+
45
+ context 'when call is successful' do
46
+ before {
47
+ expect(subject).to receive(:some_call).and_return(true)
48
+ }
49
+ it { expect { subject.some_call! }.not_to raise_error }
50
+ end
51
+
52
+ context 'when call is unsuccessful' do
53
+ before {
54
+ expect(subject).to receive(:some_call).and_return(false)
55
+ expect(subject).to receive(:error).twice.and_return(error_object)
56
+ }
57
+
58
+ it { expect { subject.some_call! }.to raise_error(PayPal::SDK::Core::Exceptions::UnsuccessfulApiCall) }
59
+ end
60
+ end
61
+ end
62
+ end
@@ -2,6 +2,8 @@ require 'bundler/setup'
2
2
 
3
3
  if ENV['COVERAGE']
4
4
  require 'simplecov'
5
+ require 'coveralls'
6
+ Coveralls.wear!
5
7
  SimpleCov.start do
6
8
  add_filter "/spec/"
7
9
  end
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.7
4
+ version: 1.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - PayPal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2016-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -137,6 +137,7 @@ files:
137
137
  - spec/log/rest_http.log
138
138
  - spec/payments_examples_spec.rb
139
139
  - spec/payouts_examples_spec.rb
140
+ - spec/rest/data_types_spec.rb
140
141
  - spec/spec_helper.rb
141
142
  - spec/subscription_examples_spec.rb
142
143
  - spec/support/sample_data.rb
@@ -182,6 +183,7 @@ test_files:
182
183
  - spec/log/rest_http.log
183
184
  - spec/payments_examples_spec.rb
184
185
  - spec/payouts_examples_spec.rb
186
+ - spec/rest/data_types_spec.rb
185
187
  - spec/spec_helper.rb
186
188
  - spec/subscription_examples_spec.rb
187
189
  - spec/support/sample_data.rb