Class: Akatus::Transactions
- Inherits:
-
Object
- Object
- Akatus::Transactions
- Defined in:
- lib/akatus/transactions.rb
Class Method Summary collapse
- .map_payment_method(payment_method) ⇒ Object
-
.prepare_xml_to_send(order) ⇒ Object
private.
- .process(order) ⇒ Object
- .status(akatus_uuid) ⇒ Object
Class Method Details
.map_payment_method(payment_method) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/akatus/transactions.rb', line 97 def self.map_payment_method(payment_method) case payment_method.to_sym when :bill 'boleto' when :eft 'tef' when :master 'cartao_master' when :visa 'cartao_visa' when :amex 'cartao_amex' when :diners 'cartao_diners' when :elo 'cartao_elo' else payment_method.to_s end end |
.prepare_xml_to_send(order) ⇒ Object
private
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/akatus/transactions.rb', line 28 def self.prepare_xml_to_send(order) builder = Nokogiri::XML::Builder.new do |xml| xml.carrinho { xml.recebedor { xml.api_key Akatus.seller_api_key xml.email Akatus.seller_email } xml.pagador { xml.nome order.buyer_name xml.email order.buyer_email xml.enderecos { xml.endereco { xml.tipo order.address.kind || 'cobranca' xml.logradouro order.address.street xml.numero order.address.number xml.bairro order.address.neighborhood xml.cidade order.address.city xml.estado order.address.state xml.pais order.address.country || 'BRA' xml.cep order.address.postal_code } } xml.telefones { xml.telefone { xml.tipo order.phone.kind xml.numero order.phone.number } } } xml.produtos { order.products.each do |product| xml.produto { xml.codigo product.code xml.descricao product.name xml.quantidade product.quantity || 1 xml.peso product.weight || 0.0 xml.frete product.freight_amount || 0.0 xml.preco '%.2f' % product.price } end } xml.transacao { xml.desconto order.discount_amount || 0.0 xml.peso order.weight || 0.0 xml.frete order.freight_amount || 0.0 xml.moeda 'BRL' xml.meio_de_pagamento map_payment_method(order.payment_method) xml.parcelas order.installments || 1 xml.referencia order.reference if order.credit_card? xml.numero order.credit_card.number xml.expiracao order.credit_card.expires_at xml.codigo_de_seguranca order.credit_card.cvv xml.portador { xml.nome order.credit_card.holder_name xml.cpf order.credit_card.holder_cpf xml.telefone order.credit_card.holder_phone } end } } end # Rails.logger.info "---------------GENERATED XML TO SEND FOR AKATUS--------------" # Rails.logger.info builder.to_xml builder.to_xml end |
.process(order) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/akatus/transactions.rb', line 3 def self.process(order) xml = prepare_xml_to_send order url = "#{Akatus.akatus_api_uri}/carrinho.xml" request = HTTPI::Request.new request.body = xml request.url = url request.open_timeout = 10 # sec request.read_timeout = 30 # sec response = HTTPI.post request Hash.from_xml(Nokogiri::XML(response.raw_body).to_s)['resposta'] end |
.status(akatus_uuid) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/akatus/transactions.rb', line 16 def self.status(akatus_uuid) url = "#{Akatus.akatus_api_uri}/transacao-simplificada/#{akatus_uuid}.json?email=#{seller_email}&api_key=#{seller_api_key}" request = HTTPI::Request.new request.url = url request.open_timeout = 10 # sec request.read_timeout = 30 # sec @response ||= HTTPI.get request #TODO Finish to implement this end |