/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.2-dev * User agent: apibuilder app.apibuilder.io/mard/mard2p-api/0.0.2-dev/http4s_0_23 */ package payp.mard2p.api.v0 { import cats.effect._ import cats.implicits._ import io.circe.syntax._ object Constants { val BaseUrl = "https://api.apibuilder.io" val Namespace = "payp.mard2p.api.v0" val UserAgent = "apibuilder app.apibuilder.io/mard/mard2p-api/0.0.2-dev/http4s_0_23" val Version = "0.0.2-dev" val VersionMajor = 0 } class Client[F[_]: Concurrent]( val baseUrl: org.http4s.Uri = org.http4s.Uri.unsafeFromString("https://api.apibuilder.io"), auth: scala.Option[payp.mard2p.api.v0.Authorization] = None, defaultHeaders: Seq[(String, String)] = Nil, httpClient: org.http4s.client.Client[F] ) extends interfaces.Client[F] { import org.http4s.Response import io.apibuilder.common.v0.models.json._ import io.apibuilder.generator.v0.models.json._ import io.apibuilder.spec.v0.models.json._ import payp.mard2p.api.v0.models.json._ def accounts: Accounts[F] = Accounts def deposits: Deposits[F] = Deposits def payments: Payments[F] = Payments def transfers: Transfers[F] = Transfers def validations: Validations[F] = Validations def withdraws: Withdraws[F] = Withdraws object Accounts extends Accounts[F] { override def postCreate( accountid: Long, ownerid: String, totalAmount: Double, sold: Double, debit: Double, currency: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Account] = { val urlPath = Seq("accounts", "create") val payload = None val formPayload = Some(org.http4s.UrlForm( "accountid" -> accountid.asJson.noSpaces, "ownerid" -> ownerid, "total_amount" -> totalAmount.asJson.noSpaces, "sold" -> sold.asJson.noSpaces, "debit" -> debit.asJson.noSpaces, "currency" -> currency )) _executeRequest[Unit, payp.mard2p.api.v0.models.Account]("POST", path = urlPath, body = payload, formBody = formPayload, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Account]("payp.mard2p.api.v0.models.Account", r) case r if r.status.code == 409 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 409")) } } override def putUpdateByAccountid( accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Account] = { val urlPath = Seq("accounts", "update", accountid.toString) val payload = None val formPayload = Some(org.http4s.UrlForm( "ownerid" -> ownerid, "total_amount" -> totalAmount.asJson.noSpaces, "currency" -> currency, "sold" -> sold.asJson.noSpaces, "debit" -> debit.asJson.noSpaces )) _executeRequest[Unit, payp.mard2p.api.v0.models.Account]("PUT", path = urlPath, body = payload, formBody = formPayload, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Account]("payp.mard2p.api.v0.models.Account", r) case r if r.status.code == 409 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 409")) } } override def deleteDeleteByAccountid( accountid: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Unit] = { val urlPath = Seq("accounts", "delete", accountid.toString) _executeRequest[Unit, Unit]("DELETE", path = urlPath, requestHeaders = requestHeaders) { case r if r.status.code == 204 => Concurrent[F].pure(()) case r if r.status.code == 401 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 204, 401, 404")) } } override def getByAccountid( accountid: Long, ownerid: String, totalAmount: Double, sold: Double, debit: Double, currency: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Account] = { val urlPath = Seq("accounts", accountid.toString) val queryParameters = Seq( Some("ownerid" -> ownerid), Some("total_amount" -> totalAmount.toString), Some("sold" -> sold.toString), Some("debit" -> debit.toString), Some("currency" -> currency) ).flatten _executeRequest[Unit, payp.mard2p.api.v0.models.Account]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Account]("payp.mard2p.api.v0.models.Account", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } override def getList( accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double, requestHeaders: Seq[(String, String)] = Nil ): F[Seq[payp.mard2p.api.v0.models.Account]] = { val urlPath = Seq("accounts", "list") val queryParameters = Seq( Some("accountid" -> accountid.toString), Some("ownerid" -> ownerid), Some("total_amount" -> totalAmount.toString), Some("currency" -> currency), Some("sold" -> sold.toString), Some("debit" -> debit.toString) ).flatten _executeRequest[Unit, Seq[payp.mard2p.api.v0.models.Account]]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, Seq[payp.mard2p.api.v0.models.Account]]("Seq[payp.mard2p.api.v0.models.Account]", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } } object Deposits extends Deposits[F] { override def deleteDeleteByDepid( depid: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Unit] = { val urlPath = Seq("deposits", "delete", depid.toString) _executeRequest[Unit, Unit]("DELETE", path = urlPath, requestHeaders = requestHeaders) { case r if r.status.code == 204 => Concurrent[F].pure(()) case r if r.status.code == 401 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 204, 401, 404")) } } override def getByDepid( depid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] = { val urlPath = Seq("deposits", depid.toString) val queryParameters = Seq( Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest[Unit, payp.mard2p.api.v0.models.Payment]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Payment]("payp.mard2p.api.v0.models.Payment", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } override def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[Seq[payp.mard2p.api.v0.models.Payment]] = { val urlPath = Seq("deposits", "list") val queryParameters = Seq( Some("payid" -> payid.toString), Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest[Unit, Seq[payp.mard2p.api.v0.models.Payment]]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, Seq[payp.mard2p.api.v0.models.Payment]]("Seq[payp.mard2p.api.v0.models.Payment]", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } } object Payments extends Payments[F] { override def postCreate( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, currency: String, phone: Long, pin: Int, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] = { val urlPath = Seq("payments", "create") val payload = None val formPayload = Some(org.http4s.UrlForm( "payid" -> payid.asJson.noSpaces, "payment_method" -> paymentMethod, "actorid" -> actorid, "ref_accountid" -> refAccountid.asJson.noSpaces, "operatorid" -> operatorid, "amount" -> amount.asJson.noSpaces, "currency" -> currency, "phone" -> phone.asJson.noSpaces, "pin" -> pin.asJson.noSpaces, "payment_context" -> paymentContext )) _executeRequest[Unit, payp.mard2p.api.v0.models.Payment]("POST", path = urlPath, body = payload, formBody = formPayload, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Payment]("payp.mard2p.api.v0.models.Payment", r) case r if r.status.code == 409 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 409")) } } override def putUpdateByPayid( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Int, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] = { val urlPath = Seq("payments", "update", payid.toString) val payload = None val formPayload = Some(org.http4s.UrlForm( "payment_method" -> paymentMethod, "actorid" -> actorid, "ref_accountid" -> refAccountid.asJson.noSpaces, "operatorid" -> operatorid, "amount" -> amount.asJson.noSpaces, "phone" -> phone.asJson.noSpaces, "pin" -> pin.asJson.noSpaces, "currency" -> currency, "payment_context" -> paymentContext )) _executeRequest[Unit, payp.mard2p.api.v0.models.Payment]("PUT", path = urlPath, body = payload, formBody = formPayload, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Payment]("payp.mard2p.api.v0.models.Payment", r) case r if r.status.code == 409 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 409")) } } override def deleteDeleteByPayid( payid: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Unit] = { val urlPath = Seq("payments", "delete", payid.toString) _executeRequest[Unit, Unit]("DELETE", path = urlPath, requestHeaders = requestHeaders) { case r if r.status.code == 204 => Concurrent[F].pure(()) case r if r.status.code == 401 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 204, 401, 404")) } } override def getByPayid( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] = { val urlPath = Seq("payments", payid.toString) val queryParameters = Seq( Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest[Unit, payp.mard2p.api.v0.models.Payment]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Payment]("payp.mard2p.api.v0.models.Payment", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } override def getByRefAccountid( refAccountid: Long, payid: Long, paymentMethod: String, actorid: String, operatorid: String, amount: Double, phone: Long, pin: Int, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] = { val urlPath = Seq("payments", refAccountid.toString) val queryParameters = Seq( Some("payid" -> payid.toString), Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest[Unit, payp.mard2p.api.v0.models.Payment]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Payment]("payp.mard2p.api.v0.models.Payment", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } override def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[Seq[payp.mard2p.api.v0.models.Payment]] = { val urlPath = Seq("payments", "list") val queryParameters = Seq( Some("payid" -> payid.toString), Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest[Unit, Seq[payp.mard2p.api.v0.models.Payment]]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, Seq[payp.mard2p.api.v0.models.Payment]]("Seq[payp.mard2p.api.v0.models.Payment]", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } } object Transfers extends Transfers[F] { override def postCreate( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Transfer] = { val urlPath = Seq("transfers", "create") val payload = None val formPayload = Some(org.http4s.UrlForm( "transferid" -> transferid.asJson.noSpaces, "senderid" -> senderid, "amount" -> amount.asJson.noSpaces, "currency" -> currency, "ref_accountid_receiver" -> refAccountidReceiver.asJson.noSpaces, "ref_accountid_sender" -> refAccountidSender.asJson.noSpaces )) _executeRequest[Unit, payp.mard2p.api.v0.models.Transfer]("POST", path = urlPath, body = payload, formBody = formPayload, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Transfer]("payp.mard2p.api.v0.models.Transfer", r) case r if r.status.code == 409 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 409")) } } override def putUpdateByTransferid( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Transfer] = { val urlPath = Seq("transfers", "update", transferid.toString) val payload = None val formPayload = Some(org.http4s.UrlForm( "senderid" -> senderid, "amount" -> amount.asJson.noSpaces, "currency" -> currency, "ref_accountid_receiver" -> refAccountidReceiver.asJson.noSpaces, "ref_accountid_sender" -> refAccountidSender.asJson.noSpaces )) _executeRequest[Unit, payp.mard2p.api.v0.models.Transfer]("PUT", path = urlPath, body = payload, formBody = formPayload, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Transfer]("payp.mard2p.api.v0.models.Transfer", r) case r if r.status.code == 409 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 409")) } } override def deleteDeleteByTransferid( transferid: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Unit] = { val urlPath = Seq("transfers", "delete", transferid.toString) _executeRequest[Unit, Unit]("DELETE", path = urlPath, requestHeaders = requestHeaders) { case r if r.status.code == 204 => Concurrent[F].pure(()) case r if r.status.code == 401 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 204, 401, 404")) } } override def getByTransferid( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Account] = { val urlPath = Seq("transfers", transferid.toString) val queryParameters = Seq( Some("senderid" -> senderid), Some("amount" -> amount.toString), Some("currency" -> currency), Some("ref_accountid_receiver" -> refAccountidReceiver.toString), Some("ref_accountid_sender" -> refAccountidSender.toString) ).flatten _executeRequest[Unit, payp.mard2p.api.v0.models.Account]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Account]("payp.mard2p.api.v0.models.Account", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } override def getList( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Seq[payp.mard2p.api.v0.models.Account]] = { val urlPath = Seq("transfers", "list") val queryParameters = Seq( Some("transferid" -> transferid.toString), Some("senderid" -> senderid), Some("amount" -> amount.toString), Some("currency" -> currency), Some("ref_accountid_receiver" -> refAccountidReceiver.toString), Some("ref_accountid_sender" -> refAccountidSender.toString) ).flatten _executeRequest[Unit, Seq[payp.mard2p.api.v0.models.Account]]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, Seq[payp.mard2p.api.v0.models.Account]]("Seq[payp.mard2p.api.v0.models.Account]", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } } object Validations extends Validations[F] { override def post( value: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Validation] = { val urlPath = Seq("validations") val (payload, formPayload) = (Some(value), None) _executeRequest[String, payp.mard2p.api.v0.models.Validation]("POST", path = urlPath, body = payload, formBody = formPayload, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Validation]("payp.mard2p.api.v0.models.Validation", r) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200")) } } } object Withdraws extends Withdraws[F] { override def deleteDeleteByWdwid( wdwid: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Unit] = { val urlPath = Seq("withdraws", "delete", wdwid.toString) _executeRequest[Unit, Unit]("DELETE", path = urlPath, requestHeaders = requestHeaders) { case r if r.status.code == 204 => Concurrent[F].pure(()) case r if r.status.code == 401 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 204, 401, 404")) } } override def getByWdwid( wdwid: Long, depid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] = { val urlPath = Seq("withdraws", wdwid.toString) val queryParameters = Seq( Some("depid" -> depid.toString), Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest[Unit, payp.mard2p.api.v0.models.Payment]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, payp.mard2p.api.v0.models.Payment]("payp.mard2p.api.v0.models.Payment", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } override def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[Seq[payp.mard2p.api.v0.models.Payment]] = { val urlPath = Seq("withdraws", "list") val queryParameters = Seq( Some("payid" -> payid.toString), Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest[Unit, Seq[payp.mard2p.api.v0.models.Payment]]("GET", path = urlPath, queryParameters = queryParameters, requestHeaders = requestHeaders) { case r if r.status.code == 200 => _root_.payp.mard2p.api.v0.Client.parseJson[F, Seq[payp.mard2p.api.v0.models.Payment]]("Seq[payp.mard2p.api.v0.models.Payment]", r) case r if r.status.code == 404 => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Unsupported response code[${r.status.code}]. Expected: 200, 404")) } } } private lazy val defaultApiHeaders = Seq( ("User-Agent", Constants.UserAgent), ("X-Apidoc-Version", Constants.Version), ("X-Apidoc-Version-Major", Constants.VersionMajor.toString) ) def apiHeaders: Seq[(String, String)] = defaultApiHeaders def modifyRequest(request: org.http4s.Request[F]): org.http4s.Request[F] = request implicit def circeJsonEncoder[F[_]: Concurrent, A](implicit encoder: io.circe.Encoder[A]) = org.http4s.circe.jsonEncoderOf[F, A] def _executeRequest[T, U]( method: String, path: Seq[String], queryParameters: Seq[(String, String)] = Nil, requestHeaders: Seq[(String, String)] = Nil, body: Option[T] = None, formBody : Option[org.http4s.UrlForm] = None )(handler: org.http4s.Response[F] => F[U] )(implicit encoder: io.circe.Encoder[T]): F[U] = { import org.http4s.QueryParamEncoder._ val m = org.http4s.Method.fromString(method) match { case Right(m) => m case Left(e) => sys.error(e.toString) } val headers = org.http4s.Headers(( apiHeaders ++ defaultHeaders ++ requestHeaders ).groupBy(_._1).map { case (k, l) => org.http4s.Header.Raw(org.typelevel.ci.CIString(k), l.last._2) }.toList) val queryMap = queryParameters.groupBy(_._1).map { case (k, v) => k -> v.map(_._2) } val uri = path.foldLeft(baseUrl){ case (uri, segment) => uri / segment }.setQueryParams(queryMap) val request = org.http4s.Request[F](method = m, uri = uri, headers = headers) val reqAndMaybeAuth = auth.fold(request) { case Authorization.Basic(username, passwordOpt) => { val userpass = s"$username:${passwordOpt.getOrElse("")}" val token = java.util.Base64.getEncoder.encodeToString(userpass.getBytes(java.nio.charset.StandardCharsets.ISO_8859_1)) request.putHeaders(org.http4s.Header.Raw(org.typelevel.ci.CIString("Authorization"), s"Basic $token")) } case a => sys.error("Invalid authorization scheme[" + a.getClass + "]") } val reqAndMaybeAuthAndBody = if (formBody.nonEmpty) formBody.fold(reqAndMaybeAuth)(reqAndMaybeAuth.withEntity) else body.fold(reqAndMaybeAuth)(reqAndMaybeAuth.withEntity) httpClient.fetch(modifyRequest(reqAndMaybeAuthAndBody))(handler) } } object Client { import cats.effect._ implicit def circeJsonDecoder[F[_]: Concurrent, A](implicit decoder: io.circe.Decoder[A]) = org.http4s.circe.jsonOf[F, A] def parseJson[F[_]: Concurrent, T]( className: String, r: org.http4s.Response[F] )(implicit decoder: io.circe.Decoder[T]): F[T] = r.attemptAs[T].value.flatMap { case Right(value) => Concurrent[F].pure(value) case Left(error) => Concurrent[F].raiseError(new payp.mard2p.api.v0.errors.FailedRequest(r.status.code, s"Invalid json for class[" + className + "]", None, error)) } } sealed trait Authorization extends _root_.scala.Product with _root_.scala.Serializable object Authorization { final case class Basic(username: String, password: Option[String] = None) extends Authorization } package interfaces { trait Client[F[_]] { def baseUrl: org.http4s.Uri def accounts: payp.mard2p.api.v0.Accounts[F] def deposits: payp.mard2p.api.v0.Deposits[F] def payments: payp.mard2p.api.v0.Payments[F] def transfers: payp.mard2p.api.v0.Transfers[F] def validations: payp.mard2p.api.v0.Validations[F] def withdraws: payp.mard2p.api.v0.Withdraws[F] } } trait Accounts[F[_]] { /** * Used to create an account. */ def postCreate( accountid: Long, ownerid: String, totalAmount: Double, sold: Double, debit: Double, currency: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Account] /** * Used to update an account. */ def putUpdateByAccountid( accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Account] /** * Delete some account. */ def deleteDeleteByAccountid( accountid: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Unit] /** * Find account by its id */ def getByAccountid( accountid: Long, ownerid: String, totalAmount: Double, sold: Double, debit: Double, currency: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Account] /** * Find all the accounts. */ def getList( accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double, requestHeaders: Seq[(String, String)] = Nil ): F[Seq[payp.mard2p.api.v0.models.Account]] } trait Deposits[F[_]] { /** * Delete some deposit. */ def deleteDeleteByDepid( depid: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Unit] /** * Find deposit by its id. */ def getByDepid( depid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] /** * List all the deposits */ def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[Seq[payp.mard2p.api.v0.models.Payment]] } trait Payments[F[_]] { /** * Used to create a payment. */ def postCreate( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, currency: String, phone: Long, pin: Int, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] /** * Used to update a payment. */ def putUpdateByPayid( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Int, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] /** * Delete some payment. */ def deleteDeleteByPayid( payid: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Unit] /** * Find payment by its id. */ def getByPayid( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] /** * Find payment by id accountid */ def getByRefAccountid( refAccountid: Long, payid: Long, paymentMethod: String, actorid: String, operatorid: String, amount: Double, phone: Long, pin: Int, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] /** * List all the payments */ def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[Seq[payp.mard2p.api.v0.models.Payment]] } trait Transfers[F[_]] { /** * Used to create a transfer resource. */ def postCreate( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Transfer] /** * Used to update a transfer resource. */ def putUpdateByTransferid( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Transfer] /** * Delete some transfer. */ def deleteDeleteByTransferid( transferid: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Unit] /** * Find transfer by its id */ def getByTransferid( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Account] /** * Find all the transfers. */ def getList( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Seq[payp.mard2p.api.v0.models.Account]] } trait Validations[F[_]] { def post( value: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Validation] } trait Withdraws[F[_]] { /** * Delete some withdraw. */ def deleteDeleteByWdwid( wdwid: Long, requestHeaders: Seq[(String, String)] = Nil ): F[Unit] /** * Find withdraw by its id. */ def getByWdwid( wdwid: Long, depid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[payp.mard2p.api.v0.models.Payment] /** * List all the withdraws */ def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil ): F[Seq[payp.mard2p.api.v0.models.Payment]] } package errors { final case class UnitResponse(status: Int) extends Exception(s"HTTP $status") final case class FailedRequest(responseCode: Int, message: String, requestUri: Option[_root_.java.net.URI] = None, parent: Exception = null) extends _root_.java.lang.Exception(s"HTTP $responseCode: $message", parent) } }