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\OrderInterface;
 8 use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties;
 9 use Team3\PayU\PropertyExtractor\ExtractorException;
10 use Team3\PayU\PropertyExtractor\ExtractorResult;
11 use Team3\PayU\Order\Transformer\UserOrder\Strategy\UserOrderTransformerStrategyInterface;
12 
13 class ShippingMethodCollectionTransformer implements UserOrderTransformerStrategyInterface
14 {
15     /**
16      * @var SingleShippingMethodTransformer
17      */
18     private $singleShippingMethodTransformer;
19 
20     /**
21      * @param SingleShippingMethodTransformer $singleShippingMethodTransformer
22      */
23     public function __construct(
24         SingleShippingMethodTransformer $singleShippingMethodTransformer
25     ) {
26         $this->singleShippingMethodTransformer = $singleShippingMethodTransformer;
27     }
28 
29     /**
30      * @inheritdoc
31      */
32     public function transform(
33         OrderInterface $order,
34         ExtractorResult $extractorResult
35     ) {
36         /** @var \Traversable $shippingMethodCollection */
37         $shippingMethodCollection = $extractorResult->getValue();
38         $this->checkCollection($shippingMethodCollection);
39 
40         foreach ($shippingMethodCollection as $usersShippingMethod) {
41             $order
42                 ->getShippingMethodCollection()
43                 ->addShippingMethod(
44                     $this
45                         ->singleShippingMethodTransformer
46                         ->transform(
47                             $usersShippingMethod
48                         )
49                 );
50         }
51     }
52 
53     /**
54      * @inheritdoc
55      */
56     public function supports($propertyName)
57     {
58         return TransformerProperties::SHIPPING_METHOD_COLLECTION === $propertyName;
59     }
60 
61     /**
62      * @param mixed $collection
63      *
64      * @throws ExtractorException
65      */
66     protected function checkCollection($collection)
67     {
68         if (!is_array($collection)
69             && !$collection instanceof \Traversable) {
70             throw new ExtractorException(sprintf(
71                 'Array or object which implements Traversable was expected, but %s was given',
72                 gettype($collection)
73             ));
74         }
75     }
76 }
77 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen