Class: Vpago::UserInformers::Firebase

Inherits:
Object
  • Object
show all
Defined in:
app/services/vpago/user_informers/firebase.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#orderObject

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_pathObject



44
45
46
# File 'app/services/vpago/user_informers/firebase.rb', line 44

def document_reference_path
  firestore_reference.path.split('/documents').last
end

#firestoreObject



48
49
50
# File 'app/services/vpago/user_informers/firebase.rb', line 48

def firestore
  @firestore ||= Google::Cloud::Firestore.new(project_id: [:project_id], credentials: )
end

#firestore_referenceObject



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(message_code, processing, reason_code = nil, reason_message = nil)
  order.reload

  data = {
    processing: processing,
    message_code: message_code,
    reason_code: reason_code,
    reason_message: 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(message_code).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, reason_message)

#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, reason_message)

#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, reason_message)

#service_accountObject



52
53
54
# File 'app/services/vpago/user_informers/firebase.rb', line 52

def 
   ||= Rails.application.credentials.
end