PayU integration by Krzysztof Gzocha
  • Namespace
  • Class

Namespaces

  • Team3
    • PayU
      • Annotation
      • Communication
        • CurlRequestBuilder
        • HttpStatusParser
        • Notification
        • Process
          • NotificationProcess
          • ResponseDeserializer
        • Request
          • Model
        • Response
          • Model
        • Sender
      • Configuration
        • Credentials
      • Order
        • Autocomplete
          • Strategy
        • Model
          • Buyer
          • Money
          • Products
          • ShippingMethods
          • Traits
        • Transformer
          • UserOrder
            • Strategy
              • Product
              • ShippingMethod
      • PropertyExtractor
        • Reader
      • Serializer
      • SignatureCalculator
        • Encoder
          • Algorithms
          • Strategy
        • ParametersSorter
        • Validator
      • ValidatorBuilder

Classes

  • Team3\PayU\ValidatorBuilder\ValidatorBuilder

Interfaces

  • Team3\PayU\ValidatorBuilder\ValidatorBuilderInterface
  1 <?php
  2 /**
  3  * @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl>
  4  */
  5 namespace Team3\PayU\Communication;
  6 
  7 use Buzz\Client\ClientInterface;
  8 use Buzz\Message\RequestInterface;
  9 use Team3\PayU\Communication\ClientInterface as PayUClientInterface;
 10 use Buzz\Exception\ClientException;
 11 use Buzz\Message\Response;
 12 use Psr\Log\LoggerInterface;
 13 use Team3\PayU\Communication\CurlRequestBuilder\CurlRequestBuilderInterface;
 14 use Team3\PayU\Communication\Request\PayURequestInterface;
 15 use Team3\PayU\Communication\Sender\Sender;
 16 use Team3\PayU\Communication\Sender\SenderInterface;
 17 use Team3\PayU\Configuration\ConfigurationInterface;
 18 
 19 /**
 20  * {@inheritdoc}
 21  *
 22  * Class ClientAdapter
 23  * @package Team3\PayU\Communication
 24  */
 25 class ClientAdapter implements PayUClientInterface
 26 {
 27     /**
 28      * @var SenderInterface
 29      */
 30     private $sender;
 31 
 32     /**
 33      * @var CurlRequestBuilderInterface
 34      */
 35     private $requestBuilder;
 36 
 37     /**
 38      * @var LoggerInterface
 39      */
 40     private $logger;
 41 
 42     /**
 43      * @param SenderInterface             $sender
 44      * @param CurlRequestBuilderInterface $requestBuilder
 45      * @param LoggerInterface             $logger
 46      */
 47     public function __construct(
 48         SenderInterface $sender,
 49         CurlRequestBuilderInterface $requestBuilder,
 50         LoggerInterface $logger
 51     ) {
 52         $this->sender = $sender;
 53         $this->requestBuilder = $requestBuilder;
 54         $this->logger = $logger;
 55     }
 56 
 57     /**
 58      * @param ConfigurationInterface $configuration
 59      * @param PayURequestInterface   $request
 60      *
 61      * @return Response
 62      * @throws ClientException
 63      */
 64     public function sendRequest(
 65         ConfigurationInterface $configuration,
 66         PayURequestInterface $request
 67     ) {
 68         $curlRequest = $this->requestBuilder->build($configuration, $request);
 69         $this->logRequest($curlRequest);
 70         $response = $this->sender->send($curlRequest, $configuration->getCredentials());
 71         $this->logResponse($curlRequest, $response);
 72 
 73         return $response;
 74     }
 75 
 76     /**
 77      * @param RequestInterface $request
 78      */
 79     private function logRequest(RequestInterface $request)
 80     {
 81         $this
 82             ->logger
 83             ->debug(sprintf(
 84                 'Sending request to host:%s resource:%s with content "%s"',
 85                 $request->getHost(),
 86                 $request->getResource(),
 87                 $request->getContent()
 88             ));
 89     }
 90 
 91     /**
 92      * @param RequestInterface $request
 93      * @param Response         $response
 94      */
 95     private function logResponse(
 96         RequestInterface $request,
 97         Response $response
 98     ) {
 99         $this
100             ->logger
101             ->debug(sprintf(
102                 'Request to %s%s with content "%s" was send and response with content "%s" and status %d received',
103                 $request->getHost(),
104                 $request->getResource(),
105                 $request->getContent(),
106                 $response->getContent(),
107                 $response->getStatusCode()
108             ));
109     }
110 }
111 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen