Class: Wheretocard::Order
- Inherits:
-
Object
- Object
- Wheretocard::Order
- Defined in:
- lib/wheretocard/order.rb
Overview
Object representing a response object with attributes provided by WTC
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#client ⇒ Object
Returns the value of attribute client.
-
#country ⇒ Object
Returns the value of attribute country.
-
#delivery_channel ⇒ Object
Returns the value of attribute delivery_channel.
-
#delivery_format ⇒ Object
Returns the value of attribute delivery_format.
-
#email ⇒ Object
Returns the value of attribute email.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#house_number ⇒ Object
Returns the value of attribute house_number.
-
#infix ⇒ Object
Returns the value of attribute infix.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#line_items ⇒ Object
Returns the value of attribute line_items.
-
#phone_number ⇒ Object
Returns the value of attribute phone_number.
-
#postal_code ⇒ Object
Returns the value of attribute postal_code.
-
#reference_id ⇒ Object
Returns the value of attribute reference_id.
-
#street ⇒ Object
Returns the value of attribute street.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#add_line_item(args = nil) ⇒ Object
adds a line item of type LineItem to the line_items atribute (array).
-
#create ⇒ Wheretocard::Response
This is the most importent method.
-
#initialize(args = nil) ⇒ Order
constructor
Initializer to transform a
Hash
into an Payment object. -
#submit ⇒ Object
submit the xml to the WtC API url return object is a Wheretocard::Response.
-
#to_xml ⇒ String
(also: #xml)
The xml to send in the SOAP API.
-
#valid? ⇒ Boolean
True/false, depending if this instanciated object is valid.
Constructor Details
#initialize(args = nil) ⇒ Order
Initializer to transform a Hash
into an Payment object
43 44 45 46 47 48 49 50 51 |
# File 'lib/wheretocard/order.rb', line 43 def initialize(args=nil) @line_items = [] @delivery_format = "BARCODE" @delivery_channel = "WEB" return if args.nil? args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end end |
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
27 28 29 |
# File 'lib/wheretocard/order.rb', line 27 def city @city end |
#client ⇒ Object
Returns the value of attribute client.
33 34 35 |
# File 'lib/wheretocard/order.rb', line 33 def client @client end |
#country ⇒ Object
Returns the value of attribute country.
29 30 31 |
# File 'lib/wheretocard/order.rb', line 29 def country @country end |
#delivery_channel ⇒ Object
Returns the value of attribute delivery_channel.
36 37 38 |
# File 'lib/wheretocard/order.rb', line 36 def delivery_channel @delivery_channel end |
#delivery_format ⇒ Object
Returns the value of attribute delivery_format.
35 36 37 |
# File 'lib/wheretocard/order.rb', line 35 def delivery_format @delivery_format end |
#email ⇒ Object
Returns the value of attribute email.
30 31 32 |
# File 'lib/wheretocard/order.rb', line 30 def email @email end |
#errors ⇒ Object
Returns the value of attribute errors.
20 21 22 |
# File 'lib/wheretocard/order.rb', line 20 def errors @errors end |
#first_name ⇒ Object
Returns the value of attribute first_name.
22 23 24 |
# File 'lib/wheretocard/order.rb', line 22 def first_name @first_name end |
#house_number ⇒ Object
Returns the value of attribute house_number.
26 27 28 |
# File 'lib/wheretocard/order.rb', line 26 def house_number @house_number end |
#infix ⇒ Object
Returns the value of attribute infix.
23 24 25 |
# File 'lib/wheretocard/order.rb', line 23 def infix @infix end |
#last_name ⇒ Object
Returns the value of attribute last_name.
24 25 26 |
# File 'lib/wheretocard/order.rb', line 24 def last_name @last_name end |
#line_items ⇒ Object
Returns the value of attribute line_items.
34 35 36 |
# File 'lib/wheretocard/order.rb', line 34 def line_items @line_items end |
#phone_number ⇒ Object
Returns the value of attribute phone_number.
31 32 33 |
# File 'lib/wheretocard/order.rb', line 31 def phone_number @phone_number end |
#postal_code ⇒ Object
Returns the value of attribute postal_code.
28 29 30 |
# File 'lib/wheretocard/order.rb', line 28 def postal_code @postal_code end |
#reference_id ⇒ Object
Returns the value of attribute reference_id.
21 22 23 |
# File 'lib/wheretocard/order.rb', line 21 def reference_id @reference_id end |
#street ⇒ Object
Returns the value of attribute street.
25 26 27 |
# File 'lib/wheretocard/order.rb', line 25 def street @street end |
#value ⇒ Object
Returns the value of attribute value.
32 33 34 |
# File 'lib/wheretocard/order.rb', line 32 def value @value end |
Instance Method Details
#add_line_item(args = nil) ⇒ Object
adds a line item of type LineItem to the line_items atribute (array)
83 84 85 86 87 |
# File 'lib/wheretocard/order.rb', line 83 def add_line_item(args=nil) line_item = Wheretocard::LineItem.new(args) line_items << line_item return line_item end |
#create ⇒ Wheretocard::Response
This is the most importent method. It uses all the attributes and performs a ‘order` action on Wheretocard API.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/wheretocard/order.rb', line 64 def create # if there are any line items, they should all be valid. validate_line_items # make the API call # response = Docdata.client.call(:create, xml: create_xml) # response_object = Docdata::Response.parse(:create, response) if response_object.success? self.key = response_object.key end # set `self` as the value of the `payment` attribute in the response object response_object.payment = self response_object.url = redirect_url return response_object end |
#submit ⇒ Object
submit the xml to the WtC API url return object is a Wheretocard::Response
100 101 102 103 |
# File 'lib/wheretocard/order.rb', line 100 def submit # validate_line_items Wheretocard::Response.from_order_request(self) end |
#to_xml ⇒ String Also known as: xml
Returns the xml to send in the SOAP API.
90 91 92 93 94 95 |
# File 'lib/wheretocard/order.rb', line 90 def to_xml xml_file = "#{File.dirname(__FILE__)}/xml/order_request.xml.erb" template = File.read(xml_file) namespace = OpenStruct.new(order: self, client: client) xml = ERB.new(template).result(namespace.instance_eval { binding }) end |
#valid? ⇒ Boolean
Returns true/false, depending if this instanciated object is valid.
54 55 56 57 |
# File 'lib/wheretocard/order.rb', line 54 def valid? validator = OrderValidator.new validator.valid?(self) end |