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\Order\Autocomplete\Strategy;
 6 
 7 use Team3\PayU\Configuration\ConfigurationInterface;
 8 use Team3\PayU\Order\Autocomplete\OrderAutocompleteException;
 9 use Team3\PayU\Order\Model\OrderInterface;
10 use Team3\PayU\SignatureCalculator\SignatureCalculatorException;
11 use Team3\PayU\SignatureCalculator\OrderSignatureCalculatorInterface;
12 
13 class SignatureStrategy implements AutocompleteStrategyInterface
14 {
15     /**
16      * @var OrderSignatureCalculatorInterface
17      */
18     private $signatureCalculator;
19 
20     /**
21      * @param OrderSignatureCalculatorInterface $signatureCalculator
22      */
23     public function __construct(
24         OrderSignatureCalculatorInterface $signatureCalculator
25     ) {
26         $this->signatureCalculator = $signatureCalculator;
27     }
28 
29     /**
30      * @param OrderInterface $order
31      *
32      * @return bool
33      */
34     public function supports(OrderInterface $order)
35     {
36         return null === $order->getSignature();
37     }
38 
39     /**
40      * @param OrderInterface         $order
41      * @param ConfigurationInterface $configuration
42      */
43     public function autocomplete(
44         OrderInterface $order,
45         ConfigurationInterface $configuration
46     ) {
47         $order->setSignature(
48             $this->getSignature($order, $configuration)
49         );
50     }
51 
52     /**
53      * @param OrderInterface         $order
54      * @param ConfigurationInterface $configuration
55      *
56      * @return string
57      * @throws OrderAutocompleteException
58      */
59     private function getSignature(
60         OrderInterface $order,
61         ConfigurationInterface $configuration
62     ) {
63         try {
64             $signature = $this
65                 ->signatureCalculator
66                 ->calculate(
67                     $order,
68                     $configuration->getCredentials(),
69                     $configuration->getCredentials()->getSignatureAlgorithm()
70                 );
71         } catch (SignatureCalculatorException $exception) {
72             throw new OrderAutocompleteException(
73                 $exception->getMessage(),
74                 $exception->getCode(),
75                 $exception
76             );
77         }
78 
79         return $signature;
80     }
81 }
82 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen