Class: ZipMoney::Checkout

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

Instance Attribute Summary collapse

Attributes included from Request

#errors

Instance Method Summary collapse

Methods included from Request

#validate_item_details

Constructor Details

#initializeCheckout

Initializes a ZipMoney::Checkout object

Returns ZipMoney::Checkout object



13
14
15
16
17
18
19
20
21
22
# File 'lib/zipMoney/api/checkout.rb', line 13

def initialize 
  @params         = Struct::CheckoutParams.new
  @params.order   = Struct::Order.new
  @params.billing_address  = Struct::Address.new
  @params.shipping_address = Struct::Address.new
  @params.consumer = Struct::Consumer.new
  @params. = Struct::Metadata.new
  @params.version  = Struct::Version.new
  @params.order.detail =  Array.new
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



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

def params
  @params
end

Instance Method Details

#doObject

Performs the Checkout api call on zipMoney endpoint

Returns ZipMoney::Checkout object



27
28
29
30
# File 'lib/zipMoney/api/checkout.rb', line 27

def do  
  validate
  ZipMoney.api.checkout(self.params)
end

#validateObject

Performs the parameters validation

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/zipMoney/api/checkout.rb', line 33

def validate

  raise ArgumentError, "Params emtpy" if @params.nil? 
  @errors = []
  @errors << 'charge must be provided' if @params.charge.nil? 
  @errors << 'currency_code must be provided' if @params.currency_code.nil? 
  @errors << 'order_id must be provided' if @params.order_id.nil? 
  @errors << 'order must be provided' if @params.order.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? 
  @errors << 'order detail must be provided' unless @params.order.detail.length > 0 

  validate_item_details @params.order.detail if @params.order.detail.length > 0 

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