This repository has been archived by the owner on May 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Basket.php
83 lines (71 loc) · 1.61 KB
/
Basket.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Hochstrasser\Wirecard\Model\Common;
use Hochstrasser\Wirecard\Model\Model;
class Basket extends Model
{
private $items = [];
/**
* Sets total amount of shopping basket
*
* @param float $amount
* @return Basket
*/
function setAmount($amount)
{
return $this->addParam('amount', $amount);
}
/**
* Returns total amount of shopping basket
*
* @return float
*/
function getAmount()
{
return $this->getParam('amount');
}
/**
* Sets currency as ISO code or numeric identifier
*
* @param string|int $currency
* @return Basket
*/
function setCurrency($currency)
{
return $this->addParam('currency', $currency);
}
/**
* Returns the currency as ISO code or numeric identifier
*
* @returns string|int
*/
function getCurrency()
{
return $this->getParam('currency');
}
/**
* Adds an item to the basket
*
* @param BasketItem $item
* @return Basket
*/
function addItem(BasketItem $item)
{
$basketItems = $this->getParam('basketItems') ?: 0;
$basketItems++;
$this->items[$basketItems] = $item;
$this->addParam('basketItems', $basketItems);
foreach ($item->toArray() as $param => $value) {
$this->addParam('basketItem'.$basketItems.ucfirst($param), $value);
}
return $this;
}
/**
* Returns a list of added BasketItem objects
*
* @return array
*/
function getItems()
{
return $this->items;
}
}