-
Notifications
You must be signed in to change notification settings - Fork 2
/
webhook.go
67 lines (60 loc) · 2.2 KB
/
webhook.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
package flutterwave
import "time"
const (
// HeaderNameVerifHash is the name of the header used to verify your webhook requests.
HeaderNameVerifHash = "verif-hash"
)
const (
eventChargeCompleted = "charge.completed"
)
const (
statusSuccessful = "successful"
statusFailed = "failed"
)
// PaymentEventV3 is the payload for webhook requests after a payment
type PaymentEventV3 struct {
Event string `json:"event"`
Data struct {
ID int64 `json:"id"`
TxRef string `json:"tx_ref"`
FlwRef string `json:"flw_ref"`
DeviceFingerprint string `json:"device_fingerprint"`
Amount int `json:"amount"`
Currency string `json:"currency"`
ChargedAmount int `json:"charged_amount"`
AppFee float64 `json:"app_fee"`
MerchantFee int `json:"merchant_fee"`
ProcessorResponse string `json:"processor_response"`
AuthModel string `json:"auth_model"`
IP string `json:"ip"`
Narration string `json:"narration"`
Status string `json:"status"`
PaymentType string `json:"payment_type"`
CreatedAt time.Time `json:"created_at"`
AccountID int `json:"account_id"`
Customer struct {
ID int `json:"id"`
Name string `json:"name"`
PhoneNumber interface{} `json:"phone_number"`
Email string `json:"email"`
CreatedAt time.Time `json:"created_at"`
} `json:"customer"`
Card struct {
First6Digits string `json:"first_6digits"`
Last4Digits string `json:"last_4digits"`
Issuer string `json:"issuer"`
Country string `json:"country"`
Type string `json:"type"`
Expiry string `json:"expiry"`
} `json:"card"`
} `json:"data"`
EventType string `json:"event.type"`
}
// IsSuccessful checks if the payment event is successfull
func (event PaymentEventV3) IsSuccessful() bool {
return event.Event == eventChargeCompleted && event.Data.Status == statusSuccessful
}
// IsFailed checks if the payment failed
func (event PaymentEventV3) IsFailed() bool {
return event.Event == eventChargeCompleted && event.Data.Status == statusFailed
}