generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constructs.go
106 lines (92 loc) · 3.72 KB
/
constructs.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package smobilpay
import (
"time"
)
// PayItem represents a payment item
type PayItem struct {
ServiceID string `json:"serviceid"`
Merchant string `json:"merchant"`
PayItemID string `json:"payItemId"`
AmountType string `json:"amountType"`
LocalCurrency string `json:"localCur"`
Name string `json:"name"`
AmountLocalCurrency interface{} `json:"amountLocalCur"`
Description string `json:"description"`
PayItemDescription interface{} `json:"payItemDescr"`
OptionalString interface{} `json:"optStrg"`
OptionalNumber interface{} `json:"optNmb"`
}
// QuoteParams is the input needed to initialize a transaction
type QuoteParams struct {
PayItemID string `json:"payItemId"`
Amount string `json:"amount"`
}
// Quote represents an initialized transaction
type Quote struct {
QuoteID string `json:"quoteId"`
ExpiresAt time.Time `json:"expiresAt"`
PayItemID string `json:"payItemId"`
AmountLocalCurrency string `json:"amountLocalCur"`
PriceLocalCurrency string `json:"priceLocalCur"`
PriceSystemCurrency string `json:"priceSystemCur"`
LocalCurrency string `json:"localCur"`
SystemCurrency string `json:"systemCur"`
Promotion interface{} `json:"promotion"`
}
// CollectParams is the input needed to confirm a transaction
type CollectParams struct {
QuoteID string `json:"quoteId"`
CustomerPhoneNumber string `json:"customerPhonenumber"`
CustomerEmailAddress string `json:"customerEmailaddress"`
CustomerName string `json:"customerName"`
CustomerAddress string `json:"customerAddress"`
CustomerNumber string `json:"customerNumber"`
ServiceNumber string `json:"serviceNumber"`
ExternalTransactionID string `json:"trid"`
}
func (params *CollectParams) toPayload() map[string]string {
payload := map[string]string{
"quoteId": params.QuoteID,
"customerPhonenumber": params.CustomerPhoneNumber,
"customerEmailaddress": params.CustomerEmailAddress,
}
if params.CustomerName != "" {
payload["customerName"] = params.CustomerName
}
if params.CustomerAddress != "" {
payload["customerAddress"] = params.CustomerAddress
}
if params.ServiceNumber != "" {
payload["serviceNumber"] = params.ServiceNumber
}
if params.ExternalTransactionID != "" {
payload["trid"] = params.ExternalTransactionID
}
return payload
}
// Transaction represents a transaction
type Transaction struct {
PaymentTransactionNumber string `json:"ptn"`
Timestamp time.Time `json:"timestamp"`
AgentBalance string `json:"agentBalance"`
ReceiptNumber string `json:"receiptNumber"`
VerificationCode string `json:"veriCode"`
ClearingDate string `json:"clearingDate"`
PriceLocalCurrency string `json:"priceLocalCur"`
PriceSystemCurrency string `json:"priceSystemCur"`
LocalCurrency string `json:"localCur"`
SystemCurrency string `json:"systemCur"`
ExternalTransactionID *string `json:"trid"`
Pin interface{} `json:"pin"`
Status string `json:"status"`
PayItemDescription *string `json:"payItemDescr"`
PayItemID string `json:"payItemId"`
}
// IsFailed checks if a transaction failed
func (transaction *Transaction) IsFailed() bool {
return transaction.Status == "ERRORED" || transaction.Status == "ERROREDREFUNDED"
}
// IsPending checks if a transaction is pending
func (transaction *Transaction) IsPending() bool {
return transaction.Status == "PENDING" || transaction.Status == "INPROCESS"
}