Class: SpreeCmCommissioner::Integrations::VireakBuntham::Resources::Booking

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

Overview

Wraps the response of POST /booking/confirm.

Success shape:

{ "header": { "statusCode": 200, "errorText": "{}" },
  "body":   { "transactionId": "VET-TXN-12345", "msg": "Booking confirmed" } }

The header is merged into the body data by Base.from_api_response so this resource can inspect both halves.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_api_response

Constructor Details

#initialize(data) ⇒ Booking

rubocop:disable Lint/MissingSuper



13
14
15
16
17
18
19
20
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 13

def initialize(data) # rubocop:disable Lint/MissingSuper
  header = data['header'] || {}
  @status_code = header['statusCode'].to_i
  @error_text = header['errorText']

  @transaction_id = data['transactionId']
  @msg = data['msg']
end

Instance Attribute Details

#error_textObject

Returns the value of attribute error_text.



11
12
13
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 11

def error_text
  @error_text
end

#msgObject

Returns the value of attribute msg.



11
12
13
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 11

def msg
  @msg
end

#status_codeObject

Returns the value of attribute status_code.



11
12
13
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 11

def status_code
  @status_code
end

#transaction_idObject

Returns the value of attribute transaction_id.



11
12
13
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 11

def transaction_id
  @transaction_id
end

Instance Method Details

#error_messageObject



30
31
32
33
34
35
36
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 30

def error_message
  return nil if success?

  return error_text if error_text.present? && error_text != '{}'

  msg.presence || "Booking failed with status #{status_code}"
end

#failed?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 26

def failed?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 22

def success?
  status_code == 200 && transaction_id.present?
end

#to_hObject



38
39
40
41
42
43
44
45
46
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 38

def to_h
  {
    transaction_id: transaction_id,
    status_code: status_code,
    msg: msg,
    success: success?,
    error_message: error_message
  }
end