java - 恒星支付查询

标签 java paypal

我无法在官网执行示例支付查询程序。这是我的代码,几乎与示例相同。这是 official website .

public class TransCheck {
  public static void main(String args[]) {
    Server server = new Server("https://horizon-testnet.stellar.org");
    KeyPair account = KeyPair.fromAccountId("GARUMRUP37CPOGQQALSXBDQQS6SUDDPKGLGFERH6PIJEHWQY5IAVZQDL");

    // Create an API call to query payments involving the account.
    // server.payments() Returns PaymentsRequestBuilder instance.
    // forAccount() Builds request to GET /accounts/{account}/payments - Account for which to get payments
    PaymentsRequestBuilder paymentsRequest = server.payments().forAccount(account);

    // If some payments have already been handled, start the results from the
    // last seen payment. (See below in `handlePayment` where it gets saved.)
    String lastToken = loadLastPagingToken();
    if (lastToken != null) {
      paymentsRequest.cursor(lastToken);
    }

    // `stream` will send each recorded payment, one by one, then keep the
    // connection open and continue to send you new payments as they occur.

    paymentsRequest.stream(new EventListener <OperationResponse>(){
      @Override
      public void onEvent(OperationResponse payment) {
        // Record the paging token so we can start from here next time.
        savePagingToken(payment.getPagingToken());

        // The payments stream includes both sent and received payments. We only
        // want to process received payments here.
        if (payment instanceof PaymentOperationResponse) {
          if (((PaymentOperationResponse) payment).getTo().equals(account)) {
            return;
          }

          String amount = ((PaymentOperationResponse) payment).getAmount();

          Asset asset = ((PaymentOperationResponse) payment).getAsset();
          String assetName;
          if (asset.equals(new AssetTypeNative())) {
            assetName = "lumens";
          } else {
            StringBuilder assetNameBuilder = new StringBuilder();
            assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getCode());
            assetNameBuilder.append(":");
            assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getIssuer().getAccountId());
            assetName = assetNameBuilder.toString();
          }

          StringBuilder output = new StringBuilder();
          output.append(amount);
          output.append(" ");
          output.append(assetName);
          output.append(" from ");
          output.append(((PaymentOperationResponse) payment).getFrom().getAccountId());
          System.out.println(output.toString());
        }
      }
    }); 
  }
}

我的代码中有两个错误。一、方法:loadLastPagingToken()未定义,我找不到此方法的详细信息。其次,当我想创建一个 new EventListener <OperationResponse>() IDE告诉了

The type EventListener is not generic; it cannot be parameterized with arguments

我真的不知道为什么。请你帮助我好吗?谢谢。

最佳答案

这是因为您的导入语句。

尝试

导入 org.stellar.sdk.requests.EventListener;

代替

导入java.util.EventListener;

关于java - 恒星支付查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41788073/

相关文章:

java - ExceptionReport.tml 中的 Tapestry 5.4 异常

java - 使用Aspectj查找实现某个接口(interface)的类列表

ruby-on-rails-3 - 如何在 (ruby on rails) 应用程序中使用 paypal-recurring gem 在 paypal 中请求退款

php - PayPal IPN 错误请求 400 错误

php - 订阅后使用 IPN 获取 PROFILEID

java - 如何将两个参数传递给命令行?

java - Z3 Java : simplify a distributive expression

php - 创建方法中的 Paypal 验证错误

php - PayPal PHP API,信用卡和借记卡的处理方式相同吗?

java - java中正则表达式的神奇日期