1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Omnipay\Heidelpay\Message; |
5
|
|
|
|
6
|
|
|
use Omnipay\Common\Item; |
7
|
|
|
|
8
|
|
|
class CreateBasketRequest extends AbstractRequest |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @return array |
12
|
|
|
* @throws \Omnipay\Common\Exception\InvalidRequestException |
13
|
|
|
*/ |
14
|
|
|
public function getData() |
15
|
|
|
{ |
16
|
|
|
$this->validate('transactionId', 'currency', 'items', 'amount'); |
17
|
|
|
|
18
|
|
|
$data = [ |
19
|
|
|
'amountTotalGross' => $this->getAmountInteger() / 100, |
20
|
|
|
'currencyCode' => $this->getCurrency(), |
21
|
|
|
'orderId' => $this->getTransactionId(), |
22
|
|
|
'note' => $this->getDescription(), |
23
|
|
|
'basketItems' => $this->getItemsData() |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
if ($this->getTaxAmount()) { |
27
|
|
|
$data['amountTotalVat'] = $this->getTaxAmount(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if ($this->getDiscount()) { |
31
|
|
|
$data['amountTotalDiscount'] = $this->getDiscount(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $data; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public function getItemsData() |
41
|
|
|
{ |
42
|
|
|
$data = []; |
43
|
|
|
|
44
|
|
|
/** @var Item $item */ |
45
|
|
|
foreach ($this->getItems() as $item) { |
|
|
|
|
46
|
|
|
$data[] = [ |
47
|
|
|
'basketItemReferenceId' => uniqid(), |
48
|
|
|
'quantity' => $item->getQuantity(), |
49
|
|
|
'amountPerUnit' => $item->getPrice(), |
50
|
|
|
'amountGross' => $item->getPrice() * $item->getQuantity(), |
51
|
|
|
'title' => $item->getName(), |
52
|
|
|
'subTitle' => $item->getDescription() |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $data; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getTaxAmount() |
64
|
|
|
{ |
65
|
|
|
return $this->getParameter('tax_amount'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param $value |
70
|
|
|
* @return CreateBasketRequest |
71
|
|
|
*/ |
72
|
|
|
public function setTaxAmount($value) |
73
|
|
|
{ |
74
|
|
|
return $this->setParameter('tax_amount', $value); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function getDiscount() |
81
|
|
|
{ |
82
|
|
|
return $this->getParameter('discount'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param $value |
87
|
|
|
* @return CreateBasketRequest |
88
|
|
|
*/ |
89
|
|
|
public function setDiscount($value) |
90
|
|
|
{ |
91
|
|
|
return $this->setParameter('discount', $value); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function getEndpoint() |
98
|
|
|
{ |
99
|
|
|
return parent::getEndpoint().'baskets'; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.