-
Notifications
You must be signed in to change notification settings - Fork 19
/
services.go
76 lines (61 loc) · 2.22 KB
/
services.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
package flows
import (
"net/http"
"time"
"github.com/nyaruka/gocommon/urns"
"github.com/shopspring/decimal"
)
// Services groups together interfaces for several services whose implementation existsi outside of the flow engine.
type Services interface {
Webhook() WebhookService
Airtime() AirtimeService
}
// WebhookStatus represents the status of a webhook call
type WebhookStatus string
const (
// WebhookStatusSuccess represents that the webhook was successful
WebhookStatusSuccess WebhookStatus = "success"
// WebhookStatusConnectionError represents that the webhook had a connection error
WebhookStatusConnectionError WebhookStatus = "connection_error"
// WebhookStatusResponseError represents that the webhook response had a non 2xx status code
WebhookStatusResponseError WebhookStatus = "response_error"
// WebhookStatusSubscriberGone represents a special state of resthook responses which indicate the caller must remove that subscriber
WebhookStatusSubscriberGone WebhookStatus = "subscriber_gone"
)
// WebhookCall is the result of a webhook call
type WebhookCall struct {
URL string
Method string
StatusCode int
Status WebhookStatus
TimeTaken time.Duration
Request []byte
Response []byte
BodyIgnored bool
Resthook string
}
// WebhookService provides webhook calling functionality to the engine
type WebhookService interface {
Call(*http.Request, string) (*WebhookCall, error)
}
// AirtimeTransferStatus is a status of a airtime transfer
type AirtimeTransferStatus string
// possible values for airtime transfer statuses
const (
AirtimeTransferStatusSuccess AirtimeTransferStatus = "success"
AirtimeTransferStatusFailed AirtimeTransferStatus = "failed"
)
// AirtimeTransfer is the result of an attempted airtime transfer
type AirtimeTransfer struct {
Sender urns.URN
Recipient urns.URN
Currency string
DesiredAmount decimal.Decimal
ActualAmount decimal.Decimal
Status AirtimeTransferStatus
}
// AirtimeService is the interface for an airtime transfer service
type AirtimeService interface {
// Transfer transfers airtime to the given URN
Transfer(session Session, sender urns.URN, recipient urns.URN, amounts map[string]decimal.Decimal) (*AirtimeTransfer, error)
}