Getting sum of values grouped by predicate

I’m still analysing your case but why not this?

  {
      "isBill": true,
      "items": [
        { "amount": 5,
          "paymentType": {"uid": "_:card"},
          "waitingpayment": true },
        { "amount": 3,
          "paymentType": {"uid": "_:cash"},
          "waitingpayment": false }
  }