Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  *
  * @param Capture $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $details = ArrayObject::ensureArrayObject($request->getModel());
     if ($details['_status']) {
         return;
     }
     if (false == $details['_completeCaptureRequired']) {
         if (false == $details->validateNotEmpty(array('card'), false) && false == $details->validateNotEmpty(array('cardReference'), false)) {
             try {
                 $obtainCreditCard = new ObtainCreditCard($request->getFirstModel(), $request->getModel());
                 $this->gateway->execute($obtainCreditCard);
                 $card = $obtainCreditCard->obtain();
                 if ($card->getToken()) {
                     $details['cardReference'] = $card->getToken();
                 } else {
                     $details['card'] = SensitiveValue::ensureSensitive(array('number' => $card->getNumber(), 'cvv' => $card->getSecurityCode(), 'expiryMonth' => $card->getExpireAt()->format('m'), 'expiryYear' => $card->getExpireAt()->format('y'), 'firstName' => $card->getHolder(), 'lastName' => ''));
                 }
             } 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.');
             }
         }
     }
     parent::execute($request);
 }
 /**
  * @test
  */
 public function shouldDoNothingIfStatusAlreadySet()
 {
     $gatewayMock = $this->createOmnipayGatewayMock();
     $gatewayMock->expects($this->never())->method('purchase');
     $gatewayMock->expects($this->never())->method('completePurchase');
     $action = new OffsiteCaptureAction();
     $action->setApi($gatewayMock);
     $action->setGateway($this->createGatewayMock());
     $action->execute(new Capture(array('_status' => 'foo')));
 }
 /**
  * @test
  */
 public function shouldSetResponseStringDataToDetails()
 {
     $details = new \ArrayObject(['card' => array('cvv' => 123), 'clientIp' => '']);
     $responseMock = $this->getMock(OmnipayAbstractResponse::class, [], [], '', false);
     $responseMock->expects($this->any())->method('getData')->willReturn('someData');
     $requestMock = $this->getMock(OmnipayRequestInterface::class);
     $requestMock->expects($this->any())->method('send')->will($this->returnValue($responseMock));
     $omnipayGateway = $this->getMock(OffsiteGateway::class);
     $omnipayGateway->expects($this->once())->method('purchase')->willReturn($requestMock);
     $captureToken = new Token();
     $captureToken->setTargetUrl('theCaptureUrl');
     $captureToken->setDetails($identity = new Identity('theId', new \stdClass()));
     $captureToken->setGatewayName('theGatewayName');
     $notifyToken = new Token();
     $notifyToken->setTargetUrl('theNotifyUrl');
     $tokenFactoryMock = $this->getMock(GenericTokenFactoryInterface::class);
     $tokenFactoryMock->expects($this->once())->method('createNotifyToken')->with('theGatewayName', $this->identicalTo($identity))->willReturn($notifyToken);
     $request = new Capture($captureToken);
     $request->setModel($details);
     $action = new OffsiteCaptureAction();
     $action->setApi($omnipayGateway);
     $action->setGateway($this->createGatewayMock());
     $action->setGenericTokenFactory($tokenFactoryMock);
     $action->execute($request);
     $details = (array) $details;
     $this->assertArrayHasKey('_data', $details);
     $this->assertEquals('someData', $details['_data']);
 }