77 lines
1.8 KiB
Go
Raw Normal View History

2017-07-16 05:50:57 +00:00
package paypal
import (
"net/http"
"github.com/aerogo/aero"
2017-07-16 18:29:10 +00:00
"github.com/animenotifier/arn"
2017-07-16 05:50:57 +00:00
"github.com/logpacker/PayPal-Go-SDK"
)
// CreatePayment ...
func CreatePayment(ctx *aero.Context) string {
2017-07-16 18:29:10 +00:00
c, err := arn.PayPal()
2017-07-16 05:50:57 +00:00
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)
}
2017-07-16 18:29:10 +00:00
// webprofile := paypalsdk.WebProfile{
// Name: "Anime Notifier",
// 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",
},
2017-07-16 05:50:57 +00:00
}
2017-07-16 18:29:10 +00:00
paymentResponse, err := c.CreatePayment(p)
2017-07-16 05:50:57 +00:00
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Could not create PayPal payment", err)
}
2017-07-16 18:29:10 +00:00
return ctx.JSON(paymentResponse)
2017-07-16 05:50:57 +00:00
}