public function initiate($data = array())
    {
        if ($this->payment->Status !== 'Created') {
            throw new InvalidStateException('Cannot authorize this payment. Status is not "Created"');
        }

        if (!$this->payment->isInDB()) {
            $this->payment->write();
        }

        $gateway = $this->oGateway();
        if (!$gateway->supportsAuthorize()) {
            throw new InvalidConfigurationException(
                sprintf('The gateway "%s" doesn\'t support authorize', $this->payment->Gateway)
            );
        }

        $gatewayData = $this->gatherGatewayData($data);

        $this->extend('onBeforeAuthorize', $gatewayData);
        $request = $this->oGateway()->authorize($gatewayData);
        $this->extend('onAfterAuthorize', $request);

        $this->createMessage(AuthorizeRequest::class, $request);

        try {
            $response = $this->response = $request->send();
        } catch (\Omnipay\Common\Exception\OmnipayException $e) {
            $this->createMessage(AuthorizeError::class, $e);
            // create an error response
            return $this->generateServiceResponse(ServiceResponse::SERVICE_ERROR);
        }

        ErrorHandling::safeExtend($this, 'onAfterSendAuthorize', $request, $response);

        $serviceResponse = $this->wrapOmnipayResponse($response);

        if ($serviceResponse->isRedirect() || $serviceResponse->isAwaitingNotification()) {
            $this->payment->Status = 'PendingAuthorization';
            $this->payment->write();

            $this->createMessage(
                $serviceResponse->isRedirect() ? AuthorizeRedirectResponse::class : AwaitingAuthorizeResponse::class,
                $response
            );
        } elseif ($serviceResponse->isError()) {
            $this->createMessage(AuthorizeError::class, $response);
        } else {
            $this->markCompleted('Authorized', $serviceResponse, $response);
        }

        return $serviceResponse;
    }
public function initiate($data = array())
    {
        if ($this->payment->Status !== 'Created') {
            throw new InvalidStateException('Cannot authorize this payment. Status is not "Created"');
        }

        if (!$this->payment->isInDB()) {
            $this->payment->write();
        }

        $gateway = $this->oGateway();
        if (!$gateway->supportsAuthorize()) {
            throw new InvalidConfigurationException(
                sprintf('The gateway "%s" doesn\'t support authorize', $this->payment->Gateway)
            );
        }

        $gatewayData = $this->gatherGatewayData($data);

        $this->extend('onBeforeAuthorize', $gatewayData);
        $request = $this->oGateway()->authorize($gatewayData);
        $this->extend('onAfterAuthorize', $request);

        $this->createMessage(AuthorizeRequest::class, $request);

        try {
            $response = $this->response = $request->send();
        } catch (\Omnipay\Common\Exception\OmnipayException $e) {
            $this->createMessage(AuthorizeError::class, $e);
            // create an error response
            return $this->generateServiceResponse(ServiceResponse::SERVICE_ERROR);
        }

        ErrorHandling::safeExtend($this, 'onAfterSendAuthorize', $request, $response);

        $serviceResponse = $this->wrapOmnipayResponse($response);

        if ($serviceResponse->isRedirect() || $serviceResponse->isAwaitingNotification()) {
            $this->payment->Status = 'PendingAuthorization';
            $this->payment->write();

            $this->createMessage(
                $serviceResponse->isRedirect() ? AuthorizeRedirectResponse::class : AwaitingAuthorizeResponse::class,
                $response
            );
        } elseif ($serviceResponse->isError()) {
            $this->createMessage(AuthorizeError::class, $response);
        } else {
            $this->markCompleted('Authorized', $serviceResponse, $response);
        }

        return $serviceResponse;
    }
public function initiate ( $ data = array ( ) ) { if ( $ this -> payment -> Status !== 'Created' ) { throw new InvalidStateException ( 'Cannot authorize this payment. Status is not "Created"' ) ; } if ( ! $ this -> payment -> isInDB ( ) ) { $ this -> payment -> write ( ) ; } $ gateway = $ this -> oGateway ( ) ; if ( ! $ gateway -> supportsAuthorize ( ) ) { throw new InvalidConfigurationException ( sprintf ( 'The gateway "%s" doesn\'t support authorize' , $ this -> payment -> Gateway ) ) ; } $ gatewayData = $ this -> gatherGatewayData ( $ data ) ; $ this -> extend ( 'onBeforeAuthorize' , $ gatewayData ) ; $ request = $ this -> oGateway ( ) -> authorize ( $ gatewayData ) ; $ this -> extend ( 'onAfterAuthorize' , $ request ) ; $ this -> createMessage ( AuthorizeRequest :: class , $ request ) ; try { $ response = $ this -> response = $ request -> send ( ) ; } catch ( \ Omnipay \ Common \ Exception \ OmnipayException $ e ) { $ this -> createMessage ( AuthorizeError :: class , $ e ) ; // create an error response return $ this -> generateServiceResponse ( ServiceResponse :: SERVICE_ERROR ) ; } ErrorHandling :: safeExtend ( $ this , 'onAfterSendAuthorize' , $ request , $ response ) ; $ serviceResponse = $ this -> wrapOmnipayResponse ( $ response ) ; if ( $ serviceResponse -> isRedirect ( ) || $ serviceResponse -> isAwaitingNotification ( ) ) { $ this -> payment -> Status = 'PendingAuthorization' ; $ this -> payment -> write ( ) ; $ this -> createMessage ( $ serviceResponse -> isRedirect ( ) ? AuthorizeRedirectResponse :: class : AwaitingAuthorizeResponse :: class , $ response ) ; } elseif ( $ serviceResponse -> isError ( ) ) { $ this -> createMessage ( AuthorizeError :: class , $ response ) ; } else { $ this -> markCompleted ( 'Authorized' , $ serviceResponse , $ response ) ; } return $ serviceResponse ; }
Start an authorization request

@inheritdoc
Start an authorization request