Skip to content

Commit

Permalink
add factures service
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine2116 committed Oct 30, 2023
1 parent 5b158d2 commit cfae2d1
Show file tree
Hide file tree
Showing 20 changed files with 1,899 additions and 21 deletions.
21 changes: 21 additions & 0 deletions choruspro.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -66,6 +67,7 @@ type Client struct {

// Services
Transverses *TransversesService
Factures *FacturesService
}

type service struct {
Expand Down Expand Up @@ -103,6 +105,7 @@ func (c *Client) initialize() {
c.BaseUrl, _ = url.Parse(defaultBaseURL)
c.AuthUrl, _ = url.Parse(defaultAuthURL)
c.Transverses = (*TransversesService)(&c.common)
c.Factures = (*FacturesService)(&c.common)
}

func (c *Client) newRequest(ctx context.Context, method, url string, body interface{}) (*http.Request, error) {
Expand Down Expand Up @@ -161,6 +164,8 @@ func (c *Client) doRequest(ctx context.Context, req *http.Request, obj interface
}

data, err := io.ReadAll(res.Body)
// Print
log.Println(string(data))
if err != nil {
return nil
}
Expand Down Expand Up @@ -215,3 +220,19 @@ func getOAuthToken(clientId, clientSecret string, authUrl *url.URL) (*oauth2.Tok

return tok, nil
}

// Bool is a helper routine that allocates a new bool value
// to store v and returns a pointer to it.
func Bool(v bool) *bool { return &v }

// Int is a helper routine that allocates a new int value
// to store v and returns a pointer to it.
func Int(v int) *int { return &v }

// Int64 is a helper routine that allocates a new int64 value
// to store v and returns a pointer to it.
func Int64(v int64) *int64 { return &v }

// String is a helper routine that allocates a new string value
// to store v and returns a pointer to it.
func String(v string) *string { return &v }
6 changes: 6 additions & 0 deletions choruspro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const (
baseAuthPath = "/api/oauth/token"
)

var (
defaultDate = time.Date(2023, 01, 01, 0, 0, 0, 0, time.UTC)
defaultDateStr = `"2023-01-01"`
defaultDateTimeStr = `"2023-01-01T00:00:00Z"`
)

func setup() (client *Client, mux *http.ServeMux, teardown func()) {
client, mux, teardown = bareSetup()

Expand Down
15 changes: 15 additions & 0 deletions date.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package choruspro

import (
"time"
)

type Date struct {
time.Time
}

func (t *Date) UnmarshalJSON(data []byte) error {
var err error
t.Time, err = time.Parse("\"2006-01-02\"", string(data))
return err
}
64 changes: 64 additions & 0 deletions factures.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package choruspro

// FacturesService gère les appels à l'API Facture
// API docs : https://developer.aife.economie.gouv.fr/api-catalog-sandbox?filter=Factures
type FacturesService service

type ActionFacture string

const (
ActionFactureRefus ActionFacture = "REFUS"
ActionFactureValidation ActionFacture = "VALIDATION"
ActionFactureMiseEnPaiement ActionFacture = "MISE_EN_PAIEMENT"
ActionFactureMiseEnRecyclage ActionFacture = "MISE_EN_RECYCLAGE"
ActionFactureSuspension ActionFacture = "SUSPENSION"
ActionFactureRejet ActionFacture = "REJET"
)

type CadreFac string

const (
CodeFacA1 CadreFac = "A1_FACTURE_FOURNISSEUR"
CodeFacA2 CadreFac = "A2_FACTURE_FOURNISSEUR_DEJA_PAYEE"
CodeFacA3 CadreFac = "A3_MEMOIRE_JUSTICE"
CodeFacA4 CadreFac = "A4_PROJET_DECOMPTE_MENSUEL_FOURNISSEUR"
CodeFacA5 CadreFac = "A5_ETAT_ACOMPTE_FOURNISSEUR"
CodeFacA6 CadreFac = "A6_ETAT_ACOMPTE_VALIDE_FOURNISSEUR"
CodeFacA7 CadreFac = "A7_PROJET_DECOMPTE_FINAL_FOURNISSEUR"
CodeFacA8 CadreFac = "A8_DECOMPTE_GENERAL_DEFINITIF_FOURNISSEUR"
CodeFacA9 CadreFac = "A9_FACTURE_SOUSTRAITANT"
CodeFacA10 CadreFac = "A10_PROJET_DECOMPTE_MENSUEL_SOUSTRAITANT"
CodeFacA11 CadreFac = "A11_PROJET_DECOMPTE_FINAL_SOUSTRAITANT"
CodeFacA12 CadreFac = "A12_FACTURE_COTRAITANT"
CodeFacA13 CadreFac = "A13_PROJET_DECOMPTE_MENSUEL_COTRAITANT"
CodeFacA14 CadreFac = "A14_PROJET_DECOMPTE_FINAL_COTRAITANT"
CodeFacA15 CadreFac = "A15_ETAT_ACOMPTE_MOE"
CodeFacA16 CadreFac = "A16_ETAT_ACOMPTE_VALIDE_MOE"
CodeFacA17 CadreFac = "A17_PROJET_DECOMPTE_GENERAL_MOE"
CodeFacA18 CadreFac = "A18_DECOMPTE_GENERAL_MOE"
CodeFacA19 CadreFac = "A19_ETAT_ACOMPTE_VALIDE_MOA"
CodeFacA20 CadreFac = "A20_DECOMPTE_GENERAL_MOA"
CodeFacA21 CadreFac = "A21_DEMANDE_REMBOURSEMENT_TIC"
CodeFacA22 CadreFac = "A22_PROJET_DECOMPTE_GENERAL_FOURNISSEUR_PROCEDURE_TACITE"
CodeFacA23 CadreFac = "A23_DECOMPTE_GENERAL_DEFINITIF_TACITE_FOURNISSEUR"
CodeFacA24 CadreFac = "A24_DECOMPTE_GENERAL_DEFINITIF_TACITE_MOE"
CodeFacA25 CadreFac = "A25_DECOMPTE_GENERAL_DEFINITIF_MOE_PROCEDURE_TACITE"
)

type RoleUtilisateur string

const (
RoleFournisseur RoleUtilisateur = "FOURNISSEUR"
RoleMoe RoleUtilisateur = "MOE"
RoleMoa RoleUtilisateur = "MOA"
RoleValidateur RoleUtilisateur = "VALIDATEUR"
RoleDestinataire RoleUtilisateur = "DESTINATAIRE"
)

type TypeFacture string

const (
TypeFactureFacture TypeFacture = "FACTURE"
TypeFactureAvoir TypeFacture = "AVOIR"
TypeFactureAcompte TypeFacture = "ACOMPTE"
)
Loading

0 comments on commit cfae2d1

Please sign in to comment.