1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHP version 5.4 and 8 |
5
|
|
|
* |
6
|
|
|
* @category RequestEntity |
7
|
|
|
* @package Payever\Payments |
8
|
|
|
* @author payever GmbH <[email protected]> |
9
|
|
|
* @copyright 2017-2021 payever GmbH |
10
|
|
|
* @license MIT <https://opensource.org/licenses/MIT> |
11
|
|
|
* @link https://docs.payever.org/shopsystems/api/getting-started |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Payever\ExternalIntegration\Payments\Http\RequestEntity; |
15
|
|
|
|
16
|
|
|
use Payever\ExternalIntegration\Core\Http\RequestEntity; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* This class represents Shipping Goods Payment RequestInterface Entity |
20
|
|
|
* |
21
|
|
|
* @method float getAmount() |
22
|
|
|
* @method self setAmount(float $amount) |
23
|
|
|
* @method string getReason() |
24
|
|
|
* @method self setReason(string $reason) |
25
|
|
|
* @method array getPaymentItems() |
26
|
|
|
* @method ShippingDetailsEntity getShippingDetails() |
27
|
|
|
*/ |
28
|
|
|
class ShippingGoodsPaymentRequest extends RequestEntity |
29
|
|
|
{ |
30
|
|
|
/** @var string $reason */ |
31
|
|
|
protected $reason; |
32
|
|
|
|
33
|
|
|
/** @var float $amount */ |
34
|
|
|
protected $amount; |
35
|
|
|
|
36
|
|
|
/** @var PaymentItemEntity[] $paymentItems */ |
37
|
|
|
protected $paymentItems; |
38
|
|
|
|
39
|
|
|
/** @var ShippingDetailsEntity $shippingDetails */ |
40
|
|
|
protected $shippingDetails; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Sets Payment Items |
44
|
|
|
* |
45
|
|
|
* @param array|string $paymentItems |
46
|
|
|
* |
47
|
|
|
* @return $this |
48
|
|
|
*/ |
49
|
|
|
public function setPaymentItems($paymentItems) |
50
|
|
|
{ |
51
|
|
|
if (!$paymentItems) { |
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (is_string($paymentItems)) { |
56
|
|
|
$paymentItems = json_decode($paymentItems); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (!is_array($paymentItems)) { |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->paymentItems = []; |
64
|
|
|
|
65
|
|
|
foreach ($paymentItems as $item) { |
66
|
|
|
$this->paymentItems[] = new PaymentItemEntity($item); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Sets shipping details |
74
|
|
|
* |
75
|
|
|
* @param ShippingDetailsEntity|string $shippingDetails |
76
|
|
|
* |
77
|
|
|
* @return $this |
78
|
|
|
*/ |
79
|
|
|
public function setShippingDetails($shippingDetails) |
80
|
|
|
{ |
81
|
|
|
if (!$shippingDetails) { |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if (is_string($shippingDetails)) { |
86
|
|
|
$shippingDetails = json_decode($shippingDetails); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
if (!is_array($shippingDetails) && !is_object($shippingDetails)) { |
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$this->shippingDetails = new ShippingDetailsEntity($shippingDetails); |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritdoc} |
100
|
|
|
*/ |
101
|
|
|
public function isValid() |
102
|
|
|
{ |
103
|
|
|
if (is_array($this->paymentItems)) { |
|
|
|
|
104
|
|
|
foreach ($this->paymentItems as $item) { |
105
|
|
|
if (!$item instanceof PaymentItemEntity || !$item->isValid()) { |
106
|
|
|
return false; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return parent::isValid() && (!$this->paymentItems || is_array($this->paymentItems)); |
|
|
|
|
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|