Class: ZipMoney::Capture

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/zipMoney/api/capture.rb

Instance Attribute Summary collapse

Attributes included from Request

#errors

Instance Method Summary collapse

Methods included from Request

#validate_item_details

Constructor Details

#initializeCapture

Initializes a ZipMoney::Capture object

Returns ZipMoney::Capture object



12
13
14
15
16
17
# File 'lib/zipMoney/api/capture.rb', line 12

def initialize 
  @params      = Struct::CaptureParams.new
  @params.order    = Struct::Order.new
  @params. = Struct::Metadata.new
  @params.version  = Struct::Version.new
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/zipMoney/api/capture.rb', line 5

def params
  @params
end

Instance Method Details

#doObject

Performs the Capture api call on zipMoney endpoint

Returns ZipMoney::Cancel object



22
23
24
25
# File 'lib/zipMoney/api/capture.rb', line 22

def do  
  validate
  ZipMoney.api.capture(@params)
end

#validateObject

Performs the parameters validation

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zipMoney/api/capture.rb', line 28

def validate
  raise ArgumentError, "Params emtpy" if @params.nil? 
  @errors = []
  @errors << 'txn_id must be provided' if @params.txn_id.nil? 
  @errors << 'order.id must be provided' if @params.order.id.nil? 
  @errors << 'order.total must be provided' if @params.order.total.nil? 
  @errors << 'order.shipping_value must be provided' if @params.order.shipping_value.nil? 
  @errors << 'order.tax must be provided' if @params.order.tax.nil? 

  raise ZipMoney::RequestError.new("Following error(s) occurred while making request, please resolve them to make the request: #{@errors}") if @errors.any?
end