Sha256: bf6cb80ac06615cf25fe25d7b0a099dec40dba982101028449c20e386f3c1ef0

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

module CatarsePagarme
  class SlipController < CatarsePagarme::ApplicationController

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

    protected

    def slip_attributes
      {
        payment_method: 'boleto',
        boleto_expiration_date: 2.days.from_now.to_i,
        amount: delegator.value_for_transaction,
        postback_url: ipn_pagarme_url(contribution, host: CatarsePagarme.configuration.host, subdomain: CatarsePagarme.configuration.subdomain),
        customer: {
          email: contribution.user.email,
          name: contribution.user.name
        }
      }.update({ user: params[:user] })
    end

    def permitted_attributes
      attrs = ActionController::Parameters.new(slip_attributes)
      attrs.permit(:boleto_expiration_date, :payment_method, :amount, :postback_url, 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

1 entries across 1 versions & 1 rubygems

Version Path
catarse_pagarme-0.1.6 app/controllers/catarse_pagarme/slip_controller.rb