aceitafacil 0.0.3 → 0.0.4

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
- MzA4ZmE5ZDA3NTA4YmQ4NDliODViNzNiOWUyN2U2NzA4OWFjM2ExNQ==
4
+ MTY0YTY5OWJjMjg4NDAwODc0ODQ5ZTZkMzMyZjQ2ZDMwYjUwNDNhNA==
5
5
  data.tar.gz: !binary |-
6
- OTQwM2NmYjY2YmZlNmZjYmYxYmRjYWM2MTVhNTQ1MmRiNGIyNWUxMQ==
6
+ NmU3MjRjNTNiM2ZmMmVkZTQzYmQxMDJmN2ViN2Q0M2YzZGUxNjEyMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGUyNzZlMDhlMjBiNzYzMThjNzk0Yzg0NTllMTQ0ZjhmNzRiZmI4YWMyZjEw
10
- ZTIxM2Q1NTUzMjJjNGVmZWQwZDI3NTM4YTI0YjI4NWQ1MTllOWY3OTU0ZDE2
11
- YmEyNmJjMzhiNmZhNjA0ZWYyMDk2ZTQxNGEwZjllOWY4MDI1ZGI=
9
+ YjgxMzI5NDMzZDJkYjFhYmYwZGFjZWI1YmQ5NTRkNDgzZmRmNjM2YmJlZDFi
10
+ MWQ0NzZlYzJiZTY4N2U0MmNmYzg0YmYwNDBiNjZlZjFiNGEwZTcwNjc2M2Fl
11
+ OGYzMDhhYmEyZDQwNTZjMjVlOGUxYTBmYTQ3N2UyZDQ4MjBiYTc=
12
12
  data.tar.gz: !binary |-
13
- NGViZWU2OWM1NWRhOTIwNDM0ODczODI4NDk3MDdlYzExZmIwMTEzMzhlYWQ5
14
- MzdjYjljM2I2Nzk4ZGQwODI0NWZhNmU3MzFmMzhlMTk2NWZkOGE4NTA4Zjk5
15
- ZmI2OTYxODQ2MGU5N2IwYTMwMzJmZmIxYWU4YzI1OGNlZGY4Y2Q=
13
+ OTdkYWI1YmUyM2VhZjAwY2Y2YTAxYTYyNTQ2MGNiNmE4NzYzZmI1M2ZiNWQ4
14
+ NmJiNGYwZjQ3M2IyMzA4NWM0Y2U1ODA3YmIwYjhlODY5YWYyMjA2MGNkOGUx
15
+ Zjc3MGM3ZGQ3OGUxYjBkMDgxZDhkZjRlZTQ1NDdkMzQ3YzdmNDQ=
data/README.md CHANGED
@@ -2,21 +2,25 @@
2
2
 
3
3
  Esta gem habilita as funcionalidades da API do serviço [Aceita Fácil][url] no Ruby on Rails.
4
4
 
5
- ## Installation
5
+ ## Instalação
6
6
 
7
7
  Adicione esta linha ao seu Gemfile:
8
8
 
9
9
  gem 'aceitafacil'
10
10
 
11
- E execute:
11
+ Execute para instalar a gem no seu projeto:
12
12
 
13
13
  $ bundle install
14
14
 
15
+ Em seguida instale o arquivo de configuração na sua aplicação:
16
+
17
+ $ rails generate aceitafacil:install
18
+
15
19
  Ou instale assim:
16
20
 
17
21
  $ gem install aceitafacil
18
22
 
19
- ## Usage
23
+ ## Como utilizar
20
24
 
21
25
  Cadastre os vendedores que receberão os pagamentos da loja em questão da seguinte forma:
22
26
 
@@ -75,6 +79,12 @@ Após a chamada do método save todos os métodos abaixo deverão estar preenchi
75
79
  @payment.payer
76
80
  @payment.paid
77
81
 
