multiquote service
This commit is contained in:
@@ -5,9 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tech/sendico/payments/orchestrator/storage/model"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
||||
paginationv1 "github.com/tech/sendico/pkg/proto/common/pagination/v1"
|
||||
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
|
||||
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
|
||||
@@ -413,74 +411,3 @@ func cloneNetworkEstimate(resp *chainv1.EstimateTransferFeeResponse) *chainv1.Es
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func protoFailureToModel(code orchestratorv1.PaymentFailureCode) model.PaymentFailureCode {
|
||||
switch code {
|
||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_BALANCE:
|
||||
return model.PaymentFailureCodeBalance
|
||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_LEDGER:
|
||||
return model.PaymentFailureCodeLedger
|
||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_FX:
|
||||
return model.PaymentFailureCodeFX
|
||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_CHAIN:
|
||||
return model.PaymentFailureCodeChain
|
||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_FEES:
|
||||
return model.PaymentFailureCodeFees
|
||||
case orchestratorv1.PaymentFailureCode_PAYMENT_FAILURE_CODE_POLICY:
|
||||
return model.PaymentFailureCodePolicy
|
||||
default:
|
||||
return model.PaymentFailureCodeUnspecified
|
||||
}
|
||||
}
|
||||
|
||||
func applyProtoPaymentToModel(src *orchestratorv1.Payment, dst *model.Payment) error {
|
||||
if src == nil || dst == nil {
|
||||
return merrors.InvalidArgument("payment payload is required")
|
||||
}
|
||||
dst.PaymentRef = strings.TrimSpace(src.GetPaymentRef())
|
||||
dst.IdempotencyKey = strings.TrimSpace(src.GetIdempotencyKey())
|
||||
dst.Intent = intentFromProto(src.GetIntent())
|
||||
dst.State = modelStateFromProto(src.GetState())
|
||||
dst.FailureCode = protoFailureToModel(src.GetFailureCode())
|
||||
dst.FailureReason = strings.TrimSpace(src.GetFailureReason())
|
||||
dst.Metadata = cloneMetadata(src.GetMetadata())
|
||||
dst.LastQuote = quoteSnapshotToModel(src.GetLastQuote())
|
||||
dst.Execution = executionFromProto(src.GetExecution())
|
||||
if src.GetCardPayout() != nil {
|
||||
dst.CardPayout = &model.CardPayout{
|
||||
PayoutRef: strings.TrimSpace(src.GetCardPayout().GetPayoutRef()),
|
||||
ProviderPaymentID: strings.TrimSpace(src.GetCardPayout().GetProviderPaymentId()),
|
||||
Status: strings.TrimSpace(src.GetCardPayout().GetStatus()),
|
||||
FailureReason: strings.TrimSpace(src.GetCardPayout().GetFailureReason()),
|
||||
CardCountry: strings.TrimSpace(src.GetCardPayout().GetCardCountry()),
|
||||
MaskedPan: strings.TrimSpace(src.GetCardPayout().GetMaskedPan()),
|
||||
ProviderCode: strings.TrimSpace(src.GetCardPayout().GetProviderCode()),
|
||||
GatewayReference: strings.TrimSpace(src.GetCardPayout().GetGatewayReference()),
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func executionFromProto(src *orchestratorv1.ExecutionRefs) *model.ExecutionRefs {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
return &model.ExecutionRefs{
|
||||
DebitEntryRef: strings.TrimSpace(src.GetDebitEntryRef()),
|
||||
CreditEntryRef: strings.TrimSpace(src.GetCreditEntryRef()),
|
||||
FXEntryRef: strings.TrimSpace(src.GetFxEntryRef()),
|
||||
ChainTransferRef: strings.TrimSpace(src.GetChainTransferRef()),
|
||||
CardPayoutRef: strings.TrimSpace(src.GetCardPayoutRef()),
|
||||
FeeTransferRef: strings.TrimSpace(src.GetFeeTransferRef()),
|
||||
}
|
||||
}
|
||||
|
||||
func ensurePageRequest(req *orchestratorv1.ListPaymentsRequest) *paginationv1.CursorPageRequest {
|
||||
if req == nil {
|
||||
return &paginationv1.CursorPageRequest{}
|
||||
}
|
||||
if req.GetPage() == nil {
|
||||
return &paginationv1.CursorPageRequest{}
|
||||
}
|
||||
return req.GetPage()
|
||||
}
|
||||
|
||||
@@ -214,20 +214,6 @@ func decimalFromMoney(m *moneyv1.Money) (decimal.Decimal, error) {
|
||||
return decimal.NewFromString(m.GetAmount())
|
||||
}
|
||||
|
||||
func decimalFromMoneyMatching(reference, candidate *moneyv1.Money) (*decimal.Decimal, error) {
|
||||
if reference == nil || candidate == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if !strings.EqualFold(reference.GetCurrency(), candidate.GetCurrency()) {
|
||||
return nil, nil
|
||||
}
|
||||
value, err := decimal.NewFromString(candidate.GetAmount())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &value, nil
|
||||
}
|
||||
|
||||
func makeMoney(currency string, value decimal.Decimal) *moneyv1.Money {
|
||||
return &moneyv1.Money{
|
||||
Currency: currency,
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestMinQuoteExpiry(t *testing.T) {
|
||||
later := now.Add(10 * time.Minute)
|
||||
earliest := now.Add(5 * time.Minute)
|
||||
|
||||
min, ok := minQuoteExpiry([]time.Time{later, time.Time{}, earliest})
|
||||
min, ok := minQuoteExpiry([]time.Time{later, {}, earliest})
|
||||
if !ok {
|
||||
t.Fatal("expected min expiry to be set")
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func TestMinQuoteExpiry(t *testing.T) {
|
||||
t.Fatalf("expected min expiry %v, got %v", earliest, min)
|
||||
}
|
||||
|
||||
if _, ok := minQuoteExpiry([]time.Time{time.Time{}}); ok {
|
||||
if _, ok := minQuoteExpiry([]time.Time{{}}); ok {
|
||||
t.Fatal("expected min expiry to be unset")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user