braspag-pagador 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +164 -162
  3. data/braspag-pagador.gemspec +3 -3
  4. data/coverage/.resultset.json +69 -26
  5. data/coverage/index.html +1431 -1147
  6. data/lib/{braspag.rb → braspag-pagador.rb} +14 -14
  7. data/lib/{braspag → braspag-pagador}/core/connection.rb +5 -3
  8. data/lib/{braspag → braspag-pagador}/core/converter.rb +4 -4
  9. data/lib/{braspag → braspag-pagador}/core/customer.rb +2 -2
  10. data/lib/{braspag → braspag-pagador}/core/order.rb +51 -51
  11. data/lib/{braspag → braspag-pagador}/core/poster.rb +1 -1
  12. data/lib/{braspag → braspag-pagador}/crypto/no_crypto.rb +2 -2
  13. data/lib/{braspag → braspag-pagador}/crypto/webservice.rb +10 -10
  14. data/lib/{braspag → braspag-pagador}/payment/billet.rb +10 -10
  15. data/lib/{braspag → braspag-pagador}/payment/credit_card.rb +8 -8
  16. data/lib/{braspag → braspag-pagador}/payment/eft.rb +3 -3
  17. data/lib/{braspag → braspag-pagador}/payment/recurrency_credit_card.rb +1 -1
  18. data/lib/{braspag → braspag-pagador}/templates/crypto/decrypt.xml.erb +0 -0
  19. data/lib/{braspag → braspag-pagador}/templates/crypto/encrypt.xml.erb +0 -0
  20. data/lib/{braspag → braspag-pagador}/templates/justclick/archive.xml.erb +0 -0
  21. data/lib/{braspag → braspag-pagador}/templates/justclick/get_recurrency.xml.erb +0 -0
  22. data/lib/{braspag → braspag-pagador}/templates/justclick/recurrency.xml.erb +0 -0
  23. data/lib/braspag-pagador/version.rb +3 -0
  24. data/spec/core/connection_spec.rb +50 -50
  25. data/spec/core/converter_spec.rb +41 -41
  26. data/spec/core/customer_spec.rb +2 -2
  27. data/spec/core/order_spec.rb +78 -78
  28. data/spec/core/poster_spec.rb +8 -8
  29. data/spec/crypto/webservice_spec.rb +23 -23
  30. data/spec/integration/billet_spec.rb +11 -11
  31. data/spec/payment/billet_spec.rb +48 -48
  32. data/spec/payment/credit_card_spec.rb +82 -82
  33. data/spec/payment/eft_spec.rb +25 -25
  34. data/spec/payment/recurrency_credit_card_spec.rb +11 -11
  35. data/spec/spec_helper.rb +5 -5
  36. metadata +20 -20
  37. data/lib/braspag/version.rb +0 -3
@@ -9,23 +9,23 @@ require 'bigdecimal'
9
9
  require 'active_merchant'
10
10
  require 'erb'
11
11
 
12
- require "braspag/version"
13
- require 'braspag/core/converter'
14
- require 'braspag/core/connection'
15
- require 'braspag/core/poster'
16
- require 'braspag/core/customer'
17
- require 'braspag/core/order'
12
+ require "braspag-pagador/version"
13
+ require 'braspag-pagador/core/converter'
14
+ require 'braspag-pagador/core/connection'
15
+ require 'braspag-pagador/core/poster'
16
+ require 'braspag-pagador/core/customer'
17
+ require 'braspag-pagador/core/order'
18
18
 
19
- require 'braspag/crypto/no_crypto'
20
- require 'braspag/crypto/webservice'
19
+ require 'braspag-pagador/crypto/no_crypto'
20
+ require 'braspag-pagador/crypto/webservice'
21
21
 
22
- require 'braspag/payment/billet'
23
- require 'braspag/payment/credit_card'
24
- require 'braspag/payment/eft'
25
- require 'braspag/payment/recurrency_credit_card'
22
+ require 'braspag-pagador/payment/billet'
23
+ require 'braspag-pagador/payment/credit_card'
24
+ require 'braspag-pagador/payment/eft'
25
+ require 'braspag-pagador/payment/recurrency_credit_card'
26
26
 
