akatus 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -16
  3. data/.rspec +2 -0
  4. data/LICENSE +1 -1
  5. data/Rakefile +6 -1
  6. data/akatus.gemspec +18 -11
  7. data/config/i18n.rb +3 -0
  8. data/lib/akatus.rb +34 -4
  9. data/lib/akatus/address.rb +11 -0
  10. data/lib/akatus/configuration.rb +43 -0
  11. data/lib/akatus/errors.rb +4 -0
  12. data/lib/akatus/formatters.rb +22 -0
  13. data/lib/akatus/installment.rb +6 -0
  14. data/lib/akatus/installment_options.rb +24 -0
  15. data/lib/akatus/item.rb +24 -0
  16. data/lib/akatus/payer.rb +35 -0
  17. data/lib/akatus/payment.rb +61 -0
  18. data/lib/akatus/payment_option.rb +6 -0
  19. data/lib/akatus/payment_types.rb +37 -0
  20. data/lib/akatus/phone.rb +6 -0
  21. data/lib/akatus/receiver.rb +6 -0
  22. data/lib/akatus/service.rb +34 -0
  23. data/lib/akatus/services/installments.rb +54 -0
  24. data/lib/akatus/services/payment_options.rb +95 -0
  25. data/lib/akatus/services/transaction.rb +50 -0
  26. data/lib/akatus/split_fee.rb +6 -0
  27. data/lib/akatus/transferrable.rb +58 -0
  28. data/lib/akatus/version.rb +1 -1
  29. data/locales/pt-BR.yml +69 -0
  30. data/spec/address_spec.rb +38 -0
  31. data/spec/factories/address_factories.rb +18 -0
  32. data/spec/factories/item_factories.rb +35 -0
  33. data/spec/factories/payer_factories.rb +8 -0
  34. data/spec/factories/phone_factories.rb +6 -0
  35. data/spec/item_spec.rb +42 -0
  36. data/spec/payer_spec.rb +31 -0
  37. data/spec/phone_spec.rb +23 -0
  38. data/spec/services/installments_spec.rb +36 -0
  39. data/spec/services/payment_options_spec.rb +22 -0
  40. data/spec/services/transaction_spec.rb +80 -0
  41. data/spec/spec_helper.rb +31 -0
  42. data/spec/support/configuration.rb +7 -0
  43. data/spec/support/shared_examples/transferrable_example.rb +22 -0
  44. metadata +142 -12
  45. data/LICENSE.txt +0 -22
  46. data/lib/akatus/configuracao.rb +0 -40
  47. data/lib/akatus/formatadores.rb +0 -7
