def getInvoices()

in src/main/scala/com/gu/invoicing/refund/Impl.scala [24:65]


  def getInvoices(accountId: String): List[Invoice] =
    post[InvoiceQueryResult](
      s"$zuoraApiHost/v1/action/query",
      s"""{"queryString": "select Id, Amount, Balance, InvoiceDate, InvoiceNumber, PaymentAmount, TargetDate, Status from Invoice where AccountId = '$accountId'"}""",
    ).records

  def getInvoiceItems(invoiceId: String): List[InvoiceItem] =
    get[InvoiceItems](s"$zuoraApiHost/v1/invoices/$invoiceId/items").invoiceItems

  def getItemsByInvoice(subscriptionName: String): Map[String, List[InvoiceItem]] =
    post[InvoiceItemQueryResult](
      s"$zuoraApiHost/v1/action/query",
      s"""{"queryString": "select Id, ChargeAmount, TaxAmount, ChargeDate, ChargeName, ChargeNumber, InvoiceId, ProductName, ServiceEndDate, ServiceStartDate, SubscriptionNumber FROM InvoiceItem where SubscriptionNumber = '$subscriptionName'"}""".stripMargin,
    ).records
      .groupBy(_.InvoiceId)

  def getTaxationItemsForInvoice(invoiceId: String): List[TaxationItem] =
    post[TaxationItemQueryResult](
      s"$zuoraApiHost/v1/action/query",
      s"""{"queryString": "select Id, InvoiceId, InvoiceItemId FROM TaxationItem where InvoiceId = '$invoiceId'"}""".stripMargin,
    ).records

  def getInvoicePaymentId(invoiceId: String): Option[String] =
    post[InvoicePaymentQueryResult](
      s"$zuoraApiHost/v1/action/query",
      s"""{"queryString": "select Id, invoiceId, paymentId, CreatedDate from InvoicePayment where invoiceId = '$invoiceId'"}""",
    ).records
      .sortBy(_.CreatedDate)
      .reverse
      .headOption
      .map(_.PaymentId)

  def createRefundObject(amount: BigDecimal, paymentId: String, comment: String): String =
    post[RefundResult](
      s"$zuoraApiHost/v1/object/refund",
      s"""
         |{
         |  "Amount": $amount,
         |  "Comment": "$comment",
         |  "PaymentId": "$paymentId",
         |  "Type": "Electronic"
         |}