ledger_sync 1.1.1 → 1.1.2

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.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +2 -3
  5. data/lib/ledger_sync.rb +12 -6
  6. data/lib/ledger_sync/adaptors/ledger_serializer.rb +124 -0
  7. data/lib/ledger_sync/adaptors/ledger_serializer_attribute.rb +148 -0
  8. data/lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb +51 -0
  9. data/lib/ledger_sync/adaptors/ledger_serializer_type/mapping_type.rb +41 -0
  10. data/lib/ledger_sync/adaptors/ledger_serializer_type/references_many_type.rb +24 -0
  11. data/lib/ledger_sync/adaptors/ledger_serializer_type/value_type.rb +17 -0
  12. data/lib/ledger_sync/adaptors/operation.rb +15 -9
  13. data/lib/ledger_sync/adaptors/quickbooks_online/account/ledger_serializer.rb +21 -0
  14. data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/create.rb +8 -36
  15. data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/find.rb +1 -13
  16. data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/update.rb +4 -35
  17. data/lib/ledger_sync/adaptors/quickbooks_online/account/searcher.rb +3 -44
  18. data/lib/ledger_sync/adaptors/quickbooks_online/adaptor.rb +75 -28
  19. data/lib/ledger_sync/adaptors/quickbooks_online/bill/ledger_serializer.rb +40 -0
  20. data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/create.rb +9 -48
  21. data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/find.rb +10 -21
  22. data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/update.rb +9 -52
  23. data/lib/ledger_sync/adaptors/quickbooks_online/bill_line_item/ledger_serializer.rb +27 -0
  24. data/lib/ledger_sync/adaptors/quickbooks_online/customer/ledger_serializer.rb +23 -0
  25. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/create.rb +2 -25
  26. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/find.rb +2 -14
  27. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb +3 -30
  28. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/ledger_serializer.rb +35 -0
  29. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/create.rb +2 -39
  30. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/find.rb +2 -14
  31. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/update.rb +4 -43
  32. data/lib/ledger_sync/adaptors/quickbooks_online/deposit_line_item/ledger_serializer.rb +27 -0
  33. data/lib/ledger_sync/adaptors/quickbooks_online/expense/ledger_serializer.rb +48 -0
  34. data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/create.rb +10 -51
  35. data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/find.rb +10 -22
  36. data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/update.rb +10 -55
  37. data/lib/ledger_sync/adaptors/quickbooks_online/expense_line_item/ledger_serializer.rb +27 -0
  38. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/ledger_serializer.rb +32 -0
  39. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/create.rb +4 -37
  40. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/find.rb +4 -15
  41. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/update.rb +5 -42
  42. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry_line_item/ledger_serializer.rb +31 -0
  43. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer.rb +103 -0
  44. data/lib/ledger_sync/adaptors/quickbooks_online/{account/mapping.rb → ledger_serializer_type/account_sub_type.rb} +128 -148
  45. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/account_type.rb +51 -0
  46. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/amount_type.rb +23 -0
  47. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/classification_type.rb +23 -0
  48. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/date_type.rb +23 -0
  49. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/journal_entry_line_item_type.rb +20 -0
  50. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/payment_type.rb +21 -0
  51. data/lib/ledger_sync/adaptors/quickbooks_online/operation.rb +2 -7
  52. data/lib/ledger_sync/adaptors/quickbooks_online/operation/create.rb +29 -0
  53. data/lib/ledger_sync/adaptors/quickbooks_online/operation/find.rb +31 -0
  54. data/lib/ledger_sync/adaptors/quickbooks_online/operation/full_update.rb +43 -0
  55. data/lib/ledger_sync/adaptors/quickbooks_online/operation/sparse_update.rb +29 -0
  56. data/lib/ledger_sync/adaptors/quickbooks_online/payment/ledger_serializer.rb +23 -0
  57. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/create.rb +1 -24
  58. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/find.rb +1 -13
  59. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/update.rb +2 -29
  60. data/lib/ledger_sync/adaptors/quickbooks_online/transfer/ledger_serializer.rb +33 -0
  61. data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/create.rb +1 -29
  62. data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/find.rb +1 -13
  63. data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/update.rb +4 -35
  64. data/lib/ledger_sync/adaptors/quickbooks_online/util/adaptor_error_parser.rb +2 -1
  65. data/lib/ledger_sync/adaptors/quickbooks_online/util/operation_error_parser.rb +2 -1
  66. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/ledger_serializer.rb +25 -0
  67. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/create.rb +1 -23
  68. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/find.rb +1 -13
  69. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/update.rb +2 -29
  70. data/lib/ledger_sync/adaptors/test/account/operations/create.rb +5 -1
  71. data/lib/ledger_sync/adaptors/test/account/operations/find.rb +5 -1
  72. data/lib/ledger_sync/adaptors/test/account/operations/invalid.rb +1 -0
  73. data/lib/ledger_sync/adaptors/test/account/operations/update.rb +8 -2
  74. data/lib/ledger_sync/adaptors/test/account/operations/valid.rb +1 -0
  75. data/lib/ledger_sync/adaptors/test/customer/operations/create.rb +5 -1
  76. data/lib/ledger_sync/adaptors/test/customer/operations/find.rb +5 -1
  77. data/lib/ledger_sync/adaptors/test/customer/operations/invalid.rb +1 -0
  78. data/lib/ledger_sync/adaptors/test/customer/operations/update.rb +1 -24
  79. data/lib/ledger_sync/adaptors/test/customer/operations/valid.rb +3 -6
  80. data/lib/ledger_sync/adaptors/test/expense/operations/create.rb +8 -3
  81. data/lib/ledger_sync/adaptors/test/expense/operations/find.rb +4 -14
  82. data/lib/ledger_sync/adaptors/test/expense/operations/update.rb +2 -32
  83. data/lib/ledger_sync/adaptors/test/ledger_serializer.rb +64 -0
  84. data/lib/ledger_sync/adaptors/test/operation/create.rb +27 -0
  85. data/lib/ledger_sync/adaptors/test/operation/find.rb +29 -0
  86. data/lib/ledger_sync/adaptors/test/operation/update.rb +34 -0
  87. data/lib/ledger_sync/adaptors/test/payment/operations/create.rb +5 -1
  88. data/lib/ledger_sync/adaptors/test/payment/operations/find.rb +5 -1
  89. data/lib/ledger_sync/adaptors/test/payment/operations/update.rb +1 -23
  90. data/lib/ledger_sync/adaptors/test/transfer/operations/create.rb +1 -22
  91. data/lib/ledger_sync/adaptors/test/transfer/operations/find.rb +1 -13
  92. data/lib/ledger_sync/adaptors/test/transfer/operations/update.rb +1 -25
  93. data/lib/ledger_sync/adaptors/test/vendor/operations/create.rb +5 -1
  94. data/lib/ledger_sync/adaptors/test/vendor/operations/find.rb +7 -1
  95. data/lib/ledger_sync/adaptors/test/vendor/operations/invalid.rb +1 -0
  96. data/lib/ledger_sync/adaptors/test/vendor/operations/update.rb +1 -23
  97. data/lib/ledger_sync/adaptors/test/vendor/operations/valid.rb +1 -0
  98. data/lib/ledger_sync/error/adaptor_errors.rb +17 -5
  99. data/lib/ledger_sync/error/operation_errors.rb +12 -5
  100. data/lib/ledger_sync/error/resource_errors.rb +5 -1
  101. data/lib/ledger_sync/resource.rb +33 -6
  102. data/lib/ledger_sync/resource_attribute.rb +4 -0
  103. data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +16 -0
  104. data/lib/ledger_sync/resource_attribute/mixin.rb +19 -7
  105. data/lib/ledger_sync/resource_attribute/reference/many.rb +55 -1
  106. data/lib/ledger_sync/resource_attribute_set.rb +6 -7
  107. data/lib/ledger_sync/resources/account.rb +1 -1
  108. data/lib/ledger_sync/resources/bill.rb +1 -0
  109. data/lib/ledger_sync/resources/bill_line_item.rb +2 -0
  110. data/lib/ledger_sync/resources/expense.rb +5 -1
  111. data/lib/ledger_sync/resources/expense_line_item.rb +2 -0
  112. data/lib/ledger_sync/resources/journal_entry.rb +1 -0
  113. data/lib/ledger_sync/result.rb +4 -3
  114. data/lib/ledger_sync/type/id.rb +34 -0
  115. data/lib/ledger_sync/type/reference_many.rb +8 -2
  116. data/lib/ledger_sync/type/reference_one.rb +5 -0
  117. data/lib/ledger_sync/type/value_mixin.rb +12 -0
  118. data/lib/ledger_sync/util/hash_helpers.rb +16 -0
  119. data/lib/ledger_sync/version.rb +1 -1
  120. data/qa.rb +142 -0
  121. metadata +38 -5
  122. data/lib/ledger_sync/adaptors/quickbooks_online/expense/mapping.rb +0 -15
  123. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/mapping.rb +0 -14
  124. data/lib/ledger_sync/error/sync_errors.rb +0 -22
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module Adaptors
5
+ module QuickBooksOnline
6
+ module LedgerSerializerType
7
+ class AccountType < Adaptors::LedgerSerializerType::MappingType
8
+ MAPPING = {
9
+ 'bank' => 'Bank',
10
+ 'other_current_assets' => 'Other Current Asset',
11
+ 'fixed_asset' => 'Fixed Asset',
12
+ 'other_asset' => 'Other Asset',
13
+ 'accounts_receivable' => 'Accounts Receivable',
14
+ 'equity' => 'Equity',
15
+ 'expense' => 'Expense',
16
+ 'other_expense' => 'Other Expense',
17
+ 'cost_of_goods_sold' => 'Cost of Goods Sold',
18
+ 'accounts_payable' => 'Accounts Payable',
19
+ 'credit_card' => 'Credit Card',
20
+ 'long_term_liability' => 'Long Term Liability',
21
+ 'other_current_liability' => 'Other Current Liability',
22
+ 'income' => 'Income',
23
+ 'other_income' => 'Other Income'
24
+ }.freeze
25
+
26
+ TYPE_TO_CLASSIFICATION_MAPPING = {
27
+ 'bank' => 'asset',
28
+ 'other_current_assets' => 'asset',
29
+ 'fixed_asset' => 'asset',
30
+ 'other_asset' => 'asset',
31
+ 'accounts_receivable' => 'asset',
32
+ 'equity' => 'equity',
33
+ 'expense' => 'expense',
34
+ 'other_expense' => 'expense',
35
+ 'cost_of_goods_sold' => 'expense',
36
+ 'accounts_payable' => 'liability',
37
+ 'credit_card' => 'liability',
38
+ 'long_term_liability' => 'liability',
39
+ 'other_current_liability' => 'liability',
40
+ 'income' => 'revenue',
41
+ 'other_income' => 'revenue'
42
+ }
43
+
44
+ def self.mapping
45
+ @mapping ||= MAPPING
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module Adaptors
5
+ module QuickBooksOnline
6
+ module LedgerSerializerType
7
+ class AmountType < Adaptors::LedgerSerializerType::MappingType
8
+ def convert_from_ledger(value:)
9
+ return if value.nil?
10
+
11
+ (value * 100).to_i
12
+ end
13
+
14
+ def convert_from_local(value:)
15
+ return if value.nil?
16
+
17
+ value / 100.0
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module Adaptors
5
+ module QuickBooksOnline
6
+ module LedgerSerializerType
7
+ class ClassificationType < Adaptors::LedgerSerializerType::MappingType
8
+ MAPPING = {
9
+ 'asset' => 'Asset',
10
+ 'equity' => 'Equity',
11
+ 'expense' => 'Expense',
12
+ 'liability' => 'Liability',
13
+ 'revenue' => 'Revenue'
14
+ }.freeze
15
+
16
+ def self.mapping
17
+ @mapping ||= MAPPING
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module Adaptors
5
+ module QuickBooksOnline
6
+ module LedgerSerializerType
7
+ class DateType < Adaptors::LedgerSerializerType::MappingType
8
+ def convert_from_ledger(value:)
9
+ return value if value.nil?
10
+
11
+ value.to_date
12
+ end
13
+
14
+ def convert_from_local(value:)
15
+ return value if value.nil?
16
+
17
+ value.to_s
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module Adaptors
5
+ module QuickBooksOnline
6
+ module LedgerSerializerType
7
+ class JournalEntryLineItemType < Adaptors::LedgerSerializerType::MappingType
8
+ MAPPING = {
9
+ 'debit' => 'Debit',
10
+ 'credit' => 'Credit'
11
+ }.freeze
12
+
13
+ def self.mapping
14
+ @mapping ||= MAPPING
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module Adaptors
5
+ module QuickBooksOnline
6
+ module LedgerSerializerType
7
+ class PaymentType < Adaptors::LedgerSerializerType::MappingType
8
+ MAPPING = {
9
+ 'cash' => 'Cash',
10
+ 'check' => 'Check',
11
+ 'credit_card' => 'CreditCard'
12
+ }.freeze
13
+
14
+ def self.mapping
15
+ @mapping ||= MAPPING
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -4,8 +4,6 @@ module LedgerSync
4
4
  module Adaptors
5
5
  module QuickBooksOnline
6
6
  module Operation
7
- TYPES = %i[create find update].freeze
8
-
9
7
  module Mixin
10
8
  def self.included(base)
11
9
  base.include Adaptors::Operation::Mixin
@@ -16,13 +14,10 @@ module LedgerSync
16
14
  rescue OAuth2::Error => e
17
15
  failure(e)
18
16
  end
19
- end
20
17
 
21
- TYPES.each do |type|
22
- klass = Class.new do
23
- include QuickBooksOnline::Operation::Mixin
18
+ def quickbooks_online_resource_type
19
+ @quickbooks_online_resource_type ||= ledger_serializer.class.quickbooks_online_resource_type
24
20
  end
25
- Operation.const_set(LedgerSync::Util::StringHelpers.camelcase(type.to_s), klass)
26
21
  end
27
22
  end
28
23
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../operation'
4
+
5
+ module LedgerSync
6
+ module Adaptors
7
+ module QuickBooksOnline
8
+ module Operation
9
+ class Create
10
+ include QuickBooksOnline::Operation::Mixin
11
+
12
+ private
13
+
14
+ def operate
15
+ response = adaptor.post(
16
+ resource: quickbooks_online_resource_type,
17
+ payload: ledger_serializer.to_ledger_hash
18
+ )
19
+
20
+ success(
21
+ resource: ledger_serializer.deserialize(hash: response),
22
+ response: response
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../operation'
4
+
5
+ module LedgerSync
6
+ module Adaptors
7
+ module QuickBooksOnline
8
+ module Operation
9
+ class Find
10
+ include QuickBooksOnline::Operation::Mixin
11
+
12
+ private
13
+
14
+ def operate
15
+ return failure(nil) if resource.ledger_id.nil?
16
+
17
+ response = adaptor.find(
18
+ resource: quickbooks_online_resource_type,
19
+ id: resource.ledger_id
20
+ )
21
+
22
+ success(
23
+ resource: ledger_serializer.deserialize(hash: response),
24
+ response: response
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../operation'
4
+
5
+ module LedgerSync
6
+ module Adaptors
7
+ module QuickBooksOnline
8
+ module Operation
9
+ class FullUpdate
10
+ include QuickBooksOnline::Operation::Mixin
11
+
12
+ private
13
+
14
+ def find_resource
15
+ adaptor.find(
16
+ resource: quickbooks_online_resource_type,
17
+ id: resource.ledger_id
18
+ )
19
+ end
20
+
21
+ def operate
22
+ update_resource(find_resource)
23
+ end
24
+
25
+ def update_resource(find_result_hash)
26
+ merged_resource = ledger_serializer.deserialize(hash: find_result_hash, merge_for_full_update: true)
27
+ merged_serializer = ledger_serializer.class.new(resource: merged_resource)
28
+
29
+ response = adaptor.post(
30
+ resource: quickbooks_online_resource_type,
31
+ payload: merged_serializer.to_ledger_hash(deep_merge_unmapped_values: find_result_hash)
32
+ )
33
+
34
+ success(
35
+ resource: ledger_serializer.deserialize(hash: response),
36
+ response: response
37
+ )
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../operation'
4
+
5
+ module LedgerSync
6
+ module Adaptors
7
+ module QuickBooksOnline
8
+ module Operation
9
+ class SparseUpdate
10
+ include QuickBooksOnline::Operation::Mixin
11
+
12
+ private
13
+
14
+ def operate
15
+ response = adaptor.post(
16
+ resource: quickbooks_online_resource_type,
17
+ payload: merged_serializer.to_ledger_hash
18
+ )
19
+
20
+ success(
21
+ resource: ledger_serializer.deserialize(hash: response),
22
+ response: response
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module Adaptors
5
+ module QuickBooksOnline
6
+ module Payment
7
+ class LedgerSerializer < QuickBooksOnline::LedgerSerializer
8
+ id
9
+
10
+ attribute ledger_attribute: 'TotalAmt',
11
+ resource_attribute: :amount,
12
+ type: LedgerSerializerType::AmountType
13
+
14
+ attribute ledger_attribute: 'CurrencyRef.value',
15
+ resource_attribute: :currency
16
+
17
+ attribute ledger_attribute: 'CustomerRef.value',
18
+ resource_attribute: 'customer.ledger_id'
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -8,6 +8,7 @@ module LedgerSync
8
8
  class Create < Operation::Create
9
9
  class Contract < LedgerSync::Adaptors::Contract
10
10
  params do
11
+ required(:external_id).maybe(:string)
11
12
  required(:ledger_id).value(:nil)
12
13
  required(:ledger_id).maybe(:string)
13
14
  required(:amount).filled(:integer)
@@ -18,30 +19,6 @@ module LedgerSync
18
19
  end
19
20
  end
20
21
  end
21
-
22
- private
23
-
24
- def operate
25
- response = adaptor.post(
26
- resource: 'payment',
27
- payload: local_resource_data
28
- )
29
-
30
- resource.ledger_id = response.dig('Id')
31
- success(response: response)
32
- end
33
-
34
- def local_resource_data
35
- {
36
- 'TotalAmt' => resource.amount / 100.0,
37
- 'CurrencyRef' => {
38
- 'value' => resource.currency
39
- },
40
- 'CustomerRef' => {
41
- 'value' => resource.customer.ledger_id
42
- }
43
- }
44
- end
45
22
  end
46
23
  end
47
24
  end
@@ -6,25 +6,13 @@ module LedgerSync
6
6
  class Find < Operation::Find
7
7
  class Contract < LedgerSync::Adaptors::Contract
8
8
  schema do
9
+ required(:external_id).maybe(:string)
9
10
  required(:ledger_id).filled(:string)
10
11
  optional(:amount).maybe(:integer)
11
12
  optional(:currency).maybe(:string)
12
13
  optional(:customer).maybe(Types::Reference)
13
14
  end
14
15
  end
15
-
16
- private
17
-
18
- def operate
19
- return failure(nil) if resource.ledger_id.nil?
20
-
21
- response = adaptor.find(
22
- resource: 'payment',
23
- id: resource.ledger_id
24
- )
25
-
26
- success(response: response)
27
- end
28
16
  end
29
17
  end
30
18
  end
@@ -3,43 +3,16 @@ module LedgerSync
3
3
  module QuickBooksOnline
4
4
  module Payment
5
5
  module Operations
6
- class Update < Operation::Update
6
+ class Update < Operation::FullUpdate
7
7
  class Contract < LedgerSync::Adaptors::Contract
8
8
  schema do
9
+ required(:external_id).maybe(:string)
9
10
  required(:ledger_id).filled(:string)
10
11
  required(:amount).filled(:integer)
11
12
  required(:currency).filled(:string)
12
13
  required(:customer).hash(Types::Reference)
13
14
  end
14
15
  end
15
-
16
- private
17
-
18
- def operate
19
- ledger_resource_data = adaptor.find(
20
- resource: 'payment',
21
- id: resource.ledger_id
22
- )
23
- response = adaptor.post(
24
- resource: 'payment',
25
- payload: merge_into(from: local_resource_data, to: ledger_resource_data)
26
- )
27
-
28
- resource.ledger_id = response.dig('Id')
29
- success(response: response)
30
- end
31
-
32
- def local_resource_data
33
- {
34
- 'TotalAmt' => resource.amount / 100.0,
35
- 'CurrencyRef' => {
36
- 'value' => resource.currency,
37
- },
38
- 'CustomerRef' => {
39
- 'value' => resource.customer.ledger_id,
40
- }
41
- }
42
- end
43
16
  end
44
17
  end
45
18
  end