feat: add per-provider allow_user_refund control and align wildcard matching
allow_user_refund: - Add allow_user_refund field to PaymentProviderInstance ent schema - Migration 103: ALTER TABLE payment_provider_instances ADD COLUMN - Cascade logic: disabling refund_enabled auto-disables allow_user_refund - User refund validation: check provider instance allows user refund - Admin refund validation: check provider instance allows admin refund - Subscription refund: deduct days on refund, rollback on failure - New endpoint: GET /payment/orders/refund-eligible-providers - Frontend: ToggleSwitch in ProviderCard/Dialog, cascade in SettingsView Wildcard matching: - Change findPricingForModel from "longest prefix wins" to "config order priority (first match wins)", aligning with channel service behavior
This commit is contained in:
@@ -15642,25 +15642,26 @@ func (m *PaymentOrderMutation) ResetEdge(name string) error {
|
||||
// PaymentProviderInstanceMutation represents an operation that mutates the PaymentProviderInstance nodes in the graph.
|
||||
type PaymentProviderInstanceMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *int64
|
||||
provider_key *string
|
||||
name *string
|
||||
_config *string
|
||||
supported_types *string
|
||||
enabled *bool
|
||||
payment_mode *string
|
||||
sort_order *int
|
||||
addsort_order *int
|
||||
limits *string
|
||||
refund_enabled *bool
|
||||
created_at *time.Time
|
||||
updated_at *time.Time
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
oldValue func(context.Context) (*PaymentProviderInstance, error)
|
||||
predicates []predicate.PaymentProviderInstance
|
||||
op Op
|
||||
typ string
|
||||
id *int64
|
||||
provider_key *string
|
||||
name *string
|
||||
_config *string
|
||||
supported_types *string
|
||||
enabled *bool
|
||||
payment_mode *string
|
||||
sort_order *int
|
||||
addsort_order *int
|
||||
limits *string
|
||||
refund_enabled *bool
|
||||
allow_user_refund *bool
|
||||
created_at *time.Time
|
||||
updated_at *time.Time
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
oldValue func(context.Context) (*PaymentProviderInstance, error)
|
||||
predicates []predicate.PaymentProviderInstance
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*PaymentProviderInstanceMutation)(nil)
|
||||
@@ -16105,6 +16106,42 @@ func (m *PaymentProviderInstanceMutation) ResetRefundEnabled() {
|
||||
m.refund_enabled = nil
|
||||
}
|
||||
|
||||
// SetAllowUserRefund sets the "allow_user_refund" field.
|
||||
func (m *PaymentProviderInstanceMutation) SetAllowUserRefund(b bool) {
|
||||
m.allow_user_refund = &b
|
||||
}
|
||||
|
||||
// AllowUserRefund returns the value of the "allow_user_refund" field in the mutation.
|
||||
func (m *PaymentProviderInstanceMutation) AllowUserRefund() (r bool, exists bool) {
|
||||
v := m.allow_user_refund
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldAllowUserRefund returns the old "allow_user_refund" field's value of the PaymentProviderInstance entity.
|
||||
// If the PaymentProviderInstance object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *PaymentProviderInstanceMutation) OldAllowUserRefund(ctx context.Context) (v bool, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldAllowUserRefund is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldAllowUserRefund requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldAllowUserRefund: %w", err)
|
||||
}
|
||||
return oldValue.AllowUserRefund, nil
|
||||
}
|
||||
|
||||
// ResetAllowUserRefund resets all changes to the "allow_user_refund" field.
|
||||
func (m *PaymentProviderInstanceMutation) ResetAllowUserRefund() {
|
||||
m.allow_user_refund = nil
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (m *PaymentProviderInstanceMutation) SetCreatedAt(t time.Time) {
|
||||
m.created_at = &t
|
||||
@@ -16211,7 +16248,7 @@ func (m *PaymentProviderInstanceMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *PaymentProviderInstanceMutation) Fields() []string {
|
||||
fields := make([]string, 0, 11)
|
||||
fields := make([]string, 0, 12)
|
||||
if m.provider_key != nil {
|
||||
fields = append(fields, paymentproviderinstance.FieldProviderKey)
|
||||
}
|
||||
@@ -16239,6 +16276,9 @@ func (m *PaymentProviderInstanceMutation) Fields() []string {
|
||||
if m.refund_enabled != nil {
|
||||
fields = append(fields, paymentproviderinstance.FieldRefundEnabled)
|
||||
}
|
||||
if m.allow_user_refund != nil {
|
||||
fields = append(fields, paymentproviderinstance.FieldAllowUserRefund)
|
||||
}
|
||||
if m.created_at != nil {
|
||||
fields = append(fields, paymentproviderinstance.FieldCreatedAt)
|
||||
}
|
||||
@@ -16271,6 +16311,8 @@ func (m *PaymentProviderInstanceMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.Limits()
|
||||
case paymentproviderinstance.FieldRefundEnabled:
|
||||
return m.RefundEnabled()
|
||||
case paymentproviderinstance.FieldAllowUserRefund:
|
||||
return m.AllowUserRefund()
|
||||
case paymentproviderinstance.FieldCreatedAt:
|
||||
return m.CreatedAt()
|
||||
case paymentproviderinstance.FieldUpdatedAt:
|
||||
@@ -16302,6 +16344,8 @@ func (m *PaymentProviderInstanceMutation) OldField(ctx context.Context, name str
|
||||
return m.OldLimits(ctx)
|
||||
case paymentproviderinstance.FieldRefundEnabled:
|
||||
return m.OldRefundEnabled(ctx)
|
||||
case paymentproviderinstance.FieldAllowUserRefund:
|
||||
return m.OldAllowUserRefund(ctx)
|
||||
case paymentproviderinstance.FieldCreatedAt:
|
||||
return m.OldCreatedAt(ctx)
|
||||
case paymentproviderinstance.FieldUpdatedAt:
|
||||
@@ -16378,6 +16422,13 @@ func (m *PaymentProviderInstanceMutation) SetField(name string, value ent.Value)
|
||||
}
|
||||
m.SetRefundEnabled(v)
|
||||
return nil
|
||||
case paymentproviderinstance.FieldAllowUserRefund:
|
||||
v, ok := value.(bool)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetAllowUserRefund(v)
|
||||
return nil
|
||||
case paymentproviderinstance.FieldCreatedAt:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
@@ -16483,6 +16534,9 @@ func (m *PaymentProviderInstanceMutation) ResetField(name string) error {
|
||||
case paymentproviderinstance.FieldRefundEnabled:
|
||||
m.ResetRefundEnabled()
|
||||
return nil
|
||||
case paymentproviderinstance.FieldAllowUserRefund:
|
||||
m.ResetAllowUserRefund()
|
||||
return nil
|
||||
case paymentproviderinstance.FieldCreatedAt:
|
||||
m.ResetCreatedAt()
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user