aceitafacil 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjM0NWYwMWFjZmZmMDZhOGVhNWExNzM1NjA2M2UxZTI2YWZkYjMxOQ==
4
+ MzA4ZmE5ZDA3NTA4YmQ4NDliODViNzNiOWUyN2U2NzA4OWFjM2ExNQ==
5
5
  data.tar.gz: !binary |-
6
- OWYwYmU5NWM2MDRjNDczZWQ3NDBjMGZlZmQzYTdhMTUxOWJhNDE2YQ==
6
+ OTQwM2NmYjY2YmZlNmZjYmYxYmRjYWM2MTVhNTQ1MmRiNGIyNWUxMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjYyNjVmMWQ0OWZmODA1ZjU3ZGZlYTU1ZmMxOTA0OTdmZWYwODkyNTU3Y2Q0
10
- YmZmY2FiZTMwOWM3ZmUyZTgxNjM0NzE2Zjc2YzQwMDFhMjRhYjdjOTFkZGJh
11
- OGQ5OTZkZDczZjlmNTFmMWFjNGIyOTRmNWQ5OTNkYTQ1Njc2ODY=
9
+ ZGUyNzZlMDhlMjBiNzYzMThjNzk0Yzg0NTllMTQ0ZjhmNzRiZmI4YWMyZjEw
10
+ ZTIxM2Q1NTUzMjJjNGVmZWQwZDI3NTM4YTI0YjI4NWQ1MTllOWY3OTU0ZDE2
11
+ YmEyNmJjMzhiNmZhNjA0ZWYyMDk2ZTQxNGEwZjllOWY4MDI1ZGI=
12
12
  data.tar.gz: !binary |-
13
- MGUwMGEzM2M4Zjg4MDY3YjJmMWUxYTVkYjFlNjNmZWRjZTFhNWQ3ZjAyYmNk
14
- NGFiZDNmYzUyNWY1YTEzMThiMGIxZmQxNDc5ZWU2Nzg3ODU2NGI4NzlkMTI5
15
- NTc2MTRlZDVkMWYyZWQzZmMzYWE3OTI2NDMxNjI0ZjA1ZDUzOGI=
13
+ NGViZWU2OWM1NWRhOTIwNDM0ODczODI4NDk3MDdlYzExZmIwMTEzMzhlYWQ5
14
+ MzdjYjljM2I2Nzk4ZGQwODI0NWZhNmU3MzFmMzhlMTk2NWZkOGE4NTA4Zjk5
15
+ ZmI2OTYxODQ2MGU5N2IwYTMwMzJmZmIxYWU4YzI1OGNlZGY4Y2Q=
data/README.md CHANGED
@@ -10,7 +10,7 @@ Adicione esta linha ao seu Gemfile:
10
10
 
11
11
  E execute:
12
12
 
13
- $ bundle
13
+ $ bundle install
14
14
 
15
15
  Ou instale assim:
16
16
 
@@ -21,19 +21,20 @@ Ou instale assim:
21
21
  Cadastre os vendedores que receberão os pagamentos da loja em questão da seguinte forma:
22
22
 
