ledger_sync-quickbooks_online 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.env.test +9 -0
  4. data/.gitignore +21 -0
  5. data/.overcommit.yml +29 -0
  6. data/.rubocop.yml +78 -0
  7. data/.rubocop_todo.yml +25 -0
  8. data/.travis.yml +25 -0
  9. data/Gemfile +8 -0
  10. data/Gemfile.lock +211 -0
  11. data/README.md +19 -0
  12. data/Rakefile +8 -0
  13. data/bin/console +15 -0
  14. data/bin/quickbooks_online_oauth_server.rb +104 -0
  15. data/bin/setup +8 -0
  16. data/ledger_sync-quickbooks_online.gemspec +46 -0
  17. data/lib/ledger_sync/quickbooks_online.rb +14 -0
  18. data/lib/ledger_sync/quickbooks_online/account/deserializer.rb +29 -0
  19. data/lib/ledger_sync/quickbooks_online/account/operations/create.rb +26 -0
  20. data/lib/ledger_sync/quickbooks_online/account/operations/find.rb +26 -0
  21. data/lib/ledger_sync/quickbooks_online/account/operations/update.rb +28 -0
  22. data/lib/ledger_sync/quickbooks_online/account/searcher.rb +13 -0
  23. data/lib/ledger_sync/quickbooks_online/account/serializer.rb +29 -0
  24. data/lib/ledger_sync/quickbooks_online/account_based_expense_line_detail/deserializer.rb +19 -0
  25. data/lib/ledger_sync/quickbooks_online/account_based_expense_line_detail/serializer.rb +19 -0
  26. data/lib/ledger_sync/quickbooks_online/bill/deserializer.rb +39 -0
  27. data/lib/ledger_sync/quickbooks_online/bill/operations/create.rb +27 -0
  28. data/lib/ledger_sync/quickbooks_online/bill/operations/find.rb +27 -0
  29. data/lib/ledger_sync/quickbooks_online/bill/operations/update.rb +27 -0
  30. data/lib/ledger_sync/quickbooks_online/bill/searcher.rb +12 -0
  31. data/lib/ledger_sync/quickbooks_online/bill/serializer.rb +39 -0
  32. data/lib/ledger_sync/quickbooks_online/bill_line/deserializer.rb +20 -0
  33. data/lib/ledger_sync/quickbooks_online/bill_line/serializer.rb +24 -0
  34. data/lib/ledger_sync/quickbooks_online/bill_payment/deserializer.rb +53 -0
  35. data/lib/ledger_sync/quickbooks_online/bill_payment/operations/create.rb +31 -0
  36. data/lib/ledger_sync/quickbooks_online/bill_payment/operations/find.rb +31 -0
  37. data/lib/ledger_sync/quickbooks_online/bill_payment/operations/update.rb +31 -0
  38. data/lib/ledger_sync/quickbooks_online/bill_payment/serializer.rb +53 -0
  39. data/lib/ledger_sync/quickbooks_online/bill_payment_line/deserializer.rb +14 -0
  40. data/lib/ledger_sync/quickbooks_online/bill_payment_line/serializer.rb +14 -0
  41. data/lib/ledger_sync/quickbooks_online/check_payment/deserializer.rb +15 -0
  42. data/lib/ledger_sync/quickbooks_online/check_payment/serializer.rb +15 -0
  43. data/lib/ledger_sync/quickbooks_online/client.rb +235 -0
  44. data/lib/ledger_sync/quickbooks_online/config.rb +15 -0
  45. data/lib/ledger_sync/quickbooks_online/credit_card_payment/deserializer.rb +15 -0
  46. data/lib/ledger_sync/quickbooks_online/credit_card_payment/serializer.rb +15 -0
  47. data/lib/ledger_sync/quickbooks_online/currency/deserializer.rb +14 -0
  48. data/lib/ledger_sync/quickbooks_online/currency/serializer.rb +15 -0
  49. data/lib/ledger_sync/quickbooks_online/customer/deserializer.rb +24 -0
  50. data/lib/ledger_sync/quickbooks_online/customer/operations/create.rb +24 -0
  51. data/lib/ledger_sync/quickbooks_online/customer/operations/find.rb +24 -0
  52. data/lib/ledger_sync/quickbooks_online/customer/operations/update.rb +24 -0
  53. data/lib/ledger_sync/quickbooks_online/customer/searcher.rb +13 -0
  54. data/lib/ledger_sync/quickbooks_online/customer/serializer.rb +24 -0
  55. data/lib/ledger_sync/quickbooks_online/dashboard_url_helper.rb +32 -0
  56. data/lib/ledger_sync/quickbooks_online/department/deserializer.rb +20 -0
  57. data/lib/ledger_sync/quickbooks_online/department/operations/create.rb +23 -0
  58. data/lib/ledger_sync/quickbooks_online/department/operations/find.rb +23 -0
  59. data/lib/ledger_sync/quickbooks_online/department/operations/update.rb +23 -0
  60. data/lib/ledger_sync/quickbooks_online/department/searcher.rb +15 -0
  61. data/lib/ledger_sync/quickbooks_online/department/serializer.rb +39 -0
  62. data/lib/ledger_sync/quickbooks_online/deposit/deserializer.rb +34 -0
  63. data/lib/ledger_sync/quickbooks_online/deposit/operations/create.rb +25 -0
  64. data/lib/ledger_sync/quickbooks_online/deposit/operations/find.rb +25 -0
  65. data/lib/ledger_sync/quickbooks_online/deposit/operations/update.rb +25 -0
  66. data/lib/ledger_sync/quickbooks_online/deposit/searcher.rb +12 -0
  67. data/lib/ledger_sync/quickbooks_online/deposit/serializer.rb +34 -0
  68. data/lib/ledger_sync/quickbooks_online/deposit_line/deserializer.rb +20 -0
  69. data/lib/ledger_sync/quickbooks_online/deposit_line/serializer.rb +24 -0
  70. data/lib/ledger_sync/quickbooks_online/deposit_line_detail/deserializer.rb +32 -0
  71. data/lib/ledger_sync/quickbooks_online/deposit_line_detail/serializer.rb +33 -0
  72. data/lib/ledger_sync/quickbooks_online/deserializer.rb +97 -0
  73. data/lib/ledger_sync/quickbooks_online/expense/deserializer.rb +52 -0
  74. data/lib/ledger_sync/quickbooks_online/expense/operations/create.rb +28 -0
  75. data/lib/ledger_sync/quickbooks_online/expense/operations/find.rb +28 -0
  76. data/lib/ledger_sync/quickbooks_online/expense/operations/update.rb +28 -0
  77. data/lib/ledger_sync/quickbooks_online/expense/searcher.rb +12 -0
  78. data/lib/ledger_sync/quickbooks_online/expense/serializer.rb +51 -0
  79. data/lib/ledger_sync/quickbooks_online/expense_line/deserializer.rb +20 -0
  80. data/lib/ledger_sync/quickbooks_online/expense_line/serializer.rb +24 -0
  81. data/lib/ledger_sync/quickbooks_online/invoice/deserializer.rb +33 -0
  82. data/lib/ledger_sync/quickbooks_online/invoice/operations/create.rb +25 -0
  83. data/lib/ledger_sync/quickbooks_online/invoice/operations/find.rb +25 -0
  84. data/lib/ledger_sync/quickbooks_online/invoice/operations/update.rb +25 -0
  85. data/lib/ledger_sync/quickbooks_online/invoice/serializer.rb +33 -0
  86. data/lib/ledger_sync/quickbooks_online/invoice_line/deserializer.rb +19 -0
  87. data/lib/ledger_sync/quickbooks_online/invoice_line/serializer.rb +23 -0
  88. data/lib/ledger_sync/quickbooks_online/item/deserializer.rb +11 -0
  89. data/lib/ledger_sync/quickbooks_online/item/serializer.rb +10 -0
  90. data/lib/ledger_sync/quickbooks_online/journal_entry/deserializer.rb +26 -0
  91. data/lib/ledger_sync/quickbooks_online/journal_entry/operations/create.rb +23 -0
  92. data/lib/ledger_sync/quickbooks_online/journal_entry/operations/find.rb +23 -0
  93. data/lib/ledger_sync/quickbooks_online/journal_entry/operations/update.rb +23 -0
  94. data/lib/ledger_sync/quickbooks_online/journal_entry/searcher.rb +12 -0
  95. data/lib/ledger_sync/quickbooks_online/journal_entry/serializer.rb +26 -0
  96. data/lib/ledger_sync/quickbooks_online/journal_entry_line/deserializer.rb +18 -0
  97. data/lib/ledger_sync/quickbooks_online/journal_entry_line/serializer.rb +22 -0
  98. data/lib/ledger_sync/quickbooks_online/journal_entry_line_detail/deserializer.rb +27 -0
  99. data/lib/ledger_sync/quickbooks_online/journal_entry_line_detail/serializer.rb +27 -0
  100. data/lib/ledger_sync/quickbooks_online/ledger_class/deserializer.rb +22 -0
  101. data/lib/ledger_sync/quickbooks_online/ledger_class/operations/create.rb +23 -0
  102. data/lib/ledger_sync/quickbooks_online/ledger_class/operations/find.rb +23 -0
  103. data/lib/ledger_sync/quickbooks_online/ledger_class/operations/update.rb +23 -0
  104. data/lib/ledger_sync/quickbooks_online/ledger_class/searcher.rb +13 -0
  105. data/lib/ledger_sync/quickbooks_online/ledger_class/serializer.rb +22 -0
  106. data/lib/ledger_sync/quickbooks_online/oauth_client.rb +91 -0
  107. data/lib/ledger_sync/quickbooks_online/operation.rb +59 -0
  108. data/lib/ledger_sync/quickbooks_online/operation/create.rb +24 -0
  109. data/lib/ledger_sync/quickbooks_online/operation/find.rb +23 -0
  110. data/lib/ledger_sync/quickbooks_online/operation/full_update.rb +40 -0
  111. data/lib/ledger_sync/quickbooks_online/operation/sparse_update.rb +27 -0
  112. data/lib/ledger_sync/quickbooks_online/payment/deserializer.rb +40 -0
  113. data/lib/ledger_sync/quickbooks_online/payment/operations/create.rb +28 -0
  114. data/lib/ledger_sync/quickbooks_online/payment/operations/find.rb +28 -0
  115. data/lib/ledger_sync/quickbooks_online/payment/operations/update.rb +28 -0
  116. data/lib/ledger_sync/quickbooks_online/payment/serializer.rb +40 -0
  117. data/lib/ledger_sync/quickbooks_online/payment_line/deserializer.rb +15 -0
  118. data/lib/ledger_sync/quickbooks_online/payment_line/serializer.rb +15 -0
  119. data/lib/ledger_sync/quickbooks_online/preferences/deserializer.rb +22 -0
  120. data/lib/ledger_sync/quickbooks_online/preferences/operations/find.rb +28 -0
  121. data/lib/ledger_sync/quickbooks_online/preferences/serializer.rb +22 -0
  122. data/lib/ledger_sync/quickbooks_online/primary_email_addr/deserializer.rb +11 -0
  123. data/lib/ledger_sync/quickbooks_online/primary_email_addr/serializer.rb +11 -0
  124. data/lib/ledger_sync/quickbooks_online/primary_phone/deserializer.rb +11 -0
  125. data/lib/ledger_sync/quickbooks_online/primary_phone/serializer.rb +11 -0
  126. data/lib/ledger_sync/quickbooks_online/reference/deserializer.rb +11 -0
  127. data/lib/ledger_sync/quickbooks_online/reference/serializer.rb +11 -0
  128. data/lib/ledger_sync/quickbooks_online/request.rb +96 -0
  129. data/lib/ledger_sync/quickbooks_online/resource.rb +8 -0
  130. data/lib/ledger_sync/quickbooks_online/resources/account.rb +357 -0
  131. data/lib/ledger_sync/quickbooks_online/resources/account_based_expense_line_detail.rb +17 -0
  132. data/lib/ledger_sync/quickbooks_online/resources/bill.rb +29 -0
  133. data/lib/ledger_sync/quickbooks_online/resources/bill_line.rb +17 -0
  134. data/lib/ledger_sync/quickbooks_online/resources/bill_payment.rb +42 -0
  135. data/lib/ledger_sync/quickbooks_online/resources/bill_payment_line.rb +17 -0
  136. data/lib/ledger_sync/quickbooks_online/resources/check_payment.rb +11 -0
  137. data/lib/ledger_sync/quickbooks_online/resources/credit_card_payment.rb +11 -0
  138. data/lib/ledger_sync/quickbooks_online/resources/currency.rb +15 -0
  139. data/lib/ledger_sync/quickbooks_online/resources/customer.rb +22 -0
  140. data/lib/ledger_sync/quickbooks_online/resources/department.rb +20 -0
  141. data/lib/ledger_sync/quickbooks_online/resources/deposit.rb +26 -0
  142. data/lib/ledger_sync/quickbooks_online/resources/deposit_line.rb +17 -0
  143. data/lib/ledger_sync/quickbooks_online/resources/deposit_line_detail.rb +20 -0
  144. data/lib/ledger_sync/quickbooks_online/resources/expense.rb +38 -0
  145. data/lib/ledger_sync/quickbooks_online/resources/expense_line.rb +17 -0
  146. data/lib/ledger_sync/quickbooks_online/resources/invoice.rb +26 -0
  147. data/lib/ledger_sync/quickbooks_online/resources/invoice_line.rb +17 -0
  148. data/lib/ledger_sync/quickbooks_online/resources/item.rb +9 -0
  149. data/lib/ledger_sync/quickbooks_online/resources/journal_entry.rb +22 -0
  150. data/lib/ledger_sync/quickbooks_online/resources/journal_entry_line.rb +18 -0
  151. data/lib/ledger_sync/quickbooks_online/resources/journal_entry_line_detail.rb +25 -0
  152. data/lib/ledger_sync/quickbooks_online/resources/ledger_class.rb +18 -0
  153. data/lib/ledger_sync/quickbooks_online/resources/payment.rb +29 -0
  154. data/lib/ledger_sync/quickbooks_online/resources/payment_line.rb +17 -0
  155. data/lib/ledger_sync/quickbooks_online/resources/preferences.rb +22 -0
  156. data/lib/ledger_sync/quickbooks_online/resources/primary_email_addr.rb +9 -0
  157. data/lib/ledger_sync/quickbooks_online/resources/primary_phone.rb +9 -0
  158. data/lib/ledger_sync/quickbooks_online/resources/sales_item_line_detail.rb +17 -0
  159. data/lib/ledger_sync/quickbooks_online/resources/transfer.rb +22 -0
  160. data/lib/ledger_sync/quickbooks_online/resources/vendor.rb +23 -0
  161. data/lib/ledger_sync/quickbooks_online/sales_item_line_detail/deserializer.rb +19 -0
  162. data/lib/ledger_sync/quickbooks_online/sales_item_line_detail/serializer.rb +19 -0
  163. data/lib/ledger_sync/quickbooks_online/searcher.rb +58 -0
  164. data/lib/ledger_sync/quickbooks_online/serialization/type/amount_float_to_integer_type.rb +19 -0
  165. data/lib/ledger_sync/quickbooks_online/serialization/type/deserialize_transaction_reference_type.rb +28 -0
  166. data/lib/ledger_sync/quickbooks_online/serialization/type/integer_to_amount_float_type.rb +19 -0
  167. data/lib/ledger_sync/quickbooks_online/serialization/type/serialize_transaction_reference_type.rb +28 -0
  168. data/lib/ledger_sync/quickbooks_online/serializer.rb +69 -0
  169. data/lib/ledger_sync/quickbooks_online/serialziation/type/mapping_type.rb +27 -0
  170. data/lib/ledger_sync/quickbooks_online/transfer/deserializer.rb +29 -0
  171. data/lib/ledger_sync/quickbooks_online/transfer/operations/create.rb +24 -0
  172. data/lib/ledger_sync/quickbooks_online/transfer/operations/find.rb +24 -0
  173. data/lib/ledger_sync/quickbooks_online/transfer/operations/update.rb +24 -0
  174. data/lib/ledger_sync/quickbooks_online/transfer/serializer.rb +29 -0
  175. data/lib/ledger_sync/quickbooks_online/util/error_matcher.rb +68 -0
  176. data/lib/ledger_sync/quickbooks_online/util/error_parser.rb +25 -0
  177. data/lib/ledger_sync/quickbooks_online/util/ledger_error_parser.rb +101 -0
  178. data/lib/ledger_sync/quickbooks_online/util/operation_error_parser.rb +97 -0
  179. data/lib/ledger_sync/quickbooks_online/vendor/deserializer.rb +25 -0
  180. data/lib/ledger_sync/quickbooks_online/vendor/operations/create.rb +25 -0
  181. data/lib/ledger_sync/quickbooks_online/vendor/operations/find.rb +25 -0
  182. data/lib/ledger_sync/quickbooks_online/vendor/operations/update.rb +25 -0
  183. data/lib/ledger_sync/quickbooks_online/vendor/searcher.rb +13 -0
  184. data/lib/ledger_sync/quickbooks_online/vendor/serializer.rb +25 -0
  185. data/lib/ledger_sync/quickbooks_online/version.rb +19 -0
  186. data/lib/ledger_sync/quickbooks_online/webhook.rb +56 -0
  187. data/lib/ledger_sync/quickbooks_online/webhook_event.rb +79 -0
  188. data/lib/ledger_sync/quickbooks_online/webhook_notification.rb +41 -0
  189. data/license.txt +4 -0
  190. metadata +456 -0
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../reference/serializer'
4
+
5
+ module LedgerSync
6
+ module QuickBooksOnline
7
+ class CheckPayment
8
+ class Serializer < QuickBooksOnline::Serializer
9
+ references_one 'BankAccountRef',
10
+ resource_attribute: :BankAccount,
11
+ serializer: Reference::Serializer
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,235 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'oauth_client'
4
+ require_relative 'dashboard_url_helper'
5
+
6
+ module LedgerSync
7
+ module QuickBooksOnline
8
+ class Client
9
+ include Ledgers::Client::Mixin
10
+
11
+ OAUTH_HEADERS = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }.freeze
12
+ ROOT_URI = 'https://quickbooks.api.intuit.com'
13
+ REVOKE_TOKEN_URI = 'https://developer.api.intuit.com/v2/oauth2/tokens/revoke'
14
+ ROOT_SANDBOX_URI = 'https://sandbox-quickbooks.api.intuit.com'
15
+ PRODUCTION_APP_URL_BASE = 'https://qbo.intuit.com/app'
16
+ SANDBOX_APP_URL_BASE = 'https://app.sandbox.qbo.intuit.com/app'
17
+
18
+ attr_reader :access_token,
19
+ :client_id,
20
+ :client_secret,
21
+ :expires_at,
22
+ :previous_access_tokens,
23
+ :previous_refresh_tokens,
24
+ :realm_id,
25
+ :refresh_token,
26
+ :refresh_token_expires_at,
27
+ :root_uri,
28
+ :test,
29
+ :update_dotenv
30
+
31
+ def initialize(
32
+ access_token:,
33
+ client_id:,
34
+ client_secret:,
35
+ realm_id:,
36
+ refresh_token:,
37
+ test: false,
38
+ update_dotenv: true
39
+ )
40
+ @access_token = access_token
41
+ @client_id = client_id
42
+ @client_secret = client_secret
43
+ @realm_id = realm_id
44
+ @refresh_token = refresh_token
45
+ @test = test
46
+ @update_dotenv = update_dotenv
47
+
48
+ @previous_access_tokens = []
49
+ @previous_refresh_tokens = []
50
+
51
+ @root_uri = (test ? ROOT_SANDBOX_URI : ROOT_URI)
52
+
53
+ update_secrets_in_dotenv if update_dotenv
54
+
55
+ super()
56
+ end
57
+
58
+ def authorization_url(redirect_uri:)
59
+ oauth_client.authorization_url(redirect_uri: redirect_uri)
60
+ end
61
+
62
+ def find(path:)
63
+ url = "#{oauth_base_uri}/#{path}"
64
+
65
+ request(
66
+ headers: OAUTH_HEADERS.dup,
67
+ method: :get,
68
+ url: url
69
+ )
70
+ end
71
+
72
+ def oauth
73
+ OAuth2::AccessToken.new(
74
+ oauth_client.client,
75
+ access_token,
76
+ refresh_token: refresh_token
77
+ )
78
+ end
79
+
80
+ def oauth_client
81
+ OAuthClient.new(
82
+ client_id: client_id,
83
+ client_secret: client_secret
84
+ )
85
+ end
86
+
87
+ def post(path:, payload:)
88
+ url = "#{oauth_base_uri}/#{path}"
89
+
90
+ request(
91
+ headers: OAUTH_HEADERS.dup,
92
+ method: :post,
93
+ body: payload,
94
+ url: url
95
+ )
96
+ end
97
+
98
+ def query(query:, resource_class:, limit: 10, offset: 1)
99
+ ledger_resource_type = self.class.ledger_resource_type_for(
100
+ resource_class: resource_class
101
+ ).classify
102
+ full_query = "SELECT * FROM #{ledger_resource_type} WHERE #{query} STARTPOSITION #{offset} MAXRESULTS "\
103
+ "#{limit}"
104
+ url = "#{oauth_base_uri}/query?query=#{CGI.escape(full_query)}"
105
+
106
+ request(
107
+ headers: OAUTH_HEADERS.dup,
108
+ method: :get,
109
+ url: url
110
+ )
111
+ end
112
+
113
+ def refresh!
114
+ set_credentials_from_oauth_token(
115
+ token: Request.new(
116
+ client: self
117
+ ).refresh!
118
+ )
119
+ self
120
+ end
121
+
122
+ def revoke_token!
123
+ headers = OAUTH_HEADERS.dup.merge(
124
+ 'Authorization' => "Basic #{Base64.strict_encode64("#{client_id}:#{client_secret}")}"
125
+ )
126
+ LedgerSync::Ledgers::Request.new(
127
+ body: {
128
+ token: access_token
129
+ },
130
+ headers: headers,
131
+ method: :post,
132
+ url: REVOKE_TOKEN_URI
133
+ ).perform.status == 200
134
+ end
135
+
136
+ def set_credentials_from_oauth_code(code:, redirect_uri:, realm_id: nil)
137
+ oauth_token = oauth_client.get_token(
138
+ code: code,
139
+ redirect_uri: redirect_uri
140
+ )
141
+
142
+ set_credentials_from_oauth_token(
143
+ realm_id: realm_id,
144
+ token: oauth_token
145
+ )
146
+
147
+ oauth_token
148
+ end
149
+
150
+ def url_for(resource:)
151
+ DashboardURLHelper.new(
152
+ resource: resource,
153
+ base_url: (test ? SANDBOX_APP_URL_BASE : PRODUCTION_APP_URL_BASE)
154
+ ).url
155
+ end
156
+
157
+ def self.ledger_attributes_to_save
158
+ %i[access_token expires_at refresh_token refresh_token_expires_at]
159
+ end
160
+
161
+ def self.ledger_resource_type_overrides
162
+ {
163
+ Expense => 'purchase',
164
+ LedgerClass => 'class',
165
+ Preferences => 'preferences'
166
+ }
167
+ end
168
+
169
+ def self.new_from_env(**override)
170
+ new(
171
+ {
172
+ access_token: ENV.fetch('QUICKBOOKS_ONLINE_ACCESS_TOKEN'),
173
+ client_id: ENV.fetch('QUICKBOOKS_ONLINE_CLIENT_ID'),
174
+ client_secret: ENV.fetch('QUICKBOOKS_ONLINE_CLIENT_SECRET'),
175
+ realm_id: ENV.fetch('QUICKBOOKS_ONLINE_REALM_ID'),
176
+ refresh_token: ENV.fetch('QUICKBOOKS_ONLINE_REFRESH_TOKEN')
177
+ }.merge(override)
178
+ )
179
+ end
180
+
181
+ def self.new_from_oauth_client_uri(oauth_client:, uri:, **override)
182
+ parsed_uri = OAuthClient::RedirectURIParser.new(uri: uri)
183
+ oauth_token = oauth_client.get_token(
184
+ code: parsed_uri.code,
185
+ redirect_uri: parsed_uri.redirect_uri
186
+ )
187
+
188
+ new(
189
+ {
190
+ access_token: oauth_token.token,
191
+ client_id: oauth_client.client_id,
192
+ client_secret: oauth_client.client_secret,
193
+ realm_id: parsed_uri.realm_id,
194
+ refresh_token: oauth_token.refresh_token
195
+ }.merge(override)
196
+ )
197
+ end
198
+
199
+ private
200
+
201
+ def oauth_base_uri
202
+ @oauth_base_uri ||= "#{root_uri}/v3/company/#{realm_id}"
203
+ end
204
+
205
+ def request(method:, url:, body: nil, headers: {})
206
+ Request.new(
207
+ client: self,
208
+ body: body,
209
+ headers: headers,
210
+ method: method,
211
+ url: url
212
+ ).perform
213
+ end
214
+
215
+ def set_credentials_from_oauth_token(token:, realm_id: nil) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
216
+ @previous_access_tokens << access_token if access_token.present?
217
+ @access_token = token.token
218
+
219
+ @expires_at = Time&.at(token.expires_at.to_i)&.to_datetime
220
+ unless token.params['x_refresh_token_expires_in'].nil?
221
+ @refresh_token_expires_at = Time&.at(
222
+ Time.now.to_i + token.params['x_refresh_token_expires_in']
223
+ )&.to_datetime
224
+ end
225
+
226
+ @previous_refresh_tokens << refresh_token if refresh_token.present?
227
+ @refresh_token = token.refresh_token
228
+
229
+ @realm_id = realm_id unless realm_id.nil?
230
+ ensure
231
+ update_secrets_in_dotenv if update_dotenv
232
+ end
233
+ end
234
+ end
235
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'client'
4
+
5
+ args = {
6
+ base_module: LedgerSync::QuickBooksOnline,
7
+ root_path: 'ledger_sync/quickbooks_online'
8
+ }
9
+
10
+ LedgerSync.register_ledger(:quickbooks_online, args) do |config|
11
+ config.name = 'QuickBooks Online'
12
+ config.add_alias :qbo
13
+ config.add_alias :quick_books_online
14
+ config.rate_limiting_wait_in_seconds = 60
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../reference/deserializer'
4
+
5
+ module LedgerSync
6
+ module QuickBooksOnline
7
+ class CreditCardPayment
8
+ class Deserializer < QuickBooksOnline::Deserializer
9
+ references_one :CCAccount,
10
+ hash_attribute: 'CCAccountRef',
11
+ deserializer: Reference::Deserializer
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../reference/serializer'
4
+
5
+ module LedgerSync
6
+ module QuickBooksOnline
7
+ class CreditCardPayment
8
+ class Serializer < QuickBooksOnline::Serializer
9
+ references_one 'CCAccountRef',
10
+ resource_attribute: :CCAccount,
11
+ serializer: Reference::Serializer
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class Currency
6
+ class Deserializer < QuickBooksOnline::Deserializer
7
+ attribute :Symbol,
8
+ hash_attribute: :value
9
+
10
+ attribute :Name
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class Currency
6
+ class Serializer < QuickBooksOnline::Serializer
7
+ attribute :value,
8
+ resource_attribute: :Symbol
9
+
10
+ attribute :name,
11
+ resource_attribute: :Name
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../primary_phone/deserializer'
4
+ require_relative '../primary_email_addr/deserializer'
5
+
6
+ module LedgerSync
7
+ module QuickBooksOnline
8
+ class Customer
9
+ class Deserializer < QuickBooksOnline::Deserializer
10
+ id
11
+
12
+ attribute :DisplayName
13
+ attribute :GivenName
14
+ attribute :FamilyName
15
+ attribute :MiddleName
16
+
17
+ references_one :PrimaryPhone,
18
+ deserializer: PrimaryPhone::Deserializer
19
+ references_one :PrimaryEmailAddr,
20
+ deserializer: PrimaryEmailAddr::Deserializer
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class Customer
6
+ module Operations
7
+ class Create < QuickBooksOnline::Operation::Create
8
+ class Contract < LedgerSync::Ledgers::Contract
9
+ params do
10
+ required(:external_id).maybe(:string)
11
+ required(:ledger_id).value(:nil)
12
+ required(:DisplayName).maybe(:string)
13
+ required(:FamilyName).maybe(:string)
14
+ required(:GivenName).maybe(:string)
15
+ required(:MiddleName).maybe(:string)
16
+ required(:PrimaryEmailAddr).maybe(:hash, Types::Reference)
17
+ required(:PrimaryPhone).maybe(:hash, Types::Reference)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class Customer
6
+ module Operations
7
+ class Find < QuickBooksOnline::Operation::Find
8
+ class Contract < LedgerSync::Ledgers::Contract
9
+ params do
10
+ required(:external_id).maybe(:string)
11
+ required(:ledger_id).filled(:string)
12
+ optional(:DisplayName).maybe(:string)
13
+ optional(:FamilyName).maybe(:string)
14
+ optional(:GivenName).maybe(:string)
15
+ optional(:MiddleName).maybe(:string)
16
+ optional(:PrimaryEmailAddr).maybe(:hash, Types::Reference)
17
+ optional(:PrimaryPhone).maybe(:hash, Types::Reference)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class Customer
6
+ module Operations
7
+ class Update < QuickBooksOnline::Operation::FullUpdate
8
+ class Contract < LedgerSync::Ledgers::Contract
9
+ params do
10
+ required(:external_id).maybe(:string)
11
+ required(:ledger_id).filled(:string)
12
+ required(:DisplayName).maybe(:string)
13
+ required(:FamilyName).maybe(:string)
14
+ required(:GivenName).maybe(:string)
15
+ required(:MiddleName).maybe(:string)
16
+ required(:PrimaryEmailAddr).maybe(:hash, Types::Reference)
17
+ required(:PrimaryPhone).maybe(:hash, Types::Reference)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module QuickBooksOnline
5
+ class Customer
6
+ class Searcher < Searcher
7
+ def query_string
8
+ "DisplayName LIKE '%#{query}%'"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end