49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package srequest
|
|
|
|
import (
|
|
"github.com/tech/sendico/pkg/merrors"
|
|
"github.com/tech/sendico/pkg/model"
|
|
)
|
|
|
|
type PaymentIntent struct {
|
|
Kind PaymentKind `json:"kind,omitempty"`
|
|
Source *Endpoint `json:"source,omitempty"`
|
|
Destination *Endpoint `json:"destination,omitempty"`
|
|
Amount *model.Money `json:"amount,omitempty"`
|
|
FX *FXIntent `json:"fx,omitempty"`
|
|
SettlementMode SettlementMode `json:"settlement_mode,omitempty"`
|
|
Attributes map[string]string `json:"attributes,omitempty"`
|
|
}
|
|
|
|
func (p *PaymentIntent) Validate() error {
|
|
// Kind must be set (non-zero)
|
|
var zeroKind PaymentKind
|
|
if p.Kind == zeroKind {
|
|
return merrors.InvalidArgument("kind is required", "intent.kind")
|
|
}
|
|
|
|
if p.Source == nil {
|
|
return merrors.InvalidArgument("source is required", "intent.source")
|
|
}
|
|
|
|
if p.Destination == nil {
|
|
return merrors.InvalidArgument("destination is required", "intent.destination")
|
|
}
|
|
|
|
if p.Amount == nil {
|
|
return merrors.InvalidArgument("amount is required", "intent.amount")
|
|
}
|
|
//TODO: collect supported currencies and validate against them
|
|
if err := ValidateMoney(p.Amount, nil); err != nil {
|
|
return err
|
|
}
|
|
|
|
if p.FX != nil {
|
|
if err := p.FX.Validate(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|