forked from LunaNode/lobster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment.go
31 lines (25 loc) · 1.01 KB
/
payment.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
package lobster
import "net/http"
type PaymentInterface interface {
Payment(w http.ResponseWriter, r *http.Request, frameParams FrameParams, userId int, username string, amount float64)
}
var paymentInterfaces map[string]PaymentInterface = make(map[string]PaymentInterface)
func paymentMethodList() []string {
var methods []string
for method := range paymentInterfaces {
methods = append(methods, method)
}
return methods
}
func paymentHandle(method string, w http.ResponseWriter, r *http.Request, frameParams FrameParams, userId int, username string, amount float64) {
if amount < cfg.Billing.DepositMinimum || amount > cfg.Billing.DepositMaximum {
RedirectMessage(w, r, "/panel/billing", L.FormattedErrorf("amount_between", cfg.Billing.DepositMinimum, cfg.Billing.DepositMaximum))
return
}
payInterface, ok := paymentInterfaces[method]
if ok {
payInterface.Payment(w, r, frameParams, userId, username, amount)
} else {
RedirectMessage(w, r, "/panel/billing", L.FormattedError("invalid_payment_method"))
}
}