23
23
  @vendor = Aceitafacil::Vendor.new(id: "2", name: "Vendor name", email: "vendor@vendor.com",
24
- bank: {
24
+ bank: @bank)
25
+
26
+ @vendor.save
27
+
28
+ O id: refere-se ao ID do vendedor na base de dados da aplicação Host. O objeto @bank pode ser instanciado da seguinte forma:
29
+
30
+ @bank = Aceitafacil::Bank.new({
25
31
  code: "001",
26
32
  agency: "123-4",
27
33
  account_type: 1, # 1 Corrent, 2 Poupança
28
34
  account_number: "1234-5",
29
35
  account_holder_name: "Fulano",
30
36
  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
+ account_holder_document_number: "12345678909"})
37
38
 
38
39
  Implemente um formulário para capturar os dados do cartão de crédito. Segue um exemplo:
39
40
 
data/aceitafacil.gemspec CHANGED
@@ -18,7 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "json", "1.8.1"
21
+ spec.add_dependency "json", "1.8.1"
22
+ spec.add_dependency "activemodel", "4.0.4"
23
+ spec.add_dependency "activesupport", "4.0.4"
22
24
 
23
25
  spec.add_development_dependency "bundler", "~> 1.5"
24
26
  spec.add_development_dependency "rake", "10.3.1"
@@ -2,6 +2,11 @@
2
2
 
3
3
  module Aceitafacil
4
4
  class Bank
5
+ include ActiveModel::Validations
6
+
7
+ validates :code, :agency, :account_type, :account_number, :account_holder_name, presence: true
8
+ validates :account_holder_document_type, :account_holder_document_number, presence: true
9
+
5
10
  attr_accessor :code, :agency, :account_type, :account_number, :account_holder_name
6
11
  attr_accessor :account_holder_document_type, :account_holder_document_number
7
12
 
@@ -1,7 +1,11 @@
1
1
  #encoding: utf-8
2
2
 
3
- module Aceitafacil
3
+ module Aceitafacil
4
4
  class Card
5
+ include ActiveModel::Validations
6
+
7
+ validates :customer_id, :number, :name, :cvv, :exp_date, presence: true
8
+
5
9
  attr_accessor :customer_id, :number, :name, :cvv, :exp_date
6
10
  attr_accessor :token, :card_brand, :last_digits, :status
7
11
 
@@ -72,6 +76,8 @@ module Aceitafacil
72
76
  end
73
77
 
74
78
  def save
79
+ return false if not self.valid?
80
+
75
81
  response = @connection.post("card", params)
76
82
 
77
83
  json = JSON.parse(response.body)
@@ -42,8 +42,6 @@ module Aceitafacil
42
42
  return response
43
43
  end
44
44
 
45
-
46
-
47
45
  def get(path, params={})
48
46
  if not params.nil?
49
47
  request = Net::HTTP::Get.new("/#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')))
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Aceitafacil
4
4
  class Vendor
5
+ include ActiveModel::Validations
6
+
7
+ validates :id, :email, :name, :bank, presence: true
8
+
5
9
  attr_accessor :id, :name, :email, :bank
6
10
 
7
11
  def initialize(params = {})
@@ -10,7 +14,7 @@ module Aceitafacil
10
14
  self.id = params[:id]
11
15
  self.name = params[:name]
12
16
  self.email = params[:email]
13
- self.bank = Bank.new(params[:bank]) if params[:bank]
17
+ self.bank = params[:bank]
14
18
  end
15
19
 
16
20
  def params
@@ -70,6 +74,8 @@ module Aceitafacil
70
74
  end
71
75
 
72
76
  def save
77
+ return false if not self.valid? or not self.bank.valid?
78
+
73
79
  response = @connection.post("vendor", params)
74
80
 
75
81
  return response
@@ -1,3 +1,3 @@
1
1
  module Aceitafacil
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/aceitafacil.rb CHANGED
@@ -1,10 +1,16 @@
1
- require 'active_support'
1
+ require 'active_support/core_ext'
2
+ require 'active_model'
2
3
  require "builder"
3
4
  require "net/http"
4
5
  require "net/https"
5
6
  require "json"
6
7
 
7
8
  module Aceitafacil
9
+ def self.clear_data
10
+ @connection = Aceitafacil::Connection.new
11
+ @connection.post("cleardata")
12
+ end
13
+
8
14
  class Production
9
15
  BASE_URL = "api.aceitafacil.com"
10
16
  end
@@ -1,9 +1,12 @@
1
+ # encode: utf-8
2
+
1
3
  module Aceitafacil
2
4
  module Generators
3
5
  class InstallGenerator < Rails::Generators::Base
4
6
  source_root File.expand_path("../../templates", __FILE__)
5
7
 
6
8
  desc "Cria o initializer do Aceita Fácil na app rails"
9
+
7
10
  def copy_initializer
8
11
  template "aceitafacil.rb", "config/initializers/aceitafacil.rb"
9
12
  end
@@ -5,6 +5,22 @@ describe Aceitafacil::Card do
5
5
 
6
6
  before do
7
7
  @card = Aceitafacil::Card.new(card_params)
8
+ @card.save
9
+ end
10
+
11
+ describe "instatiating a new card" do
12
+ it "should return valid true when" do
13
+ @invalid = Aceitafacil::Card.new
14
+ @invalid.valid?.should be_false
15
+ end
16
+
17
+ it "should return message erros for fields" do
18
+ @invalid = Aceitafacil::Card.new
19
+ @invalid.valid?
20
+ [:customer_id, :number, :name, :cvv, :exp_date].each do |key|
21
+ @invalid.errors.messages.keys.should include(key)
22
+ end
23
+ end
8
24
  end
9
25
 
10
26
  describe "make a remove call" do
@@ -3,25 +3,60 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Aceitafacil::Vendor do
6
+ let(:bank_params) {
7
+ {
8
+ code: "001",
9
+ agency: "123-4",
10
+ account_type: 1, # 1 Corrent, 2 Poupança
11
+ account_number: "1234-5",
12
+ account_holder_name: "Fulano",
13
+ account_holder_document_type: 1, # 1 CPF, 2 CNPJ
14
+ account_holder_document_number: "12345678909"
15
+ }
16
+ }
17
+
6
18
  let(:vendor_params) {
7
19
  {
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
- }
20
+ id: "2", name: "Vendor name", email: "vendor@vendor.com", bank: @bank
18
21
  }
19
22
  }
20
23
 
21
24
  before do
25
+ @bank = Aceitafacil::Bank.new(bank_params)
22
26
  @vendor = Aceitafacil::Vendor.new(vendor_params)
23
27
  end
24
28
 
29
+ describe "instatiating a new card" do
30
+ it "should return valid true when valid? is called" do
31
+ @vendor = Aceitafacil::Vendor.new
32
+ @vendor.valid?.should be_false
33
+ end
34
+
35
+ it "should return valid true when it is saved" do
36
+ @vendor = Aceitafacil::Vendor.new
37
+ @vendor.save.should be_false
38
+ end
39
+
40
+ it "should return valid true when it is saved" do
41
+ @vendor = Aceitafacil::Vendor.new(id: 1, name: "Vendor name", email: "vendor@email.com", bank: nil)
42
+ @vendor.save.should be_false
43
+ end
44
+
45
+ it "should return valid true when it is saved" do
46
+ @vendor = Aceitafacil::Vendor.new(id: 1, name: "Vendor name", email: "vendor@email.com", bank: Aceitafacil::Bank.new)
47
+
48
+ @vendor.save.should be_false
49
+ end
50
+
51
+ it "should return message erros for fields" do
52
+ @vendor = Aceitafacil::Vendor.new
53
+ @vendor.valid?
54
+ [:id, :email, :name, :bank].each do |key|
55
+ @vendor.errors.messages.keys.should include(key)
56
+ end
57
+ end
58
+ end
59
+
25
60
  describe "fetching existent vendors" do
26
61
  it "should be nil if customer_id is not passed" do
27
62
  @vendor = Aceitafacil::Vendor.find(nil)
@@ -54,6 +89,9 @@ describe Aceitafacil::Vendor do
54
89
  # describe "making a save call" do
55
90
  # it "should create a new remote vendor" do
56
91
  # response = @vendor.save
92
+
93
+ # puts response.body.inspect
94
+
57
95
  # response.should be_kind_of Net::HTTPSuccess
58
96
  # end
59
97
  # end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,12 @@ require 'fakeweb'
3
3
 
4
4
  FakeWeb.allow_net_connect = true
5
5
 
6
+ RSpec.configure do |config|
7
+ config.before(:all) do
8
+ Aceitafacil.clear_data
9
+ end
10
+ end
11
+
6
12
  Aceitafacil.setup do |config|
7
13
  # Altere para production ao final dos seus testes
8
14
  config.environment = :test
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aceitafacil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilbert Ribeiro
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.4
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -130,8 +158,8 @@ files:
130
158
  - lib/aceitafacil/utils.rb
131
159
  - lib/aceitafacil/vendor.rb
132
160
  - lib/aceitafacil/version.rb
133
- - lib/templates/aceitafacil/install_generator.rb
134
- - lib/templates/templates/aceitafacil.rb
161
+ - lib/generators/aceitafacil/install_generator.rb
162
+ - lib/generators/templates/aceitafacil.rb
135
163
  - spec/aceitafacil/card_spec.rb
136
164
  - spec/aceitafacil/connection_spec.rb
137
165
  - spec/aceitafacil/payment_spec.rb