effective_qb_online 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41c564325389352ce139af8d840c39d3f5ffaa132efd7f8bb72c5d7fe28927af
4
- data.tar.gz: 505c8393cf0e7a06b6a687ccebda7c510f9590a248cc111e4c524027cb9b8163
3
+ metadata.gz: 1a31723c72961dc0ba5993baddd7ac885b7ecd7af18faeafdfb013b9a7e5b7c9
4
+ data.tar.gz: 4b7b95d44a3781909dcf3c37cab321e4d9a1f0cafb4955e72427dfc48e2062a2
5
5
  SHA512:
6
- metadata.gz: 06fd5e50780c61176aaf4df670888855cd7590a5fb9f949d2a5d50686e2c077e8719c1a454327d2c6f82721ecf596fd0ed2f0c8d1ce4a056293d9f40c1bd11c5
7
- data.tar.gz: da8ba5c9871f8988a4e2d74393779ebd9b0b4e97c5fa4b8d65304d264556cfe1d1d1078c4d0ec3d049d48d6232d416651054f52a8beb1a27450037cee52576fe
6
+ metadata.gz: 7836b7fe029d1235578a0eaa8c5baf2585a32af0c506a212ddbd14a8a57b6b02e35515de488249045876227489e3a128979609cf03a9de77780936f71b035c6c
7
+ data.tar.gz: 4dea0b635bfd1fcb76f2b31ceab639bb721dabbf661d73a4e24eeb553b615fac1720f19491be26d1eef0536ada3da07fa9d74a11f08c01c0ea4f69e937edc463
@@ -1,3 +1,3 @@
1
1
  //= link_directory ../javascripts .js
2
2
  //= link_directory ../stylesheets .css
