Class: Centaman::Service::PurchaseTicket

Inherits:
Centaman::Service show all
Defined in:
lib/centaman/service/purchase_ticket.rb

Constant Summary

Constants inherited from Centaman::Service

DEFAULT_TIMEOUT_TIME

Constants inherited from Wrapper

Wrapper::FIXIE

Instance Attribute Summary collapse

Attributes inherited from Wrapper

#api_password, #api_token, #api_username

Instance Method Summary collapse

Methods inherited from Centaman::Service

#after_post, #fetch_all, #payload, #payload_key, #post, #wrap_request_in_case_of_timeout

Methods inherited from Wrapper

#generate_token, #headers, #initialize, #options

Constructor Details

This class inherits a constructor from Centaman::Wrapper

Instance Attribute Details

#booking_timeObject (readonly)

Returns the value of attribute booking_time.



3
4
5
# File 'lib/centaman/service/purchase_ticket.rb', line 3

def booking_time
  @booking_time
end

#booking_typeObject (readonly)

Returns the value of attribute booking_type.



3
4
5
# File 'lib/centaman/service/purchase_ticket.rb', line 3

def booking_type
  @booking_type
end

#checkout_serviceObject (readonly)

Returns the value of attribute checkout_service.



3
4
5
# File 'lib/centaman/service/purchase_ticket.rb', line 3

def checkout_service
  @checkout_service
end

#contactObject (readonly)

Returns the value of attribute contact.



3
4
5
# File 'lib/centaman/service/purchase_ticket.rb', line 3

def contact
  @contact
end

#order_infoObject (readonly)

Returns the value of attribute order_info.



3
4
5
# File 'lib/centaman/service/purchase_ticket.rb', line 3

def order_info
  @order_info
end

#payment_referenceObject (readonly)

Returns the value of attribute payment_reference.



3
4
5
# File 'lib/centaman/service/purchase_ticket.rb', line 3

def payment_reference
  @payment_reference
end

#ticketsObject (readonly)

Returns the value of attribute tickets.



3
4
5
# File 'lib/centaman/service/purchase_ticket.rb', line 3

def tickets
  @tickets
end

Instance Method Details

#after_init(args) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/centaman/service/purchase_ticket.rb', line 6

def after_init(args)
  @booking_type = args[:booking_type]
  @booking_time = args[:booking_time]
  @tickets = args[:tickets]
  @payment_reference = args[:payment_reference]
  @contact = args[:contact]
  @order_info = args[:order_info]
  @checkout_service = args[:checkout_service]
end

#endpointObject



16
17
18
# File 'lib/centaman/service/purchase_ticket.rb', line 16

def endpoint
  '/ticket_services/TimedTicketTransaction'
end

#options_hash_no_jsonObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/centaman/service/purchase_ticket.rb', line 38

def options_hash_no_json
  [
    {
      "Item" => tickets_payload,
      "TimedTicketTypeId" => booking_time.id,
      "TimedTicketTypeDescription" => "#{contact.last_name}, #{contact.first_name}",
      "BookingTypeId" => booking_type.booking_type_id,
      "StartDate" => booking_time.start_date.strftime('%Y-%m-%d'),
      # "StartTime" => booking_time.start_time,
      "EndTime" => booking_time.end_time,
      "PaymentReference" => payment_reference,
      "BookingCost" => total_after_discounts.round(2),
      "TotalPaid" => total_paid.round(2),
      "TaxPaid" => total_taxes.round(2),
      "TransactionDate" => Date.today.strftime('%Y-%m-%d'),
      "BookingContactID" => contact.member_code,
      "TotalTickets" => total_tickets,
      # "BalanceAmount" => nil,
      # "ReceiptNo" => nil,
      # "BookingId" => nil
    }
  ]
end

#tickets_payloadObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/centaman/service/purchase_ticket.rb', line 20

def tickets_payload
  calculators.map do |calculator|
    ticket_hash = {
      'ItemDescription' => calculator.description,
      'ItemCode' => calculator.id,
      'Quantity' => calculator.quantity,
      'ItemCost' => calculator.price_per_after_online_discount,
      'TotalPaid' => calculator.total_per,
      'TaxPaid' => calculator.taxes_per,
      'AttendeeName' => '',
      # 'Barcode' => nil,
      'IsExtraItem' => calculator.is_extra?,
      'CouponCode' => order_info.coupon_service.centaman_coupon_code || ''
    }
    ticket_hash
  end
end