cbraspag 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/README.md +4 -3
  2. data/cbraspag.gemspec +2 -0
  3. data/coverage/.resultset.json +3445 -0
  4. data/coverage/assets/0.5.3/app.js +88 -0
  5. data/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  6. data/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  7. data/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  8. data/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  9. data/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  10. data/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  11. data/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  12. data/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  13. data/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  14. data/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  15. data/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  16. data/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  17. data/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  18. data/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  19. data/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  20. data/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  21. data/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  22. data/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  23. data/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  24. data/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  25. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +363 -0
  26. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
  27. data/coverage/assets/0.5.3/favicon_green.png +0 -0
  28. data/coverage/assets/0.5.3/favicon_red.png +0 -0
  29. data/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  30. data/coverage/assets/0.5.3/highlight.css +129 -0
  31. data/coverage/assets/0.5.3/highlight.pack.js +1 -0
  32. data/coverage/assets/0.5.3/jquery-1.6.2.min.js +18 -0
  33. data/coverage/assets/0.5.3/jquery.dataTables.min.js +152 -0
  34. data/coverage/assets/0.5.3/jquery.timeago.js +141 -0
  35. data/coverage/assets/0.5.3/jquery.url.js +174 -0
  36. data/coverage/assets/0.5.3/loading.gif +0 -0
  37. data/coverage/assets/0.5.3/magnify.png +0 -0
  38. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  39. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  40. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  41. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  42. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  43. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  44. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  45. data/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  46. data/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  47. data/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  48. data/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  49. data/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  50. data/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  51. data/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +295 -0
  52. data/coverage/assets/0.5.3/stylesheet.css +383 -0
  53. data/coverage/index.html +21549 -0
  54. data/lib/cbraspag.rb +1 -1
  55. data/lib/cbraspag/core/connection.rb +25 -20
  56. data/lib/cbraspag/core/converter.rb +22 -119
  57. data/lib/cbraspag/core/customer.rb +0 -24
  58. data/lib/cbraspag/core/order.rb +179 -129
  59. data/lib/cbraspag/payment/billet.rb +38 -17
  60. data/lib/cbraspag/payment/credit_card.rb +86 -112
  61. data/lib/cbraspag/payment/eft.rb +0 -16
  62. data/lib/cbraspag/payment/recurrency_credit_card.rb +99 -0
  63. data/lib/cbraspag/version.rb +1 -1
  64. data/spec/core/connection_spec.rb +56 -2
  65. data/spec/core/converter_spec.rb +49 -10
  66. data/spec/core/order_spec.rb +315 -193
  67. data/spec/integration/billet_spec.rb +38 -0
  68. data/spec/integration/credit_card_spec.rb +0 -0
  69. data/spec/payment/billet_spec.rb +130 -81
  70. data/spec/payment/credit_card_spec.rb +263 -487
  71. data/spec/payment/recurrency_credit_card_spec.rb +479 -0
  72. data/spec/spec_helper.rb +15 -2
  73. metadata +92 -6
  74. data/Guardfile +0 -10
  75. data/lib/cbraspag/core/response.rb +0 -27
  76. data/spec/core/response_spec.rb +0 -5
data/lib/cbraspag.rb CHANGED
@@ -6,12 +6,12 @@ require 'json'
6
6
  require 'nokogiri'
7
7
  require 'savon'
8
8
  require 'bigdecimal'
9
+ require 'active_merchant'
9
10
 
10
11
  require "cbraspag/version"
11
12
  require 'cbraspag/core/converter'
12
13
  require 'cbraspag/core/connection'
13
14
  require 'cbraspag/core/poster'
14
- require 'cbraspag/core/response'
15
15
  require 'cbraspag/core/customer'
16
16
  require 'cbraspag/core/order'
17
17
 
@@ -54,7 +54,7 @@ module Braspag
54
54
  braspag_url + "/pagador/passthru.asp"
55
55
  when :info_billet
56
56
  braspag_info_url + "/GetDadosBoleto"
57
- when :info_card
57
+ when :info_credit_card
58
58
  braspag_info_url + "/GetDadosCartao"
59
59
  when :info
60
60
  braspag_info_url + "/GetDadosPedido"
@@ -69,28 +69,33 @@ module Braspag
69
69
  end
