调用 PayPal DO_DIRECT_PAYMENT 时出现问题:com.paypal.sdk.exceptions.FatalException:无法完成 HTTPS 交易
Posted
技术标签:
【中文标题】调用 PayPal DO_DIRECT_PAYMENT 时出现问题:com.paypal.sdk.exceptions.FatalException:无法完成 HTTPS 交易【英文标题】:Problem with calling PayPal DO_DIRECT_PAYMENT: com.paypal.sdk.exceptions.FatalException: Unable to complete HTTPS transaction 【发布时间】:2021-12-18 14:46:45 【问题描述】:我正在将DO_DIRECT_PAYMENT
集成到Java 应用程序中。我在项目 pom.xml 文件中有以下 maven 依赖项。
<!-- PayPal SDK Dependencies -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.paypal.sdk</groupId>
<artifactId>paypal-base</artifactId>
<version>1.1.0</version>
</dependency>
我正在尝试创建一个成功运行的简单集成测试。
下面是测试客户端类:
public class PaypalServiceTest
@Test
public void shouldDoASuccessfullDirectPayment() throws PayPalException
//execute
PaypalService paypalService = new PaypalService();
//verify
paypalService.doDirectPayment();
下面是 SUT(被测类):
public class PaypalService
public void doDirectPayment() throws PayPalException
NVPEncoder encoder = new NVPEncoder();
encoder.add("VERSION","72.0");
encoder.add("METHOD", "DoDirectPayment");
encoder.add("PAYMENTACTION", "SALE");
encoder.add("AMT", "20.0"); // value: 20.00
encoder.add("CREDITCARDTYPE",creditCardType); // value: type of credit card(Amex| MasterCard etc...)
encoder.add("ACCT", creditCardNumber); // value: test credit card no
encoder.add("CVV2", cvv2Number); // value: test cvv2, 4 digit for amex, three digit for master card
encoder.add("EXPDATE", "11/2023");
encoder.add("FIRSTNAME", "Test1");
encoder.add("LASTNAME", "Test2");
encoder.add("ADDRESS1", "Test Address);
encoder.add("CITY","Test City);
encoder.add("STATE","USA");
encoder.add("ZIP",""02110");
encoder.add( "COUNTRYCODE", "USA");
encoder.add( "CURRENCYCODE", "USD");
encoder.add( "IPADDRESS" , ipAddress); //my IP address
encoder.add( "EMAIL", email);// value: empty
String request = encoder.encode();
APIProfile profile = ProfileFactory.createSignatureAPIProfile();
profile.setAPIUsername(API_USERNAME); // value: useraneme
profile.setAPIPassword(API_PASSWORD); // value: password
profile.setSignature(API_SIGNATURE); // value: signature
profile.setEnvironment(API_ENVIRONMENT); // value: Sandbox
NVPCallerServices caller = new NVPCallerServices();
caller.setAPIProfile(profile);
String response = caller.call(request);
当我运行测试时,出现以下错误:
com.paypal.sdk.exceptions.FatalException: Unable to complete HTTPS transaction
at com.paypal.sdk.core.nvp.NVPAPICaller.call(NVPAPICaller.java:372)
at com.paypal.sdk.services.NVPCallerServices.call(NVPCallerServices.java:56)
at io.dexi.paypal.PaypalService.doDirectPayment(PaypalService.java:73)
at io.dexi.paypal.PaypalServiceTest.shouldDoASuccessfullDirectPayment(PaypalServiceTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: com.paypal.sdk.exceptions.FatalException: HTTP Error code 400 received, transaction not submitted
at com.paypal.sdk.core.nvp.NVPAPICaller.call(NVPAPICaller.java:355)
... 25 more
我将不胜感激任何帮助或指导解决此问题。
问候, 兰多。
【问题讨论】:
【参考方案1】:我在这个问题上浪费了几个小时。正如我所想,问题在于我发送给 Paypal 的请求参数有误。
我通过修改 EXPDATE 的格式来解决这个问题,如下所示:
// encoder.add("EXPDATE", "11/2023");
encoder.add("EXPDATE", "112023");
【讨论】:
以上是关于调用 PayPal DO_DIRECT_PAYMENT 时出现问题:com.paypal.sdk.exceptions.FatalException:无法完成 HTTPS 交易的主要内容,如果未能解决你的问题,请参考以下文章
在 Sandbox 中使用 PayPal .NET SDK 验证 PayPal Webhook 调用
如何从 Omnipay/PayPal 调用 GetExpressCheckoutDetails?