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 +4 -4
- data/README.md +9 -1
- data/lib/elasticfin/billable.rb +16 -1
- data/lib/elasticfin/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6cf1202e392aa22187ef6aadf489a4c79ae1ebf595347e1f1b6f559f7e814acc
|
|
4
|
+
data.tar.gz: 8ada24734f3e69162cfb062f3309987c0d74e076be05e4f2e68dd51f8599aeae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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:
|
data/lib/elasticfin/billable.rb
CHANGED
|
@@ -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(
|
data/lib/elasticfin/version.rb
CHANGED