feat: add online payment management and checkout
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
@@ -13,13 +13,17 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"license-platform/backend/internal/payments"
|
||||
)
|
||||
|
||||
type BusinessAPI struct {
|
||||
db *sql.DB
|
||||
signingPrivateKeyPEM string
|
||||
keyring *Keyring
|
||||
credentialEncryptionKey []byte
|
||||
paymentProviders map[string]payments.Provider
|
||||
paymentEnvConfigs map[string]payments.Config
|
||||
db *sql.DB
|
||||
signingPrivateKeyPEM string
|
||||
keyring *Keyring
|
||||
credentialEncryptionKey []byte
|
||||
paymentConfigEncryptionKey []byte
|
||||
}
|
||||
|
||||
func secureSessionCookie(c *gin.Context) bool {
|
||||
@@ -46,6 +50,23 @@ func RegisterBusinessWithKeyring(r *gin.Engine, db *sql.DB, private string, ring
|
||||
}
|
||||
registerBusinessRoutes(r, a)
|
||||
}
|
||||
func RegisterBusinessWithPayments(r *gin.Engine, db *sql.DB, private string, ring *Keyring, credentialKey []byte, providers map[string]payments.Provider, paymentConfigKey ...[]byte) *BusinessAPI {
|
||||
envConfigs := map[string]payments.Config{}
|
||||
for _, channel := range []string{"alipay", "wechat"} {
|
||||
envConfigs[channel] = payments.ConfigFromEnv(channel)
|
||||
}
|
||||
startupProviders := map[string]payments.Provider{}
|
||||
for channel, provider := range providers {
|
||||
startupProviders[channel] = provider
|
||||
}
|
||||
a := &BusinessAPI{db: db, signingPrivateKeyPEM: private, keyring: ring, credentialEncryptionKey: credentialKey, paymentProviders: startupProviders, paymentEnvConfigs: envConfigs}
|
||||
if len(paymentConfigKey) > 0 {
|
||||
a.paymentConfigEncryptionKey = paymentConfigKey[0]
|
||||
}
|
||||
registerBusinessRoutes(r, a)
|
||||
return a
|
||||
}
|
||||
|
||||
func registerBusinessRoutes(r *gin.Engine, a *BusinessAPI) {
|
||||
api := r.Group("/api/v1")
|
||||
api.POST("/auth/login", a.login)
|
||||
@@ -62,6 +83,8 @@ func registerBusinessRoutes(r *gin.Engine, a *BusinessAPI) {
|
||||
api.POST("/instances/:instance_id/heartbeat", a.heartbeat)
|
||||
api.POST("/instances/:instance_id/updates/check", a.checkUpdate)
|
||||
api.POST("/auth/logout", a.authenticated, a.logout)
|
||||
api.POST("/payments/:channel/notify", a.paymentNotify)
|
||||
api.POST("/payments/checkout", a.paymentCheckout)
|
||||
secured := api.Group("", a.authenticated)
|
||||
secured.GET("/me", a.me)
|
||||
secured.GET("/admins", a.listAdmins)
|
||||
@@ -90,6 +113,11 @@ func registerBusinessRoutes(r *gin.Engine, a *BusinessAPI) {
|
||||
secured.POST("/orders", func(c *gin.Context) { a.writeOrder(c, "create") })
|
||||
secured.POST("/orders/:id/confirm-payment", func(c *gin.Context) { a.writeOrder(c, "confirm-payment") })
|
||||
secured.POST("/orders/:id/issue", func(c *gin.Context) { a.writeOrder(c, "issue") })
|
||||
secured.GET("/payment-channels", a.listPaymentChannels)
|
||||
secured.GET("/payment-channels/:channel", a.getPaymentChannel)
|
||||
secured.PUT("/payment-channels/:channel", a.updatePaymentChannel)
|
||||
secured.GET("/payment-orders", a.listPaymentOrders)
|
||||
secured.POST("/orders/:id/payment", a.createOnlinePayment)
|
||||
secured.GET("/licenses", a.listLicenses)
|
||||
secured.GET("/licenses/:id", a.getLicense)
|
||||
secured.GET("/licenses/:id/instances", a.listInstances)
|
||||
|
||||
Reference in New Issue
Block a user