<?php

// # Search Invoices Sample
// This sample code demonstrate how you can
// search invoices from history.
/** @var Invoice $invoice */
$invoice = (require 'CreateInvoice.php');
use PayPal\Api\Invoice;
use PayPal\Api\Search;
try {
    // ### Search Object
    // Fill up your search criteria for Invoice search.
    // Using the new way to inject raw json string to constructor
    $search = new Search('{
          "start_invoice_date" : "2010-05-10 PST",
          "end_invoice_date" : "2019-05-11 PST",
          "page" : 1,
          "page_size" : 20,
          "total_count_required" : true
        }');
    // ### Search Invoices
    // Retrieve the Invoice History object by calling the
    // static `search` method on the Invoice class.
    // Refer the method doc for valid values for keys
    // (See bootstrap.php for more on `ApiContext`)
    $invoices = Invoice::search($search, $apiContext);
} catch (Exception $ex) {
    ResultPrinter::printError("Search Invoice", "Invoice", null, null, $ex);
    exit(1);
}
ResultPrinter::printResult("Search Invoice", "Invoice", null, $search, $invoices);
 /**
  * @depends testSend
  * @param $invoice Invoice
  * @return Invoice
  */
 public function testSearch($invoice)
 {
     $request = $this->operation['request']['body'];
     $search = new Search($request);
     $result = Invoice::search($search, null, $this->mockPayPalRestCall);
     $this->assertNotNull($result);
     $this->assertNotNull($result->getTotalCount());
 }
 /**
  * @dataProvider mockProvider
  * @param Invoice $obj
  */
 public function testSearch($obj, $mockApiContext)
 {
     $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(InvoiceSearchResponseTest::getJson()));
     $search = SearchTest::getObject();
     $result = $obj->search($search, $mockApiContext, $mockPayPalRestCall);
     $this->assertNotNull($result);
 }
Example #4
0
use Paypal\Api\Transaction;
use PayPal\Api\Item;
use PayPal\Transport\PPRestCall;
use PayPal\Api\InvoiceItem;
use PayPal\Api\Sale;
$searchParam = new Search();
$searchParam->status = array("PAID");
$searchParam->start_payment_date = $start . " PDT";
$searchParam->end_payment_date = $end . " PDT";
//Creating an invoice object to perform a search call
$invoiceSearch = new Invoice();
//Creates a new PayPal object for all paypal calls
$paypal = new Paypal($start, $end);
/*Calls to the classicp paypal api using the downloaded invoices sdk.*/
try {
    $invoices = $invoiceSearch->search($searchParam, $apiContext);
} catch (exception $e) {
    print "cannot do invoice search";
    print $e;
}
$invoiceIDs = array();
//This is some invoice information, but doesn't include transaction or item list
try {
    $All_Invoices = $invoices->getInvoices();
} catch (exception $e) {
    print "cannot do get invoices";
    print $e;
}
foreach ($All_Invoices as $invoice) {
    $invoiceIDs[] = $invoice->getId();
}