-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdocument.go
100 lines (84 loc) · 3.08 KB
/
document.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
package dwolla
import (
"context"
"fmt"
"io"
)
const (
// DocumentScanIDTypeNotSupported is when the scanned I.D. type is not
// supported
DocumentScanIDTypeNotSupported DocumentFailureReason = "ScanIdTypeNotSupported"
// DocumentNameMismatch is when the scanned document name does not match
DocumentScanNameMismatch DocumentFailureReason = "ScanNameMismatch"
// DocumentScanNotReadable is when the scanned document is not readable
DocumentScanNotReadable DocumentFailureReason = "ScanNotReadable"
// DocumentScanNotUploaded is when the scanned document failed to upload
DocumentScanNotUploaded DocumentFailureReason = "ScanNotUploaded"
// DocumentScanFailedOther is when the scanned document was rejected for
// another reason
DocumentScanFailedOther DocumentFailureReason = "ScanFailedOther"
// DocumentFailedOther is when the document was rejected for another
// reason
DocumentFailedOther DocumentFailureReason = "FailedOther"
)
const (
// DocumentStatusPending is when the document is pending review
DocumentStatusPending DocumentStatus = "pending"
// DocumentStatusReviewed is when the document has been reviewed
DocumentStatusReviewed DocumentStatus = "reviewed"
)
const (
// DocumentTypePassport is a passport
DocumentTypePassport DocumentType = "passport"
// DocumentTypeLicense is a state-issued driver's license
DocumentTypeLicense DocumentType = "license"
// DocumentTypeIDCard is a U.S. government issued photo I.D. card
DocumentTypeIDCard DocumentType = "idCard"
// DocumentTypeOther is an EIN Letter / IRS-issued SS4 Confirmation Letter
DocumentTypeOther DocumentType = "other"
)
// DocumentService is the document service interface
//
// see: https://docsv2.dwolla.com/#documents
type DocumentService interface {
Retrieve(context.Context, string) (*Document, error)
}
// DocumentServiceOp is an implementation of the document service
type DocumentServiceOp struct {
client *Client
}
// Document is a dwolla verification document
type Document struct {
Resource
ID string `json:"id"`
Status DocumentStatus `json:"status"`
Type DocumentType `json:"type"`
Created string `json:"created"`
FailureReason DocumentFailureReason `json:"failureReason"`
}
// DocumentFailureReason is the reason document verification failed
type DocumentFailureReason string
// Documents is a collection of dwolla documents
type Documents struct {
Collection
Embedded map[string][]Document `json:"_embedded"`
}
// DocumentStatus is the status of the document
type DocumentStatus string
// DocumentType is the type of document
type DocumentType string
// DocumentRequest is a verification document request
type DocumentRequest struct {
Type DocumentType
FileName string
File io.Reader
}
// Retrieve retrieves a document matching the id
func (d *DocumentServiceOp) Retrieve(ctx context.Context, id string) (*Document, error) {
var document Document
if err := d.client.Get(ctx, fmt.Sprintf("documents/%s", id), nil, nil, &document); err != nil {
return nil, err
}
document.client = d.client
return &document, nil
}