Sha256: e4d1c7e590e73a82700bada9691f82014e1778cec8441f4432640e9b6e890d65

Contents?: true

Size: 1.39 KB

Versions: 15

Compression:

Stored size: 1.39 KB

Contents

require 'weekdays'

module CatarsePagarme
  class SlipController < CatarsePagarme::ApplicationController

    def create
      transaction = SlipTransaction.new(slip_attributes, payment).charge!

      render json: { boleto_url: transaction.boleto_url, payment_status: transaction.status }
    rescue PagarMe::PagarMeError => e
      render json: { boleto_url: nil, payment_status: 'failed', message: e.message }
    end

    def update
      transaction = SlipTransaction.new(slip_attributes, payment).charge!
      respond_to do |format|
        format.html { redirect_to transaction.boleto_url }
        format.json do
          { boleto_url: transaction.boleto_url }
        end
      end
    end

    protected

    def slip_attributes
      expiration_date = (CatarsePagarme.configuration.slip_week_day_interval || 2).weekdays_from_now
      {
        payment_method: 'boleto',
        boleto_expiration_date: expiration_date,
        amount: delegator.value_for_transaction,
        postback_url: ipn_pagarme_index_url(host: CatarsePagarme.configuration.host,
                                            subdomain: CatarsePagarme.configuration.subdomain,
                                            protocol: CatarsePagarme.configuration.protocol),
        customer: {
          email: payment.user.email,
          name: payment.user.name
        },
        metadata: metadata_attributes
      }
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
catarse_pagarme-2.8.1 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.8.0 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.15 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.14 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.13 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.12 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.11 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.10 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.9 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.8 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.7 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.6 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.5 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.4 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.7.3 app/controllers/catarse_pagarme/slip_controller.rb