27
27
 
28
- module Braspag
28
+ module BraspagPagador
29
29
  PATH = File.dirname(__FILE__)
30
30
 
31
31
  INTEREST = {
@@ -91,6 +91,6 @@ module Braspag
91
91
  # INTERNACIONAL
92
92
  :paypal_express => 35, # PayPal Express Checkout
93
93
  # HOMOLOGATION
94
- :braspag => 997
94
+ :homologation => 997
95
95
  }
96
96
  end
@@ -1,4 +1,4 @@
1
- module Braspag
1
+ module BraspagPagador
2
2
  class Connection
3
3
 
4
4
  class InvalidMerchantId < Exception ; end
@@ -6,7 +6,9 @@ module Braspag
6
6
 
7
7
  PRODUCTION_URL = "https://transaction.pagador.com.br"
8
8
  HOMOLOGATION_URL = "https://homologacao.pagador.com.br"
9
- PROTECTED_CARD_PRODUCTION_URL = "https://cartaoprotegido.braspag.com.br/Services"
9
+ # PROTECTED_CARD_HOMOLOGATION_URL = "https://cartaoprotegido.braspag.com.br/Services/V2"
10
+ # PROTECTED_CARD_PRODUCTION_URL = "https://homologacao.braspag.com.br/services/testenvironment"
11
+ PROTECTED_CARD_PRODUCTION_URL = "https://cartaoprotegido.braspag.com.br/Services/V2"
10
12
  PROTECTED_CARD_HOMOLOGATION_URL = "https://homologacao.braspag.com.br/services/testenvironment"
11
13
 
12
14
  attr_reader :merchant_id, :env, :logger, :proxy_address
@@ -70,7 +72,7 @@ module Braspag
70
72
  end
71
73
 
72
74
  def post(method_name, *args)
