Module: EffectiveQbOnline

Includes:
EffectiveGem
Defined in:
lib/effective_qb_online.rb,
lib/effective_qb_online/engine.rb,
lib/effective_qb_online/version.rb,
lib/generators/effective_qb_online/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Engine

Constant Summary collapse

VERSION =
'0.6.0'.freeze

Class Method Summary collapse

Class Method Details

.api(realm: nil) ⇒ Object



28
29
30
31
32
33
# File 'lib/effective_qb_online.rb', line 28

def self.api(realm: nil)
  realm ||= Effective::QbRealm.first
  return nil if realm.blank?

  Effective::QbApi.new(realm: realm)
end

.config_keysObject



8
9
10
11
12
13
14
# File 'lib/effective_qb_online.rb', line 8

def self.config_keys
  [
    :qb_realms_table_name, :qb_receipts_table_name, :qb_receipt_items_table_name,
    :oauth_client_id, :oauth_client_secret,
    :layout
  ]
end

.oauth2_clientObject



18
19
20
21
22
23
24
25
26
# File 'lib/effective_qb_online.rb', line 18

def self.oauth2_client
  OAuth2::Client.new(
    oauth_client_id,
    oauth_client_secret,
    site: 'https://appcenter.intuit.com/connect/oauth2',
    authorize_url: 'https://appcenter.intuit.com/connect/oauth2',
    token_url: 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer'
  )
end

.skip_order!(order) ⇒ Object



48
49
50
51
52
53
# File 'lib/effective_qb_online.rb', line 48

def self.skip_order!(order)
  raise 'expected a purchased Effective::Order' unless order.kind_of?(Effective::Order) && order.purchased?

  qb_receipt = Effective::QbReceipt.create_from_order!(order)
  qb_receipt.skip!
end

.sync_order!(order, perform_now: false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/effective_qb_online.rb', line 35

def self.sync_order!(order, perform_now: false)
  raise 'expected a purchased Effective::Order' unless order.kind_of?(Effective::Order) && order.purchased?

  if perform_now
    qb_receipt = Effective::QbReceipt.create_from_order!(order)
    qb_receipt.sync!
  else
    QbSyncOrderJob.perform_later(order)
  end

  true
end