70
70
  end
71
71
 
72
- def convert_to(method)
73
- {:merchant_id => self.merchant_id}
72
+ def post(method_name, *args)
73
+ response = Braspag::Poster.new(
74
+ self,
75
+ self.url_for(method_name)
76
+ ).do_post(
77
+ method_name,
78
+ self.convert(method_name, :to, args)
79
+ )
80
+
81
+ self.convert(method_name, :from, args + [response] )
74
82
  end
75
83
 
76
- def post(method, *args)
77
- data = convert_to(method)
78
- args.each do |field|
79
- data.merge!(field.convert_to(method))
80
- end
81
-
82
- data = Converter::to(method, data)
83
-
84
- response = Braspag::Poster.new(self, self.url_for(method))
85
- .do_post(method, data)
86
-
87
- response = Converter::from(method, response.body)
88
-
89
- args.each do |field|
90
- field.populate!(method, response)
84
+ def convert(method_name, direction, args)
85
+ target = case method_name
86
+ when :authorize, :void, :capture, :archive_card, :get_card, :recurrency
87
+ CreditCard
88
+ when :generate_billet
89
+ Billet
90
+ when :generate_eft
91
+ EFT
92
+ when :info_billet, :info_credit_card, :info
93
+ Order
94
+ when :encrypt
95
+ Crypto::Webservice
91
96
  end
92
97
 
93
- response
94
- end
98
+ target.send("#{direction}_#{method_name}", *([self] + args))
99
+ end
95
100
  end
96
101
  end
@@ -1,14 +1,21 @@
1
1
  module Braspag
2
2
  class Converter
3
3
  def self.decimal_to_string(value)
4
+ #TODO: CHANGE ANOTHER FOR CONVERSION
4
5
  ("%.2f" % value.to_f).gsub('.', ',')
5
6
  end
6
7
 
7
- def self.string_to_decimal(value)
8
- BigDecimal.new(value.to_s.gsub(".",""))
8
+ def self.string_to_decimal(value, mode = :br)
9
+ case mode
10
+ when :br
11
+ BigDecimal.new(value.to_s.gsub(".","").gsub(",","."))
12
+ when :eua
13
+ BigDecimal.new(value.to_s.gsub(",",""))
14
+ end
9
15
  end
16
+
10
17
 
11
- def self.to_map(document, map = {})
18
+ def self.hash_from_xml(document, map = {})
12
19
  document = Nokogiri::XML(document)
13
20
 
14
21
  map.each do |key, value|
@@ -36,125 +43,21 @@ module Braspag
36
43
  def self.payment_method_name?(code)
37
44
  Braspag::PAYMENT_METHOD.key(code.to_s.to_i)
38
45
  end
39
-
40
- def self.status_name?(code)
41
- Braspag::STATUS_PAYMENT.key(code.to_s.to_i)
42
- end
43
-
44
- def self.to_hash(format, params)
45
- data = {}
46
- format.each do |k, v|
47
- case k
48
- when :amount
49
- data[v] = self.decimal_to_string(params[:amount])
50
- else
51
- data[v] = params[k] || ""
52
- end
46
+
47
+ def self.payment_method_type?(code)
48
+ key = Braspag::PAYMENT_METHOD.key(code.to_s.to_i)
49
+ return nil if key.nil?
50
+ if key.match(/billet_/)
51
+ :billet
52
+ elsif key.match(/eft_/)
53
+ :eft
54
+ else
55
+ :credit_card
53
56
  end
54
- data
55
- end
56
-
57
- def self.to(method, data)
58
- self.send("to_#{method}", data)
59
- end
60
-
61
- def self.to_authorize(params)
62
- self.to_hash({
63
- :merchant_id => "merchantId",
64
- :order_id => "orderId",
65
- :customer_name => "customerName",
66
- :amount => "amount",
67
- :payment_method => "paymentMethod",
68
- :holder => "holder",
69
- :card_number => "cardNumber",
70
- :expiration => "expiration",
71
- :security_code => "securityCode",
72
- :number_payments => "numberPayments",
73
- :type => "typePayment",
74
- }, params)
75
- end
76
-
77
- def self.to_capture(params)
78
- self.to_hash({
79
- :merchant_id => "merchantId",
80
- :order_id => "orderId"
81
- }, params)
82
57
  end
