feat(payment): PR #538 支付FM插件 - 合并 Danborad 的支付插件实现
This commit is contained in:
@@ -7,8 +7,12 @@ import (
|
||||
const (
|
||||
PaymentPluginWeChatNative = "official-payment-wechat-native"
|
||||
PaymentPluginAlipayPage = "official-payment-alipay-page"
|
||||
PaymentPluginXunHuPay = "official-payment-xunhupay"
|
||||
PaymentPluginZhiFuFM = "official-payment-zhifufm"
|
||||
PaymentProviderWeChat = "wechat-native"
|
||||
PaymentProviderAlipay = "alipay-page-pay"
|
||||
PaymentProviderXunHuPay = "xunhupay-aggregate"
|
||||
PaymentProviderZhiFuFM = "zhifufm-pay"
|
||||
)
|
||||
|
||||
func bundledPaymentPluginManifests() []protocol.Manifest {
|
||||
|
||||
@@ -151,3 +151,38 @@ func TestXunHuPayOfficialPackageIsPaymentPlugin(t *testing.T) {
|
||||
t.Fatalf("xunhupay provider type = %T", provider)
|
||||
}
|
||||
}
|
||||
|
||||
func TestZhiFuFMOfficialPackageIsPaymentPlugin(t *testing.T) {
|
||||
center, err := newPluginRuntime(t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var plugin PluginView
|
||||
for _, item := range center.list() {
|
||||
if item.Manifest.ID == "official-payment-zhifufm" {
|
||||
plugin = item
|
||||
plugin.Management = pluginManagementFromView(item)
|
||||
break
|
||||
}
|
||||
}
|
||||
if plugin.Manifest.ID == "" {
|
||||
t.Fatal("official-payment-zhifufm is missing")
|
||||
}
|
||||
if plugin.Management.Kind != PluginKindPayment || plugin.Source != PluginOriginOfficial {
|
||||
t.Fatalf("zhifufm plugin = %#v", plugin)
|
||||
}
|
||||
if len(plugin.Manifest.Contributes.PaymentProviders) != 1 || plugin.Manifest.Contributes.PaymentProviders[0].ID != "zhifufm-pay" {
|
||||
t.Fatalf("zhifufm contributions = %#v", plugin.Manifest.Contributes.PaymentProviders)
|
||||
}
|
||||
registry := center.paymentRegistrySnapshot()
|
||||
if registry == nil {
|
||||
t.Fatal("payment registry is nil")
|
||||
}
|
||||
provider, ok := registry.Get("zhifufm-pay")
|
||||
if !ok {
|
||||
t.Fatal("zhifufm-pay provider is missing")
|
||||
}
|
||||
if _, ok := provider.(*payment.RPCProvider); !ok {
|
||||
t.Fatalf("zhifufm provider type = %T", provider)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,13 +144,16 @@ func RegisterPaymentRoutes(r *gin.RouterGroup, svc *service.Service) {
|
||||
// Provider callbacks are intentionally unauthenticated at the application
|
||||
// layer. Authenticity is established by the pinned provider config and raw
|
||||
// request signature before any durable event is accepted.
|
||||
r.POST("/payments/notify/:providerId/:configId", func(c *gin.Context) {
|
||||
notifyHandler := func(c *gin.Context) {
|
||||
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, paymentNotificationMaxBytes)
|
||||
rawBody, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
writePaymentNotificationFailure(c, svc, c.Param("providerId"), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if len(rawBody) == 0 && c.Request.URL.RawQuery != "" {
|
||||
rawBody = []byte(c.Request.URL.RawQuery)
|
||||
}
|
||||
err = svc.AcceptPaymentNotification(c.Request.Context(), c.Param("providerId"), c.Param("configId"), c.Request.Header.Clone(), rawBody)
|
||||
if err != nil {
|
||||
status := http.StatusInternalServerError
|
||||
@@ -167,7 +170,10 @@ func RegisterPaymentRoutes(r *gin.RouterGroup, svc *service.Service) {
|
||||
return
|
||||
}
|
||||
c.Status(status)
|
||||
})
|
||||
}
|
||||
|
||||
r.POST("/payments/notify/:providerId/:configId", notifyHandler)
|
||||
r.GET("/payments/notify/:providerId/:configId", notifyHandler)
|
||||
r.GET("/payments/return/:providerId", func(c *gin.Context) {
|
||||
orderID := strings.ToLower(strings.TrimSpace(c.Query("orderId")))
|
||||
if !paymentOrderIDPattern.MatchString(orderID) {
|
||||
|
||||
@@ -16,6 +16,7 @@ var officialPaymentPackageIDs = []string{
|
||||
"official-payment-wechat-native",
|
||||
"official-payment-alipay-page",
|
||||
"official-payment-xunhupay",
|
||||
"official-payment-zhifufm",
|
||||
}
|
||||
|
||||
var officialPaymentTaggedArtifacts = []string{
|
||||
|
||||
Reference in New Issue
Block a user