@@ -0,0 +1,35 @@
1
+ FactoryGirl.define do
2
+
3
+ factory :item, :class => Akatus::Item do
4
+
5
+ reference 'ABC1234567'
6
+ description 'Caixa de bombons sortidos'
7
+ quantity 32
8
+ price BigDecimal.new('32.25')
9
+ weight BigDecimal.new('2.25')
10
+ shipping_cost BigDecimal.new('9.90')
11
+ discount 0
12
+
13
+ trait :with_percentage_split_fee do
14
+ split_fee {
15
+ Akatus::SplitFee.new({
16
+ :receiver => 'ze@hotmail.com',
17
+ :type => 'porcentagem',
18
+ :amount => 20
19
+ })
20
+ }
21
+ end
22
+
23
+ trait :with_fixed_split_fee do
24
+ split_fee {
25
+ Akatus::SplitFee.new({
26
+ :receiver => 'ze@hotmail.com',
27
+ :type => 'real',
28
+ :amount => 20
29
+ })
30
+ }
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,8 @@
1
+ FactoryGirl.define do
2
+ factory :payer, :class => Akatus::Payer do
3
+ name 'Jose Antonio'
4
+ email 'ze@antonio.com.br'
5
+ address { build(:address) }
6
+ phone { build(:phone) }
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :phone, :class => Akatus::Phone do
3
+ type 'comercial'
4
+ number '1199999999'
5
+ end
6
+ end
data/spec/item_spec.rb ADDED
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ describe Akatus::Item do
4
+
5
+ let(:attrs) {
6
+ {
7
+ :reference => 'ABC1234567',
8
+ :description => 'Caixa de bombons sortidos',
9
+ :quantity => 32,
10
+ :price => BigDecimal.new('32.2'),
11
+ :weight => BigDecimal.new('2.25'),
12
+ :shipping_cost => BigDecimal.new(9),
13
+ }
14
+ }
15
+
16
+ let(:payload) {
17
+ {
18
+ 'produto' => {
19
+ 'codigo' => 'ABC1234567',
20
+ 'descricao' => 'Caixa de bombons sortidos',
21
+ 'quantidade' => '32',
22
+ 'preco' => '32.20',
23
+ 'peso' => '2.25',
24
+ 'frete' => '9.00',
25
+ 'desconto' => '0.00'
26
+ }
27
+ }
28
+ }
29
+
30
+ it_behaves_like Akatus::Transferrable
31
+
32
+ it "has default values" do
33
+
34
+ item = Akatus::Item.new
35
+ item.shipping_cost.should == 0
36
+ item.discount.should == 0
37
+ item.weight.should == 0
38
+ item.quantity.should == 1
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ describe Akatus::Payer do
4
+
5
+ let(:attrs) {
6
+ {
7
+ :name => 'Jose Antonio',
8
+ :email => 'ze@antonio.com.br',
9
+ :phone => build(:phone),
10
+ :address => build(:address)
11
+ }
12
+ }
13
+
14
+ let(:payload) {
15
+ {
16
+ 'pagador' => {
17
+ 'nome' => 'Jose Antonio',
18
+ 'email' => 'ze@antonio.com.br',
19
+ 'enderecos' => {
20
+ 'endereco' => [ build(:address).to_payload(false) ]
21
+ },
22
+ 'telefones' => {
23
+ 'telefone' => [ build(:phone).to_payload(false) ]
24
+ }
25
+ }
26
+ }
27
+ }
28
+
29
+ it_behaves_like Akatus::Transferrable
30
+
31
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ describe Akatus::Phone do
4
+
5
+ let(:attrs) {
6
+ {
7
+ :type => 'comercial',
8
+ :number => '1199999999'
9
+ }
10
+ }
11
+
12
+ let(:payload) {
13
+ {
14
+ 'telefone' => {
15
+ 'tipo' => 'comercial',
16
+ 'numero' => '1199999999'
17
+ }
18
+ }
19
+ }
20
+
21
+ it_behaves_like Akatus::Transferrable
22
+
23
+ end
@@ -0,0 +1,36 @@
1
+ describe Akatus::Services::Installments do
2
+
3
+ it "fetches dummy installment options for transactions that don't support installments" do
4
+
5
+ p = Akatus::Payment.new
6
+ p.items << build(:item)
7
+ p.payment_method = Akatus::BoletoBancario.new
8
+
9
+ result = Akatus::Services::Installments.calculate(p)
10
+
11
+ result.description.should be_nil
12
+ result.taken_installments.should == 0
13
+ result.installments.size.should == 1
14
+
15
+ installment = result.installments.first
16
+ installment.quantity.should == 1
17
+ installment.unitary_amount.should == p.total_amount
18
+ installment.total_amount.should == p.total_amount
19
+
20
+ end
21
+
22
+ it "fetches installment options for transactions with credit card" do
23
+
24
+ p = Akatus::Payment.new
25
+ p.items << build(:item)
26
+ p.payment_method = Akatus::CreditCard.new(:brand => 'cartao_visa')
27
+
28
+ result = Akatus::Services::Installments.calculate(p)
29
+
30
+ result.description.length.should be > 0
31
+ result.taken_installments.should == 0
32
+ result.installments.size.should >= 0
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,22 @@
1
+ describe Akatus::Services::PaymentOptions do
2
+
3
+ it 'fetches all available payment methods for an account' do
4
+ result = Akatus::Services::PaymentOptions.available
5
+
6
+ result.should be_a(Hash)
7
+ result.keys.reject { |k| [:boleto, :credit_card, :eft].include?(k) }.should be_empty
8
+ end
9
+
10
+ it 'fetches all available payment methods (with installments) for a payment' do
11
+
12
+ p = Akatus::Payment.new
13
+ p.items << build(:item)
14
+
15
+ r1 = Akatus::Services::PaymentOptions.available
16
+ r2 = Akatus::Services::PaymentOptions.available_with_installments(p)
17
+
18
+ r2.should be_a(Hash)
19
+ r2.keys.should == r1.keys
20
+ end
21
+
22
+ end
@@ -0,0 +1,80 @@
1
+ describe Akatus::Services::Transaction do
2
+
3
+ let(:secondary_receiver) {
4
+ raise "You should replace this with a string containing a valid Akatus account e-mail"
5
+ # Example: "my-akatus-account@domain.com"
6
+ }
7
+
8
+ specify 'basic example' do
9
+
10
+ payment = Akatus::Payment.new({
11
+ :payer => build(:payer),
12
+ :items => [ build(:item) ],
13
+ :reference => 'order#0001',
14
+ :payment_method => Akatus::BoletoBancario.new
15
+ })
16
+
17
+ Akatus::Services::Transaction.create(payment)
18
+
19
+ payment.id.to_s.length.should be > 0
20
+ payment.transaction_id.to_s.length.should be > 0
21
+ payment.url.to_s.length.should be > 0
22
+
23
+ end
24
+
25
+ specify 'payment with split fees I' do
26
+
27
+ payment = Akatus::Payment.new({
28
+ :payer => build(:payer),
29
+ :items => [ build(:item, :with_percentage_split_fee) ],
30
+ :reference => 'order#0001',
31
+ :payment_method => Akatus::BoletoBancario.new
32
+ })
33
+
34
+ Akatus::Services::Transaction.create(payment)
35
+
36
+ end
37
+
38
+ specify 'payment with split fees II' do
39
+
40
+ payment = Akatus::Payment.new({
41
+ :payer => build(:payer),
42
+ :reference => 'order#0002',
43
+ :payment_method => Akatus::BoletoBancario.new
44
+ })
45
+
46
+ item1 = Akatus::Item.new({
47
+ :reference => 'P01',
48
+ :description => 'P01',
49
+ :price => 100,
50
+ :split_fee => Akatus::SplitFee.new({
51
+ :receiver => secondary_receiver,
52
+ :type => 'porcentagem',
53
+ :amount => BigDecimal.new('12.2')
54
+ })
55
+ })
56
+
57
+ item2 = Akatus::Item.new({
58
+ :reference => 'P02',
59
+ :description => 'P02',
60
+ :price => 200,
61
+ :split_fee => Akatus::SplitFee.new({
62
+ :receiver => secondary_receiver,
63
+ :type => 'real',
64
+ :amount => BigDecimal.new('3.33')
65
+ })
66
+ })
67
+
68
+ item3 = Akatus::Item.new({
69
+ :reference => 'P03',
70
+ :description => 'P03',
71
+ :price => 300
72
+ })
73
+
74
+ payment.items = [ item1, item2, item3 ]
75
+
76
+ Akatus::Services::Transaction.create(payment)
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,31 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require_relative "../lib/akatus"
9
+
10
+ require "factory_girl"
11
+
12
+ # Require factories.
13
+ Dir[File.expand_path("../factories/**/*.rb", __FILE__)].each { |f| require f }
14
+
15
+ # Require supporting ruby files with custom matchers and macros, etc,
16
+ # in spec/support/ and its subdirectories.
17
+ Dir[File.expand_path("../support/**/*.rb", __FILE__)].each { |f| require f }
18
+
19
+ RSpec.configure do |config|
20
+ config.treat_symbols_as_metadata_keys_with_true_values = true
21
+ config.run_all_when_everything_filtered = true
22
+ config.filter_run :focus
23
+
24
+ # Run specs in random order to surface order dependencies. If you find an
25
+ # order dependency and want to debug it, you can fix the order by providing
26
+ # the seed, which is printed after each run.
27
+ # --seed 1234
28
+ config.order = 'random'
29
+
30
+ config.include FactoryGirl::Syntax::Methods
31
+ end
@@ -0,0 +1,7 @@
1
+ Akatus.config.api_key = "PLEASE-REPLACE-ME"
2
+ Akatus.config.email = "PLEASE-REPLACE-ME"
3
+ Akatus.config.sandbox = true
4
+
5
+ if Akatus.config.email == "PLEASE-REPLACE-ME"
6
+ raise "Please replace the values above with your actual account information"
7
+ end
@@ -0,0 +1,22 @@
1
+ shared_examples_for Akatus::Transferrable do
2
+
3
+ it "can be initialized with attributes" do
4
+
5
+ obj = described_class.new(attrs)
6
+
7
+ attrs.each do |attr, value|
8
+ obj.send(attr).should == value
9
+ end
10
+
11
+ end
12
+
13
+ it "can be turned into a JSON payload" do
14
+
15
+ obj = described_class.new(attrs)
16
+
17
+ obj.to_payload.should == payload
18
+ obj.to_payload(false).should == payload.values.first
19
+
20
+ end
21
+
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akatus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kauplus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-25 00:00:00.000000000 Z
11
+ date: 2014-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: i18n
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: bundler
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +80,34 @@ dependencies:
38
80
  - - ~>
39
81
  - !ruby/object:Gem::Version
40
82
  version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: debugger
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_girl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '4.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '4.3'
41
111
  - !ruby/object:Gem::Dependency
42
112
  name: rake
43
113
  requirement: !ruby/object:Gem::Requirement
@@ -52,26 +122,72 @@ dependencies:
52
122
  - - '>='
53
123
  - !ruby/object:Gem::Version
54
124
  version: '0'
55
- description: A gem foi criada para suportar todas as integrações de pagamentos da
56
- Akatus.
57
- email:
58
- - tech@kauplus.com.br
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '2.14'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '2.14'
139
+ description: Built to support all types of checkout integration between Akatus and
140
+ your application
141
+ email: tech@kauplus.com.br
59
142
  executables: []
60
143
  extensions: []
61
144
  extra_rdoc_files: []
62
145
  files:
63
146
  - .gitignore
147
+ - .rspec
64
148
  - Gemfile
65
149
  - LICENSE
66
- - LICENSE.txt
67
150
  - README.md
68
151
  - Rakefile
69
152
  - akatus.gemspec
153
+ - config/i18n.rb
70
154
  - lib/akatus.rb
71
- - lib/akatus/configuracao.rb
72
- - lib/akatus/formatadores.rb
155
+ - lib/akatus/address.rb
156
+ - lib/akatus/configuration.rb
157
+ - lib/akatus/errors.rb
158
+ - lib/akatus/formatters.rb
159
+ - lib/akatus/installment.rb
160
+ - lib/akatus/installment_options.rb
161
+ - lib/akatus/item.rb
162
+ - lib/akatus/payer.rb
163
+ - lib/akatus/payment.rb
164
+ - lib/akatus/payment_option.rb
165
+ - lib/akatus/payment_types.rb
166
+ - lib/akatus/phone.rb
167
+ - lib/akatus/receiver.rb
168
+ - lib/akatus/service.rb
169
+ - lib/akatus/services/installments.rb
170
+ - lib/akatus/services/payment_options.rb
171
+ - lib/akatus/services/transaction.rb
172
+ - lib/akatus/split_fee.rb
173
+ - lib/akatus/transferrable.rb
73
174
  - lib/akatus/version.rb