83
58
 
84
- def self.to_void(params)
85
- self.to_hash({
86
- :merchant_id => "merchantId",
87
- :order_id => "order"
88
- }, params)
89
- end
90
-
91
- def self.to_generate_billet(params)
92
- self.to_hash({
93
- :merchant_id => "merchantId",
94
- :order_id => "orderId",
95
- :customer_name => "customerName",
96
- :customer_id => "customerIdNumber",
97
- :amount => "amount",
98
- :payment_method => "paymentMethod",
99
- :number => "boletoNumber",
100
- :instructions => "instructions",
101
- :expiration_date => "expirationDate",
102
- :emails => "emails"
103
- }, params)
104
- end
105
-
106
- def self.from(method, data)
107
- self.send("from_#{method}", data)
108
- end
109
-
110
- def self.from_authorize(data)
111
- to_map(data, {
112
- :amount => nil,
113
- :number => "authorisationNumber",
114
- :message => 'message',
115
- :return_code => 'returnCode',
116
- :status => 'status',
117
- :transaction_id => "transactionId"
118
- })
119
- end
120
-
121
- def self.from_capture(data)
122
- to_map(data, {
123
- :amount => nil,
124
- :message => 'message',
125
- :return_code => 'returnCode',
126
- :status => 'status',
127
- :transaction_id => "transactionId"
128
- })
129
- end
130
-
131
- def self.from_void(data)
132
- to_map(data, {
133
- :order_id => "orderId",
134
- :amount => nil,
135
- :message => 'message',
136
- :return_code => 'returnCode',
137
- :status => 'status',
138
- :transaction_id => "transactionId"
139
- })
140
- end
141
-
142
- def self.from_generate_billet(data)
143
- to_map(data, {
144
- :url => nil,
145
- :amount => nil,
146
- :number => "boletoNumber",
147
- :expiration_date => Proc.new { |document|
148
- begin
149
- Date.parse(document.search("expirationDate").first.to_s)
150
- rescue
151
- nil
152
- end
153
- },
154
- :return_code => "returnCode",
155
- :status => nil,
156
- :message => nil
157
- })
59
+ def self.status_name?(code)
60
+ Braspag::STATUS_PAYMENT.key(code.to_s.to_i)
158
61
  end
159
62
  end
160
63
  end
@@ -9,29 +9,5 @@ module Braspag
9
9
  validates :email, :length => {:minimum => 1, :maximum => 255, :on => check_on, :allow_blank => true}
10
10
  validates :document, :length => {:minimum => 11, :maximum => 18, :on => check_on, :allow_blank => true}
11
11
  end
12
-
13
- def convert_to(method)
14
- data = {}
15
- data = self.send("to_#{method}") if self.respond_to?("to_#{method}")
16
- data
17
- end
18
-
19
- def to_authorize
20
- {
21
- :customer_name => self.name.to_s
22
- }
23
- end
24
-
25
- def to_generate_billet
26
- {
27
- :customer_name => self.name.to_s,
28
- :customer_id => self.document.to_s,
29
- :emails => self.email.to_s
30
- }
31
- end
32
-
33
- def populate!(method)
34
-
35
- end
36
12
  end
37
13
  end
@@ -1,84 +1,30 @@
1
1
  module Braspag
2
2
  class Connection
3
- def self.get(order)
4
- #check if order.is valid for get
5
- return ::Response
3
+ def get(order)
4
+ response = self.post(:info, order)
6
5
 
7
- response = Braspag::Poster.new(self, self.url_for(:info)).do_post(:info, {
8
- :loja => self.merchant_id, :numeroPedido => order.id.to_s
9
- })
6
+ if ( response.size == 0 ||
7
+ !response.fetch(:error_code, nil).nil? ||
8
+ response.fetch(:status, nil).nil?
9
+ )
10
+ return ActiveMerchant::Billing::Response.new(false,
11
+ response.fetch(:error_message, ''),
12
+ response,
13
+ :test => homologation?)
14
+ end
10
15
 
