1
|
|
|
<?php |
2
|
|
|
namespace PHPSC\PagSeguro\Requests\Checkout; |
3
|
|
|
|
4
|
|
|
use PHPSC\PagSeguro\Customer\Customer; |
5
|
|
|
use PHPSC\PagSeguro\Items\Item; |
6
|
|
|
use PHPSC\PagSeguro\Requests\CheckoutBuilder as CheckoutBuilderInterface; |
7
|
|
|
use PHPSC\PagSeguro\Shipping\Shipping; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class CheckoutBuilder implements CheckoutBuilderInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Checkout |
16
|
|
|
*/ |
17
|
|
|
private $checkout; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param Checkout $checkout |
21
|
|
|
*/ |
22
|
12 |
|
public function __construct(Checkout $checkout = null) |
23
|
|
|
{ |
24
|
12 |
|
$this->checkout = $checkout ?: new Checkout(); |
25
|
12 |
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
1 |
|
public function addItem(Item $item) |
31
|
|
|
{ |
32
|
1 |
|
$this->checkout->getOrder()->getItems()->add($item); |
33
|
|
|
|
34
|
1 |
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
1 |
|
public function setShipping(Shipping $shipping) |
41
|
|
|
{ |
42
|
1 |
|
$this->checkout->getOrder()->setShipping($shipping); |
43
|
|
|
|
44
|
1 |
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
1 |
|
public function setReference($reference) |
51
|
|
|
{ |
52
|
1 |
|
$this->checkout->getOrder()->setReference($reference); |
53
|
|
|
|
54
|
1 |
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
1 |
|
public function setShippingAddressRequired($shippingAddressRequired) |
61
|
|
|
{ |
62
|
1 |
|
$this->checkout->getOrder()->setShippingAddressRequired($shippingAddressRequired); |
63
|
|
|
|
64
|
1 |
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
1 |
|
public function setCustomer(Customer $customer) |
71
|
|
|
{ |
72
|
1 |
|
$this->checkout->setCustomer($customer); |
73
|
|
|
|
74
|
1 |
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
1 |
|
public function setRedirectTo($redirectTo) |
81
|
|
|
{ |
82
|
1 |
|
$this->checkout->setRedirectTo($redirectTo); |
83
|
|
|
|
84
|
1 |
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
1 |
|
public function setMaxAge($maxAge) |
91
|
|
|
{ |
92
|
1 |
|
$this->checkout->setMaxAge($maxAge); |
93
|
|
|
|
94
|
1 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
1 |
|
public function setMaxUses($maxUses) |
101
|
|
|
{ |
102
|
1 |
|
$this->checkout->setMaxUses($maxUses); |
103
|
|
|
|
104
|
1 |
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* {@inheritdoc} |
109
|
|
|
*/ |
110
|
|
|
public function setExtraAmount($extraAmount) |
111
|
|
|
{ |
112
|
|
|
$this->checkout->getOrder()->setExtraAmount($extraAmount); |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* {@inheritdoc} |
119
|
|
|
*/ |
120
|
1 |
|
public function getCheckout() |
121
|
|
|
{ |
122
|
1 |
|
return $this->checkout; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|