3
- //= link_tree ../images
3
+ //= link_directory ../images/effective_qb_online
@@ -0,0 +1,4 @@
1
+ <svg width="223" height="36" viewBox="0 0 223 36" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <rect width="223" height="36" rx="4" fill="#2CA01C"/>
3
+ <path d="M35.3116 14.112C34.4156 12.928 32.6716 12.384 31.1996 12.384C27.7116 12.384 25.0556 14.672 25.0556 18.304C25.0556 21.84 27.5676 24.288 31.1036 24.288C33.0236 24.288 34.4956 23.552 35.4876 22.304L33.8716 21.168C33.2956 21.952 32.3356 22.48 31.1196 22.48C28.7836 22.48 27.2796 20.768 27.2796 18.304C27.2796 15.968 28.8636 14.16 31.1996 14.16C32.1116 14.16 33.1836 14.512 33.7756 15.328L35.3116 14.112ZM36.0087 20.128C36.0087 22.544 37.8647 24.224 40.1847 24.224C42.5047 24.224 44.3607 22.544 44.3607 20.128C44.3607 17.712 42.5047 16.096 40.1847 16.096C37.8647 16.096 36.0087 17.712 36.0087 20.128ZM37.9607 20.128C37.9607 18.928 38.6647 17.664 40.1847 17.664C41.7047 17.664 42.4087 18.928 42.4087 20.128C42.4087 21.328 41.7047 22.624 40.1847 22.624C38.6647 22.624 37.9607 21.328 37.9607 20.128ZM46.2223 24H48.1423V19.776C48.1423 18.752 48.7183 17.696 49.9343 17.696C51.1663 17.696 51.3743 18.832 51.3743 19.744V24H53.2943V19.2C53.2943 17.632 52.4623 16.096 50.4623 16.096C49.3263 16.096 48.4143 16.784 48.0783 17.552H48.0463V16.32H46.2223V24ZM55.5348 24H57.4548V19.776C57.4548 18.752 58.0308 17.696 59.2468 17.696C60.4788 17.696 60.6868 18.832 60.6868 19.744V24H62.6068V19.2C62.6068 17.632 61.7748 16.096 59.7748 16.096C58.6388 16.096 57.7268 16.784 57.3908 17.552H57.3588V16.32H55.5348V24ZM66.3193 19.392C66.3993 18.32 67.3113 17.536 68.4473 17.536C69.6953 17.536 70.2553 18.4 70.2553 19.392H66.3193ZM72.1753 20.256C72.1753 17.488 70.6073 16.096 68.4633 16.096C66.1433 16.096 64.3993 17.728 64.3993 20.208C64.3993 22.704 66.1593 24.224 68.5273 24.224C69.9833 24.224 71.0713 23.712 71.8233 22.688L70.5433 21.664C70.1113 22.272 69.4713 22.656 68.5113 22.656C67.3913 22.656 66.3993 21.856 66.3193 20.768H72.1593C72.1753 20.592 72.1753 20.432 72.1753 20.256ZM80.5948 17.296C79.9868 16.544 78.8188 16.096 77.6988 16.096C75.4428 16.096 73.5868 17.664 73.5868 20.16C73.5868 22.72 75.4748 24.224 77.7468 24.224C78.8828 24.224 79.9388 23.84 80.5788 23.152L79.3788 21.936C79.0108 22.384 78.3548 22.624 77.7628 22.624C76.3068 22.624 75.5868 21.36 75.5868 20.16C75.5868 18.96 76.2908 17.696 77.6988 17.696C78.3228 17.696 78.9788 18.016 79.2828 18.448L80.5948 17.296ZM82.0873 17.856V21.44C82.0873 22.912 82.5513 24.16 84.5833 24.16C85.0153 24.16 85.5273 24.08 85.8633 23.952L85.7993 22.448C85.5753 22.56 85.2393 22.608 84.9833 22.608C84.1353 22.608 83.9753 22.112 83.9753 21.424V17.856H85.8953V16.32H83.9753V14.096H82.0873V16.32H80.7433V17.856H82.0873ZM91.5248 17.856V21.44C91.5248 22.912 91.9888 24.16 94.0208 24.16C94.4528 24.16 94.9648 24.08 95.3008 23.952L95.2368 22.448C95.0128 22.56 94.6768 22.608 94.4208 22.608C93.5728 22.608 93.4128 22.112 93.4128 21.424V17.856H95.3328V16.32H93.4128V14.096H91.5248V16.32H90.1808V17.856H91.5248ZM96.2743 20.128C96.2743 22.544 98.1303 24.224 100.45 24.224C102.77 24.224 104.626 22.544 104.626 20.128C104.626 17.712 102.77 16.096 100.45 16.096C98.1303 16.096 96.2743 17.712 96.2743 20.128ZM98.2263 20.128C98.2263 18.928 98.9303 17.664 100.45 17.664C101.97 17.664 102.674 18.928 102.674 20.128C102.674 21.328 101.97 22.624 100.45 22.624C98.9303 22.624 98.2263 21.328 98.2263 20.128ZM122.792 22.368H119.992V22.336C121 21.616 122.008 20.224 122.008 18.192C122.008 14.752 119.464 12.384 115.992 12.384C112.52 12.384 109.928 14.752 109.928 18.192C109.928 21.872 112.344 24 115.96 24H122.792V22.368ZM115.992 14.192C118.28 14.192 119.816 15.888 119.816 18.192C119.816 20.608 118.2 22.24 115.96 22.24C113.688 22.24 112.136 20.608 112.136 18.192C112.136 15.888 113.8 14.192 115.992 14.192ZM131.121 16.32H129.201V20.544C129.201 21.568 128.625 22.624 127.409 22.624C126.177 22.624 125.969 21.488 125.969 20.576V16.32H124.049V21.12C124.049 22.688 124.881 24.224 126.881 24.224C128.017 24.224 128.929 23.536 129.265 22.768H129.297V24H131.121V16.32ZM133.457 24H135.377V16.32H133.457V24ZM133.185 13.712C133.185 14.32 133.697 14.864 134.401 14.864C135.105 14.864 135.649 14.368 135.649 13.712C135.649 13.056 135.105 12.56 134.401 12.56C133.697 12.56 133.185 13.104 133.185 13.712ZM144.267 17.296C143.659 16.544 142.491 16.096 141.371 16.096C139.115 16.096 137.259 17.664 137.259 20.16C137.259 22.72 139.147 24.224 141.419 24.224C142.555 24.224 143.611 23.84 144.251 23.152L143.051 21.936C142.683 22.384 142.027 22.624 141.435 22.624C139.979 22.624 139.259 21.36 139.259 20.16C139.259 18.96 139.963 17.696 141.371 17.696C141.995 17.696 142.651 18.016 142.955 18.448L144.267 17.296ZM145.551 24H147.471V20.064H147.519L150.559 24H153.103L149.567 19.792L152.895 16.32H150.431L147.519 19.552H147.471V11.904H145.551V24ZM154.303 24H158.383C160.527 24 162.671 23.168 162.671 20.704C162.671 19.184 161.647 18.224 160.223 18.032V18C161.391 17.648 162.191 16.8 162.191 15.52C162.191 13.456 160.431 12.672 158.719 12.672H154.303V24ZM156.319 14.336H157.935C159.455 14.336 160.175 14.736 160.175 15.744C160.175 16.72 159.455 17.28 158.111 17.28H156.319V14.336ZM156.319 19.008H158.207C159.839 19.008 160.655 19.424 160.655 20.608C160.655 22.096 159.167 22.304 158.127 22.304H156.319V19.008ZM164.118 20.128C164.118 22.544 165.974 24.224 168.294 24.224C170.614 24.224 172.47 22.544 172.47 20.128C172.47 17.712 170.614 16.096 168.294 16.096C165.974 16.096 164.118 17.712 164.118 20.128ZM166.07 20.128C166.07 18.928 166.774 17.664 168.294 17.664C169.814 17.664 170.518 18.928 170.518 20.128C170.518 21.328 169.814 22.624 168.294 22.624C166.774 22.624 166.07 21.328 166.07 20.128ZM173.884 20.128C173.884 22.544 175.74 24.224 178.06 24.224C180.38 24.224 182.236 22.544 182.236 20.128C182.236 17.712 180.38 16.096 178.06 16.096C175.74 16.096 173.884 17.712 173.884 20.128ZM175.836 20.128C175.836 18.928 176.54 17.664 178.06 17.664C179.58 17.664 180.284 18.928 180.284 20.128C180.284 21.328 179.58 22.624 178.06 22.624C176.54 22.624 175.836 21.328 175.836 20.128ZM184.129 24H186.049V20.064H186.097L189.137 24H191.681L188.145 19.792L191.473 16.32H189.009L186.097 19.552H186.049V11.904H184.129V24ZM198.147 17.264C197.523 16.48 196.371 16.096 195.267 16.096C193.747 16.096 192.211 16.832 192.211 18.544C192.211 19.984 193.347 20.448 194.483 20.72C195.651 20.992 196.243 21.184 196.243 21.824C196.243 22.512 195.571 22.736 195.011 22.736C194.179 22.736 193.459 22.32 193.043 21.776L191.779 22.96C192.515 23.776 193.747 24.224 194.931 24.224C196.611 24.224 198.131 23.536 198.131 21.664C198.131 20.16 196.787 19.648 195.651 19.376C194.579 19.12 193.987 18.96 193.987 18.368C193.987 17.76 194.611 17.536 195.219 17.536C195.923 17.536 196.563 17.92 196.899 18.368L198.147 17.264Z" fill="white"/>
4
+ </svg>
@@ -5,15 +5,9 @@ module Admin
5
5
 
