Class: Braspag::CreditCard
Constant Summary
collapse
- PAYMENT_METHODS =
{
:amex_2p => 18, :cielo_noauth_visa => 71, :cielo_preauth_visa => 73, :cielo_noauth_mastercard => 120, :cielo_preauth_mastercard => 122, :cielo_noauth_elo => 126, :cielo_noauth_diners => 130, :redecard => 20, :redecard_preauth => 42, :cielo_sitef => 57, :hipercard_sitef => 62, :hipercard_moip => 90, :oi_paggo => 55, :amex_sitef => 58, :aura_dtef => 37, :redecard_sitef => 44, :mex_amex_2p => 45, :mex_banorte_visa => 50, :mex_banorte_diners => 52, :mex_banorte_mastercard => 53, :col_visa => 63, :col_amex => 65, :col_diners => 66, :paypal_express => 35 }
- MAPPING =
{
:merchant_id => "merchantId",
:order_id => "orderId",
:customer_name => "customerName",
:amount => "amount",
:payment_method => "paymentMethod",
:holder => "holder",
:card_number => "cardNumber",
:expiration => "expiration",
:security_code => "securityCode",
:number_payments => "numberPayments",
:type => "typePayment",
}
- AUTHORIZE_URI =
"/webservices/pagador/Pagador.asmx/Authorize"
- CAPTURE_URI =
"/webservices/pagador/Pagador.asmx/Capture"
- PRODUCTION_INFO_URI =
"/webservices/pagador/pedido.asmx/GetDadosCartao"
- HOMOLOGATION_INFO_URI =
"/pagador/webservice/pedido.asmx/GetDadosCartao"
Class Method Summary
collapse
normalize_params, payment_method_from_id, valid_order_id?
Class Method Details
.authorize(params = {}) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/rbraspag/credit_card.rb', line 55
def self.authorize(params = {})
connection = Braspag::Connection.instance
params[:merchant_id] = connection.merchant_id
self.check_params(params)
data = {}
MAPPING.each do |k, v|
case k
when :payment_method
data[v] = PAYMENT_METHODS[params[:payment_method]]
when :amount
data[v] = Utils.convert_decimal_to_string(params[:amount])
else
data[v] = params[k] || ""
end
end
request = ::HTTPI::Request.new self.authorize_url
request.body = data
response = ::HTTPI.post request
Utils::convert_to_map(response.body, {
:amount => nil,
:number => "authorisationNumber",
:message => 'message',
:return_code => 'returnCode',
:status => 'status',
:transaction_id => "transactionId"
})
end
|
.capture(order_id) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/rbraspag/credit_card.rb', line 87
def self.capture(order_id)
connection = Braspag::Connection.instance
merchant_id = connection.merchant_id
raise InvalidOrderId unless self.valid_order_id?(order_id)
data = {
MAPPING[:order_id] => order_id,
MAPPING[:merchant_id] => merchant_id
}
request = ::HTTPI::Request.new(self.capture_url)
request.body = data
response = ::HTTPI.post(request)
Utils::convert_to_map(response.body, {
:amount => nil,
:number => "authorisationNumber",
:message => 'message',
:return_code => 'returnCode',
:status => 'status',
:transaction_id => "transactionId"
})
end
|
.check_params(params) ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/rbraspag/credit_card.rb', line 134
def self.check_params(params)
super
[:customer_name, :holder, :card_number, :expiration, :security_code, :number_payments, :type].each do |param|
raise IncompleteParams if params[param].nil?
end
raise InvalidHolder if params[:holder].to_s.size < 1 || params[:holder].to_s.size > 100
matches = params[:expiration].to_s.match /^(\d{2})\/(\d{2}|\d{4})$/
raise InvalidExpirationDate unless matches
begin
year = matches[2].to_i
year = "20#{year}" if year.size == 2
Date.new(year.to_i, matches[1].to_i)
rescue ArgumentError
raise InvalidExpirationDate
end
raise InvalidSecurityCode if params[:security_code].to_s.size < 1 || params[:security_code].to_s.size > 4
raise InvalidNumberPayments if params[:number_payments].to_i < 1 || params[:number_payments].to_i > 99
end
|
.info(order_id) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/rbraspag/credit_card.rb', line 112
def self.info(order_id)
connection = Braspag::Connection.instance
raise InvalidOrderId unless self.valid_order_id?(order_id)
request = ::HTTPI::Request.new(self.info_url)
request.body = {:loja => connection.merchant_id, :numeroPedido => order_id.to_s}
response = ::HTTPI.post(request)
response = Utils::convert_to_map(response.body, {
:checking_number => "NumeroComprovante",
:certified => "Autenticada",
:autorization_number => "NumeroAutorizacao",
:card_number => "NumeroCartao",
:transaction_number => "NumeroTransacao"
})
raise UnknownError if response[:checking_number].nil?
response
end
|