effective_qb_online 0.4.0 → 0.6.0

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: d0a57f6214297b86608b3cddc41885a14093371ccf8246471177e83adca31c93
4
- data.tar.gz: e5035d9267de8cf24a5ce0431a051e41621797b2c9ffbbdebade41f07b324d1a
3
+ metadata.gz: f42e44d9f6b787e46abb8e3db985571748f0f559baa9ec3d3b4ceede2887248e
4
+ data.tar.gz: 88234f6aff15286412e4bef9d63873f9377e05e05dccc20be7c50316207ec120
5
5
  SHA512:
6
- metadata.gz: d69dbad553ff14cd2e1cc75e32b25f39f0b900afafc8197a4efd43ddc718eb2df7e6df455b93aca8d44ff964654eacdc77195f2324a8b0882f1a72aa49b116e5
7
- data.tar.gz: c855c58edfb05b3b1bd767b9a92fa40f9f281e1c98ba3c484e33d74bb2f6175f208954fdd66d61dd3e414b539ca0c586c2a3540a5243e886a674921eb7470bcb
6
+ metadata.gz: 883700d09bf524af8e7430a7d82214762a02d76c7a145de99258c0e13a08440c6cc771ae1576ff9bd5fb78781174ca092ef31635ca6b84fdbae8a5531d797594
7
+ data.tar.gz: 359e604dcb62e8a09a018f125672f8ab797da4676d31953cbd19bee4fe7da5d116da957ec2fc42a6e14530ab9542e9ae4835a0cdae357d3bef1c6fec0c1e495e
@@ -97,36 +97,26 @@ module Effective
97
97
  payment_methods.sort_by(&:name).map { |payment_method| [payment_method.name, payment_method.id] }
98
98
  end
99
99
 
100
- def find_or_create_customer(user:)
101
- find_customer(user: user) || create_customer(user: user)
100
+ def find_or_create_customer(order:)
101
+ find_customer(order: order) || create_customer(order: order)
102
102
  end
103
103
 
104
- def find_customer(user:)
105
- raise('expected a user that responds to email') unless user.respond_to?(:email)
104
+ def find_customer(order:)
105
+ raise('expected an Effective::Order') unless order.kind_of?(Effective::Order)
106
106
 
107
107
  with_service('Customer') do |service|
108
- # Find by email
109
- customer = service.find_by(:PrimaryEmailAddr, user.email)&.first
110
-
111
- # Find by given name and family name
112
- customer ||= if user.respond_to?(:first_name) && user.respond_to?(:last_name)
113
- service.query("SELECT * FROM Customer WHERE GivenName LIKE '#{scrub(user.first_name, sql: true)}' AND FamilyName LIKE '#{scrub(user.last_name, sql: true)}'")&.first
114
- end
115
-
116
- # Find by display name
117
- customer || service.find_by(:display_name, scrub(user.to_s))&.first
108
+ service.find_by(:display_name, scrub(order.billing_name))&.first
118
109
  end
119
110
  end
120
111
 
121
- def create_customer(user:)
122
- raise('expected a user that responds to email') unless user.respond_to?(:email)
112
+ # https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/customer#create-a-customer
113
+ def create_customer(order:)
114
+ raise('expected an Effective::Order') unless order.kind_of?(Effective::Order)
123
115
 
124
116
  with_service('Customer') do |service|
125
117
  customer = Quickbooks::Model::Customer.new(
126
- primary_email_address: Quickbooks::Model::EmailAddress.new(user.email),
127
- display_name: scrub(user.to_s),
128
- given_name: scrub(user.try(:first_name)),
129
- family_name: scrub(user.try(:last_name))
118
+ primary_email_address: Quickbooks::Model::EmailAddress.new(order.email),
119
+ display_name: scrub(order.billing_name)
130
120
  )
131
121
 
132
122
  service.create(customer)
@@ -10,9 +10,7 @@ module Effective
10
10
 
11
11
  order = receipt.order
12
12
  raise('Expected a purchased Effective::Order') unless order.purchased?
13
-
14
- user = order.user
15
- raise('Expected a user with an email') unless user.respond_to?(:email)
13
+ raise('Expected an order with billing name') unless order.billing_name.present?
16
14
 
17
15
  realm = api.realm
18
16
  raise('Missing Deposit to Account') unless realm.deposit_to_account_id.present?
@@ -68,7 +66,7 @@ module Effective
68
66
 
69
67
  # Find or build customer
70
68
  if receipt.customer_id.blank?
71
- customer = api.find_or_create_customer(user: user)
69
+ customer = api.find_or_create_customer(order: order)
72
70
  receipt.update!(customer_id: customer.id)
73
71
  end
74
72
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveQbOnline
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_qb_online
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-24 00:00:00.000000000 Z
11
+ date: 2024-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails