【发布时间】:2016-08-23 18:48:59
【问题描述】:
我已经创建了 Scala 和 Play Framework 应用程序,并且我正在尝试使用 Stripe Payment Library。但是当我使用时,我遇到了以下错误:
编译错误
对象条带不是包 com 的成员
我正在使用以下版本,
- Scala 版本:2.11.6
- SBT 版本:0.13.8
我在build.sbt 中使用了 Stripe SBT 依赖,如下所示,
"com.stripe" % "stripe-scala_2.9.1" % "1.1.2"
我的build.sbt文件如下:
name := """My App Name"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
cache,
ws,
filters,
"com.typesafe.play" %% "play-mailer" % "3.0.1",
"com.typesafe.play" %% "play-slick" % "1.1.1",
"com.typesafe.play" %% "play-slick-evolutions" % "1.1.1",
"postgresql" % "postgresql" % "9.1-901.jdbc4",
"commons-lang" % "commons-lang" % "2.6",
"com.stripe" % "stripe-scala_2.9.1" % "1.1.2"
)
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
我的控制器出现异常:
package controllers
import com.stripe
import com.stripe.{Charge, Customer}
import play.api.mvc._
/**
* Created by Nishan Patel on 28-04-2016.
*/
class PaymentController extends Controller {
def getPayment = Action { request =>
val formData = (request.body).asFormUrlEncoded
val stripe.apiKey = "sk_test_xxxxxxxxxxxxx";
val token = formData.get("stripeToken")(0)
val customerParams = Map("source" -> token, "description" -> "Customer Rollback Renew req.")
val customer = Customer.create(customerParams)
val chargeParams = Map("amount" -> 2000, "currency" -> "usd", "customer" -> customer.id)
Charge.create(chargeParams);
Ok
}
}
[error] missing or invalid dependency detected while loading class file 'package
.class'.
[error] Could not access type ScalaObject in package scala,
[error] because it (or its dependencies) are missing. Check your build definitio
n for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to s
ee the problematic classpath.)
[error] A full rebuild may help if 'package.class' was compiled against an incom
patible version of scala.
[error] missing or invalid dependency detected while loading class file 'APIReso
urce.class'.
[error] Could not access type ScalaObject in package scala,
[error] because it (or its dependencies) are missing. Check your build definitio
n for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to s
ee the problematic classpath.)
[error] A full rebuild may help if 'APIResource.class' was compiled against an i
ncompatible version of scala.
[error] missing or invalid dependency detected while loading class file 'Custome
r.class'.
[error] Could not access type ScalaObject in package scala,
[error] because it (or its dependencies) are missing. Check your build definitio
n for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to s
ee the problematic classpath.)
[error] A full rebuild may help if 'Customer.class' was compiled against an inco
mpatible version of scala.
[error] missing or invalid dependency detected while loading class file 'Charge.
class'.
[error] Could not access type ScalaObject in package scala,
[error] because it (or its dependencies) are missing. Check your build definitio
n for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to s
ee the problematic classpath.)
[error] A full rebuild may help if 'Charge.class' was compiled against an incomp
atible version of scala.
[error] E:\Nishan\Confidential\My Workspace\MetaForce\app\controllers\PaymentCon
troller.scala:14: stable identifier required, but com.stripe.`package`.apiKey fo
und.
[error] val stripe.apiKey = "sk_test_xxxxxx";
[error] ^
[error] 5 errors found
[error] (compile:compileIncremental) Compilation failed
[error] application -
一切看起来都不错,但不知道为什么会出现这个编译问题。
【问题讨论】:
-
在我看来那个库已经过时了,最后一次更新是在 2012 年。这似乎是你想要使用的:mvnrepository.com/artifact/com.stripe/stripe-java
-
要对此进行扩展,请查看 stripe.com/docs/libraries - 看起来他们没有维护单独的 scala 库(我不知道他们为什么会这样做)。
-
@childofsoong 我也用过,但遇到了同样的问题。所以使用 java sbt 插件我也有同样的问题。
-
好吧,我建议发布一个关于该问题的问题,因为这是他们的网站列出的问题,实际上今年已更新,而不是四年前。这可能是语法错误。另外,我刚刚意识到 scala 在那个页面上,但它是一个“社区支持的库”(它的 github 存储库也同样过时)
-
除了@childofsoong 所说的之外,您应该能够通过将
libraryDependencies += "com.stripe" % "stripe-java" % "2.3.0"添加到您的build.sbt来包含Stripe 的Java API,然后从那里开始。
标签: scala sbt stripe-payments playframework-2.3