Class: SpreeCmCommissioner::Integrations::VireakBuntham

Inherits:
SpreeCmCommissioner::Integration show all
Defined in:
app/models/spree_cm_commissioner/integrations/vireak_buntham.rb

Defined Under Namespace

Modules: ExternalClient, Inventory, Polling, Resources, SyncStrategies Classes: SyncManager

Constant Summary collapse

ROUTE_TYPES =

VET API requires a ‘type` parameter to scope responses to a vehicle category. Each VireakBuntham integration instance represents one category.

{ bus: 1, ferry: 2, air_bus: 3 }.freeze

Instance Method Summary collapse

Methods inherited from SpreeCmCommissioner::Integration

#hold_inventory!, #release_inventory!, #supports_auto_release_inventory?, #supports_external_inventory_holding?

Instance Method Details

#clientObject

Lazy-loaded HTTP client instance for all VET API calls.



71
72
73
# File 'app/models/spree_cm_commissioner/integrations/vireak_buntham.rb', line 71

def client
  @client ||= SpreeCmCommissioner::Integrations::VireakBuntham::ExternalClient::Client.new(integration: self)
end

#external_inventory_item_status(order, options) ⇒ Object

Check seat availability and pricing for specific trip/date/nationality from VET.



62
63
64
65
66
67
68
# File 'app/models/spree_cm_commissioner/integrations/vireak_buntham.rb', line 62

def external_inventory_item_status(order, options)
  SpreeCmCommissioner::Integrations::VireakBuntham::Inventory::ExternalInventoryItemStatus.new.call(
    integration: self,
    order: order,
    options: options
  )
end

#external_inventory_items(order) ⇒ Object

Fetch available seats and prices from VET for order’s trips.



54
55
56
57
58
59
# File 'app/models/spree_cm_commissioner/integrations/vireak_buntham.rb', line 54

def external_inventory_items(order)
  SpreeCmCommissioner::Integrations::VireakBuntham::Inventory::ExternalInventoryItems.new.call(
    integration: self,
    order: order
  )
end

#restock_external_inventory!(_order, _line_items) ⇒ Object



39
40
41
# File 'app/models/spree_cm_commissioner/integrations/vireak_buntham.rb', line 39

def restock_external_inventory!(_order, _line_items)
  raise SpreeCmCommissioner::Integrations::SyncError, 'Booking cannot be cancelled once confirmed'
end

#route_type_nameObject



15
16
17
# File 'app/models/spree_cm_commissioner/integrations/vireak_buntham.rb', line 15

def route_type_name
  ROUTE_TYPES.key(route_type.to_i)
end

#sync_item_availability!(options = {}) ⇒ Object

Sync trip prices and reserved seats from VET via GET /schedule/list + /seat/unavailable APIs.



44
45
46
47
48
49
50
51
# File 'app/models/spree_cm_commissioner/integrations/vireak_buntham.rb', line 44

def sync_item_availability!(options = {})
  SpreeCmCommissioner::Integrations::VireakBuntham::Polling::SyncItemAvailability.new(
    integration: self
  ).call(
    trip_id: options[:trip_id],
    on_date: options[:on_date]
  )
end

#sync_managerObject



24
25
26
# File 'app/models/spree_cm_commissioner/integrations/vireak_buntham.rb', line 24

def sync_manager
  SpreeCmCommissioner::Integrations::VireakBuntham::SyncManager.new(integration: self)
end

#unstock_external_inventory!(order, line_items) ⇒ Object

Confirm and finalize booking on VET: POST /booking/confirm + /booking/complete in atomic transaction.



29
30
31
32
33
34
35
36
37
# File 'app/models/spree_cm_commissioner/integrations/vireak_buntham.rb', line 29

def unstock_external_inventory!(order, line_items)
  result = SpreeCmCommissioner::Integrations::VireakBuntham::Inventory::UnstockInventory.new.call(
    integration: self,
    order: order,
    line_items: line_items
  )

  raise SpreeCmCommissioner::Integrations::SyncError, result.error unless result.success?
end

#vet_type_paramObject

VET ‘type` query param used by /destination/from, /schedule/list, /schedule/listByDate



20
21
22
# File 'app/models/spree_cm_commissioner/integrations/vireak_buntham.rb', line 20

def vet_type_param
  route_type.to_i
end