/** * {@inheritDoc} */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); $environment = $this->api['environment']; $signature = $this->api['signature_key']; $posId = $this->api['pos_id']; $openPayU = $this->getOpenPayUWrapper() ? $this->getOpenPayUWrapper() : new OpenPayUWrapper($environment, $signature, $posId); $model = $request->getModel(); $model = ArrayObject::ensureArrayObject($model); /** * @var Token $token */ $token = $request->getToken(); if ($model['orderId'] == null) { $order = array(); $order['continueUrl'] = $token->getTargetUrl(); //customer will be redirected to this page after successfull payment $order['notifyUrl'] = $this->tokenFactory->createNotifyToken($token->getGatewayName(), $token->getDetails())->getTargetUrl(); $order['customerIp'] = $model['customerIp']; $order['merchantPosId'] = $posId; $order['description'] = $model['description']; $order['currencyCode'] = $model['currencyCode']; $order['totalAmount'] = $model['totalAmount']; $order['extOrderId'] = $model['extOrderId']; //must be unique! $order['buyer'] = $model['buyer']; if (!array_key_exists('products', $model) || count($model['products']) == 0) { $order['products'] = array(array('name' => $model['description'], 'unitPrice' => $model['totalAmount'], 'quantity' => 1)); } else { $order['products'] = $model['products']; } $response = $openPayU->create($order)->getResponse(); if ($response && $response->status->statusCode == 'SUCCESS') { $model['orderId'] = $response->orderId; $request->setModel($model); throw new HttpRedirect($response->redirectUri); } else { throw PayUException::newInstance($response->status); } } else { $response = $openPayU->retrieve($model['orderId'])->getResponse(); if ($response->status->statusCode == 'SUCCESS') { $model['status'] = $response->orders[0]->status; $request->setModel($model); } } }
/** * @test */ public function shouldAllowCreateNotifyTokenWithoutModel() { $gatewayName = 'theGatewayName'; $notifyPath = 'theNotifyPath'; $notifyToken = new Token(); $tokenFactoryMock = $this->createTokenFactoryMock(); $tokenFactoryMock->expects($this->once())->method('createToken')->with($gatewayName, null, $notifyPath, array(), null, array())->willReturn($notifyToken); $factory = new GenericTokenFactory($tokenFactoryMock, array('notify' => $notifyPath)); $actualToken = $factory->createNotifyToken($gatewayName); $this->assertSame($notifyToken, $actualToken); }
/** * @test */ public function shouldCreateCaptureTokenWithAfterPathAlreadyUrl() { $captureToken = new Token(); $afterToken = new Token(); $tokenStorageMock = $this->createStorageMock(); $tokenStorageMock->expects($this->at(0))->method('createModel')->will($this->returnValue($afterToken)); $tokenStorageMock->expects($this->at(1))->method('updateModel')->with($this->identicalTo($afterToken)); $tokenStorageMock->expects($this->at(2))->method('createModel')->will($this->returnValue($captureToken)); $tokenStorageMock->expects($this->at(3))->method('updateModel')->with($this->identicalTo($captureToken)); $tokenStorageMock->expects($this->at(4))->method('updateModel')->with($this->identicalTo($captureToken)); $model = new \stdClass(); $identificator = new Identificator('anId', 'stdClass'); $paymentName = 'thePaymentName'; $modelStorage = $this->createStorageMock(); $modelStorage->expects($this->exactly(2))->method('getIdentificator')->with($this->identicalTo($model))->will($this->returnValue($identificator)); $storageRegistryMock = $this->createStorageRegistryMock(); $storageRegistryMock->expects($this->exactly(2))->method('getStorage')->with($this->identicalTo($model))->will($this->returnValue($modelStorage)); $factory = new GenericTokenFactory($tokenStorageMock, $storageRegistryMock, 'http://example.com', 'capture.php', 'notify.php'); $actualToken = $factory->createCaptureToken($paymentName, $model, 'http://google.com', array('afterKey' => 'afterVal')); $this->assertSame($captureToken, $actualToken); $this->assertEquals($paymentName, $captureToken->getPaymentName()); $this->assertSame($identificator, $captureToken->getDetails()); $this->assertEquals('http://example.com/capture.php?payum_token=' . $captureToken->getHash(), $captureToken->getTargetUrl()); $this->assertEquals('http://google.com?afterKey=afterVal&payum_token=' . $afterToken->getHash(), $captureToken->getAfterUrl()); }
/** * @test */ public function shouldAllowCreatePayoutToken() { $gatewayName = 'theGatewayName'; $model = new \stdClass(); $payoutPath = 'thePayoutPath'; $afterPath = 'theAfterPath'; $afterUrl = 'theAfterUrl'; $afterParameters = array('after' => 'val'); $afterToken = new Token(); $afterToken->setTargetUrl($afterUrl); $payoutToken = new Token(); $tokenFactoryMock = $this->createTokenFactoryMock(); $tokenFactoryMock->expects($this->at(0))->method('createToken')->with($gatewayName, $this->identicalTo($model), $afterPath, $afterParameters, null, [])->willReturn($afterToken); $tokenFactoryMock->expects($this->at(1))->method('createToken')->with($gatewayName, $this->identicalTo($model), $payoutPath, [], $afterUrl, [])->willReturn($payoutToken); $factory = new GenericTokenFactory($tokenFactoryMock, array('payout' => $payoutPath)); $actualToken = $factory->createPayoutToken($gatewayName, $model, $afterPath, $afterParameters); $this->assertSame($payoutToken, $actualToken); }