PayPal\Api\Invoice::cancel PHP Method

cancel() public method

Cancels an invoice, by ID.
public cancel ( CancelNotification $cancelNotification, ApiContext $apiContext = null, PayPalRestCall $restCall = null ) : boolean
$cancelNotification CancelNotification
$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 boolean
    public function cancel($cancelNotification, $apiContext = null, $restCall = null)
    {
        ArgumentValidator::validate($this->getId(), "Id");
        ArgumentValidator::validate($cancelNotification, 'cancelNotification');
        $payLoad = $cancelNotification->toJSON();
        self::executeCall("/v1/invoicing/invoices/{$this->getId()}/cancel", "POST", $payLoad, null, $apiContext, $restCall);
        return true;
    }

Usage Example

 /**
  * @dataProvider mockProvider
  * @param Invoice $obj
  */
 public function testCancel($obj, $mockApiContext)
 {
     $mockPayPalRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPayPalRestCall->expects($this->any())->method('execute')->will($this->returnValue(true));
     $cancelNotification = CancelNotificationTest::getObject();
     $result = $obj->cancel($cancelNotification, $mockApiContext, $mockPayPalRestCall);
     $this->assertNotNull($result);
 }