Sha256: 96e6746aa28eb5a25fcc6393464a18b7d970b284209b1d6a2d91056648a5cf64

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

module Opay
  module Helpers

    module PayuHelper

      def payu_form_for(record, options = {}, &block)
        options[:builder] ||= Opay::FormBuilder

        options[:url]  = Opay::Providers::Payu.url(:new_payment)
        options[:html] = { id: "payu_payment_form_#{record.id}", class: 'payu_payment_form' }

        record.create_payment!(session_id: record.payment_session_id, provider: 'payu', amount: record.amount) if record.payment.blank?

        form_for(record, options, &block)
      end

      def payment_info(options = {})
        options[:first_name]   ||= object.first_name
        options[:last_name]    ||= object.last_name
        options[:email]        ||= object.email

        options[:pos_id]       ||= Opay.config.pos_id
        options[:pos_auth_key] ||= Opay.config.pos_auth_key
        options[:session_id]   ||= object.payment_session_id

        options[:amount]       ||= object.amount
        options[:desc]         ||= object.payment_description
        options[:client_ip]    ||= @template.request.remote_ip
        options[:js]             = 0

        options[:pay_type] = 't' if Opay.config.test_mode


        fields = options.map { |key, val| @template.hidden_field_tag(key, val) }.join("\n")
        js = "<script type=\"text/javascript\"><!-- document.forms['payu_payment_form_#{object.id}'].js.value = 1; --></script>"

        "#{fields}\n#{js}".html_safe
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opay-1.0.1 lib/opay/helpers/payu_helper.rb
opay-1.0.0 lib/opay/helpers/payu_helper.rb