diff --git a/api/payments/orchestrator/internal/service/orchestrator/convert.go b/api/payments/orchestrator/internal/service/orchestrator/convert.go index 37c867cb..a5bb955d 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/convert.go +++ b/api/payments/orchestrator/internal/service/orchestrator/convert.go @@ -404,8 +404,9 @@ func filterFromProto(req *orchestratorv1.ListPaymentsRequest) *model.PaymentFilt return &model.PaymentFilter{} } filter := &model.PaymentFilter{ - SourceRef: strings.TrimSpace(req.GetSourceRef()), - DestinationRef: strings.TrimSpace(req.GetDestinationRef()), + SourceRef: strings.TrimSpace(req.GetSourceRef()), + DestinationRef: strings.TrimSpace(req.GetDestinationRef()), + OrganizationRef: strings.TrimSpace(req.GetOrganizationRef()), } if req.GetPage() != nil { filter.Cursor = strings.TrimSpace(req.GetPage().GetCursor()) diff --git a/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go b/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go index 2b24f0ff..3ef2ec92 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go +++ b/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go @@ -53,13 +53,11 @@ func (p *paymentExecutor) buildProviderSettlementTransferRequest(payment *model. if strings.TrimSpace(metadata[providerSettlementMetaOutgoingLeg]) == "" { metadata[providerSettlementMetaOutgoingLeg] = strings.ToLower(strings.TrimSpace(string(step.Rail))) } - if amount != nil { - if strings.TrimSpace(metadata[providerSettlementMetaSourceAmount]) == "" { - metadata[providerSettlementMetaSourceAmount] = strings.TrimSpace(amount.Amount) - } - if strings.TrimSpace(metadata[providerSettlementMetaSourceCurrency]) == "" { - metadata[providerSettlementMetaSourceCurrency] = strings.TrimSpace(amount.Currency) - } + if strings.TrimSpace(metadata[providerSettlementMetaSourceAmount]) == "" { + metadata[providerSettlementMetaSourceAmount] = strings.TrimSpace(amount.Amount) + } + if strings.TrimSpace(metadata[providerSettlementMetaSourceCurrency]) == "" { + metadata[providerSettlementMetaSourceCurrency] = strings.TrimSpace(amount.Currency) } sourceWalletRef := "" diff --git a/api/payments/orchestrator/storage/model/payment.go b/api/payments/orchestrator/storage/model/payment.go index 7b138f11..d86591b5 100644 --- a/api/payments/orchestrator/storage/model/payment.go +++ b/api/payments/orchestrator/storage/model/payment.go @@ -368,11 +368,12 @@ func (*Payment) Collection() string { // PaymentFilter enables filtered queries. type PaymentFilter struct { - States []PaymentState - SourceRef string - DestinationRef string - Cursor string - Limit int32 + States []PaymentState + SourceRef string + OrganizationRef string + DestinationRef string + Cursor string + Limit int32 } // PaymentList contains paginated results. diff --git a/api/payments/orchestrator/storage/mongo/store/payments.go b/api/payments/orchestrator/storage/mongo/store/payments.go index 63b190e6..705ee661 100644 --- a/api/payments/orchestrator/storage/mongo/store/payments.go +++ b/api/payments/orchestrator/storage/mongo/store/payments.go @@ -200,6 +200,14 @@ func (p *Payments) List(ctx context.Context, filter *model.PaymentFilter) (*mode query = query.And(endpointFilter) } } + if ref := strings.TrimSpace(filter.OrganizationRef); ref != "" { + orgRef, err := bson.ObjectIDFromHex(ref) + if err != nil { + p.logger.Warn("Failed to decode organization reference", zap.Error(err), zap.String("provided_org_ref", ref)) + return nil, err + } + query.And(repository.OrgFilter(orgRef)) + } if ref := strings.TrimSpace(filter.DestinationRef); ref != "" { if endpointFilter := endpointQuery("intent.destination", ref); endpointFilter != nil { @@ -223,6 +231,7 @@ func (p *Payments) List(ctx context.Context, filter *model.PaymentFilter) (*mode decoder := func(cur *mongo.Cursor) error { item := &model.Payment{} if err := cur.Decode(item); err != nil { + p.logger.Warn("Failed to decode item", zap.Error(err), zap.Any("item", cur.Current)) return err } payments = append(payments, item) diff --git a/api/proto/payments/orchestrator/v1/orchestrator.proto b/api/proto/payments/orchestrator/v1/orchestrator.proto index 58e67929..7306ecbe 100644 --- a/api/proto/payments/orchestrator/v1/orchestrator.proto +++ b/api/proto/payments/orchestrator/v1/orchestrator.proto @@ -290,6 +290,7 @@ message ListPaymentsRequest { string source_ref = 3; string destination_ref = 4; common.pagination.v1.CursorPageRequest page = 5; + string organization_ref = 6; } message ListPaymentsResponse { diff --git a/api/server/internal/server/paymentapiimp/list.go b/api/server/internal/server/paymentapiimp/list.go index 15f2fba0..5715946f 100644 --- a/api/server/internal/server/paymentapiimp/list.go +++ b/api/server/internal/server/paymentapiimp/list.go @@ -38,9 +38,7 @@ func (a *PaymentAPI) listPayments(r *http.Request, account *model.Account, token } req := &orchestratorv1.ListPaymentsRequest{ - Meta: &orchestratorv1.RequestMeta{ - OrganizationRef: orgRef.Hex(), - }, + OrganizationRef: orgRef.Hex(), } if page, err := listPaymentsPage(r); err != nil {