Payum\AuthorizeNet\Aim\Action\CaptureAction::execute PHP Method

execute() public method

{@inheritDoc}
public execute ( Payum\Core\Request\Capture $request )
$request Payum\Core\Request\Capture
    public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);
        $model = ArrayObject::ensureArrayObject($request->getModel());
        if (null != $model['response_code']) {
            return;
        }
        if (false == $model->validateNotEmpty(array('card_num', 'exp_date'), false)) {
            try {
                $obtainCreditCard = new ObtainCreditCard($request->getToken());
                $obtainCreditCard->setModel($request->getFirstModel());
                $obtainCreditCard->setModel($request->getModel());
                $this->gateway->execute($obtainCreditCard);
                $card = $obtainCreditCard->obtain();
                $model['exp_date'] = SensitiveValue::ensureSensitive($card->getExpireAt()->format('m/y'));
                $model['card_num'] = SensitiveValue::ensureSensitive($card->getNumber());
            } catch (RequestNotSupportedException $e) {
                throw new LogicException('Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.');
            }
        }
        $api = clone $this->api;
        $api->ignore_not_x_fields = true;
        $api->setFields(array_filter($model->toUnsafeArray()));
        $response = $api->authorizeAndCapture();
        $model->replace(get_object_vars($response));
    }

Usage Example

Beispiel #1
0
 /**
  * @test
  */
 public function shouldCaptureWithObtainedCreditCard()
 {
     $api = $this->createAuthorizeNetAIMMock();
     $api->expects($this->once())->method('authorizeAndCapture')->will($this->returnValue($this->createAuthorizeNetAIMResponseMock()));
     $gatewayMock = $this->createGatewayMock();
     $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\ObtainCreditCard'))->will($this->returnCallback(function (ObtainCreditCard $request) {
         $card = new CreditCard();
         $card->setNumber('1234567812345678');
         $card->setExpireAt(new \DateTime('2014-10-01'));
         $request->set($card);
     }));
     $action = new CaptureAction();
     $action->setApi($api);
     $action->setGateway($gatewayMock);
     $action->execute(new Capture(array('amount' => 10)));
 }