aceitafacil 0.0.2
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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +85 -0
- data/Rakefile +16 -0
- data/aceitafacil.gemspec +29 -0
- data/lib/aceitafacil.rb +36 -0
- data/lib/aceitafacil/bank.rb +18 -0
- data/lib/aceitafacil/card.rb +86 -0
- data/lib/aceitafacil/connection.rb +58 -0
- data/lib/aceitafacil/item.rb +16 -0
- data/lib/aceitafacil/payment.rb +70 -0
- data/lib/aceitafacil/utils.rb +7 -0
- data/lib/aceitafacil/vendor.rb +78 -0
- data/lib/aceitafacil/version.rb +3 -0
- data/lib/templates/aceitafacil/install_generator.rb +12 -0
- data/lib/templates/templates/aceitafacil.rb +13 -0
- data/spec/aceitafacil/card_spec.rb +56 -0
- data/spec/aceitafacil/connection_spec.rb +25 -0
- data/spec/aceitafacil/payment_spec.rb +59 -0
- data/spec/aceitafacil/utils_spec.rb +11 -0
- data/spec/aceitafacil/vendor_spec.rb +60 -0
- data/spec/spec_helper.rb +13 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjM0NWYwMWFjZmZmMDZhOGVhNWExNzM1NjA2M2UxZTI2YWZkYjMxOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWYwYmU5NWM2MDRjNDczZWQ3NDBjMGZlZmQzYTdhMTUxOWJhNDE2YQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjYyNjVmMWQ0OWZmODA1ZjU3ZGZlYTU1ZmMxOTA0OTdmZWYwODkyNTU3Y2Q0
|
10
|
+
YmZmY2FiZTMwOWM3ZmUyZTgxNjM0NzE2Zjc2YzQwMDFhMjRhYjdjOTFkZGJh
|
11
|
+
OGQ5OTZkZDczZjlmNTFmMWFjNGIyOTRmNWQ5OTNkYTQ1Njc2ODY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGUwMGEzM2M4Zjg4MDY3YjJmMWUxYTVkYjFlNjNmZWRjZTFhNWQ3ZjAyYmNk
|
14
|
+
NGFiZDNmYzUyNWY1YTEzMThiMGIxZmQxNDc5ZWU2Nzg3ODU2NGI4NzlkMTI5
|
15
|
+
NTc2MTRlZDVkMWYyZWQzZmMzYWE3OTI2NDMxNjI0ZjA1ZDUzOGI=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Wilbert Ribeiro
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Aceita Fácil
|
2
|
+
|
3
|
+
Esta gem habilita as funcionalidades da API do serviço [Aceita Fácil][url] no Ruby on Rails.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Adicione esta linha ao seu Gemfile:
|
8
|
+
|
9
|
+
gem 'aceitafacil'
|
10
|
+
|
11
|
+
E execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Ou instale assim:
|
16
|
+
|
17
|
+
$ gem install aceitafacil
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Cadastre os vendedores que receberão os pagamentos da loja em questão da seguinte forma:
|
22
|
+
|
23
|
+
@vendor = Aceitafacil::Vendor.new(id: "2", name: "Vendor name", email: "vendor@vendor.com",
|
24
|
+
bank: {
|
25
|
+
code: "001",
|
26
|
+
agency: "123-4",
|
27
|
+
account_type: 1, # 1 Corrent, 2 Poupança
|
28
|
+
account_number: "1234-5",
|
29
|
+
account_holder_name: "Fulano",
|
30
|
+
account_holder_document_type: 1, # 1 CPF, 2 CNPJ
|
31
|
+
account_holder_document_number: "12345678909"
|
32
|
+
})
|
33
|
+
|
34
|
+
@vendor.save
|
35
|
+
|
36
|
+
O id: refere-se ao ID do vendedor na base de dados da aplicação Host.
|
37
|
+
|
38
|
+
Implemente um formulário para capturar os dados do cartão de crédito. Segue um exemplo:
|
39
|
+
|
40
|
+
@card = Aceitafacil::Card.new(name: "Card Holder", number: "4012001038443335", cvv: "123", exp_date: "201807", customer_id: "1")
|
41
|
+
@card.save
|
42
|
+
|
43
|
+
O customer_id reference ao ID do cliente no banco de dados da aplicação Host.
|
44
|
+
|
45
|
+
O método __save__ sincroniza as informações enviadas com o servidor do [Aceita Fácil][url].
|
46
|
+
|
47
|
+
Com os dados do cartão de crédito enviados e os vendedores cadastrados você já pode efetuar um pagamento, segue um exemplo:
|
48
|
+
|
49
|
+
Recupere a instância de um vendedor na API, Ex:
|
50
|
+
|
51
|
+
@vendor = Aceitafacil::Vendor.find(2)
|
52
|
+
|
53
|
+
Instancie os items que estão sendo vendidos da seguinte forma:
|
54
|
+
|
55
|
+
@item = Aceitafacil::Item.new(amount: 10.0, vendor_id: @vendor.id, vendor_name: @vendor.name, fee_split: 1, description: "Test item", trigger_lock: false)
|
56
|
+
|
57
|
+
Recupere as informações do TOKEN do cartão de crédito, Ex:
|
58
|
+
|
59
|
+
@card = Aceitafacil::Card.find_by_customer_id(1)[0]
|
60
|
+
|
61
|
+
Faça uma requisição para efetuar o pagamento:
|
62
|
+
|
63
|
+
@payment = Payment.new(description: "Test payment", customer_id: 1, customer_name: "Fulano de Tal", customer_email: "fulano@fulanodetal.com.br", customer_email_language: "pt-BR", paymentmethod_id: 1, total_amount: 10, items: [@item], card: @card)
|
64
|
+
|
65
|
+
@payment.save
|
66
|
+
|
67
|
+
Após a chamada do método save todos os métodos abaixo deverão estar preenchidos:
|
68
|
+
|
69
|
+
@payment.id
|
70
|
+
@payment.organization_id
|
71
|
+
@payment.organization_name
|
72
|
+
@payment.paymentmethod
|
73
|
+
@payment.chargetype
|
74
|
+
@payment.payer
|
75
|
+
@payment.paid
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
1. Fork it ( http://github.com/wilbert/aceitafacil/fork )
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create new Pull Request
|
84
|
+
|
85
|
+
[url]: http://www.aceitafacil.com "Aceita Fácil"
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new
|
7
|
+
|
8
|
+
require 'rdoc/task'
|
9
|
+
Rake::RDocTask.new do |rdoc|
|
10
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
11
|
+
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = "Aceitafacil #{version}"
|
14
|
+
rdoc.rdoc_files.include('README*')
|
15
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
16
|
+
end
|
data/aceitafacil.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'aceitafacil/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "aceitafacil"
|
8
|
+
spec.version = Aceitafacil::VERSION
|
9
|
+
spec.authors = ["Wilbert Ribeiro"]
|
10
|
+
spec.email = ["wkelyson@gmail.com"]
|
11
|
+
spec.summary = %q{ This gem enables Aceita Fácil API features on Ruby on Rails }
|
12
|
+
spec.description = %q{ It implements Cards and Payments from Aceita Fácil doc spec. }
|
13
|
+
spec.homepage = "http://www.github.com/wilbert/aceitafacil"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "json", "1.8.1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake", "10.3.1"
|
25
|
+
spec.add_development_dependency "rspec-rails", "2.14.2"
|
26
|
+
spec.add_development_dependency "fakeweb", "1.3.0"
|
27
|
+
spec.add_development_dependency "factory_girl_rails", "4.4.0"
|
28
|
+
spec.add_development_dependency "debugger", "1.6.6"
|
29
|
+
end
|
data/lib/aceitafacil.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require "builder"
|
3
|
+
require "net/http"
|
4
|
+
require "net/https"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module Aceitafacil
|
8
|
+
class Production
|
9
|
+
BASE_URL = "api.aceitafacil.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
class Test
|
13
|
+
BASE_URL = "sandbox.api.aceitafacil.com"
|
14
|
+
# BASE_URL = "127.0.0.1:3000"
|
15
|
+
end
|
16
|
+
|
17
|
+
@@environment = :test
|
18
|
+
mattr_accessor :environment
|
19
|
+
@@api_key = "e3c23d27ca61ac2cc3b8a1e4ed5340247221757d"
|
20
|
+
mattr_accessor :api_key
|
21
|
+
@@api_password = "773aebdf0d1202cac6837751f354c0a70553b3cd"
|
22
|
+
mattr_accessor :api_password
|
23
|
+
|
24
|
+
def self.setup
|
25
|
+
yield self
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.site
|
29
|
+
environment = eval(Aceitafacil.environment.to_s.capitalize)
|
30
|
+
return "https://#{environment::BASE_URL}"
|
31
|
+
end
|
32
|
+
|
33
|
+
class MissingArgumentError < StandardError; end
|
34
|
+
end
|
35
|
+
|
36
|
+
[:version, :card, :connection, :vendor, :bank, :payment, :item, :utils].each { |lib| require "aceitafacil/#{lib}" }
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
module Aceitafacil
|
4
|
+
class Bank
|
5
|
+
attr_accessor :code, :agency, :account_type, :account_number, :account_holder_name
|
6
|
+
attr_accessor :account_holder_document_type, :account_holder_document_number
|
7
|
+
|
8
|
+
def initialize(params = {})
|
9
|
+
self.code = params[:code]
|
10
|
+
self.agency = params[:agency]
|
11
|
+
self.account_type = params[:account_type]
|
12
|
+
self.account_number = params[:account_number]
|
13
|
+
self.account_holder_name = params[:account_holder_name]
|
14
|
+
self.account_holder_document_type = params[:account_holder_document_type]
|
15
|
+
self.account_holder_document_number = params[:account_holder_document_number]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
module Aceitafacil
|
4
|
+
class Card
|
5
|
+
attr_accessor :customer_id, :number, :name, :cvv, :exp_date
|
6
|
+
attr_accessor :token, :card_brand, :last_digits, :status
|
7
|
+
|
8
|
+
def self.find_by_customer_id(customer_id)
|
9
|
+
return nil if customer_id.nil?
|
10
|
+
|
11
|
+
@connection = Aceitafacil::Connection.new
|
12
|
+
|
13
|
+
cards = []
|
14
|
+
|
15
|
+
connection_params = {}
|
16
|
+
connection_params["customer[id]"] = customer_id
|
17
|
+
response = @connection.get("card", connection_params)
|
18
|
+
|
19
|
+
json = JSON.parse(response.body)
|
20
|
+
|
21
|
+
json["card"].each do |remote_card|
|
22
|
+
card = Card.new(token: remote_card["token"], card_brand: remote_card["card_brand"], last_digits: remote_card["last_digits"])
|
23
|
+
cards << card
|
24
|
+
end
|
25
|
+
|
26
|
+
return cards
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.remove(card)
|
30
|
+
return nil if card.nil?
|
31
|
+
|
32
|
+
delete_params = {}
|
33
|
+
|
34
|
+
delete_params["customer[id]"] = card.customer_id
|
35
|
+
delete_params["card[token]"] = card.token
|
36
|
+
|
37
|
+
@connection = Aceitafacil::Connection.new
|
38
|
+
|
39
|
+
response = @connection.delete("card", delete_params)
|
40
|
+
|
41
|
+
json = JSON.parse(response.body)
|
42
|
+
|
43
|
+
card = Card.new(token: json["card"][0]["token"], status: json["card"][0]["status"])
|
44
|
+
|
45
|
+
return card
|
46
|
+
end
|
47
|
+
|
48
|
+
def initialize(params = {})
|
49
|
+
@connection = Aceitafacil::Connection.new
|
50
|
+
|
51
|
+
self.customer_id = params[:customer_id]
|
52
|
+
self.number = params[:number]
|
53
|
+
self.name = params[:name]
|
54
|
+
self.cvv = params[:cvv]
|
55
|
+
self.exp_date = params[:exp_date]
|
56
|
+
self.status = params[:status]
|
57
|
+
self.token = params[:token]
|
58
|
+
self.last_digits = params[:last_digits]
|
59
|
+
self.card_brand = params[:card_brand]
|
60
|
+
end
|
61
|
+
|
62
|
+
def params
|
63
|
+
params = {}
|
64
|
+
|
65
|
+
params["customer[id]"] = self.customer_id
|
66
|
+
params["card[name]"] = self.name
|
67
|
+
params["card[number]"] = self.number
|
68
|
+
params["card[cvv]"] = self.cvv
|
69
|
+
params["card[exp_date]"] = self.exp_date
|
70
|
+
|
71
|
+
return params
|
72
|
+
end
|
73
|
+
|
74
|
+
def save
|
75
|
+
response = @connection.post("card", params)
|
76
|
+
|
77
|
+
json = JSON.parse(response.body)
|
78
|
+
|
79
|
+
self.token = json["card"][0]["token"]
|
80
|
+
self.card_brand = json["card"][0]["card_brand"]
|
81
|
+
self.last_digits = json["card"][0]["last_digits"]
|
82
|
+
|
83
|
+
return response
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
module Aceitafacil
|
4
|
+
class Connection
|
5
|
+
attr_reader :environment
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@environment = eval(Aceitafacil.environment.to_s.capitalize)
|
9
|
+
port = 443
|
10
|
+
@http = Net::HTTP.new(@environment::BASE_URL,port)
|
11
|
+
|
12
|
+
@http.ssl_version = :SSLv3 if @http.respond_to? :ssl_version
|
13
|
+
@http.use_ssl = true
|
14
|
+
@http.open_timeout = 10*1000
|
15
|
+
@http.read_timeout = 40*1000
|
16
|
+
end
|
17
|
+
|
18
|
+
def post(path, params={})
|
19
|
+
request = Net::HTTP::Post.new("/#{path}")
|
20
|
+
request.basic_auth(Aceitafacil.api_key, Aceitafacil.api_password)
|
21
|
+
request.set_form_data(params)
|
22
|
+
response = @http.request(request)
|
23
|
+
return response
|
24
|
+
end
|
25
|
+
|
26
|
+
def put(path, params={})
|
27
|
+
request = Net::HTTP::Put.new("/#{path}")
|
28
|
+
request.basic_auth(Aceitafacil.api_key, Aceitafacil.api_password)
|
29
|
+
request.set_form_data(params)
|
30
|
+
response = @http.request(request)
|
31
|
+
return response
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete(path, params = {})
|
35
|
+
if not params.nil?
|
36
|
+
request = Net::HTTP::Delete.new("/#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')))
|
37
|
+
else
|
38
|
+
request = Net::HTTP::Delete.new("/#{path}")
|
39
|
+
end
|
40
|
+
request.basic_auth(Aceitafacil.api_key, Aceitafacil.api_password)
|
41
|
+
response = @http.request(request)
|
42
|
+
return response
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
def get(path, params={})
|
48
|
+
if not params.nil?
|
49
|
+
request = Net::HTTP::Get.new("/#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')))
|
50
|
+
else
|
51
|
+
request = Net::HTTP::Get.new("/#{path}")
|
52
|
+
end
|
53
|
+
request.basic_auth(Aceitafacil.api_key, Aceitafacil.api_password)
|
54
|
+
response = @http.request(request)
|
55
|
+
return response
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
module Aceitafacil
|
4
|
+
class Item
|
5
|
+
attr_accessor :amount, :vendor_id, :vendor_name, :fee_split, :description, :trigger_lock
|
6
|
+
|
7
|
+
def initialize(params = {})
|
8
|
+
self.amount = params[:amount]
|
9
|
+
self.vendor_id = params[:vendor_id]
|
10
|
+
self.vendor_name = params[:vendor_name]
|
11
|
+
self.fee_split = params[:fee_split]
|
12
|
+
self.description = params[:description]
|
13
|
+
self.trigger_lock = params[:trigger_lock]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
module Aceitafacil
|
4
|
+
class Payment
|
5
|
+
attr_accessor :card, :customer_id, :customer_name, :customer_email, :customer_email_language
|
6
|
+
attr_accessor :organization_id, :organization_name, :paymentmethod, :charge_type, :payer, :total_amount
|
7
|
+
attr_accessor :paid, :closed, :attempted, :attempted_count, :next_payment_attempt, :period_start
|
8
|
+
attr_accessor :period_end, :items, :id, :description, :paymentmethod_id, :chargetype
|
9
|
+
|
10
|
+
def initialize(params = {})
|
11
|
+
@connection = Aceitafacil::Connection.new
|
12
|
+
|
13
|
+
self.card = params[:card]
|
14
|
+
self.customer_id = params[:customer_id]
|
15
|
+
self.customer_name = params[:customer_name]
|
16
|
+
self.customer_email = params[:customer_email]
|
17
|
+
self.customer_email_language = params[:customer_email_language]
|
18
|
+
self.description = params[:description]
|
19
|
+
self.paymentmethod_id = params[:paymentmethod_id]
|
20
|
+
self.total_amount = params[:total_amount]
|
21
|
+
self.items = params[:items]
|
22
|
+
end
|
23
|
+
|
24
|
+
def params
|
25
|
+
params = {}
|
26
|
+
|
27
|
+
params["card[token]"] = self.card.token
|
28
|
+
params["customer[id]"] = self.customer_id.to_i
|
29
|
+
params["customer[name]"] = self.customer_name
|
30
|
+
params["customer[email]"] = self.customer_email
|
31
|
+
params["customer[email_language]"] = self.customer_email_language
|
32
|
+
params["description"] = self.description
|
33
|
+
params["paymentmethod[id]"] = self.paymentmethod_id
|
34
|
+
params["total_amount"] = Aceitafacil::Utils.format_number(self.total_amount)
|
35
|
+
|
36
|
+
self.items.each_with_index do |item, index|
|
37
|
+
params["item[#{index}][amount]"] = Aceitafacil::Utils.format_number(item.amount)
|
38
|
+
params["item[#{index}][vendor_id]"] = item.vendor_id
|
39
|
+
params["item[#{index}][vendor_name]"] = item.vendor_name
|
40
|
+
params["item[#{index}][fee_split]"] = item.fee_split
|
41
|
+
params["item[#{index}][description]"] = item.description
|
42
|
+
params["item[#{index}][trigger_lock]"] = item.trigger_lock
|
43
|
+
end
|
44
|
+
|
45
|
+
return params
|
46
|
+
end
|
47
|
+
|
48
|
+
def save
|
49
|
+
response = @connection.post("payment", params)
|
50
|
+
|
51
|
+
json = JSON.parse(response.body)
|
52
|
+
|
53
|
+
self.id = json["id"]
|
54
|
+
self.organization_id = json["organization_id"]
|
55
|
+
self.organization_name = json["organization_name"]
|
56
|
+
self.paymentmethod = json["paymentmethod"]
|
57
|
+
self.chargetype = json["chargetype"]
|
58
|
+
self.payer = json["payer"]
|
59
|
+
self.paid = json["paid"]
|
60
|
+
self.closed = json["closed"]
|
61
|
+
self.attempted = json["attempted"]
|
62
|
+
self.attempted_count = json["attempted_count"]
|
63
|
+
self.next_payment_attempt = json["next_payment_attempt"]
|
64
|
+
self.period_start = json["period_start"]
|
65
|
+
self.period_end = json["period_end"]
|
66
|
+
|
67
|
+
return response
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
module Aceitafacil
|
4
|
+
class Vendor
|
5
|
+
attr_accessor :id, :name, :email, :bank
|
6
|
+
|
7
|
+
def initialize(params = {})
|
8
|
+
@connection = Aceitafacil::Connection.new
|
9
|
+
|
10
|
+
self.id = params[:id]
|
11
|
+
self.name = params[:name]
|
12
|
+
self.email = params[:email]
|
13
|
+
self.bank = Bank.new(params[:bank]) if params[:bank]
|
14
|
+
end
|
15
|
+
|
16
|
+
def params
|
17
|
+
params = {}
|
18
|
+
|
19
|
+
params["vendor[id]"] = self.id
|
20
|
+
params["vendor[name]"] = self.name
|
21
|
+
params["vendor[email]"] = self.email
|
22
|
+
params["vendor[bank][code]"] = self.bank.code
|
23
|
+
params["vendor[bank][agency]"] = self.bank.agency
|
24
|
+
params["vendor[bank][account_type]"] = self.bank.account_type
|
25
|
+
params["vendor[bank][account_number]"] = self.bank.account_number
|
26
|
+
params["vendor[bank][account_holder_name]"] = self.bank.account_holder_name
|
27
|
+
params["vendor[bank][account_holder_document_type]"] = self.bank.account_holder_document_type
|
28
|
+
params["vendor[bank][account_holder_document_number]"] = self.bank.account_holder_document_number
|
29
|
+
|
30
|
+
return params
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.find(vendor_id)
|
34
|
+
return nil if vendor_id.nil?
|
35
|
+
|
36
|
+
@connection = Aceitafacil::Connection.new
|
37
|
+
|
38
|
+
find_params = {}
|
39
|
+
|
40
|
+
find_params["vendor[id]"] = vendor_id
|
41
|
+
|
42
|
+
response = @connection.get("vendor", find_params)
|
43
|
+
|
44
|
+
json = JSON.parse(response.body)
|
45
|
+
|
46
|
+
bank = {
|
47
|
+
code: json["vendor"]["bank"][0]["code"],
|
48
|
+
agency: json["vendor"]["bank"][0]["agency"],
|
49
|
+
account_type: json["vendor"]["bank"][0]["account_type"],
|
50
|
+
account_number: json["vendor"]["bank"][0]["account_number"],
|
51
|
+
account_holder_name: json["vendor"]["bank"][0]["account_holder_name"],
|
52
|
+
account_holder_document_type: json["vendor"]["bank"][0]["account_holder_document_type"],
|
53
|
+
account_holder_document_number: json["vendor"]["bank"][0]["account_holder_document_number"]
|
54
|
+
}
|
55
|
+
|
56
|
+
vendor = Aceitafacil::Vendor.new(
|
57
|
+
id: json["vendor"]["id"],
|
58
|
+
name: json["vendor"]["name"],
|
59
|
+
email: json["vendor"]["email"],
|
60
|
+
bank: bank
|
61
|
+
)
|
62
|
+
|
63
|
+
return vendor
|
64
|
+
end
|
65
|
+
|
66
|
+
def update
|
67
|
+
response = @connection.put("vendor", params)
|
68
|
+
|
69
|
+
return response
|
70
|
+
end
|
71
|
+
|
72
|
+
def save
|
73
|
+
response = @connection.post("vendor", params)
|
74
|
+
|
75
|
+
return response
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Aceitafacil
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Cria o initializer do Aceita Fácil na app rails"
|
7
|
+
def copy_initializer
|
8
|
+
template "aceitafacil.rb", "config/initializers/aceitafacil.rb"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Use esse arquivo para configurar a integração com o Aceita Fácil.
|
4
|
+
Aceitafacil.setup do |config|
|
5
|
+
# Altere para production ao final dos seus testes
|
6
|
+
config.environment = :test
|
7
|
+
|
8
|
+
# Chave pública
|
9
|
+
config.api_key = ""
|
10
|
+
|
11
|
+
# Chave privada
|
12
|
+
config.api_password = ""
|
13
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Aceitafacil::Card do
|
4
|
+
let(:card_params) { { name: "Card Holder", number: "4012001038443335", cvv: "123", exp_date: "201807", customer_id: "1" } }
|
5
|
+
|
6
|
+
before do
|
7
|
+
@card = Aceitafacil::Card.new(card_params)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "make a remove call" do
|
11
|
+
it "should return nil if card is nil" do
|
12
|
+
remote_card = Aceitafacil::Card.remove(nil)
|
13
|
+
remote_card.should be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should remote a remote card" do
|
17
|
+
@card.save
|
18
|
+
|
19
|
+
token = @card.token
|
20
|
+
|
21
|
+
remote_card = Aceitafacil::Card.remove(@card)
|
22
|
+
remote_card.token.should eq(token)
|
23
|
+
remote_card.status.should eq("removed")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "fetching existent cards" do
|
28
|
+
it "should be nil if customer_id is not passed" do
|
29
|
+
@card.save
|
30
|
+
@cards = Aceitafacil::Card.find_by_customer_id(nil)
|
31
|
+
@cards.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return a list cards" do
|
35
|
+
@card.save
|
36
|
+
@cards = Aceitafacil::Card.find_by_customer_id("1")
|
37
|
+
@cards.count.should == 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "making a save call" do
|
42
|
+
it "should return an http success" do
|
43
|
+
response = @card.save
|
44
|
+
|
45
|
+
response.should be_kind_of Net::HTTPSuccess
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should create a new remote card" do
|
49
|
+
@card.save
|
50
|
+
|
51
|
+
@card.token.should_not be_nil
|
52
|
+
@card.card_brand.should_not be_nil
|
53
|
+
@card.last_digits.should_not be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Aceitafacil::Connection do
|
4
|
+
before do
|
5
|
+
# FakeWeb.allow_net_connect = true
|
6
|
+
@connection = Aceitafacil::Connection.new
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
# FakeWeb.allow_net_connect = false
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should estabilish connection when was created" do
|
14
|
+
@connection.environment.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "making a request" do
|
18
|
+
it "should make a request" do
|
19
|
+
@card = Aceitafacil::Card.new(name: "Card Holder", number: "4012001038443335", cvv: "123", exp_date: "201807", customer_id: "1")
|
20
|
+
response = @connection.post(:card, @card.params)
|
21
|
+
response.body.should_not be_nil
|
22
|
+
response.should be_kind_of Net::HTTPOK
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Aceitafacil::Payment do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@vendor = Aceitafacil::Vendor.find(2)
|
9
|
+
@card = Aceitafacil::Card.find_by_customer_id(1)[0]
|
10
|
+
@item = Aceitafacil::Item.new(item_params)
|
11
|
+
@payment = Aceitafacil::Payment.new(payment_params)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'payments crud' do
|
15
|
+
describe "request to create an payment" do
|
16
|
+
let(:payment_params) {
|
17
|
+
{
|
18
|
+
description: "Test payment",
|
19
|
+
customer_id: 1,
|
20
|
+
customer_name: "Fulano de Tal",
|
21
|
+
customer_email: "fulano@fulanodetal.com.br",
|
22
|
+
customer_email_language: "pt-BR",
|
23
|
+
paymentmethod_id: 1, # 1 Credit Card, 2 billet
|
24
|
+
total_amount: 10,
|
25
|
+
items: [@item],
|
26
|
+
card: @card
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
let(:item_params) {
|
31
|
+
{
|
32
|
+
amount: 10.0,
|
33
|
+
vendor_id: @vendor.id,
|
34
|
+
vendor_name: @vendor.name,
|
35
|
+
fee_split: 1,
|
36
|
+
description: "Test item",
|
37
|
+
trigger_lock: false
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
it "should return a successfully response" do
|
42
|
+
response = @payment.save
|
43
|
+
response.should be_kind_of Net::HTTPSuccess
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return a correct params" do
|
47
|
+
response = @payment.save
|
48
|
+
|
49
|
+
@payment.id.should_not be_nil
|
50
|
+
@payment.organization_id.should_not be_nil
|
51
|
+
@payment.organization_name.should_not be_nil
|
52
|
+
@payment.paymentmethod.should eq("CREDITCARD")
|
53
|
+
@payment.chargetype = "AVISTA"
|
54
|
+
@payment.payer = "CUSTOMER"
|
55
|
+
@payment.paid = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Aceitafacil::Vendor do
|
6
|
+
let(:vendor_params) {
|
7
|
+
{
|
8
|
+
id: "2", name: "Vendor name", email: "vendor@vendor.com",
|
9
|
+
bank: {
|
10
|
+
code: "001",
|
11
|
+
agency: "123-4",
|
12
|
+
account_type: 1, # 1 Corrent, 2 Poupança
|
13
|
+
account_number: "1234-5",
|
14
|
+
account_holder_name: "Fulano",
|
15
|
+
account_holder_document_type: 1, # 1 CPF, 2 CNPJ
|
16
|
+
account_holder_document_number: "12345678909"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
before do
|
22
|
+
@vendor = Aceitafacil::Vendor.new(vendor_params)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "fetching existent vendors" do
|
26
|
+
it "should be nil if customer_id is not passed" do
|
27
|
+
@vendor = Aceitafacil::Vendor.find(nil)
|
28
|
+
@vendor.should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# it "should return a list vendors" do
|
32
|
+
# @vendor = Aceitafacil::Vendor.find(2)
|
33
|
+
|
34
|
+
# @vendor.id.should == vendor_params[:id]
|
35
|
+
# @vendor.name.should == vendor_params[:name]
|
36
|
+
# @vendor.email.should == vendor_params[:email]
|
37
|
+
# end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "making a update call" do
|
41
|
+
it do
|
42
|
+
response = @vendor.update
|
43
|
+
response.should be_kind_of Net::HTTPSuccess
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should update a remote vendor" do
|
47
|
+
@vendor.name = "Chuck Norris"
|
48
|
+
@vendor.update
|
49
|
+
@vendor = Aceitafacil::Vendor.find(2)
|
50
|
+
@vendor.name.should eq("Chuck Norris")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# describe "making a save call" do
|
55
|
+
# it "should create a new remote vendor" do
|
56
|
+
# response = @vendor.save
|
57
|
+
# response.should be_kind_of Net::HTTPSuccess
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'aceitafacil'
|
2
|
+
require 'fakeweb'
|
3
|
+
|
4
|
+
FakeWeb.allow_net_connect = true
|
5
|
+
|
6
|
+
Aceitafacil.setup do |config|
|
7
|
+
# Altere para production ao final dos seus testes
|
8
|
+
config.environment = :test
|
9
|
+
# Chave pública
|
10
|
+
config.api_key = "e3c23d27ca61ac2cc3b8a1e4ed5340247221757d"
|
11
|
+
# Chave privada
|
12
|
+
config.api_password = "773aebdf0d1202cac6837751f354c0a70553b3cd"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aceitafacil
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wilbert Ribeiro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 10.3.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 10.3.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.14.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.14.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: fakeweb
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: factory_girl_rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 4.4.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 4.4.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: debugger
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.6.6
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.6.6
|
111
|
+
description: ! ' It implements Cards and Payments from Aceita Fácil doc spec. '
|
112
|
+
email:
|
113
|
+
- wkelyson@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- aceitafacil.gemspec
|
124
|
+
- lib/aceitafacil.rb
|
125
|
+
- lib/aceitafacil/bank.rb
|
126
|
+
- lib/aceitafacil/card.rb
|
127
|
+
- lib/aceitafacil/connection.rb
|
128
|
+
- lib/aceitafacil/item.rb
|
129
|
+
- lib/aceitafacil/payment.rb
|
130
|
+
- lib/aceitafacil/utils.rb
|
131
|
+
- lib/aceitafacil/vendor.rb
|
132
|
+
- lib/aceitafacil/version.rb
|
133
|
+
- lib/templates/aceitafacil/install_generator.rb
|
134
|
+
- lib/templates/templates/aceitafacil.rb
|
135
|
+
- spec/aceitafacil/card_spec.rb
|
136
|
+
- spec/aceitafacil/connection_spec.rb
|
137
|
+
- spec/aceitafacil/payment_spec.rb
|
138
|
+
- spec/aceitafacil/utils_spec.rb
|
139
|
+
- spec/aceitafacil/vendor_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
homepage: http://www.github.com/wilbert/aceitafacil
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
metadata: {}
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 2.2.2
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: This gem enables Aceita Fácil API features on Ruby on Rails
|
165
|
+
test_files:
|
166
|
+
- spec/aceitafacil/card_spec.rb
|
167
|
+
- spec/aceitafacil/connection_spec.rb
|
168
|
+
- spec/aceitafacil/payment_spec.rb
|
169
|
+
- spec/aceitafacil/utils_spec.rb
|
170
|
+
- spec/aceitafacil/vendor_spec.rb
|
171
|
+
- spec/spec_helper.rb
|