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\Transformer\UserOrder\Strategy\ShippingMethod;
 6 
 7 use Team3\PayU\Order\Model\ShippingMethods\ShippingMethod;
 8 use Team3\PayU\Order\Model\ShippingMethods\ShippingMethodInterface;
 9 use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties;
10 use Team3\PayU\Order\Transformer\UserOrder\TransformerPropertiesRegExp;
11 use Team3\PayU\PropertyExtractor\ExtractorInterface;
12 use Team3\PayU\PropertyExtractor\ExtractorResult;
13 
14 class SingleShippingMethodTransformer
15 {
16     /**
17      * @var ExtractorInterface
18      */
19     private $extractor;
20 
21     /**
22      * @param ExtractorInterface $extractor
23      */
24     public function __construct(
25         ExtractorInterface $extractor
26     ) {
27         $this->extractor = $extractor;
28     }
29 
30     /**
31      * @param mixed $usersShippingMethod
32      *
33      * @return ShippingMethod
34      */
35     public function transform($usersShippingMethod)
36     {
37         $shippingMethod = new ShippingMethod();
38 
39         foreach ($this->extractor->extract($usersShippingMethod) as $extractedResult) {
40             if ($this->supports($extractedResult->getPropertyName())) {
41                 $this->copyValue($shippingMethod, $extractedResult);
42             }
43         }
44 
45         return $shippingMethod;
46     }
47 
48     /**
49      * @param string $propertyName
50      *
51      * @return bool
52      */
53     protected function supports($propertyName)
54     {
55         return 1 === preg_match(
56             TransformerPropertiesRegExp::SHIPPING_METHOD_REGEXP,
57             $propertyName
58         );
59     }
60 
61     /**
62      * @param ShippingMethodInterface $shippingMethod
63      * @param ExtractorResult         $extractorResult
64      */
65     protected function copyValue(
66         ShippingMethodInterface $shippingMethod,
67         ExtractorResult $extractorResult
68     ) {
69         switch ($extractorResult->getPropertyName()) {
70             case TransformerProperties::SHIPPING_METHOD_NAME:
71                 $shippingMethod->setName($extractorResult->getValue());
72                 break;
73             case TransformerProperties::SHIPPING_METHOD_PRICE:
74                 $shippingMethod->setPrice($extractorResult->getValue());
75                 break;
76             case TransformerProperties::SHIPPING_METHOD_COUNTRY:
77                 $shippingMethod->setCountry($extractorResult->getValue());
78                 break;
79             default:
80         }
81     }
82 }
83 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen