Class: SpreeCmCommissioner::Integrations::Larryta::Resources::Booking

Inherits:
Base
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb

Overview

Represents a confirmed booking from Larryta API

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_api_response

Constructor Details

#initialize(data) ⇒ Booking

rubocop:disable Lint/MissingSuper



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 10

def initialize(data) # rubocop:disable Lint/MissingSuper
  @booking_code = data['booking_code']
  @booking_date = data['booking_date']
  @payment_date = data['pay_date']
  @booking_status = data['booking_status']
  @payment_status = data['payment_status']
  @total_amount = data['total_amount']
  @currency = data['currency']
  @passenger_name = data.dig('customer', 'full_name')
  @departure_time = data['departure_time']
  @arrival_time = data['arrival_time']
  @departure_date = data['departure_date']
  @seat_number = data['seat_nums']
  @bus_type = data['bus_type']
  @status = data['status']
  @msg = data['msg']

  direction = data['direction'] || {}
  @direction_info = {
    from_location: direction['from_location'],
    to_location: direction['to_location']
  }
end

Instance Attribute Details

#arrival_timeObject

Returns the value of attribute arrival_time.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def arrival_time
  @arrival_time
end

#booking_codeObject

Returns the value of attribute booking_code.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def booking_code
  @booking_code
end

#booking_dateObject

Returns the value of attribute booking_date.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def booking_date
  @booking_date
end

#booking_statusObject

Returns the value of attribute booking_status.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def booking_status
  @booking_status
end

#bus_typeObject

Returns the value of attribute bus_type.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def bus_type
  @bus_type
end

#currencyObject

Returns the value of attribute currency.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def currency
  @currency
end

#departure_dateObject

Returns the value of attribute departure_date.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def departure_date
  @departure_date
end

#departure_timeObject

Returns the value of attribute departure_time.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def departure_time
  @departure_time
end

#direction_infoObject (readonly)

Returns the value of attribute direction_info.



8
9
10
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 8

def direction_info
  @direction_info
end

#msgObject

Returns the value of attribute msg.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def msg
  @msg
end

#passenger_nameObject

Returns the value of attribute passenger_name.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def passenger_name
  @passenger_name
end

#payment_dateObject

Returns the value of attribute payment_date.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def payment_date
  @payment_date
end

#payment_statusObject

Returns the value of attribute payment_status.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def payment_status
  @payment_status
end

#seat_numberObject

Returns the value of attribute seat_number.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def seat_number
  @seat_number
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def status
  @status
end

#total_amountObject

Returns the value of attribute total_amount.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4

def total_amount
  @total_amount
end

Instance Method Details

#confirmed?Boolean

Returns true if the booking was confirmed successfully

Returns:

  • (Boolean)


40
41
42
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 40

def confirmed?
  booking_status&.include?('Confirmed') && payment_status&.include?('Paid')
end

#display_nameObject

Returns the display name for this booking



72
73
74
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 72

def display_name
  "#{passenger_name} - #{booking_code} (#{from_location}#{to_location})"
end

#error_messageObject

Returns the error message if failed



55
56
57
58
59
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 55

def error_message
  return msg if failed?

  nil
end

#failed?Boolean

Returns true if the booking failed

Returns:

  • (Boolean)


50
51
52
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 50

def failed?
  !confirmed? && !pending?
end

#from_locationObject

Returns the from location name



62
63
64
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 62

def from_location
  direction_info[:from_location]
end

#idObject

Returns the booking ID



35
36
37
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 35

def id
  booking_code
end

#pending?Boolean

Returns true if the booking is pending

Returns:

  • (Boolean)


45
46
47
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 45

def pending?
  booking_status == 'Pending' || payment_status == 'Unpaid'
end

#pricing_summaryObject

Returns pricing summary



77
78
79
80
81
82
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 77

def pricing_summary
  {
    total_amount: total_amount,
    currency: currency
  }
end

#to_hObject

Returns a hash representation



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 85

def to_h
  {
    id: id,
    booking_code: booking_code,
    booking_date: booking_date,
    payment_date: payment_date,
    booking_status: booking_status,
    payment_status: payment_status,
    confirmed: confirmed?,
    pending: pending?,
    failed: failed?,
    error_message: error_message,
    total_amount: total_amount,
    currency: currency,
    passenger_name: passenger_name,
    departure_time: departure_time,
    arrival_time: arrival_time,
    seat_number: seat_number,
    bus_type: bus_type,
    from_location: from_location,
    to_location: to_location,
    display_name: display_name,
    pricing: pricing_summary,
    status: status,
    message: msg
  }
end

#to_locationObject

Returns the to location name



67
68
69
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 67

def to_location
  direction_info[:to_location]
end