是否有分页进行交易搜索? [英] Is there pagination for transaction search?

查看:75
本文介绍了是否有分页进行交易搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PayPal SOAP API执行TransactionSearchReq方法,并且收到以下警告:

I am trying to execute the TransactionSearchReq method using the PayPal SOAP API and i get the following warning:

ShortMessage:搜索警告

ShortMessage: Search warning

LongMessage:结果数被截断.如果希望查看所有结果,请更改搜索参数.

LongMessage: The number of results were truncated. Please change your search parameters if you wish to see all your results.

ErrorCode:11002

ErrorCode: 11002

严重性代码:警告

它在文档中还说:可以从TransactionSearch API调用返回的最大事务数为100." ( https://developer.paypal.com/docs/classic/api/商人/TransactionSearch_API_Operation_SOAP/)

It also says in the docs that "The maximum number of transactions that can be returned from a TransactionSearch API call is 100." (https://developer.paypal.com/docs/classic/api/merchant/TransactionSearch_API_Operation_SOAP/)

是否有一些方法可以对结果进行分页,以便从多个查询中获得100多个结果?

Is there some way to paginate results so that I can get more than 100 results from multiple queries?

推荐答案

这是在Rails中实现它的一种方法.假定您要从现在的特定时间点开始搜索,但是可以更改end_date以指定结束日期.请注意,我已经将'paypal-sdk-merchant' gem添加到我的gemfile中(请参见 https://github. com/paypal/merchant-sdk-ruby ),并按照说明进行设置.

Here's one way you can do it in Rails. This assumes you want to search from a specific point in time until now, but you could change the end_date to specify an end date. Note that I've added the 'paypal-sdk-merchant' gem to my gemfile (see https://github.com/paypal/merchant-sdk-ruby) and followed the instructions to setup my authentication.

您要在下面编辑的两件事是start_date方法(用于设置您自己的开始日期)和do_something(x)方法,这将是您要对日期内的每个单个订单执行的操作范围.

The two things you'll want to edit below are the start_date method (to set your own start date) and the do_something(x) method which will be whatever you want to do to each of the individual orders within your date range.

module PaypalTxnSearch
  def check_for_updated_orders
    begin
      @paypal_order_list = get_paypal_orders_in_range(start_date, end_date)

      @paypal_order_list.PaymentTransactions.each do |x|
        # This is where you can call a method to process each transaction
        do_something(x)
      end
      # TransactionSearch returns up to 100 of the most recent items.
    end while txn_search_result_needs_pagination?
  end

  def get_paypal_orders_in_range(start_date, end_date)
    @api = PayPal::SDK::Merchant::API.new
    # Build Transaction Search request object
    # https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/TransactionSearch_API_Operation_NVP/
    @transaction_search = @api.build_transaction_search(
      StartDate: start_date,
      EndDate: end_date
    )
    # Make API call & get response
    @response = @api.transaction_search(@transaction_search)
    # Access Response
    return_response_or_errors(@response)
  end

  def start_date
    # In this example we look back 6 months, but you can change it 
    Date.today.advance(months: -6)
  end

  def end_date
    if defined?(@paypal_order_list)
      @paypal_order_list.PaymentTransactions.last.Timestamp
    else
      DateTime.now
    end
  end

  def txn_search_result_needs_pagination?
    @@paypal_order_list.Ack == 'SuccessWithWarning' &&
      @@paypal_order_list.Errors.count == 1 &&
      @@paypal_order_list.Errors[0].ErrorCode == '11002'
  end

  def return_response_or_errors(response)
    if response.success?
      response
    else
      response.Errors
    end
  end
end

这篇关于是否有分页进行交易搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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