Class: SpreeCmCommissioner::Integrations::VireakBuntham::Resources::Booking
- Inherits:
-
Base
- Object
- Base
- SpreeCmCommissioner::Integrations::VireakBuntham::Resources::Booking
- 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
-
#error_text ⇒ Object
Returns the value of attribute error_text.
-
#msg ⇒ Object
Returns the value of attribute msg.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
Instance Method Summary collapse
- #error_message ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(data) ⇒ Booking
constructor
rubocop:disable Lint/MissingSuper.
- #success? ⇒ Boolean
- #to_h ⇒ Object
Methods inherited from Base
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_text ⇒ Object
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 |
#msg ⇒ Object
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_code ⇒ Object
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_id ⇒ Object
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_message ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 30 def return nil if success? return error_text if error_text.present? && error_text != '{}' msg.presence || "Booking failed with status #{status_code}" end |
#failed? ⇒ Boolean
26 27 28 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/booking.rb', line 26 def failed? !success? end |
#success? ⇒ 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_h ⇒ Object
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: } end |