Example #1
0
 /**
  * {@inheritDoc}
  */
 public function createToken($gatewayName, $model, $targetPath, array $targetParameters = [], $afterPath = null, array $afterParameters = [])
 {
     /** @var TokenInterface $token */
     $token = $this->tokenStorage->create();
     $token->setHash($token->getHash() ?: Random::generateToken());
     $targetParameters = array_replace(['payum_token' => $token->getHash()], $targetParameters);
     $token->setGatewayName($gatewayName);
     if ($model instanceof IdentityInterface) {
         $token->setDetails($model);
     } elseif (null !== $model) {
         $token->setDetails($this->storageRegistry->getStorage($model)->identify($model));
     }
     if (0 === strpos($targetPath, 'http')) {
         $targetUri = HttpUri::createFromString($targetPath);
         $targetUri = $this->addQueryToUri($targetUri, $targetParameters);
         $token->setTargetUrl((string) $targetUri);
     } else {
         $token->setTargetUrl($this->generateUrl($targetPath, $targetParameters));
     }
     if ($afterPath && 0 === strpos($afterPath, 'http')) {
         $afterUri = HttpUri::createFromString($afterPath);
         $afterUri = $this->addQueryToUri($afterUri, $afterParameters);
         $token->setAfterUrl((string) $afterUri);
     } elseif ($afterPath) {
         $token->setAfterUrl($this->generateUrl($afterPath, $afterParameters));
     }
     $this->tokenStorage->update($token);
     return $token;
 }
Example #2
0
 /**
  * {@inheritDoc}
  *
  * @param $request GetToken
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     if (false == ($token = $this->tokenStorage->find($request->getHash()))) {
         throw new LogicException(sprintf('The token %s could not be found', $request->getHash()));
     }
     $request->setToken($token);
 }
 /**
  * {@inheritDoc}
  */
 public function createCaptureToken($paymentName, $model, $afterPath, array $afterParameters = array())
 {
     $afterToken = $this->createToken($paymentName, $model, $afterPath, $afterParameters);
     $captureToken = $this->createToken($paymentName, $model, $this->capturePath);
     $captureToken->setAfterUrl($afterToken->getTargetUrl());
     $this->tokenStorage->updateModel($captureToken);
     return $captureToken;
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function getGateway($name)
 {
     /** @var GatewayConfigInterface[] $configs */
     if ($configs = $this->gatewayConfigStore->findBy(array('gateway_name' => $name))) {
         $config = array_shift($configs);
         $factory = $this->getGatewayFactory($config->getFactoryName());
         return $factory->create($config->getParameters()->toArray());
     }
     return $this->staticRegistry->getGateway($name);
 }
Example #5
0
 /**
  * @param mixed $model
  */
 protected function scheduleForUpdateIfSupported($model)
 {
     if ($this->storage->support($model)) {
         $modelHash = spl_object_hash($model);
         if (array_key_exists($modelHash, $this->scheduledForUpdateModels)) {
             return;
         }
         $this->scheduledForUpdateModels[$modelHash] = $model;
     }
 }
 /**
  * @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' => '2014­01­01T19:01:01.123Z', 'expirationTime' => '2014­01­01T19:01:01.123Z', 'currentTime' => '2014­01­01T19: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 getPayment($name)
    {
        /** @var PaymentConfigInterface $config */
        if ($config = $this->paymentConfigStore->findBy(array('paymentName' => $name))) {
            $factory = $this->getPaymentFactory($config->getFactoryName());

            return $factory->create($config->getConfig());
        }

        return $this->staticRegistry->getPayment($name);
    }
Example #9
0
 /**
  * {@inheritDoc}
  *
  * @param $request Notify
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $this->gateway->execute($httpRequest = new GetHttpRequest());
     if (empty($httpRequest->query['ORDERID'])) {
         throw new HttpResponse('The notification is invalid. Code 3', 400);
     }
     $payment = $this->paymentStorage->findBy([$this->idField => $httpRequest->query['ORDERID']]);
     if (null === $payment) {
         throw new HttpResponse('The notification is invalid. Code 4', 400);
     }
     $this->gateway->execute(new Notify($payment));
 }
 /**
  * {@inheritDoc}
  *
  * @param Notify $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     $this->gateway->execute($httpRequest = new GetHttpRequest());
     if (false == $this->api->verifyRequest($httpRequest->request)) {
         throw new HttpResponse('The notification is invalid. [2]', 400, array('x-reason-code' => 2));
     }
     if ($model['amount'] != $httpRequest->request['withdraw_amount'] && $model['amount'] != $httpRequest->request['amount']) {
         throw new HttpResponse('The notification is invalid. [3]', 400, array('x-reason-code' => 3));
     }
     if ('true' === $httpRequest->request['unaccepted']) {
         throw new HttpResponse('The notification is invalid. [4]', 400, array('x-reason-code' => 4));
     }
     $model->replace(array(Api::FIELD_STATUS => Api::STATUS_CAPTURED));
     $this->tokenStorage->delete($request->getToken());
     throw new HttpResponse('', 200, array('x-reason-code' => 0));
 }
Example #11
0
 /**
  * @param string $name
  *
  * @return GatewayConfigInterface
  */
 protected function findGatewayConfigByName($name)
 {
     if (false == $name) {
         throw new NotFoundHttpException(sprintf('Config name is empty.', $name));
     }
     /** @var GatewayConfigInterface $gatewayConfigs */
     $gatewayConfigs = $this->gatewayConfigStorage->findBy(['gatewayName' => $name]);
     if (empty($gatewayConfigs)) {
         throw new NotFoundHttpException(sprintf('Config with name %s was not found.', $name));
     }
     return array_shift($gatewayConfigs);
 }
Example #12
0
 /**
  * {@inheritDoc}
  */
 public function getGateways()
 {
     // @deprecated It will return empty array here
     if ($this->backwardCompatibility && $this->gatewayFactoryRegistry instanceof RegistryInterface) {
         return $this->gatewayFactoryRegistry->getGateways();
     }
     $gateways = [];
     foreach ($this->gatewayConfigStore->findBy([]) as $gatewayConfig) {
         /** @var GatewayConfigInterface $gatewayConfig */
         $gateways[$gatewayConfig->getGatewayName()] = $this->getGateway($gatewayConfig->getGatewayName());
     }
     return $gateways;
 }
 /**
  * {@inheritDoc}
  */
 public function invalidate(TokenInterface $token)
 {
     $this->tokenStorage->delete($token);
 }