2016-12-20 5 views
0

私はペイパルSOAP APIを使用してTransactionSearchReqメソッドを実行しようとしていると私は次の警告を得る:トランザクション検索のページ番号はありますか?

のShortMessage:検索警告

longmessageは:結果の数が切り捨てられたし。すべての結果を表示したい場合は、検索パラメータを変更してください。

のErrorCode:11002

SeverityCode:警告それはまた、「TransactionSearchのAPI呼び出しから返すことができるトランザクションの最大数は100です」というドキュメントで述べている

https://developer.paypal.com/docs/classic/api/merchant/TransactionSearch_API_Operation_SOAP/

結果を改ページする方法はありますか?複数のクエリから100を超える結果を得ることができますか?

答えて

0

これは、Railsでこれを行う方法の1つです。これは、特定の時点から現在まで検索したいと仮定していますが、end_dateを変更して終了日を指定することができます。私が'paypal-sdk-merchant'の宝石を私の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