/** * {@inheritDoc} * * @param Notify $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); $details = ArrayObject::ensureArrayObject($request->getModel()); $this->gateway->execute($httpRequest = new GetHttpRequest()); if (!isset($httpRequest->request['merchantReference']) || empty($httpRequest->request['merchantReference'])) { $details['response_status'] = 401; return; } if (!isset($details['merchantReference']) || $details['merchantReference'] != $httpRequest->request['merchantReference']) { $details['response_status'] = 402; return; } if (false === $this->api->verifyNotification($httpRequest->request)) { $details['response_status'] = 403; return; } // Check notification code if (isset($httpRequest->request['eventCode'])) { $httpRequest->request['authResult'] = $httpRequest->request['eventCode']; if ('AUTHORISATION' == $httpRequest->request['eventCode']) { if ('true' == $httpRequest->request['success']) { $httpRequest->request['authResult'] = 'AUTHORISED'; } elseif (!empty($httpRequest->request['reason'])) { $httpRequest->request['authResult'] = 'REFUSED'; } } } $details['authResult'] = $httpRequest->request['authResult']; $details['response_status'] = 200; }
/** * {@inheritDoc} * * @param Capture $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); /** * @var TokenInterface */ $token = $request->getToken(); $model = ArrayObject::ensureArrayObject($request->getModel()); $this->gateway->execute($httpRequest = new GetHttpRequest()); // Check httpRequest $extraData = $model['extraData'] ? json_decode($model['extraData'], true) : []; if (false == isset($extraData['capture_token']) && $token) { $extraData['capture_token'] = $token->getHash(); } if (false == isset($extraData['notify_token']) && $token && $this->tokenFactory) { $notifyToken = $this->tokenFactory->createNotifyToken($token->getGatewayName(), $token->getDetails()); $extraData['notify_token'] = $notifyToken->getHash(); $model['resURL'] = $notifyToken->getTargetUrl(); } $model['extraData'] = json_encode($extraData); throw new HttpPostRedirect($this->api->getApiEndpoint(), $this->api->prepareFields($model->toUnsafeArray())); }
/** * @test */ public function shouldReturnTrueIfHmacKeyMatched() { $params = array('foo' => 'fooVal', 'bar' => 'barVal'); $api = new Api(array('skinCode' => 'skin', 'merchantAccount' => 'account', 'hmacKey' => '4468', 'sandbox' => true), $this->createHttpClientMock()); $params['merchantSig'] = $api->merchantSig($params); $this->assertTrue($api->verifySign($params)); }