-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmobile_money_gh.go
53 lines (48 loc) · 1.88 KB
/
mobile_money_gh.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
package ravepay
import (
"encoding/json"
"log"
)
// MobileMoneyGH is a type that encapsulates rave's ghana mobile money description
// It has all mpesa attributes necessary for rave api ghana mobile money description references
// It also implements the chargable interface required for making charge requests and validating them
type MobileMoneyGH struct {
ChargeRequestURL string `json:"-"`
Currency string `json:"currency"`
Country string `json:"country"`
LastName string `json:"lastname,omitempty"`
FirstName string `json:"firstname,omitempty"`
IsMobileMoneyGH int `json:"is_mobile_money_gh"`
Network string `json:"network"`
}
// ChargeURL is an implemenation of the Chargeable interface
// it returns the url to be used for charging the given card
func (gh *MobileMoneyGH) ChargeURL() string {
if gh.ChargeRequestURL == "" {
gh.ChargeRequestURL = buildURL(defaultChargeURL)
}
return gh.ChargeRequestURL
}
// ValidateChargeURL is an implemenation of the Chargeable interface
// it returns the url to be used for charging the given card
func (gh *MobileMoneyGH) ValidateChargeURL() string {
return ""
}
// BuildChargeRequestPayload is an implemenation of the Chargeable interface
// it returns the byte representation of the charge request client
// at the ChargeRequest level, chargeables are merely interface objects
// so trying to compose a struct with an interface object results in go adding the interface name key to the result bytes
// see https://play.golang.com/p/MFfbuPLrjo6
// so here we upend it so the individual concrete types do the marshalling
func (gh *MobileMoneyGH) BuildChargeRequestPayload(cReq *ChargeRequest) []byte {
cReq.PaymentType = "mobilemoneygh"
payload := struct {
*MobileMoneyGH
*ChargeRequest
}{gh, cReq}
b, err := json.Marshal(payload)
if err != nil {
log.Println("couldn't marshal payload: ", err)
}
return b
}