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\Sender;
  6 
  7 use Buzz\Client\ClientInterface;
  8 use Buzz\Message\RequestInterface;
  9 use Buzz\Message\Response;
 10 use Psr\Log\LoggerInterface;
 11 use Team3\PayU\Configuration\Credentials\CredentialsInterface;
 12 use Team3\PayU\Communication\ClientException;
 13 
 14 /**
 15  * Encapsulates all cURL related options and sending function.
 16  *
 17  * Class Sender
 18  * @package Team3\PayU\Communication\Sender
 19  */
 20 class Sender implements SenderInterface
 21 {
 22     /**
 23      * @var ClientInterface
 24      */
 25     private $curlClient;
 26 
 27     /**
 28      * @var LoggerInterface
 29      */
 30     private $logger;
 31 
 32     /**
 33      * @param ClientInterface $curlClient
 34      * @param LoggerInterface $logger
 35      */
 36     public function __construct(
 37         ClientInterface $curlClient,
 38         LoggerInterface $logger
 39     ) {
 40         $this->curlClient = $curlClient;
 41         $this->logger = $logger;
 42     }
 43 
 44     /**
 45      * @param RequestInterface     $request
 46      * @param CredentialsInterface $credentials
 47      *
 48      * @return Response
 49      * @throws ClientException
 50      */
 51     public function send(
 52         RequestInterface $request,
 53         CredentialsInterface $credentials
 54     ) {
 55         $response = new Response();
 56 
 57         try {
 58             $this
 59                 ->curlClient
 60                 ->send(
 61                     $request,
 62                     $response,
 63                     $this->getOptions($credentials)
 64                 );
 65         } catch (\Exception $exception) {
 66             $this->logException($exception);
 67             throw new ClientException(
 68                 sprintf(
 69                     'Exception %s occurred with message: "%s"',
 70                     get_class($exception),
 71                     $exception->getMessage()
 72                 ),
 73                 $exception->getCode(),
 74                 $exception
 75             );
 76         }
 77 
 78         return $response;
 79     }
 80 
 81     /**
 82      * @param CredentialsInterface $credentials
 83      *
 84      * @return array
 85      */
 86     private function getOptions(CredentialsInterface $credentials)
 87     {
 88         return [
 89             CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
 90             CURLOPT_USERPWD => sprintf(
 91                 '%s:%s',
 92                 $credentials->getMerchantPosId(),
 93                 $credentials->getMerchantPosId()
 94             ),
 95             CURLOPT_SSLVERSION => 1,
 96             CURLOPT_SSL_CIPHER_LIST => $credentials->getEncryptionProtocols(),
 97             CURLOPT_SSL_VERIFYHOST => 2,
 98             CURLOPT_SSL_VERIFYPEER => false,
 99             CURLOPT_ENCODING => 'gzip',
100             CURLOPT_FOLLOWLOCATION => false,
101         ];
102     }
103 
104     /**
105      * @param \Exception $exception
106      */
107     private function logException(\Exception $exception)
108     {
109         $this
110             ->logger
111             ->error(sprintf(
112                 '%s was thrown with message %s',
113                 get_class($exception),
114                 $exception->getMessage()
115             ));
116     }
117 }
118 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen