-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsci.go
More file actions
148 lines (120 loc) · 4.35 KB
/
sci.go
File metadata and controls
148 lines (120 loc) · 4.35 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package paykassasci
import (
"strconv"
)
// SCI contains basic settings
type SCI struct {
ID int
Key string
Test bool
}
// CheckPaymentResponse is wrapper response CheckPayment
type CheckPaymentResponse struct {
Error bool `json:"error"`
Message string `json:"message"`
Data struct {
Transaction string `json:"transaction"`
ShopID string `json:"shop_id"`
OrderID string `json:"order_id"`
Amount string `json:"amount"`
Currency string `json:"currency"`
System string `json:"system"`
Address string `json:"address"`
Hash string `json:"hash"`
Partial string `json:"partial"`
} `json:"data"`
}
// CheckPayment is wrapper sci_confirm_order
// https://paykassa.pro/docs/#api-SCI-sci_confirm_order
func (s *SCI) CheckPayment(privateHash string) (CheckPaymentResponse, error) {
var responseCheckPayment = &CheckPaymentResponse{}
var param = s.getParamMap()
param["func"] = ConfirmOrder
param["private_hash"] = privateHash
data, statusCode, err := sendRequest(param)
if err != nil {
return *responseCheckPayment, err
}
err = handlerResp(data, statusCode, responseCheckPayment)
return *responseCheckPayment, err
}
// GetCryptocurrencyAddressForDepositResponse is wrapper response GetCryptocurrencyAddressForDeposit
type GetCryptocurrencyAddressForDepositResponse struct {
Error bool `json:"error"`
Message string `json:"message"`
Data struct {
Invoice int `json:"invoice"`
OrderID string `json:"order_id"`
Wallet string `json:"wallet"`
Amount string `json:"amount"`
System string `json:"system"`
Currency string `json:"currency"`
URL string `json:"url"`
Tag bool `json:"tag"`
} `json:"data"`
}
// GetCryptocurrencyAddressForDeposit is wrapper sci_create_order_get_data
// https://paykassa.pro/docs/#api-SCI-sci_create_order_get_data
func (s *SCI) GetCryptocurrencyAddressForDeposit(orderID int, amount float64, currencyID int, comment string, phone bool, paidCommission string) (GetCryptocurrencyAddressForDepositResponse, error) {
var responseGetCryptocurrency = &GetCryptocurrencyAddressForDepositResponse{}
var param = s.getParamPayMap(orderID, amount, currencyID, comment, phone, paidCommission)
param["func"] = CreateOrderGetData
data, statusCode, err := sendRequest(param)
if err != nil {
return *responseGetCryptocurrency, err
}
err = handlerResp(data, statusCode, responseGetCryptocurrency)
return *responseGetCryptocurrency, err
}
// GetLinkForDepositResponse is wrapper response GetLinkForDeposit
type GetLinkForDepositResponse struct {
Error bool `json:"error"`
Message string `json:"message"`
Data struct {
Invoice int `json:"invoice"`
OrderID string `json:"order_id"`
Amount string `json:"amount"`
System string `json:"system"`
Currency string `json:"currency"`
URL string `json:"url"`
} `json:"data"`
}
// GetLinkForDeposit is wrapper sci_create_order
// https://paykassa.pro/docs/#api-SCI-sci_create_order
func (s *SCI) GetLinkForDeposit(orderID int, amount float64, currencyID int, comment string, phone bool, paidCommission string) (GetLinkForDepositResponse, error) {
var responseGetLinkForDeposit = &GetLinkForDepositResponse{}
var param = s.getParamPayMap(orderID, amount, currencyID, comment, phone, paidCommission)
param["func"] = CreateOrder
data, statusCode, err := sendRequest(param)
if err != nil {
return *responseGetLinkForDeposit, err
}
err = handlerResp(data, statusCode, responseGetLinkForDeposit)
return *responseGetLinkForDeposit, err
}
func (s *SCI) getParamPayMap(orderID int, amount float64, currencyID int, comment string, phone bool, paidCommission string) map[string]string {
var param = s.getParamMap()
param["order_id"] = strconv.Itoa(orderID)
param["amount"] = strconv.FormatFloat(amount, 'E', -1, 64)
param["currency"] = CurrencyCode(currencyID)
param["system"] = strconv.Itoa(currencyID)
param["comment"] = comment
param["phone"] = strconv.FormatBool(phone)
param["paid_commission"] = paidCommission
return param
}
func (s *SCI) getParamMap() map[string]string {
var param = make(map[string]string)
param["sci_id"] = strconv.Itoa(s.ID)
param["sci_key"] = s.Key
param["test"] = strconv.FormatBool(s.Test)
return param
}
// InitSCI initializes SCI
func InitSCI(merchantID int, merchantKey string, test bool) SCI {
return SCI{
ID: merchantID,
Key: merchantKey,
Test: test,
}
}