Sha256: 57c8a66b64082b35e9a12e8a33372df5340dc04eb0b18fcd9d3b77a21d956436

Contents?: true

Size: 1.8 KB

Versions: 4

Compression:

Stored size: 1.8 KB

Contents

module BraspagPagador
  class Connection
    def generate_eft(order, eft)

      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
      }

      html = "<form id='form_tef_#{order.id}' name='form_tef_#{order.id}' action='#{self.url_for(:generate_eft)}' method='post'>"


      begin
        unless eft.crypto.respond_to?(:encrypt)
          params.each do |key, value|
            html << "<input type='text' name='#{key}' value='#{value}' />"
          end
        else
          params.delete("Id_Loja")
          html << "<input type='text' name='Id_Loja' value='#{self.merchant_id}' />"
          html << "<input type='text' name='crypt' value='#{eft.crypto.encrypt(self, params)}' />"
        end

        html << "</form><script type='text/javascript' charset='utf-8'>document.forms['form_tef_#{order.id}'].submit();</script>"

        eft.code = html
        status = true
        message = 'OK'
      rescue Exception => e
        status = false
        message = e.message
      end

      ActiveMerchant::Billing::Response.new(status,
       message,
       {},
       :test => homologation?)
    end
  end

  class EFT
    include ::ActiveAttr::Model

    class CryptoValidator < ActiveModel::EachValidator
      def validate_each(record, attribute, value)
        unless (
          value.kind_of?(BraspagPagador::Crypto::NoCrypto) ||
          value.respond_to?(:encrypt)
          )
          record.errors.add attribute, "invalid crypto"
        end
      end
    end

    attr_accessor :crypto, :code

    validates :crypto, :presence => { :on => :generate }
    validates :crypto, :crypto => { :on => :generate }

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
braspag-pagador-1.0.1 lib/braspag-pagador/payment/eft.rb
braspag-pagador-1.0.0 lib/braspag-pagador/payment/eft.rb
braspag-pagador-0.9.6 lib/braspag-pagador/payment/eft.rb
braspag-pagador-0.9.5 lib/braspag-pagador/payment/eft.rb