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\SignatureCalculator;
 6 
 7 use Team3\PayU\Configuration\Credentials\CredentialsInterface;
 8 use Team3\PayU\SignatureCalculator\Encoder\Algorithms\AlgorithmInterface;
 9 use Team3\PayU\SignatureCalculator\Encoder\EncoderException;
10 use Team3\PayU\SignatureCalculator\Encoder\EncoderInterface;
11 
12 /**
13  * {@inheritdoc}
14  *
15  * Class SignatureCalculator
16  * @package Team3\PayU\SignatureCalculator
17  */
18 class SignatureCalculator implements SignatureCalculatorInterface
19 {
20     /**
21      * @var EncoderInterface
22      */
23     private $encoder;
24 
25     /**
26      * @param EncoderInterface $encoder
27      */
28     public function __construct(EncoderInterface $encoder)
29     {
30         $this->encoder = $encoder;
31     }
32 
33     /**
34      * Calculates signature for any data given as an array of strings.
35      *
36      * @param string[]             $data
37      * @param CredentialsInterface $credentials private key is needed to calculate signature
38      * @param AlgorithmInterface   $algorithm   calculator uses encoder which can use multiple algorithms
39      *
40      * @return string
41      * @throws SignatureCalculatorException
42      */
43     public function calculate(
44         array $data,
45         CredentialsInterface $credentials,
46         AlgorithmInterface $algorithm
47     ) {
48         $concatenated = '';
49         array_walk_recursive($data, function ($value) use (&$concatenated) {
50             $concatenated .= $value;
51         });
52         $concatenated .= $credentials->getPrivateKey();
53 
54         return $this->encode($concatenated, $algorithm);
55     }
56 
57     /**
58      * Encode single string with given algorithm.
59      *
60      * @param string             $data
61      * @param AlgorithmInterface $algorithm
62      *
63      * @return string
64      * @throws SignatureCalculatorException
65      */
66     private function encode($data, AlgorithmInterface $algorithm)
67     {
68         try {
69             $encodedData = $this->encoder->encode($data, $algorithm);
70         } catch (EncoderException $exception) {
71             throw new SignatureCalculatorException(
72                 $exception->getMessage(),
73                 $exception->getCode(),
74                 $exception
75             );
76         }
77 
78         return $encodedData;
79     }
80 }
81 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen