2016-04-28 1 views
0

Я создал приложение Scala и Play Framework, и с ним я пытаюсь использовать библиотеку платежей Stripe. Но когда я использую я получаю ниже ошибки:Проблема с библиотекой платформ в Scala и Play

Compilation error

object stripe is not a member of package com

Я использую версии, как показано ниже,

  1. Scala Версия: 2.11.6
  2. SBT Версия: 0.13.8

Я использовал зависимость Stripe SBT в build.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 -

Все выглядит хорошо, но не знаю, почему я Я получаю эту проблему компиляции.

+0

Мне кажется, что эта библиотека очень устарела, последняя обновляется в 2012 году. Кажется, это то, что вы хотели бы использовать: http://mvnrepository.com/artifact/com.stripe/stripe-java – childofsoong

+0

To Расширьте это, посмотрите https://stripe.com/docs/libraries - похоже, что они не поддерживают отдельную библиотеку scala (и я понятия не имею, почему они будут). – childofsoong

+0

@childofsoong Я тоже использовал это, но имел ту же проблему. Так что с java sbt plugin у меня тоже такая же проблема. – Nishan

ответ

1

Ну, на основании сообщения об ошибке у вас возникли проблемы с несовместимыми версиями Scala. В основном то, что @cchantep рассказывал вам в комментариях. Имейте в виду, что Scala 2.9.x не является бинарным, совместимым с Scala 2.11.x, и вы просто задаете проблемы при смешивании обеих версий.

Удалить следующую строку файла build.sbt:

"com.stripe" % "stripe-scala_2.9.1" % "1.1.2" 

И добавить обновленный и поддерживается версию клиента, предоставленной Stripe:

"com.stripe" % "stripe-java" % "2.4.0" 

После этого, вам нужно переписать код для использования этого нового клиента. Вот пример, основанный на Stripe docs, а также код:

def getPayment = Action { request => 
    val requestOptions = new RequestOptionsBuilder() 
    .setApiKey("sk_test_xxxxxxxxxxxxx") 
    .build() 

    val formData = (request.body).asFormUrlEncoded 
    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, requestOptions); 

    Ok 
} 

Но ... имейте в виду, что этот код является только начальной точкой и есть проблемы (он блокирует, каждый экземпляр).

+0

Спасибо @marcospereira, над решением работает для меня. Большое спасибо..! – Nishan

Смежные вопросы