/** * 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_20 */ package payp.mard2p.api.v0.models { /** * Account is defined by the app specifically to manage users transactions. * * @param accountid Internal unique identifier for this account. * @param ownerid The username registered in the application * @param totalAmount The amount specific to the debit and sold account. This field allows the process * transactions. * @param currency The currency specific to location. * @param sold The amount specific to the balance account. This field allows the process * transactions. * @param debit The amount specific to the money merchant have to collect and pay. This field * allows the process transactions. */ final case class Account( accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double ) /** * @param accountid Internal unique identifier for this account. * @param ownerid The username registered in the application. * @param totalAmount The amount specific to the debit and sold account. This field allows the process * transactions. * @param sold The amount specific to the balance account. This field allows the process * transactions. * @param debit The amount specific to the money merchant have to collect and pay. This field * allows the process transactions. * @param currency The currency specific to location. */ final case class AccountForm( accountid: Long, ownerid: String, totalAmount: _root_.scala.Option[Double] = None, sold: Double, debit: _root_.scala.Option[Double] = None, currency: String ) /** * Deposit describes a way a payment is handled. It depends of Payment Resource * * @param depid Internal unique identifier for this account. * @param paymentid The added paymentid used to proceed the deposit transaction. */ final case class Deposit( depid: Long, paymentid: Long ) /** * Payment is defined by the app specifically to emit users transactions. * * @param payid Internal unique identifier for this payment. * @param actorid The username registered in the application * @param amount The amount to send. This field allowed the processing transactions. * @param refAccountid The accountid to use to send money to the specific account. * @param paymentMethod The type of payment to use [Mobile Money or Credit Card]. * @param operatorid The operator specified the type of payment if Mobile Money. * @param phone The phone identifying specific account of consumer. * @param pin The code used to validate the transaction. * @param currency The phone identifying specific account of consumer. * @param paymentContext This field specify the type of transaction [Buying, Deposit, Withdraw]. */ final case class Payment( payid: Long, actorid: String, amount: Double, refAccountid: Long, paymentMethod: String, operatorid: String, phone: Long, pin: Int, currency: String, paymentContext: String ) /** * @param payid Internal unique identifier for this payment. * @param actorid The username registered in the application * @param amount The amount to send. This field allowed the processing transactions. * @param refAccountid The accountid to use to send money to the specific account. * @param paymentMethod The type of payment to use [Mobile Money or Credit Card]. * @param operatorid The operator specified the type of payment if Mobile Money. * @param phone The phone identifying specific account of consumer. * @param pin The code used to validate the transaction. * @param currency The phone identifying specific account of consumer. * @param paymentContext This field specify the type of transaction [Buying, Deposit, Withdraw]. */ final case class PaymentForm( payid: Long, actorid: String, amount: Double, refAccountid: Long, paymentMethod: String, operatorid: String, phone: Long, pin: Int, currency: String, paymentContext: String ) /** * Transfer is defined by the app specifically to manage users transactions * (sending and receiving). * * @param transferid Internal unique identifier for this account. * @param senderid The username registered in the application * @param amount The amount to be send. This field allows the process transactions. * @param refAccountidReceiver The accountid to use to send money and referencing the receiver. * @param refAccountidSender The accountid to use to send money and referencing the sender. * @param currency The currency specific to a country. */ final case class Transfer( transferid: Long, senderid: String, amount: Double, refAccountidReceiver: Long, refAccountidSender: Long, currency: String ) /** * @param transferid Internal unique identifier for this account. * @param senderid The username registered in the application. * @param amount The amount to be send. This field allows the process transactions. * @param refAccountidReceiver The accountid to use to send money and referencing the receiver. * @param refAccountidSender The accountid to use to send money and referencing the sender. * @param currency The currency specific to a country. */ final case class TransferForm( transferid: Long, senderid: String, amount: Double, refAccountidReceiver: Long, refAccountidSender: Long, currency: String ) /** * Used only to validate json files - used as a resource where http status code * defines success * * @param valid If true, the json schema is valid. If false, there is at least one validation * error. * @param errors Contains any validation errors that result from parsing the json document. If * empty, the document is valid. */ final case class Validation( valid: Boolean, errors: Seq[String] = Nil ) /** * Withdraw describes a way a payment is handled. It depends of Payment Resource * * @param wdwid Internal unique identifier for this account. * @param paymentid The added paymentid used to proceed the deposit transaction. */ final case class Withdraw( wdwid: Long, paymentid: Long ) sealed trait AppSortBy extends _root_.scala.Product with _root_.scala.Serializable object AppSortBy { case object Created extends AppSortBy { override def toString = "created" } case object Edited extends AppSortBy { override def toString = "edited" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends AppSortBy /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[AppSortBy] = scala.List(Created, Edited) private val byName: Map[String, AppSortBy] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): AppSortBy = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[AppSortBy] = byName.get(value.toLowerCase) } sealed trait OriginalType extends _root_.scala.Product with _root_.scala.Serializable object OriginalType { /** * The original is in the api.json format */ case object ApiJson extends OriginalType { override def toString = "api_json" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends OriginalType /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[OriginalType] = scala.List(ApiJson) private val byName: Map[String, OriginalType] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): OriginalType = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[OriginalType] = byName.get(value.toLowerCase) } /** * A publication represents something that a user can subscribe to. An example * would be subscribing to an email alert whenever a new version of an application * is created. */ sealed trait Publication extends _root_.scala.Product with _root_.scala.Serializable object Publication { /** * For organizations for which I am an administrator, email me whenever a user * applies to join the org. */ case object MembershipRequestsCreate extends Publication { override def toString = "membership_requests.create" } /** * For organizations for which I am a member, email me whenever a user joins the * org. */ case object MembershipsCreate extends Publication { override def toString = "memberships.create" } /** * For organizations for which I am a member, email me whenever an application is * created. */ case object ApplicationsCreate extends Publication { override def toString = "applications.create" } /** * For applications that I watch, email me whenever a version is created. */ case object VersionsCreate extends Publication { override def toString = "versions.create" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends Publication /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[Publication] = scala.List(MembershipRequestsCreate, MembershipsCreate, ApplicationsCreate, VersionsCreate) private val byName: Map[String, Publication] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): Publication = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[Publication] = byName.get(value.toLowerCase) } sealed trait SortOrder extends _root_.scala.Product with _root_.scala.Serializable object SortOrder { case object Asc extends SortOrder { override def toString = "asc" } case object Desc extends SortOrder { override def toString = "desc" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends SortOrder /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[SortOrder] = scala.List(Asc, Desc) private val byName: Map[String, SortOrder] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): SortOrder = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[SortOrder] = byName.get(value.toLowerCase) } /** * Controls who is able to view this version */ sealed trait Visibility extends _root_.scala.Product with _root_.scala.Serializable object Visibility { /** * Anybody, including non logged in users, can view this application */ case object Public extends Visibility { override def toString = "public" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends Visibility /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[Visibility] = scala.List(Public) private val byName: Map[String, Visibility] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): Visibility = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[Visibility] = byName.get(value.toLowerCase) } } package payp.mard2p.api.v0.models { package object json { import io.circe.Decoder._ import io.circe.Encoder._ import scala.language.implicitConversions // See below - Make Scala 2.11 Either monadic import scala.util.Try import io.circe.{Json, JsonObject, Encoder, Decoder, DecodingFailure} import io.circe.syntax._ 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._ // Make Scala 2.11 Either monadic private[v0] implicit def eitherOps[A,B](e: Either[A,B]) = cats.implicits.catsSyntaxEither(e) private[v0] implicit val decodeUUID: Decoder[_root_.java.util.UUID] = Decoder.decodeString.emapTry(str => Try(_root_.java.util.UUID.fromString(str))) private[v0] implicit val encodeUUID: Encoder[_root_.java.util.UUID] = Encoder.encodeString.contramap[_root_.java.util.UUID](uuid => uuid.toString) private[v0] implicit val decodeInstant: Decoder[_root_.java.time.Instant] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.OffsetDateTime.parse(str).toInstant)) private[v0] implicit val encodeInstant: Encoder[_root_.java.time.Instant] = Encoder.encodeString.contramap[_root_.java.time.Instant](_.toString) private[v0] implicit val decodeLocalDate: Decoder[_root_.java.time.LocalDate] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.LocalDate.parse(str))) private[v0] implicit val encodeLocalDate: Encoder[_root_.java.time.LocalDate] = Encoder.encodeString.contramap[_root_.java.time.LocalDate](_.toString) implicit val jsonDecoderMard2pAPIAppSortBy: Decoder[payp.mard2p.api.v0.models.AppSortBy] = Decoder.decodeString.map(payp.mard2p.api.v0.models.AppSortBy(_)) implicit val jsonEncoderMard2pAPIAppSortBy: Encoder[payp.mard2p.api.v0.models.AppSortBy] = Encoder.encodeString.contramap[payp.mard2p.api.v0.models.AppSortBy](_.toString) implicit val jsonDecoderMard2pAPIOriginalType: Decoder[payp.mard2p.api.v0.models.OriginalType] = Decoder.decodeString.map(payp.mard2p.api.v0.models.OriginalType(_)) implicit val jsonEncoderMard2pAPIOriginalType: Encoder[payp.mard2p.api.v0.models.OriginalType] = Encoder.encodeString.contramap[payp.mard2p.api.v0.models.OriginalType](_.toString) implicit val jsonDecoderMard2pAPIPublication: Decoder[payp.mard2p.api.v0.models.Publication] = Decoder.decodeString.map(payp.mard2p.api.v0.models.Publication(_)) implicit val jsonEncoderMard2pAPIPublication: Encoder[payp.mard2p.api.v0.models.Publication] = Encoder.encodeString.contramap[payp.mard2p.api.v0.models.Publication](_.toString) implicit val jsonDecoderMard2pAPISortOrder: Decoder[payp.mard2p.api.v0.models.SortOrder] = Decoder.decodeString.map(payp.mard2p.api.v0.models.SortOrder(_)) implicit val jsonEncoderMard2pAPISortOrder: Encoder[payp.mard2p.api.v0.models.SortOrder] = Encoder.encodeString.contramap[payp.mard2p.api.v0.models.SortOrder](_.toString) implicit val jsonDecoderMard2pAPIVisibility: Decoder[payp.mard2p.api.v0.models.Visibility] = Decoder.decodeString.map(payp.mard2p.api.v0.models.Visibility(_)) implicit val jsonEncoderMard2pAPIVisibility: Encoder[payp.mard2p.api.v0.models.Visibility] = Encoder.encodeString.contramap[payp.mard2p.api.v0.models.Visibility](_.toString) implicit def decodeMard2pAPIAccount: Decoder[Account] = Decoder.instance { c => for { accountid <- c.downField("accountid").as[Long] ownerid <- c.downField("ownerid").as[String] totalAmount <- c.downField("total_amount").as[Double] currency <- c.downField("currency").as[String] sold <- c.downField("sold").as[Double] debit <- c.downField("debit").as[Double] } yield { Account( accountid = accountid, ownerid = ownerid, totalAmount = totalAmount, currency = currency, sold = sold, debit = debit ) } } implicit def encodeMard2pAPIAccount: Encoder[Account] = Encoder.instance { t => Json.fromFields(Seq( Some("accountid" -> t.accountid.asJson), Some("ownerid" -> t.ownerid.asJson), Some("total_amount" -> t.totalAmount.asJson), Some("currency" -> t.currency.asJson), Some("sold" -> t.sold.asJson), Some("debit" -> t.debit.asJson) ).flatten) } implicit def decodeMard2pAPIAccountForm: Decoder[AccountForm] = Decoder.instance { c => for { accountid <- c.downField("accountid").as[Long] ownerid <- c.downField("ownerid").as[String] totalAmount <- c.downField("total_amount").as[Option[Double]] sold <- c.downField("sold").as[Double] debit <- c.downField("debit").as[Option[Double]] currency <- c.downField("currency").as[String] } yield { AccountForm( accountid = accountid, ownerid = ownerid, totalAmount = totalAmount, sold = sold, debit = debit, currency = currency ) } } implicit def encodeMard2pAPIAccountForm: Encoder[AccountForm] = Encoder.instance { t => Json.fromFields(Seq( Some("accountid" -> t.accountid.asJson), Some("ownerid" -> t.ownerid.asJson), t.totalAmount.map(t => "total_amount" -> t.asJson), Some("sold" -> t.sold.asJson), t.debit.map(t => "debit" -> t.asJson), Some("currency" -> t.currency.asJson) ).flatten) } implicit def decodeMard2pAPIDeposit: Decoder[Deposit] = Decoder.instance { c => for { depid <- c.downField("depid").as[Long] paymentid <- c.downField("paymentid").as[Long] } yield { Deposit( depid = depid, paymentid = paymentid ) } } implicit def encodeMard2pAPIDeposit: Encoder[Deposit] = Encoder.instance { t => Json.fromFields(Seq( Some("depid" -> t.depid.asJson), Some("paymentid" -> t.paymentid.asJson) ).flatten) } implicit def decodeMard2pAPIPayment: Decoder[Payment] = Decoder.instance { c => for { payid <- c.downField("payid").as[Long] actorid <- c.downField("actorid").as[String] amount <- c.downField("amount").as[Double] refAccountid <- c.downField("ref_accountid").as[Long] paymentMethod <- c.downField("payment_method").as[String] operatorid <- c.downField("operatorid").as[String] phone <- c.downField("phone").as[Long] pin <- c.downField("pin").as[Int] currency <- c.downField("currency").as[String] paymentContext <- c.downField("payment_context").as[String] } yield { Payment( payid = payid, actorid = actorid, amount = amount, refAccountid = refAccountid, paymentMethod = paymentMethod, operatorid = operatorid, phone = phone, pin = pin, currency = currency, paymentContext = paymentContext ) } } implicit def encodeMard2pAPIPayment: Encoder[Payment] = Encoder.instance { t => Json.fromFields(Seq( Some("payid" -> t.payid.asJson), Some("actorid" -> t.actorid.asJson), Some("amount" -> t.amount.asJson), Some("ref_accountid" -> t.refAccountid.asJson), Some("payment_method" -> t.paymentMethod.asJson), Some("operatorid" -> t.operatorid.asJson), Some("phone" -> t.phone.asJson), Some("pin" -> t.pin.asJson), Some("currency" -> t.currency.asJson), Some("payment_context" -> t.paymentContext.asJson) ).flatten) } implicit def decodeMard2pAPIPaymentForm: Decoder[PaymentForm] = Decoder.instance { c => for { payid <- c.downField("payid").as[Long] actorid <- c.downField("actorid").as[String] amount <- c.downField("amount").as[Double] refAccountid <- c.downField("ref_accountid").as[Long] paymentMethod <- c.downField("payment_method").as[String] operatorid <- c.downField("operatorid").as[String] phone <- c.downField("phone").as[Long] pin <- c.downField("pin").as[Int] currency <- c.downField("currency").as[String] paymentContext <- c.downField("payment_context").as[String] } yield { PaymentForm( payid = payid, actorid = actorid, amount = amount, refAccountid = refAccountid, paymentMethod = paymentMethod, operatorid = operatorid, phone = phone, pin = pin, currency = currency, paymentContext = paymentContext ) } } implicit def encodeMard2pAPIPaymentForm: Encoder[PaymentForm] = Encoder.instance { t => Json.fromFields(Seq( Some("payid" -> t.payid.asJson), Some("actorid" -> t.actorid.asJson), Some("amount" -> t.amount.asJson), Some("ref_accountid" -> t.refAccountid.asJson), Some("payment_method" -> t.paymentMethod.asJson), Some("operatorid" -> t.operatorid.asJson), Some("phone" -> t.phone.asJson), Some("pin" -> t.pin.asJson), Some("currency" -> t.currency.asJson), Some("payment_context" -> t.paymentContext.asJson) ).flatten) } implicit def decodeMard2pAPITransfer: Decoder[Transfer] = Decoder.instance { c => for { transferid <- c.downField("transferid").as[Long] senderid <- c.downField("senderid").as[String] amount <- c.downField("amount").as[Double] refAccountidReceiver <- c.downField("ref_accountid_receiver").as[Long] refAccountidSender <- c.downField("ref_accountid_sender").as[Long] currency <- c.downField("currency").as[String] } yield { Transfer( transferid = transferid, senderid = senderid, amount = amount, refAccountidReceiver = refAccountidReceiver, refAccountidSender = refAccountidSender, currency = currency ) } } implicit def encodeMard2pAPITransfer: Encoder[Transfer] = Encoder.instance { t => Json.fromFields(Seq( Some("transferid" -> t.transferid.asJson), Some("senderid" -> t.senderid.asJson), Some("amount" -> t.amount.asJson), Some("ref_accountid_receiver" -> t.refAccountidReceiver.asJson), Some("ref_accountid_sender" -> t.refAccountidSender.asJson), Some("currency" -> t.currency.asJson) ).flatten) } implicit def decodeMard2pAPITransferForm: Decoder[TransferForm] = Decoder.instance { c => for { transferid <- c.downField("transferid").as[Long] senderid <- c.downField("senderid").as[String] amount <- c.downField("amount").as[Double] refAccountidReceiver <- c.downField("ref_accountid_receiver").as[Long] refAccountidSender <- c.downField("ref_accountid_sender").as[Long] currency <- c.downField("currency").as[String] } yield { TransferForm( transferid = transferid, senderid = senderid, amount = amount, refAccountidReceiver = refAccountidReceiver, refAccountidSender = refAccountidSender, currency = currency ) } } implicit def encodeMard2pAPITransferForm: Encoder[TransferForm] = Encoder.instance { t => Json.fromFields(Seq( Some("transferid" -> t.transferid.asJson), Some("senderid" -> t.senderid.asJson), Some("amount" -> t.amount.asJson), Some("ref_accountid_receiver" -> t.refAccountidReceiver.asJson), Some("ref_accountid_sender" -> t.refAccountidSender.asJson), Some("currency" -> t.currency.asJson) ).flatten) } implicit def decodeMard2pAPIValidation: Decoder[Validation] = Decoder.instance { c => for { valid <- c.downField("valid").as[Boolean] errors <- c.downField("errors").as[Seq[String]] } yield { Validation( valid = valid, errors = errors ) } } implicit def encodeMard2pAPIValidation: Encoder[Validation] = Encoder.instance { t => Json.fromFields(Seq( Some("valid" -> t.valid.asJson), Some("errors" -> t.errors.asJson) ).flatten) } implicit def decodeMard2pAPIWithdraw: Decoder[Withdraw] = Decoder.instance { c => for { wdwid <- c.downField("wdwid").as[Long] paymentid <- c.downField("paymentid").as[Long] } yield { Withdraw( wdwid = wdwid, paymentid = paymentid ) } } implicit def encodeMard2pAPIWithdraw: Encoder[Withdraw] = Encoder.instance { t => Json.fromFields(Seq( Some("wdwid" -> t.wdwid.asJson), Some("paymentid" -> t.paymentid.asJson) ).flatten) } } } 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_20" val Version = "0.0.2-dev" val VersionMajor = 0 } class Client[F[_]: Sync]( 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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].pure(()) case r if r.status.code == 401 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r if r.status.code == 404 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].pure(()) case r if r.status.code == 401 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r if r.status.code == 404 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].pure(()) case r if r.status.code == 401 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r if r.status.code == 404 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].pure(()) case r if r.status.code == 401 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r if r.status.code == 404 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[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 => Sync[F].pure(()) case r if r.status.code == 401 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r if r.status.code == 404 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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 => Sync[F].raiseError(new payp.mard2p.api.v0.errors.UnitResponse(r.status.code)) case r => Sync[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[_]: Sync, 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(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("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[_]: Sync, A](implicit decoder: io.circe.Decoder[A]) = org.http4s.circe.jsonOf[F, A] def parseJson[F[_]: Sync, T]( className: String, r: org.http4s.Response[F] )(implicit decoder: io.circe.Decoder[T]): F[T] = r.attemptAs[T].value.flatMap { case Right(value) => Sync[F].pure(value) case Left(error) => Sync[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) } }