Exception: PinPayment::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/pin_payment/error.rb

Defined Under Namespace

Classes: InvalidResource, InvalidResponse, ResourceNotFound, TokenAlreadyUsed

Class Method Summary collapse

Class Method Details

.create(type, description, messages = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/pin_payment/error.rb', line 4

def self.create type, description, messages = nil
  klass = case type
    when 'token_already_used'; TokenAlreadyUsed
    when 'invalid_resource';   InvalidResource
    when 'resource_not_found'; ResourceNotFound
    else self
  end
  if messages.is_a?(Array)
    description = description + ' ' + messages.map{|x| "(#{x['message']})" }.join(' & ')
  elsif messages.is_a?(Hash)
    description = description + ' ' + messages.values.flatten.map{|x| "(#{x})" }.join(' & ')
  end
  klass.new(description)
end