From 649672429dab21a01f6201455e9af4bda9e64238 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 16 Jul 2017 07:50:57 +0200 Subject: [PATCH] Started implementing PayPal --- main.go | 8 +++++--- mixins/Navigation.pixy | 4 ++-- pages/paypal/paypal.go | 41 ++++++++++++++++++++++++++++++++++++++ pages/profile/profile.pixy | 2 +- scripts/Actions.ts | 2 +- tests.go | 9 +++++---- 6 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 pages/paypal/paypal.go diff --git a/main.go b/main.go index 74fa4eb8..d847bbf9 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ import ( "github.com/animenotifier/notify.moe/pages/newsoundtrack" "github.com/animenotifier/notify.moe/pages/newthread" "github.com/animenotifier/notify.moe/pages/notifications" + "github.com/animenotifier/notify.moe/pages/paypal" "github.com/animenotifier/notify.moe/pages/posts" "github.com/animenotifier/notify.moe/pages/profile" "github.com/animenotifier/notify.moe/pages/search" @@ -76,12 +77,12 @@ func configure(app *aero.Application) *aero.Application { app.Ajax("/forum/:tag", forum.Get) app.Ajax("/thread/:id", threads.Get) app.Ajax("/post/:id", posts.Get) - app.Ajax("/track/:id", tracks.Get) + app.Ajax("/soundtrack/:id", tracks.Get) app.Ajax("/character/:id", character.Get) app.Ajax("/new/thread", newthread.Get) app.Ajax("/new/soundtrack", newsoundtrack.Get) app.Ajax("/settings", settings.Get) - app.Ajax("/music", music.Get) + app.Ajax("/soundtracks", music.Get) app.Ajax("/users", users.Get) app.Ajax("/login", login.Get) @@ -90,7 +91,7 @@ func configure(app *aero.Application) *aero.Application { app.Ajax("/user/:nick", profile.Get) app.Ajax("/user/:nick/threads", profile.GetThreadsByUser) app.Ajax("/user/:nick/posts", profile.GetPostsByUser) - app.Ajax("/user/:nick/tracks", profile.GetSoundTracksByUser) + app.Ajax("/user/:nick/soundtracks", profile.GetSoundTracksByUser) app.Ajax("/user/:nick/stats", profile.GetStatsByUser) app.Ajax("/user/:nick/animelist", animelist.Get) app.Ajax("/user/:nick/animelist/watching", animelist.FilterByStatus(arn.AnimeListStatusWatching)) @@ -129,6 +130,7 @@ func configure(app *aero.Application) *aero.Application { // API app.Get("/api/test/notification", notifications.Test) + app.Get("/api/paypal/payment/create", paypal.CreatePayment) // Middleware app.Use(middleware.Log()) diff --git a/mixins/Navigation.pixy b/mixins/Navigation.pixy index edff724b..4ce84de4 100644 --- a/mixins/Navigation.pixy +++ b/mixins/Navigation.pixy @@ -15,7 +15,7 @@ component LoggedOutMenu .extra-navigation NavigationButton("Users", "/users", "globe") - NavigationButton("Music", "/music", "headphones") + NavigationButton("Soundtracks", "/soundtracks", "headphones") NavigationButton("Login", "/login", "sign-in") @@ -29,7 +29,7 @@ component LoggedInMenu(user *arn.User) NavigationButton("Forum", "/forum", "comment") .extra-navigation - NavigationButton("Music", "/music", "headphones") + NavigationButton("Soundtracks", "/soundtracks", "headphones") FuzzySearch diff --git a/pages/paypal/paypal.go b/pages/paypal/paypal.go new file mode 100644 index 00000000..6e1c1846 --- /dev/null +++ b/pages/paypal/paypal.go @@ -0,0 +1,41 @@ +package paypal + +import ( + "net/http" + "os" + + "github.com/aerogo/aero" + "github.com/logpacker/PayPal-Go-SDK" +) + +// CreatePayment ... +func CreatePayment(ctx *aero.Context) string { + // Create a client instance + c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox) + c.SetLog(os.Stdout) // Set log to terminal stdout + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Could not initiate PayPal client", err) + } + + _, err = c.GetAccessToken() + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Could not get PayPal access token", err) + } + + amount := paypalsdk.Amount{ + Total: "7.00", + Currency: "USD", + } + redirectURI := "http://example.com/redirect-uri" + cancelURI := "http://example.com/cancel-uri" + description := "Description for this payment" + paymentResult, err := c.CreateDirectPaypalPayment(amount, redirectURI, cancelURI, description) + + if err != nil { + return ctx.Error(http.StatusInternalServerError, "Could not create PayPal payment", err) + } + + return ctx.JSON(paymentResult) +} diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index 90da6855..464cda20 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -64,7 +64,7 @@ component ProfileNavigation(viewUser *arn.User, uri string) Icon("comments") span.tab-text Posts - a.button.tab.action(href="/+" + viewUser.Nick + "/tracks", data-action="diff", data-trigger="click") + a.button.tab.action(href="/+" + viewUser.Nick + "/soundtracks", data-action="diff", data-trigger="click") Icon("music") span.tab-text Tracks diff --git a/scripts/Actions.ts b/scripts/Actions.ts index 7b81702c..66bd6dde 100644 --- a/scripts/Actions.ts +++ b/scripts/Actions.ts @@ -194,7 +194,7 @@ export function createSoundTrack(arn: AnimeNotifier, button: HTMLButtonElement) } arn.post("/api/new/soundtrack", soundtrack) - .then(() => arn.app.load("/music")) + .then(() => arn.app.load("/soundtracks")) .catch(err => arn.statusMessage.showError(err)) } diff --git a/tests.go b/tests.go index 48a1aadc..c0a6ef7f 100644 --- a/tests.go +++ b/tests.go @@ -22,8 +22,8 @@ var routeTests = map[string][]string{ "/+Akyoto/posts", }, - "/user/:nick/tracks": []string{ - "/+Akyoto/tracks", + "/user/:nick/soundtracks": []string{ + "/+Akyoto/soundtracks", }, "/user/:nick/animelist": []string{ @@ -75,8 +75,8 @@ var routeTests = map[string][]string{ "/search/Dragon Ball", }, - "/track/:id": []string{ - "/track/h0ac8sKkg", + "/soundtrack/:id": []string{ + "/soundtrack/h0ac8sKkg", }, // API @@ -186,6 +186,7 @@ var routeTests = map[string][]string{ "/import/kitsu/animelist": nil, "/import/kitsu/animelist/finish": nil, "/api/test/notification": nil, + "/api/paypal/payment/create": nil, "/anime/:id/edit": nil, "/new/thread": nil, "/new/soundtrack": nil,