PayPal\Api\Order::authorize PHP Method

authorize() public method

Authorizes an order, by ID. Include an amount object in the JSON request body.
public authorize ( Authorization $authorization, ApiContext $apiContext = null, PayPalRestCall $restCall = null ) : Authorization
$authorization Authorization Authorization Object with Amount value to be authorized
$apiContext PayPal\Rest\ApiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
$restCall PayPalRestCall is the Rest Call Service that is used to make rest calls
return Authorization
    public function authorize($authorization, $apiContext = null, $restCall = null)
    {
        ArgumentValidator::validate($this->getId(), "Id");
        ArgumentValidator::validate($authorization, 'Authorization');
        $payLoad = $authorization->toJSON();
        $json = self::executeCall("/v1/payments/orders/{$this->getId()}/authorize", "POST", $payLoad, null, $apiContext, $restCall);
        $ret = new Authorization();
        $ret->fromJson($json);
        return $ret;
    }

Usage Example

 /**
  * @dataProvider mockProvider
  * @param Order $obj
  */
 public function testAuthorize($obj, $mockApiContext)
 {
     $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(AuthorizationTest::getJson()));
     $authorization = new Authorization();
     $result = $obj->authorize($authorization, $mockApiContext, $mockPPRestCall);
     $this->assertNotNull($result);
 }