74
- homepage: ''
175
+ - locales/pt-BR.yml
176
+ - spec/address_spec.rb
177
+ - spec/factories/address_factories.rb
178
+ - spec/factories/item_factories.rb
179
+ - spec/factories/payer_factories.rb
180
+ - spec/factories/phone_factories.rb
181
+ - spec/item_spec.rb
182
+ - spec/payer_spec.rb
183
+ - spec/phone_spec.rb
184
+ - spec/services/installments_spec.rb
185
+ - spec/services/payment_options_spec.rb
186
+ - spec/services/transaction_spec.rb
187
+ - spec/spec_helper.rb
188
+ - spec/support/configuration.rb
189
+ - spec/support/shared_examples/transferrable_example.rb
190
+ homepage: http://github.com/kauplus/akatus
75
191
  licenses:
76
192
  - MIT
77
193
  metadata: {}
@@ -94,5 +210,19 @@ rubyforge_project:
94
210
  rubygems_version: 2.0.3
95
211
  signing_key:
96
212
  specification_version: 4
97
- summary: Gem de integração com o meio de pagamentos Akatus
98
- test_files: []
213
+ summary: Ruby gem for the Akatus payment system
214
+ test_files:
215
+ - spec/address_spec.rb
216
+ - spec/factories/address_factories.rb
217
+ - spec/factories/item_factories.rb
218
+ - spec/factories/payer_factories.rb
219
+ - spec/factories/phone_factories.rb
220
+ - spec/item_spec.rb
221
+ - spec/payer_spec.rb
222
+ - spec/phone_spec.rb
223
+ - spec/services/installments_spec.rb
224
+ - spec/services/payment_options_spec.rb
225
+ - spec/services/transaction_spec.rb
226
+ - spec/spec_helper.rb
227
+ - spec/support/configuration.rb
228
+ - spec/support/shared_examples/transferrable_example.rb