【问题标题】:Is there pagination for transaction search?交易搜索有分页吗?
【发布时间】:2017-05-05 18:04:11
【问题描述】:

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

ShortMessage:搜索警告

LongMessage:结果数被截断。如果您想查看所有结果,请更改您的搜索参数。

错误代码:11002

严重性代码:警告

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

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

【问题讨论】:

    标签: soap paypal pagination paypal-soap


    【解决方案1】:

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

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-19
      • 2017-03-17
      • 2013-09-11
      • 1970-01-01
      • 2012-05-11
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多