|
1
|
|
|
package afrikpay |
|
2
|
|
|
|
|
3
|
|
|
// TransactionStatusRequest is used to request the status of a transaction |
|
4
|
|
|
type TransactionStatusRequest struct { |
|
5
|
|
|
ReferenceNumber string `json:"referenceNumber,omitempty"` |
|
6
|
|
|
Amount int `json:"amount,omitempty"` |
|
7
|
|
|
ExternalID string `json:"externalId,omitempty"` |
|
8
|
|
|
RequestID string `json:"requestId,omitempty"` |
|
9
|
|
|
TransactionID int `json:"transactionId,omitempty"` |
|
10
|
|
|
FinancialID string `json:"financialId,omitempty"` |
|
11
|
|
|
ProviderID string `json:"providerId,omitempty"` |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
// TransactionStatusResponse is the response from Afrikpay for a transaction status |
|
15
|
|
|
type TransactionStatusResponse struct { |
|
16
|
|
|
Code int `json:"code"` |
|
17
|
|
|
Message string `json:"message"` |
|
18
|
|
|
Result *struct { |
|
19
|
|
|
ErrorCode any `json:"errorCode"` |
|
20
|
|
|
ErrorMessage any `json:"errorMessage"` |
|
21
|
|
|
ErrorType any `json:"errorType"` |
|
22
|
|
|
Status string `json:"status"` |
|
23
|
|
|
CallbackURL string `json:"callbackUrl"` |
|
24
|
|
|
Voucher struct { |
|
25
|
|
|
Value string `json:"value"` |
|
26
|
|
|
} `json:"voucher"` |
|
27
|
|
|
TransactionID int `json:"transactionId"` |
|
28
|
|
|
AccountName string `json:"accountName"` |
|
29
|
|
|
AccountNumber string `json:"accountNumber"` |
|
30
|
|
|
Username string `json:"username"` |
|
31
|
|
|
ReferenceNumber string `json:"referenceNumber"` |
|
32
|
|
|
Amount int `json:"amount"` |
|
33
|
|
|
Type string `json:"type"` |
|
34
|
|
|
Service string `json:"service"` |
|
35
|
|
|
ServiceName string `json:"serviceName"` |
|
36
|
|
|
FinancialFees int `json:"financialFees"` |
|
37
|
|
|
FinancialCommission int `json:"financialCommission"` |
|
38
|
|
|
ProviderFees int `json:"providerFees"` |
|
39
|
|
|
Phone string `json:"phone"` |
|
40
|
|
|
Email string `json:"email"` |
|
41
|
|
|
Code string `json:"code"` |
|
42
|
|
|
OptionSlug string `json:"optionSlug"` |
|
43
|
|
|
Description string `json:"description"` |
|
44
|
|
|
ExternalID string `json:"externalId"` |
|
45
|
|
|
FinancialID string `json:"financialId"` |
|
46
|
|
|
ProviderID string `json:"providerId"` |
|
47
|
|
|
RequestID string `json:"requestId"` |
|
48
|
|
|
Data struct{} `json:"data"` |
|
49
|
|
|
RequestStatus string `json:"requestStatus"` |
|
50
|
|
|
CommissionID string `json:"commissionId"` |
|
51
|
|
|
RollbackID string `json:"rollbackId"` |
|
52
|
|
|
TerminalID int `json:"terminalId"` |
|
53
|
|
|
TerminalName string `json:"terminalName"` |
|
54
|
|
|
TerminalUserAgent string `json:"terminalUserAgent"` |
|
55
|
|
|
Reference struct{} `json:"reference"` |
|
56
|
|
|
IPAddress string `json:"ipAddress"` |
|
57
|
|
|
Date string `json:"date"` |
|
58
|
|
|
Signature string `json:"signature"` |
|
59
|
|
|
PaymentServiceFeature string `json:"paymentServiceFeature"` |
|
60
|
|
|
PaymentWallet string `json:"paymentWallet"` |
|
61
|
|
|
NoFees bool `json:"noFees"` |
|
62
|
|
|
PaymentLink string `json:"paymentLink"` |
|
63
|
|
|
AcceptURL string `json:"acceptUrl"` |
|
64
|
|
|
DeclineURL string `json:"declineUrl"` |
|
65
|
|
|
CancelURL string `json:"cancelUrl"` |
|
66
|
|
|
} `json:"result"` |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// IsFailed checks if the CANAL+ payment has failed |
|
70
|
|
|
func (response *TransactionStatusResponse) IsFailed() bool { |
|
71
|
|
|
return response.Code != 200 || (response.Result != nil && response.Result.Status == "FAILED") |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
// IsInProgress checks if the CANAL+ payment is still in progress |
|
75
|
|
|
func (response *TransactionStatusResponse) IsInProgress() bool { |
|
76
|
|
|
return response.Code == 200 && response.Result != nil && (response.Result.Status == "PROGRESS" || response.Result.Status == "PENDING" || response.Result.Status == "ACCEPTED" || response.Result.Status == "PAYED") |
|
77
|
|
|
} |
|
78
|
|
|
|