(888) 475-FLOW(3569)

Payments Scala

Payments Scala
# Add a card
import io.flow.v0.{Authorization, Client}
import io.flow.v0.models._

object Main extends App {

 import scala.concurrent.ExecutionContext.Implicits.global

 val client = new Client(auth = Some(Authorization.Basic("HlGgfflLamiTQJ")))
 val org = "playground"

 import scala.concurrent.Future
 
 for {
 card <- client.cards.post(
 org,
 CardForm(
 number = Some("4012888888881881"),
 name = "Joe Smith",
 expirationMonth = 1,
 expirationYear = 2020,
 cvv = "737"
 )
 ).recoverWith {
 case ex => Future.successful {
 client.closeAsyncHttpClient()
 println(s"ERROR: ${ex}")
 throw ex
 }
 }
 
 auth <- client.authorizations.post(
 org,
 MerchantOfRecordAuthorizationForm(
 orderNumber = "R726941",
 token = card.token
 )
 ).recoverWith {
 case ex => Future.successful {
 client.closeAsyncHttpClient()
 println(s"ERROR: ${ex}")
 throw ex
 }
 }
 
 capture <- client.captures.post(
 org,
 CaptureForm(
 authorizationId = auth.id
 )
 ).recoverWith {
 case ex => Future.successful {
 client.closeAsyncHttpClient()
 println(s"ERROR: ${ex}")
 throw ex
 }
 }
 
 } yield {
 println(s"Card created - secure token is ${card.token}")
 println(s"Authorization created for ${auth.amount} ${auth.currency} [id ${auth.id}]")
 println(s"Capture created for ${capture.amount} ${capture.currency} [id ${capture.id}]")
 
 client.closeAsyncHttpClient()
 }

}