elasticfin 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c78e701014b495c4f7e12b88a46d8f1de01ec24e444d1d9eef8a30a9a7f0bb6e
4
- data.tar.gz: ec13a239c75b63583d8753a72b2ae168080d8699a8859e35df0566c0e590e4d5
3
+ metadata.gz: 6cf1202e392aa22187ef6aadf489a4c79ae1ebf595347e1f1b6f559f7e814acc
4
+ data.tar.gz: 8ada24734f3e69162cfb062f3309987c0d74e076be05e4f2e68dd51f8599aeae
5
5
  SHA512:
6
- metadata.gz: 15f626f3542b2ac4048bc9c6535678e0a80d79339f724d662108c1bb2558d35cea1c118147b360b10ab0ef056cafd55fd6f941237cafc29133a8768a2bfc3954
7
- data.tar.gz: 4eaaf8c667ddf1115a71b7ef122400a0343b8938af2d13442ed7bfbdc8d0b5e9376ec3e1edf541652d2f93d286ad7bb3ca6b2cc6dba1bcf00f3f2cdcd5db77a6
6
+ metadata.gz: 973de4dc109f63a9818bf4e0dbd876255b0e9f6a57f4c17a2efbd578547f88e5d8c4abbeff167a8982f69d7331bd1d3deaabddf214e8aec36c35e64f8b6646a0
7
+ data.tar.gz: 365489562e0b799b2b86b94b1a840f26cd20a3abd0b2592727b0acb7a3e2d139b392b0839f8335b297067a33887bb44a5b4351bccd3b9a8b95792f511f8766f6
data/README.md CHANGED
@@ -28,12 +28,20 @@ end
28
28
 
29
29
  By default uses `:id` for external_id and auto-detects `:email` or `:email_address`.
30
30
 
31
- Customize if needed:
31
+ **Options:**
32
32
 
33
33
  ```ruby
34
34
  elasticfin_billable external_id: :uuid, email: :contact_email
35
35
  ```
36
36
 
37
+ **Auto-sync on create/update:**
38
+
39
+ ```ruby
40
+ elasticfin_billable auto_sync: true
41
+ ```
42
+
43
+ This automatically syncs customers to Elasticfin when created or when email/external_id changes.
44
+
37
45
  ## Usage
38
46
 
39
47
  All methods are called on instances of your billable model:
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Elasticfin
4
4
  module Billable
5
- def elasticfin_billable(external_id: :id, email: nil)
5
+ def elasticfin_billable(external_id: :id, email: nil, auto_sync: false)
6
6
  include InstanceMethods
7
7
  extend ClassMethods
8
8
 
@@ -15,6 +15,12 @@ module Elasticfin
15
15
 
16
16
  # Register this model with Elasticfin
17
17
  Elasticfin.register_billable_model(self)
18
+
19
+ # Add auto-sync callbacks if enabled
20
+ if auto_sync
21
+ after_create :elasticfin_sync
22
+ after_update :elasticfin_sync_if_changed
23
+ end
18
24
  end
19
25
 
20
26
  def self.detect_email_field
@@ -66,6 +72,15 @@ module Elasticfin
66
72
  Elasticfin.sync_customer(self)
67
73
  end
68
74
 
75
+ def elasticfin_sync_if_changed
76
+ id_field = self.class.elasticfin_external_id_field
77
+ email_field = self.class.elasticfin_email_field
78
+
79
+ if saved_change_to_attribute?(id_field) || saved_change_to_attribute?(email_field)
80
+ elasticfin_sync
81
+ end
82
+ end
83
+
69
84
  # Checkout
70
85
  def elasticfin_checkout_url(price_id:)
71
86
  Elasticfin.checkout.create_session(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Elasticfin
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticfin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - elasticfin