Example #1
0
 /**
  * @test
  */
 public function shouldSetZeroPaymentActionAsSell()
 {
     $action = new CaptureAction();
     $action->setPayment($this->createPaymentMock());
     $action->execute($request = new Capture(array()));
     $model = $request->getModel();
     $this->assertArrayHasKey('PAYMENTREQUEST_0_PAYMENTACTION', $model);
     $this->assertEquals(Api::PAYMENTACTION_SALE, $model['PAYMENTREQUEST_0_PAYMENTACTION']);
 }
 /**
  * @param Capture $request
  *
  * @throws RequestNotSupportedException if the action dose not support the request.
  */
 public function execute($request)
 {
     /** @var Transaction $model */
     $model = $request->getModel();
     try {
         $invoice = $this->bitPayClient->createInvoice($model->getRequest()->jsonSerialize());
     } catch (\Exception $ex) {
         throw new RequestNotSupportedException($ex->getMessage());
     }
     $model->setResponse($invoice);
 }
 /**
  * @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);
 }
Example #4
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);
 }
Example #5
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);
 }
Example #6
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);
 }
 function it_does_not_supports_capture(Capture $model, Capture $request)
 {
     $request->getModel()->willReturn($model);
     $this->supports($request)->shouldReturn(false);
 }
 /**
  * @test
  */
 public function shouldSetDetailsBackToPaymentEvenIfExceptionThrown()
 {
     $expectedDetails = array('foo' => 'fooVal');
     $payment = new Payment();
     $payment->setDetails($expectedDetails);
     $gatewayMock = $this->createGatewayMock();
     $gatewayMock->expects($this->at(0))->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\GetHumanStatus'))->will($this->returnCallback(function (GetHumanStatus $request) {
         $request->markPending();
     }));
     $gatewayMock->expects($this->at(1))->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\Capture'))->will($this->returnCallback(function (Capture $request) {
         $details = $request->getModel();
         $details['bar'] = 'barVal';
         throw new \Exception();
     }));
     $action = new CapturePaymentAction();
     $action->setGateway($gatewayMock);
     $this->setExpectedException('Exception');
     $action->execute($capture = new Capture($payment));
     $this->assertSame($payment, $capture->getFirstModel());
     $this->assertInstanceOf('ArrayAccess', $capture->getModel());
     $this->assertEquals(array('foo' => 'fooVal', 'bar' => 'barVal'), $payment->getDetails());
 }
 /**
  * @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 shouldKeepOrderEvenIfExceptionThrown()
 {
     $details = array('foo' => 'fooVal');
     $order = new Order();
     $order->setDetails($details);
     $paymentMock = $this->createPaymentMock();
     $paymentMock->expects($this->at(0))->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\GetHumanStatus'))->will($this->returnCallback(function (GetHumanStatus $request) {
         $request->markPending();
     }));
     $paymentMock->expects($this->at(1))->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\Capture'))->will($this->throwException(new \Exception()));
     $action = new CaptureOrderAction();
     $action->setPayment($paymentMock);
     $this->setExpectedException('Exception');
     $action->execute($capture = new Capture($order));
     $this->assertSame($order, $capture->getModel());
 }
 /**
  * @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']);
 }
 public function testShouldDoNothingIfCustomerSetOnPreExecute()
 {
     $model = new \ArrayObject(['customer' => 'aCustomerId', 'card' => 'theTokenMustBeObtained', 'local' => ['save_card' => true]]);
     $request = new Capture($model);
     $gatewayMock = $this->createGatewayMock();
     $gatewayMock->expects($this->never())->method('execute');
     $context = new Context($gatewayMock, $request, []);
     $extension = new CreateCustomerExtension();
     $extension->onPreExecute($context);
     $this->assertEquals(['customer' => 'aCustomerId', 'card' => 'theTokenMustBeObtained', 'local' => ['save_card' => true]], (array) $request->getModel());
 }
 function it_supports_capture(Transaction $model, Capture $request)
 {
     $request->getModel()->willReturn($model);
     $this->supports($request)->shouldReturn(true);
 }