Class: InvisibleCollector::Resources::PaymentResource

Inherits:
Object
  • Object
show all
Includes:
DefaultHandlers
Defined in:
lib/invisible_collector/resources/payment_resource.rb

Instance Method Summary collapse

Methods included from DefaultHandlers

#execute, #execute_get, #execute_post, #handle, #handles

Constructor Details

#initialize(options = {}) ⇒ PaymentResource

Returns a new instance of PaymentResource.



8
9
10
11
12
13
14
# File 'lib/invisible_collector/resources/payment_resource.rb', line 8

def initialize(options = {})
  super(options)
  handle(400) { |response| raise InvisibleCollector::InvalidRequest.from_json(response.body) }
  handle(404) { |response| raise InvisibleCollector::NotFound.from_json(response.body) }
  handle(409) { |response| raise InvisibleCollector::InvalidRequest.from_json(response.body) }
  handle(422) { |response| raise InvisibleCollector::InvalidRequest.from_json(response.body) }
end

Instance Method Details

#save(payment) ⇒ Object



16
17
18
19
20
# File 'lib/invisible_collector/resources/payment_resource.rb', line 16

def save(payment)
  response = execute_post('payments', payment)
  payment = Model::Payment.new(JSON.parse(response.body).deep_transform_keys(&:underscore))
  Response.new(response, payment)
end