class ActiveMerchant::Billing::PagoFacilGateway
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 14 def initialize(options={}) requires!(options, :branch_id, :merchant_id, :service_id) super end
Public Instance Methods
purchase(money, credit_card, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 19 def purchase(money, credit_card, options={}) post = {} add_invoice(post, money, options) add_payment(post, credit_card) add_address(post, options) add_customer_data(post, options) add_merchant_data(post) commit(post) end
Private Instance Methods
add_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 37 def add_address(post, options) address = options.fetch(:billing_address, {}) post[:calleyNumero] = address[:address1] post[:colonia] = address[:address2] post[:municipio] = address[:city] post[:estado] = address[:state] post[:pais] = address[:country] post[:telefono] = address[:phone] post[:cp] = address[:zip] end
add_currency(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 54 def add_currency(post, money, options) currency = options.fetch(:currency, currency(money)) unless currency == self.class.default_currency post[:divisa] = currency end end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 32 def add_customer_data(post, options) post[:email] = options[:email] post[:celular] = options[:cellphone] end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 48 def add_invoice(post, money, options) post[:monto] = amount(money) post[:idPedido] = options[:order_id] add_currency(post, money, options) end
add_merchant_data(post)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 70 def add_merchant_data(post) post[:idSucursal] = options.fetch(:branch_id) post[:idUsuario] = options.fetch(:merchant_id) post[:idServicio] = options.fetch(:service_id) end
add_payment(post, credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 61 def add_payment(post, credit_card) post[:nombre] = credit_card.first_name post[:apellidos] = credit_card.last_name post[:numeroTarjeta] = credit_card.number post[:cvt] = credit_card.verification_value post[:mesExpiracion] = sprintf("%02d", credit_card.month) post[:anyoExpiracion] = credit_card.year.to_s.slice(-2, 2) end
commit(parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 82 def commit(parameters) url = (test? ? test_url : live_url) response = parse(ssl_post(url, post_data(parameters))) Response.new( success_from(response), message_from(response), response, authorization: authorization_from(response), test: test? ) end
json_error(response)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 114 def json_error(response) { "texto" => 'Invalid response received from the PagoFacil API.', "raw_response" => response } end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 99 def message_from(response) response["texto"] end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 76 def parse(body) JSON.parse(body)["WebServices_Transacciones"]["transaccion"] rescue JSON::ParserError json_error(body) end
post_data(parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 107 def post_data(parameters = {}) { method: 'transaccion', data: parameters }.to_query end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/pago_facil.rb, line 94 def success_from(response) response["autorizado"] == "1" || response["autorizado"] == true end