1
|
|
|
package flutterwave |
2
|
|
|
|
3
|
|
|
import "time" |
4
|
|
|
|
5
|
|
|
const ( |
6
|
|
|
// HeaderNameVerifHash is the name of the header used to verify your webhook requests. |
7
|
|
|
HeaderNameVerifHash = "verif-hash" |
8
|
|
|
) |
9
|
|
|
|
10
|
|
|
const ( |
11
|
|
|
eventChargeCompleted = "charge.completed" |
12
|
|
|
) |
13
|
|
|
|
14
|
|
|
const ( |
15
|
|
|
statusSuccessful = "successful" |
16
|
|
|
statusFailed = "failed" |
17
|
|
|
) |
18
|
|
|
|
19
|
|
|
// PaymentEventV3 is the payload for webhook requests after a payment |
20
|
|
|
type PaymentEventV3 struct { |
21
|
|
|
Event string `json:"event"` |
22
|
|
|
Data struct { |
23
|
|
|
ID int64 `json:"id"` |
24
|
|
|
TxRef string `json:"tx_ref"` |
25
|
|
|
FlwRef string `json:"flw_ref"` |
26
|
|
|
DeviceFingerprint string `json:"device_fingerprint"` |
27
|
|
|
Amount int `json:"amount"` |
28
|
|
|
Currency string `json:"currency"` |
29
|
|
|
ChargedAmount int `json:"charged_amount"` |
30
|
|
|
AppFee float64 `json:"app_fee"` |
31
|
|
|
MerchantFee int `json:"merchant_fee"` |
32
|
|
|
ProcessorResponse string `json:"processor_response"` |
33
|
|
|
AuthModel string `json:"auth_model"` |
34
|
|
|
IP string `json:"ip"` |
35
|
|
|
Narration string `json:"narration"` |
36
|
|
|
Status string `json:"status"` |
37
|
|
|
PaymentType string `json:"payment_type"` |
38
|
|
|
CreatedAt time.Time `json:"created_at"` |
39
|
|
|
AccountID int `json:"account_id"` |
40
|
|
|
Customer struct { |
41
|
|
|
ID int `json:"id"` |
42
|
|
|
Name string `json:"name"` |
43
|
|
|
PhoneNumber interface{} `json:"phone_number"` |
44
|
|
|
Email string `json:"email"` |
45
|
|
|
CreatedAt time.Time `json:"created_at"` |
46
|
|
|
} `json:"customer"` |
47
|
|
|
Card struct { |
48
|
|
|
First6Digits string `json:"first_6digits"` |
49
|
|
|
Last4Digits string `json:"last_4digits"` |
50
|
|
|
Issuer string `json:"issuer"` |
51
|
|
|
Country string `json:"country"` |
52
|
|
|
Type string `json:"type"` |
53
|
|
|
Expiry string `json:"expiry"` |
54
|
|
|
} `json:"card"` |
55
|
|
|
} `json:"data"` |
56
|
|
|
EventType string `json:"event.type"` |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// IsSuccessful checks if the payment event is successfull |
60
|
|
|
func (event PaymentEventV3) IsSuccessful() bool { |
61
|
|
|
return event.Event == eventChargeCompleted && event.Data.Status == statusSuccessful |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// IsFailed checks if the payment failed |
65
|
|
|
func (event PaymentEventV3) IsFailed() bool { |
66
|
|
|
return event.Event == eventChargeCompleted && event.Data.Status == statusFailed |
67
|
|
|
} |
68
|
|
|
|