Added payment overview for administrators

This commit is contained in:
Eduard Urbach 2018-10-18 10:15:06 +09:00
parent 5956b82d9d
commit 9ad99995c3
4 changed files with 58 additions and 0 deletions

View File

@ -5,6 +5,7 @@ component AdminTabs
Tab("Client errors", "exclamation", "/admin/errors/client") Tab("Client errors", "exclamation", "/admin/errors/client")
Tab("Registrations", "user-plus", "/admin/registrations") Tab("Registrations", "user-plus", "/admin/registrations")
Tab("Purchases", "shopping-cart", "/admin/purchases") Tab("Purchases", "shopping-cart", "/admin/purchases")
Tab("Payments", "paypal", "/admin/payments")
.corner-buttons .corner-buttons
a.button(href="/editor", aria-label="Editor") a.button(href="/editor", aria-label="Editor")

36
pages/admin/payments.go Normal file
View File

@ -0,0 +1,36 @@
package admin
import (
"net/http"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// PaymentHistory ...
func PaymentHistory(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
if user.Role != "admin" {
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
payments, err := arn.AllPayPalPayments()
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Error fetching shop item data", err)
}
sort.Slice(payments, func(i, j int) bool {
return payments[i].Created > payments[j].Created
})
return ctx.HTML(components.GlobalPaymentHistory(payments))
}

20
pages/admin/payments.pixy Normal file
View File

@ -0,0 +1,20 @@
component GlobalPaymentHistory(payments []*arn.PayPalPayment)
AdminTabs
h1.page-title All Payments
table
thead
tr.mountable
th User
th Amount
th Currency
th.history-date Date
tbody
each payment in payments
tr.mountable
td
a(href=payment.User().Link())= payment.User().Nick
td= payment.Amount
td= payment.Currency
td.utc-date(data-date=payment.Created)

View File

@ -78,4 +78,5 @@ func Register(l *layout.Layout) {
l.Page("/admin/registrations", admin.UserRegistrations) l.Page("/admin/registrations", admin.UserRegistrations)
l.Page("/admin/errors/client", admin.ClientErrors) l.Page("/admin/errors/client", admin.ClientErrors)
l.Page("/admin/purchases", admin.PurchaseHistory) l.Page("/admin/purchases", admin.PurchaseHistory)
l.Page("/admin/payments", admin.PaymentHistory)
} }