From 9ad99995c3a4be92de7ee1c04fe375b1494a3d7c Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 18 Oct 2018 10:15:06 +0900 Subject: [PATCH] Added payment overview for administrators --- pages/admin/admin.pixy | 1 + pages/admin/payments.go | 36 ++++++++++++++++++++++++++ pages/admin/payments.pixy | 20 ++++++++++++++ pages/index/staffroutes/staffroutes.go | 1 + 4 files changed, 58 insertions(+) create mode 100644 pages/admin/payments.go create mode 100644 pages/admin/payments.pixy diff --git a/pages/admin/admin.pixy b/pages/admin/admin.pixy index 578f4ce7..5b9e4497 100644 --- a/pages/admin/admin.pixy +++ b/pages/admin/admin.pixy @@ -5,6 +5,7 @@ component AdminTabs Tab("Client errors", "exclamation", "/admin/errors/client") Tab("Registrations", "user-plus", "/admin/registrations") Tab("Purchases", "shopping-cart", "/admin/purchases") + Tab("Payments", "paypal", "/admin/payments") .corner-buttons a.button(href="/editor", aria-label="Editor") diff --git a/pages/admin/payments.go b/pages/admin/payments.go new file mode 100644 index 00000000..3d66ecf7 --- /dev/null +++ b/pages/admin/payments.go @@ -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)) +} diff --git a/pages/admin/payments.pixy b/pages/admin/payments.pixy new file mode 100644 index 00000000..37d9bb40 --- /dev/null +++ b/pages/admin/payments.pixy @@ -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) \ No newline at end of file diff --git a/pages/index/staffroutes/staffroutes.go b/pages/index/staffroutes/staffroutes.go index 5d3e228e..995cedf0 100644 --- a/pages/index/staffroutes/staffroutes.go +++ b/pages/index/staffroutes/staffroutes.go @@ -78,4 +78,5 @@ func Register(l *layout.Layout) { l.Page("/admin/registrations", admin.UserRegistrations) l.Page("/admin/errors/client", admin.ClientErrors) l.Page("/admin/purchases", admin.PurchaseHistory) + l.Page("/admin/payments", admin.PaymentHistory) }