Added a start to the paypal feature, using the mockserver from the go paypal api.

master
Zed A. Shaw 3 weeks ago
parent a45371e48f
commit bf9c3e1f9d
  1. 5
      config/settings.go
  2. 6
      config_example.json
  3. 2
      features/init.go
  4. 47
      features/paypal/api.go
  5. 9
      features/paypal/db.go
  6. 44
      features/paypal/init.go
  7. 11
      features/paypal/views.go
  8. 6
      go.mod
  9. 13
      go.sum
  10. 14
      tests/paypal/example_test.go
  11. 3
      views/paypal/index.html

@ -30,6 +30,11 @@ type config struct {
RedisQueue string
Templates string
}
Paypal struct {
ClientID string
SecretID string
URL string
}
}
var Settings config

@ -3,7 +3,7 @@
"Admin": "admin",
"Views": "./views",
"Layouts": "layouts/main",
"HostPort": ":7001"
"HostPort": "127.0.0.1:7001"
},
"Database": {
"Driver": "sqlite3",
@ -21,5 +21,9 @@
"UserAgent": "nunya-business",
"RedisQueue": "email",
"Templates": "emails"
},
"Paypal": {
"ClientID": "test-client-id",
"SecretID": "test-secret"
}
}

@ -3,8 +3,10 @@ package features
import (
"github.com/gofiber/fiber/v2"
email "MY/webapp/features/email"
paypal "MY/webapp/features/paypal"
)
func Setup(app *fiber.App) {
email.Setup(app)
paypal.Setup(app)
}

@ -0,0 +1,47 @@
package features_paypal
import (
"github.com/gofiber/fiber/v2"
"github.com/plutov/paypal/v4"
"os"
"context"
. "MY/webapp/common"
config "MY/webapp/config"
)
func GetApiStart(c *fiber.Ctx) error {
ctx := context.Background()
pay, err := paypal.NewClient(
config.Settings.Paypal.ClientID,
config.Settings.Paypal.SecretID,
config.Settings.Paypal.URL) // or paypal.APIBaseLive
if err != nil { return IfErrNil(err, c) }
pay.SetLog(os.Stdout)
pay.Token = &paypal.TokenResponse{Token: "dummy"}
payout := paypal.Payout{
Items: []paypal.PayoutItem{
{
Amount: &paypal.AmountPayout{
Currency: "USD",
Value: "10.00",
},
Receiver: "test@example.com",
},
},
SenderBatchHeader: &paypal.SenderBatchHeader{
SenderBatchID: "BATCH123",
},
}
response, err := pay.CreatePayout(ctx, payout)
if err != nil { return IfErrNil(err, c) }
return c.JSON(response)
}
func SetupApi(app *fiber.App) {
app.Get("/api/paypal/start", GetApiStart)
}

@ -0,0 +1,9 @@
package features_paypal
import (
// "MY/webapp/data"
// _ "github.com/mattn/go-sqlite3"
// sq "github.com/Masterminds/squirrel"
)

@ -0,0 +1,44 @@
package features_paypal
import (
"github.com/gofiber/fiber/v2"
"net/http"
"net/http/httptest"
mockserver "github.com/plutov/paypal/v4/mockserver"
srvPayouts "github.com/plutov/paypal/v4/mockserver/payments_payouts_batch_v1"
srvShipping "github.com/plutov/paypal/v4/mockserver/shipping_shipment_tracking_v1"
"MY/webapp/config"
)
var PAYPAL *httptest.Server = nil
func createTestServer() *httptest.Server {
mock := &mockserver.MockServer{}
mux := http.NewServeMux()
payoutsSI := srvPayouts.NewStrictHandler(mock, nil)
srvPayouts.HandlerWithOptions(payoutsSI, srvPayouts.StdHTTPServerOptions{
BaseRouter: mux,
})
shippingSI := srvShipping.NewStrictHandler(mock, nil)
srvShipping.HandlerWithOptions(shippingSI, srvShipping.StdHTTPServerOptions{
BaseRouter: mux,
})
return httptest.NewServer(mux)
}
func Setup(app *fiber.App) {
// if you don't set the URL then use a fake mock
if config.Settings.Paypal.URL == "" {
PAYPAL = createTestServer()
config.Settings.Paypal.URL = PAYPAL.URL
}
SetupApi(app)
SetupViews(app)
}

@ -0,0 +1,11 @@
package features_paypal
import (
"github.com/gofiber/fiber/v2"
. "MY/webapp/common"
)
func SetupViews(app *fiber.App) {
err := ConfigViews(app, "views/paypal")
if err != nil { panic(err) }
}

@ -11,14 +11,17 @@ require (
github.com/guregu/null/v6 v6.0.0
github.com/jmoiron/sqlx v1.4.0
github.com/mattn/go-sqlite3 v1.14.32
github.com/plutov/paypal/v4 v4.17.0
github.com/redis/go-redis/v9 v9.17.2
github.com/stretchr/testify v1.11.1
github.com/wneessen/go-mail v0.7.2
github.com/yuin/goldmark v1.7.13
golang.org/x/crypto v0.43.0
)
require (
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chromedp/cdproto v0.0.0-20250803210736-d308e07a266d // indirect
github.com/chromedp/sysutil v1.1.0 // indirect
@ -46,11 +49,10 @@ require (
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
github.com/oapi-codegen/runtime v1.1.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.68.0 // indirect
github.com/yuin/goldmark v1.7.13 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/text v0.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect

@ -2,8 +2,12 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM=
github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=
github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
@ -21,6 +25,7 @@ github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEX
github.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuhIGpJy4=
github.com/clipperhouse/uax29/v2 v2.3.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
@ -62,6 +67,7 @@ github.com/guregu/null/v6 v6.0.0 h1:N14VRS+4di81i1PXRiprbQJ9EM9gqBa0+KVMeS/QSjQ=
github.com/guregu/null/v6 v6.0.0/go.mod h1:hrMIhIfrOZeLPZhROSn149tpw2gHkidAqxoXNyeX3iQ=
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@ -91,8 +97,12 @@ github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhg
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/oapi-codegen/runtime v1.1.2 h1:P2+CubHq8fO4Q6fV1tqDBZHCwpVpvPg7oKiYzQgXIyI=
github.com/oapi-codegen/runtime v1.1.2/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw=
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
github.com/plutov/paypal/v4 v4.17.0 h1:FtqBQ/ENdSw40NsoZK2aRW9zWhMNM+TaQhH3dzDtSqg=
github.com/plutov/paypal/v4 v4.17.0/go.mod h1:4N6hzf47wQUGdS3ef94jku6kjiSvFm2hxVlT9CnIHmU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4ViluI=
@ -100,7 +110,10 @@ github.com/redis/go-redis/v9 v9.17.2/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=

@ -0,0 +1,14 @@
package tests
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestLogin(t *testing.T) {
assert.Equal(true, false)
}
func TestMain(m *testing.M) {
m.Run()
}

@ -0,0 +1,3 @@
<h1>paypal</h1>
<p>Replace me.</p>
Loading…
Cancel
Save