【问题标题】:com.paypal.core.rest.PayPalRESTException: Error code : 400com.paypal.core.rest.PayPalRESTException:错误代码:400
【发布时间】:2015-12-28 12:48:04
【问题描述】:

我正在使用 scala 实现 paypal-rest-api 调用。 我有 java 中的工作示例。

但是在 scala 中实现相同时,从 paypal 沙盒 api 得到“未知错误”。

这里是代码。

class DirectPayment {

    def pay(): Unit = {
    val payment = new Payment
    val accessToken = AccessTokenGenerator.getAccessToken()
    val apiContext = new APIContext(accessToken)
    try {      


        val amount = new Amount
        amount.setCurrency("USD")
        amount.setTotal("12")

        val transaction = new Transaction
        transaction.setDescription("creating a direct payment with credit card");
        transaction.setAmount(amount);


        val transactions = new java.util.ArrayList[Transaction]
        transactions.add(transaction)

        val creditCard = new CreditCard
        creditCard.setType("visa")
        creditCard.setNumber("xxxxxxxxxxxxxxxxx")
        creditCard.setExpireMonth(12)
        creditCard.setExpireYear(2020)
        creditCard.setCvv2("874")
        creditCard.setFirstName("xxxx")
        creditCard.setLastName("xxxxxxx")

        val billingAddress = new Address
        billingAddress.setLine1("111 First Street")
        billingAddress.setCity("Saratoga")
        billingAddress.setState("CA")
        billingAddress.setPostalCode("95070")
        billingAddress.setCountryCode("US")

        val fundingInstrument = new FundingInstrument
        fundingInstrument.setCreditCard(creditCard)

        val fundingInstrumentList = new ArrayList[FundingInstrument]()
        fundingInstrumentList.add(fundingInstrument)

        val payer = new Payer
        payer.setFundingInstruments(fundingInstrumentList)
        payer.setPaymentMethod("credit_card")   

        payment.setIntent("sale")
        payment.setPayer(payer)
        payment.setTransactions(transactions)

        val sdkConfig = new HashMap[String, String]()
        sdkConfig.put("mode", "sandbox")

        val requestId = UUID.randomUUID().toString();
        val apiContext = new APIContext(accessToken, requestId);
        apiContext.setConfigurationMap(sdkConfig)
        println("apiContext" + apiContext)
        val createdPayment = payment.create(apiContext)
        //exception occurs here          

    println(Payment.getLastResponse())

    println(String.format("created payment with id [%s] and status=[%s]", createdPayment.getId(), createdPayment.getState()))

   } catch {
 case e: PayPalRESTException => {
   println("EXCEPTION IN DO FINAL PAYMENT METHOD")
   val msg = e.getMessage
   println(e)
   println(msg)
 }   
 }

}

在 buil.sbt 中有这个

 libraryDependencies += "com.paypal.sdk" % "paypal-core" % "1.5.2"
 libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.4" % "test"
 libraryDependencies += "com.paypal.sdk" % "rest-api-sdk" % "0.7.0"

【问题讨论】:

  • 请您多解释一下发生在您身上的事情。也许如果您通过 HTTP 调用或类似的方式使用您的应用程序。
  • 谢谢@salc2。它是一个独立的 scala 代码。我找到了我错过的东西。错过添加 creditCard.setBillingAddress(billingAddress),然后将其添加到fundingInstruments。现在修好了。

标签: scala paypal-sandbox


【解决方案1】:

错过添加

    creditCard.setBillingAddress(billingAddress)

在将其添加到fundingInstruments 之前。现在修好了。

【讨论】:

    猜你喜欢
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    相关资源
    最近更新 更多