11
- response = Utils::convert_to_map(response.body, {
12
- :authorization => "CodigoAutorizacao",
13
- :error_code => "CodigoErro",
14
- :error_message => "MensagemErro",
15
- :payment_method => "CodigoPagamento",
16
- :payment_method_name => "FormaPagamento",
17
- :installments => "NumeroParcelas",
18
- :status => "Status",
19
- :amount => "Valor",
20
- :cancelled_at => "DataCancelamento",
21
- :paid_at => "DataPagamento",
22
- :order_date => "DataPedido",
23
- :transaction_id => "TransId",
24
- :tid => "BraspagTid"
25
- })
26
-
27
- # raise InvalidData if response[:authorization].nil?
16
+ case order.payment_method_type?
17
+ when :billet
18
+ self.post(:info_billet, order)
19
+ when :credit_card
20
+ self.post(:info_credit_card, order)
21
+ end
28
22
 
29
- self.get_billet(order)
30
- self.get_credit_card(order)
31
- response
32
- end
33
-
34
- private
35
- def self.get_billet(order)
36
-
37
- request = ::HTTPI::Request.new(self.info_url)
38
- request.body = {
39
- :loja => connection.merchant_id,
40
- :numeroPedido => order_id.to_s
41
- }
42
-
43
- response = ::HTTPI.post(request)
44
-
45
- response = Utils::convert_to_map(response.body, {
46
- :document_number => "NumeroDocumento",
47
- :payer => "Sacado",
48
- :our_number => "NossoNumero",
49
- :bill_line => "LinhaDigitavel",
50
- :document_date => "DataDocumento",
51
- :expiration_date => "DataVencimento",
52
- :receiver => "Cedente",
53
- :bank => "Banco",
54
- :agency => "Agencia",
55
- :account => "Conta",
56
- :wallet => "Carteira",
57
- :amount => "ValorDocumento",
58
- :amount_invoice => "ValorPago",
59
- :invoice_date => "DataCredito"
60
- })
61
-
62
- raise UnknownError if response[:document_number].nil?
63
- response
64
- end
65
-
66
- def self.get_credit_card(order)
67
- data = {:loja => self.merchant_id, :numeroPedido => order.id.to_s}
68
- response = Braspag::Poster.new(self, self.info_url).do_post(:info_credit_card, data)
69
-
70
- response = Utils::convert_to_map(response.body, {
71
- :checking_number => "NumeroComprovante",
72
- :certified => "Autenticada",
73
- :autorization_number => "NumeroAutorizacao",
74
- :card_number => "NumeroCartao",
75
- :transaction_number => "NumeroTransacao"
76
- })
77
-
78
- raise UnknownError if response[:checking_number].nil?
79
- response
23
+ ActiveMerchant::Billing::Response.new(true,
24
+ 'OK',
25
+ response,
26
+ :test => homologation?)
80
27
  end
81
-
82
28
  end
83
29
 
84
30
  class Order
@@ -112,6 +58,8 @@ module Braspag
112
58
  attr_accessor :gateway_authorization, :gateway_id, :gateway_return_code, :gateway_status, :gateway_message, :gateway_amount
113
59
  attr_accessor :gateway_capture_return_code, :gateway_capture_status, :gateway_capture_message, :gateway_capture_amount
114
60
  attr_accessor :gateway_void_return_code, :gateway_void_status, :gateway_void_message, :gateway_void_amount
61
+ attr_accessor :authorization, :payment_method_name, :status, :gateway_cancelled_at, :gateway_paid_at
62
+ attr_accessor :gateway_created_at, :transaction_id, :gateway_id, :billet, :credit_card
115
63
 
116
64
  [:purchase, :generate, :authorize, :capture, :void, :recurrency].each do |check_on|
117
65
  validates :id, :presence => { :on => check_on }
@@ -143,83 +91,184 @@ module Braspag
143
91
  when Braspag::INTEREST[:no],
144
92
  Braspag::INTEREST[:no_iata]
145
93
  true
94
+ else
95
+ false
146
96
  end
147
97
  end
148
98
 
149
- def convert_to(method)
150
- data = {}
151
- data = self.send("to_#{method}") if self.respond_to?("to_#{method}")
152
- data.merge!(self.customer.convert_to(method)) if self.customer
153
- data
99
+ def payment_method_type?
100
+ Converter.payment_method_type?(self.payment_method)
154
101
  end
155
102
 