73
- response = Braspag::Poster.new(
75
+ response = BraspagPagador::Poster.new(
74
76
  self,
75
77
  self.url_for(method_name)
76
78
  ).do_post(
@@ -1,4 +1,4 @@
1
- module Braspag
1
+ module BraspagPagador
2
2
  class Converter
3
3
  def self.decimal_to_string(value)
4
4
  #TODO: CHANGE ANOTHER FOR CONVERSION
@@ -41,11 +41,11 @@ module Braspag
41
41
  end
42
42
 
43
43
  def self.payment_method_name?(code)
44
- Braspag::PAYMENT_METHOD.key(code.to_s.to_i)
44
+ BraspagPagador::PAYMENT_METHOD.key(code.to_s.to_i)
45
45
  end
46
46
 
47
47
  def self.payment_method_type?(code)
48
- key = Braspag::PAYMENT_METHOD.key(code.to_s.to_i)
48
+ key = BraspagPagador::PAYMENT_METHOD.key(code.to_s.to_i)
49
49
  return nil if key.nil?
50
50
  if key.match(/billet_/)
51
51
  :billet
@@ -57,7 +57,7 @@ module Braspag
57
57
  end
58
58
 
59
59
  def self.status_name?(code)
60
- Braspag::STATUS_PAYMENT.key(code.to_s.to_i)
60
+ BraspagPagador::STATUS_PAYMENT.key(code.to_s.to_i)
61
61
  end
62
62
  end
63
63
  end
@@ -1,4 +1,4 @@
1
- module Braspag
1
+ module BraspagPagador
2
2
  class Customer
3
3
  include ::ActiveAttr::Model
4
4
 
@@ -10,4 +10,4 @@ module Braspag
10
10
  validates :document, :length => {:minimum => 11, :maximum => 18, :on => check_on, :allow_blank => true}
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -1,10 +1,10 @@
1
- module Braspag
1
+ module BraspagPagador
2
2
  class Connection
3
3
  def get(order)
4
4
  response = self.post(:info, order)
5
-
6
- if ( response.size == 0 ||
7
- !response.fetch(:error_code, nil).nil? ||
5
+
6
+ if ( response.size == 0 ||
7
+ !response.fetch(:error_code, nil).nil? ||
8
8
  response.fetch(:status, nil).nil?
9
9
  )
10
10
  return ActiveMerchant::Billing::Response.new(false,
@@ -12,24 +12,24 @@ module Braspag
12
12
  response,
13
13
  :test => homologation?)
14
14
  end
15
-
15
+
16
16
  case order.payment_method_type?
17
17
  when :billet
18
18
  self.post(:info_billet, order)
19
19
  when :credit_card
20
20
  self.post(:info_credit_card, order)
21
21
  end
22
-
22
+
23
23
  ActiveMerchant::Billing::Response.new(true,
24
24
  'OK',
25
25
  response,
26
26
  :test => homologation?)
27
27
  end
28
28
  end
29
-
29
+
30
30
  class Order
31
31
  include ::ActiveAttr::Model
32
-
32
+
33
33
  class AssociationValidator < ActiveModel::EachValidator
34
34
  def validate_each(record, attribute, value)
35
35
  unless value.respond_to?(:valid?) && value.try(:valid?, self.options[:on])
@@ -37,47 +37,47 @@ module Braspag
37
37
  end
38
38
  end
39
39
  end
40
-
40
+
41
41
  class PaymentMethodValidator < ActiveModel::EachValidator
42
42
  def validate_each(record, attribute, value)
43
- if Braspag::PAYMENT_METHOD.key(value).nil?
43
+ if BraspagPagador::PAYMENT_METHOD.key(value).nil?
44
44
  record.errors.add attribute, "invalid payment code"
45
45
  end
46
46
  end
47
47
  end
48
-
48
+
49
49
  class InstallmentsTypeValidator < ActiveModel::EachValidator
50
50
  def validate_each(record, attribute, value)
51
- if Braspag::INTEREST.key(value).nil?
51
+ if BraspagPagador::INTEREST.key(value).nil?
52
52
  record.errors.add attribute, "invalid installments type"
53
53
  end
54
54
  end
55
55
  end
56
-
56
+
57
57
  attr_accessor :id, :payment_method, :amount, :customer, :installments, :installments_type
58
58
  attr_accessor :gateway_authorization, :gateway_id, :gateway_return_code, :gateway_status, :gateway_message, :gateway_amount
59
59
  attr_accessor :gateway_capture_return_code, :gateway_capture_status, :gateway_capture_message, :gateway_capture_amount
60
60
  attr_accessor :gateway_void_return_code, :gateway_void_status, :gateway_void_message, :gateway_void_amount
61
61
  attr_accessor :authorization, :payment_method_name, :status, :gateway_cancelled_at, :gateway_paid_at
62
62
  attr_accessor :gateway_created_at, :transaction_id, :gateway_id, :billet, :credit_card
63
-
63
+
64
64
  [:purchase, :generate, :authorize, :capture, :void, :recurrency].each do |check_on|
65
65
  validates :id, :presence => { :on => check_on }
66
66
  validates :id, :length => {:minimum => 1, :maximum => 20, :on => check_on }
67
67
  validates :id, :format => { :with => /^[0-9]+$/, :on => check_on, :if => :payment_for_cielo? }
68
68
  end
69
-
69
+
70
70
  [:purchase, :generate, :authorize, :recurrency].each do |check_on|
71
71
  validates :payment_method, :presence => { :on => check_on }
72
72
  validates :payment_method, :payment_method => { :on => check_on }
73
73
 
74
74
  validates :amount, :presence => { :on => check_on }
75
75
  validates :amount, :numericality => {:greater_than => 0, :on => check_on}
76
-
76
+
77
77
  validates :customer, :presence => { :on => check_on }
78
78
  validates :customer, :association => { :on => check_on }
79
79
  end
80
-
80
+
81
81
  [:purchase, :authorize, :recurrency].each do |check_on|
82
82
  validates :installments, :presence => { :on => check_on }
83
83
  validates :installments, :numericality => {:only_integer => true, :greater_than => 0, :less_than => 100, :on => check_on}
@@ -85,21 +85,21 @@ module Braspag
85
85
  validates :installments_type, :presence => { :on => check_on }
86
86
  validates :installments_type, :installments_type => { :on => check_on }
87
87
  end
88
-
88
+
89
89
  def no_interest?
90
90
  case installments_type
91
- when Braspag::INTEREST[:no],
92
- Braspag::INTEREST[:no_iata]
91
+ when BraspagPagador::INTEREST[:no],
92
+ BraspagPagador::INTEREST[:no_iata]
93
93
  true
94
94
  else
95
95
  false
96
96
  end
97
97
  end
98
-
98
+
99
99
  def payment_method_type?
100
100
  Converter.payment_method_type?(self.payment_method)
101
101
  end
102
-
102
+
103
103
  def build_customer
104
104
  self.customer = Customer.new
105
105
  end
@@ -107,7 +107,7 @@ module Braspag
107
107
  def build_billet
108
108
  self.billet = Billet.new
109
109
  end
110
-
110
+
111
111
  def build_credit_card
112
112
  self.credit_card = CreditCard.new
113
113
  end
@@ -118,9 +118,9 @@ module Braspag
118
118
  "numeroPedido" => order.id.to_s
119
119
  }
120
120
  end
121
-
121
+
122
122
  def self.from_info(connection, order, params)
123
- response = Braspag::Converter::hash_from_xml(params.body, {
123
+ response = BraspagPagador::Converter::hash_from_xml(params.body, {
124
124
  :authorization => "CodigoAutorizacao",
125
125
  :error_code => "CodigoErro",
126
126
  :error_message => "MensagemErro",
@@ -153,13 +153,13 @@ module Braspag
153
153
  :transaction_id => "TransId",
154
154
  :tid => "BraspagTid"
155
155
  })
156
-
156
+
157
157
  order.authorization = response[:authorization]
158
158
  order.payment_method_name = response[:payment_method_name]
159
159
  order.payment_method = response[:payment_method]
160
160
  order.installments = response[:installments]
161
161
  order.status = response[:status]
162
- order.amount = Braspag::Converter::string_to_decimal(response[:amount], :eua)
162
+ order.amount = BraspagPagador::Converter::string_to_decimal(response[:amount], :eua)
163
163
  order.gateway_cancelled_at = response[:cancelled_at]
164
164
  order.gateway_paid_at = response[:paid_at]
165
165
  order.gateway_created_at = response[:order_date]
@@ -168,16 +168,16 @@ module Braspag
168
168
 
169
169
  response
170
170
  end
171
-
171
+
172
172
  def self.to_info_credit_card(connection, order)
173
173
  {
174
174
  "loja" => connection.merchant_id,
175
175
  "numeroPedido" => order.id.to_s
176
176
  }
177
177
  end
178
-
178
+
179
179
  def self.from_info_credit_card(connection, order, params)
180
- response = Braspag::Converter::hash_from_xml(params.body, {
180
+ response = BraspagPagador::Converter::hash_from_xml(params.body, {
181
181
  :checking_number => "NumeroComprovante",
182
182
  :certified => "Autenticada",
183
183
  :autorization_number => "NumeroAutorizacao",
@@ -188,9 +188,9 @@ module Braspag
188
188
  :issuing => "Emissor",
189
189
  :authenticated_number => "NumeroAutenticacao"
190
190
  })
191
-
191
+
192
192
  order.build_credit_card if order.credit_card.nil?
193
-
193
+
194
194
  order.credit_card.checking_number = response[:checking_number]
195
195
  order.credit_card.avs = response[:certified]
196
196
  order.credit_card.autorization_number = response[:autorization_number]
@@ -199,19 +199,19 @@ module Braspag
199
199
  order.credit_card.avs_response = response[:avs_response]
200
200
  order.credit_card.issuing = response[:issuing]
201
201
  order.credit_card.authenticated_number = response[:authenticated_number]
202
-
202
+
203
203
  response
204
204
  end
205
-
205
+
206
206
  def self.to_info_billet(connection, order)
207
207
  {
208
208
  "loja" => connection.merchant_id,
209
209
  "numeroPedido" => order.id.to_s
210
210
  }
211
211
  end
212
-
212
+
213
213
  def self.from_info_billet(connection, order, params)
214
- response = Braspag::Converter::hash_from_xml(params.body, {
214
+ response = BraspagPagador::Converter::hash_from_xml(params.body, {
215
215
  :document_number => "NumeroDocumento",
216
216
  :payer => "Sacado",
217
217
  :our_number => "NossoNumero",
@@ -245,42 +245,42 @@ module Braspag
245
245
  end
246
246
  }
247
247
  })
248
-
248
+
249
249
  order.build_customer if order.customer.nil?
250
250
  order.customer.name = response[:payer]
251
251
 
252
252
  order.build_billet if order.billet.nil?
253
253
  order.billet.id = response[:our_number]
254
254
  order.billet.code = response[:bill_line]
255
-
255
+
256
256
  order.billet.created_at = response[:document_date]
257
257
  order.billet.due_date_on = response[:expiration_date]
258
-
258
+
259
259
  order.billet.receiver = response[:receiver]
260
-
260
+
261
261
  order.billet.bank = response[:bank]
262
262
  order.billet.agency = response[:agency]
263
263
  order.billet.account = response[:account]
264
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])
265
+ order.billet.amount = BraspagPagador::Converter::string_to_decimal(response[:amount])
266
+ order.billet.amount_paid = BraspagPagador::Converter::string_to_decimal(response[:amount_invoice])
267
267
  order.billet.paid_at = response[:invoice_date]
268
-
268
+
269
269
  response
270
270
  end
271
-
271
+
272
272
  private
273
273
  def payment_for_cielo?
274
274
  case payment_method
275
- when Braspag::PAYMENT_METHOD[:cielo_noauth_visa],
276
- Braspag::PAYMENT_METHOD[:cielo_preauth_visa],
277
- Braspag::PAYMENT_METHOD[:cielo_noauth_mastercard],
278
- Braspag::PAYMENT_METHOD[:cielo_preauth_mastercard],
279
- Braspag::PAYMENT_METHOD[:cielo_noauth_elo],
280
- Braspag::PAYMENT_METHOD[:cielo_noauth_diners]
275
+ when BraspagPagador::PAYMENT_METHOD[:cielo_noauth_visa],
276
+ BraspagPagador::PAYMENT_METHOD[:cielo_preauth_visa],
277
+ BraspagPagador::PAYMENT_METHOD[:cielo_noauth_mastercard],
278
+ BraspagPagador::PAYMENT_METHOD[:cielo_preauth_mastercard],
279
+ BraspagPagador::PAYMENT_METHOD[:cielo_noauth_elo],
280
+ BraspagPagador::PAYMENT_METHOD[:cielo_noauth_diners]
281
281
  true
282
282
  end
283
283
  end
284
-
284
+
285
285
  end
286
286
  end
@@ -1,4 +1,4 @@
1
- module Braspag
1
+ module BraspagPagador
2
2
  class Poster
3
3
  def initialize(connection, url)
4
4
  @connection = connection
@@ -1,6 +1,6 @@
1
- module Braspag
1
+ module BraspagPagador
2
2
  module Crypto
3
3
  class NoCrypto
4
4
  end
5
5
  end
6
- end
6
+ end
@@ -1,18 +1,18 @@
1
- module Braspag
1
+ module BraspagPagador
2
2
  module Crypto
3
3
  class Webservice
4
4
  def encrypt(connection, map)
5
- data = ERB.new(File.read(Braspag::PATH + '/braspag/templates/crypto/encrypt.xml.erb'))
5
+ data = ERB.new(File.read(BraspagPagador::PATH + '/braspag-pagador/templates/crypto/encrypt.xml.erb'))
6
6
 
7
- response = Braspag::Poster.new(
8
- connection,
7
+ response = BraspagPagador::Poster.new(
8
+ connection,
9
9
  connection.url_for(:encrypt)
10
10
  ).do_post(
11
11
  :encrypt,
12
12
  data.result(binding),
13
13
  {"Content-Type" => "text/xml"}
14
14
  )
15
-
15
+
16
16
  document = Nokogiri::XML(response.body)
17
17
 
18
18
  raise 'UnknownError' if document.children.empty?
@@ -27,17 +27,17 @@ module Braspag
27
27
  end
28
28
 
29
29
  def decrypt(connection, encripted_text)
30
- data = ERB.new(File.read(Braspag::PATH + '/braspag/templates/crypto/decrypt.xml.erb'))
31
-
32
- response = Braspag::Poster.new(
33
- connection,
30
+ data = ERB.new(File.read(BraspagPagador::PATH + '/braspag-pagador/templates/crypto/decrypt.xml.erb'))
31
+
32
+ response = BraspagPagador::Poster.new(
33
+ connection,
34
34
  connection.url_for(:decrypt)
35
35
  ).do_post(
36
36
  :decrypt,
37
37
  data.result(binding),
38
38
  {"Content-Type" => "text/xml"}
39
39
  )
40
-
40
+
41
41
  document = Nokogiri::XML(response.body)
42
42
  raise 'UnknownError' if document.children.empty?
43
43
 
@@ -1,6 +1,6 @@
1
1
  require "bigdecimal"
2
2
 
3
- module Braspag
3
+ module BraspagPagador
4
4
  class Connection
5
5
  def generate_billet(order, billet)
6
6
  response = self.post(:generate_billet, order, billet)
@@ -13,10 +13,10 @@ module Braspag
13
13
  :authorization => response[:number])
14
14
  end
15
15
  end
16
-
16
+
17
17
  class Billet
18
18
  include ::ActiveAttr::Model
19
-
19
+
20
20
  class DueDateValidator < ActiveModel::EachValidator
21
21
  def validate_each(record, attribute, value)
22
22
  # unless value.class.in? [Date, Time]
@@ -27,7 +27,7 @@ module Braspag
27
27
  end
28
28
  end
29
29
  end
30
-
30
+
31
31
  attr_accessor :id, :instructions, :due_date_on, :url, :code, :created_at, :due_date_on
32
32
  attr_accessor :receiver, :bank, :agency, :account, :wallet, :amount, :amount_paid, :paid_at
33
33
 
@@ -35,7 +35,7 @@ module Braspag
35
35
  validates :instructions, :length => {:minimum => 1, :maximum => 512, :on => :generate, :allow_blank => true }
36
36
  validates :due_date_on, :presence => { :on => :generate }
37
37
  validates :due_date_on, :due_date => { :on => :generate }
38
-
38
+
39
39
  def self.to_generate_billet(connection, order, billet)
40
40
  {
41
41
  "merchantId" => connection.merchant_id,
@@ -46,13 +46,13 @@ module Braspag
46
46
  "customerIdNumber" => order.customer.document.to_s,
47
47
  "emails" => order.customer.email.to_s,
48
48
  "orderId" => order.id.to_s,
49
- "amount" => Braspag::Converter::decimal_to_string(order.amount),
49
+ "amount" => BraspagPagador::Converter::decimal_to_string(order.amount),
50
50
  "paymentMethod" => order.payment_method
51
51
  }
52
52
  end
53
-
53
+
54
54
  def self.from_generate_billet(connection, order, billet, params)
55
- response = Braspag::Converter::hash_from_xml(params.body, {
55
+ response = BraspagPagador::Converter::hash_from_xml(params.body, {
56
56
  :url => nil,
57
57
  :amount => nil,
58
58
  :number => "boletoNumber",
@@ -67,12 +67,12 @@ module Braspag
67
67
  :status => nil,
68
68
  :message => nil
69
69
  })
70
-
70
+
71
71
  order.gateway_return_code = response[:return_code]
72
72
  order.gateway_status = response[:status]
73
73
  order.gateway_amount = BigDecimal.new(response[:amount].to_s) if response[:amount]
74
74
  billet.url = response[:url]
75
-
75
+
76
76
  response
77
77
  end
78
78
  end