I use Scala in my project and want to integrate with Stripe, but it provides only Java API. For example, to create session I use:
val params = new util.HashMap[String, AnyRef]
val paymentMethodTypes = new util.ArrayList[String]
paymentMethodTypes.add("card")
params.put("payment_method_types", paymentMethodTypes)
params.put("mode", "setup")
params.put("success_url", "https://test.app/success")
params.put("cancel_url", "https://test.app/cancel")
val session = Session.create(params)
This code works perfectly, but it's very ugly and contains a lot of boilerplate. I'd like to use a Scala Map[String, AnyRef] and create session as follows:
import scala.collection.JavaConverters._
val params2: Map[String, AnyRef] = Map(
"payment_method_types" -> List("card"),
"mode" -> "setup",
"success_url" -> "https://test.app/success",
"cancel_url" -> "https://test.app/cancel"
)
val session2 = Session.create(mapAsJavaMap[String, AnyRef](params2))
It turns out that mapAsJavaMap can't convert nested objects in the Map. Is there a way to convert arbitrary Scala Map with other Maps and Lists inside to their Java equivalents?