aceitafacil 0.0.5 → 0.0.6

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NWM0OGFlZTNkMjU1YTcyNDRlZTBiYWY4NGQ3ZTZjNGRlZWIyMjYzMQ==
4
+ ODgzZTkwZDdlMDU5MWM2OWMzYjg1ZjBmYjI3OWEzYjE4NWE2YTQ1Yw==
5
5
  data.tar.gz: !binary |-
6
- MTM2YTNlZGYyNWE1MzBkNmVmY2M5NjVlNTQ4NjdkMGNkMDc5YmU4ZA==
6
+ ZGNhYTVlYzUyMWRiYWNiNGY4YTdlMDU5N2M0ZTg1YjY0M2M0NTY1ZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjZiZjk0OGNjNzI2OThhODZkMDU1M2IxNjQ2ZDk0MmZmNjlmZjQyNWM2ZTZm
10
- NGI5NzdlNDFjNTk1Y2I0NTEwYzJmMDE1MGZhYTA2MTJmOGZlZGVkM2M2Nzhk
11
- NjMyYjI3YTEzNzE5MDQ0ODFjNTgwMmEwYWJhMjhmYTBkNGIxZmY=
9
+ MjY4NmVmN2NmOWI5NGEyMTFjM2Y1ZDZkOGY0NmM2MGEyZTdmOGEyNmNkODhh
10
+ ZmE2YWZlYTkwMjg4ZjYxZTEwMzQ0MjhkYzc5OTM2NmRjOGY5MmRjOTdhNThj
11
+ ODA4MmEyMmY0MDU2OGM2NjQ1NDI3MDExMTgzMmY2ZWJmOTBlMDQ=
12
12
  data.tar.gz: !binary |-
13
- Zjc1MTE1MWZlZGM4YTlmNWFkNjA3NTU0ZjNjYzY1ZjEwMmVhYzYzZmNhNTUx
14
- OWExZTU5Njg5NWE2NTA1NWJiZGNjNjg4OTdlMWExZjE5MDAyYjAxN2IzNTRk
15
- NDlkNjlhNDljZTc3YTAzYTU2NDI0OGU3MTdmNmNmZjE0NmVlMDI=
13
+ OWM1YzkyZjE1NTM1NTVlN2Y0MGExMjZhNjg0ODMyYmI0MjMwODQxNTcyZjc4
14
+ NjM2ZWRlNWE5NWI3M2VkZmQ0NDc4MTQ5M2IzOTJmYTM0NjE3N2E2ZjczNDU2
15
+ ZWZkMDAxYWM0N2RkYjEyYzUzZTA3MmU3MGMwMmM0YjE1YTI1OWU=
data/README.md CHANGED
@@ -65,7 +65,7 @@ Recupere as informações do TOKEN do cartão de crédito, Ex:
65
65
 
66
66
  Faça uma requisição para efetuar o pagamento:
67
67
 
68
- @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)
68
+ @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_token: @card.token)
69
69
 
70
70
  @payment.save
71
71
 
@@ -23,7 +23,7 @@ module Aceitafacil
23
23
  response = @connection.get("card", connection_params)
24
24
 
25
25
  json = JSON.parse(response.body)
26
-
26
+
27
27
  return [] if json["card"].nil?
28
28
 
29
29
  json["card"].each do |remote_card|
@@ -4,7 +4,7 @@ module Aceitafacil
4
4
  class Item
5
5
  include ActiveModel::Validations
6
6
 
7
- validates :amount, :vendor_id, :vendor_name, :fee_split, :description, :trigger_lock, presence: true
7
+ validates :amount, presence: true
8
8
 
9
9
  attr_accessor :amount, :vendor_id, :vendor_name, :fee_split, :description, :trigger_lock
10
10
 
@@ -5,10 +5,10 @@ module Aceitafacil
5
5
  include ActiveModel::Validations
6
6
  include ActiveModel::Model
7
7
 
8
- validates :card, :customer_id, :customer_name, :customer_email, :customer_email_language, presence: true
8
+ validates :card_token, :customer_id, presence: true
9
9
  validates :description, :paymentmethod_id, :total_amount, presence: true
10
10
 
11
- attr_accessor :card, :customer_id, :customer_name, :customer_email, :customer_email_language
11
+ attr_accessor :card_token, :customer_id, :customer_name, :customer_email, :customer_email_language
12
12
  attr_accessor :organization_id, :organization_name, :paymentmethod, :charge_type, :payer, :total_amount
13
13
  attr_accessor :paid, :closed, :attempted, :attempted_count, :next_payment_attempt, :period_start
14
14
  attr_accessor :period_end, :items, :id, :description, :paymentmethod_id, :chargetype
@@ -16,7 +16,7 @@ module Aceitafacil
16
16
  def initialize(params = {})
17
17
  @connection = Aceitafacil::Connection.new
18
18
 
19
- self.card = params[:card]
19
+ self.card_token = params[:card_token]
20
20
  self.customer_id = params[:customer_id]
21
21
  self.customer_name = params[:customer_name]