82
+ Todos os modelos Card, Vendor, Bank, Item, Payment possuem validação no estilo ActiveRecord, ex:
83
+
84
+ @card.valid?
85
+
86
+ Se for válido retornará true, se não false e o array @card.errors será preenchido com as mensagens de erro padrão do ActiveRecord.
87
+
78
88
  ## Contributing
79
89
 
80
90
  1. Fork it ( http://github.com/wilbert/aceitafacil/fork )
@@ -2,9 +2,11 @@
2
2
 
3
3
  module Aceitafacil
4
4
  class Card
5
+ include ActiveModel::Model
5
6
  include ActiveModel::Validations
6
7
 
7
8
  validates :customer_id, :number, :name, :cvv, :exp_date, presence: true
9
+ validates :exp_date, format: { with: /\d{6}/ }
8
10
 
9
11
  attr_accessor :customer_id, :number, :name, :cvv, :exp_date
10
12
  attr_accessor :token, :card_brand, :last_digits, :status
@@ -22,6 +24,8 @@ module Aceitafacil
22
24
 
23
25
  json = JSON.parse(response.body)
24
26
 
27
+ return [] if json["card"].nil?
28
+
25
29
  json["card"].each do |remote_card|
26
30
  card = Card.new(token: remote_card["token"], card_brand: remote_card["card_brand"], last_digits: remote_card["last_digits"])
27
31
  cards << card
@@ -81,7 +85,7 @@ module Aceitafacil
81
85
  response = @connection.post("card", params)
82
86
 
83
87
  json = JSON.parse(response.body)
84
-
88
+
85
89
  self.token = json["card"][0]["token"]
86
90
  self.card_brand = json["card"][0]["card_brand"]
87
91
  self.last_digits = json["card"][0]["last_digits"]
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Aceitafacil
4
4
  class Item
5
+ include ActiveModel::Validations
6
+
7
+ validates :amount, :vendor_id, :vendor_name, :fee_split, :description, :trigger_lock, presence: true
8
+
5
9
  attr_accessor :amount, :vendor_id, :vendor_name, :fee_split, :description, :trigger_lock
6
10
 
7
11
  def initialize(params = {})
@@ -2,6 +2,12 @@
2
2
 
3
3
  module Aceitafacil
4
4
  class Payment
5
+ include ActiveModel::Validations
6
+ include ActiveModel::Model
7
+
8
+ validates :card, :customer_id, :customer_name, :customer_email, :customer_email_language, presence: true
9
+ validates :description, :paymentmethod_id, :total_amount, presence: true
10
+
5
11
  attr_accessor :card, :customer_id, :customer_name, :customer_email, :customer_email_language
6
12
  attr_accessor :organization_id, :organization_name, :paymentmethod, :charge_type, :payer, :total_amount
7
13
  attr_accessor :paid, :closed, :attempted, :attempted_count, :next_payment_attempt, :period_start
@@ -46,6 +52,12 @@ module Aceitafacil
46
52
  end
47
53
 
48
54
  def save
55
+ return false if not self.valid?
56
+
57
+ self.items.each do |item|
58
+ return false if not item.valid?
59
+ end
60
+
49
61
  response = @connection.post("payment", params)
50
62
 
51
63
  json = JSON.parse(response.body)
@@ -1,3 +1,3 @@
1
1
  module Aceitafacil
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,11 +1,11 @@
1
- # encode: utf-8
1
+ # encode: utf8
2
2
 
3
3
  module Aceitafacil
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  source_root File.expand_path("../../templates", __FILE__)
7
7
 
8
- desc "Cria o initializer do Aceita Fácil na app rails"
8
+ desc "Create the initializer on rails app"
9
9
 
10
10
  def copy_initializer
11
11
  template "aceitafacil.rb", "config/initializers/aceitafacil.rb"
@@ -5,7 +5,7 @@ describe Aceitafacil::Card do
5
5
 
6
6
  before do
7
7
  @card = Aceitafacil::Card.new(card_params)
8
- @card.save
8
+ #@card.save
9
9
  end
10
10
 
11
11
  describe "instatiating a new card" do
@@ -49,6 +49,7 @@ describe Aceitafacil::Card do
49
49
 
50
50
  it "should return a list cards" do
51
51
  @card.save
52
+
52
53
  @cards = Aceitafacil::Card.find_by_customer_id("1")
53
54
  @cards.count.should == 1
54
55
  end
@@ -3,9 +3,34 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Aceitafacil::Payment do
6
+ let(:card_params) { { name: "Card Holder", number: "4012001038443335", cvv: "123", exp_date: "201807", customer_id: "1" } }
7
+
8
+ let(:bank_params) {
9
+ {
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
+ let(:vendor_params) {
21
+ {
22
+ id: "2", name: "Vendor name", email: "vendor@vendor.com", bank: @bank
23
+ }
24
+ }
25
+
26
+ before do
27
+ @card = Aceitafacil::Card.new(card_params)
28
+ @bank = Aceitafacil::Bank.new(bank_params)
29
+ @vendor = Aceitafacil::Vendor.new(vendor_params)
30
+
31
+ @vendor.save
32
+ @card.save
6
33
 
7
- before :each do
8
- @vendor = Aceitafacil::Vendor.find(2)
9
34
  @card = Aceitafacil::Card.find_by_customer_id(1)[0]
10
35
  @item = Aceitafacil::Item.new(item_params)
11
36
  @payment = Aceitafacil::Payment.new(payment_params)
@@ -34,13 +59,33 @@ describe Aceitafacil::Payment do
34
59
  vendor_name: @vendor.name,
35
60
  fee_split: 1,
36
61
  description: "Test item",
37
- trigger_lock: false
62
+ trigger_lock: "false"
38
63
  }
39
64
  }
40
65
 
66
+ it "should return false if an item is invalid" do
67
+ @item = Aceitafacil::Item.new
68
+ @item.valid?.should be_false
69
+ end
70
+
71
+ it "should return false if an item is invalid" do
72
+ @payment = Aceitafacil::Payment.new
73
+
74
+ @payment.valid?.should be_false
75
+ end
76
+
77
+ # it "should return false if an item is invalid" do
78
+ # incorrect_params = payment_params.dup
79
+
80
+ # incorrect_params[:item] = [Aceitafacil::Item.new]
81
+
82
+ # @payment = Aceitafacil::Payment.new(incorrect_params)
83
+ # @payment.save.should be_false
84
+ # end
85
+
41
86
  it "should return a successfully response" do
42
87
  response = @payment.save
43
- response.should be_kind_of Net::HTTPSuccess
88
+ response.should be_kind_of Net::HTTPOK
44
89
  end
45
90
 
46
91
  it "should return a correct params" do
@@ -79,20 +79,19 @@ describe Aceitafacil::Vendor do
79
79
  end
80
80
 
81
81
  it "should update a remote vendor" do
82
+ @vendor.save
82
83
  @vendor.name = "Chuck Norris"
83
84
  @vendor.update
84
- @vendor = Aceitafacil::Vendor.find(2)
85
+ @vendor = Aceitafacil::Vendor.find(@vendor.id)
85
86
  @vendor.name.should eq("Chuck Norris")
86
87
  end
87
88
  end
88
89
 
89
- # describe "making a save call" do
90
- # it "should create a new remote vendor" do
91
- # response = @vendor.save
92
-
93
- # puts response.body.inspect
94
-
95
- # response.should be_kind_of Net::HTTPSuccess
96
- # end
97
- # end
90
+ describe "making a save call" do
91
+ it "should create a new remote vendor" do
92
+ response = @vendor.save
93
+ puts response.inspect
94
+ response.should be_kind_of Net::HTTPOK
95
+ end
96
+ end
98
97
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aceitafacil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilbert Ribeiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-05 00:00:00.000000000 Z
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json