Class: ZipMoney::Quote
- Inherits:
-
Object
- Object
- ZipMoney::Quote
- Includes:
- Request
- Defined in:
- lib/zipMoney/api/quote.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 Quote api call on zipMoney endpoint.
-
#initialize ⇒ Quote
constructor
Initializes a ZipMoney::Quote object.
-
#validate ⇒ Object
Performs the parameters validation.
Methods included from Request
Constructor Details
#initialize ⇒ Quote
Initializes a ZipMoney::Quote object
Returns ZipMoney::Quote object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/zipMoney/api/quote.rb', line 13 def initialize @params = Struct::QuoteParams.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/quote.rb', line 5 def params @params end |
Instance Method Details
#do ⇒ Object
Performs the Quote api call on zipMoney endpoint
Returns ZipMoney::Quote object
27 28 29 30 |
# File 'lib/zipMoney/api/quote.rb', line 27 def do validate ZipMoney.api.quote(@params) end |
#validate ⇒ Object
Performs the parameters validation
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zipMoney/api/quote.rb', line 33 def validate raise ArgumentError, "Params emtpy" if @params.nil? @errors = [] @errors << 'quote_id must be provided' if @params.quote_id.nil? @errors << 'success_url must be provided' if @params.success_url.nil? @errors << 'cancel_url must be provided' if @params.cancel_url.nil? @errors << 'error_url must be provided' if @params.error_url.nil? @errors << 'decline_url must be provided' if @params.decline_url.nil? @errors << 'quote_id must be provided' if @params.quote_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 |