2016-04-28 5 views
0

Ich habe Scala und Play Framework-Anwendung erstellt und damit versuche ich Stripe Payment Library zu verwenden. Aber wenn ich verwende ich wurde unter Fehlern bekommen:Stripe Zahlung Bibliothek Problem mit Scala und Play App

Compilation error

object stripe is not a member of package com

I-Versionen, wie unten verwenden,

  1. Scala Version: 2.11.6
  2. SBT Version: 0.13.8

ich habe, wie unten in build.sbt Streifen SBT Abhängigkeit verwendet,

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

Meine build.sbt wie unter Datei:

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 

Mein Controller, wo es Ausnahme gibt:

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 -

Alles sieht gut aus, aber weiß nicht, warum bin Ich bekomme dieses Kompilierproblem.

+0

Es sieht für mich so aus, dass die Bibliothek sehr veraltet ist, zuletzt im Jahr 2012 aktualisiert. Dies scheint zu sein, was Sie verwenden möchten: http://mvnrepository.com/artifact/com.stripe/stripe-java – childofsoong

+0

An erweitern Sie das, überprüfen Sie https://stripe.com/docs/libraries - sieht so aus, als würden sie keine separate Scala-Bibliothek verwalten (und ich habe keine Ahnung, warum sie das tun würden). – childofsoong

+0

@childofsoong Ich benutzte das auch, aber das gleiche Problem. Also mit Java sbt Plugin habe ich auch das gleiche Problem. – Nishan

Antwort

1

Nun, basierend auf der Fehlermeldung haben Sie Probleme mit inkompatiblen Versionen von Scala. Im Grunde, was @cchanstep Ihnen bei den Kommentaren gesagt hat. Beachten Sie, dass Scala 2.9.x nicht binärkompatibel zu Scala 2.11.x ist und Sie nur nach Problemen fragen, wenn Sie beide Versionen mischen.

Entfernen Sie die folgende Zeile Ihrer build.sbt Datei:

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

und die aktualisierte hinzufügen und gepflegte Version des von Streifen bereitgestellt Client:

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

Danach werden Sie Ihren Code neu schreiben müssen um diesen neuen Client zu verwenden. Hier ist ein Beispiel, basierend auf Stripe docs und auch Ihr Code:

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 
} 

Aber ... beachten Sie, dass dieser Code nur ein Startpunkt ist und es Probleme (es blockiert, pro Instanz).

+0

Danke @marcospereira, obige Lösung funktioniert für mich. Danke vielmals..! – Nishan

Verwandte Themen