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\NotificationProcess;
 6 
 7 use Team3\PayU\Communication\Notification\OrderNotification;
 8 use Team3\PayU\Configuration\Credentials\CredentialsInterface;
 9 use Team3\PayU\Serializer\SerializerInterface;
10 use Team3\PayU\SignatureCalculator\Validator\SignatureValidatorInterface;
11 
12 /**
13  * This class will help in notification's receiving process.
14  *
15  * Class NotificationProcess
16  * @package Team3\PayU\Communication\Process\NotificationProcess
17  */
18 class NotificationProcess
19 {
20     const ORDER_NOTIFICATION_CLASS = 'Team3\PayU\Communication\Notification\OrderNotification';
21 
22     /**
23      * @var SerializerInterface
24      */
25     private $serializer;
26 
27     /**
28      * @var SignatureValidatorInterface
29      */
30     private $signatureValidator;
31 
32     /**
33      * @param SerializerInterface         $serializer
34      * @param SignatureValidatorInterface $signatureValidator
35      */
36     public function __construct(
37         SerializerInterface $serializer,
38         SignatureValidatorInterface $signatureValidator
39     ) {
40         $this->serializer = $serializer;
41         $this->signatureValidator = $signatureValidator;
42     }
43 
44     /**
45      * @param CredentialsInterface $credentials
46      * @param string               $data
47      * @param string|null          $signatureHeader Signature can be null when notifyUrl starts with https
48      *
49      * @return OrderNotification
50      */
51     public function process(
52         CredentialsInterface $credentials,
53         $data,
54         $signatureHeader = null
55     ) {
56         if (null !== $signatureHeader) {
57             $this->validateSignature($credentials, $data, $signatureHeader);
58         }
59 
60         return $this
61             ->serializer
62             ->fromJson($data, self::ORDER_NOTIFICATION_CLASS);
63     }
64 
65     /**
66      * @param CredentialsInterface $credentials
67      * @param string               $data
68      * @param string               $signatureHeader
69      *
70      * @throws NotificationProcessException
71      */
72     private function validateSignature(
73         CredentialsInterface $credentials,
74         $data,
75         $signatureHeader
76     ) {
77         $isSignatureValid = $this
78             ->signatureValidator
79             ->isSignatureValid(
80                 $data,
81                 $signatureHeader,
82                 $credentials
83             );
84 
85         if (!$isSignatureValid) {
86             throw new NotificationProcessException(sprintf(
87                 'Signature header "%s" for data "%s" is not correct.',
88                 $signatureHeader,
89                 $data
90             ));
91         }
92     }
93 }
94 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen