Sha256: 0f344f698f3d5e5d8d5ee19d853a58f18bc2fcf8cd527e7cbd171bb76520ecc2

Contents?: true

Size: 1.59 KB

Versions: 13

Compression:

Stored size: 1.59 KB

Contents

module CatarsePagarme
  class CreditCardBaseController < CatarsePagarme::ApplicationController

    protected

    def charge_with_class(kclass)
      transaction = kclass.new(credit_card_attributes, contribution).charge!

      render json: { payment_status: transaction.status }
    rescue Exception => e
      render json: { payment_status: 'failed', message: e.message }
    end

    def splited_month_and_year
      params[:payment_card_date].split('/')
    rescue
      [0, 0]
    end

    def get_installment
      if contribution.value < CatarsePagarme.configuration.minimum_value_for_installment
        1
      elsif params[:payment_card_installments].to_i > 0
        params[:payment_card_installments].to_i
      else
        1
      end
    end

    def credit_card_attributes
      {
        payment_method: 'credit_card',
        card_number: params[:payment_card_number],
        card_holder_name: params[:payment_card_name],
        card_expiration_month: splited_month_and_year[0],
        card_expiration_year: splited_month_and_year[1],
        card_cvv: params[:payment_card_source],
        amount: delegator.value_with_installment_tax(get_installment),
        postback_url: ipn_pagarme_index_url(host: CatarsePagarme.configuration.host,
                                            subdomain: CatarsePagarme.configuration.subdomain,
                                            protocol: CatarsePagarme.configuration.protocol),
        installments: get_installment,
        customer: {
          email: contribution.user.email,
          name: contribution.user.name
        }
      }
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
catarse_pagarme-1.4.0 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-2.3.0 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-2.2.1 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-1.3.1 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-2.2.0 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-1.3.0 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-2.1.1 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-2.1.0 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-1.2.0 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-2.0.3 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-2.0.2 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-2.0.1 app/controllers/catarse_pagarme/credit_card_base_controller.rb
catarse_pagarme-1.1.0 app/controllers/catarse_pagarme/credit_card_base_controller.rb