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 Psr\Log\LoggerInterface;
  8 use Team3\PayU\Configuration\Credentials\CredentialsInterface;
  9 use Team3\PayU\Order\Model\OrderInterface;
 10 use Team3\PayU\SignatureCalculator\Encoder\Algorithms\AlgorithmInterface;
 11 use Team3\PayU\SignatureCalculator\Encoder\EncoderInterface;
 12 use Team3\PayU\SignatureCalculator\ParametersSorter\ParametersSorterInterface;
 13 
 14 /**
 15  * {@inheritdoc}
 16  *
 17  * Class OrderSignatureCalculator
 18  * @package Team3\PayU\SignatureCalculator
 19  */
 20 class OrderSignatureCalculator implements OrderSignatureCalculatorInterface
 21 {
 22     const SIGNATURE_FORMAT = 'signature=%s;algorithm=%s;sender=%s';
 23 
 24     /**
 25      * @var SignatureCalculatorInterface
 26      */
 27     private $signatureCalculator;
 28 
 29     /**
 30      * @var ParametersSorterInterface
 31      */
 32     private $parametersSorter;
 33 
 34     /**
 35      * @var LoggerInterface
 36      */
 37     private $logger;
 38 
 39     /**
 40      * @param EncoderInterface          $encoder
 41      * @param ParametersSorterInterface $parametersSorter
 42      * @param LoggerInterface           $logger
 43      */
 44     public function __construct(
 45         EncoderInterface $encoder,
 46         ParametersSorterInterface $parametersSorter,
 47         LoggerInterface $logger
 48     ) {
 49         $this->signatureCalculator = new SignatureCalculator($encoder);
 50         $this->parametersSorter = $parametersSorter;
 51         $this->logger = $logger;
 52     }
 53 
 54     /**
 55      * Calculates signature only for model which implements OrderInterface.
 56      * Signature for order is string with multiple variables described in SIGNATURE_FORMAT.
 57      * It uses SignatureCalculatorInterface to calculate one of the parameters.
 58      *
 59      * @param OrderInterface       $order
 60      * @param CredentialsInterface $credentials
 61      * @param AlgorithmInterface   $algorithm
 62      *
 63      * @return string
 64      * @throws SignatureCalculatorException
 65      */
 66     public function calculate(
 67         OrderInterface $order,
 68         CredentialsInterface $credentials,
 69         AlgorithmInterface $algorithm
 70     ) {
 71         $signature = $this->signatureCalculator->calculate(
 72             $this->getSortedParameters($order),
 73             $credentials,
 74             $algorithm
 75         );
 76 
 77         $signature = sprintf(
 78             self::SIGNATURE_FORMAT,
 79             $signature,
 80             $algorithm->getName(),
 81             $credentials->getMerchantPosId()
 82         );
 83 
 84         $this->logCalculatedSignature($order, $signature);
 85 
 86         return $signature;
 87     }
 88 
 89     /**
 90      * @param OrderInterface $order
 91      *
 92      * @return array
 93      */
 94     private function getSortedParameters(OrderInterface $order)
 95     {
 96         return $this->parametersSorter->getSortedParameters($order);
 97     }
 98 
 99     /**
100      * @param OrderInterface $order
101      * @param string         $signature
102      */
103     private function logCalculatedSignature(OrderInterface $order, $signature)
104     {
105         $this
106             ->logger
107             ->debug(sprintf(
108                 'Signature for order with id %s was calculated to "%s"',
109                 $order->getOrderId(),
110                 $signature
111             ));
112     }
113 }
114 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen