/**
  * @param string $id
  * @param string $secret
  * @param string $url
  */
 public function __construct($id, $secret, $url)
 {
     $this->logger = new NullLogger();
     if (!strlen($id) || !strlen($secret)) {
         throw new InvalidArgumentException('api_id and api_secret must both be provided');
     }
     $validatedUrl = filter_var($url, FILTER_VALIDATE_URL);
     if (!$validatedUrl) {
         throw new InvalidArgumentException($url . ' is not a valid URL');
     }
     $this->id = $id;
     $this->secret = $secret;
     $this->baseUrl = $validatedUrl . '/page/api/';
     $handlerStack = HandlerStack::create(GuzzleHttp\choose_handler());
     $handlerStack->push(Middleware::mapRequest(function (RequestInterface $request) {
         $uri = $request->getUri();
         $query = new Query($uri->getQuery());
         /*
          * Add id and version to the query
          */
         $query = $query->merge(Query::createFromArray(['api_id' => $this->id, 'api_ver' => '2']));
         /*
          * Add timestamp to the query
          */
         if (!$query->hasKey('api_ts')) {
             $query = $query->merge(Query::createFromArray(['api_ts', time()]));
         }
         $query = $query->merge(Query::createFromArray(['api_mac' => $this->generateMac($uri->getPath(), $query)]));
         return $request->withUri($uri->withQuery((string) $query));
     }));
     $this->guzzleClient = new GuzzleClient(['handler' => $handlerStack]);
 }
Example #2
0
 /**
  * @param HttpUri $uri
  * @param array $query
  *
  * @return HttpUri
  */
 protected function addQueryToUri(HttpUri $uri, array $query)
 {
     $query = array_replace($uri->query->toArray(), $query);
     $query = array_filter($query, function ($value) {
         return null !== $value;
     });
     return $uri->withQuery((string) Query::createFromArray($query));
 }
 /**
  * {@inheritDoc}
  *
  * @param Capture $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $this->gateway->execute($httpRequest = new GetHttpRequest());
     //we are back from be2bill site so we have to just update model.
     if (empty($httpRequest->query['EXTRADATA'])) {
         throw new HttpResponse('The capture is invalid. Code Be2Bell1', 400);
     }
     $extraDataJson = $httpRequest->query['EXTRADATA'];
     if (false == ($extraData = json_decode($extraDataJson, true))) {
         throw new HttpResponse('The capture is invalid. Code Be2Bell2', 400);
     }
     if (empty($extraData['capture_token'])) {
         throw new HttpResponse('The capture is invalid. Code Be2Bell3', 400);
     }
     $this->gateway->execute($getToken = new GetToken($extraData['capture_token']));
     $uri = HttpUri::createFromString($getToken->getToken()->getTargetUrl());
     $uri = $uri->withQuery((string) Query::createFromArray($httpRequest->query));
     throw new HttpRedirect((string) $uri);
 }
Example #4
0
 /**
  * @param $url
  * @param array $params
  * @return string
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws InvalidConfigException
  */
 public function signUrl($url, array $params = [])
 {
     $uri = Http::createFromString($url);
     $paramsQuery = Query::createFromArray($params);
     $path = $uri->getPath();
     $query = $uri->query->merge($paramsQuery);
     $signature = $this->getHttpSignature()->generateSignature($path, $query->toArray());
     $query = $query->merge(Query::createFromArray(['s' => $signature]));
     $uri = $uri->withQuery((string) $query);
     return (string) $uri;
 }