156
- def to_authorize
157
- {
158
- :order_id => self.id.to_s,
159
- :amount => self.amount,
160
- :payment_method => self.payment_method,
161
- :number_payments => self.installments,
162
- :type => self.installments_type,
163
- }
103
+ def build_customer
104
+ self.customer = Customer.new
105
+ end
106
+
107
+ def build_billet
108
+ self.billet = Billet.new
164
109
  end
165
110
 
166
- def to_capture
111
+ def build_credit_card
112
+ self.credit_card = CreditCard.new
113
+ end
114
+
115
+ def self.to_info(connection, order)
167
116
  {
168
- :order_id => self.id.to_s
117
+ "loja" => connection.merchant_id,
118
+ "numeroPedido" => order.id.to_s
169
119
  }
170
120
  end
171
121
 
172
- def to_void
173
- {
174
- :order_id => self.id.to_s
175
- }
122
+ def self.from_info(connection, order, params)
123
+ response = Braspag::Converter::hash_from_xml(params.body, {
124
+ :authorization => "CodigoAutorizacao",
125
+ :error_code => "CodigoErro",
126
+ :error_message => "MensagemErro",
127
+ :payment_method => "CodigoPagamento",
128
+ :payment_method_name => "FormaPagamento",
129
+ :installments => "NumeroParcelas",
130
+ :status => "Status",
131
+ :amount => "Valor",
132
+ :cancelled_at => Proc.new { |document|
133
+ begin
134
+ Time.parse(document.search("DataCancelamento").first.to_s)
135
+ rescue
136
+ nil
137
+ end
138
+ },
139
+ :paid_at => Proc.new { |document|
140
+ begin
141
+ Time.parse(document.search("DataPagamento").first.to_s)
142
+ rescue
143
+ nil
144
+ end
145
+ },
146
+ :order_date => Proc.new { |document|
147
+ begin
148
+ Time.parse(document.search("DataPedido").first.to_s)
149
+ rescue
150
+ nil
151
+ end
152
+ },
153
+ :transaction_id => "TransId",
154
+ :tid => "BraspagTid"
155
+ })
156
+
157
+ order.authorization = response[:authorization]
158
+ order.payment_method_name = response[:payment_method_name]
159
+ order.payment_method = response[:payment_method]
160
+ order.installments = response[:installments]
161
+ order.status = response[:status]
162
+ order.amount = Braspag::Converter::string_to_decimal(response[:amount], :eua)
163
+ order.gateway_cancelled_at = response[:cancelled_at]
164
+ order.gateway_paid_at = response[:paid_at]
165
+ order.gateway_created_at = response[:order_date]
166
+ order.transaction_id = response[:transaction_id]
167
+ order.gateway_id = response[:tid]
168
+
169
+ response
176
170
  end
177
171
 
178
- def to_generate_billet
172
+ def self.to_info_credit_card(connection, order)
179
173
  {
180
- :order_id => self.id.to_s,
181
- :amount => self.amount,
182
- :payment_method => self.payment_method
174
+ "loja" => connection.merchant_id,
175
+ "numeroPedido" => order.id.to_s
183
176
  }
184
177
  end
185
178
 
186
- def populate!(method, response)
187
- self.send("populate_#{method}!", response)
188
- end
189
-
190
- def populate_authorize!(response)
191
- self.gateway_authorization = response[:number]
192
- self.gateway_id = response[:transaction_id]
193
- self.gateway_return_code = response[:return_code]
194
- self.gateway_status = response[:status]
195
- self.gateway_message = response[:message]
196
- self.gateway_amount = Converter::string_to_decimal(response[:amount])
197
- end
179
+ def self.from_info_credit_card(connection, order, params)
180
+ response = Braspag::Converter::hash_from_xml(params.body, {
181
+ :checking_number => "NumeroComprovante",
182
+ :certified => "Autenticada",
183
+ :autorization_number => "NumeroAutorizacao",
184
+ :card_number => "NumeroCartao",
185
+ :transaction_number => "NumeroTransacao",
198
186
 
199
- def populate_capture!(response)
200
- #TODO: CHECK IF IS NECESSARY
201
- # self.gateway_capture_id = response[:transaction_id]
202
- self.gateway_capture_return_code = response[:return_code]
203
- self.gateway_capture_status = response[:status]
204
- self.gateway_capture_message = response[:message]
205
- self.gateway_capture_amount = Converter::string_to_decimal(response[:amount])
187
+ :avs_response => "RetornoAVS",
188
+ :issuing => "Emissor",
189
+ :authenticated_number => "NumeroAutenticacao"
190
+ })
191
+
192
+ order.build_credit_card if order.credit_card.nil?
193
+
194
+ order.credit_card.checking_number = response[:checking_number]
195
+ order.credit_card.avs = response[:certified]
196
+ order.credit_card.autorization_number = response[:autorization_number]
197
+ order.credit_card.number = response[:card_number]
198
+ order.credit_card.transaction_number = response[:transaction_number]
199
+ order.credit_card.avs_response = response[:avs_response]
200
+ order.credit_card.issuing = response[:issuing]
201
+ order.credit_card.authenticated_number = response[:authenticated_number]
202
+
203
+ response
206
204
  end
207
205
 
208
- def populate_void!(response)
209
- #TODO: CHECK IF IS NECESSARY
210
- # self.gateway_void_id = response[:transaction_id]
211
- self.gateway_void_return_code = response[:return_code]
212
- self.gateway_void_status = response[:status]
213
- self.gateway_void_message = response[:message]
214
- self.gateway_void_amount = Converter::string_to_decimal(response[:amount])
206
+ def self.to_info_billet(connection, order)
207
+ {
208
+ "loja" => connection.merchant_id,
209
+ "numeroPedido" => order.id.to_s
210
+ }
215
211
  end
216
212
 
217
- def populate_generate_billet!(response)
218
- self.gateway_return_code = response[:return_code]
219
- self.gateway_status = response[:status]
220
- self.gateway_amount = BigDecimal.new(response[:amount].to_s) if response[:amount]
221
- end
213
+ def self.from_info_billet(connection, order, params)
214
+ response = Braspag::Converter::hash_from_xml(params.body, {
215
+ :document_number => "NumeroDocumento",
216
+ :payer => "Sacado",
217
+ :our_number => "NossoNumero",
218
+ :bill_line => "LinhaDigitavel",
219
+ :document_date => Proc.new { |document|
220
+ begin
221
+ Date.parse(document.search("DataDocumento").first.to_s)
222
+ rescue
223
+ nil
224
+ end
225
+ },
226
+ :expiration_date => Proc.new { |document|
227
+ begin
228
+ Date.parse(document.search("DataVencimento").first.to_s)
229
+ rescue
230
+ nil
231
+ end
232
+ },
233
+ :receiver => "Cedente",
234
+ :bank => "Banco",
235
+ :agency => "Agencia",
236
+ :account => "Conta",
237
+ :wallet => "Carteira",
238
+ :amount => "ValorDocumento",
239
+ :amount_invoice => "ValorPago",
240
+ :invoice_date => Proc.new { |document|
241
+ begin
242
+ Date.parse(document.search("DataCredito").first.to_s)
243
+ rescue
244
+ nil
245
+ end
246
+ }
247
+ })
248
+
249
+ order.build_customer if order.customer.nil?
250
+ order.customer.name = response[:payer]
251
+
252
+ order.build_billet if order.billet.nil?
253
+ order.billet.id = response[:our_number]
254
+ order.billet.code = response[:bill_line]
255
+
256
+ order.billet.created_at = response[:document_date]
257
+ order.billet.due_date_on = response[:expiration_date]
258
+
259
+ order.billet.receiver = response[:receiver]
260
+
261
+ order.billet.bank = response[:bank]
262
+ order.billet.agency = response[:agency]
263
+ order.billet.account = response[:account]
264
+ order.billet.wallet = response[:wallet]
265
+ order.billet.amount = Braspag::Converter::string_to_decimal(response[:amount])
266
+ order.billet.amount_paid = Braspag::Converter::string_to_decimal(response[:amount_invoice])
267
+ order.billet.paid_at = response[:invoice_date]
222
268
 
269
+ response
270
+ end
271
+
223
272
  private
224
273
  def payment_for_cielo?
225
274
  case payment_method
@@ -232,5 +281,6 @@ module Braspag
232
281
  true
233
282
  end
234
283
  end
284
+
235
285
  end
236
286
  end