akatus-rb 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +20 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +45 -0
- data/README.md +42 -0
- data/Rakefile +7 -0
- data/akatus-rb.gemspec +29 -0
- data/lib/akatus.rb +27 -0
- data/lib/akatus/address.rb +13 -0
- data/lib/akatus/base.rb +38 -0
- data/lib/akatus/credit_card.rb +12 -0
- data/lib/akatus/installments.rb +34 -0
- data/lib/akatus/order.rb +63 -0
- data/lib/akatus/payment_methods.rb +74 -0
- data/lib/akatus/phone.rb +12 -0
- data/lib/akatus/product.rb +11 -0
- data/lib/akatus/transactions.rb +118 -0
- data/lib/akatus/version.rb +3 -0
- data/lib/generators/akatus_generator.rb +5 -0
- data/lib/generators/templates/akatus.yml +14 -0
- data/spec/akatus/base_spec.rb +33 -0
- data/spec/factories/factories.rb +51 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/config/akatus.yml +4 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NWUxODQwMTBjNTg4ZTJiNTU3ZjI5MTQzODBjNTdjMzk5ZTc2YzdkZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWU4ZmMwMGVkNjQ3YzMwZWQyZmZiMDk0MTE3Nzc4MDUwODc0ZTI5Mg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTM4NTlmZWE1YzIzMjRlMjE0NzU2YzI1ODMxYjgxNDIzYTQ0ZDY3MTY0NGM4
|
10
|
+
NTUzMjFmNTBlZmNkZTRkZWZjNzQzMjVhNmU4MmMyM2ZhM2U3ZjFkYzYyODNh
|
11
|
+
OWM3OTRiNzFjNmVmOTAzYWEyZGU3ZTU4MTRiZjFkOTU3NDFiYmE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDk1MTczZTM4N2I4ZDljZWU0ZmY1YmMzZTczNWUxYmE0NjgzOTU0MmQ2MTNh
|
14
|
+
YTZlZTcwYmZlNjlhOTY1ZGJhN2Y5MmE1YmJkNWFiYzg1YzE3YTcxOTkxZDIy
|
15
|
+
MjIxNGM3ZWU4YTFjMTFjODE4ZDJiNTkxODBmMmRmZDI3ZGQ0ZDk=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
akatus-rb (0.0.1)
|
5
|
+
httpi
|
6
|
+
nokogiri
|
7
|
+
rack
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (3.2.11)
|
13
|
+
i18n (~> 0.6)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
diff-lcs (1.1.3)
|
16
|
+
factory_girl (2.5.2)
|
17
|
+
activesupport (>= 2.3.9)
|
18
|
+
httpi (2.1.0)
|
19
|
+
rack
|
20
|
+
rubyntlm (~> 0.3.2)
|
21
|
+
i18n (0.6.1)
|
22
|
+
mini_portile (0.5.2)
|
23
|
+
multi_json (1.5.0)
|
24
|
+
nokogiri (1.6.0)
|
25
|
+
mini_portile (~> 0.5.0)
|
26
|
+
rack (1.5.2)
|
27
|
+
rake (10.0.3)
|
28
|
+
rspec (2.12.0)
|
29
|
+
rspec-core (~> 2.12.0)
|
30
|
+
rspec-expectations (~> 2.12.0)
|
31
|
+
rspec-mocks (~> 2.12.0)
|
32
|
+
rspec-core (2.12.2)
|
33
|
+
rspec-expectations (2.12.1)
|
34
|
+
diff-lcs (~> 1.1.3)
|
35
|
+
rspec-mocks (2.12.1)
|
36
|
+
rubyntlm (0.3.4)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
akatus-rb!
|
43
|
+
factory_girl
|
44
|
+
rake
|
45
|
+
rspec
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# akatus-rb
|
2
|
+
|
3
|
+
Client oficial de integração com Akatus em Ruby
|
4
|
+
|
5
|
+
[Documentação](https://connect.akatus.com) | [Sandbox](https://sandbox.akatus.com)
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
akatus gem is available through [Rubygems](http://rubygems.org/gems/akatus-rb) and can be installed via:
|
11
|
+
|
12
|
+
```
|
13
|
+
$ gem install akatus-rb
|
14
|
+
```
|
15
|
+
|
16
|
+
or add it to your Gemfile like this:
|
17
|
+
|
18
|
+
```
|
19
|
+
gem 'akatus-rb', '~> 0.0.1'
|
20
|
+
```
|
21
|
+
|
22
|
+
and generate the config:
|
23
|
+
|
24
|
+
```
|
25
|
+
$ rails generate akatus:config
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage example
|
29
|
+
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
require "akatus-rb"
|
33
|
+
|
34
|
+
order = Akatus::Order.new(
|
35
|
+
...
|
36
|
+
)
|
37
|
+
transaction = Akatus::Transaction.process(order)
|
38
|
+
|
39
|
+
puts transaction.uuid
|
40
|
+
# => 1234-abcd-9876abc
|
41
|
+
|
42
|
+
```
|
data/Rakefile
ADDED
data/akatus-rb.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
require "akatus/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'akatus-rb'
|
8
|
+
gem.version = Akatus::VERSION
|
9
|
+
gem.date = '2012-01-14'
|
10
|
+
gem.summary = "Akatus Meios de Pagamento"
|
11
|
+
gem.description = "Client de integração para Akatus Meios de Pagamento"
|
12
|
+
gem.authors = ["Rodrigo Panachi", "Diego Charles"]
|
13
|
+
gem.email = 'desenvolvimento@akatus.com'
|
14
|
+
gem.files = ["lib/akatus.rb"]
|
15
|
+
gem.homepage = 'https://github.com/Akatus/akatus-rb'
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
18
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
|
22
|
+
gem.add_runtime_dependency "rack"
|
23
|
+
gem.add_runtime_dependency "httpi"
|
24
|
+
gem.add_runtime_dependency "nokogiri"
|
25
|
+
|
26
|
+
gem.add_development_dependency "rake"
|
27
|
+
gem.add_development_dependency "rspec"
|
28
|
+
gem.add_development_dependency "factory_girl"
|
29
|
+
end
|
data/lib/akatus.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
require 'akatus/base'
|
4
|
+
require 'akatus/installments'
|
5
|
+
require 'akatus/payment_methods'
|
6
|
+
require 'akatus/transactions'
|
7
|
+
require 'akatus/product'
|
8
|
+
require 'akatus/order'
|
9
|
+
require 'akatus/credit_card'
|
10
|
+
require 'akatus/address'
|
11
|
+
require 'akatus/phone'
|
12
|
+
|
13
|
+
module Akatus
|
14
|
+
autoload :Installments, 'akatus/installments'
|
15
|
+
autoload :PaymentMethods, 'akatus/payment_methods'
|
16
|
+
autoload :Transactions, 'akatus/transactions'
|
17
|
+
autoload :Product, 'akatus/product'
|
18
|
+
autoload :Order, 'akatus/order'
|
19
|
+
autoload :CreditCard, 'akatus/credit_card'
|
20
|
+
autoload :Address, 'akatus/address'
|
21
|
+
autoload :Phone, 'akatus/phone'
|
22
|
+
end
|
23
|
+
|
24
|
+
if defined?(Rails)
|
25
|
+
Akatus.env = Rails.env
|
26
|
+
Akatus.config_file = Rails.root || Pathname.new('').join("config/akatus.yml")
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Akatus
|
2
|
+
class Address
|
3
|
+
|
4
|
+
attr_accessor :postal_code, :neighborhood, :complement, :number, :street, :city,
|
5
|
+
:state, :country, :kind
|
6
|
+
|
7
|
+
def initialize(attributes = {})
|
8
|
+
attributes.each do |name, value|
|
9
|
+
send("#{name}=", value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/akatus/base.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Akatus
|
2
|
+
|
3
|
+
class InvalidEnvironment < Exception; end
|
4
|
+
class MissingConfiguration < Exception; end
|
5
|
+
|
6
|
+
extend self
|
7
|
+
|
8
|
+
attr_accessor :env, :config_file
|
9
|
+
|
10
|
+
def config
|
11
|
+
validate!
|
12
|
+
@config ||= YAML.load_file(config_file)[env]
|
13
|
+
end
|
14
|
+
|
15
|
+
def config!
|
16
|
+
@config = nil
|
17
|
+
config
|
18
|
+
end
|
19
|
+
|
20
|
+
def seller_email
|
21
|
+
config["email"]
|
22
|
+
end
|
23
|
+
def seller_api_key
|
24
|
+
config["api_key"]
|
25
|
+
end
|
26
|
+
def akatus_uri
|
27
|
+
config["uri"]
|
28
|
+
end
|
29
|
+
def akatus_api_uri
|
30
|
+
akatus_uri + "/api/v1"
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def validate!
|
35
|
+
raise InvalidEnvironment unless %(production development test).include?(env)
|
36
|
+
raise MissingConfiguration unless File.exist?(config_file)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Akatus
|
2
|
+
class Installments
|
3
|
+
|
4
|
+
SIMULATION_URI =
|
5
|
+
|
6
|
+
def self.simulate(payment_method_code, amount)
|
7
|
+
url = "#{Akatus.akatus_api_uri}/parcelamento/simulacao.json?email=#{Akatus.seller_email}&api_key=#{Akatus.seller_api_key}&payment_method=#{payment_method_code}&amount=#{amount}"
|
8
|
+
request = HTTPI::Request.new
|
9
|
+
request.url = url
|
10
|
+
request.open_timeout = 10 # sec
|
11
|
+
request.read_timeout = 30 # sec
|
12
|
+
response = HTTPI.get request
|
13
|
+
translate_installments_keys_to_english(response)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.translate_installments_keys_to_english(response)
|
19
|
+
parsed_response = JSON.parse(response.raw_body)['resposta']
|
20
|
+
translated = {}
|
21
|
+
translated[:description] = parsed_response['descricao']
|
22
|
+
translated[:assumed_installments] = parsed_response['parcelas_assumidas']
|
23
|
+
translated[:installments] = []
|
24
|
+
parsed_response['parcelas'].each do |p|
|
25
|
+
installment = {}
|
26
|
+
installment[:installments_number] = p['quantidade'].to_i
|
27
|
+
installment[:installments_amount] = p['valor'].to_f
|
28
|
+
installment[:total_amount] = p['total'].to_f
|
29
|
+
translated[:installments] << installment
|
30
|
+
end
|
31
|
+
translated
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/akatus/order.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Akatus
|
2
|
+
class Order
|
3
|
+
attr_accessor :buyer_name, :buyer_email, :discount_amount, :freight_amount, :weight,
|
4
|
+
:payment_method, :installments, :products, :reference, :credit_card, :address,
|
5
|
+
:phone
|
6
|
+
|
7
|
+
def initialize(attributes = {})
|
8
|
+
attributes.each do |name, value|
|
9
|
+
send("#{name}=", value)
|
10
|
+
end
|
11
|
+
self.products = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_product(attributes = {})
|
15
|
+
self.products << Product.new({
|
16
|
+
:code => attributes[:code],
|
17
|
+
:name => attributes[:name],
|
18
|
+
:weight => attributes[:weight],
|
19
|
+
:quantity => attributes[:quantity],
|
20
|
+
:freight_amount => attributes[:freight_amount],
|
21
|
+
:discount_amount => attributes[:discount_amount],
|
22
|
+
:price => attributes[:price]
|
23
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
def credit_card(attributes = {})
|
27
|
+
@credit_card ||= CreditCard.new({
|
28
|
+
:number => attributes[:number],
|
29
|
+
:cvv => attributes[:cvv],
|
30
|
+
:expires_at => attributes[:expires_at],
|
31
|
+
:flag => attributes[:flag],
|
32
|
+
:holder_name => attributes[:holder_name],
|
33
|
+
:holder_cpf => attributes[:holder_cpf],
|
34
|
+
:holder_phone => attributes[:holder_phone]
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
def address(attributes = {})
|
39
|
+
@address ||= Address.new({
|
40
|
+
:postal_code => attributes[:postal_code],
|
41
|
+
:neighborhood => attributes[:neighborhood],
|
42
|
+
:street => attributes[:street],
|
43
|
+
:number => attributes[:number],
|
44
|
+
:complement => attributes[:complement],
|
45
|
+
:kind => attributes[:kind],
|
46
|
+
:city => attributes[:city],
|
47
|
+
:state => attributes[:state],
|
48
|
+
:country => attributes[:country]
|
49
|
+
})
|
50
|
+
end
|
51
|
+
|
52
|
+
def phone(attributes = {})
|
53
|
+
@phone ||= Phone.new({
|
54
|
+
:kind => attributes[:kind],
|
55
|
+
:number => attributes[:number]
|
56
|
+
})
|
57
|
+
end
|
58
|
+
|
59
|
+
def credit_card?
|
60
|
+
%w{cartao_visa cartao_master cartao_amex cartao_diners cartao_elo cartao_hipercard}.include? payment_method
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
module Akatus
|
4
|
+
class PaymentMethods
|
5
|
+
|
6
|
+
ALL = [
|
7
|
+
MASTER = :master,
|
8
|
+
VISA = :visa,
|
9
|
+
AMEX = :amex,
|
10
|
+
ELO = :elo,
|
11
|
+
DINERS = :diners,
|
12
|
+
BOLETO = :boleto,
|
13
|
+
ITAU = :itau,
|
14
|
+
BB = :bb,
|
15
|
+
BRADESCO = :bradesco
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
def self.available
|
19
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
20
|
+
xml.meios_de_pagamento {
|
21
|
+
xml.correntista {
|
22
|
+
xml.api_key Akatus.seller_api_key
|
23
|
+
xml.email Akatus.seller_email
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
request = HTTPI::Request.new(Akatus.akatus_api_uri + '/meios-de-pagamento.xml')
|
28
|
+
request.body = builder.to_xml
|
29
|
+
request.open_timeout = 10 # sec
|
30
|
+
request.read_timeout = 30 # sec
|
31
|
+
|
32
|
+
parsed_response = parse_response(HTTPI.post request)
|
33
|
+
splited_payment_methods = split_by_kind(parsed_response)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def self.split_by_kind(parsed_response)
|
39
|
+
splited_payment_methods = {}
|
40
|
+
parsed_response.each do |pr|
|
41
|
+
if pr['descricao'] == 'Cartão de Crédito' || pr['descricao'] == 'TEF'
|
42
|
+
payment_methods = []
|
43
|
+
pr['bandeiras']['bandeira'].each do |pm|
|
44
|
+
payment_method = {}
|
45
|
+
payment_method[:code] = pm['codigo']
|
46
|
+
payment_method[:description] = pm['descricao']
|
47
|
+
payment_method[:installments] = pm['parcelas'].to_i
|
48
|
+
payment_methods << payment_method
|
49
|
+
end
|
50
|
+
if pr['descricao'] == 'Cartão de Crédito'
|
51
|
+
splited_payment_methods[:credit_card] = payment_methods
|
52
|
+
else
|
53
|
+
splited_payment_methods[:eft] = payment_methods
|
54
|
+
end
|
55
|
+
else
|
56
|
+
bills = []
|
57
|
+
bill = {}
|
58
|
+
bill[:code] = pr['codigo']
|
59
|
+
bill[:description] = pr['descricao']
|
60
|
+
bill[:installments] = pr['parcelas'].to_i
|
61
|
+
bills << bill
|
62
|
+
splited_payment_methods[:bill] = bills
|
63
|
+
end
|
64
|
+
end
|
65
|
+
splited_payment_methods
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.parse_response(response)
|
69
|
+
parsed_response = Hash.from_xml(Nokogiri.XML(response.raw_body).to_s)
|
70
|
+
raise StandardError, 'Akatus account not found' if parsed_response['resposta']['status'] == 'erro'
|
71
|
+
parsed_response['resposta']['meios_de_pagamento']['meio_de_pagamento']
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/akatus/phone.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
module Akatus
|
2
|
+
class Transactions
|
3
|
+
def self.process(order)
|
4
|
+
xml = prepare_xml_to_send order
|
5
|
+
url = "#{Akatus.akatus_api_uri}/carrinho.xml"
|
6
|
+
request = HTTPI::Request.new
|
7
|
+
request.body = xml
|
8
|
+
request.url = url
|
9
|
+
request.open_timeout = 10 # sec
|
10
|
+
request.read_timeout = 30 # sec
|
11
|
+
response = HTTPI.post request
|
12
|
+
|
13
|
+
Hash.from_xml(Nokogiri::XML(response.raw_body).to_s)['resposta']
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.status(akatus_uuid)
|
17
|
+
url = "#{Akatus.akatus_api_uri}/transacao-simplificada/#{akatus_uuid}.json?email=#{seller_email}&api_key=#{seller_api_key}"
|
18
|
+
request = HTTPI::Request.new
|
19
|
+
request.url = url
|
20
|
+
request.open_timeout = 10 # sec
|
21
|
+
request.read_timeout = 30 # sec
|
22
|
+
@response ||= HTTPI.get request
|
23
|
+
#TODO Finish to implement this
|
24
|
+
end
|
25
|
+
|
26
|
+
# private
|
27
|
+
|
28
|
+
def self.prepare_xml_to_send(order)
|
29
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
30
|
+
xml.carrinho {
|
31
|
+
xml.recebedor {
|
32
|
+
xml.api_key Akatus.seller_api_key
|
33
|
+
xml.email Akatus.seller_email
|
34
|
+
}
|
35
|
+
xml.pagador {
|
36
|
+
xml.nome order.buyer_name
|
37
|
+
xml.email order.buyer_email
|
38
|
+
xml.enderecos {
|
39
|
+
xml.endereco {
|
40
|
+
xml.tipo order.address.kind || 'cobranca'
|
41
|
+
xml.logradouro order.address.street
|
42
|
+
xml.numero order.address.number
|
43
|
+
xml.bairro order.address.neighborhood
|
44
|
+
xml.cidade order.address.city
|
45
|
+
xml.estado order.address.state
|
46
|
+
xml.pais order.address.country || 'BRA'
|
47
|
+
xml.cep order.address.postal_code
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
xml.telefones {
|
52
|
+
xml.telefone {
|
53
|
+
xml.tipo order.phone.kind
|
54
|
+
xml.numero order.phone.number
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
xml.produtos {
|
59
|
+
order.products.each do |product|
|
60
|
+
xml.produto {
|
61
|
+
xml.codigo product.code
|
62
|
+
xml.descricao product.name
|
63
|
+
xml.quantidade product.quantity || 1
|
64
|
+
xml.peso product.weight || 0.0
|
65
|
+
xml.frete product.freight_amount || 0.0
|
66
|
+
xml.preco '%.2f' % product.price
|
67
|
+
}
|
68
|
+
end
|
69
|
+
}
|
70
|
+
|
71
|
+
xml.transacao {
|
72
|
+
xml.desconto order.discount_amount || 0.0
|
73
|
+
xml.peso order.weight || 0.0
|
74
|
+
xml.frete order.freight_amount || 0.0
|
75
|
+
xml.moeda 'BRL'
|
76
|
+
xml.meio_de_pagamento map_payment_method(order.payment_method)
|
77
|
+
xml.parcelas order.installments || 1
|
78
|
+
xml.referencia order.reference
|
79
|
+
if order.credit_card?
|
80
|
+
xml.numero order.credit_card.number
|
81
|
+
xml.expiracao order.credit_card.expires_at
|
82
|
+
xml.codigo_de_seguranca order.credit_card.cvv
|
83
|
+
xml.portador {
|
84
|
+
xml.nome order.credit_card.holder_name
|
85
|
+
xml.cpf order.credit_card.holder_cpf
|
86
|
+
xml.telefone order.credit_card.holder_phone
|
87
|
+
}
|
88
|
+
end
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
# Rails.logger.info "---------------GENERATED XML TO SEND FOR AKATUS--------------"
|
93
|
+
# Rails.logger.info builder.to_xml
|
94
|
+
builder.to_xml
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.map_payment_method(payment_method)
|
98
|
+
case payment_method.to_sym
|
99
|
+
when :bill
|
100
|
+
'boleto'
|
101
|
+
when :eft
|
102
|
+
'tef'
|
103
|
+
when :master
|
104
|
+
'cartao_master'
|
105
|
+
when :visa
|
106
|
+
'cartao_visa'
|
107
|
+
when :amex
|
108
|
+
'cartao_amex'
|
109
|
+
when :diners
|
110
|
+
'cartao_diners'
|
111
|
+
when :elo
|
112
|
+
'cartao_elo'
|
113
|
+
else
|
114
|
+
payment_method.to_s
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
development:
|
2
|
+
uri: https://dev.akatus.com
|
3
|
+
email: (your akatus sandbox's email here)
|
4
|
+
api_key: (your api key here)
|
5
|
+
|
6
|
+
test:
|
7
|
+
uri: https://dev.akatus.com
|
8
|
+
email: (your akatus sandbox's email here)
|
9
|
+
api_key: (your api key here)
|
10
|
+
|
11
|
+
production:
|
12
|
+
uri: https://www.akatus.com
|
13
|
+
email: (your akatus email here)
|
14
|
+
api_key: (your api key here)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Akatus do
|
4
|
+
|
5
|
+
context "config" do
|
6
|
+
|
7
|
+
it "valid configuration" do
|
8
|
+
subject.config.should_not be_empty
|
9
|
+
end
|
10
|
+
it "email" do
|
11
|
+
subject.seller_email.should == "seller@store.com"
|
12
|
+
end
|
13
|
+
it "api_key key" do
|
14
|
+
subject.seller_api_key.should == "1234-000000000-987654321"
|
15
|
+
end
|
16
|
+
it "uri key" do
|
17
|
+
subject.akatus_uri.should == "https://test.akatus.com"
|
18
|
+
end
|
19
|
+
it "akatus api key" do
|
20
|
+
subject.akatus_api_uri.should == "https://test.akatus.com/api/v1"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "invalid environment" do
|
24
|
+
Akatus.env = "blah"
|
25
|
+
expect { Akatus.config }.to raise_error(Akatus::InvalidEnvironment)
|
26
|
+
end
|
27
|
+
it "invalid configuration" do
|
28
|
+
Akatus.config_file = "/tmp/a-file-that-dont-exist"
|
29
|
+
expect { Akatus.config }.to raise_error(Akatus::MissingConfiguration)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
Factory.define :order do |f|
|
2
|
+
f.buyer_email 'user@mailer.com'
|
3
|
+
f.buyer_name 'Homer Simpson'
|
4
|
+
f.discount_amount 1.98
|
5
|
+
f.weight 0.99
|
6
|
+
f.freight_amount 1.78
|
7
|
+
f.payment_method 'cartao_master'
|
8
|
+
f.installments 3
|
9
|
+
f.reference 'referencia-01'
|
10
|
+
|
11
|
+
2.times { f.products << Factory(:product) }
|
12
|
+
f.credit_card Factory(:credit_card)
|
13
|
+
f.address Factory(:address)
|
14
|
+
f.phone Factory(:phone)
|
15
|
+
end
|
16
|
+
|
17
|
+
Factory.define :product do |f|
|
18
|
+
f.code '0001'
|
19
|
+
f.name 'Produto Tabajara'
|
20
|
+
f.quantity 1
|
21
|
+
f.weight 2.5
|
22
|
+
f.freight_amount 10.0
|
23
|
+
f.discount_amount 1.99
|
24
|
+
f.price 55.99
|
25
|
+
end
|
26
|
+
|
27
|
+
Factory.define :credit_card do |f|
|
28
|
+
f.number '5453010000066167'
|
29
|
+
f.flag 'master'
|
30
|
+
f.cvv '123'
|
31
|
+
f.expires_at '05/2018'
|
32
|
+
f.holder_name 'AUTORIZAR'
|
33
|
+
f.holder_cpf '13786614431'
|
34
|
+
f.holder_phone '1133331111'
|
35
|
+
end
|
36
|
+
|
37
|
+
Factory.define :address do |f|
|
38
|
+
f.postal_code '03222000'
|
39
|
+
f.street 'Evergreen Al.'
|
40
|
+
f.number '30'
|
41
|
+
f.complement 'apto 23'
|
42
|
+
f.neighborhood 'Centro'
|
43
|
+
f.city 'London'
|
44
|
+
f.state 'AC'
|
45
|
+
f.kind 'residencial'
|
46
|
+
end
|
47
|
+
|
48
|
+
Factory.define :phone do |f|
|
49
|
+
f.kind 'residencial'
|
50
|
+
f.number '1133331111'
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: akatus-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodrigo Panachi
|
8
|
+
- Diego Charles
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: httpi
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: nokogiri
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: factory_girl
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description: Client de integração para Akatus Meios de Pagamento
|
99
|
+
email: desenvolvimento@akatus.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- akatus-rb.gemspec
|
110
|
+
- lib/akatus.rb
|
111
|
+
- lib/akatus/address.rb
|
112
|
+
- lib/akatus/base.rb
|
113
|
+
- lib/akatus/credit_card.rb
|
114
|
+
- lib/akatus/installments.rb
|
115
|
+
- lib/akatus/order.rb
|
116
|
+
- lib/akatus/payment_methods.rb
|
117
|
+
- lib/akatus/phone.rb
|
118
|
+
- lib/akatus/product.rb
|
119
|
+
- lib/akatus/transactions.rb
|
120
|
+
- lib/akatus/version.rb
|
121
|
+
- lib/generators/akatus_generator.rb
|
122
|
+
- lib/generators/templates/akatus.yml
|
123
|
+
- spec/akatus/base_spec.rb
|
124
|
+
- spec/factories/factories.rb
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
- spec/support/config/akatus.yml
|
127
|
+
homepage: https://github.com/Akatus/akatus-rb
|
128
|
+
licenses: []
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.1.5
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Akatus Meios de Pagamento
|
150
|
+
test_files:
|
151
|
+
- spec/akatus/base_spec.rb
|
152
|
+
- spec/factories/factories.rb
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
- spec/support/config/akatus.yml
|
155
|
+
has_rdoc:
|