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\Model\Money\Money;
 9 use Team3\PayU\Order\Model\Money\MoneyInterface;
10 use Team3\PayU\Order\Model\OrderInterface;
11 use Team3\PayU\Order\Model\Products\ProductCollectionInterface;
12 use Team3\PayU\Order\Model\Products\ProductInterface;
13 
14 class TotalAmountStrategy implements AutocompleteStrategyInterface
15 {
16     /**
17      * @param OrderInterface $order
18      *
19      * @return bool
20      */
21     public function supports(OrderInterface $order)
22     {
23         return 0 == $order->getTotalAmount()->getValue()
24             && 0 < $order->getProductCollection()->count();
25     }
26 
27     /**
28      * @param OrderInterface         $order
29      * @param ConfigurationInterface $configuration
30      */
31     public function autocomplete(
32         OrderInterface $order,
33         ConfigurationInterface $configuration
34     ) {
35         $order->setTotalAmount(
36             $this->getProductsCost(
37                 $order->getProductCollection()
38             )
39         );
40     }
41 
42     /**
43      * @param ProductCollectionInterface $productCollection
44      *
45      * @return MoneyInterface
46      */
47     private function getProductsCost(
48         ProductCollectionInterface $productCollection
49     ) {
50         $totalAmount = new Money(0);
51 
52         /** @var ProductInterface $product */
53         foreach ($productCollection as $product) {
54             // $totalAmount += $unitPrice * $quantity
55             $totalAmount = $totalAmount->add(
56                 $product->getUnitPrice()->multiply(
57                     $product->getQuantity()
58                 )
59             );
60         }
61 
62         return $totalAmount;
63     }
64 }
65 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen