extended aurora scenarios + payment operation amounts
This commit is contained in:
@@ -302,7 +302,7 @@ func toPayment(p *orchestrationv2.Payment) *Payment {
|
||||
return nil
|
||||
}
|
||||
intent := p.GetIntentSnapshot()
|
||||
operations := toUserVisibleOperations(p.GetStepExecutions(), p.GetQuoteSnapshot())
|
||||
operations := toUserVisibleOperations(p.GetStepExecutions())
|
||||
failureCode, failureReason := firstFailure(operations)
|
||||
return &Payment{
|
||||
PaymentRef: p.GetPaymentRef(),
|
||||
@@ -562,7 +562,7 @@ func firstFailure(operations []PaymentOperation) (string, string) {
|
||||
return "", ""
|
||||
}
|
||||
|
||||
func toUserVisibleOperations(steps []*orchestrationv2.StepExecution, quote *quotationv2.PaymentQuote) []PaymentOperation {
|
||||
func toUserVisibleOperations(steps []*orchestrationv2.StepExecution) []PaymentOperation {
|
||||
if len(steps) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -571,7 +571,7 @@ func toUserVisibleOperations(steps []*orchestrationv2.StepExecution, quote *quot
|
||||
if step == nil || !isUserVisibleStep(step.GetReportVisibility()) {
|
||||
continue
|
||||
}
|
||||
ops = append(ops, toPaymentOperation(step, quote))
|
||||
ops = append(ops, toPaymentOperation(step))
|
||||
}
|
||||
if len(ops) == 0 {
|
||||
return nil
|
||||
@@ -579,9 +579,10 @@ func toUserVisibleOperations(steps []*orchestrationv2.StepExecution, quote *quot
|
||||
return ops
|
||||
}
|
||||
|
||||
func toPaymentOperation(step *orchestrationv2.StepExecution, quote *quotationv2.PaymentQuote) PaymentOperation {
|
||||
func toPaymentOperation(step *orchestrationv2.StepExecution) PaymentOperation {
|
||||
operationRef, gateway := operationRefAndGateway(step.GetStepCode(), step.GetRefs())
|
||||
amount, convertedAmount := operationAmounts(step.GetStepCode(), quote)
|
||||
amount := normalizeOperationMoney(toMoney(step.GetExecutedMoney()))
|
||||
convertedAmount := normalizeOperationMoney(toMoney(step.GetConvertedMoney()))
|
||||
op := PaymentOperation{
|
||||
StepRef: step.GetStepRef(),
|
||||
Code: step.GetStepCode(),
|
||||
@@ -606,52 +607,19 @@ func toPaymentOperation(step *orchestrationv2.StepExecution, quote *quotationv2.
|
||||
return op
|
||||
}
|
||||
|
||||
func operationAmounts(stepCode string, quote *quotationv2.PaymentQuote) (*paymenttypes.Money, *paymenttypes.Money) {
|
||||
if quote == nil {
|
||||
return nil, nil
|
||||
func normalizeOperationMoney(value *paymenttypes.Money) *paymenttypes.Money {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
operation := stepOperationToken(stepCode)
|
||||
|
||||
primary := firstValidMoney(
|
||||
toMoney(quote.GetDestinationAmount()),
|
||||
toMoney(quote.GetTransferPrincipalAmount()),
|
||||
toMoney(quote.GetPayerTotalDebitAmount()),
|
||||
)
|
||||
if operation != "fx_convert" {
|
||||
return primary, nil
|
||||
amount := strings.TrimSpace(value.GetAmount())
|
||||
currency := strings.TrimSpace(value.GetCurrency())
|
||||
if amount == "" || currency == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
base := firstValidMoney(
|
||||
toMoney(quote.GetTransferPrincipalAmount()),
|
||||
toMoney(quote.GetPayerTotalDebitAmount()),
|
||||
toMoney(quote.GetFxQuote().GetBaseAmount()),
|
||||
)
|
||||
quoteAmount := firstValidMoney(
|
||||
toMoney(quote.GetDestinationAmount()),
|
||||
toMoney(quote.GetFxQuote().GetQuoteAmount()),
|
||||
)
|
||||
return base, quoteAmount
|
||||
}
|
||||
|
||||
func stepOperationToken(stepCode string) string {
|
||||
parts := strings.Split(strings.ToLower(strings.TrimSpace(stepCode)), ".")
|
||||
if len(parts) == 0 {
|
||||
return ""
|
||||
return &paymenttypes.Money{
|
||||
Amount: amount,
|
||||
Currency: currency,
|
||||
}
|
||||
return strings.TrimSpace(parts[len(parts)-1])
|
||||
}
|
||||
|
||||
func firstValidMoney(values ...*paymenttypes.Money) *paymenttypes.Money {
|
||||
for _, value := range values {
|
||||
if value == nil {
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(value.GetAmount()) == "" || strings.TrimSpace(value.GetCurrency()) == "" {
|
||||
continue
|
||||
}
|
||||
return value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user