Added paypal callbacks
This commit is contained in:
parent
649672429d
commit
d33b93d115
4
main.go
4
main.go
@ -130,6 +130,10 @@ func configure(app *aero.Application) *aero.Application {
|
|||||||
|
|
||||||
// API
|
// API
|
||||||
app.Get("/api/test/notification", notifications.Test)
|
app.Get("/api/test/notification", notifications.Test)
|
||||||
|
|
||||||
|
// PayPal
|
||||||
|
app.Ajax("/paypal/success", paypal.Success)
|
||||||
|
app.Ajax("/paypal/cancel", paypal.Cancel)
|
||||||
app.Get("/api/paypal/payment/create", paypal.CreatePayment)
|
app.Get("/api/paypal/payment/create", paypal.CreatePayment)
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
|
15
pages/paypal/cancel.go
Normal file
15
pages/paypal/cancel.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package paypal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/aerogo/aero"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Cancel ...
|
||||||
|
func Cancel(ctx *aero.Context) string {
|
||||||
|
token := ctx.Query("token")
|
||||||
|
fmt.Println("cancel", token)
|
||||||
|
|
||||||
|
return ctx.HTML("cancel")
|
||||||
|
}
|
@ -2,17 +2,15 @@ package paypal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
"github.com/logpacker/PayPal-Go-SDK"
|
"github.com/logpacker/PayPal-Go-SDK"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreatePayment ...
|
// CreatePayment ...
|
||||||
func CreatePayment(ctx *aero.Context) string {
|
func CreatePayment(ctx *aero.Context) string {
|
||||||
// Create a client instance
|
c, err := arn.PayPal()
|
||||||
c, err := paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
|
|
||||||
c.SetLog(os.Stdout) // Set log to terminal stdout
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.Error(http.StatusInternalServerError, "Could not initiate PayPal client", err)
|
return ctx.Error(http.StatusInternalServerError, "Could not initiate PayPal client", err)
|
||||||
@ -24,18 +22,55 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
amount := paypalsdk.Amount{
|
// webprofile := paypalsdk.WebProfile{
|
||||||
Total: "7.00",
|
// Name: "Anime Notifier",
|
||||||
Currency: "USD",
|
// Presentation: paypalsdk.Presentation{
|
||||||
|
// BrandName: "Anime Notifier",
|
||||||
|
// LogoImage: "https://notify.moe/brand/300",
|
||||||
|
// 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)
|
||||||
|
// }
|
||||||
|
|
||||||
|
p := paypalsdk.Payment{
|
||||||
|
Intent: "sale",
|
||||||
|
Payer: &paypalsdk.Payer{
|
||||||
|
PaymentMethod: "paypal",
|
||||||
|
},
|
||||||
|
Transactions: []paypalsdk.Transaction{paypalsdk.Transaction{
|
||||||
|
Amount: &paypalsdk.Amount{
|
||||||
|
Currency: "USD",
|
||||||
|
Total: "7.00",
|
||||||
|
},
|
||||||
|
Description: "Pro Account",
|
||||||
|
}},
|
||||||
|
RedirectURLs: &paypalsdk.RedirectURLs{
|
||||||
|
ReturnURL: "https://" + ctx.App.Config.Domain + "/paypal/success",
|
||||||
|
CancelURL: "https://" + ctx.App.Config.Domain + "/paypal/cancel",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
redirectURI := "http://example.com/redirect-uri"
|
|
||||||
cancelURI := "http://example.com/cancel-uri"
|
paymentResponse, err := c.CreatePayment(p)
|
||||||
description := "Description for this payment"
|
|
||||||
paymentResult, err := c.CreateDirectPaypalPayment(amount, redirectURI, cancelURI, description)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.Error(http.StatusInternalServerError, "Could not create PayPal payment", err)
|
return ctx.Error(http.StatusInternalServerError, "Could not create PayPal payment", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.JSON(paymentResult)
|
return ctx.JSON(paymentResponse)
|
||||||
}
|
}
|
||||||
|
37
pages/paypal/success.go
Normal file
37
pages/paypal/success.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package paypal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Success ...
|
||||||
|
func Success(ctx *aero.Context) string {
|
||||||
|
paymentID := ctx.Query("paymentId")
|
||||||
|
// token := ctx.Query("token")
|
||||||
|
// payerID := ctx.Query("PayerID")
|
||||||
|
|
||||||
|
c, err := arn.PayPal()
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
payment, err := c.GetPayment(paymentID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ctx.Error(http.StatusInternalServerError, "Could not retrieve payment information", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
arn.PrettyPrint(payment)
|
||||||
|
|
||||||
|
return ctx.HTML("success")
|
||||||
|
}
|
2
tests.go
2
tests.go
@ -187,6 +187,8 @@ var routeTests = map[string][]string{
|
|||||||
"/import/kitsu/animelist/finish": nil,
|
"/import/kitsu/animelist/finish": nil,
|
||||||
"/api/test/notification": nil,
|
"/api/test/notification": nil,
|
||||||
"/api/paypal/payment/create": nil,
|
"/api/paypal/payment/create": nil,
|
||||||
|
"/paypal/success": nil,
|
||||||
|
"/paypal/cancel": nil,
|
||||||
"/anime/:id/edit": nil,
|
"/anime/:id/edit": nil,
|
||||||
"/new/thread": nil,
|
"/new/thread": nil,
|
||||||
"/new/soundtrack": nil,
|
"/new/soundtrack": nil,
|
||||||
|
Loading…
Reference in New Issue
Block a user