Skip to content

Instantly share code, notes, and snippets.

@sipple
Created December 10, 2010 20:18
Show Gist options
  • Save sipple/736739 to your computer and use it in GitHub Desktop.
Save sipple/736739 to your computer and use it in GitHub Desktop.
module Webservices
module Responses
module GetOrder
class GetOrderResponse
include Webservices::Responses::ResponseErrorHandler, CulturaldistrictApp::OrderDetails
attr_reader :order, :line_items, :shipping_address, :contributions, :gift_cards,
:redeemed_gift_cards, :gift_card_fees, :parking_line_items, :restaurant_line_items, :package_line_items,
:flex_package_line_items, :package_parking_line_items, :package_restaurant_line_items, :fee_line_items,
:super_package_line_items
expect_errors :empty_order => "TESSITURA_INVALID_ORDER_EXCEPTION",
:seat_locking_error => "TESSITURA_SEAT_LOCKING_EXCEPTION"
PARKING_PRODUCTION_TYPE = 11
RESTAURANT_PRODUCTION_TYPE = 19
def initialize a_raw_response={}
@line_items = []
@contributions = []
@gift_cards = []
@redeemed_gift_cards = []
@parking_line_items = []
@restaurant_line_items = []
@package_line_items = []
@flex_package_line_items = []
@package_parking_line_items= []
@package_restaurant_line_items = []
@gift_card_fees = []
@fee_line_items = []
@super_package_line_items = []
extract_order_from the_inner_part_of a_raw_response if a_raw_response.size > 0
end
private
def extract_line_items(the_response, sub_line_items)
return nil if the_response[:line_item].nil?
[the_response[:line_item]].flatten.each do |line_item|
unless add_on_line_item?(line_item)
item = LineItem.make(line_item)
item.sub_line_items = find_sub_line_items_for(item, sub_line_items)
@line_items << item
end
end
end
def find_sub_line_items_for line_item, sub_line_items
sub_line_items.find_all { |sli| sli.line_item_key == line_item.key }
end
def extract_sub_line_items(the_response)
return nil if the_response[:sub_line_item].nil?
sub_line_items = [the_response[:sub_line_item]].flatten.collect do |sub_line_item|
SubLineItem.make(sub_line_item) unless add_on_line_item?(sub_line_item)
end
sub_line_items.compact
end
def extract_add_on_from(the_response, sub_line_items)
combined_line_items = [the_response[:line_item]].flatten.compact
return nil if combined_line_items.blank?
combined_line_items.each do |line_item|
extract_parking_line_item(line_item, sub_line_items)
extract_restaurant_line_item(line_item, sub_line_items)
end
end
def extract_parking_line_item line_item, sub_line_items
if parking_line_item?(line_item)
item = LineItem.make(line_item)
item.sub_line_items = find_sub_line_items_for(item, sub_line_items)
@parking_line_items << item
end
end
def extract_restaurant_line_item line_item, sub_line_items
if restaurant_line_item?(line_item)
item = LineItem.make(line_item)
item.sub_line_items = find_sub_line_items_for(item, sub_line_items)
@restaurant_line_items << item
end
end
def extract_all_sub_line_items(the_response)
combined_sub_line_items = [the_response[:sub_line_item]].flatten.compact
return nil if combined_sub_line_items.blank?
combined_sub_line_items.collect { |s| SubLineItem.make(s) }.compact
end
def extract_shipping_address(the_response)
return nil if the_response[:shipping_address].nil?
@shipping_address = ShippingAddress.make(the_response[:shipping_address])
end
def extract_contributions_from(the_response)
return nil if the_response[:contribution].nil?
[the_response[:contribution]].flatten.each do |contribution|
@contributions << Contribution.make(contribution)
end
end
def extract_order_from the_response
return if the_response.nil?
@order = Order.make the_response[:order]
extract_line_items(the_response, extract_sub_line_items(the_response))
extract_gift_card_processing_fees_from the_response
extract_shipping_address(the_response)
extract_contributions_from the_response
extract_gift_card_from the_response
extract_add_on_from(the_response, extract_all_sub_line_items(the_response))
extract_exchange_differential_fee_from(the_response)
extract_package_line_items_from the_response[:package_line_item], the_response[:package_sub_line_item]
return order_populated_with_fee_details the_response
end
def extract_exchange_differential_fee_from the_response
exchange_differential_fee = [the_response[:fee]].compact.flatten.select{|fee| fee[:category] == "36"}
@order.exchange_differential_fee = exchange_differential_fee.first[:total_fees].to_f unless exchange_differential_fee.empty?
end
def sub_line_items_for_fees(the_response)
[the_response[:sub_line_item_fee]].flatten.compact.each do |fee_item|
@gift_card_fees << GiftCardFee.make(fee_item) if fee_item[:fee_desc].index("Gift Certificate Fee")
@fee_line_items << FeeLineItem.make(fee_item)
end
end
def extract_gift_card_processing_fees_from the_response
sub_line_items_for_fees(the_response).compact
end
def create_package(line_item, sub_line_items)
package_line_item = PackageLineItem.make line_item
package_line_item.sub_line_items = sub_line_items.find_all { |sli| sli.line_item_key == package_line_item.id }
return package_line_item
end
def create(line_item, sub_line_items)
package_line_item = create_package(line_item, sub_line_items)
if package_line_item.parking?
@package_parking_line_items << package_line_item
elsif package_line_item.restaurant?
@package_restaurant_line_items << package_line_item
else
@package_line_items << package_line_item
end
end
def create_super_package(line_item, sub_line_items, package_line_items_from_the_response)
super_package_line_item = SuperPackageLineItem.make line_item
super_package_line_item.sub_package_line_items = package_line_items_from_the_response.collect do |sub_line_item|
next if sub_line_item[:perf_no] == "0" or sub_line_item[:pkg_li_no] != line_item[:li_no]
create_package(sub_line_item, sub_line_items)
end .compact
@super_package_line_items << super_package_line_item
end
def create_and_fill(package_line_items_from_the_response, sub_line_items)
package_line_items_from_the_response.each do |line_item|
next if (line_item[:perf_no] == "0" or sub_package?(line_item))
create(line_item, sub_line_items)
end
end
def create_and_fill_super_package(package_line_items_from_the_response, sub_line_items)
package_line_items_from_the_response.each do |line_item|
next if (line_item[:super_pkg_ind] == "N")
create_super_package(line_item, sub_line_items, package_line_items_from_the_response)
end
end
def sub_package? line_item
line_item[:pkg_no] != line_item[:super_pkg_no]
end
def extract_package_line_items_from(package_line_items_from_the_response, package_sub_line_items_from_the_response)
return if package_line_items_from_the_response.blank?
sub_line_items = package_sub_line_items_from_the_response.collect { |l| PackageSubLineItem.make l if l[:perf_no] != "0" }.compact
create_and_fill(package_line_items_from_the_response, sub_line_items)
create_and_fill_super_package(package_line_items_from_the_response, sub_line_items)
extract_flex_package
end
def extract_flex_package
@flex_package_line_items = @package_line_items.find_all { |li| li.flex? }
@package_line_items -= @flex_package_line_items
end
def parking_line_item? line_item
line_item[:prod_type].to_i == PARKING_PRODUCTION_TYPE
end
def add_on_line_item? line_item
parking_line_item?(line_item) || restaurant_line_item?(line_item)
end
def restaurant_line_item? line_item
line_item[:prod_type].to_i == RESTAURANT_PRODUCTION_TYPE
end
def parking_sub_line_item? sub_line_item
description = sub_line_item[:seat_type_desc]
!description.blank? and description.downcase.include? "parking"
end
def extract_gift_card_from(the_response)
return nil if the_response[:payment].nil?
[the_response[:payment]].flatten.each do |gift_card|
gift_card[:pmt_amt] = gift_card[:pmt_amt].to_f * -1
gift_card[:pmt_amt] <= 0 ?
@redeemed_gift_cards << Webservices::Responses::CommonResponses::GiftCard.make(gift_card) :
@gift_cards << Webservices::Responses::CommonResponses::GiftCard.make(gift_card)
end
end
def the_inner_part_of a_raw_response
a_raw_response[:get_order_response][:get_order_result][:diffgram][:get_order_results]
end
end
class Order < Webservices::Responses::WSDLObject
number :order_number => :order_no, :customer_number => :customer_no, :shipping_method => :shipping_method, :address_number => :address_no,
:mode_of_sale => :mos
decimal :balance_to_charge => :balance_to_charge, :sub_total => :sub_total, :facility_fee => :handling_charges,
:total => :order_total
string :notes => :notes, :solicitor => :solicitor
attr_accessor :merchandise_fee, :web_fee, :exchange_differential_fee
end
class SubLineItem < Webservices::Responses::WSDLObject
string :seat_row => :seat_row, :seat_number => :seat_num, :section_name => :section_desc
number :line_item_key => :li_seq_no, :production_id => :prod_season_no, :price_type_id => :price_type, :zone_id => :zone_no, :facility_id => :facility_no
decimal :seat_price => :due_amt
end
class LineItem < Webservices::Responses::WSDLObject
string :performance_name => :perf_desc, :facility => :facility_desc, :notes => :notes
date_time :performance_date => :perf_dt
number :key => :li_seq_no, :performance_id => :perf_no, :production_type => :prod_type
attr_accessor :sub_line_items
end
class Contribution < Webservices::Responses::WSDLObject
number :key => :ref_no, :account_id => :on_account_method
decimal :amount => :contribution_amt
end
class ShippingAddress < Webservices::Responses::WSDLObject
string :street1 => :street1, :street2 => :street2, :city => :city, :state => :state,
:postal_code => :postal_code, :country_name => :country_name
number :country_id => :country_id, :id => :address_no
end
class GiftCardFee < Webservices::Responses::WSDLObject
number :id => :id, :fee_number => :fee_no
end
class FeeLineItem < Webservices::Responses::WSDLObject
number :id => :id, :fee_number => :fee_no, :amount => :fee_amt
string :override_indicator => :fee_override_ind
end
class PackageLineItem < Webservices::Responses::WSDLObject
string :package_name => :pkg_desc, :facility => :facility_desc
number :key => :pkg_li_no, :id => :li_seq_no, :season_no => :season_no, :package_id => :pkg_no, :production_type => :prod_type, :performance_id => :perf_no
boolean :flex? => :flex_ind
attr_accessor :sub_line_items
def parking?
!package_name.blank? and package_name.downcase.include? "parking"
end
def restaurant?
production_type == 19
end
end
class PackageSubLineItem < Webservices::Responses::WSDLObject
string :seat_row => :seat_row, :seat_number => :seat_num, :section_name => :section_desc, :zone_description => :zone_desc
number :line_item_key => :li_seq_no, :package_id => :pkg_no, :price_type_id => :price_type, :zone_id => :zone_no
decimal :seat_price => :due_amt
end
class SuperPackageLineItem < PackageLineItem
attr_accessor :sub_package_line_items
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment