Sha256: 0de2fedb57998d0b1a755f6152587c3da845725f5168f7cef64c200ba16b4105

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      module Customer
        module Operations
          class Update < Operation::Update
            class Contract < LedgerSync::Adaptors::Contract
              params do
                required(:ledger_id).filled(:string)
                required(:email).maybe(:string)
                required(:name).filled(:string)
                required(:phone_number).maybe(:string)
              end
            end

            private

            def operate
              ledger_resource_data = adaptor.find(
                resource: 'customer',
                id: resource.ledger_id
              )

              response = adaptor.upsert(
                resource: 'customer',
                payload: merge_into(from: local_resource_data, to: ledger_resource_data)
              )

              resource.ledger_id = response.dig('Id')
              success(response: response)
            rescue OAuth2::Error => e
              failure(e)
            end

            def local_resource_data
              {
                'DisplayName': resource.name,
                "PrimaryPhone": {
                  "FreeFormNumber": resource.phone_number
                },
                "PrimaryEmailAddr": {
                  "Address": resource.email
                }
              }
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ledger_sync-1.0.10 lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb
ledger_sync-1.0.9 lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb
ledger_sync-1.0.3 lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb
ledger_sync-1.0.2 lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb
ledger_sync-1.0.0 lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb