/**
  * @test
  */
 public function shouldSetTokenTargetUrlAsCancelUrlIfCapturePassedWithToken()
 {
     $testCase = $this;
     $expectedCancelUrl = 'theCancelUrl';
     $token = new Token();
     $token->setTargetUrl($expectedCancelUrl);
     $token->setDetails(array());
     $paymentMock = $this->createPaymentMock();
     $paymentMock->expects($this->at(0))->method('execute')->with($this->isInstanceOf('Eki\\Payum\\Nganluong\\Request\\Api\\SetExpressCheckout'))->will($this->returnCallback(function ($request) use($testCase, $expectedCancelUrl) {
         $model = $request->getModel();
         $testCase->assertEquals($expectedCancelUrl, $model['cancel_url']);
     }));
     $action = new CaptureAction();
     $action->setPayment($paymentMock);
     $request = new Capture($token);
     $request->setModel(array());
     $action->execute($request);
 }
Пример #2
0
 /**
  * @test
  */
 public function shouldPassFirstAndCurrentModelsWithObtainCreditCardSubRequest()
 {
     $firstModel = new \stdClass();
     $currentModel = new \ArrayObject(array('AMOUNT' => 10, 'CLIENTUSERAGENT' => 'anAgent', 'CLIENTIP' => '127.0.0.1'));
     $apiMock = $this->createApiMock();
     $apiMock->expects($this->once())->method('payment')->will($this->returnValue(array('FOO' => 'FOOVAL', 'BAR' => 'BARVAL')));
     $gatewayMock = $this->createGatewayMock();
     $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\ObtainCreditCard'))->will($this->returnCallback(function (ObtainCreditCard $request) use($firstModel, $currentModel) {
         $this->assertSame($firstModel, $request->getFirstModel());
         $this->assertSame($currentModel, $request->getModel());
         $card = new CreditCard();
         $card->setExpireAt(new \DateTime('2014-10-01'));
         $request->set($card);
     }));
     $action = new CaptureAction();
     $action->setApi($apiMock);
     $action->setGateway($gatewayMock);
     $capture = new Capture($firstModel);
     $capture->setModel($currentModel);
     $action->execute($capture);
 }
Пример #3
0
 /**
  * @test
  */
 public function shouldNotAddNotifyUrlIfTokenFactoryNotSet()
 {
     $details = new \ArrayObject(array());
     $captureToken = new Token();
     $captureToken->setGatewayName('theGatewayName');
     $captureToken->setDetails($details);
     $action = new CaptureAction();
     $action->setGateway($this->createGatewayMock());
     $request = new Capture($captureToken);
     $request->setModel($details);
     $action->execute($request);
     $this->assertArrayNotHasKey('PAYMENTREQUEST_0_NOTIFYURL', $details);
 }
Пример #4
0
 /**
  * @test
  */
 public function shouldPassFirstAndCurrentModelsWithObtainCreditCardSubRequest()
 {
     $firstModel = new \stdClass();
     $currentModel = new \ArrayObject(array('amount' => 10));
     $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) use($firstModel, $currentModel) {
         $this->assertSame($firstModel, $request->getFirstModel());
         $this->assertSame($currentModel, $request->getModel());
         $card = new CreditCard();
         $card->setExpireAt(new \DateTime('2014-10-01'));
         $request->set($card);
     }));
     $action = new CaptureAction();
     $action->setApi($api);
     $action->setGateway($gatewayMock);
     $capture = new Capture($firstModel);
     $capture->setModel($currentModel);
     $action->execute($capture);
 }
 /**
  * @test
  */
 public function shouldExecuteConvertRequestWithTokenIfOnePresent()
 {
     $payment = new Payment();
     $token = $this->createTokenMock();
     $testCase = $this;
     $gatewayMock = $this->createGatewayMock();
     $gatewayMock->expects($this->at(0))->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\GetHumanStatus'))->will($this->returnCallback(function (GetHumanStatus $request) {
         $request->markNew();
     }));
     $gatewayMock->expects($this->at(1))->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\Convert'))->will($this->returnCallback(function (Convert $request) use($testCase, $payment, $token) {
         $testCase->assertSame($payment, $request->getSource());
         $testCase->assertSame($token, $request->getToken());
         $request->setResult(array());
     }));
     $action = new CapturePaymentAction();
     $action->setGateway($gatewayMock);
     $capture = new Capture($token);
     $capture->setModel($payment);
     $action->execute($capture);
     $this->assertSame($payment, $capture->getFirstModel());
     $this->assertInstanceOf('ArrayAccess', $capture->getModel());
     $this->assertSame($token, $capture->getToken());
 }
 /**
  * @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']);
 }
    /**
     * @test
     */
    public function shouldExecuteFillOrderDetailsWithTokenIfStatusNew()
    {
        $order = new Order();
        $token = $this->createTokenMock();

        $testCase = $this;

        $paymentMock = $this->createPaymentMock();
        $paymentMock
            ->expects($this->at(0))
            ->method('execute')
            ->with($this->isInstanceOf('Payum\Core\Request\GetHumanStatus'))
            ->will($this->returnCallback(function (GetHumanStatus $request) {
                $request->markNew();
            }))
        ;
        $paymentMock
            ->expects($this->at(1))
            ->method('execute')
            ->with($this->isInstanceOf('Payum\Core\Request\FillOrderDetails'))
            ->will($this->returnCallback(function (FillOrderDetails $request) use ($testCase, $order, $token) {
                $testCase->assertSame($order, $request->getOrder());
                $testCase->assertSame($token, $request->getToken());
            }))
        ;

        $action = new CaptureOrderAction();
        $action->setPayment($paymentMock);

        $capture = new Capture($token);
        $capture->setModel($order);

        $action->execute($capture);

        $this->assertSame($order, $capture->getFirstModel());
        $this->assertInstanceOf('ArrayAccess', $capture->getModel());
        $this->assertSame($token, $capture->getToken());
    }
 /**
  * @test
  */
 public function shouldObtainCreditCardAndPopulateCardReferenceFieldIfNotSet()
 {
     $firstModel = new \stdClass();
     $model = new \ArrayObject([]);
     $responseMock = $this->getMock(OmnipayAbstractResponse::class, [], [], '', false);
     $responseMock->expects($this->once())->method('getData')->willReturn([]);
     $requestMock = $this->getMock(OmnipayRequestInterface::class);
     $requestMock->expects($this->once())->method('send')->willReturn($responseMock);
     $omnipayGateway = $this->getMock(CreditCardGateway::class, [], [], '', false);
     $omnipayGateway->expects($this->once())->method('purchase')->with(['cardReference' => 'theCardToken', 'clientIp' => ''])->willReturn($requestMock);
     $gateway = $this->createGatewayMock();
     $gateway->expects($this->at(0))->method('execute')->with($this->isInstanceOf(ObtainCreditCard::class))->willReturnCallback(function (ObtainCreditCard $request) use($firstModel, $model) {
         $this->assertSame($firstModel, $request->getFirstModel());
         $this->assertSame($model, $request->getModel());
         $card = new CreditCard();
         $card->setToken('theCardToken');
         $request->set($card);
     });
     $action = new CaptureAction();
     $action->setApi($omnipayGateway);
     $action->setGateway($gateway);
     $capture = new Capture($firstModel);
     $capture->setModel($model);
     $action->execute($capture);
     $details = iterator_to_array($model);
     $this->assertArrayNotHasKey('card', $details);
     $this->assertArrayHasKey('cardReference', $details);
     $this->assertEquals('theCardToken', $details['cardReference']);
 }