def getInvoices()

in src/main/scala/com/gu/invoicing/refundErroneousPayment/Impl.scala [55:91]


  def getInvoices(accountId: String): List[Invoice] =
    Http(s"$zuoraApiHost/v1/action/query")
      .header("Authorization", s"Bearer $accessToken")
      .header("Content-Type", "application/json")
      .postData(
        s"""{"queryString": "select Id, Amount, Balance, InvoiceDate, InvoiceNumber, PaymentAmount, TargetDate, Status from Invoice where AccountId = '$accountId' and Status = 'Posted'"}""",
      )
      .method("POST")
      .asString
      .body
      .pipe(read[InvoiceQueryResult](_))
      .records

  def getPayments(accountId: String, paymentDate: LocalDate): List[Payment] =
    Http(s"$zuoraApiHost/v1/transactions/payments/accounts/$accountId")
      .header("Authorization", s"Bearer $accessToken")
      .asString
      .body
      .pipe(read[Payments](_))
      .payments
      .filter(payment => payment.status == "Processed" && payment.effectiveDate == paymentDate)

  def transferToCreditBalance(
      invoiceNumber: String,
      amount: BigDecimal,
      comment: String,
  ): Unit =
    Http(s"$zuoraApiHost/v1/object/credit-balance-adjustment")
      .header("Authorization", s"Bearer $accessToken")
      .header("Content-Type", "application/json")
      .postData(s"""
           |{
           |  "Amount": $amount,
           |  "Comment": "$comment",
           |  "SourceTransactionNumber": "$invoiceNumber",
           |  "Type": "Increase"
           |}