From fa6fca84a6807e20eb770a18877fc4b0f5d05366 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 24 Feb 2018 10:29:20 +0100 Subject: [PATCH] Improved documentation --- pages/paypal/cancel.go | 2 +- pages/paypal/paypal.go | 33 +++------------------------------ pages/paypal/success.go | 3 ++- pages/paypal/webprofile.go | 31 +++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 pages/paypal/webprofile.go diff --git a/pages/paypal/cancel.go b/pages/paypal/cancel.go index d607bf5c..3bd33809 100644 --- a/pages/paypal/cancel.go +++ b/pages/paypal/cancel.go @@ -11,5 +11,5 @@ func Cancel(ctx *aero.Context) string { token := ctx.Query("token") fmt.Println("cancel", token) - return ctx.HTML("cancel") + return ctx.HTML("Payment has been canceled.") } diff --git a/pages/paypal/paypal.go b/pages/paypal/paypal.go index af1813f6..55345639 100644 --- a/pages/paypal/paypal.go +++ b/pages/paypal/paypal.go @@ -9,21 +9,22 @@ import ( "github.com/logpacker/PayPal-Go-SDK" ) -// CreatePayment ... +// CreatePayment creates the PayPal payment, typically via a JSON API route. func CreatePayment(ctx *aero.Context) string { + // Make sure the user is logged in user := utils.GetUser(ctx) if user == nil { return ctx.Error(http.StatusUnauthorized, "Not logged in", nil) } + // Verify amount amount, err := ctx.Request().Body().String() if err != nil { return ctx.Error(http.StatusBadRequest, "Could not read amount", err) } - // Verify amount switch amount { case "1000", "2000", "3000", "6000", "12000": // OK @@ -45,34 +46,6 @@ func CreatePayment(ctx *aero.Context) string { return ctx.Error(http.StatusInternalServerError, "Could not get PayPal access token", err) } - // webprofile := paypalsdk.WebProfile{ - // Name: "Anime Notifier", - // Presentation: paypalsdk.Presentation{ - // BrandName: "Anime Notifier", - // LogoImage: "https://notify.moe/brand/220", - // LocaleCode: "US", - // }, - - // InputFields: paypalsdk.InputFields{ - // AllowNote: true, - // NoShipping: paypalsdk.NoShippingDisplay, - // AddressOverride: paypalsdk.AddrOverrideFromCall, - // }, - - // FlowConfig: paypalsdk.FlowConfig{ - // LandingPageType: paypalsdk.LandingPageTypeBilling, - // }, - // } - - // result, err := c.CreateWebProfile(webprofile) - // c.SetWebProfile(*result) - - // if err != nil { - // return ctx.Error(http.StatusInternalServerError, "Could not create PayPal web profile", err) - // } - - // total := amount[:len(amount)-2] + "." + amount[len(amount)-2:] - // Create payment p := paypalsdk.Payment{ Intent: "sale", diff --git a/pages/paypal/success.go b/pages/paypal/success.go index ef7e6e6c..a7d7e642 100644 --- a/pages/paypal/success.go +++ b/pages/paypal/success.go @@ -13,7 +13,8 @@ import ( const adminID = "4J6qpK1ve" -// Success ... +// Success is called once the payment has been confirmed by the user on the PayPal website. +// However, the actual payment still needs to be executed and can fail. func Success(ctx *aero.Context) string { user := utils.GetUser(ctx) diff --git a/pages/paypal/webprofile.go b/pages/paypal/webprofile.go new file mode 100644 index 00000000..c7a34d85 --- /dev/null +++ b/pages/paypal/webprofile.go @@ -0,0 +1,31 @@ +package paypal + +// Web profile is currently disabled. + +// webprofile := paypalsdk.WebProfile{ +// Name: "Anime Notifier", +// Presentation: paypalsdk.Presentation{ +// BrandName: "Anime Notifier", +// LogoImage: "https://notify.moe/brand/220", +// LocaleCode: "US", +// }, + +// InputFields: paypalsdk.InputFields{ +// AllowNote: true, +// NoShipping: paypalsdk.NoShippingDisplay, +// AddressOverride: paypalsdk.AddrOverrideFromCall, +// }, + +// FlowConfig: paypalsdk.FlowConfig{ +// LandingPageType: paypalsdk.LandingPageTypeBilling, +// }, +// } + +// result, err := c.CreateWebProfile(webprofile) +// c.SetWebProfile(*result) + +// if err != nil { +// return ctx.Error(http.StatusInternalServerError, "Could not create PayPal web profile", err) +// } + +// total := amount[:len(amount)-2] + "." + amount[len(amount)-2:]