Sha256: 21a5175be82d674ac1a5f09ff229a685e1578383b5557323f722b8889615ee26

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

module CatarsePagarme
  class SlipController < CatarsePagarme::ApplicationController

    def create
      transaction = SlipTransaction.new(permitted_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(permitted_attributes, payment).charge!
      render text: transaction.boleto_url
    end

    protected

    def slip_attributes
      {
        payment_method: 'boleto',
        boleto_expiration_date: 2.days.from_now,
        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
      }.update({ user: params[:user] })
    end

    def permitted_attributes
      attrs = ActionController::Parameters.new(slip_attributes)
      attrs.permit(:boleto_expiration_date, :payment_method, :amount, :postback_url, metadata: [:key], customer: [:name, :email],
        user: [
          bank_account_attributes: [
            :bank_id, :account, :account_digit, :agency,
            :agency_digit, :owner_name, :owner_document
          ]
        ])
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
catarse_pagarme-2.6.8 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.6.7 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.6.6 app/controllers/catarse_pagarme/slip_controller.rb
catarse_pagarme-2.6.5 app/controllers/catarse_pagarme/slip_controller.rb