[英]Is there pagination for transaction search?
我正在嘗試使用PayPal SOAP API執行TransactionSearchReq方法,並且收到以下警告:
短信:搜索警告
LongMessage:結果數被截斷。 如果希望查看所有結果,請更改搜索參數。
錯誤代碼:11002
嚴重性代碼:警告
它還在文檔中說:“可以從TransactionSearch API調用返回的最大事務數為100。” ( https://developer.paypal.com/docs/classic/api/merchant/TransactionSearch_API_Operation_SOAP/ )
有什么方法可以分頁結果,以便從多個查詢中獲得100多個結果?
這是您可以在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.