22
22
  self.customer_email = params[:customer_email]
@@ -30,22 +30,22 @@ module Aceitafacil
30
30
  def params
31
31
  params = {}
32
32
 
33
- params["card[token]"] = self.card.token
33
+ params["card[token]"] = self.card_token
34
34
  params["customer[id]"] = self.customer_id.to_i
35
- params["customer[name]"] = self.customer_name
36
- params["customer[email]"] = self.customer_email
37
- params["customer[email_language]"] = self.customer_email_language
38
- params["description"] = self.description
39
- params["paymentmethod[id]"] = self.paymentmethod_id
35
+ params["customer[name]"] = self.customer_name unless self.customer_name.blank?
36
+ params["customer[email]"] = self.customer_email unless self.customer_name.blank?
37
+ params["customer[email_language]"] = self.customer_email_language unless self.customer_name.blank?
38
+ params["description"] = self.description unless self.customer_name.blank?
39
+ params["paymentmethod[id]"] = self.paymentmethod_id unless self.customer_name.blank?
40
40
  params["total_amount"] = Aceitafacil::Utils.format_number(self.total_amount)
41
41
 
42
42
  self.items.each_with_index do |item, index|
43
43
  params["item[#{index}][amount]"] = Aceitafacil::Utils.format_number(item.amount)
44
- params["item[#{index}][vendor_id]"] = item.vendor_id
45
- params["item[#{index}][vendor_name]"] = item.vendor_name
46
- params["item[#{index}][fee_split]"] = item.fee_split
47
- params["item[#{index}][description]"] = item.description
48
- params["item[#{index}][trigger_lock]"] = item.trigger_lock
44
+ params["item[#{index}][vendor_id]"] = item.vendor_id unless item.vendor_id.blank?
45
+ params["item[#{index}][vendor_name]"] = item.vendor_name unless item.vendor_name.blank?
46
+ params["item[#{index}][fee_split]"] = item.fee_split unless item.fee_split.blank?
47
+ params["item[#{index}][description]"] = item.description unless item.description.blank?
48
+ params["item[#{index}][trigger_lock]"] = item.trigger_lock unless item.trigger_lock.blank?
49
49
  end
50
50
 
51
51
  return params
@@ -61,22 +61,26 @@ module Aceitafacil
61
61
  response = @connection.post("payment", params)
62
62
 
63
63
  json = JSON.parse(response.body)
64
+
65
+ if json["errors"]
66
+ return json["errors"]
67
+ else
68
+ self.id = json["id"]
69
+ self.organization_id = json["organization_id"]
70
+ self.organization_name = json["organization_name"]
71
+ self.paymentmethod = json["paymentmethod"]
72
+ self.chargetype = json["chargetype"]
73
+ self.payer = json["payer"]
74
+ self.paid = json["paid"]
75
+ self.closed = json["closed"]
76
+ self.attempted = json["attempted"]
77
+ self.attempted_count = json["attempted_count"]
78
+ self.next_payment_attempt = json["next_payment_attempt"]
79
+ self.period_start = json["period_start"]
80
+ self.period_end = json["period_end"]
64
81
 
65
- self.id = json["id"]
66
- self.organization_id = json["organization_id"]
67
- self.organization_name = json["organization_name"]
68
- self.paymentmethod = json["paymentmethod"]
69
- self.chargetype = json["chargetype"]
70
- self.payer = json["payer"]
71
- self.paid = json["paid"]
72
- self.closed = json["closed"]
73
- self.attempted = json["attempted"]
74
- self.attempted_count = json["attempted_count"]
75
- self.next_payment_attempt = json["next_payment_attempt"]
76
- self.period_start = json["period_start"]
77
- self.period_end = json["period_end"]
78
-
79
- return response
82
+ return true
83
+ end
80
84
  end
81
85
  end
82
86
  end
@@ -1,3 +1,3 @@
1
1
  module Aceitafacil
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -48,7 +48,7 @@ describe Aceitafacil::Payment do
48
48
  paymentmethod_id: 1, # 1 Credit Card, 2 billet
49
49
  total_amount: 10,
50
50
  items: [@item],
51
- card: @card
51
+ card_token: @card.token
52
52
  }
53
53
  }
54
54
 
@@ -83,11 +83,6 @@ describe Aceitafacil::Payment do
83
83
  # @payment.save.should be_false
84
84
  # end
85
85
 
86
- it "should return a successfully response" do
87
- response = @payment.save
88
- response.should be_kind_of Net::HTTPOK
89
- end
90
-
91
86
  it "should return a correct params" do
92
87
  response = @payment.save
93
88
 
@@ -75,6 +75,7 @@ describe Aceitafacil::Vendor do
75
75
  describe "making a update call" do
76
76
  it do
77
77
  response = @vendor.update
78
+
78
79
  response.should be_kind_of Net::HTTPSuccess
79
80
  end
80
81
 
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.5
4
+ version: 0.0.6
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-14 00:00:00.000000000 Z
11
+ date: 2014-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json