Overview
  • Namespace
  • Class

Namespaces

  • Mypos
    • IPC

Classes

  • Mypos\IPC\Base
  • Mypos\IPC\Card
  • Mypos\IPC\CardStore
  • Mypos\IPC\Cart
  • Mypos\IPC\Config
  • Mypos\IPC\Customer
  • Mypos\IPC\Defines
  • Mypos\IPC\GetTxnStatus
  • Mypos\IPC\Helper
  • Mypos\IPC\IAPurchase
  • Mypos\IPC\IAStoreCard
  • Mypos\IPC\IAStoredCardUpdate
  • Mypos\IPC\IPCGetTxnLog
  • Mypos\IPC\Loader
  • Mypos\IPC\MandateManagement
  • Mypos\IPC\Purchase
  • Mypos\IPC\Refund
  • Mypos\IPC\RequestMoney
  • Mypos\IPC\Response
  • Mypos\IPC\Reversal

Exceptions

  • Mypos\IPC\IPC_Exception
 1 <?php
 2 namespace Mypos\IPC;
 3 /**
 4  * Purchase cart object
 5  */
 6 class Cart{
 7 
 8     /**
 9      * Array containg cart items
10      * @var array 
11      */
12     private $cart;
13 
14     /**
15      * 
16      * @param string $itemName Item name
17      * @param int $quantity Items quantity 
18      * @param float $price Single item price
19      * @return Cart
20      * @throws IPC_Exception
21      */
22     public function add($itemName, $quantity, $price){
23         if(empty($itemName)){
24             throw new IPC_Exception('Invalid cart item name');
25         }
26 
27         if(empty($quantity) || !Helper::isValidCartQuantity($quantity)){
28             throw new IPC_Exception('Invalid cart item quantity');
29         }
30 
31         if(empty($price) || !Helper::isValidAmount($price)){
32             throw new IPC_Exception('Invalid cart item price');
33         }
34 
35         $this->cart[] = array(
36             'name' => $itemName,
37             'quantity' => $quantity,
38             'price' => $price
39         );
40         return $this;
41     }
42 
43     /**
44      * Return cart array
45      * @return array
46      */
47     public function getCart(){
48         return $this->cart;
49     }
50 
51     /**
52      * Returns cart total amount
53      * @return float
54      */
55     public function getTotal(){
56         $sum = 0;
57         if(!empty($this->cart)){
58             foreach($this->cart as $v){
59                 $sum += $v['quantity'] * $v['price'];
60             }
61         }
62         return $sum;
63     }
64 
65     /**
66      * Returns count of items in cart
67      * @return int
68      */
69     public function getItemsCount(){
70         return (is_array($this->cart) && !empty($this->cart)) ? count($this->cart) : 0;
71     }
72 
73     /**
74      * Validate cart items
75      * @return boolean
76      * @throws IPC_Exception
77      */
78     public function validate(){
79         if(!$this->getCart() || count($this->getCart()) == 0){
80             throw new IPC_Exception('Missing cart items');
81         }
82         return true;
83     }
84 
85 }
86 
API documentation generated by ApiGen