Reputation: 1
I am trying to execute the TransactionSearchReq method using the PayPal SOAP API and i get the following warning:
ShortMessage: Search warning
LongMessage: The number of results were truncated. Please change your search parameters if you wish to see all your results.
ErrorCode: 11002
SeverityCode: Warning
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/)
Is there some way to paginate results so that I can get more than 100 results from multiple queries?
Upvotes: 0
Views: 503
Reputation: 78
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.
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
Upvotes: 0