payment rails

This commit is contained in:
Stephan D
2025-12-10 18:40:55 +01:00
parent 81d2db394b
commit 47899e25d4
39 changed files with 3043 additions and 909 deletions

View File

@@ -1,17 +1,60 @@
package srequest
import (
"github.com/tech/sendico/pkg/merrors"
)
type QuotePayment struct {
IdempotencyKey string `json:"idempotencyKey"`
Intent *PaymentIntent `json:"intent"`
Intent PaymentIntent `json:"intent"`
PreviewOnly bool `json:"previewOnly"`
Metadata map[string]string `json:"metadata,omitempty"`
}
type InitiatePayment struct {
IdempotencyKey string `json:"idempotencyKey"`
Intent *PaymentIntent `json:"intent"`
Metadata map[string]string `json:"metadata,omitempty"`
FeeQuoteToken string `json:"feeQuoteToken,omitempty"`
FxQuoteRef string `json:"fxQuoteRef,omitempty"`
Intent *PaymentIntent `json:"intent,omitempty"`
QuoteRef string `json:"quoteRef,omitempty"`
}
func (r QuotePayment) Validate() error {
if r.IdempotencyKey == "" {
return merrors.InvalidArgument("idempotencyKey is required", "idempotencyKey")
}
if validator, ok := any(r.Intent).(interface{ Validate() error }); ok {
if err := validator.Validate(); err != nil {
return err
}
}
return nil
}
// Validate проверяет базовые инварианты запроса на инициацию платежа.
func (r InitiatePayment) Validate() error {
if r.IdempotencyKey == "" {
return merrors.InvalidArgument("idempotencyKey is required", "idempotencyKey")
}
hasIntent := r.Intent != nil
hasQuote := r.QuoteRef != ""
switch {
case !hasIntent && !hasQuote:
return merrors.NoData("either intent or quoteRef must be provided")
case hasIntent && hasQuote:
return merrors.DataConflict("intent and quoteRef are mutually exclusive")
}
if hasIntent {
if validator, ok := any(*r.Intent).(interface{ Validate() error }); ok {
if err := validator.Validate(); err != nil {
return err
}
}
}
return nil
}