1: <?php
2:
3: namespace mcfedr\Paypal\Products;
4:
5: /**
6: * Describes a product to be sold
7: * Some vars effect selling
8: * Some are set when receiving a notification
9: */
10: abstract class Product {
11:
12: /**
13: * unique id of this product
14: * @var int
15: */
16: public $id;
17:
18: /**
19: * name of product
20: * @var string
21: */
22: public $name;
23:
24: /**
25: * Cost per item
26: * @var double
27: */
28: public $amount;
29:
30: /**
31: * total fee paid to paypal for these items
32: * Set when received by notification
33: * (ie you received {@link $total}-{@link $fee})
34: * @var double
35: */
36: public $fee;
37:
38: /**
39: * Get a product from $vars
40: *
41: * @param array $vars
42: * @param string $number use when more than one product eg '1', '2'
43: */
44: public function __construct($vars = null, $number = '') {
45: if (!is_null($vars)) {
46: if (isset($vars["item_number$number"])) {
47: $this->id = $vars["item_number$number"];
48: }
49: if (isset($vars["item_name$number"])) {
50: $this->name = $vars["item_name$number"];
51: }
52: if (isset($vars["mc_fee_$number"])) {
53: $this->fee = $vars["mc_fee_$number"];
54: }
55: else if (isset($vars["mc_fee$number"])) {
56: $this->fee = $vars["mc_fee$number"];
57: }
58: }
59: }
60:
61: /**
62: * Sets up the array with paypal vars for $product
63: *
64: * @param array $params
65: * @param string $suffix
66: */
67: public function setParams(&$params, $suffix = '') {
68: if (!empty($this->id)) {
69: $params["item_number$suffix"] = $this->id;
70: }
71: $params["item_name$suffix"] = substr($this->name, 0, 127);
72: }
73:
74: }
75: