com.paypal.core.rest.PayPalRESTException:错误代码:400 [英] com.paypal.core.rest.PayPalRESTException: Error code : 400

查看:119
本文介绍了com.paypal.core.rest.PayPalRESTException:错误代码:400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Am implementing the paypal-rest-api call using scala. Am having the working example in java.

但是在 Scala 中实现相同的内容时,从 paypal 沙箱 api 中得到未知错误".

But getting "Unknown error" from paypal sandbox api, when implementing the same in scala.

这是代码.

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 中有这个

having this in 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"

推荐答案

错过添加

    creditCard.setBillingAddress(billingAddress)

在将其添加到fundingInstruments 之前.现已修复.

before adding it to the fundingInstruments. Got fixed now.

这篇关于com.paypal.core.rest.PayPalRESTException:错误代码:400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