Test Setup Failed
Push — main ( 97f3ea...a413d7 )
by Acho
03:05
created

mtnmomo.*BasicUserInfo.FullName   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
package mtnmomo
2
3
import "strings"
4
5
type AccountHolderIDType string
6
7
const (
8
	// AccountHolderIDTypeMSISDN is the account holder ID type for a mobile number
9
	AccountHolderIDTypeMSISDN AccountHolderIDType = "msisdn"
10
11
	// AccountHolderIDTypeEMAIL is the account holder ID type for an email address
12
	AccountHolderIDTypeEMAIL AccountHolderIDType = "email"
13
)
14
15
// AccountHolderStatus is the status of an account holder
16
type AccountHolderStatus struct {
17
	IsActive bool `json:"result"`
18
}
19
20
// BasicUserInfo contains personal information of an account holder
21
type BasicUserInfo struct {
22
	GivenName  string `json:"given_name"`
23
	FamilyName string `json:"family_name"`
24
	Sub        string `json:"sub"`
25
}
26
27
// FullName returns the full name of the account holder
28
func (info *BasicUserInfo) FullName() string {
29
	return strings.TrimSpace(info.FamilyName + " " + info.GivenName)
30
}
31
32
// RequestToPayParams is the set of parameters used when creating a payment request
33
type RequestToPayParams struct {
34
	Amount       string         `json:"amount"`
35
	Currency     string         `json:"currency"`
36
	ExternalID   string         `json:"externalId"`
37
	Payer        *AccountHolder `json:"payer"`
38
	PayerMessage string         `json:"payerMessage"`
39
	PayeeNote    string         `json:"payeeNote"`
40
}
41
42
// CollectionTransactionStatus is the status of a request to pay request.
43
type CollectionTransactionStatus struct {
44
	Amount                 string         `json:"amount"`
45
	Currency               string         `json:"currency"`
46
	ExternalID             string         `json:"externalId"`
47
	ReferenceID            string         `json:"referenceId"`
48
	Payer                  *AccountHolder `json:"payer"`
49
	Status                 string         `json:"status"`
50
	FinancialTransactionID *string        `json:"financialTransactionId,omitempty"`
51
	Reason                 *string        `json:"reason,omitempty"`
52
}
53
54
// IsPending checks if a transaction is in pending status
55
func (status *CollectionTransactionStatus) IsPending() bool {
56
	return status.Status == "PENDING"
57
}
58
59
// IsFailed checks if a transaction is in failed status
60
func (status *CollectionTransactionStatus) IsFailed() bool {
61
	return status.Status == "FAILED"
62
}
63
64
// IsCancelled checks if a transaction is cancelled
65
func (status *CollectionTransactionStatus) IsCancelled() bool {
66
	return status.Status == "CANCELLED"
67
}
68
69
// IsSuccessful checks if a transaction is successful
70
func (status *CollectionTransactionStatus) IsSuccessful() bool {
71
	return status.Status == "SUCCESSFUL"
72
}
73
74
// AccountHolder identifies an account holder in the wallet platform.
75
type AccountHolder struct {
76
	PartyIDType string `json:"partyIdType"`
77
	PartyID     string `json:"partyId"`
78
}
79
80
// AccountBalance is available balance of the account
81
type AccountBalance struct {
82
	AvailableBalance string `json:"availableBalance"`
83
	Currency         string `json:"currency"`
84
}
85