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\Product;
 6 
 7 use Team3\PayU\Order\Model\Products\Product;
 8 use Team3\PayU\Order\Model\Products\ProductInterface;
 9 use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties;
10 use Team3\PayU\PropertyExtractor\ExtractorInterface;
11 use Team3\PayU\PropertyExtractor\ExtractorResult;
12 
13 class SingleProductTransformer
14 {
15     /**
16      * @var ExtractorInterface
17      */
18     private $extractor;
19 
20     /**
21      * @param ExtractorInterface $extractor
22      */
23     public function __construct(ExtractorInterface $extractor)
24     {
25         $this->extractor = $extractor;
26     }
27 
28     /**
29      * @param $userProduct
30      *
31      * @return ProductInterface
32      */
33     public function transform($userProduct)
34     {
35         $product = new Product();
36 
37         foreach ($this->getExtractedAnnotations($userProduct) as $extractionResult) {
38             $this->transformParameter($product, $extractionResult);
39         }
40 
41         return $product;
42     }
43 
44     /**
45      * @param object $userProduct
46      *
47      * @return ExtractorResult[]
48      */
49     private function getExtractedAnnotations($userProduct)
50     {
51         return $this
52             ->extractor
53             ->extract($userProduct);
54     }
55 
56     /**
57      * @param ProductInterface $product
58      * @param ExtractorResult  $extractionResult
59      */
60     private function transformParameter(
61         ProductInterface $product,
62         ExtractorResult $extractionResult
63     ) {
64         switch ($extractionResult->getPropertyName()) {
65             case TransformerProperties::PRODUCT_UNIT_PRICE:
66                 $product->setUnitPrice($extractionResult->getValue());
67                 break;
68             case TransformerProperties::PRODUCT_QUANTITY:
69                 $product->setQuantity($extractionResult->getValue());
70                 break;
71             case TransformerProperties::PRODUCT_NAME:
72                 $product->setName($extractionResult->getValue());
73                 break;
74             default:
75         }
76     }
77 }
78 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen