Search code examples
phppaypalpaypal-ipnpaypal-rest-sdk

Searching Paypal Transactions from classic (IPN endpoint) with new REST API app


I've been using PayPal's IPN to handle transactions. I wanted to build a invoice search tool to be able to search through older or current user payments for various reasons. I spent some time today setting up the PayPal PHP REST API SDK to facilitate this and did the following.

  • I created a new app on developer.paypal.com using my current account.
  • I installed the latest (1.6.3) PayPal PHP REST SDK via composer.
  • I configured the sdk_config.ini with my LIVE client id and secret.
  • I set the ini file's mode from sandbox to LIVE.
  • I create an OAuthTokenCredential using my LIVE client id and secret.
  • I generate an AccessToken via the OAuthTokenCredential object, which requires an instance of the config .

    $config = PayPal\Core\PayPalConfigManager::getInstance()->getConfigHashmap();
    $oauth_credential->getAccessToken($config);
    
  • I create an ApiContext using the primed OAuthTokenCredential.

    $api_context = new PayPal\Rest\ApiContext($oauth_credential);
    
  • I create a search object using a broad date span that I'm 100% sure should return results.

    $search = new PayPal\Api\Search(
       '{
          "start_invoice_date" : "2014-12-01 PST",
          "end_invoice_date" : "2015-01-01 PST",
          "page" : 1,
          "page_size" : 20,
          "total_count_required" : true
       }'
    );
    
  • I then do an invoice search utilizing both my search object and API context

    $invoices = PayPal\Api\Invoice::search($search, $api_context);
    

There are no errors and everything runs fine. The issue is that I get no results back in the $invoices object. It acts as if I just created a new account and have no invoices. I get the feeling I'm missing a setting somewhere, Used an inappropriate API call for what I want to do, or that I should be using one of their other APIs .


Solution

  • Usually the classic and REST architecture in PayPal works independently and cannot be always used together. For instance, you cannot use REST API to search for a transaction ran using Classic API and vice versa.