Class: Braspag::Eft
- Inherits:
-
PaymentMethod
- Object
- PaymentMethod
- Braspag::Eft
- Defined in:
- lib/rbraspag/eft.rb
Constant Summary collapse
- PAYMENT_METHODS =
{ :bradesco => 11, :itau => 12, :banco_do_brasil => 15, :banco_real => 16, :banrisul => 30, :unibanco => 31 }
- MAPPING =
{ :merchant_id => "Id_Loja", :order_id => "VendaId", :customer_name => "Nome", :customer_id => "Cpf", :amount => "Valor", :payment_method => "codpagamento", :installments => "PARCELAS", :has_interest => "TIPOPARCELADO" }
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(connection, params, crypto_strategy = nil) ⇒ Eft
constructor
A new instance of Eft.
- #ok? ⇒ Boolean
Methods inherited from PaymentMethod
Constructor Details
#initialize(connection, params, crypto_strategy = nil) ⇒ Eft
Returns a new instance of Eft.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rbraspag/eft.rb', line 23 def initialize(connection, params, crypto_strategy = nil) raise InvalidConnection unless connection.is_a?(Braspag::Connection) @connection = connection @params = params @params[:merchant_id] = connection.merchant_id @crypto_strategy = crypto_strategy if @params[:amount] && !@params[:amount].is_a?(BigDecimal) @params[:amount] = BigDecimal.new(@params[:amount].to_s) end ok? end |
Instance Method Details
#generate ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rbraspag/eft.rb', line 68 def generate data = create_data_from_params html = "<form id=\"form_tef_#{@params[:order_id]}\" name=\"form_tef_#{@params[:order_id]}\" action=\"#{self.uri}\" method=\"post\">\n" if @crypto_strategy.nil? data.each do |key, value| html.concat " <input type=\"text\" name=\"#{key}\" value=\"#{value}\" />\n" end else data.delete("Id_Loja") html.concat " <input type=\"text\" name=\"crypt\" value=\"#{@crypto_strategy.encrypt(data)}\" />\n" html.concat " <input type=\"text\" name=\"Id_Loja\" value=\"#{@params[:merchant_id]}\" />\n" end html.concat "</form>\n<script type=\"text/javascript\" charset=\"utf-8\">\n document.forms[\"form_tef_\#{@params[:order_id]}\"].submit();\n</script>\n EOHTML\n\n html\nend\n" |
#ok? ⇒ Boolean
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 |
# File 'lib/rbraspag/eft.rb', line 38 def ok? raise IncompleteParams if @params[:order_id].nil? || @params[:amount].nil? || @params[:payment_method].nil? raise InvalidOrderId unless @params[:order_id].is_a?(String) || @params[:order_id].is_a?(Fixnum) raise InvalidOrderId unless (1..50).include?(@params[:order_id].to_s.size) unless @params[:customer_name].nil? raise InvalidCustomerName unless (1..255).include?(@params[:customer_name].to_s.size) end unless @params[:customer_id].nil? raise InvalidCustomerId unless (11..18).include?(@params[:customer_id].to_s.size) end unless @params[:installments].nil? raise InvalidInstallments unless (1..2).include?(@params[:installments].to_s.size) begin @params[:installments] = Integer(@params[:installments]) unless @params[:installments].is_a?(Integer) rescue Exception => e raise InvalidInstallments end end unless @params[:has_interest].nil? raise InvalidHasInterest unless (@params[:has_interest].is_a?(TrueClass) || @params[:has_interest].is_a?(FalseClass)) end true end |