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\Validator;
 6 
 7 use Team3\PayU\SignatureCalculator\Encoder\Algorithms\AlgorithmInterface;
 8 
 9 class AlgorithmExtractor implements AlgorithmExtractorInterface
10 {
11     /**
12      * Will extract one algorithm name from signature header and
13      * search for algorithm with the same name in array passed as 2 parameter.
14      * If there is no algorithm with this name will throw exception.
15      *
16      * @param string               $signatureHeader
17      * @param AlgorithmInterface[] $algorithms      array of algorithms to search
18      *
19      * @throws AlgorithmExtractorException
20      * @return AlgorithmInterface
21      */
22     public function extractAlgorithm($signatureHeader, array $algorithms)
23     {
24         $algorithmName = $this->extractAlgorithmString($signatureHeader);
25 
26         foreach ($algorithms as $algorithm) {
27             if ($this->isNameEqual($algorithmName, $algorithm)) {
28                 return $algorithm;
29             }
30         }
31 
32         throw new AlgorithmExtractorException(sprintf(
33             'There is no algorithm with name %s.',
34             $algorithmName
35         ));
36     }
37 
38     /**
39      * @param string $signatureHeader
40      *
41      * @return string
42      * @throws AlgorithmExtractorException
43      */
44     private function extractAlgorithmString($signatureHeader)
45     {
46         $matches = [];
47         preg_match('/algorithm=([a-zA-Z0-9]+);/', $signatureHeader, $matches);
48         if (array_key_exists(1, $matches)) {
49             return $matches[1];
50         }
51 
52         throw new AlgorithmExtractorException(sprintf(
53             'Could not extract algorithm name from string "%s"',
54             $signatureHeader
55         ));
56     }
57 
58     /**
59      * @param string             $name
60      * @param AlgorithmInterface $algorithm
61      *
62      * @return bool
63      */
64     private function isNameEqual($name, AlgorithmInterface $algorithm)
65     {
66         return 0 === strcasecmp($name, $algorithm->getName());
67     }
68 }
69 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen