Sha256: 7c9634aefa1b0c3d85aa6e3071fce1dac62a7e2bc76a3cae50c9b76669a0168a

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

module Moiper
  class Notification
    PAYMENT_STATUSES = {
      1 => :authorized,
      2 => :started,
      3 => :payment_form_printed,
      4 => :finished,
      5 => :canceled,
      6 => :under_analysis,
      7 => :returned,
      9 => :reimbursed
    }

    FINANCIAL_INSTITUTIONS = {
      1 => "MoIP",
      3 => "Visa",
      7 => "AmericanExpress",
      5 => "Mastercard",
      6 => "Diners",
      8 => "BancoDoBrasil",
      22 => "Bradesco",
      13 => "Itau",
      75 => "Hipercard",
      76 => "Paggo",
      88 => "Banrisul"
    }

    PAYMENT_METHODS = {
      "BoletoBancario" => :payment_form,
      "CartaoDeCredito" => :credit_card,
      "DebitoBancario" => :debit,
      "CartaoDeDebito" => :debit_card,
      "FinanciamentoBancario" => :financing,
      "CarteiraMoIP" => :moip_account
    }

    attr_reader :params
    private :params

    def initialize(params)
      @params = params
    end

    def id
      params["id_transacao"]
    end

    def price
      params["valor"].to_i / 100.0
    end

    def payment_status
      PAYMENT_STATUSES[params["status_pagamento"].to_i]
    end

    def moip_id
      params["cod_moip"].to_i
    end

    def financial_institution
      FINANCIAL_INSTITUTIONS[params["forma_pagamento"].to_i]
    end

    def payment_method
      PAYMENT_METHODS[params["tipo_pagamento"]]
    end

    def quotas
      params["parcelas"].to_i
    end

    def user_email
      params["email_consumidor"]
    end

    def additional_info
      params["classificacao"]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
moiper-0.1.1 lib/moiper/notification.rb
moiper-0.1.0 lib/moiper/notification.rb