This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
forked from uw-labs/go-onfido
-
Notifications
You must be signed in to change notification settings - Fork 2
/
report.go
136 lines (115 loc) · 4.46 KB
/
report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package onfido
import (
"context"
"encoding/json"
"time"
)
// Supported report names, results, subresults, and variants
const (
ReportNameDocument ReportName = "document"
ReportNameDocumentWithAddress ReportName = "document_with_address_information"
ReportNameDocumentWithDrivingLicense ReportName = "document_with_driving_licence_information"
ReportNameFacialSimilarityPhoto ReportName = "facial_similarity_photo"
ReportNameFacialSimilarityVideo ReportName = "facial_similarity_video"
ReportNameKnownFaces ReportName = "known_faces"
ReportNameIdentityEnhanced ReportName = "identity_enhanced"
ReportNameWatchlistEnhanced ReportName = "watchlist_enhanced"
ReportNameWatchlistStandard ReportName = "watchlist_standard"
ReportNameWatchlistPepsOnly ReportName = "watchlist_peps_only"
ReportNameWatchlistSanctionsOnly ReportName = "watchlist_sanctions_only"
ReportNameProofOfAddress ReportName = "proof_of_address"
ReportNameRightToWork ReportName = "right_to_work"
ReportResultClear ReportResult = "clear"
ReportResultConsider ReportResult = "consider"
ReportResultUnidentified ReportResult = "unidentified"
ReportSubResultClear ReportSubResult = "clear"
ReportSubResultRejected ReportSubResult = "rejected"
ReportSubResultSuspected ReportSubResult = "suspected"
ReportSubResultCaution ReportSubResult = "caution"
)
// ReportName represents a report type name
type ReportName string
// ReportResult represents a report result
type ReportResult string
// ReportSubResult represents a report sub result
type ReportSubResult string
// DocumentProcessed contains metadata about the document that has been processed
type DocumentProcessed map[string]interface{}
// Report represents a report from the Onfido API
type Report struct {
ID string `json:"id,omitempty"`
Name ReportName `json:"name,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
Status string `json:"status,omitempty"`
Result ReportResult `json:"result,omitempty"`
SubResult ReportSubResult `json:"sub_result,omitempty"`
Href string `json:"href,omitempty"`
Options map[string]interface{} `json:"options,omitempty"`
Breakdown Breakdowns `json:"breakdown,omitempty"`
Properties Properties `json:"properties,omitempty"`
CheckID string `json:"check_id,omitempty"`
Documents []DocumentProcessed `json:"documents,omitempty"`
}
// Reports represents a list of reports from the Onfido API
type Reports struct {
Reports []*Report `json:"reports"`
}
// GetReport retrieves a report for the provided check by its ID.
// see https://documentation.onfido.com/?shell#retrieve-report
func (c *client) GetReport(ctx context.Context, id string) (*Report, error) {
req, err := c.newRequest("GET", "/reports/"+id, nil)
if err != nil {
return nil, err
}
var resp Report
_, err = c.do(ctx, req, &resp)
return &resp, err
}
// ResumeReport resumes a paused report by its ID.
// see https://documentation.onfido.com/?shell#resume-report
func (c *client) ResumeReport(ctx context.Context, id string) error {
req, err := c.newRequest("POST", "/reports/"+id+"/resume", nil)
if err != nil {
return err
}
_, err = c.do(ctx, req, nil)
return err
}
// CancelReport cancels a report by its ID.
// see https://documentation.onfido.com/?shell#cancel-report
func (c *client) CancelReport(ctx context.Context, id string) error {
req, err := c.newRequest("POST", "/reports/"+id+"/cancel", nil)
if err != nil {
return err
}
_, err = c.do(ctx, req, nil)
return err
}
// ReportIter represents a document iterator
type ReportIter struct {
*iter
}
// Report returns the current item in the iterator as a Report.
func (i *ReportIter) Report() *Report {
return i.Current().(*Report)
}
// ListReports retrieves the list of reports for the provided check.
// see https://documentation.onfido.com/?shell#list-reports
func (c *client) ListReports(checkID string) *ReportIter {
handler := func(body []byte) ([]interface{}, error) {
var r Reports
if err := json.Unmarshal(body, &r); err != nil {
return nil, err
}
values := make([]interface{}, len(r.Reports))
for i, v := range r.Reports {
values[i] = v
}
return values, nil
}
return &ReportIter{&iter{
c: c,
nextURL: "/reports?check_id=" + checkID,
handler: handler,
}}
}