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\CurlRequestBuilder;
 6 
 7 use Buzz\Message\Request;
 8 use Team3\PayU\Communication\Request\PayURequestInterface;
 9 use Team3\PayU\Configuration\ConfigurationInterface;
10 use Team3\PayU\Serializer\SerializerInterface;
11 
12 /**
13  * {@inheritdoc}
14  */
15 class CurlRequestBuilder implements CurlRequestBuilderInterface
16 {
17     const CONTENT_TYPE = 'application/json';
18 
19     /**
20      * @var SerializerInterface
21      */
22     private $serializer;
23 
24     /**
25      * @param SerializerInterface $serializer
26      */
27     public function __construct(SerializerInterface $serializer)
28     {
29         $this->serializer = $serializer;
30     }
31 
32     /**
33      * @param ConfigurationInterface $configuration
34      * @param PayURequestInterface   $request
35      *
36      * @return Request
37      */
38     public function build(
39         ConfigurationInterface $configuration,
40         PayURequestInterface $request
41     ) {
42         $curlRequest = new Request();
43 
44         if (PayURequestInterface::METHOD_POST === $request->getMethod()) {
45             $curlRequest->setContent(
46                 $this->serializer->toJson($request->getDataObject())
47             );
48         }
49 
50         $curlRequest->setHost(sprintf(
51             '%s://%s/',
52             $configuration->getProtocol(),
53             $configuration->getDomain()
54         ));
55         $curlRequest->setResource(sprintf(
56             '%s/%s/%s',
57             $configuration->getPath(),
58             $configuration->getVersion(),
59             $request->getPath()
60         ));
61         $curlRequest->setMethod($request->getMethod());
62         $this->addHeaders($curlRequest, $configuration);
63 
64         return $curlRequest;
65     }
66 
67     /**
68      * @param Request                $curlRequest
69      * @param ConfigurationInterface $configuration
70      */
71     private function addHeaders(
72         Request $curlRequest,
73         ConfigurationInterface $configuration
74     ) {
75         $authorization = sprintf(
76             'Basic %s',
77             base64_encode(
78                 sprintf(
79                     '%s:%s',
80                     $configuration->getCredentials()->getMerchantPosId(),
81                     $configuration->getCredentials()->getPrivateKey()
82                 )
83             )
84         );
85         $curlRequest->addHeaders([
86             'Authorization' => $authorization,
87             'Content-Type' => self::CONTENT_TYPE,
88             'Accept' => self::CONTENT_TYPE,
89         ]);
90     }
91 }
92 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen