factpulse 2.0.13 → 2.0.15
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/CHANGELOG.md +3 -3
- data/Gemfile.lock +1 -1
- data/lib/factpulse/helpers/client.rb +82 -2
- data/lib/factpulse/helpers.rb +5 -1
- data/lib/factpulse/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: 3da860c71e15cff4b5aba46ce609a41208b41160587a9db29527af206980d169
|
|
4
|
+
data.tar.gz: 1623fb5cb93a19ac8e2920bc709d4a87f1350dd65832b15f616e9208d5463593
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95f30c17f1bd1c7c11a0531b2ad89ca370777722661e86d23d336cc7403fb3f968464aa0df8f9e60130b784befaaff26d1756c24d13c3d9453c3f3ce50099599
|
|
7
|
+
data.tar.gz: f6b594c721a29d2dae65539f49d57ce60ced99a7533f637e014d1b8d9ef700d10a36dcdc307217518a80df81ba9b7ab91f284062ad598d947b9393b673828208
|
data/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,7 @@ et ce projet adhère au [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [2.0.
|
|
10
|
+
## [2.0.15] - 2025-11-26
|
|
11
11
|
|
|
12
12
|
### Added
|
|
13
13
|
- Version initiale du SDK ruby
|
|
@@ -24,5 +24,5 @@ et ce projet adhère au [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
24
24
|
- Guide d'authentification JWT
|
|
25
25
|
- Configuration avancée (timeout, proxy, debug)
|
|
26
26
|
|
|
27
|
-
[Unreleased]: https://github.com/factpulse/sdk-ruby/compare/v2.0.
|
|
28
|
-
[2.0.
|
|
27
|
+
[Unreleased]: https://github.com/factpulse/sdk-ruby/compare/v2.0.15...HEAD
|
|
28
|
+
[2.0.15]: https://github.com/factpulse/sdk-ruby/releases/tag/v2.0.15
|
data/Gemfile.lock
CHANGED
|
@@ -3,13 +3,93 @@ require 'net/http'; require 'json'; require 'base64'; require 'uri'; require 'se
|
|
|
3
3
|
|
|
4
4
|
module FactPulse
|
|
5
5
|
module Helpers
|
|
6
|
+
# Credentials Chorus Pro pour le mode Zero-Trust.
|
|
7
|
+
# Ces credentials sont passés dans chaque requête et ne sont jamais stockés côté serveur.
|
|
8
|
+
class ChorusProCredentials
|
|
9
|
+
attr_reader :piste_client_id, :piste_client_secret, :chorus_pro_login, :chorus_pro_password, :sandbox
|
|
10
|
+
def initialize(piste_client_id:, piste_client_secret:, chorus_pro_login:, chorus_pro_password:, sandbox: true)
|
|
11
|
+
@piste_client_id, @piste_client_secret = piste_client_id, piste_client_secret
|
|
12
|
+
@chorus_pro_login, @chorus_pro_password, @sandbox = chorus_pro_login, chorus_pro_password, sandbox
|
|
13
|
+
end
|
|
14
|
+
def to_h
|
|
15
|
+
{ 'piste_client_id' => @piste_client_id, 'piste_client_secret' => @piste_client_secret,
|
|
16
|
+
'chorus_pro_login' => @chorus_pro_login, 'chorus_pro_password' => @chorus_pro_password, 'sandbox' => @sandbox }
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Credentials AFNOR PDP pour le mode Zero-Trust.
|
|
21
|
+
# Ces credentials sont passés dans chaque requête et ne sont jamais stockés côté serveur.
|
|
22
|
+
class AFNORCredentials
|
|
23
|
+
attr_reader :client_id, :client_secret, :flow_service_url
|
|
24
|
+
def initialize(client_id:, client_secret:, flow_service_url:)
|
|
25
|
+
@client_id, @client_secret, @flow_service_url = client_id, client_secret, flow_service_url
|
|
26
|
+
end
|
|
27
|
+
def to_h
|
|
28
|
+
{ 'client_id' => @client_id, 'client_secret' => @client_secret, 'flow_service_url' => @flow_service_url }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Helpers pour créer des montants totaux simplifiés.
|
|
33
|
+
module MontantHelpers
|
|
34
|
+
def self.montant(value)
|
|
35
|
+
return '0.00' if value.nil?
|
|
36
|
+
return format('%.2f', value) if value.is_a?(Numeric)
|
|
37
|
+
value.is_a?(String) ? value : '0.00'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.montant_total(ht, tva, ttc, a_payer, remise_ttc: nil, motif_remise: nil, acompte: nil)
|
|
41
|
+
result = {
|
|
42
|
+
'montantHtTotal' => montant(ht), 'montantTva' => montant(tva),
|
|
43
|
+
'montantTtcTotal' => montant(ttc), 'montantAPayer' => montant(a_payer)
|
|
44
|
+
}
|
|
45
|
+
result['montantRemiseGlobaleTtc'] = montant(remise_ttc) if remise_ttc
|
|
46
|
+
result['motifRemiseGlobaleTtc'] = motif_remise if motif_remise
|
|
47
|
+
result['acompte'] = montant(acompte) if acompte
|
|
48
|
+
result
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.ligne_de_poste(numero, denomination, quantite, montant_unitaire_ht, montant_ligne_ht,
|
|
52
|
+
taux_tva: '20.00', unite: 'C62', **options)
|
|
53
|
+
result = {
|
|
54
|
+
'numero' => numero, 'denomination' => denomination,
|
|
55
|
+
'quantite' => montant(quantite), 'montantUnitaireHt' => montant(montant_unitaire_ht),
|
|
56
|
+
'montantTotalLigneHt' => montant(montant_ligne_ht), 'tauxTva' => montant(taux_tva), 'unite' => unite
|
|
57
|
+
}
|
|
58
|
+
result['montantTvaLigne'] = montant(options[:montant_tva_ligne]) if options[:montant_tva_ligne]
|
|
59
|
+
result['montantRemiseHt'] = montant(options[:montant_remise_ht]) if options[:montant_remise_ht]
|
|
60
|
+
result['codeRaisonReduction'] = options[:code_raison_remise] if options[:code_raison_remise]
|
|
61
|
+
result['motifRemise'] = options[:motif_remise] if options[:motif_remise]
|
|
62
|
+
result['description'] = options[:description] if options[:description]
|
|
63
|
+
result
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def self.ligne_de_tva(taux, base_ht, montant_tva, categorie: 'S', motif_exoneration: nil)
|
|
67
|
+
result = {
|
|
68
|
+
'tauxTva' => montant(taux), 'montantBaseHt' => montant(base_ht),
|
|
69
|
+
'montantTva' => montant(montant_tva), 'categorieTva' => categorie
|
|
70
|
+
}
|
|
71
|
+
result['motifExoneration'] = motif_exoneration if motif_exoneration
|
|
72
|
+
result
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
6
76
|
class FactPulseClient
|
|
7
|
-
|
|
77
|
+
attr_reader :chorus_credentials, :afnor_credentials
|
|
78
|
+
|
|
79
|
+
def initialize(email:, password:, api_url: nil, client_uid: nil, chorus_credentials: nil, afnor_credentials: nil,
|
|
80
|
+
polling_interval: nil, polling_timeout: nil, max_retries: nil)
|
|
8
81
|
@email, @password = email, password; @api_url = (api_url || 'https://factpulse.fr').chomp('/')
|
|
9
82
|
@client_uid, @polling_interval, @polling_timeout, @max_retries = client_uid, polling_interval || 2000, polling_timeout || 120000, max_retries || 1
|
|
83
|
+
@chorus_credentials, @afnor_credentials = chorus_credentials, afnor_credentials
|
|
10
84
|
@access_token = @refresh_token = @token_expires_at = nil
|
|
11
85
|
end
|
|
12
86
|
|
|
87
|
+
def chorus_credentials_for_api; @chorus_credentials&.to_h; end
|
|
88
|
+
def afnor_credentials_for_api; @afnor_credentials&.to_h; end
|
|
89
|
+
# Alias plus courts
|
|
90
|
+
def get_chorus_pro_credentials; chorus_credentials_for_api; end
|
|
91
|
+
def get_afnor_credentials; afnor_credentials_for_api; end
|
|
92
|
+
|
|
13
93
|
def ensure_authenticated(force_refresh: false)
|
|
14
94
|
now = (Time.now.to_f * 1000).to_i
|
|
15
95
|
if force_refresh || @access_token.nil? || (@token_expires_at && now >= @token_expires_at)
|
|
@@ -40,7 +120,7 @@ module FactPulse
|
|
|
40
120
|
end
|
|
41
121
|
end
|
|
42
122
|
|
|
43
|
-
def self.format_montant(m);
|
|
123
|
+
def self.format_montant(m); MontantHelpers.montant(m); end
|
|
44
124
|
|
|
45
125
|
private
|
|
46
126
|
def http_post(uri, payload)
|
data/lib/factpulse/helpers.rb
CHANGED
|
@@ -4,6 +4,10 @@ require_relative 'helpers/client'
|
|
|
4
4
|
module FactPulse
|
|
5
5
|
module Helpers
|
|
6
6
|
def self.create_client(**opts); FactPulseClient.new(**opts); end
|
|
7
|
-
def self.format_montant(m);
|
|
7
|
+
def self.format_montant(m); MontantHelpers.montant(m); end
|
|
8
|
+
def self.montant(m); MontantHelpers.montant(m); end
|
|
9
|
+
def self.montant_total(*args, **kwargs); MontantHelpers.montant_total(*args, **kwargs); end
|
|
10
|
+
def self.ligne_de_poste(*args, **kwargs); MontantHelpers.ligne_de_poste(*args, **kwargs); end
|
|
11
|
+
def self.ligne_de_tva(*args, **kwargs); MontantHelpers.ligne_de_tva(*args, **kwargs); end
|
|
8
12
|
end
|
|
9
13
|
end
|
data/lib/factpulse/version.rb
CHANGED