ledger_sync 1.1.3 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env.template +25 -0
- data/.gitignore +3 -1
- data/.rubocop_todo.yml +4 -1
- data/.travis.yml +1 -1
- data/Gemfile.lock +59 -25
- data/README.md +160 -8
- data/_config.yml +1 -0
- data/bin/qa +3 -0
- data/ledger_sync.gemspec +4 -0
- data/lib/ledger_sync.rb +40 -30
- data/lib/ledger_sync/adaptor_configuration.rb +17 -11
- data/lib/ledger_sync/adaptor_configuration_store.rb +13 -9
- data/lib/ledger_sync/adaptors/adaptor.rb +9 -1
- data/lib/ledger_sync/adaptors/ledger_serializer.rb +3 -6
- data/lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb +1 -1
- data/lib/ledger_sync/adaptors/ledger_serializer_type/references_many_type.rb +1 -1
- data/lib/ledger_sync/adaptors/mixins/infer_adaptor_class_mixin.rb +24 -0
- data/lib/ledger_sync/adaptors/mixins/infer_ledger_serializer_mixin.rb +31 -0
- data/lib/ledger_sync/adaptors/mixins/infer_resource_class_mixin.rb +22 -0
- data/lib/ledger_sync/adaptors/mixins/offset_and_limit_pagination_searcher_mixin.rb +37 -0
- data/lib/ledger_sync/adaptors/netsuite/account/ledger_deserializer.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/account/ledger_serializer.rb +22 -0
- data/lib/ledger_sync/adaptors/netsuite/account/operations/create.rb +28 -0
- data/lib/ledger_sync/adaptors/netsuite/account/operations/find.rb +28 -0
- data/lib/ledger_sync/adaptors/netsuite/account/searcher.rb +28 -0
- data/lib/ledger_sync/adaptors/netsuite/adaptor.rb +145 -0
- data/lib/ledger_sync/adaptors/netsuite/config.rb +6 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/deledger_serializer.rb +28 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/ledger_serializer.rb +25 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/operations/create.rb +25 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/operations/delete.rb +23 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/operations/find.rb +23 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/operations/update.rb +23 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/ledger_deserializer.rb +27 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/ledger_serializer.rb +38 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/operations/create.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/operations/delete.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/operations/find.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/operations/update.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/ledger_serializer.rb +30 -0
- data/lib/ledger_sync/adaptors/netsuite/ledger_serializer_type/reference_type.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/ledger_serializer_type/subsidiary_type.rb +22 -0
- data/lib/ledger_sync/adaptors/netsuite/operation.rb +25 -0
- data/lib/ledger_sync/adaptors/netsuite/operation/create.rb +65 -0
- data/lib/ledger_sync/adaptors/netsuite/operation/delete.rb +49 -0
- data/lib/ledger_sync/adaptors/netsuite/operation/find.rb +56 -0
- data/lib/ledger_sync/adaptors/netsuite/operation/update.rb +68 -0
- data/lib/ledger_sync/adaptors/netsuite/record/http_method.rb +38 -0
- data/lib/ledger_sync/adaptors/netsuite/record/metadata.rb +75 -0
- data/lib/ledger_sync/adaptors/netsuite/record/property.rb +45 -0
- data/lib/ledger_sync/adaptors/netsuite/searcher.rb +17 -0
- data/lib/ledger_sync/adaptors/netsuite/token.rb +162 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/ledger_deserializer.rb +32 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/ledger_serializer.rb +35 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/operations/create.rb +27 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/operations/delete.rb +27 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/operations/find.rb +27 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/operations/update.rb +27 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/adaptor.rb +92 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/config.rb +5 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/customer/ledger_serializer.rb +13 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/customer/operations/create.rb +64 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/customer/operations/find.rb +49 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/ledger_serializer.rb +25 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/operation.rb +40 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/operation/create.rb +29 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/operation/find.rb +15 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/subsidiary/operations/create.rb +42 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/subsidiary/operations/find.rb +38 -0
- data/lib/ledger_sync/adaptors/operation.rb +7 -11
- data/lib/ledger_sync/adaptors/quickbooks_online/account/searcher.rb +2 -13
- data/lib/ledger_sync/adaptors/quickbooks_online/adaptor.rb +158 -109
- data/lib/ledger_sync/adaptors/quickbooks_online/bill/searcher.rb +1 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/config.rb +3 -2
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/create.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/find.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/searcher.rb +2 -16
- data/lib/ledger_sync/adaptors/quickbooks_online/dashboard_url_helper.rb +57 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/department/ledger_serializer.rb +38 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/department/operations/create.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/department/operations/find.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/department/operations/update.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/department/searcher.rb +17 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/ledger_serializer.rb +3 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/create.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/find.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/update.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/searcher.rb +0 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/ledger_serializer.rb +0 -2
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/searcher.rb +1 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/invoice/ledger_serializer.rb +35 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/create.rb +27 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/find.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/update.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/invoice_sales_line_item/ledger_serializer.rb +30 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/item/ledger_serializer.rb +13 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/searcher.rb +1 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/ledger_serializer.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/operations/create.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/operations/find.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/operations/update.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/searcher.rb +15 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer.rb +8 -5
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/entity_reference_type.rb +4 -14
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/transaction_reference_type.rb +49 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/oauth_client.rb +93 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/operation.rb +42 -7
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/create.rb +5 -8
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/find.rb +9 -9
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/full_update.rb +17 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/ledger_serializer.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/create.rb +9 -6
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/find.rb +9 -2
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/update.rb +8 -1
- data/lib/ledger_sync/adaptors/quickbooks_online/payment_line_item/ledger_serializer.rb +19 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/request.rb +98 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/searcher.rb +29 -13
- data/lib/ledger_sync/adaptors/quickbooks_online/util/operation_error_parser.rb +1 -1
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/create.rb +3 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/find.rb +3 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/update.rb +3 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb +5 -54
- data/lib/ledger_sync/adaptors/quickbooks_online/webhook.rb +58 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/webhook_event.rb +79 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/webhook_notification.rb +42 -0
- data/lib/ledger_sync/adaptors/request.rb +53 -0
- data/lib/ledger_sync/adaptors/response.rb +55 -0
- data/lib/ledger_sync/adaptors/searcher.rb +3 -1
- data/lib/ledger_sync/adaptors/stripe/adaptor.rb +45 -0
- data/lib/ledger_sync/adaptors/stripe/config.rb +6 -0
- data/lib/ledger_sync/adaptors/stripe/customer/operations/create.rb +44 -0
- data/lib/ledger_sync/adaptors/stripe/customer/operations/delete.rb +35 -0
- data/lib/ledger_sync/adaptors/stripe/customer/operations/find.rb +44 -0
- data/lib/ledger_sync/adaptors/stripe/customer/operations/update.rb +43 -0
- data/lib/ledger_sync/adaptors/stripe/operation.rb +35 -0
- data/lib/ledger_sync/adaptors/stripe/operation/create.rb +17 -0
- data/lib/ledger_sync/adaptors/stripe/operation/delete.rb +17 -0
- data/lib/ledger_sync/adaptors/stripe/operation/find.rb +15 -0
- data/lib/ledger_sync/adaptors/stripe/operation/update.rb +17 -0
- data/lib/ledger_sync/adaptors/test/config.rb +0 -1
- data/lib/ledger_sync/adaptors/test/customer/operations/create.rb +1 -0
- data/lib/ledger_sync/adaptors/test/customer/operations/find.rb +1 -0
- data/lib/ledger_sync/adaptors/test/customer/operations/invalid.rb +1 -0
- data/lib/ledger_sync/adaptors/test/customer/operations/update.rb +1 -0
- data/lib/ledger_sync/adaptors/test/customer/operations/valid.rb +1 -0
- data/lib/ledger_sync/adaptors/test/payment/operations/create.rb +8 -1
- data/lib/ledger_sync/adaptors/test/payment/operations/find.rb +9 -2
- data/lib/ledger_sync/adaptors/test/payment/operations/update.rb +9 -5
- data/lib/ledger_sync/adaptors/test/vendor/operations/create.rb +5 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/find.rb +3 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/invalid.rb +5 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/update.rb +5 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/valid.rb +5 -0
- data/lib/ledger_sync/error/adaptor_errors.rb +18 -5
- data/lib/ledger_sync/error/operation_errors.rb +13 -4
- data/lib/ledger_sync/resource.rb +6 -0
- data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +16 -15
- data/lib/ledger_sync/resources/bill.rb +7 -1
- data/lib/ledger_sync/resources/bill_line_item.rb +2 -0
- data/lib/ledger_sync/resources/currency.rb +9 -0
- data/lib/ledger_sync/resources/customer.rb +16 -0
- data/lib/ledger_sync/resources/department.rb +14 -0
- data/lib/ledger_sync/resources/deposit.rb +7 -0
- data/lib/ledger_sync/resources/deposit_line_item.rb +6 -0
- data/lib/ledger_sync/resources/expense.rb +5 -0
- data/lib/ledger_sync/resources/expense_line_item.rb +2 -0
- data/lib/ledger_sync/resources/invoice.rb +23 -0
- data/lib/ledger_sync/resources/invoice_sales_line_item.rb +17 -0
- data/lib/ledger_sync/resources/item.rb +5 -0
- data/lib/ledger_sync/resources/journal_entry.rb +5 -1
- data/lib/ledger_sync/resources/journal_entry_line_item.rb +4 -0
- data/lib/ledger_sync/resources/ledger_class.rb +14 -0
- data/lib/ledger_sync/resources/payment.rb +13 -0
- data/lib/ledger_sync/resources/payment_line_item.rb +15 -0
- data/lib/ledger_sync/resources/subsidiary.rb +8 -0
- data/lib/ledger_sync/resources/transfer.rb +4 -0
- data/lib/ledger_sync/resources/vendor.rb +9 -2
- data/lib/ledger_sync/type/reference_many.rb +12 -1
- data/lib/ledger_sync/type/reference_one.rb +1 -1
- data/lib/ledger_sync/util/resonad.rb +18 -0
- data/lib/ledger_sync/util/signer.rb +36 -0
- data/lib/ledger_sync/util/string_helpers.rb +12 -12
- data/lib/ledger_sync/version.rb +1 -1
- data/qa/env_spec.rb +5 -0
- data/qa/netsuite/account_spec.rb +20 -0
- data/qa/netsuite/currency_spec.rb +16 -0
- data/qa/netsuite/customer.rb +76 -0
- data/qa/netsuite/customer_spec.rb +21 -0
- data/qa/netsuite/vendor.rb +76 -0
- data/qa/netsuite/vendor_spec.rb +23 -0
- data/qa/netsuite_soap/customer_spec.rb +21 -0
- data/qa/netsuite_soap/subsidiary_spec.rb +0 -0
- data/qa/netsuite_test.rb +42 -0
- data/qa/qa_helper.rb +58 -0
- data/qa/quickbooks_online/account_spec.rb +14 -0
- data/qa/quickbooks_online/customer_spec.rb +13 -0
- data/qa/quickbooks_online/expense_spec.rb +31 -0
- data/qa/quickbooks_online/vendor_spec.rb +13 -0
- data/qa/stripe/customers_spec.rb +15 -0
- data/qa/support/adaptor_helpers.rb +99 -0
- data/qa/support/adaptor_support_setup.rb +23 -0
- data/qa/support/netsuite_helpers.rb +33 -0
- data/qa/support/netsuite_shared_examples.rb +30 -0
- data/qa/support/netsuite_soap_helpers.rb +33 -0
- data/qa/support/netsuite_soap_shared_examples.rb +10 -0
- data/qa/support/quickbooks_online_helpers.rb +42 -0
- data/qa/support/quickbooks_online_shared_examples.rb +82 -0
- data/qa/support/shared_examples.rb +127 -0
- data/qa/support/stripe_helpers.rb +22 -0
- data/qa/support/stripe_shared_examples.rb +10 -0
- data/qa/test.rb +67 -0
- data/release.sh +13 -1
- metadata +189 -3
- data/qa.rb +0 -142
|
@@ -12,14 +12,11 @@ module LedgerSync
|
|
|
12
12
|
private
|
|
13
13
|
|
|
14
14
|
def operate
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
success(
|
|
21
|
-
resource: ledger_serializer.deserialize(hash: response),
|
|
22
|
-
response: response
|
|
15
|
+
result(
|
|
16
|
+
response: adaptor.post(
|
|
17
|
+
path: ledger_resource_type_for_path,
|
|
18
|
+
payload: ledger_serializer.to_ledger_hash
|
|
19
|
+
)
|
|
23
20
|
)
|
|
24
21
|
end
|
|
25
22
|
end
|
|
@@ -12,16 +12,16 @@ module LedgerSync
|
|
|
12
12
|
private
|
|
13
13
|
|
|
14
14
|
def operate
|
|
15
|
-
return failure(
|
|
15
|
+
return failure(
|
|
16
|
+
Errors::OperationError::LedgerIDRequired.new(
|
|
17
|
+
operation: self
|
|
18
|
+
)
|
|
19
|
+
) if resource.ledger_id.nil?
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
success(
|
|
23
|
-
resource: ledger_serializer.deserialize(hash: response),
|
|
24
|
-
response: response
|
|
21
|
+
result(
|
|
22
|
+
response: adaptor.find(
|
|
23
|
+
path: ledger_resource_path
|
|
24
|
+
)
|
|
25
25
|
)
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -13,27 +13,29 @@ module LedgerSync
|
|
|
13
13
|
|
|
14
14
|
def find_resource
|
|
15
15
|
adaptor.find(
|
|
16
|
-
|
|
17
|
-
id: resource.ledger_id
|
|
16
|
+
path: ledger_resource_path
|
|
18
17
|
)
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
def operate
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
resource:
|
|
31
|
-
payload: merged_serializer.to_ledger_hash(deep_merge_unmapped_values: find_result_hash)
|
|
21
|
+
find_result_hash = find_resource.body.dig(
|
|
22
|
+
quickbooks_online_resource_type.to_s.classify
|
|
23
|
+
)
|
|
24
|
+
merged_resource = ledger_serializer.deserialize(
|
|
25
|
+
hash: find_result_hash,
|
|
26
|
+
merge_for_full_update: true
|
|
27
|
+
)
|
|
28
|
+
merged_serializer = ledger_serializer.class.new(
|
|
29
|
+
resource: merged_resource
|
|
32
30
|
)
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
result(
|
|
33
|
+
response: adaptor.post(
|
|
34
|
+
path: ledger_resource_type_for_path,
|
|
35
|
+
payload: merged_serializer.to_ledger_hash(
|
|
36
|
+
deep_merge_unmapped_values: find_result_hash
|
|
37
|
+
)
|
|
38
|
+
)
|
|
37
39
|
)
|
|
38
40
|
end
|
|
39
41
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative '../payment_line_item/ledger_serializer'
|
|
4
|
+
|
|
3
5
|
module LedgerSync
|
|
4
6
|
module Adaptors
|
|
5
7
|
module QuickBooksOnline
|
|
@@ -16,6 +18,29 @@ module LedgerSync
|
|
|
16
18
|
|
|
17
19
|
attribute ledger_attribute: 'CustomerRef.value',
|
|
18
20
|
resource_attribute: 'customer.ledger_id'
|
|
21
|
+
|
|
22
|
+
attribute ledger_attribute: 'DepositToAccountRef.value',
|
|
23
|
+
resource_attribute: 'deposit_account.ledger_id'
|
|
24
|
+
|
|
25
|
+
attribute ledger_attribute: 'ARAccountRef.value',
|
|
26
|
+
resource_attribute: 'account.ledger_id'
|
|
27
|
+
|
|
28
|
+
attribute ledger_attribute: 'PaymentRefNum',
|
|
29
|
+
resource_attribute: :reference_number
|
|
30
|
+
|
|
31
|
+
attribute ledger_attribute: 'PrivateNote',
|
|
32
|
+
resource_attribute: :memo
|
|
33
|
+
|
|
34
|
+
attribute ledger_attribute: 'ExchangeRate',
|
|
35
|
+
resource_attribute: :exchange_rate
|
|
36
|
+
|
|
37
|
+
attribute ledger_attribute: 'TxnDate',
|
|
38
|
+
resource_attribute: :transaction_date,
|
|
39
|
+
type: LedgerSerializerType::DateType
|
|
40
|
+
|
|
41
|
+
references_many ledger_attribute: 'Line',
|
|
42
|
+
resource_attribute: :line_items,
|
|
43
|
+
serializer: PaymentLineItem::LedgerSerializer
|
|
19
44
|
end
|
|
20
45
|
end
|
|
21
46
|
end
|
|
@@ -9,14 +9,17 @@ module LedgerSync
|
|
|
9
9
|
class Contract < LedgerSync::Adaptors::Contract
|
|
10
10
|
params do
|
|
11
11
|
required(:external_id).maybe(:string)
|
|
12
|
-
|
|
13
|
-
required(:ledger_id).maybe(:string)
|
|
12
|
+
optional(:account).hash(Types::Reference)
|
|
14
13
|
required(:amount).filled(:integer)
|
|
15
14
|
required(:currency).filled(:string)
|
|
16
|
-
required(:customer).hash
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
required(:customer).hash(Types::Reference)
|
|
16
|
+
optional(:deposit_account).hash(Types::Reference)
|
|
17
|
+
optional(:exchange_rate).maybe(:float)
|
|
18
|
+
required(:ledger_id).value(:nil)
|
|
19
|
+
required(:line_items).array(Types::Reference)
|
|
20
|
+
optional(:memo).filled(:string)
|
|
21
|
+
optional(:reference_number).maybe(:string)
|
|
22
|
+
optional(:transaction_date).filled(:date?)
|
|
20
23
|
end
|
|
21
24
|
end
|
|
22
25
|
end
|
|
@@ -7,10 +7,17 @@ module LedgerSync
|
|
|
7
7
|
class Contract < LedgerSync::Adaptors::Contract
|
|
8
8
|
schema do
|
|
9
9
|
required(:external_id).maybe(:string)
|
|
10
|
-
|
|
10
|
+
optional(:account).hash(Types::Reference)
|
|
11
11
|
optional(:amount).maybe(:integer)
|
|
12
12
|
optional(:currency).maybe(:string)
|
|
13
|
-
optional(:customer).
|
|
13
|
+
optional(:customer).hash(Types::Reference)
|
|
14
|
+
optional(:deposit_account).hash(Types::Reference)
|
|
15
|
+
optional(:exchange_rate).maybe(:float)
|
|
16
|
+
required(:ledger_id).filled(:string)
|
|
17
|
+
optional(:line_items).array(Types::Reference)
|
|
18
|
+
optional(:memo).maybe(:string)
|
|
19
|
+
optional(:reference_number).maybe(:string)
|
|
20
|
+
optional(:transaction_date).maybe(:date?)
|
|
14
21
|
end
|
|
15
22
|
end
|
|
16
23
|
end
|
|
@@ -7,10 +7,17 @@ module LedgerSync
|
|
|
7
7
|
class Contract < LedgerSync::Adaptors::Contract
|
|
8
8
|
schema do
|
|
9
9
|
required(:external_id).maybe(:string)
|
|
10
|
-
|
|
10
|
+
optional(:account).hash(Types::Reference)
|
|
11
11
|
required(:amount).filled(:integer)
|
|
12
12
|
required(:currency).filled(:string)
|
|
13
13
|
required(:customer).hash(Types::Reference)
|
|
14
|
+
optional(:deposit_account).hash(Types::Reference)
|
|
15
|
+
optional(:exchange_rate).maybe(:float)
|
|
16
|
+
required(:ledger_id).filled(:string)
|
|
17
|
+
required(:line_items).array(Types::Reference)
|
|
18
|
+
optional(:memo).filled(:string)
|
|
19
|
+
optional(:reference_number).maybe(:string)
|
|
20
|
+
optional(:transaction_date).filled(:date?)
|
|
14
21
|
end
|
|
15
22
|
end
|
|
16
23
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LedgerSync
|
|
4
|
+
module Adaptors
|
|
5
|
+
module QuickBooksOnline
|
|
6
|
+
module PaymentLineItem
|
|
7
|
+
class LedgerSerializer < QuickBooksOnline::LedgerSerializer
|
|
8
|
+
attribute ledger_attribute: 'Amount',
|
|
9
|
+
resource_attribute: :amount,
|
|
10
|
+
type: LedgerSerializerType::AmountType
|
|
11
|
+
|
|
12
|
+
attribute ledger_attribute: 'LinkedTxn',
|
|
13
|
+
resource_attribute: :ledger_transactions,
|
|
14
|
+
type: LedgerSerializerType::TransactionReferenceType
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LedgerSync
|
|
4
|
+
module Adaptors
|
|
5
|
+
module QuickBooksOnline
|
|
6
|
+
class Request < Adaptors::Request
|
|
7
|
+
attr_reader :adaptor
|
|
8
|
+
|
|
9
|
+
def initialize(*args, adaptor:, **keywords)
|
|
10
|
+
@adaptor = adaptor
|
|
11
|
+
super(*args, **keywords)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def perform
|
|
15
|
+
raise 'Request already performed' if performed?
|
|
16
|
+
|
|
17
|
+
@response = generate_response(
|
|
18
|
+
body: body,
|
|
19
|
+
headers: headers,
|
|
20
|
+
method: method,
|
|
21
|
+
url: url
|
|
22
|
+
)
|
|
23
|
+
rescue OAuth2::Error => e
|
|
24
|
+
error = parse_error(error: e)
|
|
25
|
+
|
|
26
|
+
if error.is_a?(Error::AdaptorError::AuthenticationError)
|
|
27
|
+
begin
|
|
28
|
+
adaptor.refresh!
|
|
29
|
+
@response = generate_response(
|
|
30
|
+
body: body,
|
|
31
|
+
headers: headers,
|
|
32
|
+
method: method,
|
|
33
|
+
url: url
|
|
34
|
+
)
|
|
35
|
+
return @response
|
|
36
|
+
rescue OAuth2::Error => e
|
|
37
|
+
raise parse_error(error: e)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
raise error
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def refresh!
|
|
45
|
+
oauth.refresh!
|
|
46
|
+
rescue OAuth2::Error => e
|
|
47
|
+
raise parse_error(error: e)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def generate_response(body:, headers:, method:, url:)
|
|
53
|
+
oauth_response = oauth.send(
|
|
54
|
+
method,
|
|
55
|
+
url,
|
|
56
|
+
body: body,
|
|
57
|
+
headers: headers
|
|
58
|
+
)
|
|
59
|
+
ret = Response.new_from_oauth_response(
|
|
60
|
+
oauth_response: oauth_response,
|
|
61
|
+
request: self
|
|
62
|
+
)
|
|
63
|
+
@performed = true
|
|
64
|
+
ret
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def parse_error(error:)
|
|
68
|
+
parsed_adaptor_error(error: error) ||
|
|
69
|
+
parsed_operation_error(error: error) ||
|
|
70
|
+
error
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def parsed_adaptor_error(error:)
|
|
74
|
+
Util::AdaptorErrorParser.new(
|
|
75
|
+
error: error,
|
|
76
|
+
adaptor: self
|
|
77
|
+
).parse
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def parsed_operation_error(error:)
|
|
81
|
+
return nil unless error.is_a?(OAuth2::Error)
|
|
82
|
+
|
|
83
|
+
Util::OperationErrorParser.new(
|
|
84
|
+
error: error
|
|
85
|
+
).parse
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def oauth
|
|
89
|
+
adaptor.oauth
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def oauth_client
|
|
93
|
+
adaptor.oauth_client
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -4,14 +4,35 @@ module LedgerSync
|
|
|
4
4
|
module Adaptors
|
|
5
5
|
module QuickBooksOnline
|
|
6
6
|
class Searcher < Adaptors::Searcher
|
|
7
|
-
|
|
8
|
-
paginate(limit: limit, offset: offset + limit)
|
|
9
|
-
end
|
|
7
|
+
include Mixins::OffsetAndLimitPaginationSearcherMixin
|
|
10
8
|
|
|
11
|
-
def
|
|
12
|
-
|
|
9
|
+
def query_string
|
|
10
|
+
''
|
|
11
|
+
end
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
def resources
|
|
14
|
+
resource_class = self.class.inferred_resource_class
|
|
15
|
+
|
|
16
|
+
response = adaptor.query(
|
|
17
|
+
limit: limit,
|
|
18
|
+
offset: offset,
|
|
19
|
+
query: query_string,
|
|
20
|
+
resource_class: resource_class
|
|
21
|
+
)
|
|
22
|
+
return [] if response.body.blank?
|
|
23
|
+
|
|
24
|
+
(response.body.dig(
|
|
25
|
+
'QueryResponse',
|
|
26
|
+
adaptor.class.ledger_resource_type_for(
|
|
27
|
+
resource_class: resource_class
|
|
28
|
+
).classify
|
|
29
|
+
) || []).map do |c|
|
|
30
|
+
self.class.inferred_ledger_serializer_class.new(
|
|
31
|
+
resource: resource_class.new
|
|
32
|
+
).deserialize(
|
|
33
|
+
hash: c
|
|
34
|
+
)
|
|
35
|
+
end
|
|
15
36
|
end
|
|
16
37
|
|
|
17
38
|
def search
|
|
@@ -31,13 +52,8 @@ module LedgerSync
|
|
|
31
52
|
#
|
|
32
53
|
# More here:
|
|
33
54
|
# https://developer.intuit.com/app/developer/qbo/docs/develop/explore-the-quickbooks-online-api/data-queries#pagination
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
pagination.fetch(:limit, 10).to_i
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def offset
|
|
40
|
-
pagination.fetch(:offset, 1).to_i
|
|
55
|
+
def default_offset
|
|
56
|
+
1
|
|
41
57
|
end
|
|
42
58
|
end
|
|
43
59
|
end
|
|
@@ -14,6 +14,9 @@ module LedgerSync
|
|
|
14
14
|
optional(:first_name).maybe(:string)
|
|
15
15
|
optional(:last_name).maybe(:string)
|
|
16
16
|
optional(:email).maybe(:string)
|
|
17
|
+
optional(:company_name).maybe(:string)
|
|
18
|
+
optional(:phone_number).maybe(:string)
|
|
19
|
+
optional(:subsidiary).maybe(:hash, Types::Reference)
|
|
17
20
|
end
|
|
18
21
|
end
|
|
19
22
|
end
|
|
@@ -14,6 +14,9 @@ module LedgerSync
|
|
|
14
14
|
required(:first_name).maybe(:string)
|
|
15
15
|
required(:last_name).maybe(:string)
|
|
16
16
|
optional(:email).maybe(:string)
|
|
17
|
+
optional(:company_name).maybe(:string)
|
|
18
|
+
optional(:phone_number).maybe(:string)
|
|
19
|
+
optional(:subsidiary).maybe(:hash, Types::Reference)
|
|
17
20
|
end
|
|
18
21
|
end
|
|
19
22
|
end
|
|
@@ -14,6 +14,9 @@ module LedgerSync
|
|
|
14
14
|
optional(:first_name).maybe(:string)
|
|
15
15
|
optional(:last_name).maybe(:string)
|
|
16
16
|
optional(:email).maybe(:string)
|
|
17
|
+
optional(:company_name).maybe(:string)
|
|
18
|
+
optional(:phone_number).maybe(:string)
|
|
19
|
+
optional(:subsidiary).maybe(:hash, Types::Reference)
|
|
17
20
|
end
|
|
18
21
|
end
|
|
19
22
|
end
|
|
@@ -1,61 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module LedgerSync
|
|
2
4
|
module Adaptors
|
|
3
5
|
module QuickBooksOnline
|
|
4
6
|
module Vendor
|
|
5
|
-
class Searcher <
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def previous_searcher
|
|
11
|
-
return nil if offset <= 1
|
|
12
|
-
|
|
13
|
-
paginate(limit: limit, offset: offset - limit)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def resources
|
|
17
|
-
@resources ||= begin
|
|
18
|
-
adaptor
|
|
19
|
-
.query(
|
|
20
|
-
resource: 'vendor',
|
|
21
|
-
query: "DisplayName LIKE '%#{query}%'",
|
|
22
|
-
limit: limit,
|
|
23
|
-
offset: offset
|
|
24
|
-
)
|
|
25
|
-
.map do |c|
|
|
26
|
-
LedgerSync::Vendor.new(
|
|
27
|
-
ledger_id: c.fetch('Id'),
|
|
28
|
-
display_name: c.fetch('DisplayName'),
|
|
29
|
-
first_name: c.dig('GivenName'),
|
|
30
|
-
last_name: c.dig('FamilyName')
|
|
31
|
-
)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def search
|
|
37
|
-
super
|
|
38
|
-
rescue OAuth2::Error => e
|
|
39
|
-
@response = e # TODO: Better catch/raise errors as LedgerSync::Error
|
|
40
|
-
failure
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
private
|
|
44
|
-
# Pagination uses notation of limit and offset
|
|
45
|
-
# limit: number of results per page
|
|
46
|
-
#
|
|
47
|
-
# offset: position of first result in a list.
|
|
48
|
-
# starts from 1, not 0
|
|
49
|
-
#
|
|
50
|
-
# More here:
|
|
51
|
-
# https://developer.intuit.com/app/developer/qbo/docs/develop/explore-the-quickbooks-online-api/data-queries#pagination
|
|
52
|
-
|
|
53
|
-
def limit
|
|
54
|
-
pagination.fetch(:limit, 10).to_i
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def offset
|
|
58
|
-
pagination.fetch(:offset, 1).to_i
|
|
7
|
+
class Searcher < Searcher
|
|
8
|
+
def query_string
|
|
9
|
+
"DisplayName LIKE '%#{query}%'"
|
|
59
10
|
end
|
|
60
11
|
end
|
|
61
12
|
end
|