getAll() public static method

Lists some or all merchant invoices. Filters the response by any specified optional query string parameters.
public static getAll ( array $params = [], ApiContext $apiContext = null, PayPalRestCall $restCall = null ) : PayPal\Api\InvoiceSearchResponse
$params array
$apiContext PayPal\Rest\ApiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
$restCall PayPal\Transport\PayPalRestCall is the Rest Call Service that is used to make rest calls
return PayPal\Api\InvoiceSearchResponse
 /**
  * @dataProvider mockProvider
  * @param Invoice $obj
  */
 public function testGetAll($obj, $mockApiContext)
 {
     $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(InvoiceSearchResponseTest::getJson()));
     $result = $obj->getAll(array(), $mockApiContext, $mockPayPalRestCall);
     $this->assertNotNull($result);
 }
Beispiel #2
0
<?php

// # List Invoices Sample
// This sample code demonstrate how you can get
// all invoice from history.
/** @var Invoice $invoice */
$invoice = (require 'CreateInvoice.php');
use PayPal\Api\Invoice;
try {
    // ### Retrieve Invoices
    // Retrieve the Invoice History object by calling the
    // static `get_all` method on the Invoice class.
    // Refer the method doc for valid values for keys
    // (See bootstrap.php for more on `ApiContext`)
    $invoices = Invoice::getAll(array('page' => 0, 'page_size' => 4, 'total_count_required' => "true"), $apiContext);
} catch (Exception $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("Lookup Invoice History", "Invoice", null, null, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Lookup Invoice History", "Invoice", null, null, $invoices);
 /**
  * @depends testSend
  * @param $invoice Invoice
  * @return Invoice
  */
 public function testGetAll($invoice)
 {
     $result = Invoice::getAll(array('page_size' => '20', 'total_count_required' => 'true'), null, $this->mockPayPalRestCall);
     $this->assertNotNull($result);
     $this->assertNotNull($result->getTotalCount());
     $totalPages = ceil($result->getTotalCount() / 20);
     $found = false;
     $foundObject = null;
     do {
         foreach ($result->getInvoices() as $obj) {
             if ($obj->getId() == $invoice->getId()) {
                 $found = true;
                 $foundObject = $obj;
                 break;
             }
         }
         if (!$found) {
             $result = Invoice::getAll(array('page' => --$totalPages, 'page_size' => '20', 'total_required' => 'yes'), null, $this->mockPayPalRestCall);
         }
     } while ($totalPages > 0 && $found == false);
     $this->assertTrue($found, "The Created Invoice was not found in the get list");
     $this->assertEquals($invoice->getId(), $foundObject->getId());
 }