Orchestrator refactoring + planned amounts
This commit is contained in:
@@ -91,18 +91,27 @@ type PaymentEndpoint struct {
|
||||
}
|
||||
|
||||
type PaymentOperation struct {
|
||||
StepRef string `json:"stepRef,omitempty"`
|
||||
Code string `json:"code,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Label string `json:"label,omitempty"`
|
||||
StepRef string `json:"stepRef,omitempty"`
|
||||
Code string `json:"code,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Label string `json:"label,omitempty"`
|
||||
Money *PaymentOperationMoney `json:"money,omitempty"`
|
||||
OperationRef string `json:"operationRef,omitempty"`
|
||||
Gateway string `json:"gateway,omitempty"`
|
||||
FailureCode string `json:"failureCode,omitempty"`
|
||||
FailureReason string `json:"failureReason,omitempty"`
|
||||
StartedAt time.Time `json:"startedAt,omitempty"`
|
||||
CompletedAt time.Time `json:"completedAt,omitempty"`
|
||||
}
|
||||
|
||||
type PaymentOperationMoney struct {
|
||||
Planned *PaymentOperationMoneySnapshot `json:"planned,omitempty"`
|
||||
Executed *PaymentOperationMoneySnapshot `json:"executed,omitempty"`
|
||||
}
|
||||
|
||||
type PaymentOperationMoneySnapshot struct {
|
||||
Amount *paymenttypes.Money `json:"amount,omitempty"`
|
||||
ConvertedAmount *paymenttypes.Money `json:"convertedAmount,omitempty"`
|
||||
OperationRef string `json:"operationRef,omitempty"`
|
||||
Gateway string `json:"gateway,omitempty"`
|
||||
FailureCode string `json:"failureCode,omitempty"`
|
||||
FailureReason string `json:"failureReason,omitempty"`
|
||||
StartedAt time.Time `json:"startedAt,omitempty"`
|
||||
CompletedAt time.Time `json:"completedAt,omitempty"`
|
||||
}
|
||||
|
||||
type paymentQuoteResponse struct {
|
||||
@@ -581,19 +590,20 @@ func toUserVisibleOperations(steps []*orchestrationv2.StepExecution) []PaymentOp
|
||||
|
||||
func toPaymentOperation(step *orchestrationv2.StepExecution) PaymentOperation {
|
||||
operationRef, gateway := operationRefAndGateway(step.GetStepCode(), step.GetRefs())
|
||||
amount := normalizeOperationMoney(toMoney(step.GetExecutedMoney()))
|
||||
convertedAmount := normalizeOperationMoney(toMoney(step.GetConvertedMoney()))
|
||||
plannedAmount := stepPlannedAmount(step)
|
||||
plannedConvertedAmount := stepPlannedConvertedAmount(step)
|
||||
executedAmount := stepExecutedAmount(step)
|
||||
executedConvertedAmount := stepExecutedConvertedAmount(step)
|
||||
op := PaymentOperation{
|
||||
StepRef: step.GetStepRef(),
|
||||
Code: step.GetStepCode(),
|
||||
State: enumJSONName(step.GetState().String()),
|
||||
Label: strings.TrimSpace(step.GetUserLabel()),
|
||||
Amount: amount,
|
||||
ConvertedAmount: convertedAmount,
|
||||
OperationRef: operationRef,
|
||||
Gateway: gateway,
|
||||
StartedAt: timestampAsTime(step.GetStartedAt()),
|
||||
CompletedAt: timestampAsTime(step.GetCompletedAt()),
|
||||
StepRef: step.GetStepRef(),
|
||||
Code: step.GetStepCode(),
|
||||
State: enumJSONName(step.GetState().String()),
|
||||
Label: strings.TrimSpace(step.GetUserLabel()),
|
||||
Money: toOperationMoney(plannedAmount, plannedConvertedAmount, executedAmount, executedConvertedAmount),
|
||||
OperationRef: operationRef,
|
||||
Gateway: gateway,
|
||||
StartedAt: timestampAsTime(step.GetStartedAt()),
|
||||
CompletedAt: timestampAsTime(step.GetCompletedAt()),
|
||||
}
|
||||
failure := step.GetFailure()
|
||||
if failure == nil {
|
||||
@@ -607,6 +617,89 @@ func toPaymentOperation(step *orchestrationv2.StepExecution) PaymentOperation {
|
||||
return op
|
||||
}
|
||||
|
||||
func stepPlannedAmount(step *orchestrationv2.StepExecution) *paymenttypes.Money {
|
||||
if step == nil {
|
||||
return nil
|
||||
}
|
||||
if money := step.GetMoney(); money != nil {
|
||||
if planned := money.GetPlanned(); planned != nil {
|
||||
if normalized := normalizeOperationMoney(toMoney(planned.GetAmount())); normalized != nil {
|
||||
return normalized
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func stepPlannedConvertedAmount(step *orchestrationv2.StepExecution) *paymenttypes.Money {
|
||||
if step == nil {
|
||||
return nil
|
||||
}
|
||||
if money := step.GetMoney(); money != nil {
|
||||
if planned := money.GetPlanned(); planned != nil {
|
||||
if normalized := normalizeOperationMoney(toMoney(planned.GetConvertedAmount())); normalized != nil {
|
||||
return normalized
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func stepExecutedAmount(step *orchestrationv2.StepExecution) *paymenttypes.Money {
|
||||
if step == nil {
|
||||
return nil
|
||||
}
|
||||
if money := step.GetMoney(); money != nil {
|
||||
if executed := money.GetExecuted(); executed != nil {
|
||||
if normalized := normalizeOperationMoney(toMoney(executed.GetAmount())); normalized != nil {
|
||||
return normalized
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func stepExecutedConvertedAmount(step *orchestrationv2.StepExecution) *paymenttypes.Money {
|
||||
if step == nil {
|
||||
return nil
|
||||
}
|
||||
if money := step.GetMoney(); money != nil {
|
||||
if executed := money.GetExecuted(); executed != nil {
|
||||
if normalized := normalizeOperationMoney(toMoney(executed.GetConvertedAmount())); normalized != nil {
|
||||
return normalized
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func toOperationMoney(
|
||||
plannedAmount *paymenttypes.Money,
|
||||
plannedConvertedAmount *paymenttypes.Money,
|
||||
executedAmount *paymenttypes.Money,
|
||||
executedConvertedAmount *paymenttypes.Money,
|
||||
) *PaymentOperationMoney {
|
||||
planned := toOperationMoneySnapshot(plannedAmount, plannedConvertedAmount)
|
||||
executed := toOperationMoneySnapshot(executedAmount, executedConvertedAmount)
|
||||
if planned == nil && executed == nil {
|
||||
return nil
|
||||
}
|
||||
return &PaymentOperationMoney{
|
||||
Planned: planned,
|
||||
Executed: executed,
|
||||
}
|
||||
}
|
||||
|
||||
func toOperationMoneySnapshot(amount *paymenttypes.Money, convertedAmount *paymenttypes.Money) *PaymentOperationMoneySnapshot {
|
||||
if amount == nil && convertedAmount == nil {
|
||||
return nil
|
||||
}
|
||||
return &PaymentOperationMoneySnapshot{
|
||||
Amount: amount,
|
||||
ConvertedAmount: convertedAmount,
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeOperationMoney(value *paymenttypes.Money) *paymenttypes.Money {
|
||||
if value == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user