|
1
|
|
|
package smobilpay |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"time" |
|
5
|
|
|
) |
|
6
|
|
|
|
|
7
|
|
|
// QuoteParams is the input needed to initialize a transaction |
|
8
|
|
|
type QuoteParams struct { |
|
9
|
|
|
PayItemID string `json:"payItemId"` |
|
10
|
|
|
Amount string `json:"amount"` |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
// Quote represents an initialized transaction |
|
14
|
|
|
type Quote struct { |
|
15
|
|
|
QuoteID string `json:"quoteId"` |
|
16
|
|
|
ExpiresAt time.Time `json:"expiresAt"` |
|
17
|
|
|
PayItemID string `json:"payItemId"` |
|
18
|
|
|
AmountLocalCurrency string `json:"amountLocalCur"` |
|
19
|
|
|
PriceLocalCurrency int `json:"priceLocalCur"` |
|
20
|
|
|
PriceSystemCurrency int `json:"priceSystemCur"` |
|
21
|
|
|
LocalCurrency string `json:"localCur"` |
|
22
|
|
|
SystemCurrency string `json:"systemCur"` |
|
23
|
|
|
Promotion interface{} `json:"promotion"` |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
// CollectParams is the input needed to confirm a transaction |
|
27
|
|
|
type CollectParams struct { |
|
28
|
|
|
QuoteID string `json:"quoteId"` |
|
29
|
|
|
CustomerPhoneNumber string `json:"customerPhonenumber"` |
|
30
|
|
|
CustomerEmailAddress string `json:"customerEmailaddress"` |
|
31
|
|
|
CustomerName string `json:"customerName"` |
|
32
|
|
|
CustomerAddress string `json:"customerAddress"` |
|
33
|
|
|
CustomerNumber string `json:"customerNumber"` |
|
34
|
|
|
ServiceNumber string `json:"serviceNumber"` |
|
35
|
|
|
ExternalTransactionID string `json:"trid"` |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
func (params *CollectParams) toPayload() map[string]string { |
|
39
|
|
|
payload := map[string]string{ |
|
40
|
|
|
"quoteId": params.QuoteID, |
|
41
|
|
|
"customerPhonenumber": params.CustomerPhoneNumber, |
|
42
|
|
|
"customerEmailaddress": params.CustomerEmailAddress, |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if params.CustomerName != "" { |
|
46
|
|
|
payload["customerName"] = params.CustomerName |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if params.CustomerAddress != "" { |
|
50
|
|
|
payload["customerAddress"] = params.CustomerAddress |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if params.ServiceNumber != "" { |
|
54
|
|
|
payload["serviceNumber"] = params.ServiceNumber |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if params.ExternalTransactionID != "" { |
|
58
|
|
|
payload["trid"] = params.ExternalTransactionID |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return payload |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// Transaction represents a transaction |
|
65
|
|
|
type Transaction struct { |
|
66
|
|
|
PaymentTransactionNumber string `json:"ptn"` |
|
67
|
|
|
Timestamp time.Time `json:"timestamp"` |
|
68
|
|
|
AgentBalance string `json:"agentBalance"` |
|
69
|
|
|
ReceiptNumber string `json:"receiptNumber"` |
|
70
|
|
|
VerificationCode string `json:"veriCode"` |
|
71
|
|
|
PriceLocalCurrency string `json:"priceLocalCur"` |
|
72
|
|
|
PriceSystemCurrency string `json:"priceSystemCur"` |
|
73
|
|
|
LocalCurrency string `json:"localCur"` |
|
74
|
|
|
SystemCurrency string `json:"systemCur"` |
|
75
|
|
|
ExternalTransactionID *string `json:"trid"` |
|
76
|
|
|
Pin interface{} `json:"pin"` |
|
77
|
|
|
Status string `json:"status"` |
|
78
|
|
|
PayItemDescription *string `json:"payItemDescr"` |
|
79
|
|
|
PayItemID string `json:"payItemId"` |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// IsFailed checks if a transaction failed |
|
83
|
|
|
func (transaction *Transaction) IsFailed() bool { |
|
84
|
|
|
return transaction.Status == "ERRORED" || transaction.Status == "ERROREDREFUNDED" |
|
85
|
|
|
} |
|
86
|
|
|
|