Sha256: 05bd643325ef5d7935def2103f77bfb74f10e2afb65406fcc62c0a6f21f5368d

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require 'mercadopago'
require 'app_configuration'

class MercadoPagoHelper

  APPROVED = :approved
  PENDING = :pending
  IN_PROCESS = :in_process
  REJECTED = :rejected
  REFUNDED = :refunded
  CANCELLED = :cancelled
  IN_MEDIATION = :in_mediation

  class << self

    @@mp = MercadoPago.new(AppConfiguration.for(:mercadopago).client_id, AppConfiguration.for(:mercadopago).client_secret)

    def mp
      @@mp
    end

    def set_handlers(status_handlers = {})
      validate_presence(status_handlers)
      @contexts = status_handlers.dup
    end

    def get_context(response, obj)
      status = response['response']['collection']['status'].to_sym
      @contexts[status].new(response, obj)
    end

    private
      def validate_presence(status_handlers)
        if status_handlers[APPROVED].nil? || status_handlers[PENDING].nil? || status_handlers[IN_PROCESS].nil? || status_handlers[REJECTED].nil? || status_handlers[REFUNDED].nil? || status_handlers[CANCELLED].nil? || status_handlers[IN_MEDIATION].nil?
          raise "MissingStatusHandler"
        end
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mercado_pago_rails-0.1.1 lib/mercado_pago_rails/mercado_pago_helper.rb
mercado_pago_rails-0.1.0 lib/mercado_pago_rails/mercado_pago_helper.rb