mymoip 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -14
- data/README.md +106 -56
- data/Rakefile +9 -44
- data/lib/mymoip/request.rb +4 -0
- data/lib/mymoip.rb +8 -0
- data/mymoip.gemspec +3 -15
- data/test/live_test.rb +1 -1
- metadata +3 -15
- data/VERSION +0 -1
- data/test/helper.rb +0 -29
- data/test/test_commission.rb +0 -121
- data/test/test_credit_card_payment.rb +0 -114
- data/test/test_creditcard.rb +0 -150
- data/test/test_formatter.rb +0 -49
- data/test/test_instruction.rb +0 -217
- data/test/test_mymoip.rb +0 -81
- data/test/test_payer.rb +0 -219
- data/test/test_payment_request.rb +0 -96
- data/test/test_request.rb +0 -50
- data/test/test_transparent_request.rb +0 -71
data/Gemfile
CHANGED
@@ -1,15 +1,4 @@
|
|
1
|
-
source '
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem
|
4
|
-
|
5
|
-
gem 'activemodel'
|
6
|
-
|
7
|
-
group :development do
|
8
|
-
gem 'rdoc', '~> 3.12'
|
9
|
-
gem 'bundler', '>= 0'
|
10
|
-
gem 'jeweler', '~> 1.8.4'
|
11
|
-
gem 'turn'
|
12
|
-
gem 'mocha', require: false
|
13
|
-
gem 'vcr'
|
14
|
-
gem 'webmock'
|
15
|
-
end
|
3
|
+
# Specify your gem's dependencies in new_gem.gemspec
|
4
|
+
gemspec
|
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
MoIP transactions in a gem to call your own.
|
4
4
|
|
5
|
-
|
5
|
+
The easier way to use Moip's transparent checkout.
|
6
6
|
|
7
|
-
Planning to use with Rails? Check [my_moip-rails](https://github.com/Irio/my_moip-rails).
|
7
|
+
Planning to use with Rails? Check [my_moip-rails](https://github.com/Irio/my_moip-rails) too.
|
8
8
|
|
9
9
|
## Contributing to MyMoip
|
10
10
|
|
@@ -14,80 +14,130 @@ Climate](https://codeclimate.com/github/Irio/mymoip.png)](https://codeclimate.co
|
|
14
14
|
|
15
15
|
What would you do if you could make your own implementation of MoIP?
|
16
16
|
|
17
|
-
Any patch are welcome, even removing extra
|
17
|
+
Any patch are welcome, even removing extra white spaces.
|
18
18
|
|
19
19
|
1. Open a pull request.
|
20
20
|
2. Done.
|
21
21
|
|
22
|
-
|
22
|
+
# Using
|
23
23
|
|
24
|
-
|
24
|
+
## First of all
|
25
25
|
|
26
26
|
**Bundler - Gemfile**
|
27
27
|
```ruby
|
28
28
|
gem 'mymoip'
|
29
29
|
```
|
30
30
|
|
31
|
-
|
31
|
+
**Configuration**
|
32
32
|
```ruby
|
33
|
-
MyMoip.environment =
|
33
|
+
MyMoip.environment = 'production' # 'sandbox' by default
|
34
34
|
|
35
|
-
MyMoip.sandbox_token =
|
36
|
-
MyMoip.sandbox_key =
|
35
|
+
MyMoip.sandbox_token = 'your_moip_sandbox_token'
|
36
|
+
MyMoip.sandbox_key = 'your_moip_sandbox_key'
|
37
37
|
|
38
|
-
MyMoip.production_token =
|
39
|
-
MyMoip.production_key =
|
38
|
+
MyMoip.production_token = 'your_moip_production_token'
|
39
|
+
MyMoip.production_key = 'your_moip_production_key'
|
40
40
|
```
|
41
41
|
|
42
|
-
|
42
|
+
## The easy way
|
43
43
|
|
44
|
+
If you just need to pass some attributes and get if the payment based on them was succesfull or not, this can be your start point.
|
45
|
+
|
46
|
+
The payer attributes will be sent to Moip to be stored as your client, identified by... his id. If you don't want to, on each payment, ask your user to all his data, you can always save them in your database.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
purchase_id = 'UNIQUE_PURCHASE_ID'
|
50
|
+
transaction_price = 100.0
|
51
|
+
|
52
|
+
card_attrs = {
|
53
|
+
logo: 'visa',
|
54
|
+
card_number: '4916654211627608',
|
55
|
+
expiration_date: '06/15',
|
56
|
+
security_code: '000',
|
57
|
+
owner_name: 'Juquinha da Rocha',
|
58
|
+
owner_birthday: '03/11/1980',
|
59
|
+
owner_phone: '5130405060',
|
60
|
+
owner_cpf: '52211670695'
|
61
|
+
}
|
62
|
+
|
63
|
+
payer_attrs = {
|
64
|
+
id: 'payer_id_defined_by_you',
|
65
|
+
name: 'Juquinha da Rocha',
|
66
|
+
email: 'juquinha@rocha.com',
|
67
|
+
address_street: 'Felipe Neri',
|
68
|
+
address_street_number: '406',
|
69
|
+
address_street_extra: 'Sala 501',
|
70
|
+
address_neighbourhood: 'Auxiliadora',
|
71
|
+
address_city: 'Porto Alegre',
|
72
|
+
address_state: 'RS',
|
73
|
+
address_country: 'BRA',
|
74
|
+
address_cep: '90440150',
|
75
|
+
address_phone: '5130405060'
|
76
|
+
}
|
77
|
+
|
78
|
+
purchase = MyMoip::Purchase.new(
|
79
|
+
id: purchase_id,
|
80
|
+
price: transaction_price,
|
81
|
+
reason: 'Payment of my product',
|
82
|
+
credit_card: card_attrs,
|
83
|
+
payer: payer_attrs
|
84
|
+
)
|
85
|
+
purchase.checkout! # => true OR false (succesfull state)
|
86
|
+
purchase.code # Moip code or nil, depending of the checkout's return
|
87
|
+
```
|
88
|
+
|
89
|
+
## The hard way
|
90
|
+
|
91
|
+
**First request: what and from who**
|
44
92
|
```ruby
|
45
93
|
payer = MyMoip::Payer.new(
|
46
|
-
id:
|
47
|
-
name:
|
48
|
-
email:
|
49
|
-
address_street:
|
50
|
-
address_street_number:
|
51
|
-
address_street_extra:
|
52
|
-
address_neighbourhood:
|
53
|
-
address_city:
|
54
|
-
address_state:
|
55
|
-
address_country:
|
56
|
-
address_cep:
|
57
|
-
address_phone:
|
94
|
+
id: 'payer_id_defined_by_you',
|
95
|
+
name: 'Juquinha da Rocha',
|
96
|
+
email: 'juquinha@rocha.com',
|
97
|
+
address_street: 'Felipe Neri',
|
98
|
+
address_street_number: '406',
|
99
|
+
address_street_extra: 'Sala 501',
|
100
|
+
address_neighbourhood: 'Auxiliadora',
|
101
|
+
address_city: 'Porto Alegre',
|
102
|
+
address_state: 'RS',
|
103
|
+
address_country: 'BRA',
|
104
|
+
address_cep: '90440150',
|
105
|
+
address_phone: '5130405060'
|
58
106
|
)
|
59
107
|
|
60
108
|
instruction = MyMoip::Instruction.new(
|
61
|
-
id:
|
62
|
-
payment_reason:
|
63
|
-
values:
|
64
|
-
payer:
|
109
|
+
id: 'instruction_id_defined_by_you',
|
110
|
+
payment_reason: 'Order in Buy Everything Store',
|
111
|
+
values: [100.0],
|
112
|
+
payer: payer
|
65
113
|
)
|
66
114
|
|
67
|
-
transparent_request = MyMoip::TransparentRequest.new(
|
115
|
+
transparent_request = MyMoip::TransparentRequest.new('your_logging_id')
|
68
116
|
transparent_request.api_call(instruction)
|
69
117
|
```
|
70
118
|
|
71
|
-
|
119
|
+
**Second request: how**
|
72
120
|
|
73
121
|
```ruby
|
74
122
|
credit_card = MyMoip::CreditCard.new(
|
75
|
-
logo:
|
76
|
-
card_number:
|
77
|
-
expiration_date:
|
78
|
-
security_code:
|
79
|
-
owner_name:
|
80
|
-
owner_birthday:
|
81
|
-
owner_phone:
|
82
|
-
owner_cpf:
|
123
|
+
logo: 'visa',
|
124
|
+
card_number: '4916654211627608',
|
125
|
+
expiration_date: '06/15',
|
126
|
+
security_code: '000',
|
127
|
+
owner_name: 'Juquinha da Rocha',
|
128
|
+
owner_birthday: '03/11/1984',
|
129
|
+
owner_phone: '5130405060',
|
130
|
+
owner_cpf: '52211670695'
|
83
131
|
)
|
84
132
|
|
85
|
-
credit_card_payment = MyMoip::CreditCardPayment.new(credit_card,
|
86
|
-
|
87
|
-
payment_request
|
133
|
+
credit_card_payment = MyMoip::CreditCardPayment.new(credit_card,
|
134
|
+
installments: 1)
|
135
|
+
payment_request = MyMoip::PaymentRequest.new('your_logging_id')
|
136
|
+
payment_request.api_call(credit_card_payment,
|
137
|
+
token: transparent_request.token)
|
88
138
|
```
|
89
139
|
|
90
|
-
|
140
|
+
**Success?**
|
91
141
|
```ruby
|
92
142
|
payment_request.success?
|
93
143
|
```
|
@@ -106,27 +156,27 @@ Choosing between commission with fixed or percentage value.
|
|
106
156
|
|
107
157
|
```ruby
|
108
158
|
commissions = [MyMoip::Commission.new(
|
109
|
-
reason:
|
159
|
+
reason: 'System maintenance',
|
110
160
|
receiver_login: 'commissioned_moip_login',
|
111
|
-
fixed_value:
|
161
|
+
fixed_value: 15.0
|
112
162
|
)]
|
113
163
|
|
114
164
|
# OR
|
115
165
|
|
116
166
|
commissions = [MyMoip::Commission.new(
|
117
|
-
reason:
|
118
|
-
receiver_login:
|
167
|
+
reason: 'Shipping',
|
168
|
+
receiver_login: 'commissioned_moip_login',
|
119
169
|
percentage_value: 0.15
|
120
170
|
)]
|
121
171
|
```
|
122
172
|
|
123
173
|
```ruby
|
124
174
|
instruction = MyMoip::Instruction.new(
|
125
|
-
id:
|
126
|
-
payment_reason:
|
127
|
-
values:
|
128
|
-
payer:
|
129
|
-
commissions:
|
175
|
+
id: 'instruction_id_defined_by_you',
|
176
|
+
payment_reason: 'Order in Buy Everything Store',
|
177
|
+
values: [100.0],
|
178
|
+
payer: payer,
|
179
|
+
commissions: commissions
|
130
180
|
)
|
131
181
|
```
|
132
182
|
|
@@ -146,11 +196,11 @@ installments = [
|
|
146
196
|
]
|
147
197
|
|
148
198
|
MyMoip::Instruction.new(
|
149
|
-
id:
|
150
|
-
payment_reason:
|
151
|
-
values:
|
152
|
-
payer:
|
153
|
-
installments:
|
199
|
+
id: 'instruction_id_defined_by_you',
|
200
|
+
payment_reason: 'Order in Buy Everything Store',
|
201
|
+
values: [100.0],
|
202
|
+
payer: payer,
|
203
|
+
installments: installments
|
154
204
|
)
|
155
205
|
```
|
156
206
|
|
data/Rakefile
CHANGED
@@ -1,45 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "mymoip"
|
18
|
-
gem.homepage = "http://github.com/Irio/mymoip"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = "MoIP transactions in a gem to call your own."
|
21
|
-
gem.description = "Provides a implementation of MoIP's transparent checkout."
|
22
|
-
gem.email = "irio.musskopf@caixadeideias.com.br"
|
23
|
-
gem.authors = ["Irio Irineu Musskopf Junior"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
28
2
|
require 'rake/testtask'
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
require 'rdoc/task'
|
38
|
-
Rake::RDocTask.new do |rdoc|
|
39
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
-
|
41
|
-
rdoc.rdoc_dir = 'rdoc'
|
42
|
-
rdoc.title = "mymoip #{version}"
|
43
|
-
rdoc.rdoc_files.include('README*')
|
44
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
-
end
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << 'lib/mymoip'
|
6
|
+
t.test_files = FileList['test/test_*.rb']
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
task default: :test
|
data/lib/mymoip/request.rb
CHANGED
@@ -13,6 +13,10 @@ module MyMoip
|
|
13
13
|
opts[:username] ||= MyMoip.token
|
14
14
|
opts[:password] ||= MyMoip.key
|
15
15
|
|
16
|
+
unless opts[:username].present? && opts[:password].present?
|
17
|
+
MyMoip.ensure_key_and_token_set!
|
18
|
+
end
|
19
|
+
|
16
20
|
opts[:logger].info "New #{self.class} being sent to MoIP."
|
17
21
|
opts[:logger].debug "#{self.class} of ##{@id} with #{params.inspect}"
|
18
22
|
|
data/lib/mymoip.rb
CHANGED
@@ -35,6 +35,14 @@ module MyMoip
|
|
35
35
|
def token
|
36
36
|
send(:"#{environment}_token")
|
37
37
|
end
|
38
|
+
|
39
|
+
def ensure_key_and_token_set!
|
40
|
+
if MyMoip.key.blank?
|
41
|
+
raise StandardError, "Invalid MyMoip.#{environment}_key set."
|
42
|
+
elsif MyMoip.token.blank?
|
43
|
+
raise StandardError, "Invalid MyMoip.#{environment}_token set."
|
44
|
+
end
|
45
|
+
end
|
38
46
|
end
|
39
47
|
end
|
40
48
|
|
data/mymoip.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "mymoip"
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Irio Irineu Musskopf Junior"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-06-13"
|
13
13
|
s.description = "Provides a implementation of MoIP's transparent checkout."
|
14
14
|
s.email = "irio.musskopf@caixadeideias.com.br"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,7 +24,6 @@ Gem::Specification.new do |s|
|
|
24
24
|
"LICENSE.txt",
|
25
25
|
"README.md",
|
26
26
|
"Rakefile",
|
27
|
-
"VERSION",
|
28
27
|
"lib/mymoip.rb",
|
29
28
|
"lib/mymoip/commission.rb",
|
30
29
|
"lib/mymoip/credit_card.rb",
|
@@ -42,18 +41,7 @@ Gem::Specification.new do |s|
|
|
42
41
|
"test/fixtures/vcr_cassettes/payment_request.yml",
|
43
42
|
"test/fixtures/vcr_cassettes/transparent_request.yml",
|
44
43
|
"test/fixtures/vcr_cassettes/transparent_request_with_commissions.yml",
|
45
|
-
"test/
|
46
|
-
"test/live_test.rb",
|
47
|
-
"test/test_commission.rb",
|
48
|
-
"test/test_credit_card_payment.rb",
|
49
|
-
"test/test_creditcard.rb",
|
50
|
-
"test/test_formatter.rb",
|
51
|
-
"test/test_instruction.rb",
|
52
|
-
"test/test_mymoip.rb",
|
53
|
-
"test/test_payer.rb",
|
54
|
-
"test/test_payment_request.rb",
|
55
|
-
"test/test_request.rb",
|
56
|
-
"test/test_transparent_request.rb"
|
44
|
+
"test/live_test.rb"
|
57
45
|
]
|
58
46
|
s.homepage = "http://github.com/Irio/mymoip"
|
59
47
|
s.licenses = ["MIT"]
|
data/test/live_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mymoip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: builder
|
@@ -186,7 +186,6 @@ files:
|
|
186
186
|
- LICENSE.txt
|
187
187
|
- README.md
|
188
188
|
- Rakefile
|
189
|
-
- VERSION
|
190
189
|
- lib/mymoip.rb
|
191
190
|
- lib/mymoip/commission.rb
|
192
191
|
- lib/mymoip/credit_card.rb
|
@@ -204,18 +203,7 @@ files:
|
|
204
203
|
- test/fixtures/vcr_cassettes/payment_request.yml
|
205
204
|
- test/fixtures/vcr_cassettes/transparent_request.yml
|
206
205
|
- test/fixtures/vcr_cassettes/transparent_request_with_commissions.yml
|
207
|
-
- test/helper.rb
|
208
206
|
- test/live_test.rb
|
209
|
-
- test/test_commission.rb
|
210
|
-
- test/test_credit_card_payment.rb
|
211
|
-
- test/test_creditcard.rb
|
212
|
-
- test/test_formatter.rb
|
213
|
-
- test/test_instruction.rb
|
214
|
-
- test/test_mymoip.rb
|
215
|
-
- test/test_payer.rb
|
216
|
-
- test/test_payment_request.rb
|
217
|
-
- test/test_request.rb
|
218
|
-
- test/test_transparent_request.rb
|
219
207
|
homepage: http://github.com/Irio/mymoip
|
220
208
|
licenses:
|
221
209
|
- MIT
|
@@ -231,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
219
|
version: '0'
|
232
220
|
segments:
|
233
221
|
- 0
|
234
|
-
hash:
|
222
|
+
hash: 4071666260752952182
|
235
223
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
224
|
none: false
|
237
225
|
requirements:
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.6.0
|
data/test/helper.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'turn/autorun'
|
12
|
-
require 'mocha/setup'
|
13
|
-
require 'vcr'
|
14
|
-
|
15
|
-
VCR.configure do |c|
|
16
|
-
c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
|
17
|
-
c.hook_into :webmock
|
18
|
-
end
|
19
|
-
|
20
|
-
require 'live_test'
|
21
|
-
|
22
|
-
require 'fixtures/fixture'
|
23
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
24
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
25
|
-
|
26
|
-
Dir[File.dirname(__FILE__) + "/../lib/*.rb"].each { |file| require file }
|
27
|
-
|
28
|
-
MyMoip.logger = Logger.new("/dev/null")
|
29
|
-
$VERBOSE = nil
|
data/test/test_commission.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestCommission < Test::Unit::TestCase
|
4
|
-
def test_initialization_and_setters
|
5
|
-
params = {
|
6
|
-
reason: 'Because we can',
|
7
|
-
receiver_login: 'comissioned_indentifier',
|
8
|
-
fixed_value: 23.5,
|
9
|
-
percentage_value: 0.15
|
10
|
-
}
|
11
|
-
subject = MyMoip::Commission.new(params)
|
12
|
-
assert_equal params[:reason], subject.reason
|
13
|
-
assert_equal params[:receiver_login], subject.receiver_login
|
14
|
-
assert_equal params[:fixed_value], subject.fixed_value
|
15
|
-
assert_equal params[:percentage_value], subject.percentage_value
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_validate_presence_of_reason
|
19
|
-
subject = Fixture.commission(reason: nil)
|
20
|
-
assert subject.invalid? && subject.errors[:reason].present?,
|
21
|
-
"should be invalid without a reason"
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_validate_presence_of_receiver_login
|
25
|
-
subject = Fixture.commission(receiver_login: nil)
|
26
|
-
assert subject.invalid? && subject.errors[:receiver_login].present?,
|
27
|
-
"should be invalid without a receiver_login"
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_validate_presence_of_fixed_value_or_percentage_value
|
31
|
-
subject = Fixture.commission(fixed_value: nil, percentage_value: nil)
|
32
|
-
|
33
|
-
assert subject.invalid? && subject.errors[:fixed_value].present?,
|
34
|
-
"should be invalid without a fixed value"
|
35
|
-
|
36
|
-
assert subject.invalid? && subject.errors[:percentage_value].present?,
|
37
|
-
"should be invalid without a percentage value"
|
38
|
-
|
39
|
-
subject.fixed_value = 2
|
40
|
-
assert subject.valid?, "should be valid with only fixed value set"
|
41
|
-
|
42
|
-
subject.fixed_value = nil
|
43
|
-
subject.percentage_value = 0.15
|
44
|
-
assert subject.valid?, "should be valid with only percentage value set"
|
45
|
-
|
46
|
-
subject.fixed_value = subject.percentage_value
|
47
|
-
assert subject.valid?, "should be valid with both values set"
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
def test_validate_numericality_of_fixed_value
|
52
|
-
subject = Fixture.commission(fixed_value: "I'm not a number")
|
53
|
-
assert subject.invalid? && subject.errors[:fixed_value].present?,
|
54
|
-
"should be invalid with a non number"
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_validate_numericality_of_percentage_value
|
58
|
-
subject = Fixture.commission(percentage_value: "I'm not a number", fixed_value: nil)
|
59
|
-
assert subject.invalid? && subject.errors[:percentage_value].present?,
|
60
|
-
"should be invalid with a non number"
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_validate_positive_number_of_fixed_value
|
64
|
-
subject = Fixture.commission(fixed_value: -0.1)
|
65
|
-
assert subject.invalid? && subject.errors[:fixed_value].present?,
|
66
|
-
"should be invalid with negative number"
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_validate_percentage_number_of_percentage_value
|
70
|
-
subject = Fixture.commission(percentage_value: -0.1, fixed_value: nil)
|
71
|
-
assert subject.invalid? && subject.errors[:percentage_value].present?,
|
72
|
-
"should be invalid if lesser than 0"
|
73
|
-
subject.percentage_value = 1.01
|
74
|
-
assert subject.invalid? && subject.errors[:percentage_value].present?,
|
75
|
-
"should be invalid if greater than 1"
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_gross_amount_is_equal_to_fixed_value_when_this_is_present
|
79
|
-
instruction = Fixture.instruction
|
80
|
-
subject = Fixture.commission(fixed_value: 5, percentage_value: nil)
|
81
|
-
assert_equal 5, subject.gross_amount(instruction)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_gross_amount_with_percentage_is_equal_to_a_percentage_of_instructions_values
|
85
|
-
instruction = stub(gross_amount: 200)
|
86
|
-
subject = Fixture.commission(fixed_value: nil, percentage_value: 0.2)
|
87
|
-
assert_equal 40, subject.gross_amount(instruction)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_cannot_give_gross_amount_without_fixed_or_percentage_value_set
|
91
|
-
instruction = stub(gross_amount: 200)
|
92
|
-
subject = Fixture.commission(fixed_value: nil, percentage_value: nil)
|
93
|
-
assert_raise MyMoip::InvalidComission do
|
94
|
-
subject.gross_amount(instruction)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_xml_format_with_fixed_value
|
99
|
-
subject = Fixture.commission(fixed_value: 5)
|
100
|
-
expected_format = <<XML
|
101
|
-
<Comissionamento><Razao>Because we can</Razao><Comissionado><LoginMoIP>commissioned_indentifier</LoginMoIP></Comissionado><ValorFixo>5</ValorFixo></Comissionamento>
|
102
|
-
XML
|
103
|
-
assert_equal expected_format.rstrip, subject.to_xml
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_xml_format_with_percentage_value
|
107
|
-
subject = Fixture.commission(percentage_value: 0.15, fixed_value: nil)
|
108
|
-
expected_format = <<XML
|
109
|
-
<Comissionamento><Razao>Because we can</Razao><Comissionado><LoginMoIP>commissioned_indentifier</LoginMoIP></Comissionado><ValorPercentual>0.15</ValorPercentual></Comissionamento>
|
110
|
-
XML
|
111
|
-
assert_equal expected_format.rstrip, subject.to_xml
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_xml_method_raises_exception_when_called_with_invalid_params
|
115
|
-
subject = Fixture.commission
|
116
|
-
subject.stubs(:invalid?).returns(true)
|
117
|
-
assert_raise MyMoip::InvalidComission do
|
118
|
-
subject.to_xml
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|