feat(payment): 虎皮椒聚合支付 - 官方插件与跨平台可执行文件
新增 xunhupay 官方包,支付 RPC 与宿主只保留订单和验签边界;官方支付包同时带上各系统 provider,避免把 Linux ELF 当成本机入口。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e5a5f0ccc8
commit
a23df0cb32
63 files changed
+2070
-128
No files matched your search
@@ -187,7 +187,7 @@ func (s *Service) AdminPaymentProviders(actor *model.User) ([]AdminPaymentProvid
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
manifest, _ := paymentManifestForProvider(descriptor.ID)
|
||||
manifest, _ := s.paymentManifestForProvider(descriptor.ID)
|
||||
view := AdminPaymentProviderView{PaymentProviderView: base, Values: map[string]string{}, SecretConfigured: map[string]bool{}, ConfigFields: manifest.Configuration.Fields}
|
||||
if config != nil {
|
||||
values, err := s.decryptPaymentConfig(config)
|
||||
@@ -220,11 +220,14 @@ func (s *Service) UpdatePaymentProviderConfig(actor *model.User, providerID stri
|
||||
return nil, BadAuthRequest("未知支付渠道")
|
||||
}
|
||||
descriptor := provider.Descriptor()
|
||||
manifest, ok := paymentManifestForProvider(descriptor.ID)
|
||||
manifest, ok := s.paymentManifestForProvider(descriptor.ID)
|
||||
if !ok {
|
||||
return nil, BadAuthRequest("支付插件清单不存在")
|
||||
}
|
||||
policy, ok := paymentExpiryPolicy(manifest, descriptor.ID)
|
||||
if !ok {
|
||||
return nil, BadAuthRequest("支付插件清单不存在")
|
||||
}
|
||||
policy := manifest.Contributes.PaymentProviders[0].ExpiryPolicy
|
||||
if request.CloseAfterMinutes < policy.MinMinutes || request.CloseAfterMinutes > policy.MaxMinutes {
|
||||
return nil, BadAuthRequest(fmt.Sprintf("未支付关闭时间必须为 %d-%d 分钟", policy.MinMinutes, policy.MaxMinutes))
|
||||
}
|
||||
@@ -318,8 +321,10 @@ func (s *Service) UpdatePaymentProviderConfig(actor *model.User, providerID stri
|
||||
|
||||
func (s *Service) paymentProviderView(descriptor payment.Descriptor) (PaymentProviderView, *model.PaymentProviderConfig, error) {
|
||||
view := PaymentProviderView{ID: descriptor.ID, PluginID: descriptor.PluginID, Name: descriptor.Name, Icon: descriptor.Icon, CheckoutMode: descriptor.CheckoutMode}
|
||||
if manifest, ok := paymentManifestForProvider(descriptor.ID); ok && len(manifest.Contributes.PaymentProviders) > 0 {
|
||||
view.CloseAfterMinutes = manifest.Contributes.PaymentProviders[0].ExpiryPolicy.DefaultMinutes
|
||||
if manifest, ok := s.paymentManifestForProvider(descriptor.ID); ok {
|
||||
if policy, found := paymentExpiryPolicy(manifest, descriptor.ID); found {
|
||||
view.CloseAfterMinutes = policy.DefaultMinutes
|
||||
}
|
||||
}
|
||||
state, err := s.pluginStateForUser(nil, descriptor.PluginID, s.Plugins())
|
||||
if err == nil {
|
||||
@@ -339,7 +344,24 @@ func (s *Service) paymentProviderView(descriptor payment.Descriptor) (PaymentPro
|
||||
return view, config, nil
|
||||
}
|
||||
|
||||
func paymentManifestForProvider(providerID string) (protocol.Manifest, bool) {
|
||||
func (s *Service) paymentManifestForProvider(providerID string) (protocol.Manifest, bool) {
|
||||
providerID = strings.TrimSpace(providerID)
|
||||
if providerID == "" {
|
||||
return protocol.Manifest{}, false
|
||||
}
|
||||
if s != nil {
|
||||
for _, plugin := range s.Plugins() {
|
||||
for _, contribution := range plugin.Manifest.Contributes.PaymentProviders {
|
||||
if contribution.ID == providerID {
|
||||
return protocolManifestFromPluginView(plugin), true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return bundledPaymentManifestForProvider(providerID)
|
||||
}
|
||||
|
||||
func bundledPaymentManifestForProvider(providerID string) (protocol.Manifest, bool) {
|
||||
for _, manifest := range bundledPaymentPluginManifests() {
|
||||
for _, contribution := range manifest.Contributes.PaymentProviders {
|
||||
if contribution.ID == providerID {
|
||||
@@ -350,6 +372,34 @@ func paymentManifestForProvider(providerID string) (protocol.Manifest, bool) {
|
||||
return protocol.Manifest{}, false
|
||||
}
|
||||
|
||||
func protocolManifestFromPluginView(plugin PluginView) protocol.Manifest {
|
||||
return protocol.Manifest{
|
||||
APIVersion: plugin.Manifest.APIVersion,
|
||||
Metadata: protocol.Metadata{
|
||||
ID: plugin.Manifest.ID, Version: plugin.Manifest.Version, Name: plugin.Manifest.Name,
|
||||
Vendor: plugin.Manifest.Author, Description: plugin.Manifest.Description,
|
||||
Documentation: plugin.Manifest.Documentation,
|
||||
},
|
||||
Surfaces: plugin.Manifest.Surfaces,
|
||||
Runtime: plugin.Manifest.Runtime,
|
||||
Permissions: plugin.Manifest.Permissions,
|
||||
Configuration: plugin.Manifest.Configuration,
|
||||
Contributes: plugin.Manifest.Contributes,
|
||||
}
|
||||
}
|
||||
|
||||
func paymentExpiryPolicy(manifest protocol.Manifest, providerID string) (protocol.ManifestPaymentExpiryPolicy, bool) {
|
||||
for _, contribution := range manifest.Contributes.PaymentProviders {
|
||||
if contribution.ID == providerID {
|
||||
return contribution.ExpiryPolicy, true
|
||||
}
|
||||
}
|
||||
if len(manifest.Contributes.PaymentProviders) == 1 {
|
||||
return manifest.Contributes.PaymentProviders[0].ExpiryPolicy, true
|
||||
}
|
||||
return protocol.ManifestPaymentExpiryPolicy{}, false
|
||||
}
|
||||
|
||||
func (s *Service) decryptPaymentConfig(config *model.PaymentProviderConfig) (payment.Config, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("支付渠道配置不存在")
|
||||
|
||||
Reference in new issue
Block a user