effective_qb_online 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/app/controllers/admin/qb_online_controller.rb +1 -1
- data/app/controllers/effective/qb_oauth_controller.rb +4 -4
- data/app/models/effective/qb_api.rb +5 -5
- data/app/models/effective/qb_realm.rb +3 -3
- data/app/models/effective/qb_receipt.rb +5 -4
- data/app/models/effective/qb_sales_receipt.rb +5 -5
- data/app/views/admin/qb_online/_company.html.haml +2 -2
- data/app/views/admin/qb_online/_connect.html.haml +3 -3
- data/app/views/admin/qb_online/index.html.haml +1 -1
- data/app/views/admin/qb_receipts/_form.html.haml +2 -2
- data/config/effective_qb_online.rb +2 -2
- data/lib/effective_qb_online/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f968250054d40c75ee2bc796e410de19045376c8f08677ee687f3490c9e6112b
|
4
|
+
data.tar.gz: 653edff54bf9a9a1eaace903f2b60097c472de077e6617dacf1dd68cf85035da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af13a7eb3903c75dedbcc8cdf234208393fe8f79438321bd7fc9f524c9d3d8c0ba91eb163c494f0919a1127197a0a4d5cf94e18f1417fc6cb7aa4fbd50523213
|
7
|
+
data.tar.gz: 359c596ffac483d5c1599b6008e590a0e58c8127be3ab468a6aab64bcb356035db2dde2de0cb8388bc17f0a5cb4849cac5f6b1424505ea5e5f4c771c1e2ae35f
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Effective
|
1
|
+
# Effective QuickBooks Online
|
2
2
|
|
3
|
-
Create
|
3
|
+
Create QuickBooks Online SalesReceipts for purchased effective orders. This is an unofficial integration that is not supported by or affiliated with Intuit.
|
4
4
|
|
5
5
|
## Getting Started
|
6
6
|
|
@@ -44,7 +44,7 @@ Add a link to the admin menu:
|
|
44
44
|
|
45
45
|
```haml
|
46
46
|
- if can? :admin, :effective_qb_online
|
47
|
-
= nav_link_to '
|
47
|
+
= nav_link_to 'QuickBooks Online', effective_qb_online.admin_quickbooks_path
|
48
48
|
```
|
49
49
|
|
50
50
|
and visit `/admin/quickbooks`.
|
@@ -66,11 +66,11 @@ if user.admin?
|
|
66
66
|
end
|
67
67
|
```
|
68
68
|
|
69
|
-
## Configuring
|
69
|
+
## Configuring QuickBooks Company
|
70
70
|
|
71
|
-
This gem has only been tested with
|
71
|
+
This gem has only been tested with Canadian Quickbooks Online stores.
|
72
72
|
|
73
|
-
It has GST, HST and Tax Exempt tax codes and rates set up ahead of time by
|
73
|
+
It has GST, HST and Tax Exempt tax codes and rates set up ahead of time by QuickBooks.
|
74
74
|
|
75
75
|
## License
|
76
76
|
|
@@ -4,7 +4,7 @@ module Effective
|
|
4
4
|
class QbOauthController < ApplicationController
|
5
5
|
before_action(:authenticate_user!) if defined?(Devise)
|
6
6
|
|
7
|
-
# Any user that has priviledges with the
|
7
|
+
# Any user that has priviledges with the QuickBooks Online company could authenticate
|
8
8
|
# But we assume this user also has admin priviledges on our site
|
9
9
|
# This should only be done once anyway
|
10
10
|
before_action { EffectiveResources.authorize!(self, :admin, :effective_qb_online) }
|
@@ -20,7 +20,7 @@ module Effective
|
|
20
20
|
redirect_to(grant_url)
|
21
21
|
end
|
22
22
|
|
23
|
-
# This matches the
|
23
|
+
# This matches the QuickBooks Redirect URI and we have to set it up ahead of time.
|
24
24
|
def callback
|
25
25
|
return unless params[:code].present? && params[:realmId].present? && params[:state].present?
|
26
26
|
|
@@ -37,7 +37,7 @@ module Effective
|
|
37
37
|
refresh_token_expires_at: (Time.at(token.expires_at) + 100.days)
|
38
38
|
)
|
39
39
|
|
40
|
-
flash[:success] = 'Successfully connected with
|
40
|
+
flash[:success] = 'Successfully connected with QuickBooks Online'
|
41
41
|
|
42
42
|
redirect_to(effective_qb_online.admin_quickbooks_path)
|
43
43
|
end
|
@@ -53,7 +53,7 @@ module Effective
|
|
53
53
|
response = token.post('/o/oauth2/revoke', params: { token: realm.refresh_token })
|
54
54
|
|
55
55
|
if response.status == 200
|
56
|
-
flash[:success] = 'Successfully revoked from
|
56
|
+
flash[:success] = 'Successfully revoked from QuickBooks Online'
|
57
57
|
realm.destroy!
|
58
58
|
else
|
59
59
|
flash[:danger] = 'Unable to revoke'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# The
|
1
|
+
# The QuickBooks namespace comes from quickbooks-ruby gem
|
2
2
|
# https://github.com/ruckus/quickbooks-ruby
|
3
3
|
|
4
4
|
module Effective
|
@@ -135,8 +135,8 @@ module Effective
|
|
135
135
|
with_service('TaxRate') { |service| service.all }
|
136
136
|
end
|
137
137
|
|
138
|
-
# Returns a Hash of
|
139
|
-
# { 0.0 => Quickbooks::Model::TaxCode }
|
138
|
+
# Returns a Hash of BigDecimal.to_s String Tax Rate => TaxCode Object
|
139
|
+
# { '0.0' => 'Quickbooks::Model::TaxCode(Exempt)', '5.0' => 'Quickbooks::Model::TaxCode(GST)' }
|
140
140
|
def taxes_collection
|
141
141
|
rates = tax_rates()
|
142
142
|
codes = tax_codes()
|
@@ -180,10 +180,10 @@ module Effective
|
|
180
180
|
token = OAuth2::AccessToken.new(EffectiveQbOnline.oauth2_client, realm.access_token, refresh_token: realm.refresh_token)
|
181
181
|
yield(token)
|
182
182
|
rescue OAuth2::Error, Quickbooks::AuthorizationFailure => e
|
183
|
-
puts "
|
183
|
+
puts "QuickBooks OAuth Error: #{e.message}"
|
184
184
|
|
185
185
|
attempts += 1
|
186
|
-
raise "unable to refresh
|
186
|
+
raise "unable to refresh QuickBooks OAuth2 token" if attempts >= max_attempts
|
187
187
|
|
188
188
|
# Refresh
|
189
189
|
refreshed = token.refresh!
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# One
|
1
|
+
# One QuickBooks Realm / Company
|
2
2
|
|
3
3
|
module Effective
|
4
4
|
class QbRealm < ActiveRecord::Base
|
5
5
|
|
6
6
|
effective_resource do
|
7
|
-
# As per
|
7
|
+
# As per QuickBooks oAuth
|
8
8
|
realm_id :string
|
9
9
|
|
10
10
|
access_token :text
|
@@ -30,7 +30,7 @@ module Effective
|
|
30
30
|
validates :refresh_token_expires_at, presence: true
|
31
31
|
|
32
32
|
def to_s
|
33
|
-
'
|
33
|
+
'QuickBooks Online Settings'
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -13,7 +13,7 @@ module Effective
|
|
13
13
|
# QuickBooks Customer
|
14
14
|
customer_id :string
|
15
15
|
|
16
|
-
#
|
16
|
+
# QuickBooks Online SalesReceipt id, once sync'd
|
17
17
|
sales_receipt_id :string
|
18
18
|
|
19
19
|
# Any error message from our sync
|
@@ -57,7 +57,7 @@ module Effective
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def sync!(force: false)
|
60
|
-
raise('Already created SalesReceipt with
|
60
|
+
raise('Already created SalesReceipt with QuickBooks Online') if sales_receipt_id.present? && !force
|
61
61
|
save!
|
62
62
|
|
63
63
|
api = EffectiveQbOnline.api
|
@@ -68,13 +68,14 @@ module Effective
|
|
68
68
|
|
69
69
|
# Sanity check
|
70
70
|
if (expected = api.price_to_amount(order.total)) != sales_receipt.total
|
71
|
-
raise("A
|
71
|
+
raise("A QuickBooks Online Sales Receipt has been created with an unexpected total. QuickBooks total is #{sales_receipt.total} but we expected #{expected}. Please adjust the Sales Receipt on QuickBooks")
|
72
72
|
end
|
73
73
|
|
74
74
|
assign_attributes(result: 'completed successfully', sales_receipt_id: sales_receipt.id)
|
75
75
|
complete!
|
76
76
|
rescue => e
|
77
|
-
|
77
|
+
result = [e.message, *("(intuit_tid: #{e.intuit_tid})" if e.try(:intuit_tid).present?)].join(' ')
|
78
|
+
assign_attributes(result: result)
|
78
79
|
error!
|
79
80
|
end
|
80
81
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Effective
|
2
2
|
class QbSalesReceipt
|
3
3
|
|
4
|
-
# Build the
|
4
|
+
# Build the QuickBooks SalesReceipt from a QbReceipt
|
5
5
|
def self.build_from_receipt!(receipt, api: nil)
|
6
6
|
raise('Expected a persisted Effective::QbReceipt') unless receipt.kind_of?(Effective::QbReceipt) && receipt.persisted?
|
7
7
|
|
8
8
|
api ||= EffectiveQbOnline.api
|
9
|
-
raise('Expected a connected
|
9
|
+
raise('Expected a connected QuickBooks API') unless api.present?
|
10
10
|
|
11
11
|
order = receipt.order
|
12
12
|
raise('Expected a purchased Effective::Order') unless order.purchased?
|
@@ -39,7 +39,7 @@ module Effective
|
|
39
39
|
end
|
40
40
|
|
41
41
|
if item.blank?
|
42
|
-
raise("Unknown
|
42
|
+
raise("Unknown QuickBooks Item for #{purchasable} (#{purchasable.class.name} ##{purchasable.id})")
|
43
43
|
end
|
44
44
|
|
45
45
|
receipt_item.update!(item_id: item.id)
|
@@ -54,7 +54,7 @@ module Effective
|
|
54
54
|
# Receipt
|
55
55
|
sales_receipt = Quickbooks::Model::SalesReceipt.new(
|
56
56
|
customer_id: receipt.customer_id,
|
57
|
-
deposit_to_account_id: api.realm.deposit_to_account_id, # The ID of the Account Entity you want
|
57
|
+
deposit_to_account_id: api.realm.deposit_to_account_id, # The ID of the Account Entity you want the SalesReceipt to be deposited to
|
58
58
|
payment_method_id: api.realm.payment_method_id, # The ID of the PaymentMethod Entity
|
59
59
|
payment_ref_number: order.to_param, # Optional payment reference number/string
|
60
60
|
txn_date: order.purchased_at.to_date,
|
@@ -64,7 +64,7 @@ module Effective
|
|
64
64
|
email_status: 'EmailSent'
|
65
65
|
)
|
66
66
|
|
67
|
-
# Allows
|
67
|
+
# Allows QuickBooks to auto-generate the transaction number
|
68
68
|
sales_receipt.auto_doc_number!
|
69
69
|
|
70
70
|
# Addresses
|
@@ -11,9 +11,9 @@
|
|
11
11
|
%td= company_info.country
|
12
12
|
|
13
13
|
%tr
|
14
|
-
%td
|
14
|
+
%td QuickBooks Online
|
15
15
|
%td
|
16
|
-
= link_to('Revoke Access and Disconnect', effective_qb_online.revoke_quickbooks_oauth_path, class: 'btn btn-sm btn-danger', 'data-method': 'delete', 'data-confirm': 'Really disconnect from
|
16
|
+
= link_to('Revoke Access and Disconnect', effective_qb_online.revoke_quickbooks_oauth_path, class: 'btn btn-sm btn-danger', 'data-method': 'delete', 'data-confirm': 'Really disconnect from QuickBooks Online?')
|
17
17
|
|
18
18
|
%tr
|
19
19
|
%td Deposit to Account
|
@@ -1,5 +1,5 @@
|
|
1
1
|
%p Welcome!
|
2
|
-
%p Please click below to connect this website with your
|
2
|
+
%p Please click below to connect this website with your QuickBooks Online company.
|
3
3
|
|
4
4
|
%p
|
5
5
|
= link_to(effective_qb_online.quickbooks_oauth_path) do
|
@@ -7,11 +7,11 @@
|
|
7
7
|
|
8
8
|
%p
|
9
9
|
If it's not connecting, make sure the
|
10
|
-
|
10
|
+
QuickBooks Application has the correct Redirect URI.
|
11
11
|
|
12
12
|
%ul
|
13
13
|
%li The url is: #{effective_qb_online.quickbooks_oauth_callback_url}
|
14
14
|
|
15
15
|
%p
|
16
|
-
Once connected, a
|
16
|
+
Once connected, a QuickBooks Online Sales Receipt
|
17
17
|
will be created when an order is purchased.
|
@@ -11,7 +11,7 @@
|
|
11
11
|
= f.static_field :updated_at
|
12
12
|
|
13
13
|
= f.static_field :status
|
14
|
-
= f.static_field :result, label: '
|
14
|
+
= f.static_field :result, label: 'QuickBooks Online Result'
|
15
15
|
|
16
16
|
%table.table.table-sm
|
17
17
|
%thead
|
@@ -19,7 +19,7 @@
|
|
19
19
|
%th Id
|
20
20
|
%th Order Item
|
21
21
|
%th Existing Name
|
22
|
-
%th
|
22
|
+
%th QuickBooks Online Item
|
23
23
|
|
24
24
|
%tbody
|
25
25
|
- items_collection = EffectiveQbOnline.api.items_collection
|
@@ -7,12 +7,12 @@ EffectiveQbOnline.setup do |config|
|
|
7
7
|
# Configure the Layout per controller, or all at once
|
8
8
|
# config.layout = { application: 'application', admin: 'admin' }
|
9
9
|
|
10
|
-
#
|
10
|
+
# QuickBooks Online Application
|
11
11
|
# Client and Seceret
|
12
12
|
config.oauth_client_id = ENV['QUICKBOOKS_ONLINE_OAUTH_CLIENT_ID']
|
13
13
|
config.oauth_client_secret = ENV['QUICKBOOKS_ONLINE_OAUTH_CLIENT_SECRET']
|
14
14
|
|
15
|
-
#
|
15
|
+
# QuickBooks API
|
16
16
|
# https://github.com/ruckus/quickbooks-ruby
|
17
17
|
Quickbooks.sandbox_mode = (ENV['QUICKBOOKS_ONLINE_SANDBOX'].to_s == 'true')
|
18
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_qb_online
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -192,7 +192,7 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
-
description: Create
|
195
|
+
description: Create QuickBooks Online SalesReceipts for purchased effective orders
|
196
196
|
email:
|
197
197
|
- info@codeandeffect.com
|
198
198
|
executables: []
|
@@ -259,5 +259,5 @@ requirements: []
|
|
259
259
|
rubygems_version: 3.1.2
|
260
260
|
signing_key:
|
261
261
|
specification_version: 4
|
262
|
-
summary: Create
|
262
|
+
summary: Create QuickBooks Online SalesReceipts for purchased effective orders
|
263
263
|
test_files: []
|