/** * @param Notify $request * * @throws RequestNotSupportedException if the action dose not support the request. */ public function execute($request) { /** @var Array $notification */ $notification = $request->getNotification(); $response = BitPayNotification::fromArray($notification); /** @var Transaction $model */ $model = $this->storageInterface->findModelById($response->getId()); $model->setResponse($response); $this->storageInterface->updateModel($model); }
function it_should_store_invoices(StorageInterface $storageInterface, SecuredNotify $request, Transaction $transaction) { $notification = ['id' => '1', 'url' => 'http://bitpay.com/invoice', 'status' => BitPayNotification::STATUS_CONFIRMED, 'btcPrice' => 0.001, 'price' => 0.001, 'currency' => 'BTC', 'invoiceTime' => '20140101T19:01:01.123Z', 'expirationTime' => '20140101T19:01:01.123Z', 'currentTime' => '20140101T19:01:01.123Z']; $invoice = BitPayNotification::fromArray($notification); $request->getNotification()->willReturn($notification); $transaction->setResponse($invoice)->shouldBeCalled(); $storageInterface->findModelById('1')->willReturn($transaction); $storageInterface->updateModel($transaction)->shouldBeCalled(); $this->execute($request); }
/** * {@inheritDoc} */ public function verify($httpRequest) { if (false == is_array($httpRequest)) { throw new InvalidArgumentException('Invalid request given. In most cases you have to pass $_REQUEST array.'); } if (false == isset($httpRequest[$this->tokenParameter])) { throw new InvalidArgumentException(sprintf('Token parameter `%s` was not found in in the http request.', $this->tokenParameter)); } if ($httpRequest[$this->tokenParameter] instanceof TokenInterface) { return $httpRequest[$this->tokenParameter]; } if (false == ($token = $this->tokenStorage->findModelById($httpRequest[$this->tokenParameter]))) { throw new InvalidArgumentException(sprintf('A token with hash `%s` could not be found.', $httpRequest[$this->tokenParameter])); } /** @var $token TokenInterface */ if (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) != parse_url($token->getTargetUrl(), PHP_URL_PATH)) { throw new InvalidArgumentException(sprintf('The current url %s not match target url %s set in the token.', $_SERVER['REQUEST_URI'], $token->getTargetUrl())); } return $token; }
/** * {@inheritDoc} */ public function verify($httpRequest) { if (false == $httpRequest instanceof Request) { throw new InvalidArgumentException(sprintf('Invalid request given. Expected %s but it is %s', 'Symfony\\Component\\HttpFoundation\\Request', is_object($httpRequest) ? get_class($httpRequest) : gettype($httpRequest))); } if (false === ($hash = $httpRequest->attributes->get('payum_token', $httpRequest->get('payum_token', false)))) { throw new NotFoundHttpException('Token parameter not set in request'); } if ($hash instanceof TokenInterface) { $token = $hash; } else { if (false == ($token = $this->tokenStorage->findModelById($hash))) { throw new NotFoundHttpException(sprintf('A token with hash `%s` could not be found.', $hash)); } if (parse_url($httpRequest->getUri(), PHP_URL_PATH) != parse_url($token->getTargetUrl(), PHP_URL_PATH)) { throw new HttpException(400, sprintf('The current url %s not match target url %s set in the token.', $httpRequest->getUri(), $token->getTargetUrl())); } } return $token; }