ledger autoresolution
This commit is contained in:
@@ -81,7 +81,7 @@ func (p *paymentExecutor) postLedgerBlock(ctx context.Context, payment *model.Pa
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
blockAccount, err := ledgerBlockAccount(payment)
|
||||
blockAccount, err := p.resolveLedgerBlockAccount(ctx, payment, amount)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func (p *paymentExecutor) postLedgerRelease(ctx context.Context, payment *model.
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
blockAccount, err := ledgerBlockAccount(payment)
|
||||
blockAccount, err := p.resolveLedgerBlockAccount(ctx, payment, amount)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -441,6 +441,23 @@ func setLedgerAccountAttributes(payment *model.Payment, accountRef string) {
|
||||
}
|
||||
}
|
||||
|
||||
func setLedgerBlockAccountAttributes(payment *model.Payment, accountRef string) {
|
||||
if payment == nil || strings.TrimSpace(accountRef) == "" {
|
||||
return
|
||||
}
|
||||
if payment.Intent.Attributes == nil {
|
||||
payment.Intent.Attributes = map[string]string{}
|
||||
}
|
||||
if attributeLookup(payment.Intent.Attributes,
|
||||
"ledger_block_account_ref",
|
||||
"ledgerBlockAccountRef",
|
||||
"ledger_hold_account_ref",
|
||||
"ledgerHoldAccountRef",
|
||||
) == "" {
|
||||
payment.Intent.Attributes["ledger_block_account_ref"] = accountRef
|
||||
}
|
||||
}
|
||||
|
||||
func ledgerDebitAccount(payment *model.Payment) (string, string, error) {
|
||||
if payment == nil {
|
||||
return "", "", merrors.InvalidArgument("ledger: payment is required")
|
||||
@@ -483,6 +500,24 @@ func ledgerBlockAccount(payment *model.Payment) (string, error) {
|
||||
return "", merrors.InvalidArgument("ledger: block account is required")
|
||||
}
|
||||
|
||||
func (p *paymentExecutor) resolveLedgerBlockAccount(ctx context.Context, payment *model.Payment, amount *moneyv1.Money) (string, error) {
|
||||
if payment == nil {
|
||||
return "", merrors.InvalidArgument("ledger: payment is required")
|
||||
}
|
||||
if amount == nil || strings.TrimSpace(amount.GetCurrency()) == "" {
|
||||
return "", merrors.InvalidArgument("ledger: amount is required")
|
||||
}
|
||||
if ref, err := ledgerBlockAccount(payment); err == nil && strings.TrimSpace(ref) != "" {
|
||||
return ref, nil
|
||||
}
|
||||
account, err := p.resolveOrgOwnedLedgerAccount(ctx, payment, amount)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
setLedgerBlockAccountAttributes(payment, account)
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func ledgerBlockAccountIfConfirmed(payment *model.Payment) string {
|
||||
if payment == nil {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user