Class: Vpago::UserInformers::Firebase
- Inherits:
-
Object
- Object
- Vpago::UserInformers::Firebase
- Defined in:
- app/services/vpago/user_informers/firebase.rb
Instance Attribute Summary collapse
-
#order ⇒ Object
Returns the value of attribute order.
Instance Method Summary collapse
- #document_reference_path ⇒ Object
- #firestore ⇒ Object
- #firestore_reference ⇒ Object
-
#initialize(order) ⇒ Firebase
constructor
A new instance of Firebase.
- #notify(message_code, processing, reason_code = nil, reason_message = nil) ⇒ Object
- #order_is_completed(processing:) ⇒ Object
- #order_is_processing(processing:) ⇒ Object
- #order_process_failed(processing:, reason_code:, reason_message: nil) ⇒ Object
- #payment_is_processing(processing:) ⇒ Object
- #payment_is_refunded(processing:, reason_code:, reason_message: nil) ⇒ Object
- #payment_process_failed(processing:, reason_code:, reason_message: nil) ⇒ Object
- #service_account ⇒ Object
Constructor Details
#initialize(order) ⇒ Firebase
Returns a new instance of Firebase.
8 9 10 |
# File 'app/services/vpago/user_informers/firebase.rb', line 8 def initialize(order) @order = order end |
Instance Attribute Details
#order ⇒ Object
Returns the value of attribute order.
6 7 8 |
# File 'app/services/vpago/user_informers/firebase.rb', line 6 def order @order end |
Instance Method Details
#document_reference_path ⇒ Object
44 45 46 |
# File 'app/services/vpago/user_informers/firebase.rb', line 44 def document_reference_path firestore_reference.path.split('/documents').last end |
#firestore ⇒ Object
48 49 50 |
# File 'app/services/vpago/user_informers/firebase.rb', line 48 def firestore @firestore ||= Google::Cloud::Firestore.new(project_id: service_account[:project_id], credentials: service_account) end |
#firestore_reference ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/services/vpago/user_informers/firebase.rb', line 36 def firestore_reference order_created_date = order.created_at.strftime('%Y-%m-%d') @firestore_reference ||= firestore.col('statuses') .doc('cart') .col(order_created_date) .doc(order.number) end |
#notify(message_code, processing, reason_code = nil, reason_message = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/vpago/user_informers/firebase.rb', line 19 def notify(, processing, reason_code = nil, = nil) order.reload data = { processing: processing, message_code: , reason_code: reason_code, reason_message: , order_state: order.state, payment_state: order.payment_state, updated_at: Time.current }.compact firestore_reference.set(data, merge: true) firestore_reference.col('histories').doc().set(data) end |
#order_is_completed(processing:) ⇒ Object
14 |
# File 'app/services/vpago/user_informers/firebase.rb', line 14 def order_is_completed(processing:) = notify(:order_is_completed, processing) |
#order_is_processing(processing:) ⇒ Object
13 |
# File 'app/services/vpago/user_informers/firebase.rb', line 13 def order_is_processing(processing:) = notify(:order_is_processing, processing) |
#order_process_failed(processing:, reason_code:, reason_message: nil) ⇒ Object
15 |
# File 'app/services/vpago/user_informers/firebase.rb', line 15 def order_process_failed(processing:, reason_code:, reason_message: nil) = notify(:order_process_failed, processing, reason_code, ) |
#payment_is_processing(processing:) ⇒ Object
12 |
# File 'app/services/vpago/user_informers/firebase.rb', line 12 def payment_is_processing(processing:) = notify(:payment_is_processing, processing) |
#payment_is_refunded(processing:, reason_code:, reason_message: nil) ⇒ Object
16 |
# File 'app/services/vpago/user_informers/firebase.rb', line 16 def payment_is_refunded(processing:, reason_code:, reason_message: nil) = notify(:payment_is_refunded, processing, reason_code, ) |
#payment_process_failed(processing:, reason_code:, reason_message: nil) ⇒ Object
17 |
# File 'app/services/vpago/user_informers/firebase.rb', line 17 def payment_process_failed(processing:, reason_code:, reason_message: nil) = notify(:payment_process_failed, processing, reason_code, ) |
#service_account ⇒ Object
52 53 54 |
# File 'app/services/vpago/user_informers/firebase.rb', line 52 def service_account @service_account ||= Rails.application.credentials.cloud_firestore_service_account end |