einvoicing-connect 0.2.0 → 0.3.0
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/lib/einvoicing/connect/fr/pennylane/client.rb +41 -0
- data/lib/einvoicing/connect/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: c1d5afb37eec4ff165c07ca7f35ca30470385c3c9820fe012f69bdb2b663d347
|
|
4
|
+
data.tar.gz: 79882e661a1683484e4a5ffdcc53640916e70b0b5e997a85b0a58ee14e74dfb2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8f426765e61378bbbb5a8e7c7ea0860b93c9e73d0be38287b7d690731a095277ee62ed4d97570c4181f3086f6eae5ceacc1e706b15cbb470a1be779b524c71d
|
|
7
|
+
data.tar.gz: cec80f177749ff036fb921d011fa2f4b909647c1dfa29af808e49984a334cfe1ca4cb1ae0308eb20be6e0a0516212eb2bdb11f03d1f44b914e79ef94dcf34b9c
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "net/http"
|
|
4
4
|
require "json"
|
|
5
5
|
require "uri"
|
|
6
|
+
require "cgi"
|
|
6
7
|
require "securerandom"
|
|
7
8
|
|
|
8
9
|
module Einvoicing
|
|
@@ -36,6 +37,46 @@ module Einvoicing
|
|
|
36
37
|
get("/customer_invoices/#{id}")
|
|
37
38
|
end
|
|
38
39
|
|
|
40
|
+
# Find a customer by the caller's own identifier.
|
|
41
|
+
#
|
|
42
|
+
# Pennylane does not match a customer from the invoice itself: a
|
|
43
|
+
# document imported without +customer_id+ lands as "incomplete" with
|
|
44
|
+
# customer nil, whatever SIRET or VAT number the Factur-X carries.
|
|
45
|
+
# +external_reference+ is the caller's key into Pennylane's own
|
|
46
|
+
# numbering, which is what makes resolution repeatable.
|
|
47
|
+
#
|
|
48
|
+
# @return [Hash, nil] the customer, or nil when none carries that reference
|
|
49
|
+
def customer_by_reference(reference)
|
|
50
|
+
filter = JSON.generate([ { field: "external_reference", operator: "eq", value: reference } ])
|
|
51
|
+
get("/customers?filter=#{CGI.escape(filter)}")["items"]&.first
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Create a company customer (an organisation, invoiced under its own name).
|
|
55
|
+
#
|
|
56
|
+
# @param attributes [Hash] at least +name+ and +billing_address+;
|
|
57
|
+
# +reg_no+ carries the SIRET, +external_reference+ the caller's key.
|
|
58
|
+
def create_company_customer(attributes)
|
|
59
|
+
post("/company_customers", attributes)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Create an individual customer (a private person).
|
|
63
|
+
def create_individual_customer(attributes)
|
|
64
|
+
post("/individual_customers", attributes)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# The customer for +reference+, created from +attributes+ if Pennylane
|
|
68
|
+
# does not know it yet. Idempotent as long as the caller keeps the
|
|
69
|
+
# reference stable, which is the point of it.
|
|
70
|
+
#
|
|
71
|
+
# @param company [Boolean] an organisation rather than a private person
|
|
72
|
+
def find_or_create_customer(reference:, attributes:, company: true)
|
|
73
|
+
existing = customer_by_reference(reference)
|
|
74
|
+
return existing if existing
|
|
75
|
+
|
|
76
|
+
payload = attributes.merge(external_reference: reference)
|
|
77
|
+
company ? create_company_customer(payload) : create_individual_customer(payload)
|
|
78
|
+
end
|
|
79
|
+
|
|
39
80
|
private
|
|
40
81
|
|
|
41
82
|
def current_token
|