Improved documentation

This commit is contained in:
Eduard Urbach 2018-02-24 10:29:20 +01:00
parent 8cc80d7e59
commit fa6fca84a6
4 changed files with 37 additions and 32 deletions

View File

@ -11,5 +11,5 @@ func Cancel(ctx *aero.Context) string {
token := ctx.Query("token") token := ctx.Query("token")
fmt.Println("cancel", token) fmt.Println("cancel", token)
return ctx.HTML("cancel") return ctx.HTML("Payment has been canceled.")
} }

View File

@ -9,21 +9,22 @@ import (
"github.com/logpacker/PayPal-Go-SDK" "github.com/logpacker/PayPal-Go-SDK"
) )
// CreatePayment ... // CreatePayment creates the PayPal payment, typically via a JSON API route.
func CreatePayment(ctx *aero.Context) string { func CreatePayment(ctx *aero.Context) string {
// Make sure the user is logged in
user := utils.GetUser(ctx) user := utils.GetUser(ctx)
if user == nil { if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil) return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
} }
// Verify amount
amount, err := ctx.Request().Body().String() amount, err := ctx.Request().Body().String()
if err != nil { if err != nil {
return ctx.Error(http.StatusBadRequest, "Could not read amount", err) return ctx.Error(http.StatusBadRequest, "Could not read amount", err)
} }
// Verify amount
switch amount { switch amount {
case "1000", "2000", "3000", "6000", "12000": case "1000", "2000", "3000", "6000", "12000":
// OK // OK
@ -45,34 +46,6 @@ func CreatePayment(ctx *aero.Context) string {
return ctx.Error(http.StatusInternalServerError, "Could not get PayPal access token", err) 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 // Create payment
p := paypalsdk.Payment{ p := paypalsdk.Payment{
Intent: "sale", Intent: "sale",

View File

@ -13,7 +13,8 @@ import (
const adminID = "4J6qpK1ve" 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 { func Success(ctx *aero.Context) string {
user := utils.GetUser(ctx) user := utils.GetUser(ctx)

View File

@ -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:]