PAYPAL api调用adaptiveAccountsService获取“MissingCredentialException”的createAccount

时间:2015-04-08 20:22:05

标签: java paypal

我正在尝试从Java类中调用Paypal API中的adaptiveAadountsService的createAccount方法来创建帐户。

我的代码如下。

RequestEnvelope env = new RequestEnvelope();
        env.setErrorLanguage("en_US");
        NameType name = new NameType();
        AddressType address = new AddressType();
        String preferredLanguageCode ="en_US";

        CreateAccountRequest createAccountRequest = new CreateAccountRequest();

        createAccountRequest.setAccountType("PERSONAL");
        createAccountRequest.setEmailAddress("testing-account@paypal.com");

        name.setFirstName("John");
        name.setLastName("Smith");
        createAccountRequest.setName(name);

        address.setLine1("1968 Ape Way");
        address.setLine2("Apt 123");
        address.setCity("Austin");
        address.setState("TX");
        address.setCountryCode("US");
        address.setPostalCode("78750"); 
        createAccountRequest.setAddress(address);

        createAccountRequest.setContactPhoneNumber("888-555-1212");
        createAccountRequest.setCurrencyCode("USD");
        createAccountRequest.setCitizenshipCountryCode("US");
        createAccountRequest.setPreferredLanguageCode("en_US");

        createAccountRequest.setRegistrationType("WEB");

        Map<String, String> paypalConfig = new HashMap<String, String>();
        paypalConfig.put("mode", "sandbox");
        paypalConfig.put("connectionTimeout", "30000");
        paypalConfig.put("requestRetries", "5");
        paypalConfig.put("IPAddress", "127.0.0.1"); 
        paypalConfig.put("account1.apiUsername", "john-facilitator_api1.gmail.com");
        paypalConfig.put("account1.apiPassword", "RQGOB80BU4XMA8");
        paypalConfig.put("account1.apiSignature", "Signature here");
        paypalConfig.put("applicationId", "APP-80W284485P519543T");


        AdaptiveAccountsService adaptiveAccountsService = new AdaptiveAccountsService(paypalConfig);
        CreateAccountResponse createAccountResponse = adaptiveAccountsService.createAccount(createAccountRequest);

当我运行上面的代码时,得到以下异常。

  

“线程中的异常”主“   com.paypal.exception.MissingCredentialException:没有API帐户   已在应用程序属性中配置“

任何建议都将不胜感激。

谢谢,

1 个答案:

答案 0 :(得分:0)

我有同样的错误,但与群发支付功能相关联。如果您查看MissingCredentialException's implementation,您会看到(作为评论)MissingCredentialException is throw when the credential used are wrongly configured or not found in the application properties
在我的情况下,我丢失了一些属性(clientIdclientSecret)并将它们添加到sdk_config.properties解决了我的问题。如果它有帮助,我已经添加了大量支付功能:

  • acct1.UserName
  • acct1.Password
  • acct1.Signature
  • acct1.AppId
  • acct1.Subject

您应该检查sdk_config.properties文件。希望它有所帮助。