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\Process;
  6 
  7 use Symfony\Component\Validator\Validator\ValidatorInterface;
  8 use Team3\PayU\Communication\ClientInterface;
  9 use Team3\PayU\Communication\HttpStatusParser\HttpStatusParser;
 10 use Team3\PayU\Communication\HttpStatusParser\HttpStatusParserException;
 11 use Team3\PayU\Communication\HttpStatusParser\HttpStatusParserInterface;
 12 use Team3\PayU\Communication\Process\ResponseDeserializer\ResponseDeserializerInterface;
 13 use Team3\PayU\Communication\Request\PayURequestInterface;
 14 use Team3\PayU\Communication\Response\ResponseInterface;
 15 use Team3\PayU\Configuration\ConfigurationInterface;
 16 use Team3\PayU\Serializer\SerializableInterface;
 17 
 18 /**
 19  * This class will help user to make a request to PayU.
 20  * Basing on {@link PayURequestInterface} and {@link ConfigurationInterface}
 21  * it will serialize objects, send request, parse HTTP status code of the response
 22  * and deserialize the response into proper objects.
 23  *
 24  * Class RequestProcess
 25  * @package Team3\PayU\Communication\Process
 26  */
 27 class RequestProcess implements RequestProcessInterface
 28 {
 29     /**
 30      * @var ResponseDeserializerInterface
 31      */
 32     private $responseDeserializer;
 33 
 34     /**
 35      * @var ClientInterface
 36      */
 37     private $client;
 38 
 39     /**
 40      * @var ValidatorInterface
 41      */
 42     private $validator;
 43 
 44     /**
 45      * @var HttpStatusParserInterface
 46      */
 47     private $httpStatusParser;
 48 
 49     /**
 50      * @var bool
 51      */
 52     private $shouldValidate;
 53 
 54     /**
 55      * @param ResponseDeserializerInterface $responseDeserializer
 56      * @param ClientInterface               $client
 57      * @param ValidatorInterface            $validator
 58      * @param HttpStatusParserInterface     $httpStatusParser
 59      */
 60     public function __construct(
 61         ResponseDeserializerInterface $responseDeserializer,
 62         ClientInterface $client,
 63         ValidatorInterface $validator,
 64         HttpStatusParserInterface $httpStatusParser
 65     ) {
 66         $this->responseDeserializer = $responseDeserializer;
 67         $this->client = $client;
 68         $this->validator = $validator;
 69         $this->httpStatusParser = $httpStatusParser;
 70         $this->shouldValidate = true;
 71     }
 72 
 73     /**
 74      * @param PayURequestInterface   $payURequest
 75      * @param ConfigurationInterface $configuration
 76      *
 77      * @return object
 78      * @throws HttpStatusParserException         when status code is not 200
 79      * @throws InvalidRequestDataObjectException when request data object is invalid
 80      */
 81     public function process(
 82         PayURequestInterface $payURequest,
 83         ConfigurationInterface $configuration
 84     ) {
 85         if ($this->shouldValidate) {
 86             $this->validate($payURequest->getDataObject());
 87         }
 88 
 89         $curlResponse = $this->client->sendRequest($configuration, $payURequest);
 90         $this->httpStatusParser->parse($curlResponse);
 91 
 92         return $this->responseDeserializer->deserializeResponse($curlResponse, $payURequest);
 93     }
 94 
 95     /**
 96      * @param ResponseInterface $response
 97      *
 98      * @return $this
 99      */
100     public function addResponse(ResponseInterface $response)
101     {
102         $this->responseDeserializer->addResponse($response);
103 
104         return $this;
105     }
106 
107     /**
108      * @return $this
109      */
110     public function disableValidation()
111     {
112         $this->shouldValidate = false;
113 
114         return $this;
115     }
116 
117     /**
118      * @param SerializableInterface $object
119      *
120      * @throws InvalidRequestDataObjectException
121      */
122     private function validate(SerializableInterface $object)
123     {
124         $violations = $this->validator->validate($object);
125 
126         if (0 < $violations->count()) {
127             throw new InvalidRequestDataObjectException(
128                 $violations,
129                 sprintf(
130                     'Given object %s in PayU request is invalid. %d violations are in this exception.',
131                     get_class($object),
132                     $violations->count()
133                 )
134             );
135         }
136     }
137 }
138 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen