ianfleeton-paypal-express 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +4 -3
- data/VERSION +1 -1
- data/lib/paypal/nvp/request.rb +1 -1
- data/lib/paypal/util.rb +11 -3
- data/spec/paypal/express/request_spec.rb +6 -5
- data/spec/paypal/payment/common/amount_spec.rb +3 -1
- data/spec/paypal/payment/request_spec.rb +11 -12
- data/spec/paypal/payment/response/info_spec.rb +1 -1
- data/spec/paypal/util_spec.rb +12 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 860b0d8f5a56c23d0d48d2306949be8ab7687e93cb8c54d57c875f5d44ebb349
|
4
|
+
data.tar.gz: d36695184583cef8c027cfab2b150fcb9b348a5a2d8de0823b6b6b017bc59d45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c703ea1e91682f791c9adac0babfa33282a721380ebd082d65c3a0967c4c3cd3f14b5d12ea90ba2d12c7d5f5a59f6c9e189adf4ef2b6915945bd669694c7abe8
|
7
|
+
data.tar.gz: 3e9de3ff947c7d5fd75bfb7c21e4aa16c70d857ec64f7a6eb8172fd05b98fd209c514b5f4ca74a1c6f105344ba507201b0a02f342a0c81a357972f74b386cc31
|
data/.travis.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.4
|
data/lib/paypal/nvp/request.rb
CHANGED
@@ -50,7 +50,7 @@ module Paypal
|
|
50
50
|
def handle_response
|
51
51
|
response = yield
|
52
52
|
response = CGI.parse(response).inject({}) do |res, (k, v)|
|
53
|
-
res.merge!(k.to_sym => v.first)
|
53
|
+
res.merge!(k.to_sym => v.first.to_s)
|
54
54
|
end
|
55
55
|
case response[:ACK]
|
56
56
|
when 'Success', 'SuccessWithWarning'
|
data/lib/paypal/util.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
1
|
+
require "bigdecimal"
|
2
|
+
|
1
3
|
module Paypal
|
2
4
|
module Util
|
3
5
|
|
4
6
|
def self.formatted_amount(x)
|
5
|
-
|
7
|
+
x = '0' if x == '' || x.nil?
|
8
|
+
sprintf '%0.2f', BigDecimal.new(x.to_s).round(2)
|
6
9
|
end
|
7
10
|
|
8
11
|
def self.to_numeric(x)
|
9
|
-
|
12
|
+
string = x.to_s
|
13
|
+
string = "0" if string == "" # Ruby 2.5 compatibility.
|
14
|
+
|
15
|
+
decimal = BigDecimal(string)
|
16
|
+
|
17
|
+
if decimal == x.to_i
|
10
18
|
x.to_i
|
11
19
|
else
|
12
|
-
|
20
|
+
decimal
|
13
21
|
end
|
14
22
|
end
|
15
23
|
|
@@ -8,7 +8,8 @@ describe Paypal::Express::Request do
|
|
8
8
|
self._sent_params_ = params
|
9
9
|
post_without_logging method, params
|
10
10
|
end
|
11
|
-
|
11
|
+
alias_method :post_without_logging, :post
|
12
|
+
alias_method :post, :post_with_logging
|
12
13
|
end
|
13
14
|
|
14
15
|
let(:return_url) { 'http://example.com/success' }
|
@@ -39,7 +40,7 @@ describe Paypal::Express::Request do
|
|
39
40
|
items << Paypal::Payment::Request::Item.new(
|
40
41
|
:name => "Item#{index.to_s}",
|
41
42
|
:description => "A new Item #{index.to_s}",
|
42
|
-
:
|
43
|
+
amount: BigDecimal('50.00'),
|
43
44
|
:quantity => 1
|
44
45
|
)
|
45
46
|
end
|
@@ -266,20 +267,20 @@ describe Paypal::Express::Request do
|
|
266
267
|
describe "#capture!" do
|
267
268
|
it 'should return Paypal::Express::Response' do
|
268
269
|
fake_response 'DoCapture/success'
|
269
|
-
response = instance.capture! 'authorization_id', 181.98, :BRL
|
270
|
+
response = instance.capture! 'authorization_id', BigDecimal('181.98'), :BRL
|
270
271
|
expect(response).to be_instance_of Paypal::Express::Response
|
271
272
|
end
|
272
273
|
|
273
274
|
it 'should call DoExpressCheckoutPayment' do
|
274
275
|
expect do
|
275
|
-
instance.capture! 'authorization_id', 181.98, :BRL
|
276
|
+
instance.capture! 'authorization_id', BigDecimal('181.98'), :BRL
|
276
277
|
end.to request_to nvp_endpoint, :post
|
277
278
|
|
278
279
|
expect(instance._method_).to eq(:DoCapture)
|
279
280
|
expect(instance._sent_params_).to eq({
|
280
281
|
:AUTHORIZATIONID => 'authorization_id',
|
281
282
|
:COMPLETETYPE => 'Complete',
|
282
|
-
:
|
283
|
+
AMT: BigDecimal('181.98'),
|
283
284
|
:CURRENCYCODE => :BRL
|
284
285
|
})
|
285
286
|
end
|
@@ -29,7 +29,9 @@ describe Paypal::Payment::Common::Amount do
|
|
29
29
|
end
|
30
30
|
amount = Paypal::Payment::Common::Amount.new attributes
|
31
31
|
keys.each do |key|
|
32
|
-
|
32
|
+
actual = amount.send(key)
|
33
|
+
expect(actual).to be_a(BigDecimal)
|
34
|
+
expect(actual).to eq BigDecimal('10.25')
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -3,9 +3,9 @@ require 'spec_helper.rb'
|
|
3
3
|
describe Paypal::Payment::Request do
|
4
4
|
let :instant_request do
|
5
5
|
Paypal::Payment::Request.new(
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
6
|
+
amount: BigDecimal('25.7'),
|
7
|
+
tax_amount: BigDecimal('0.4'),
|
8
|
+
shipping_amount: BigDecimal('1.5'),
|
9
9
|
:currency_code => :JPY,
|
10
10
|
:description => 'Instant Payment Request',
|
11
11
|
:notify_url => 'http://merchant.example.com/notify',
|
@@ -15,12 +15,12 @@ describe Paypal::Payment::Request do
|
|
15
15
|
:quantity => 2,
|
16
16
|
:name => 'Item1',
|
17
17
|
:description => 'Awesome Item 1!',
|
18
|
-
:amount => 10.25
|
18
|
+
:amount => BigDecimal("10.25")
|
19
19
|
}, {
|
20
20
|
:quantity => 3,
|
21
21
|
:name => 'Item2',
|
22
22
|
:description => 'Awesome Item 2!',
|
23
|
-
:
|
23
|
+
amount: BigDecimal('1.1')
|
24
24
|
}],
|
25
25
|
:custom_fields => {
|
26
26
|
"l_surveychoice{n}" => 'abcd' # The '{n}' will be replaced with the index
|
@@ -46,9 +46,9 @@ describe Paypal::Payment::Request do
|
|
46
46
|
|
47
47
|
describe '.new' do
|
48
48
|
it 'should handle Instant Payment parameters' do
|
49
|
-
expect(instant_request.amount.total).to eq(25.7)
|
50
|
-
expect(instant_request.amount.tax).to eq(0.4)
|
51
|
-
expect(instant_request.amount.shipping).to eq(1.5)
|
49
|
+
expect(instant_request.amount.total).to eq(BigDecimal('25.7'))
|
50
|
+
expect(instant_request.amount.tax).to eq(BigDecimal('0.4'))
|
51
|
+
expect(instant_request.amount.shipping).to eq(BigDecimal('1.5'))
|
52
52
|
expect(instant_request.currency_code).to eq(:JPY)
|
53
53
|
expect(instant_request.description).to eq('Instant Payment Request')
|
54
54
|
expect(instant_request.notify_url).to eq('http://merchant.example.com/notify')
|
@@ -115,22 +115,21 @@ describe Paypal::Payment::Request do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
describe '#items_amount' do
|
118
|
-
context 'when BigDecimal'
|
119
118
|
let(:instance) do
|
120
119
|
Paypal::Payment::Request.new(
|
121
120
|
:items => [{
|
122
121
|
:quantity => 3,
|
123
122
|
:name => 'Item1',
|
124
123
|
:description => 'Awesome Item 1!',
|
125
|
-
:amount => 130.45
|
124
|
+
:amount => BigDecimal("130.45")
|
126
125
|
}]
|
127
126
|
)
|
128
127
|
end
|
129
128
|
|
130
|
-
# NOTE:
|
129
|
+
# NOTE: with floats,
|
131
130
|
# 130.45 * 3 => 391.34999999999997 (in ruby 1.9)
|
132
131
|
it 'should calculate total amount correctly' do
|
133
|
-
expect(instance.items_amount).to eq(391.35)
|
132
|
+
expect(instance.items_amount).to eq(BigDecimal('391.35'))
|
134
133
|
end
|
135
134
|
end
|
136
135
|
end
|
data/spec/paypal/util_spec.rb
CHANGED
@@ -5,28 +5,28 @@ describe Paypal::Util do
|
|
5
5
|
it 'should return String in "xx.yy" format' do
|
6
6
|
expect(Paypal::Util.formatted_amount(nil)).to eq('0.00')
|
7
7
|
expect(Paypal::Util.formatted_amount(10)).to eq('10.00')
|
8
|
-
expect(Paypal::Util.formatted_amount(10.02)).to eq('10.02')
|
9
|
-
expect(Paypal::Util.formatted_amount(10.2)).to eq('10.20')
|
10
|
-
expect(Paypal::Util.formatted_amount(10.24)).to eq('10.24')
|
11
|
-
expect(Paypal::Util.formatted_amount(10.255)).to eq('10.
|
8
|
+
expect(Paypal::Util.formatted_amount(BigDecimal('10.02'))).to eq('10.02')
|
9
|
+
expect(Paypal::Util.formatted_amount(BigDecimal('10.2'))).to eq('10.20')
|
10
|
+
expect(Paypal::Util.formatted_amount(BigDecimal('10.24'))).to eq('10.24')
|
11
|
+
expect(Paypal::Util.formatted_amount(BigDecimal('10.255'))).to eq('10.26')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '.to_numeric' do
|
16
|
-
it 'should return
|
16
|
+
it 'should return Integer or BigDecimal' do
|
17
17
|
expect(Paypal::Util.to_numeric('10')).to be_kind_of(Integer)
|
18
|
-
expect(Paypal::Util.to_numeric('10.5')).to be_kind_of(
|
19
|
-
expect(Paypal::Util.to_numeric('-1.5')).to eq(-1.5)
|
18
|
+
expect(Paypal::Util.to_numeric('10.5')).to be_kind_of(BigDecimal)
|
19
|
+
expect(Paypal::Util.to_numeric('-1.5')).to eq(BigDecimal('-1.5'))
|
20
20
|
expect(Paypal::Util.to_numeric('-1')).to eq(-1)
|
21
21
|
expect(Paypal::Util.to_numeric('0')).to eq(0)
|
22
22
|
expect(Paypal::Util.to_numeric('0.00')).to eq(0)
|
23
23
|
expect(Paypal::Util.to_numeric('10')).to eq(10)
|
24
24
|
expect(Paypal::Util.to_numeric('10.00')).to eq(10)
|
25
|
-
expect(Paypal::Util.to_numeric('10.02')).to eq(10.02)
|
26
|
-
expect(Paypal::Util.to_numeric('10.2')).to eq(10.2)
|
27
|
-
expect(Paypal::Util.to_numeric('10.20')).to eq(10.2)
|
28
|
-
expect(Paypal::Util.to_numeric('10.24')).to eq(10.24)
|
29
|
-
expect(Paypal::Util.to_numeric('10.25')).to eq(10.25)
|
25
|
+
expect(Paypal::Util.to_numeric('10.02')).to eq(BigDecimal('10.02'))
|
26
|
+
expect(Paypal::Util.to_numeric('10.2')).to eq(BigDecimal('10.2'))
|
27
|
+
expect(Paypal::Util.to_numeric('10.20')).to eq(BigDecimal('10.2'))
|
28
|
+
expect(Paypal::Util.to_numeric('10.24')).to eq(BigDecimal('10.24'))
|
29
|
+
expect(Paypal::Util.to_numeric('10.25')).to eq(BigDecimal('10.25'))
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ianfleeton-paypal-express
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Fleeton
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -254,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
254
|
version: 1.3.6
|
255
255
|
requirements: []
|
256
256
|
rubyforge_project:
|
257
|
-
rubygems_version: 2.6
|
257
|
+
rubygems_version: 2.7.6
|
258
258
|
signing_key:
|
259
259
|
specification_version: 4
|
260
260
|
summary: PayPal Express Checkout API Client for Instance, Recurring and Digital Goods
|