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\Serializer;
  6 
  7 use Psr\Log\LoggerInterface;
  8 use Team3\PayU\Order\Model\Buyer\DeliveryInterface;
  9 use Team3\PayU\Order\Model\Buyer\InvoiceInterface;
 10 use Team3\PayU\Order\Model\OrderInterface;
 11 use Team3\PayU\Order\Model\Products\ProductCollectionInterface;
 12 use Team3\PayU\Order\Model\ShippingMethods\ShippingMethodCollectionInterface;
 13 
 14 class GroupsSpecifier implements GroupsSpecifierInterface
 15 {
 16     const DEFAULT_GROUP = 'Default';
 17     const BUYER_GROUP = 'buyer';
 18     const INVOICE_GROUP = 'invoice';
 19     const DELIVERY_GROUP = 'delivery';
 20     const SHIPPING_METHODS_GROUP = 'shippingMethods';
 21     const PRODUCT_COLLECTION_GROUP = 'products';
 22 
 23     /**
 24      * @var string[]
 25      */
 26     private $groups;
 27 
 28     /**
 29      * @var LoggerInterface
 30      */
 31     private $logger;
 32 
 33     /**
 34      * @param LoggerInterface $logger
 35      */
 36     public function __construct(LoggerInterface $logger)
 37     {
 38         $this->logger = $logger;
 39     }
 40 
 41     /**
 42      * Not all orders parameters have to be serialized.
 43      * For example if buyer has no name, then whole buyer section should not be serialized.
 44      *
 45      * @param  OrderInterface $order
 46      * @return array
 47      */
 48     public function specifyGroups(OrderInterface $order)
 49     {
 50         $this->groups = [self::DEFAULT_GROUP];
 51 
 52         $this->checkBuyer($order);
 53         $this->checkShippingMethods($order->getShippingMethodCollection());
 54         $this->checkProducts($order->getProductCollection());
 55 
 56         $this->logSpecifiedGroups($order);
 57 
 58         return $this->groups;
 59     }
 60 
 61     /**
 62      * @param OrderInterface $order
 63      *
 64      * @return $this
 65      */
 66     private function checkBuyer(OrderInterface $order)
 67     {
 68         $buyer = $order->getBuyer();
 69         if ($buyer->isFilled()) {
 70             $this->groups[] = self::BUYER_GROUP;
 71         }
 72 
 73         return $this
 74             ->checkInvoice($buyer->getInvoice())
 75             ->checkDelivery($buyer->getDelivery());
 76     }
 77 
 78     /**
 79      * @param InvoiceInterface $invoice
 80      *
 81      * @return $this
 82      */
 83     private function checkInvoice(InvoiceInterface $invoice)
 84     {
 85         if ($invoice->isFilled()) {
 86             $this->groups[] = self::INVOICE_GROUP;
 87         }
 88 
 89         return $this;
 90     }
 91 
 92     /**
 93      * @param DeliveryInterface $delivery
 94      *
 95      * @return $this
 96      */
 97     private function checkDelivery(DeliveryInterface $delivery)
 98     {
 99         if ($delivery->isFilled()) {
100             $this->groups[] = self::DELIVERY_GROUP;
101         }
102 
103         return $this;
104     }
105 
106     /**
107      * @param ShippingMethodCollectionInterface $shippingMethodCollection
108      *
109      * @return $this
110      */
111     private function checkShippingMethods(
112         ShippingMethodCollectionInterface $shippingMethodCollection
113     ) {
114         if ($shippingMethodCollection->isFilled()) {
115             $this->groups[] = self::SHIPPING_METHODS_GROUP;
116         }
117 
118         return $this;
119     }
120 
121     /**
122      * @param ProductCollectionInterface $productCollection
123      *
124      * @return $this
125      */
126     private function checkProducts(
127         ProductCollectionInterface $productCollection
128     ) {
129         if ($productCollection->isFilled()) {
130             $this->groups[] = self::PRODUCT_COLLECTION_GROUP;
131         }
132 
133         return $this;
134     }
135 
136     /**
137      * @param OrderInterface $order
138      */
139     private function logSpecifiedGroups(OrderInterface $order)
140     {
141         $this
142             ->logger
143             ->debug(sprintf(
144                 'Serialization groups for order %s were specified to %s',
145                 $order->getOrderId(),
146                 print_r($this->groups, true)
147             ));
148     }
149 }
150 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen