-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect.go
66 lines (55 loc) · 2 KB
/
collect.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
package bankid
import (
"encoding/xml"
"fmt"
)
type orderRef struct {
XMLName xml.Name `xml:"typ:orderRef"`
OrderRef string `xml:",chardata"`
}
// CollectResponse is the response from a bankid collect-request
type CollectResponse struct {
XMLName xml.Name `xml:"CollectResponse"`
Status progressStatus `xml:"progressStatus"`
Signature string `xml:"signature"`
UserInfo UserInfo `xml:"userInfo"`
}
type progressStatus string
// Different statuses received from bankid-api
const (
StatusOutstandingTransaction progressStatus = "OUTSTANDING_TRANSACTION"
StatusNoClient progressStatus = "NO_CLIENT"
StatusStarted progressStatus = "STARTED"
StatusUserSign progressStatus = "USER_SIGN"
StatusUserReq progressStatus = "USER_REQ"
StatusComplete progressStatus = "COMPLETE"
)
// UserInfo is all information about a user returned from bankid-api
type UserInfo struct {
GivenName string `xml:"givenName"`
Surname string `xml:"surname"`
Name string `xml:"name"`
PersonalNumber string `xml:"personalNumber"`
NotBefore string `xml:"notBefore"`
NotAfter string `xml:"notAfter"`
IPAddress string `xml:"ipAddress"`
}
// Collect is a method to call the Collect resource on the BankID API.
func (c *Client) Collect(ref string) (*CollectResponse, error) {
respEnvelope := new(soapEnvelope)
respEnvelope.Body = soapBody{Content: &AuthResponse{}}
orderRef := &orderRef{
OrderRef: ref,
}
respEnvelope.Body = soapBody{Content: &CollectResponse{}}
err := c.RoundTripSoap12("Collect", orderRef, respEnvelope)
if err != nil {
return nil, err
}
collResp, ok := respEnvelope.Body.Content.(*CollectResponse)
if !ok {
err = fmt.Errorf("errorcode: %v \n string: %v \n faultStatus: %v \n detailed: %v", respEnvelope.Body.Fault.String, respEnvelope.Body.Fault.Code, respEnvelope.Body.Fault.Detail.FaultStatus, respEnvelope.Body.Fault.Detail.Description)
return nil, err
}
return collResp, nil
}