(888) 475-FLOW(3569)

Landed Cost Scala

Landed Cost Scala
# Products in Flow are localized (duty, tax, and currency calculated) by 
# experience; usually by country. The scala code below will find the 
# best experience and localized items for Canada, in this example.

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"

 client.experiences.getItems(
 org,
 country = Some("CAN"),
 number = Some(Seq("sku-1", "sku-2"))
 ).map { items =>
 
 items.foreach { i =>
 println(i.number)
 i.local.map(_.prices).get foreach {
 case p: LocalizedItemPrice =>
 println(s" - Price: ${p.label}")
 
 case p: LocalizedItemVat =>
 println(s" - ${p.name}: ${p.label}")
 
 case p: LocalizedItemDuty =>
 println(s" - Duty: ${p.label}")
 
 case p: LocalizedTotal =>
 println(s" - Total: ${p.label}")
 
 case LocalizedPriceUndefinedType(_) =>
 // Placeholder for future types
 }
 }
 
 client.closeAsyncHttpClient()
 
 }

}