braspag-pagador 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.md +23 -0
- data/README.md +532 -0
- data/RELEASES.md +20 -0
- data/Rakefile +6 -0
- data/braspag-pagador.gemspec +32 -0
- data/coverage/.resultset.json +2732 -0
- data/coverage/assets/0.5.3/app.js +88 -0
- data/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
- data/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
- data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +363 -0
- data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
- data/coverage/assets/0.5.3/favicon_green.png +0 -0
- data/coverage/assets/0.5.3/favicon_red.png +0 -0
- data/coverage/assets/0.5.3/favicon_yellow.png +0 -0
- data/coverage/assets/0.5.3/highlight.css +129 -0
- data/coverage/assets/0.5.3/highlight.pack.js +1 -0
- data/coverage/assets/0.5.3/jquery-1.6.2.min.js +18 -0
- data/coverage/assets/0.5.3/jquery.dataTables.min.js +152 -0
- data/coverage/assets/0.5.3/jquery.timeago.js +141 -0
- data/coverage/assets/0.5.3/jquery.url.js +174 -0
- data/coverage/assets/0.5.3/loading.gif +0 -0
- data/coverage/assets/0.5.3/magnify.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +295 -0
- data/coverage/assets/0.5.3/stylesheet.css +383 -0
- data/coverage/index.html +17219 -0
- data/lib/braspag.rb +96 -0
- data/lib/braspag/core/connection.rb +112 -0
- data/lib/braspag/core/converter.rb +63 -0
- data/lib/braspag/core/customer.rb +13 -0
- data/lib/braspag/core/order.rb +286 -0
- data/lib/braspag/core/poster.rb +40 -0
- data/lib/braspag/crypto/no_crypto.rb +6 -0
- data/lib/braspag/crypto/webservice.rb +63 -0
- data/lib/braspag/payment/billet.rb +79 -0
- data/lib/braspag/payment/credit_card.rb +190 -0
- data/lib/braspag/payment/eft.rb +65 -0
- data/lib/braspag/payment/recurrency_credit_card.rb +15 -0
- data/lib/braspag/templates/crypto/decrypt.xml.erb +10 -0
- data/lib/braspag/templates/crypto/encrypt.xml.erb +14 -0
- data/lib/braspag/templates/justclick/archive.xml.erb +16 -0
- data/lib/braspag/templates/justclick/get_recurrency.xml.erb +12 -0
- data/lib/braspag/templates/justclick/recurrency.xml.erb +23 -0
- data/lib/braspag/version.rb +3 -0
- data/spec/core/connection_spec.rb +149 -0
- data/spec/core/converter_spec.rb +123 -0
- data/spec/core/customer_spec.rb +49 -0
- data/spec/core/order_spec.rb +504 -0
- data/spec/core/poster_spec.rb +63 -0
- data/spec/crypto/webservice_spec.rb +136 -0
- data/spec/integration/billet_spec.rb +38 -0
- data/spec/integration/credit_card_spec.rb +0 -0
- data/spec/payment/billet_spec.rb +205 -0
- data/spec/payment/credit_card_spec.rb +385 -0
- data/spec/payment/eft_spec.rb +88 -0
- data/spec/payment/recurrency_credit_card_spec.rb +100 -0
- data/spec/spec_helper.rb +24 -0
- metadata +292 -0
data/lib/braspag.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require 'active_attr'
|
4
|
+
require 'httpi'
|
5
|
+
require 'json'
|
6
|
+
require 'nokogiri'
|
7
|
+
require 'savon'
|
8
|
+
require 'bigdecimal'
|
9
|
+
require 'active_merchant'
|
10
|
+
require 'erb'
|
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'
|
18
|
+
|
19
|
+
require 'braspag/crypto/no_crypto'
|
20
|
+
require 'braspag/crypto/webservice'
|
21
|
+
|
22
|
+
require 'braspag/payment/billet'
|
23
|
+
require 'braspag/payment/credit_card'
|
24
|
+
require 'braspag/payment/eft'
|
25
|
+
require 'braspag/payment/recurrency_credit_card'
|
26
|
+
|
27
|
+
|
28
|
+
module Braspag
|
29
|
+
PATH = File.dirname(__FILE__)
|
30
|
+
|
31
|
+
INTEREST = {
|
32
|
+
:no => 0,
|
33
|
+
:merchant => 1,
|
34
|
+
:customer => 2,
|
35
|
+
:merchant_iata => 3,
|
36
|
+
:customer_iata => 4,
|
37
|
+
:no_iata => 5
|
38
|
+
}
|
39
|
+
|
40
|
+
STATUS_PAYMENT = {
|
41
|
+
:starting => 1,
|
42
|
+
:close => 2,
|
43
|
+
:paid => 3,
|
44
|
+
:cancelled => 4
|
45
|
+
}
|
46
|
+
|
47
|
+
PAYMENT_METHOD = {
|
48
|
+
#BILLET
|
49
|
+
:billet_bradesco => 6, #Boleto Bradesco
|
50
|
+
:billet_cef => 7, #Boleto Caixa Economica Federal
|
51
|
+
:billet_hsbc => 8, #Boleto HSBC
|
52
|
+
:billet_banco_do_brasil => 9, #Boleto Banco do Brasil
|
53
|
+
:billet_santader => 10, #Boleto Banco Santader
|
54
|
+
:billet_citibank => 13, #Boleto Citibank
|
55
|
+
:billet_itau => 14, #Boleto Itau
|
56
|
+
:billet_unibanco => 26, #Boleto Unibanco
|
57
|
+
#EFT
|
58
|
+
:eft_bradesco => 11, #EFT Bradesco
|
59
|
+
:eft_itau => 12, #EFT Itau Shopline
|
60
|
+
:eft_banco_do_brasil => 15, #EFT Banco do Brasil
|
61
|
+
:eft_banco_real => 16, #EFT Banco Real
|
62
|
+
:eft_banrisul => 30, #EFT Banrisul
|
63
|
+
:eft_unibanco => 31, #EFT Unibanco
|
64
|
+
#CARDS - BRASIL
|
65
|
+
:amex_2p => 18, # American Express 2 Party
|
66
|
+
:cielo_noauth_visa => 71, # Cielo webservice captura automática sem autenticação - Visa
|
67
|
+
:cielo_preauth_visa => 73, # Cielo webservice preauth sem autenticação - Visa
|
68
|
+
:cielo_noauth_mastercard => 120, # Cielo webservice captura automática sem autenticação - Mastercard
|
69
|
+
:cielo_preauth_mastercard => 122, # Cielo webservice preauth sem autenticação - Mastercard
|
70
|
+
:cielo_noauth_elo => 126, # Cielo webservice captura automática sem autenticação - ELO
|
71
|
+
:cielo_noauth_diners => 130, # Cielo webservice captura automática sem autenticação - Diners
|
72
|
+
:cielo_noauth_amex => 182, # Cielo webservice captura automática sem autenticaçãi - AMEX
|
73
|
+
:redecard => 20, # Redecard Mastercard/Diners/Visa
|
74
|
+
:redecard_preauth => 42, # Redecard preauth Mastercard/Diners/Visa
|
75
|
+
:cielo_sitef => 57, # Cielo SITEF
|
76
|
+
:hipercard_sitef => 62, # Hipercard SITEF
|
77
|
+
:hipercard_moip => 90, # Hipercard MOIP
|
78
|
+
:oi_paggo => 55, # OiPaggo
|
79
|
+
:amex_sitef => 58, # Amex SITEF
|
80
|
+
:aura_dtef => 37, # Aura DTEF
|
81
|
+
:redecard_sitef => 44, # Redecard SITEF - Mastercard/Diners
|
82
|
+
#CARDS - MEXICO
|
83
|
+
:mex_amex_2p => 45, # American Express 2 Party
|
84
|
+
:mex_banorte_visa => 50, # Banorte Visa
|
85
|
+
:mex_banorte_diners => 52, # Banorte Diners
|
86
|
+
:mex_banorte_mastercard => 53, # Banorte Mastercard
|
87
|
+
#CARDS - COLOMBIA
|
88
|
+
:col_visa => 63, # Visa
|
89
|
+
:col_amex => 65, # Amex
|
90
|
+
:col_diners => 66, # Diners
|
91
|
+
# INTERNACIONAL
|
92
|
+
:paypal_express => 35, # PayPal Express Checkout
|
93
|
+
# HOMOLOGATION
|
94
|
+
:braspag => 997
|
95
|
+
}
|
96
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Braspag
|
2
|
+
class Connection
|
3
|
+
|
4
|
+
class InvalidMerchantId < Exception ; end
|
5
|
+
class InvalidEnvironment < Exception ; end
|
6
|
+
|
7
|
+
PRODUCTION_URL = "https://transaction.pagador.com.br"
|
8
|
+
HOMOLOGATION_URL = "https://homologacao.pagador.com.br"
|
9
|
+
PROTECTED_CARD_PRODUCTION_URL = "https://cartaoprotegido.braspag.com.br/Services"
|
10
|
+
PROTECTED_CARD_HOMOLOGATION_URL = "https://homologacao.braspag.com.br/services/testenvironment"
|
11
|
+
|
12
|
+
attr_reader :merchant_id, :env, :logger, :proxy_address
|
13
|
+
|
14
|
+
def initialize(params = {})
|
15
|
+
merchant_id = params[:merchant_id]
|
16
|
+
env = params[:environment]
|
17
|
+
raise InvalidMerchantId unless merchant_id =~ /\{[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\}/i
|
18
|
+
raise InvalidEnvironment unless (env == :homologation || env == :production)
|
19
|
+
|
20
|
+
@merchant_id = merchant_id
|
21
|
+
@env = env
|
22
|
+
@logger = params[:logger]
|
23
|
+
@proxy_address = params[:proxy_address]
|
24
|
+
end
|
25
|
+
|
26
|
+
def production?
|
27
|
+
@env == :production
|
28
|
+
end
|
29
|
+
|
30
|
+
def homologation?
|
31
|
+
@env == :homologation
|
32
|
+
end
|
33
|
+
|
34
|
+
def url_for(method_name)
|
35
|
+
braspag_url = production? ? PRODUCTION_URL : HOMOLOGATION_URL
|
36
|
+
protected_card_url = production? ? PROTECTED_CARD_PRODUCTION_URL : PROTECTED_CARD_HOMOLOGATION_URL
|
37
|
+
|
38
|
+
braspag_info_url = if production?
|
39
|
+
braspag_url + "/webservices/pagador/pedido.asmx"
|
40
|
+
else
|
41
|
+
braspag_url + "/pagador/webservice/pedido.asmx"
|
42
|
+
end
|
43
|
+
|
44
|
+
case method_name
|
45
|
+
when :authorize
|
46
|
+
braspag_url + "/webservices/pagador/Pagador.asmx/Authorize"
|
47
|
+
when :void
|
48
|
+
braspag_url + "/webservices/pagador/Pagador.asmx/VoidTransaction"
|
49
|
+
when :capture
|
50
|
+
braspag_url + "/webservices/pagador/Pagador.asmx/Capture"
|
51
|
+
when :generate_billet
|
52
|
+
braspag_url + "/webservices/pagador/Boleto.asmx/CreateBoleto"
|
53
|
+
when :generate_eft
|
54
|
+
braspag_url + "/pagador/passthru.asp"
|
55
|
+
when :info_billet
|
56
|
+
braspag_info_url + "/GetDadosBoleto"
|
57
|
+
when :info_credit_card
|
58
|
+
braspag_info_url + "/GetDadosCartao"
|
59
|
+
when :info
|
60
|
+
braspag_info_url + "/GetDadosPedido"
|
61
|
+
when :encrypt
|
62
|
+
braspag_url + "/BraspagGeneralService/BraspagGeneralService.asmx"
|
63
|
+
when :save_credit_card
|
64
|
+
protected_card_url + "/CartaoProtegido.asmx?wsdl"
|
65
|
+
when :get_card
|
66
|
+
protected_card_url + "/CartaoProtegido.asmx/GetCreditCard"
|
67
|
+
when :recurrency
|
68
|
+
protected_card_url + "/CartaoProtegido.asmx?wsdl"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
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] )
|
82
|
+
end
|
83
|
+
|
84
|
+
def soap_request(method_name, *args)
|
85
|
+
url = url_for(method_name)
|
86
|
+
client = Savon.client(wsdl: url)
|
87
|
+
|
88
|
+
binding.pry
|
89
|
+
|
90
|
+
response = client.call method_name, message: self.convert(method_name, :to, args)
|
91
|
+
|
92
|
+
self.convert(method_name, :from, args + [response] )
|
93
|
+
end
|
94
|
+
|
95
|
+
def convert(method_name, direction, args)
|
96
|
+
target = case method_name
|
97
|
+
when :authorize, :void, :capture, :save_credit_card, :get_card, :recurrency
|
98
|
+
CreditCard
|
99
|
+
when :generate_billet
|
100
|
+
Billet
|
101
|
+
when :generate_eft
|
102
|
+
EFT
|
103
|
+
when :info_billet, :info_credit_card, :info
|
104
|
+
Order
|
105
|
+
when :encrypt
|
106
|
+
Crypto::Webservice
|
107
|
+
end
|
108
|
+
|
109
|
+
target.send("#{direction}_#{method_name}", *([self] + args))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Braspag
|
2
|
+
class Converter
|
3
|
+
def self.decimal_to_string(value)
|
4
|
+
#TODO: CHANGE ANOTHER FOR CONVERSION
|
5
|
+
("%.2f" % value.to_f).gsub('.', ',')
|
6
|
+
end
|
7
|
+
|
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
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def self.hash_from_xml(document, map = {})
|
19
|
+
document = Nokogiri::XML(document)
|
20
|
+
|
21
|
+
map.each do |key, value|
|
22
|
+
if value.is_a?(String) || value.nil?
|
23
|
+
value = key if value.nil?
|
24
|
+
|
25
|
+
new_value = document.search(value).first
|
26
|
+
|
27
|
+
if new_value.nil?
|
28
|
+
map[key] = nil
|
29
|
+
else
|
30
|
+
new_value = new_value.content.to_s
|
31
|
+
map[key] = new_value unless new_value == ""
|
32
|
+
map[key] = nil if new_value == ""
|
33
|
+
end
|
34
|
+
|
35
|
+
elsif value.is_a?(Proc)
|
36
|
+
map[key] = value.call(document)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
map
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.payment_method_name?(code)
|
44
|
+
Braspag::PAYMENT_METHOD.key(code.to_s.to_i)
|
45
|
+
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
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.status_name?(code)
|
60
|
+
Braspag::STATUS_PAYMENT.key(code.to_s.to_i)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Braspag
|
2
|
+
class Customer
|
3
|
+
include ::ActiveAttr::Model
|
4
|
+
|
5
|
+
attr_accessor :name, :document, :email
|
6
|
+
|
7
|
+
[:purchase, :generate, :authorize, :archive, :recurrency ].each do |check_on|
|
8
|
+
validates :name, :length => {:minimum => 1, :maximum => 100, :on => check_on }
|
9
|
+
validates :email, :length => {:minimum => 1, :maximum => 255, :on => check_on, :allow_blank => true}
|
10
|
+
validates :document, :length => {:minimum => 11, :maximum => 18, :on => check_on, :allow_blank => true}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,286 @@
|
|
1
|
+
module Braspag
|
2
|
+
class Connection
|
3
|
+
def get(order)
|
4
|
+
response = self.post(:info, order)
|
5
|
+
|
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
|
15
|
+
|
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
|
22
|
+
|
23
|
+
ActiveMerchant::Billing::Response.new(true,
|
24
|
+
'OK',
|
25
|
+
response,
|
26
|
+
:test => homologation?)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Order
|
31
|
+
include ::ActiveAttr::Model
|
32
|
+
|
33
|
+
class AssociationValidator < ActiveModel::EachValidator
|
34
|
+
def validate_each(record, attribute, value)
|
35
|
+
unless value.respond_to?(:valid?) && value.try(:valid?, self.options[:on])
|
36
|
+
record.errors.add attribute, "invalid data"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class PaymentMethodValidator < ActiveModel::EachValidator
|
42
|
+
def validate_each(record, attribute, value)
|
43
|
+
if Braspag::PAYMENT_METHOD.key(value).nil?
|
44
|
+
record.errors.add attribute, "invalid payment code"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class InstallmentsTypeValidator < ActiveModel::EachValidator
|
50
|
+
def validate_each(record, attribute, value)
|
51
|
+
if Braspag::INTEREST.key(value).nil?
|
52
|
+
record.errors.add attribute, "invalid installments type"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
attr_accessor :id, :payment_method, :amount, :customer, :installments, :installments_type
|
58
|
+
attr_accessor :gateway_authorization, :gateway_id, :gateway_return_code, :gateway_status, :gateway_message, :gateway_amount
|
59
|
+
attr_accessor :gateway_capture_return_code, :gateway_capture_status, :gateway_capture_message, :gateway_capture_amount
|
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
|
63
|
+
|
64
|
+
[:purchase, :generate, :authorize, :capture, :void, :recurrency].each do |check_on|
|
65
|
+
validates :id, :presence => { :on => check_on }
|
66
|
+
validates :id, :length => {:minimum => 1, :maximum => 20, :on => check_on }
|
67
|
+
validates :id, :format => { :with => /^[0-9]+$/, :on => check_on, :if => :payment_for_cielo? }
|
68
|
+
end
|
69
|
+
|
70
|
+
[:purchase, :generate, :authorize, :recurrency].each do |check_on|
|
71
|
+
validates :payment_method, :presence => { :on => check_on }
|
72
|
+
validates :payment_method, :payment_method => { :on => check_on }
|
73
|
+
|
74
|
+
validates :amount, :presence => { :on => check_on }
|
75
|
+
validates :amount, :numericality => {:greater_than => 0, :on => check_on}
|
76
|
+
|
77
|
+
validates :customer, :presence => { :on => check_on }
|
78
|
+
validates :customer, :association => { :on => check_on }
|
79
|
+
end
|
80
|
+
|
81
|
+
[:purchase, :authorize, :recurrency].each do |check_on|
|
82
|
+
validates :installments, :presence => { :on => check_on }
|
83
|
+
validates :installments, :numericality => {:only_integer => true, :greater_than => 0, :less_than => 100, :on => check_on}
|
84
|
+
validates :installments, :format => { :with => /1/, :on => check_on, :if => :no_interest? }
|
85
|
+
validates :installments_type, :presence => { :on => check_on }
|
86
|
+
validates :installments_type, :installments_type => { :on => check_on }
|
87
|
+
end
|
88
|
+
|
89
|
+
def no_interest?
|
90
|
+
case installments_type
|
91
|
+
when Braspag::INTEREST[:no],
|
92
|
+
Braspag::INTEREST[:no_iata]
|
93
|
+
true
|
94
|
+
else
|
95
|
+
false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def payment_method_type?
|
100
|
+
Converter.payment_method_type?(self.payment_method)
|
101
|
+
end
|
102
|
+
|
103
|
+
def build_customer
|
104
|
+
self.customer = Customer.new
|
105
|
+
end
|
106
|
+
|
107
|
+
def build_billet
|
108
|
+
self.billet = Billet.new
|
109
|
+
end
|
110
|
+
|
111
|
+
def build_credit_card
|
112
|
+
self.credit_card = CreditCard.new
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.to_info(connection, order)
|
116
|
+
{
|
117
|
+
"loja" => connection.merchant_id,
|
118
|
+
"numeroPedido" => order.id.to_s
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
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
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.to_info_credit_card(connection, order)
|
173
|
+
{
|
174
|
+
"loja" => connection.merchant_id,
|
175
|
+
"numeroPedido" => order.id.to_s
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
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",
|
186
|
+
|
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
|
204
|
+
end
|
205
|
+
|
206
|
+
def self.to_info_billet(connection, order)
|
207
|
+
{
|
208
|
+
"loja" => connection.merchant_id,
|
209
|
+
"numeroPedido" => order.id.to_s
|
210
|
+
}
|
211
|
+
end
|
212
|
+
|
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]
|
268
|
+
|
269
|
+
response
|
270
|
+
end
|
271
|
+
|
272
|
+
private
|
273
|
+
def payment_for_cielo?
|
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]
|
281
|
+
true
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
end
|