6
6
  include Effective::CrudController
7
7
 
8
- page_title 'Quickbooks Online'
9
-
10
8
  # /admin/quickbooks
11
9
  def index
12
- @api = EffectiveQbOnline.api
13
-
14
- authorize! :index, Effective::QbRealm
15
-
16
- render(@api.present? ? 'index' : 'instructions')
10
+ @page_title = 'Quickbooks Online'
17
11
  end
18
12
 
19
13
  end
@@ -10,7 +10,7 @@ module Effective
10
10
  before_action { EffectiveResources.authorize!(self, :admin, :effective_qb_online) }
11
11
 
12
12
  def authorize
13
- grant_url = EffectiveQbOnline.oauth2_client.auth_code.authorize_url(
13
+ grant_url = client.auth_code.authorize_url(
14
14
  redirect_uri: redirect_uri,
15
15
  response_type: 'code',
16
16
  state: SecureRandom.hex(12),
@@ -24,7 +24,7 @@ module Effective
24
24
  def callback
25
25
  return unless params[:code].present? && params[:realmId].present? && params[:state].present?
26
26
 
27
- token = EffectiveQbOnline.oauth2_client.auth_code.get_token(params[:code], redirect_uri: redirect_uri)
27
+ token = client.auth_code.get_token(params[:code], redirect_uri: redirect_uri)
28
28
  return unless token
29
29
 
30
30
  realm = Effective::QbRealm.all.first_or_initialize
@@ -42,8 +42,32 @@ module Effective
42
42
  redirect_to(effective_qb_online.admin_quickbooks_path)
43
43
  end
44
44
 
45
+ def revoke
46
+ realm = EffectiveQbOnline.api.realm
47
+ return unless realm
48
+
49
+ # Instantiate the token
50
+ token = OAuth2::AccessToken.new(client, realm.access_token, refresh_token: realm.refresh_token)
51
+
52
+ # Revoke
53
+ response = token.post('/o/oauth2/revoke', params: { token: realm.refresh_token })
54
+
55
+ if response.status == 200
56
+ flash[:success] = 'Successfully revoked from Quickbooks Online'
57
+ realm.destroy!
58
+ else
59
+ flash[:danger] = 'Unable to revoke'
60
+ end
61
+
62
+ redirect_to(effective_qb_online.admin_quickbooks_path)
63
+ end
64
+
45
65
  private
46
66
 
67
+ def client
68
+ EffectiveQbOnline.oauth2_client
69
+ end
70
+
47
71
  def redirect_uri
48
72
  effective_qb_online.quickbooks_oauth_callback_url
49
73
  end
@@ -6,7 +6,7 @@ module EffectiveQbOnlineHelper
6
6
  orders = Effective::Order.purchased.sorted.includes(:user).where.not(id: existing)
7
7
 
8
8
  orders.map do |order|
9
- label = "#{order} - #{order.user} - #{price_to_currency(order.total)}"
9
+ label = "#{order} - #{order.billing_name} - #{order.email} - #{price_to_currency(order.total)}"
10
10
  [label, order.to_param]
11
11
  end
12
12
 
@@ -11,8 +11,9 @@
11
11
  %td= company_info.country
12
12
 
13
13
  %tr
14
- %td OAuth2 Connection
15
- %td= link_to('Reconnect to Quickbooks Online', effective_qb_online.quickbooks_oauth_path)
14
+ %td Quickbooks Online
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 Quickbooks Online?')
16
17
 
17
18
  %tr
18
19
  %td Deposit to Account
@@ -0,0 +1,17 @@
1
+ %p Welcome!
2
+ %p Please click below to connect this website with your Quickbooks Online company.
3
+
4
+ %p
5
+ = link_to(effective_qb_online.quickbooks_oauth_path) do
6
+ = image_tag('effective_qb_online/C2QB_green_btn_med_default.svg')
7
+
8
+ %p
9
+ If it's not connecting, make sure the
10
+ Quickbooks Application has the correct Redirect URI.
11
+
12
+ %ul
13
+ %li The url is: #{effective_qb_online.quickbooks_oauth_callback_url}
14
+
15
+ %p
16
+ Once connected, a Quickbooks Online Sales Receipt
17
+ will be created when an order is purchased.
@@ -1,14 +1,21 @@
1
1
  %h1.effective-admin-heading= @page_title
2
2
 
3
- - if Rails.env.development?
4
- = card('Test Credentials') do
5
- = render('test_credentials', api: @api)
3
+ - api = EffectiveQbOnline.api
6
4
 
7
- = card('Company') do
8
- = render('company', api: @api)
5
+ - if api.blank?
6
+ = card('Connect to Quickbooks Online') do
7
+ = render('connect')
9
8
 
10
- = card('Sales Receipts') do
11
- .text-right.mb-2
12
- = link_to 'New Sales Receipt', effective_qb_online.new_admin_qb_receipt_path, class: 'btn btn-primary btn-sm'
9
+ - if api.present?
10
+ - if Rails.env.development?
11
+ = card('Test Credentials') do
12
+ = render('test_credentials', api: api)
13
13
 
14
- = render_datatable(Admin::EffectiveQbReceiptsDatatable.new)
14
+ = card('Company') do
15
+ = render('company', api: api)
16
+
17
+ = card('Sales Receipts') do
18
+ .text-right.mb-2
19
+ = link_to 'New Sales Receipt', effective_qb_online.new_admin_qb_receipt_path, class: 'btn btn-primary btn-sm'
20
+
21
+ = render_datatable(Admin::EffectiveQbReceiptsDatatable.new)
data/config/routes.rb CHANGED
@@ -9,6 +9,7 @@ EffectiveQbOnline::Engine.routes.draw do
9
9
  scope module: 'effective' do
10
10
  get '/quickbooks/oauth/authorize', to: 'qb_oauth#authorize', as: :quickbooks_oauth
11
11
  get '/quickbooks/oauth/callback', to: 'qb_oauth#callback', as: :quickbooks_oauth_callback
12
+ delete '/quickbooks/oauth/revoke', to: 'qb_oauth#revoke', as: :revoke_quickbooks_oauth
12
13
  end
13
14
 
14
15
  namespace :admin do
@@ -27,6 +27,8 @@ class CreateEffectiveQbOnline < ActiveRecord::Migration[6.1]
27
27
  t.timestamps
28
28
  end
29
29
 
30
+ add_index <%= @qb_receipts_table_name %>, :order_id
31
+
30
32
  create_table <%= @qb_receipt_items_name %> do |t|
31
33
  t.integer :qb_receipt_id
32
34
  t.integer :order_item_id
@@ -7,6 +7,10 @@ module EffectiveQbOnline
7
7
  eval File.read("#{config.root}/config/effective_qb_online.rb")
8
8
  end
9
9
 
10
+ initializer 'effective_qb_online.assets' do |app|
11
+ app.config.assets.precompile += ['effective_qb_online_manifest.js', 'effective_qb_online/*']
12
+ end
13
+
10
14
  # Include acts_as_addressable concern and allow any ActiveRecord object to call it
11
15
  initializer 'effective_qb_online.active_record' do |app|
12
16
  ActiveSupport.on_load :active_record do
@@ -1,3 +1,3 @@
1
1
  module EffectiveQbOnline
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_qb_online
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
@@ -203,6 +203,7 @@ files:
203
203
  - README.md
204
204
  - Rakefile
205
205
  - app/assets/config/effective_qb_online_manifest.js
206
+ - app/assets/images/effective_qb_online/C2QB_green_btn_med_default.svg
206
207
  - app/assets/javascripts/effective_qb_online.js
207
208
  - app/assets/javascripts/effective_qb_online/base.js
208
209
  - app/assets/stylesheets/effective_qb_online.scss
@@ -220,9 +221,9 @@ files:
220
221
  - app/models/effective/qb_receipt_item.rb
221
222
  - app/models/effective/qb_sales_receipt.rb
222
223
  - app/views/admin/qb_online/_company.html.haml
224
+ - app/views/admin/qb_online/_connect.html.haml
223
225
  - app/views/admin/qb_online/_test_credentials.html.haml
224
226
  - app/views/admin/qb_online/index.html.haml
225
- - app/views/admin/qb_online/instructions.html.haml
226
227
  - app/views/admin/qb_receipts/_form.html.haml
227
228
  - app/views/admin/qb_receipts/edit.html.haml
228
229
  - app/views/admin/qb_receipts/new.html.haml
@@ -1,18 +0,0 @@
1
- %h1.effective-page-title= @page_title
2
-
3
- %p Welcome to the Quickbooks Online first run instructions!
4
-
5
- %p
6
- 1.) Ask Code & Effect to add a Redirect URI
7
- to the Quickbooks Online Effective Orders application.
8
-
9
- %ul
10
- %li The uri is: #{effective_qb_online.quickbooks_oauth_callback_url}
11
-
12
- %p
13
- 2.) Then
14
- = link_to('click here', effective_qb_online.quickbooks_oauth_path)
15
- and sign in to the Quickbooks Online company you wish to connect.
16
-
17
- %p
18
- 3.) Once connected, you will be be returned to this website. All done!