Class: ZipMoney::Checkout
- Inherits:
-
Object
- Object
- ZipMoney::Checkout
- Includes:
- Request
- Defined in:
- lib/zipMoney/api/checkout.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Attributes included from Request
Instance Method Summary collapse
-
#do ⇒ Object
Performs the Checkout api call on zipMoney endpoint.
-
#initialize ⇒ Checkout
constructor
Initializes a ZipMoney::Checkout object.
-
#validate ⇒ Object
Performs the parameters validation.
Methods included from Request
Constructor Details
#initialize ⇒ Checkout
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
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/zipMoney/api/checkout.rb', line 5 def params @params end |
Instance Method Details
#do ⇒ Object
Performs the Checkout api call on zipMoney endpoint
Returns ZipMoney::Checkout object
27 28 29 30 31 |
# File 'lib/zipMoney/api/checkout.rb', line 27 def do validate ZipMoney.api.checkout(self.params) end |
#validate ⇒ Object
Performs the parameters validation
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zipMoney/api/checkout.rb', line 34 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' if @params.order.detail.nil? validate_item_details @params.order.detail raise ZipMoney::RequestError.new("Following error(s) occurred while making request, please resolve them to make the request: #{@errors}") if @errors.any? end |