-
1
require "rubygems"
-
1
require "bundler/setup"
-
1
require 'active_attr'
-
1
require 'httpi'
-
1
require 'json'
-
1
require 'nokogiri'
-
1
require 'savon'
-
1
require 'bigdecimal'
-
1
require 'active_merchant'
-
1
require 'erb'
-
-
1
require "braspag-pagador/version"
-
1
require 'braspag-pagador/core/converter'
-
1
require 'braspag-pagador/core/connection'
-
1
require 'braspag-pagador/core/poster'
-
1
require 'braspag-pagador/core/customer'
-
1
require 'braspag-pagador/core/order'
-
-
1
require 'braspag-pagador/crypto/no_crypto'
-
1
require 'braspag-pagador/crypto/webservice'
-
-
1
require 'braspag-pagador/payment/billet'
-
1
require 'braspag-pagador/payment/credit_card'
-
1
require 'braspag-pagador/payment/eft'
-
1
require 'braspag-pagador/payment/recurrency_credit_card'
-
-
-
1
module BraspagPagador
-
1
PATH = File.dirname(__FILE__)
-
-
1
INTEREST = {
-
:no => 0,
-
:merchant => 1,
-
:customer => 2,
-
:merchant_iata => 3,
-
:customer_iata => 4,
-
:no_iata => 5
-
}
-
-
1
STATUS_PAYMENT = {
-
:starting => 1,
-
:close => 2,
-
:paid => 3,
-
:cancelled => 4
-
}
-
-
1
PAYMENT_METHOD = {
-
#BILLET
-
:billet_bradesco => 6, #Boleto Bradesco
-
:billet_cef => 7, #Boleto Caixa Economica Federal
-
:billet_hsbc => 8, #Boleto HSBC
-
:billet_banco_do_brasil => 9, #Boleto Banco do Brasil
-
:billet_santader => 10, #Boleto Banco Santader
-
:billet_citibank => 13, #Boleto Citibank
-
:billet_itau => 14, #Boleto Itau
-
:billet_unibanco => 26, #Boleto Unibanco
-
#EFT
-
:eft_bradesco => 11, #EFT Bradesco
-
:eft_itau => 12, #EFT Itau Shopline
-
:eft_banco_do_brasil => 15, #EFT Banco do Brasil
-
:eft_banco_real => 16, #EFT Banco Real
-
:eft_banrisul => 30, #EFT Banrisul
-
:eft_unibanco => 31, #EFT Unibanco
-
#CARDS - BRASIL
-
:amex_2p => 18, # American Express 2 Party
-
:cielo_noauth_visa => 71, # Cielo webservice captura automática sem autenticação - Visa
-
:cielo_preauth_visa => 73, # Cielo webservice preauth sem autenticação - Visa
-
:cielo_noauth_mastercard => 120, # Cielo webservice captura automática sem autenticação - Mastercard
-
:cielo_preauth_mastercard => 122, # Cielo webservice preauth sem autenticação - Mastercard
-
:cielo_noauth_elo => 126, # Cielo webservice captura automática sem autenticação - ELO
-
:cielo_noauth_diners => 130, # Cielo webservice captura automática sem autenticação - Diners
-
:cielo_noauth_amex => 182, # Cielo webservice captura automática sem autenticaçãi - AMEX
-
:redecard => 20, # Redecard Mastercard/Diners/Visa
-
:redecard_preauth => 42, # Redecard preauth Mastercard/Diners/Visa
-
:cielo_sitef => 57, # Cielo SITEF
-
:hipercard_sitef => 62, # Hipercard SITEF
-
:hipercard_moip => 90, # Hipercard MOIP
-
:oi_paggo => 55, # OiPaggo
-
:amex_sitef => 58, # Amex SITEF
-
:aura_dtef => 37, # Aura DTEF
-
:redecard_sitef => 44, # Redecard SITEF - Mastercard/Diners
-
#CARDS - MEXICO
-
:mex_amex_2p => 45, # American Express 2 Party
-
:mex_banorte_visa => 50, # Banorte Visa
-
:mex_banorte_diners => 52, # Banorte Diners
-
:mex_banorte_mastercard => 53, # Banorte Mastercard
-
#CARDS - COLOMBIA
-
:col_visa => 63, # Visa
-
:col_amex => 65, # Amex
-
:col_diners => 66, # Diners
-
# INTERNACIONAL
-
:paypal_express => 35, # PayPal Express Checkout
-
# HOMOLOGATION
-
:homologation => 997
-
}
-
end
-
1
module BraspagPagador
-
1
class Connection
-
-
1
class InvalidMerchantId < Exception ; end
-
1
class InvalidEnvironment < Exception ; end
-
-
1
PRODUCTION_URL = "https://transaction.pagador.com.br"
-
1
HOMOLOGATION_URL = "https://homologacao.pagador.com.br"
-
# PROTECTED_CARD_HOMOLOGATION_URL = "https://cartaoprotegido.braspag.com.br/Services/V2"
-
# PROTECTED_CARD_PRODUCTION_URL = "https://homologacao.braspag.com.br/services/testenvironment"
-
1
PROTECTED_CARD_PRODUCTION_URL = "https://cartaoprotegido.braspag.com.br/Services/V2"
-
1
PROTECTED_CARD_HOMOLOGATION_URL = "https://homologacao.braspag.com.br/services/testenvironment"
-
-
1
attr_reader :merchant_id, :env, :logger, :proxy_address
-
-
1
def initialize(params = {})
-
69
merchant_id = params[:merchant_id]
-
69
env = params[:environment]
-
69
raise InvalidMerchantId unless merchant_id =~ /\{[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\}/i
-
68
raise InvalidEnvironment unless (env == :homologation || env == :production)
-
-
66
@merchant_id = merchant_id
-
66
@env = env
-
66
@logger = params[:logger]
-
66
@proxy_address = params[:proxy_address]
-
end
-
-
1
def production?
-
89
@env == :production
-
end
-
-
1
def homologation?
-
21
@env == :homologation
-
end
-
-
1
def url_for(method_name)
-
29
braspag_url = production? ? PRODUCTION_URL : HOMOLOGATION_URL
-
29
protected_card_url = production? ? PROTECTED_CARD_PRODUCTION_URL : PROTECTED_CARD_HOMOLOGATION_URL
-
-
29
braspag_info_url = if production?
-
12
braspag_url + "/webservices/pagador/pedido.asmx"
-
else
-
17
braspag_url + "/pagador/webservice/pedido.asmx"
-
end
-
-
29
case method_name
-
when :authorize
-
2
braspag_url + "/webservices/pagador/Pagador.asmx/Authorize"
-
when :void
-
2
braspag_url + "/webservices/pagador/Pagador.asmx/VoidTransaction"
-
when :capture
-
2
braspag_url + "/webservices/pagador/Pagador.asmx/Capture"
-
when :generate_billet
-
2
braspag_url + "/webservices/pagador/Boleto.asmx/CreateBoleto"
-
when :generate_eft
-
6
braspag_url + "/pagador/passthru.asp"
-
when :info_billet
-
2
braspag_info_url + "/GetDadosBoleto"
-
when :info_credit_card
-
2
braspag_info_url + "/GetDadosCartao"
-
when :info
-
3
braspag_info_url + "/GetDadosPedido"
-
when :encrypt
-
2
braspag_url + "/BraspagGeneralService/BraspagGeneralService.asmx"
-
when :save_credit_card
-
2
protected_card_url + "/CartaoProtegido.asmx?wsdl"
-
when :get_card
-
2
protected_card_url + "/CartaoProtegido.asmx/GetCreditCard"
-
when :recurrency
-
2
protected_card_url + "/CartaoProtegido.asmx?wsdl"
-
end
-
end
-
-
1
def post(method_name, *args)
-
1
response = BraspagPagador::Poster.new(
-
self,
-
self.url_for(method_name)
-
).do_post(
-
method_name,
-
self.convert(method_name, :to, args)
-
)
-
-
1
self.convert(method_name, :from, args + [response] )
-
end
-
-
1
def soap_request(method_name, *args)
-
url = url_for(method_name)
-
client = Savon.client(wsdl: url)
-
-
binding.pry
-
-
response = client.call method_name, message: self.convert(method_name, :to, args)
-
-
self.convert(method_name, :from, args + [response] )
-
end
-
-
1
def convert(method_name, direction, args)
-
12
target = case method_name
-
when :authorize, :void, :capture, :save_credit_card, :get_card, :recurrency
-
6
CreditCard
-
when :generate_billet
-
1
Billet
-
when :generate_eft
-
1
EFT
-
when :info_billet, :info_credit_card, :info
-
3
Order
-
when :encrypt
-
1
Crypto::Webservice
-
end
-
-
12
target.send("#{direction}_#{method_name}", *([self] + args))
-
end
-
end
-
end
-
1
module BraspagPagador
-
1
class Converter
-
1
def self.decimal_to_string(value)
-
#TODO: CHANGE ANOTHER FOR CONVERSION
-
15
("%.2f" % value.to_f).gsub('.', ',')
-
end
-
-
1
def self.string_to_decimal(value, mode = :br)
-
19
case mode
-
when :br
-
16
BigDecimal.new(value.to_s.gsub(".","").gsub(",","."))
-
when :eua
-
3
BigDecimal.new(value.to_s.gsub(",",""))
-
end
-
end
-
-
-
1
def self.hash_from_xml(document, map = {})
-
14
document = Nokogiri::XML(document)
-
-
14
map.each do |key, value|
-
115
if value.is_a?(String) || value.nil?
-
97
value = key if value.nil?
-
-
97
new_value = document.search(value).first
-
-
97
if new_value.nil?
-
36
map[key] = nil
-
else
-
61
new_value = new_value.content.to_s
-
61
map[key] = new_value unless new_value == ""
-
61
map[key] = nil if new_value == ""
-
end
-
-
elsif value.is_a?(Proc)
-
18
map[key] = value.call(document)
-
end
-
end
-
-
14
map
-
end
-
-
1
def self.payment_method_name?(code)
-
4
BraspagPagador::PAYMENT_METHOD.key(code.to_s.to_i)
-
end
-
-
1
def self.payment_method_type?(code)
-
8
key = BraspagPagador::PAYMENT_METHOD.key(code.to_s.to_i)
-
8
return nil if key.nil?
-
6
if key.match(/billet_/)
-
3
:billet
-
3
elsif key.match(/eft_/)
-
1
:eft
-
else
-
2
:credit_card
-
end
-
end
-
-
1
def self.status_name?(code)
-
4
BraspagPagador::STATUS_PAYMENT.key(code.to_s.to_i)
-
end
-
end
-
end
-
1
module BraspagPagador
-
1
class Customer
-
1
include ::ActiveAttr::Model
-
-
1
attr_accessor :name, :document, :email
-
-
1
[:purchase, :generate, :authorize, :archive, :recurrency ].each do |check_on|
-
5
validates :name, :length => {:minimum => 1, :maximum => 100, :on => check_on }
-
5
validates :email, :length => {:minimum => 1, :maximum => 255, :on => check_on, :allow_blank => true}
-
5
validates :document, :length => {:minimum => 11, :maximum => 18, :on => check_on, :allow_blank => true}
-
end
-
end
-
end
-
1
module BraspagPagador
-
1
class Connection
-
1
def get(order)
-
6
response = self.post(:info, order)
-
-
if ( response.size == 0 ||
-
6
!response.fetch(:error_code, nil).nil? ||
-
response.fetch(:status, nil).nil?
-
)
-
return ActiveMerchant::Billing::Response.new(false,
-
response.fetch(:error_message, ''),
-
response,
-
3
:test => homologation?)
-
end
-
-
3
case order.payment_method_type?
-
when :billet
-
1
self.post(:info_billet, order)
-
when :credit_card
-
1
self.post(:info_credit_card, order)
-
end
-
-
3
ActiveMerchant::Billing::Response.new(true,
-
'OK',
-
response,
-
:test => homologation?)
-
end
-
end
-
-
1
class Order
-
1
include ::ActiveAttr::Model
-
-
1
class AssociationValidator < ActiveModel::EachValidator
-
1
def validate_each(record, attribute, value)
-
126
unless value.respond_to?(:valid?) && value.try(:valid?, self.options[:on])
-
126
record.errors.add attribute, "invalid data"
-
end
-
end
-
end
-
-
1
class PaymentMethodValidator < ActiveModel::EachValidator
-
1
def validate_each(record, attribute, value)
-
126
if BraspagPagador::PAYMENT_METHOD.key(value).nil?
-
54
record.errors.add attribute, "invalid payment code"
-
end
-
end
-
end
-
-
1
class InstallmentsTypeValidator < ActiveModel::EachValidator
-
1
def validate_each(record, attribute, value)
-
99
if BraspagPagador::INTEREST.key(value).nil?
-
96
record.errors.add attribute, "invalid installments type"
-
end
-
end
-
end
-
-
1
attr_accessor :id, :payment_method, :amount, :customer, :installments, :installments_type
-
1
attr_accessor :gateway_authorization, :gateway_id, :gateway_return_code, :gateway_status, :gateway_message, :gateway_amount
-
1
attr_accessor :gateway_capture_return_code, :gateway_capture_status, :gateway_capture_message, :gateway_capture_amount
-
1
attr_accessor :gateway_void_return_code, :gateway_void_status, :gateway_void_message, :gateway_void_amount
-
1
attr_accessor :authorization, :payment_method_name, :status, :gateway_cancelled_at, :gateway_paid_at
-
1
attr_accessor :gateway_created_at, :transaction_id, :gateway_id, :billet, :credit_card
-
-
1
[:purchase, :generate, :authorize, :capture, :void, :recurrency].each do |check_on|
-
6
validates :id, :presence => { :on => check_on }
-
6
validates :id, :length => {:minimum => 1, :maximum => 20, :on => check_on }
-
6
validates :id, :format => { :with => /^[0-9]+$/, :on => check_on, :if => :payment_for_cielo? }
-
end
-
-
1
[:purchase, :generate, :authorize, :recurrency].each do |check_on|
-
4
validates :payment_method, :presence => { :on => check_on }
-
4
validates :payment_method, :payment_method => { :on => check_on }
-
-
4
validates :amount, :presence => { :on => check_on }
-
4
validates :amount, :numericality => {:greater_than => 0, :on => check_on}
-
-
4
validates :customer, :presence => { :on => check_on }
-
4
validates :customer, :association => { :on => check_on }
-
end
-
-
1
[:purchase, :authorize, :recurrency].each do |check_on|
-
3
validates :installments, :presence => { :on => check_on }
-
3
validates :installments, :numericality => {:only_integer => true, :greater_than => 0, :less_than => 100, :on => check_on}
-
3
validates :installments, :format => { :with => /1/, :on => check_on, :if => :no_interest? }
-
3
validates :installments_type, :presence => { :on => check_on }
-
3
validates :installments_type, :installments_type => { :on => check_on }
-
end
-
-
1
def no_interest?
-
99
case installments_type
-
when BraspagPagador::INTEREST[:no],
-
BraspagPagador::INTEREST[:no_iata]
-
3
true
-
else
-
96
false
-
end
-
end
-
-
1
def payment_method_type?
-
4
Converter.payment_method_type?(self.payment_method)
-
end
-
-
1
def build_customer
-
2
self.customer = Customer.new
-
end
-
-
1
def build_billet
-
2
self.billet = Billet.new
-
end
-
-
1
def build_credit_card
-
1
self.credit_card = CreditCard.new
-
end
-
-
1
def self.to_info(connection, order)
-
{
-
"loja" => connection.merchant_id,
-
"numeroPedido" => order.id.to_s
-
1
}
-
end
-
-
1
def self.from_info(connection, order, params)
-
3
response = BraspagPagador::Converter::hash_from_xml(params.body, {
-
:authorization => "CodigoAutorizacao",
-
:error_code => "CodigoErro",
-
:error_message => "MensagemErro",
-
:payment_method => "CodigoPagamento",
-
:payment_method_name => "FormaPagamento",
-
:installments => "NumeroParcelas",
-
:status => "Status",
-
:amount => "Valor",
-
:cancelled_at => Proc.new { |document|
-
3
begin
-
3
Time.parse(document.search("DataCancelamento").first.to_s)
-
rescue
-
2
nil
-
end
-
},
-
:paid_at => Proc.new { |document|
-
3
begin
-
3
Time.parse(document.search("DataPagamento").first.to_s)
-
rescue
-
2
nil
-
end
-
},
-
:order_date => Proc.new { |document|
-
3
begin
-
3
Time.parse(document.search("DataPedido").first.to_s)
-
rescue
-
2
nil
-
end
-
},
-
:transaction_id => "TransId",
-
:tid => "BraspagTid"
-
})
-
-
3
order.authorization = response[:authorization]
-
3
order.payment_method_name = response[:payment_method_name]
-
3
order.payment_method = response[:payment_method]
-
3
order.installments = response[:installments]
-
3
order.status = response[:status]
-
3
order.amount = BraspagPagador::Converter::string_to_decimal(response[:amount], :eua)
-
3
order.gateway_cancelled_at = response[:cancelled_at]
-
3
order.gateway_paid_at = response[:paid_at]
-
3
order.gateway_created_at = response[:order_date]
-
3
order.transaction_id = response[:transaction_id]
-
3
order.gateway_id = response[:tid]
-
-
3
response
-
end
-
-
1
def self.to_info_credit_card(connection, order)
-
{
-
"loja" => connection.merchant_id,
-
"numeroPedido" => order.id.to_s
-
1
}
-
end
-
-
1
def self.from_info_credit_card(connection, order, params)
-
1
response = BraspagPagador::Converter::hash_from_xml(params.body, {
-
:checking_number => "NumeroComprovante",
-
:certified => "Autenticada",
-
:autorization_number => "NumeroAutorizacao",
-
:card_number => "NumeroCartao",
-
:transaction_number => "NumeroTransacao",
-
-
:avs_response => "RetornoAVS",
-
:issuing => "Emissor",
-
:authenticated_number => "NumeroAutenticacao"
-
})
-
-
1
order.build_credit_card if order.credit_card.nil?
-
-
1
order.credit_card.checking_number = response[:checking_number]
-
1
order.credit_card.avs = response[:certified]
-
1
order.credit_card.autorization_number = response[:autorization_number]
-
1
order.credit_card.number = response[:card_number]
-
1
order.credit_card.transaction_number = response[:transaction_number]
-
1
order.credit_card.avs_response = response[:avs_response]
-
1
order.credit_card.issuing = response[:issuing]
-
1
order.credit_card.authenticated_number = response[:authenticated_number]
-
-
1
response
-
end
-
-
1
def self.to_info_billet(connection, order)
-
{
-
"loja" => connection.merchant_id,
-
"numeroPedido" => order.id.to_s
-
1
}
-
end
-
-
1
def self.from_info_billet(connection, order, params)
-
2
response = BraspagPagador::Converter::hash_from_xml(params.body, {
-
:document_number => "NumeroDocumento",
-
:payer => "Sacado",
-
:our_number => "NossoNumero",
-
:bill_line => "LinhaDigitavel",
-
:document_date => Proc.new { |document|
-
2
begin
-
2
Date.parse(document.search("DataDocumento").first.to_s)
-
rescue
-
1
nil
-
end
-
},
-
:expiration_date => Proc.new { |document|
-
2
begin
-
2
Date.parse(document.search("DataVencimento").first.to_s)
-
rescue
-
1
nil
-
end
-
},
-
:receiver => "Cedente",
-
:bank => "Banco",
-
:agency => "Agencia",
-
:account => "Conta",
-
:wallet => "Carteira",
-
:amount => "ValorDocumento",
-
:amount_invoice => "ValorPago",
-
:invoice_date => Proc.new { |document|
-
2
begin
-
2
Date.parse(document.search("DataCredito").first.to_s)
-
rescue
-
1
nil
-
end
-
}
-
})
-
-
2
order.build_customer if order.customer.nil?
-
2
order.customer.name = response[:payer]
-
-
2
order.build_billet if order.billet.nil?
-
2
order.billet.id = response[:our_number]
-
2
order.billet.code = response[:bill_line]
-
-
2
order.billet.created_at = response[:document_date]
-
2
order.billet.due_date_on = response[:expiration_date]
-
-
2
order.billet.receiver = response[:receiver]
-
-
2
order.billet.bank = response[:bank]
-
2
order.billet.agency = response[:agency]
-
2
order.billet.account = response[:account]
-
2
order.billet.wallet = response[:wallet]
-
2
order.billet.amount = BraspagPagador::Converter::string_to_decimal(response[:amount])
-
2
order.billet.amount_paid = BraspagPagador::Converter::string_to_decimal(response[:amount_invoice])
-
2
order.billet.paid_at = response[:invoice_date]
-
-
2
response
-
end
-
-
1
private
-
1
def payment_for_cielo?
-
168
case payment_method
-
when BraspagPagador::PAYMENT_METHOD[:cielo_noauth_visa],
-
BraspagPagador::PAYMENT_METHOD[:cielo_preauth_visa],
-
BraspagPagador::PAYMENT_METHOD[:cielo_noauth_mastercard],
-
BraspagPagador::PAYMENT_METHOD[:cielo_preauth_mastercard],
-
BraspagPagador::PAYMENT_METHOD[:cielo_noauth_elo],
-
BraspagPagador::PAYMENT_METHOD[:cielo_noauth_diners]
-
108
true
-
end
-
end
-
-
end
-
end
-
1
module BraspagPagador
-
1
class Poster
-
1
def initialize(connection, url)
-
7
@connection = connection
-
7
@request = ::HTTPI::Request.new(url)
-
end
-
-
1
def do_post(method, data, headers = {})
-
6
@request.body = data
-
6
@request.proxy = @connection.proxy_address if @connection.proxy_address
-
6
headers.each_pair do |k,v|
-
@request.headers[k] = v
-
end
-
-
6
with_logger(method) do
-
6
::HTTPI.post @request
-
end
-
end
-
-
1
private
-
-
1
def with_logger(method)
-
6
if @connection.logger
-
3
@connection.logger.info("[Braspag] ##{method}: #{@request.url}, data: #{mask_data(@request.body).inspect}")
-
3
response = yield
-
3
@connection.logger.info("[Braspag] ##{method} returns: #{response.body.inspect}")
-
else
-
3
response = yield
-
end
-
6
response
-
end
-
-
1
def mask_data(data)
-
3
copy_data = data.dup
-
3
copy_data['cardNumber'] = "************%s" % copy_data['cardNumber'][-4..-1] if copy_data['cardNumber']
-
3
copy_data['securityCode'] = "***" if copy_data['securityCode']
-
3
copy_data
-
end
-
end
-
end
-
1
module BraspagPagador
-
1
module Crypto
-
1
class NoCrypto
-
end
-
end
-
end
-
1
module BraspagPagador
-
1
module Crypto
-
1
class Webservice
-
1
def encrypt(connection, map)
-
4
data = ERB.new(File.read(BraspagPagador::PATH + '/braspag-pagador/templates/crypto/encrypt.xml.erb'))
-
-
4
response = BraspagPagador::Poster.new(
-
connection,
-
connection.url_for(:encrypt)
-
).do_post(
-
:encrypt,
-
data.result(binding),
-
{"Content-Type" => "text/xml"}
-
)
-
-
4
document = Nokogiri::XML(response.body)
-
-
4
raise 'UnknownError' if document.children.empty?
-
-
#melhorar este parser cof cof
-
3
response = document.children.children.children.children.children.to_s
-
-
3
raise 'InvalidMerchantId' if (response == 'Erro BP 011' || response == 'Erro BP 012')
-
2
raise 'InvalidIP' if (response == 'Erro BP 067' || response == 'Erro BP 068')
-
-
1
response
-
end
-
-
1
def decrypt(connection, encripted_text)
-
3
data = ERB.new(File.read(BraspagPagador::PATH + '/braspag-pagador/templates/crypto/decrypt.xml.erb'))
-
-
3
response = BraspagPagador::Poster.new(
-
connection,
-
connection.url_for(:decrypt)
-
).do_post(
-
:decrypt,
-
data.result(binding),
-
{"Content-Type" => "text/xml"}
-
)
-
-
3
document = Nokogiri::XML(response.body)
-
3
raise 'UnknownError' if document.children.empty?
-
-
2
result_error = document.children.children.children.children.children.first.content.to_s
-
-
2
raise 'InvalidMerchantId' if (result_error == 'Erro BP 011' || result_error == 'Erro BP 012')
-
2
raise 'InvalidIP' if (result_error == 'Erro BP 067' || result_error == 'Erro BP 068')
-
-
1
convert_request_to_map document
-
end
-
-
1
protected
-
1
def convert_request_to_map(document)
-
1
map = {}
-
1
document.children.children.children.children.children.each do |n|
-
11
values = n.content.to_s.split("=")
-
11
map[values[0].downcase.to_sym] = values[1] if values.size == 2
-
end
-
1
map
-
end
-
end
-
end
-
end
-
1
require "bigdecimal"
-
-
1
module BraspagPagador
-
1
class Connection
-
1
def generate_billet(order, billet)
-
2
response = self.post(:generate_billet, order, billet)
-
2
status = (response[:status] == "0")
-
-
2
ActiveMerchant::Billing::Response.new(status,
-
response[:message],
-
response,
-
:test => homologation?,
-
:authorization => response[:number])
-
end
-
end
-
-
1
class Billet
-
1
include ::ActiveAttr::Model
-
-
1
class DueDateValidator < ActiveModel::EachValidator
-
1
def validate_each(record, attribute, value)
-
# unless value.class.in? [Date, Time]
-
unless (
-
7
value.kind_of?(Time) || value.kind_of?(Date)
-
)
-
6
record.errors.add attribute, "invalid date"
-
end
-
end
-
end
-
-
1
attr_accessor :id, :instructions, :due_date_on, :url, :code, :created_at, :due_date_on
-
1
attr_accessor :receiver, :bank, :agency, :account, :wallet, :amount, :amount_paid, :paid_at
-
-
1
validates :id, :length => {:minimum => 1, :maximum => 255, :on => :generate, :allow_blank => true }
-
1
validates :instructions, :length => {:minimum => 1, :maximum => 512, :on => :generate, :allow_blank => true }
-
1
validates :due_date_on, :presence => { :on => :generate }
-
1
validates :due_date_on, :due_date => { :on => :generate }
-
-
1
def self.to_generate_billet(connection, order, billet)
-
{
-
"merchantId" => connection.merchant_id,
-
"boletoNumber" => billet.id.to_s,
-
"instructions" => billet.instructions.to_s,
-
"expirationDate" => billet.due_date_on.strftime("%d/%m/%y"),
-
"customerName" => order.customer.name.to_s,
-
"customerIdNumber" => order.customer.document.to_s,
-
"emails" => order.customer.email.to_s,
-
"orderId" => order.id.to_s,
-
"amount" => BraspagPagador::Converter::decimal_to_string(order.amount),
-
"paymentMethod" => order.payment_method
-
1
}
-
end
-
-
1
def self.from_generate_billet(connection, order, billet, params)
-
2
response = BraspagPagador::Converter::hash_from_xml(params.body, {
-
:url => nil,
-
:amount => nil,
-
:number => "boletoNumber",
-
:expiration_date => Proc.new { |document|
-
2
begin
-
2
Date.parse(document.search("expirationDate").first.to_s)
-
rescue
-
1
nil
-
end
-
},
-
:return_code => "returnCode",
-
:status => nil,
-
:message => nil
-
})
-
-
2
order.gateway_return_code = response[:return_code]
-
2
order.gateway_status = response[:status]
-
2
order.gateway_amount = BigDecimal.new(response[:amount].to_s) if response[:amount]
-
2
billet.url = response[:url]
-
-
2
response
-
end
-
end
-
end
-
1
module BraspagPagador
-
1
class Connection
-
1
def purchase(order, credit_card)
-
2
resp = self.authorize(order, credit_card)
-
2
resp = self.capture(order) if resp.success?
-
2
resp
-
end
-
-
1
def authorize(order, credit_card)
-
3
response = self.post(:authorize, order, credit_card)
-
-
3
status = (response[:status] == "0" || response[:status] == "1")
-
-
3
ActiveMerchant::Billing::Response.new(status,
-
response[:message],
-
response,
-
:test => homologation?,
-
:authorization => response[:number])
-
end
-
-
1
def capture(order)
-
2
response = self.post(:capture, order)
-
-
2
status = (response[:status] == "0")
-
-
2
ActiveMerchant::Billing::Response.new(status,
-
response[:message],
-
response,
-
:test => homologation?,
-
:authorization => response[:number])
-
end
-
-
1
def void(order, partial=nil)
-
2
response = self.post(:void, order)
-
-
2
status = (response[:status] == "0")
-
-
2
ActiveMerchant::Billing::Response.new(status,
-
response[:message],
-
response,
-
:test => homologation?)
-
end
-
end
-
-
1
class CreditCard
-
1
include ::ActiveAttr::Model
-
-
1
attr_accessor :holder_name, :number, :month, :year, :verification_value, :alias, :id
-
1
attr_accessor :checking_number, :avs, :autorization_number, :transaction_number
-
1
attr_accessor :avs_response, :issuing, :authenticated_number
-
-
1
class ExpiratorValidator < ActiveModel::EachValidator
-
1
def validate_each(record, attribute, value)
-
112
begin
-
112
year = record.year.try(:to_i)
-
112
year = "20#{year}".to_i if year && year.to_s.size == 2
-
-
112
month = record.month.try(:to_i)
-
-
112
Date.new(year, month) if year && month
-
12
rescue ArgumentError
-
12
record.errors.add attribute, "invalid date"
-
end
-
end
-
end
-
-
-
1
[:purchase, :authorize, :archive].each do |check_on|
-
3
validates :holder_name, :length => {:minimum => 1, :maximum => 100, :on => check_on}
-
-
3
validates :number, :presence => { :on => check_on }
-
-
3
validates :month, :presence => { :on => check_on }
-
3
validates :month, :expirator => { :on => check_on }
-
3
validates :year, :presence => { :on => check_on }
-
3
validates :year, :expirator => { :on => check_on }
-
end
-
-
1
[:purchase, :authorize, :recurrency].each do |check_on|
-
3
validates :verification_value, :length => {:minimum => 1, :maximum => 4, :on => check_on}
-
end
-
-
1
[:get_recurrency, :recurrency].each do |check_on|
-
2
validates :id, :length => {:is => 36, :on => check_on}
-
end
-
-
1
def self.to_save_credit_card(connection,credit_card,customer,request_id)
-
{
-
'saveCreditCardRequestWS' => {
-
'MerchantKey' => connection.merchant_id,
-
'CustomerName' => customer.name.to_s,
-
'CardHolder' => credit_card.holder_name.to_s,
-
'CardNumber' => credit_card.number.to_s,
-
'CardExpiration' => "#{credit_card.month}/#{credit_card.year}",
-
'RequestId' => request_id
-
}
-
}
-
end
-
-
1
def self.to_authorize(connection, order, credit_card)
-
1
year_normalize = credit_card.year.to_s[-2, 2]
-
{
-
"merchantId" => connection.merchant_id,
-
"holder" => credit_card.holder_name.to_s,
-
"cardNumber" => credit_card.number.to_s,
-
"expiration" => "#{credit_card.month}/#{year_normalize}",
-
"securityCode" => credit_card.verification_value.to_s,
-
"customerName" => order.customer.name.to_s,
-
"orderId" => order.id.to_s,
-
"amount" => BraspagPagador::Converter::decimal_to_string(order.amount),
-
"paymentMethod" => order.payment_method,
-
"numberPayments" => order.installments,
-
"typePayment" => order.installments_type
-
1
}
-
end
-
-
1
def self.from_authorize(connection, order, credit_card, params)
-
1
response = BraspagPagador::Converter::hash_from_xml(params.body, {
-
:amount => nil,
-
:number => "authorisationNumber",
-
:message => nil,
-
:return_code => 'returnCode',
-
:status => nil,
-
:transaction_id => "transactionId"
-
})
-
-
1
order.gateway_authorization = response[:number]
-
1
order.gateway_id = response[:transaction_id]
-
1
order.gateway_return_code = response[:return_code]
-
1
order.gateway_status = response[:status]
-
1
order.gateway_message = response[:message]
-
1
order.gateway_amount = BraspagPagador::Converter::string_to_decimal(response[:amount])
-
-
1
response
-
end
-
-
1
def self.to_capture(connection, order)
-
{
-
"merchantId" => connection.merchant_id,
-
"orderId" => order.id.to_s
-
1
}
-
end
-
-
1
def self.from_capture(connection, order, params)
-
1
response = BraspagPagador::Converter::hash_from_xml(params.body, {
-
:amount => nil,
-
:message => 'message',
-
:return_code => 'returnCode',
-
:status => 'status',
-
:transaction_id => "transactionId"
-
})
-
-
#TODO: CHECK IF IS NECESSARY
-
# order.gateway_capture_id = response[:transaction_id]
-
1
order.gateway_capture_return_code = response[:return_code]
-
1
order.gateway_capture_status = response[:status]
-
1
order.gateway_capture_message = response[:message]
-
1
order.gateway_capture_amount = BraspagPagador::Converter::string_to_decimal(response[:amount])
-
-
1
response
-
end
-
-
1
def self.to_void(connection, order)
-
{
-
"merchantId" => connection.merchant_id,
-
"order" => order.id.to_s
-
1
}
-
end
-
-
1
def self.from_void(connection, order, params)
-
1
response = BraspagPagador::Converter::hash_from_xml(params.body, {
-
:order_id => "orderId",
-
:amount => nil,
-
:message => 'message',
-
:return_code => 'returnCode',
-
:status => 'status',
-
:transaction_id => "transactionId"
-
})
-
-
#TODO: CHECK IF IS NECESSARY
-
# order.gateway_void_id = response[:transaction_id]
-
1
order.gateway_void_return_code = response[:return_code]
-
1
order.gateway_void_status = response[:status]
-
1
order.gateway_void_message = response[:message]
-
1
order.gateway_void_amount = BraspagPagador::Converter::string_to_decimal(response[:amount])
-
-
1
response
-
end
-
end
-
end
-
1
module BraspagPagador
-
1
class Connection
-
1
def generate_eft(order, eft)
-
-
4
params = {
-
Id_Loja: self.merchant_id,
-
VALOR: BraspagPagador::Converter::decimal_to_string(order.amount),
-
CODPAGAMENTO: order.payment_method,
-
VENDAID: order.id,
-
NOME: order.customer.name
-
}
-
-
4
html = "<form id='form_tef_#{order.id}' name='form_tef_#{order.id}' action='#{self.url_for(:generate_eft)}' method='post'>"
-
-
-
4
begin
-
4
unless eft.crypto.respond_to?(:encrypt)
-
2
params.each do |key, value|
-
10
html << "<input type='text' name='#{key}' value='#{value}' />"
-
end
-
else
-
2
params.delete("Id_Loja")
-
2
html << "<input type='text' name='Id_Loja' value='#{self.merchant_id}' />"
-
2
html << "<input type='text' name='crypt' value='#{eft.crypto.encrypt(self, params)}' />"
-
end
-
-
3
html << "</form><script type='text/javascript' charset='utf-8'>document.forms['form_tef_#{order.id}'].submit();</script>"
-
-
3
eft.code = html
-
3
status = true
-
3
message = 'OK'
-
rescue Exception => e
-
1
status = false
-
1
message = e.message
-
end
-
-
4
ActiveMerchant::Billing::Response.new(status,
-
message,
-
{},
-
:test => homologation?)
-
end
-
end
-
-
1
class EFT
-
1
include ::ActiveAttr::Model
-
-
1
class CryptoValidator < ActiveModel::EachValidator
-
1
def validate_each(record, attribute, value)
-
unless (
-
value.kind_of?(BraspagPagador::Crypto::NoCrypto) ||
-
4
value.respond_to?(:encrypt)
-
)
-
2
record.errors.add attribute, "invalid crypto"
-
end
-
end
-
end
-
-
1
attr_accessor :crypto, :code
-
-
1
validates :crypto, :presence => { :on => :generate }
-
1
validates :crypto, :crypto => { :on => :generate }
-
-
end
-
-
end
-
1
module BraspagPagador
-
1
class Connection
-
1
def save_credit_card(credit_card, customer, request_id)
-
response = self.soap_request(:save_credit_card, credit_card, customer, request_id)
-
end
-
# request the credit card info in Braspag PCI Compliant
-
1
def get_recurrency(credit_card)
-
-
end
-
-
1
def recurrency(order, credit_card, request_id)
-
-
end
-
end
-
end
-
1
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-
1
describe BraspagPagador::Converter do
-
1
describe ".decimal_to_string" do
-
1
it "should convert decimal to string with comma as decimal separator" do
-
1
BraspagPagador::Converter.decimal_to_string(10).should eq("10,00")
-
1
BraspagPagador::Converter.decimal_to_string(1).should eq("1,00")
-
1
BraspagPagador::Converter.decimal_to_string(0.1).should eq("0,10")
-
1
BraspagPagador::Converter.decimal_to_string(0.01).should eq("0,01")
-
1
BraspagPagador::Converter.decimal_to_string(9.99999).should eq("10,00") # round up
-
1
BraspagPagador::Converter.decimal_to_string(10.9).should eq("10,90")
-
1
BraspagPagador::Converter.decimal_to_string(9.1111).should eq("9,11")
-
1
BraspagPagador::Converter.decimal_to_string("10,00").should eq("10,00")
-
end
-
end
-
-
1
describe ".string_to_decimal" do
-
1
it "should string with comma as decimal separator to decimal" do
-
1
BraspagPagador::Converter.string_to_decimal("1000,00").should eq(1000.00)
-
1
BraspagPagador::Converter.string_to_decimal("1.000,00").should eq(1000.00)
-
1
BraspagPagador::Converter.string_to_decimal("10,00").should eq(10.00)
-
1
BraspagPagador::Converter.string_to_decimal("1,00").should eq(1.00)
-
1
BraspagPagador::Converter.string_to_decimal("0,10").should eq(0.1)
-
1
BraspagPagador::Converter.string_to_decimal("0,01").should eq(0.01)
-
1
BraspagPagador::Converter.string_to_decimal("9,99").should eq(9.99)
-
1
BraspagPagador::Converter.string_to_decimal("10,9").should eq(10.90)
-
1
BraspagPagador::Converter.string_to_decimal("9,1111").should eq(9.1111)
-
end
-
end
-
-
1
describe ".hash_from_xml" do
-
1
let(:document) do
-
3
<<-XML
-
<root>
-
<foo>blabla</foo>
-
<bar>bleble</bar>
-
<baz></baz>
-
</root>
-
XML
-
end
-
-
1
context "basic document and keys" do
-
1
it "should return a Hash" do
-
1
keys = { :foo => nil, :meu_elemento => "bar", :outro_elemento => "baz" }
-
1
expected = { :foo => "blabla", :meu_elemento => "bleble", :outro_elemento => nil }
-
-
1
BraspagPagador::Converter::hash_from_xml(document, keys).should == expected
-
end
-
-
1
it "should return a Hash with invalid key" do
-
1
keys = { :foo => "invalid", :meu_elemento => "bar", :outro_elemento => "baz" }
-
1
expected = { :foo => nil, :meu_elemento => "bleble", :outro_elemento => nil }
-
-
1
BraspagPagador::Converter::hash_from_xml(document, keys).should == expected
-
end
-
end
-
-
1
context "keys with a Proc" do
-
1
it "should return a Hash" do
-
2
proc = Proc.new { "value returned by Proc" }
-
-
1
keys = { :foo => proc, :meu_elemento => "bar", :outro_elemento => "baz" }
-
1
expected = { :foo => "value returned by Proc", :meu_elemento => "bleble", :outro_elemento => nil }
-
-
1
BraspagPagador::Converter::hash_from_xml(document, keys).should == expected
-
end
-
end
-
end
-
-
1
describe ".payment_method_name?" do
-
1
it "should return name from number" do
-
1
BraspagPagador::Converter.payment_method_name?(6).should eq(:billet_bradesco)
-
end
-
-
1
it "should return name from string" do
-
1
BraspagPagador::Converter.payment_method_name?("6").should eq(:billet_bradesco)
-
end
-
-
1
it "should return name from string with 0" do
-
1
BraspagPagador::Converter.payment_method_name?("06").should eq(:billet_bradesco)
-
end
-
-
1
it "should return nil when not found" do
-
1
BraspagPagador::Converter.payment_method_name?("AAA").should be(nil)
-
end
-
end
-
-
1
describe ".status_name?" do
-
1
it "should return name from number" do
-
1
BraspagPagador::Converter.status_name?(1).should eq(:starting)
-
end
-
-
1
it "should return name from string" do
-
1
BraspagPagador::Converter.status_name?("1").should eq(:starting)
-
end
-
-
1
it "should return name from string with 0" do
-
1
BraspagPagador::Converter.status_name?("01").should eq(:starting)
-
end
-
-
1
it "should return nil when not found" do
-
1
BraspagPagador::Converter.status_name?("AAA").should be(nil)
-
end
-
end
-
-
1
describe "payment_method_type?" do
-
1
it "should response nil when invalid method" do
-
1
BraspagPagador::Converter.payment_method_type?(999).should be(nil)
-
end
-
-
1
it "should response billet" do
-
1
BraspagPagador::Converter.payment_method_type?(6).should be(:billet)
-
end
-
-
1
it "should response eft" do
-
1
BraspagPagador::Converter.payment_method_type?(16).should be(:eft)
-
end
-
-
1
it "should response credit_card" do
-
1
BraspagPagador::Converter.payment_method_type?(997).should be(:credit_card)
-
end
-
end
-
end
-
1
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-
1
describe BraspagPagador::Customer do
-
1
[:purchase, :generate, :authorize, :archive, :recurrency ].each do |context_type|
-
5
context "on #{context_type}" do
-
5
it "should validate minimum 1 length of name" do
-
5
subject.name = ''
-
5
subject.valid?(context_type)
-
5
subject.errors.messages[:name].should include("is too short (minimum is 1 characters)")
-
end
-
-
5
it "should validate maximum 100 length of name" do
-
5
subject.name = '*' * 110
-
5
subject.valid?(context_type)
-
5
subject.errors.messages[:name].should include("is too long (maximum is 100 characters)")
-
end
-
-
5
it "should allow blank for email" do
-
5
subject.email = ''
-
5
subject.valid?(context_type)
-
5
subject.errors.messages[:email].should be(nil)
-
end
-
-
5
it "should validate maximum 255 length of email" do
-
5
subject.email = '*' * 260
-
5
subject.valid?(context_type)
-
5
subject.errors.messages[:email].should include("is too long (maximum is 255 characters)")
-
end
-
-
5
it "should allow blank for document" do
-
5
subject.document = ''
-
5
subject.valid?(context_type)
-
5
subject.errors.messages[:document].should be(nil)
-
end
-
-
5
it "should validate minimum 11 length of document" do
-
5
subject.document = 'XXX'
-
5
subject.valid?(context_type)
-
5
subject.errors.messages[:document].should include("is too short (minimum is 11 characters)")
-
end
-
-
5
it "should validate maximum 18 length of document" do
-
5
subject.document = '*' * 20
-
5
subject.valid?(context_type)
-
5
subject.errors.messages[:document].should include("is too long (maximum is 18 characters)")
-
end
-
end
-
end
-
end
-
# encoding: utf-8
-
1
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-
1
describe BraspagPagador::Connection do
-
7
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
7
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
7
let(:order) { BraspagPagador::Order.new(:id => "XPTO") }
-
-
1
describe ".get" do
-
1
context "when error" do
-
1
it "should return message for response blank" do
-
1
connection.stub(:post).and_return({})
-
1
response = connection.get(order)
-
-
1
response.success?.should eq(false)
-
1
response.message.should eq('')
-
1
response.params.should eq({})
-
1
response.test.should eq(true)
-
end
-
-
1
it "should return message for error code" do
-
1
order_response = {:error_code => 'bla', :error_message => 'xpto', :status => '223'}
-
1
connection.stub(:post).and_return(order_response)
-
1
response = connection.get(order)
-
-
1
response.success?.should eq(false)
-
1
response.message.should eq(order_response[:error_message])
-
1
response.params.should eq({"error_code"=>"bla", "error_message"=>"xpto", "status" => '223'})
-
1
response.test.should eq(true)
-
end
-
-
1
it "should return message for empty status" do
-
1
connection.stub(:post).and_return({:error_message => 'bla'})
-
1
response = connection.get(order)
-
-
1
response.success?.should eq(false)
-
1
response.message.should eq('bla')
-
1
response.params.should eq({"error_message"=>"bla"})
-
1
response.test.should eq(true)
-
end
-
end
-
-
1
it "should return response ok" do
-
1
connection.stub(:post).and_return({:status => '1'})
-
1
response = connection.get(order)
-
-
1
response.success?.should eq(true)
-
1
response.message.should eq('OK')
-
1
response.params.should eq({"status" => "1"})
-
1
response.test.should eq(true)
-
end
-
-
1
it "should get more info for billet" do
-
1
connection.should_receive(:post).and_return({:status => '1'})
-
1
connection.should_receive(:post).with(:info_billet, order)
-
1
order.payment_method = 6 #BILLET BRADESCO
-
1
response = connection.get(order)
-
-
1
response.success?.should eq(true)
-
1
response.message.should eq('OK')
-
1
response.params.should eq({"status" => "1"})
-
1
response.test.should eq(true)
-
end
-
-
1
it "should get more info for credit_card" do
-
1
connection.should_receive(:post).and_return({:status => '1'})
-
1
connection.should_receive(:post).with(:info_credit_card, order)
-
1
order.payment_method = 18 #AMEX
-
1
response = connection.get(order)
-
-
1
response.success?.should eq(true)
-
1
response.message.should eq('OK')
-
1
response.params.should eq({"status" => "1"})
-
1
response.test.should eq(true)
-
end
-
end
-
end
-
-
1
describe BraspagPagador::Order do
-
10
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
10
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
-
1
describe ".payment_method_type?" do
-
1
it "should return payment method type" do
-
1
order = subject
-
1
order.payment_method = 6
-
1
order.payment_method_type?.should eq(:billet)
-
end
-
end
-
-
1
context "on info" do
-
1
let(:valid_xml) do
-
1
<<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xmlns="http://www.pagador.com.br/">
-
<CodigoAutorizacao>885796</CodigoAutorizacao>
-
<CodigoPagamento>18</CodigoPagamento>
-
<FormaPagamento>American Express 2P</FormaPagamento>
-
<NumeroParcelas>1</NumeroParcelas>
-
<Status>3</Status>
-
<Valor>0.01</Valor>
-
<DataCancelamento>7/8/2011 1:19:38 PM</DataCancelamento>
-
<DataPagamento>7/8/2011 1:19:38 PM</DataPagamento>
-
<DataPedido>7/8/2011 1:06:06 PM</DataPedido>
-
<TransId>398591</TransId>
-
<BraspagTid>5a1d4463-1d11-4571-a877-763aba0ef7ff</BraspagTid>
-
</DadosPedido>
-
EOXML
-
end
-
-
1
let(:invalid_xml) do
-
1
<<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xsi:nil="true"
-
xmlns="http://www.pagador.com.br/" />
-
EOXML
-
end
-
-
1
let(:error_xml) do
-
1
<<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xmlns="http://www.pagador.com.br/">
-
<CodigoErro>885796</CodigoErro>
-
<MensagemErro>Deu um erro terrivel</MensagemErro>
-
</DadosPedido>
-
EOXML
-
end
-
-
5
let(:order) { BraspagPagador::Order.new(:id => "XPTO") }
-
-
1
it "should convert objects to hash" do
-
1
BraspagPagador::Order.to_info(connection, order).should eq({
-
"loja" => "#{merchant_id}",
-
"numeroPedido" => "#{order.id}"
-
})
-
end
-
-
1
it "should populate data" do
-
1
resp = BraspagPagador::Order.from_info(connection, order, mock(:body => valid_xml))
-
-
1
order.authorization.should eq('885796')
-
1
order.payment_method_name.should eq('American Express 2P')
-
1
order.payment_method.should eq('18')
-
1
order.installments.should eq('1')
-
1
order.status.should eq('3')
-
1
order.amount.should eq(0.01)
-
1
order.gateway_cancelled_at.should eq(Time.parse('2011-08-07 13:19:38'))
-
1
order.gateway_paid_at.should eq(Time.parse('2011-08-07 13:19:38'))
-
1
order.gateway_created_at.should eq(Time.parse('2011-08-07 13:06:06'))
-
1
order.transaction_id.should eq('398591')
-
1
order.gateway_id.should eq('5a1d4463-1d11-4571-a877-763aba0ef7ff')
-
-
1
resp.should eq({
-
:authorization => "885796",
-
:error_code => nil,
-
:error_message => nil,
-
:payment_method => "18",
-
:payment_method_name => "American Express 2P",
-
:installments => "1",
-
:status => "3",
-
:amount => "0.01",
-
:cancelled_at => Time.parse('2011-08-07 13:19:38'),
-
:paid_at => Time.parse('2011-08-07 13:19:38'),
-
:order_date => Time.parse('2011-08-07 13:06:06'),
-
:transaction_id => "398591",
-
:tid => "5a1d4463-1d11-4571-a877-763aba0ef7ff"
-
})
-
end
-
-
1
it "should populate data accepts invalid xml" do
-
1
resp = BraspagPagador::Order.from_info(connection, order, mock(:body => invalid_xml))
-
-
1
resp.should eq({
-
:authorization => nil,
-
:error_code => nil,
-
:error_message => nil,
-
:payment_method => nil,
-
:payment_method_name => nil,
-
:installments => nil,
-
:status => nil,
-
:amount => nil,
-
:cancelled_at => nil,
-
:paid_at => nil,
-
:order_date => nil,
-
:transaction_id => nil,
-
:tid => nil
-
})
-
end
-
-
1
it "should populate data for error" do
-
1
resp = BraspagPagador::Order.from_info(connection, order, mock(:body => error_xml))
-
-
1
resp.should eq({
-
:authorization => nil,
-
:error_code => "885796",
-
:error_message => "Deu um erro terrivel",
-
:payment_method => nil,
-
:payment_method_name => nil,
-
:installments => nil,
-
:status => nil,
-
:amount => nil,
-
:cancelled_at => nil,
-
:paid_at => nil,
-
:order_date => nil,
-
:transaction_id => nil,
-
:tid => nil
-
})
-
end
-
end
-
-
1
context "on info for billet" do
-
1
let(:valid_xml) do
-
1
<<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xmlns="http://www.pagador.com.br/">
-
<NumeroDocumento>999</NumeroDocumento>
-
<Sacado>XPTO</Sacado>
-
<NossoNumero>999</NossoNumero>
-
<LinhaDigitavel>35690.00361 03962.070003 00000.009993 4 50160000001000</LinhaDigitavel>
-
<DataDocumento>22/6/2011</DataDocumento>
-
<DataVencimento>2/7/2011</DataVencimento>
-
<DataCredito>2/7/2011</DataCredito>
-
<Cedente>Acessoria Empresarial Ltda</Cedente>
-
<Banco>356-5</Banco>
-
<Agencia>0003</Agencia>
-
<Conta>6039620</Conta>
-
<Carteira>57</Carteira>
-
<ValorDocumento>10,00</ValorDocumento>
-
<ValorPago>10,00</ValorPago>
-
</DadosBoleto>
-
EOXML
-
end
-
-
1
let(:invalid_xml) do
-
1
<<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xmlns="http://www.pagador.com.br/">
-
</DadosBoleto>
-
EOXML
-
end
-
-
4
let(:order) { BraspagPagador::Order.new(:id => "XPTO") }
-
-
1
it "should convert objects to hash" do
-
1
BraspagPagador::Order.to_info_billet(connection, order).should eq({
-
"loja" => "#{merchant_id}",
-
"numeroPedido" => "#{order.id}"
-
})
-
end
-
-
1
it "should populate data" do
-
1
resp = BraspagPagador::Order.from_info_billet(connection, order, mock(:body => valid_xml))
-
-
1
order.customer.name.should eq('XPTO')
-
-
1
order.billet.id.should eq('999')
-
1
order.billet.code.should eq('35690.00361 03962.070003 00000.009993 4 50160000001000')
-
-
1
order.billet.created_at.should eq(Date.parse('2011-06-22'))
-
1
order.billet.due_date_on.should eq(Date.parse('2011-07-2'))
-
-
1
order.billet.receiver.should eq('Acessoria Empresarial Ltda')
-
-
1
order.billet.bank.should eq('356-5')
-
1
order.billet.agency.should eq('0003')
-
1
order.billet.account.should eq('6039620')
-
1
order.billet.wallet.should eq('57')
-
1
order.billet.amount.should eq(10.00)
-
1
order.billet.amount_paid.should eq(10.00)
-
1
order.billet.paid_at.should eq(Date.parse('2011-07-02'))
-
-
1
resp.should eq({
-
:document_number=>"999",
-
:payer=>"XPTO",
-
:our_number=>"999",
-
:bill_line=>"35690.00361 03962.070003 00000.009993 4 50160000001000",
-
:document_date=>Date.parse('2011-06-22'),
-
:expiration_date=>Date.parse('2011-07-2'),
-
:receiver=>"Acessoria Empresarial Ltda",
-
:bank=>"356-5",
-
:agency=>"0003",
-
:account=>"6039620",
-
:wallet=>"57",
-
:amount=>"10,00",
-
:amount_invoice=>"10,00",
-
:invoice_date=> Date.parse('2011-07-02')
-
})
-
end
-
-
1
it "should not raise error for invalid xml" do
-
1
resp = BraspagPagador::Order.from_info_billet(connection, order, mock(:body => invalid_xml))
-
-
1
resp.should eq({
-
:document_number => nil,
-
:payer => nil,
-
:our_number => nil,
-
:bill_line => nil,
-
:document_date => nil,
-
:expiration_date => nil,
-
:receiver => nil,
-
:bank=> nil,
-
:agency=> nil,
-
:account=> nil,
-
:wallet=> nil,
-
:amount=> nil,
-
:amount_invoice=> nil,
-
:invoice_date=> nil
-
})
-
end
-
end
-
-
1
context "on info for credit card" do
-
1
let(:valid_xml) do
-
1
<<-EOXML
-
<DadosCartao xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xmlns="http://www.pagador.com.br/">
-
<RetornoAVS>12</RetornoAVS>
-
<Emissor>VISA</Emissor>
-
<NumeroAutenticacao>12345</NumeroAutenticacao>
-
<NumeroComprovante>11111</NumeroComprovante>
-
<Autenticada>false</Autenticada>
-
<NumeroAutorizacao>557593</NumeroAutorizacao>
-
<NumeroCartao>345678*****0007</NumeroCartao>
-
<NumeroTransacao>101001225645</NumeroTransacao>
-
</DadosCartao>
-
EOXML
-
end
-
-
3
let(:order) { BraspagPagador::Order.new(:id => "XPTO") }
-
-
1
it "should convert objects to hash" do
-
1
BraspagPagador::Order.to_info_credit_card(connection, order).should eq({
-
"loja" => "#{merchant_id}",
-
"numeroPedido" => "#{order.id}"
-
})
-
end
-
-
1
it "should populate data" do
-
1
resp = BraspagPagador::Order.from_info_credit_card(connection, order, mock(:body => valid_xml))
-
-
1
order.credit_card.checking_number.should eq('11111')
-
1
order.credit_card.avs.should eq('false')
-
1
order.credit_card.autorization_number.should eq('557593')
-
1
order.credit_card.number.should eq('345678*****0007')
-
1
order.credit_card.transaction_number.should eq('101001225645')
-
1
order.credit_card.avs_response.should eq('12')
-
1
order.credit_card.issuing.should eq('VISA')
-
1
order.credit_card.authenticated_number.should eq('12345')
-
-
1
resp.should eq({
-
:checking_number => "11111",
-
:certified => "false",
-
:autorization_number => "557593",
-
:card_number => "345678*****0007",
-
:transaction_number => "101001225645",
-
:avs_response => "12",
-
:issuing => "VISA",
-
:authenticated_number => "12345"
-
})
-
end
-
end
-
-
1
[:purchase, :generate, :authorize, :capture, :void, :recurrency].each do |context_type|
-
6
context "on #{context_type}" do
-
6
it "should validate minimum 1 length of id" do
-
6
subject.id = ''
-
6
subject.valid?(context_type)
-
6
subject.errors.messages[:id].should include("is too short (minimum is 1 characters)")
-
end
-
-
6
it "should validate maximum 20 length of id" do
-
6
subject.id = '*' * 25
-
6
subject.valid?(context_type)
-
6
subject.errors.messages[:id].should include("is too long (maximum is 20 characters)")
-
end
-
-
6
it "should allow characters without payment_method" do
-
6
subject.id = '*13*'
-
6
subject.valid?(context_type)
-
6
subject.errors.messages[:id].should eq(nil)
-
end
-
-
6
[:cielo_noauth_visa, :cielo_preauth_visa, :cielo_noauth_mastercard, :cielo_preauth_mastercard, :cielo_noauth_elo, :cielo_noauth_diners ].each do |payment_method|
-
36
context "when has payment method for #{payment_method}" do
-
36
it "should not allow spaces" do
-
36
subject.payment_method = BraspagPagador::PAYMENT_METHOD[payment_method]
-
36
subject.id = '123 4'
-
36
subject.valid?(context_type)
-
36
subject.errors.messages[:id].should include("is invalid")
-
end
-
36
it "should not allow characters" do
-
36
subject.payment_method = BraspagPagador::PAYMENT_METHOD[payment_method]
-
36
subject.id = 'abcd'
-
36
subject.valid?(context_type)
-
36
subject.errors.messages[:id].should include("is invalid")
-
end
-
-
36
it "should not allow special characters" do
-
36
subject.payment_method = BraspagPagador::PAYMENT_METHOD[payment_method]
-
36
subject.id = '*-[]'
-
36
subject.valid?(context_type)
-
36
subject.errors.messages[:id].should include("is invalid")
-
end
-
end
-
end
-
end
-
end
-
-
1
[:purchase, :generate, :authorize, :recurrency].each do |context_type|
-
4
context "on #{context_type}" do
-
4
it "should not allow blank for payment_method" do
-
4
subject.payment_method = ''
-
4
subject.valid?(context_type)
-
4
subject.errors.messages[:payment_method].should include("can't be blank")
-
end
-
-
4
it "should not allow blank for amount" do
-
4
subject.amount = ''
-
4
subject.valid?(context_type)
-
4
subject.errors.messages[:amount].should include("can't be blank")
-
end
-
-
4
it "should validate minimum 1 of amount" do
-
4
subject.amount = 0
-
4
subject.valid?(context_type)
-
4
subject.errors.messages[:amount].should include("must be greater than 0")
-
end
-
-
4
it "should not allow blank for customer" do
-
4
subject.customer = ''
-
4
subject.valid?(context_type)
-
4
subject.errors.messages[:customer].should include("can't be blank")
-
end
-
-
4
it "should not allow invalid customer" do
-
4
subject.customer = BraspagPagador::Customer.new
-
4
subject.valid?(context_type)
-
4
subject.errors.messages[:customer].should include("invalid data")
-
end
-
-
4
it "should accept only valid payment method" do
-
4
subject.payment_method = 0
-
4
subject.valid?(context_type)
-
4
subject.errors.messages[:payment_method].should include("invalid payment code")
-
end
-
end
-
end
-
-
1
[:purchase, :authorize, :recurrency].each do |context_type|
-
3
context "on #{context_type}" do
-
3
it "should not allow blank for installments" do
-
3
subject.installments = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:installments].should include("can't be blank")
-
end
-
-
3
it "should validate minimum 1 of installments" do
-
3
subject.installments = 0
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:installments].should include("must be greater than 0")
-
end
-
-
-
3
it "should validate maxium 99 of installments" do
-
3
subject.installments = 100
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:installments].should include("must be less than 100")
-
end
-
-
3
it "should not allow blank for installments_type" do
-
3
subject.installments_type = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:installments_type].should include("can't be blank")
-
end
-
-
3
it "should accept only valid installments_type" do
-
3
subject.installments_type = 100
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:installments_type].should include("invalid installments type")
-
end
-
-
-
3
context "when installments_type is NO_INTEREST" do
-
3
it "should installments is one" do
-
3
subject.installments_type = BraspagPagador::INTEREST[:no]
-
3
subject.installments = 3
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:installments].should include("is invalid")
-
end
-
end
-
end
-
end
-
end
-
1
require 'spec_helper'
-
1
require 'ostruct'
-
-
1
describe BraspagPagador::Poster do
-
7
let(:request) { OpenStruct.new(:url => 'http://foo/bar') }
-
7
let(:response) { mock(:body => 'success') }
-
4
let(:logger) { mock(:info => nil) }
-
7
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
3
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
4
let(:connection_logger) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation, :logger => logger)}
-
2
let(:connection_proxy) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation, :proxy_address => 'http://proxy.com')}
-
-
1
describe "#do_post" do
-
1
before do
-
6
::HTTPI::Request.should_receive(:new).with('http://foo/bar').and_return(request)
-
6
::HTTPI.should_receive(:post).with(request).and_return(response)
-
end
-
-
1
context "without proxy and logger" do
-
3
subject { described_class.new(connection, 'http://foo/bar') }
-
-
1
it "should not set the proxy if the proxy_address is not set" do
-
1
request.should_not_receive(:proxy=)
-
1
subject.do_post(:foo, {})
-
end
-
-
1
it "should not raise an error if logger is not defined" do
-
1
expect {
-
1
subject.do_post(:doe, { :foo => :bar, :egg => :span })
-
}.to_not raise_error
-
end
-
-
end
-
-
1
context "with logger" do
-
4
subject { described_class.new(connection_logger, 'http://foo/bar') }
-
-
1
it "should log the request info" do
-
1
logger.should_receive(:info).with('[Braspag] #doe: http://foo/bar, data: {:foo=>:bar, :egg=>:span}')
-
1
subject.do_post(:doe, { :foo => :bar, :egg => :span })
-
end
-
-
1
it "should log the request info removing the credit card sensitive info" do
-
1
logger.should_receive(:info).with('[Braspag] #doe: http://foo/bar, data: {"cardNumber"=>"************", "securityCode"=>"***"}')
-
1
subject.do_post(:doe, { 'cardNumber' => '123', 'securityCode' => '456' })
-
end
-
-
1
it "should log response info" do
-
1
logger.should_receive(:info).with('[Braspag] #doe: http://foo/bar, data: {:foo=>:bar, :egg=>:span}')
-
1
subject.do_post(:doe, { :foo => :bar, :egg => :span })
-
end
-
end
-
-
1
context "with proxy" do
-
2
subject { described_class.new(connection_proxy, 'http://foo/bar') }
-
-
1
it "should set the proxy if the proxy_address is set" do
-
1
request.should_receive(:proxy=).with('http://proxy.com')
-
1
subject.do_post(:foo, {})
-
end
-
end
-
end
-
end
-
#encoding: utf-8
-
1
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-
1
describe BraspagPagador::Crypto::Webservice do
-
-
8
let(:merchant_id) { "merchant_id" }
-
1
let(:connection) do
-
7
conn = double(BraspagPagador::Connection)
-
7
conn.stub(:merchant_id => merchant_id)
-
7
conn.stub(:url_for => 'fakeurl')
-
7
conn
-
end
-
-
8
let(:poster) { mock }
-
-
1
describe "encrypt" do
-
5
let(:key) {"XXXXX"}
-
-
1
it "should return error with invalid data after process" do
-
1
body_invalid = <<-EOXML
-
SERVER was unable to process
-
EOXML
-
1
poster.stub(:do_post => mock(:body => body_invalid))
-
1
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
-
-
1
expect {
-
1
BraspagPagador::Crypto::Webservice.new.encrypt(connection, {key: key})
-
}.to raise_error(RuntimeError, 'UnknownError')
-
end
-
-
1
it "should return error with invalid merchant_id" do
-
1
body_invalid = <<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-
<soap:Body><EncryptRequestResponse xmlns="https://www.pagador.com.br/webservice/BraspagGeneralService">
-
<EncryptRequestResult>Erro BP 011</EncryptRequestResult></EncryptRequestResponse>
-
</soap:Body></soap:Envelope>
-
EOXML
-
-
1
poster.stub(:do_post => mock(:body => body_invalid))
-
1
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
-
-
1
expect {
-
1
BraspagPagador::Crypto::Webservice.new.encrypt(connection, {key: key})
-
}.to raise_error(RuntimeError, 'InvalidMerchantId')
-
end
-
-
1
it "should return error with invalid ip" do
-
1
body_invalid = <<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-
<soap:Body><EncryptRequestResponse xmlns="https://www.pagador.com.br/webservice/BraspagGeneralService">
-
<EncryptRequestResult>Erro BP 067</EncryptRequestResult></EncryptRequestResponse>
-
</soap:Body></soap:Envelope>
-
EOXML
-
1
poster.stub(:do_post => mock(:body => body_invalid))
-
1
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
-
-
1
expect {
-
1
BraspagPagador::Crypto::Webservice.new.encrypt(connection, {key: key})
-
}.to raise_error(RuntimeError, 'InvalidIP')
-
-
end
-
-
1
it "should return a string" do
-
1
valid_body = <<-EOXML
-
<?xml version='1.0' encoding='utf-8'?>
-
<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
-
<soap:Body>
-
<EncryptRequestResponse xmlns='https://www.pagador.com.br/webservice/BraspagGeneralService'>
-
<EncryptRequestResult>#{key}</EncryptRequestResult>
-
</EncryptRequestResponse>
-
</soap:Body></soap:Envelope>
-
EOXML
-
-
1
poster.stub(:do_post => mock(:body => valid_body))
-
1
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
-
-
1
resp = BraspagPagador::Crypto::Webservice.new.encrypt(connection, {key: key})
-
1
resp.should eq(key)
-
end
-
end
-
-
1
describe "decrypt" do
-
4
let(:crypt_string) {"{sdfsdf34543534}"}
-
1
it "should return error with invalid data" do
-
1
body_invalid = <<-EOXML
-
SERVER was unable to process
-
EOXML
-
1
poster.stub(:do_post => mock(:body => body_invalid))
-
1
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
-
-
1
expect {
-
1
BraspagPagador::Crypto::Webservice.new.decrypt(connection, crypt_string)
-
}.to raise_error(RuntimeError, 'UnknownError')
-
-
end
-
-
1
it "should return error with invalid ip" do
-
1
body_invalid = <<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-
<soap:Body><DecryptRequestResponse xmlns="https://www.pagador.com.br/webservice/BraspagGeneralService">
-
<DecryptRequestResult><string>Erro BP 068</string></DecryptRequestResult>
-
</DecryptRequestResponse></soap:Body></soap:Envelope>
-
EOXML
-
1
poster.stub(:do_post => mock(:body => body_invalid))
-
1
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
-
-
1
expect {
-
1
BraspagPagador::Crypto::Webservice.new.decrypt(connection, crypt_string)
-
}.to raise_error(RuntimeError, 'InvalidIP')
-
end
-
-
1
it "should return a string" do
-
1
valid_body = <<-EOXML
-
<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
-
<soap:Body><DecryptRequestResponse xmlns='https://www.pagador.com.br/webservice/BraspagGeneralService'>
-
<DecryptRequestResult>
-
<string>CODPAGAMENTO=18</string>
-
<string>VENDAID=teste123</string>
-
<string>VALOR=100</string>
-
<string>PARCELAS=1</string>
-
<string>NOME=comprador</string>
-
</DecryptRequestResult></DecryptRequestResponse>
-
</soap:Body></soap:Envelope>
-
EOXML
-
-
1
poster.stub(:do_post => mock(:body => valid_body))
-
1
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
-
-
1
resp = BraspagPagador::Crypto::Webservice.new.decrypt(connection, crypt_string)
-
1
resp.should eq({:codpagamento=>"18", :vendaid=>"teste123", :valor=>"100", :parcelas=>"1", :nome=>"comprador"})
-
end
-
end
-
end
-
# encoding: utf-8
-
1
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-
1
describe BraspagPagador::Connection do
-
1
it "should generate a billet", :billet_integration => true do
-
gateway = BraspagPagador::Connection.new(
-
:merchant_id => ENV['BRASPAG_MERCHANT_ID'],
-
:environment => :homologation
-
)
-
-
billet = BraspagPagador::Billet.new(
-
:instructions => 'does not accepted after due date', # (optional)
-
:due_date_on => Date.today + 2
-
)
-
-
customer = BraspagPagador::Customer.new(
-
:document => '21473696240', # (OPTIONAL)
-
:name => 'Bob Dela Bobsen',
-
:email => 'bob@mailinator.com' # send email to consumer (OPTIONAL)
-
)
-
-
order = BraspagPagador::Order.new(
-
:payment_method => BraspagPagador::PAYMENT_METHOD[:billet_santader],
-
:id => 11,
-
:amount => 10.00, # $10.00 (accepts all amounts as Integer values in cents)
-
:customer => customer
-
)
-
-
# Validating the card automatically detects the card type
-
if billet.valid?(:generate) && customer.valid?(:generate) && order.valid?(:generate)
-
response = gateway.generate_billet(order, billet)
-
response.success?.should eq(true)
-
puts "Successfully created billet, open in:#{billet.url}"
-
else
-
fail "Invalid Params"
-
end
-
end
-
end
-
# encoding: utf-8
-
1
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-
1
describe BraspagPagador::Connection do
-
3
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
3
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
-
1
context ".generate_billet" do
-
1
it "should return response" do
-
1
generate_billet = {
-
:status => "1",
-
:message => "BLA",
-
:number => "12345"
-
}
-
-
1
connection.should_receive(:post).and_return(generate_billet)
-
-
1
response = connection.generate_billet(mock, mock)
-
-
1
response.success?.should eq(false)
-
1
response.message.should eq(generate_billet[:message])
-
1
response.authorization.should eq(generate_billet[:number])
-
1
response.params.should eq({"status"=>"1", "message"=>"BLA", "number"=>"12345"})
-
1
response.test.should eq(true)
-
end
-
-
1
it "should return success when status is zero" do
-
1
generate_billet = {
-
:status => "0",
-
:message => "BLA",
-
:number => "12345"
-
}
-
-
1
connection.should_receive(:post).and_return(generate_billet)
-
-
1
response = connection.generate_billet(mock, mock)
-
-
1
response.success?.should eq(true)
-
end
-
end
-
end
-
-
1
describe BraspagPagador::Billet do
-
1
context "on generate" do
-
1
it "should allow blank for id" do
-
1
subject.id = ''
-
1
subject.valid?(:generate)
-
1
subject.errors.messages[:id].should be(nil)
-
end
-
-
1
it "should validate maximum 255 length of id" do
-
1
subject.id = '*' * 260
-
1
subject.valid?(:generate)
-
1
subject.errors.messages[:id].should include("is too long (maximum is 255 characters)")
-
end
-
-
1
it "should allow blank for instructions" do
-
1
subject.instructions = ''
-
1
subject.valid?(:generate)
-
1
subject.errors.messages[:instructions].should be(nil)
-
end
-
-
1
it "should validate maximum 512 length of instructions" do
-
1
subject.instructions = '*' * 520
-
1
subject.valid?(:generate)
-
1
subject.errors.messages[:instructions].should include("is too long (maximum is 512 characters)")
-
end
-
-
1
it "should not allow blank for due_date_on" do
-
1
subject.due_date_on = ''
-
1
subject.valid?(:generate)
-
1
subject.errors.messages[:due_date_on].should include("can't be blank")
-
end
-
-
1
it "should not allow invalid date for due_date_on" do
-
1
subject.due_date_on = '12345'
-
1
subject.valid?(:generate)
-
1
subject.errors.messages[:due_date_on].should include("invalid date")
-
end
-
-
1
it "should allow date for due_date_on" do
-
1
subject.due_date_on = Date.parse('07/03/1988')
-
1
subject.valid?(:generate)
-
1
subject.errors.messages[:due_date_on].should be(nil)
-
end
-
end
-
-
1
context "on generate billet" do
-
4
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
4
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
-
1
let(:customer) do
-
3
BraspagPagador::Customer.new(
-
:document => '21473696240', # (OPTIONAL)
-
:name => 'Bob Dela Bobsen',
-
:email => 'bob@mailinator.com' # send email to consumer (OPTIONAL)
-
)
-
end
-
-
1
let(:order) do
-
3
BraspagPagador::Order.new(
-
:id => "um order id",
-
:amount => 100.00,
-
:payment_method => BraspagPagador::PAYMENT_METHOD[:billet_bradesco],
-
:customer => customer
-
)
-
end
-
-
1
let(:billet) do
-
3
BraspagPagador::Billet.new(
-
:id => '123456',
-
:instructions => 'does not accepted after due date',
-
:due_date_on => Date.parse('2012-01-01')
-
)
-
end
-
-
2
let(:url) { "https://homologacao.pagador.com.br/pagador/reenvia.asp?Id_Transacao=722934be-6756-477a-87ab-42115ee1424d" }
-
-
1
let(:valid_xml) do
-
1
<<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<PagadorBoletoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xmlns="https://www.pagador.com.br/webservice/pagador">
-
<amount>3.00</amount>
-
<boletoNumber>123123</boletoNumber>
-
<expirationDate>2012-01-08T00:00:00</expirationDate>
-
<url>https://homologacao.pagador.com.br/pagador/reenvia.asp?Id_Transacao=722934be-6756-477a-87ab-42115ee1424d</url>
-
<returnCode>0</returnCode>
-
<status>0</status>
-
</PagadorBoletoReturn>
-
EOXML
-
end
-
-
1
let(:invalid_xml) do
-
1
<<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<PagadorBoletoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xmlns="https://www.pagador.com.br/webservice/pagador">
-
<amount xsi:nil="true" />
-
<expirationDate xsi:nil="true" />
-
<returnCode>1</returnCode>
-
<message>Invalid merchantId</message>
-
<status xsi:nil="true" />
-
</PagadorBoletoReturn>
-
EOXML
-
end
-
-
1
it "should convert objects to hash" do
-
1
BraspagPagador::Billet.to_generate_billet(connection, order, billet).should eq({
-
"merchantId" => connection.merchant_id,
-
"boletoNumber" => billet.id.to_s,
-
"instructions" => billet.instructions.to_s,
-
"expirationDate" => billet.due_date_on.strftime("%d/%m/%y"),
-
"customerName" => order.customer.name.to_s,
-
"customerIdNumber" => order.customer.document.to_s,
-
"emails" => order.customer.email.to_s,
-
"orderId" => order.id.to_s,
-
"amount" => BraspagPagador::Converter::decimal_to_string(order.amount),
-
"paymentMethod" => order.payment_method
-
})
-
end
-
-
-
1
it "should convert response from xml" do
-
1
resp = BraspagPagador::Billet.from_generate_billet(connection, order, billet, mock(:body => valid_xml))
-
-
1
billet.url.should eq(url)
-
1
order.gateway_return_code.should eq('0')
-
1
order.gateway_status.should eq('0')
-
1
order.gateway_amount.should eq(3.00)
-
-
1
resp.should eq({
-
:url => url,
-
:amount => "3.00",
-
:number => "123123",
-
:expiration_date => Date.parse('2012-01-08'),
-
:return_code => "0",
-
:status => "0",
-
:message => nil
-
})
-
end
-
-
1
it "should convert response from xml with invalid date" do
-
1
resp = BraspagPagador::Billet.from_generate_billet(connection, order, billet, mock(:body => invalid_xml))
-
-
1
billet.url.should eq(nil)
-
1
order.gateway_return_code.should eq('1')
-
1
order.gateway_status.should eq(nil)
-
1
order.gateway_amount.should eq(nil)
-
-
1
resp.should eq({
-
:url => nil,
-
:amount => nil,
-
:number => nil,
-
:expiration_date => nil,
-
:return_code => "1",
-
:status => nil,
-
:message => "Invalid merchantId"
-
})
-
end
-
end
-
end
-
-
1
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-
1
describe BraspagPagador::Connection do
-
10
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
10
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
-
1
context ".purchase" do
-
1
it "should return authorize when authroize response failed" do
-
1
auth = mock(:success? => false)
-
1
connection.stub(:authorize).and_return(auth)
-
1
connection.purchase(mock, mock).should eq(auth)
-
end
-
-
1
it "should return capture when authorize response success" do
-
1
cap = mock(:success? => true)
-
1
connection.stub(:authorize).and_return(mock(:success? => true))
-
1
connection.stub(:capture).and_return(cap)
-
1
connection.purchase(mock, mock).should eq(cap)
-
end
-
end
-
-
1
context ".authorize" do
-
1
it "should return response" do
-
1
authorize = {
-
:status => "2",
-
:message => "BLA",
-
:number => "12345"
-
}
-
-
1
connection.should_receive(:post).and_return(authorize)
-
-
1
response = connection.authorize(mock, mock)
-
-
1
response.success?.should eq(false)
-
1
response.message.should eq(authorize[:message])
-
1
response.authorization.should eq(authorize[:number])
-
1
response.params.should eq({"status"=>"2", "message"=>"BLA", "number"=>"12345"})
-
1
response.test.should eq(true)
-
end
-
-
1
it "should return success when status is zero" do
-
1
authorize = {
-
:status => "0",
-
:message => "BLA",
-
:number => "12345"
-
}
-
-
1
connection.should_receive(:post).and_return(authorize)
-
-
1
response = connection.authorize(mock, mock)
-
-
1
response.success?.should eq(true)
-
end
-
-
1
it "should return success when status is one" do
-
1
authorize = {
-
:status => "1",
-
:message => "BLA",
-
:number => "12345"
-
}
-
-
1
connection.should_receive(:post).and_return(authorize)
-
-
1
response = connection.authorize(mock, mock)
-
-
1
response.success?.should eq(true)
-
end
-
end
-
-
1
context ".capture" do
-
1
it "should return response" do
-
1
capture = {
-
:status => "1",
-
:message => "BLA",
-
:number => "12345"
-
}
-
-
1
connection.should_receive(:post).and_return(capture)
-
-
1
response = connection.capture(mock)
-
-
1
response.success?.should eq(false)
-
1
response.message.should eq(capture[:message])
-
1
response.authorization.should eq(capture[:number])
-
1
response.params.should eq({"status"=>"1", "message"=>"BLA", "number"=>"12345"})
-
1
response.test.should eq(true)
-
end
-
-
1
it "should return success when status is zero" do
-
1
capture = {
-
:status => "0",
-
:message => "BLA",
-
:number => "12345"
-
}
-
-
1
connection.should_receive(:post).and_return(capture)
-
-
1
response = connection.capture(mock)
-
-
1
response.success?.should eq(true)
-
end
-
end
-
-
1
context ".void" do
-
1
it "should return response" do
-
1
void = {
-
:status => "1",
-
:message => "BLA"
-
}
-
-
1
connection.should_receive(:post).and_return(void)
-
-
1
response = connection.void(mock)
-
-
1
response.success?.should eq(false)
-
1
response.message.should eq(void[:message])
-
1
response.params.should eq({"status"=>"1", "message"=>"BLA"})
-
1
response.test.should eq(true)
-
end
-
-
1
it "should return success when status is zero" do
-
1
void = {
-
:status => "0",
-
:message => "BLA"
-
}
-
-
1
connection.should_receive(:post).and_return(void)
-
-
1
response = connection.void(mock)
-
-
1
response.success?.should eq(true)
-
end
-
end
-
end
-
-
1
describe BraspagPagador::CreditCard do
-
-
1
[:purchase, :authorize, :archive].each do |context_type|
-
3
context "on #{context_type}" do
-
3
it "should validate minimum 1 length of holder_name" do
-
3
subject.holder_name = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:holder_name].should include("is too short (minimum is 1 characters)")
-
end
-
-
3
it "should validate maximum 100 length of holder_name" do
-
3
subject.holder_name = '*' * 110
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:holder_name].should include("is too long (maximum is 100 characters)")
-
end
-
-
3
it "should not allow blank for number" do
-
3
subject.number = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:number].should include("can't be blank")
-
end
-
-
3
it "should not allow blank for month" do
-
3
subject.month = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:month].should include("can't be blank")
-
end
-
-
3
it "should not allow blank for year" do
-
3
subject.year = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:year].should include("can't be blank")
-
end
-
-
3
it "should not allow invalid date for month & year" do
-
3
subject.month = "14"
-
3
subject.year = "2012"
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:month].should include("invalid date")
-
3
subject.errors.messages[:year].should include("invalid date")
-
end
-
-
3
it "should allow valid date for month & year" do
-
3
subject.month = "09"
-
3
subject.year = "12"
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:month].should be(nil)
-
3
subject.errors.messages[:year].should be(nil)
-
end
-
-
3
it "should allow valid date for month & year" do
-
3
subject.month = 12
-
3
subject.year = 2014
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:month].should be(nil)
-
3
subject.errors.messages[:year].should be(nil)
-
end
-
end
-
end
-
-
1
[:purchase, :authorize, :recurrency].each do |context_type|
-
3
context "on #{context_type}" do
-
3
it "should validate minimum 1 length of verification_value" do
-
3
subject.verification_value = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:verification_value].should include("is too short (minimum is 1 characters)")
-
end
-
-
3
it "should validate maximum 4 length of verification_value" do
-
3
subject.verification_value = '*' * 5
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:verification_value].should include("is too long (maximum is 4 characters)")
-
end
-
end
-
end
-
-
1
[:get_recurrency, :recurrency].each do |context_type|
-
2
context "on #{context_type}" do
-
2
it "should validate length of id" do
-
2
subject.id = '*' * 37
-
2
subject.valid?(context_type)
-
2
subject.errors.messages[:id].should include("is the wrong length (should be 36 characters)")
-
end
-
end
-
end
-
-
1
let(:customer) do
-
6
BraspagPagador::Customer.new(:name => "W" * 21)
-
end
-
-
1
let(:order) do
-
6
BraspagPagador::Order.new(
-
:id => "um order id",
-
:amount => 1000.00,
-
:payment_method => BraspagPagador::PAYMENT_METHOD[:redecard],
-
:installments => 1,
-
:installments_type => BraspagPagador::INTEREST[:no],
-
:customer => customer
-
)
-
end
-
-
1
let(:credit_card) do
-
2
BraspagPagador::CreditCard.new(
-
:holder_name => "Joao Maria Souza",
-
:number => "9" * 10,
-
:month => "10",
-
:year => "12",
-
:verification_value => "123"
-
)
-
end
-
-
1
context "on authorize credit card" do
-
3
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
3
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
-
1
let(:valid_xml) do
-
1
<<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xmlns="https://www.pagador.com.br/webservice/pagador">
-
<amount>1.000,00</amount>
-
<message>Transaction Successful</message>
-
<authorisationNumber>733610</authorisationNumber>
-
<returnCode>0</returnCode>
-
<status>1</status>
-
<transactionId>01231234</transactionId>
-
</PagadorReturn>
-
EOXML
-
end
-
-
1
it "should convert objects to hash" do
-
1
BraspagPagador::CreditCard.to_authorize(connection, order, credit_card).should eq({
-
"merchantId" => "#{merchant_id}",
-
"orderId" => "#{order.id}",
-
"customerName" => "#{customer.name}",
-
"amount" => "1000,00",
-
"paymentMethod" => 20,
-
"holder" => "#{credit_card.holder_name}",
-
"cardNumber" => "#{credit_card.number}",
-
"expiration" => "10/12",
-
"securityCode" => "123",
-
"numberPayments" => order.installments,
-
"typePayment" => order.installments_type
-
})
-
end
-
-
1
it "should populate data" do
-
1
resp = BraspagPagador::CreditCard.from_authorize(connection, order, credit_card, mock(:body => valid_xml))
-
-
1
order.gateway_authorization.should eq('733610')
-
1
order.gateway_id.should eq('01231234')
-
1
order.gateway_return_code.should eq('0')
-
1
order.gateway_status.should eq('1')
-
1
order.gateway_message.should eq('Transaction Successful')
-
1
order.gateway_amount.should eq(1000.00)
-
-
1
resp.should eq({
-
:amount=>"1.000,00",
-
:number=>"733610",
-
:message=>"Transaction Successful",
-
:return_code=>"0",
-
:status=>"1",
-
:transaction_id=>"01231234"})
-
end
-
end
-
-
1
context "on capture credit card" do
-
3
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
3
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
-
1
let(:valid_xml) do
-
1
<<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xmlns="https://www.pagador.com.br/webservice/pagador">
-
<amount>2</amount>
-
<message>Approved</message>
-
<returnCode>0</returnCode>
-
<status>0</status>
-
</PagadorReturn>
-
EOXML
-
end
-
-
1
it "should convert objects to hash" do
-
1
BraspagPagador::CreditCard.to_capture(connection, order).should eq({
-
"merchantId" => "#{merchant_id}",
-
"orderId" => "#{order.id}"
-
})
-
end
-
-
1
it "should populate data" do
-
1
resp = BraspagPagador::CreditCard.from_capture(connection, order, mock(:body => valid_xml))
-
-
1
order.gateway_capture_return_code.should eq('0')
-
1
order.gateway_capture_status.should eq('0')
-
1
order.gateway_capture_message.should eq('Approved')
-
1
order.gateway_capture_amount.should eq(2.00)
-
-
-
1
resp.should eq({
-
:amount=>"2",
-
:message=>"Approved",
-
:return_code=>"0",
-
:status=>"0",
-
:transaction_id=>nil
-
})
-
end
-
end
-
-
1
context "on void credit card" do
-
3
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
3
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
-
1
let(:valid_xml) do
-
1
<<-EOXML
-
<?xml version="1.0" encoding="utf-8"?>
-
<PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-
xmlns="https://www.pagador.com.br/webservice/pagador">
-
<orderId>1234</orderId>
-
<transactionId>0</transactionId>
-
<amount>100</amount>
-
<message>Approved</message>
-
<returnCode>0</returnCode>
-
<status>0</status>
-
</PagadorReturn>
-
EOXML
-
end
-
-
1
it "should convert objects to hash" do
-
1
BraspagPagador::CreditCard.to_void(connection, order).should eq({
-
"merchantId" => "#{merchant_id}",
-
"order" => "#{order.id}"
-
})
-
end
-
-
1
it "should populate data" do
-
1
resp = BraspagPagador::CreditCard.from_void(connection, order, mock(:body => valid_xml))
-
-
1
order.gateway_void_return_code.should eq('0')
-
1
order.gateway_void_status.should eq('0')
-
1
order.gateway_void_message.should eq('Approved')
-
1
order.gateway_void_amount.should eq(100.00)
-
-
1
resp.should eq({:order_id=>"1234", :amount=>"100", :message=>"Approved", :return_code=>"0", :status=>"0", :transaction_id=>"0"})
-
end
-
end
-
end
-
1
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-
1
describe BraspagPagador::Connection do
-
5
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
5
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
-
1
let(:customer) do
-
4
BraspagPagador::Customer.new(:name => "W" * 21)
-
end
-
-
1
let(:order) do
-
4
BraspagPagador::Order.new(
-
:id => "um order id",
-
:amount => 1000.00,
-
:payment_method => BraspagPagador::PAYMENT_METHOD[:eft_itau],
-
:customer => customer
-
)
-
end
-
-
1
let(:eft) do
-
2
BraspagPagador::EFT.new(
-
:crypto => BraspagPagador::Crypto::NoCrypto.new
-
)
-
end
-
-
1
let(:eft_with_encrypt) do
-
2
BraspagPagador::EFT.new(
-
:crypto => BraspagPagador::Crypto::Webservice.new
-
)
-
end
-
-
1
context ".generate_eft" do
-
1
it "should return active merchant response" do
-
1
response = connection.generate_eft(order, eft)
-
1
response.success?.should eq(true)
-
1
response.message.should eq('OK')
-
end
-
-
1
it "should return active merchant response for encrypt error" do
-
1
BraspagPagador::Crypto::Webservice.any_instance.should_receive(:encrypt).and_raise('ERROR')
-
1
response = connection.generate_eft(order, eft_with_encrypt)
-
1
response.success?.should eq(false)
-
1
response.message.should eq('ERROR')
-
end
-
-
1
it "should popule eft code a html form" do
-
1
response = connection.generate_eft(order, eft)
-
-
1
eft.code.should eq("<form id='form_tef_um order id' name='form_tef_um order id' action='https://homologacao.pagador.com.br/pagador/passthru.asp' method='post'><input type='text' name='Id_Loja' value='{12345678-1234-1234-1234-123456789000}' /><input type='text' name='VALOR' value='1000,00' /><input type='text' name='CODPAGAMENTO' value='12' /><input type='text' name='VENDAID' value='um order id' /><input type='text' name='NOME' value='WWWWWWWWWWWWWWWWWWWWW' /></form><script type='text/javascript' charset='utf-8'>document.forms['form_tef_um order id'].submit();</script>")
-
end
-
-
1
it "should populate eft code a html form when crypto strategy is given" do
-
1
BraspagPagador::Crypto::Webservice.any_instance.should_receive(:encrypt).and_return('vei na boa')
-
1
response = connection.generate_eft(order, eft_with_encrypt)
-
-
1
eft_with_encrypt.code.should eq("<form id='form_tef_um order id' name='form_tef_um order id' action='https://homologacao.pagador.com.br/pagador/passthru.asp' method='post'><input type='text' name='Id_Loja' value='{12345678-1234-1234-1234-123456789000}' /><input type='text' name='crypt' value='vei na boa' /></form><script type='text/javascript' charset='utf-8'>document.forms['form_tef_um order id'].submit();</script>")
-
end
-
end
-
end
-
-
-
1
describe BraspagPagador::EFT do
-
-
1
context "on generate" do
-
1
it "should not allow blank for crypto" do
-
1
subject.crypto = ''
-
1
subject.valid?(:generate)
-
1
subject.errors.messages[:crypto].should include("can't be blank")
-
end
-
-
1
it "should not allow invalid crypto" do
-
1
subject.crypto = 1234
-
1
subject.valid?(:generate)
-
1
subject.errors.messages[:crypto].should include("invalid crypto")
-
end
-
-
[ BraspagPagador::Crypto::Webservice.new,
-
BraspagPagador::Crypto::NoCrypto.new
-
1
].each do |crypto|
-
2
it "should accept valid crypto: #{crypto.class}" do
-
2
subject.crypto = crypto
-
2
subject.valid?(:generate)
-
2
subject.errors.messages[:crypto].should be(nil)
-
end
-
end
-
end
-
-
end
-
1
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-
1
describe BraspagPagador::Connection do
-
1
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
-
1
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
-
-
1
pending 'archive'
-
-
1
pending 'get_recurrency'
-
-
1
pending 'recurrency'
-
end
-
-
1
describe BraspagPagador::CreditCard do
-
-
1
[:purchase, :authorize, :archive].each do |context_type|
-
3
context "on #{context_type}" do
-
3
it "should validate minimum 1 length of holder_name" do
-
3
subject.holder_name = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:holder_name].should include("is too short (minimum is 1 characters)")
-
end
-
-
3
it "should validate maximum 100 length of holder_name" do
-
3
subject.holder_name = '*' * 110
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:holder_name].should include("is too long (maximum is 100 characters)")
-
end
-
-
3
it "should not allow blank for number" do
-
3
subject.number = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:number].should include("can't be blank")
-
end
-
-
3
it "should not allow blank for month" do
-
3
subject.month = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:month].should include("can't be blank")
-
end
-
-
3
it "should not allow blank for year" do
-
3
subject.year = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:year].should include("can't be blank")
-
end
-
-
3
it "should not allow invalid date for month & year" do
-
3
subject.month = "14"
-
3
subject.year = "2012"
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:month].should include("invalid date")
-
3
subject.errors.messages[:year].should include("invalid date")
-
end
-
-
3
it "should allow valid date for month & year" do
-
3
subject.month = "09"
-
3
subject.year = "12"
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:month].should be(nil)
-
3
subject.errors.messages[:year].should be(nil)
-
end
-
-
3
it "should allow valid date for month & year" do
-
3
subject.month = 12
-
3
subject.year = 2014
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:month].should be(nil)
-
3
subject.errors.messages[:year].should be(nil)
-
end
-
end
-
end
-
-
1
[:purchase, :authorize, :recurrency].each do |context_type|
-
3
context "on #{context_type}" do
-
3
it "should validate minimum 1 length of verification_value" do
-
3
subject.verification_value = ''
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:verification_value].should include("is too short (minimum is 1 characters)")
-
end
-
-
3
it "should validate maximum 4 length of verification_value" do
-
3
subject.verification_value = '*' * 5
-
3
subject.valid?(context_type)
-
3
subject.errors.messages[:verification_value].should include("is too long (maximum is 4 characters)")
-
end
-
end
-
end
-
-
1
[:get_recurrency, :recurrency].each do |context_type|
-
2
context "on #{context_type}" do
-
2
it "should validate length of id" do
-
2
subject.id = '*' * 37
-
2
subject.valid?(context_type)
-
2
subject.errors.messages[:id].should include("is the wrong length (should be 36 characters)")
-
end
-
end
-
end
-
-
end