-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRequest.php
143 lines (122 loc) · 2.59 KB
/
Request.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
namespace Devpark\PayboxGateway\Requests;
use Carbon\Carbon;
use Devpark\PayboxGateway\Currency;
use Devpark\PayboxGateway\Services\ServerSelector;
use Illuminate\Contracts\Config\Repository as Config;
use Devpark\PayboxGateway\Services\Amount;
abstract class Request
{
/**
* Type of gateway.
*
* @var string|null
*/
protected $type = null;
/**
* Selected server to send request.
*
* @var ServerSelector
*/
protected $serverSelector;
/**
* @var string|null
*/
protected $url = null;
/**
* @var Amount
*/
protected $amountService;
/**
* @var Config
*/
protected $config;
/**
* @var int|null
*/
protected $amount = null;
/**
* @var string|null
*/
protected $currencyCode = null;
/**
* @var string|null
*/
protected $time = null;
/**
* @var string|null
*/
protected $paymentNumber = null;
/**
* Whether extra filling should be done when formatting amount.
*
* @var bool
*/
protected $amountFill = false;
/**
* Request constructor.
*
* @param ServerSelector $serverSelector
* @param Config $config
* @param Amount $amountService
*/
public function __construct(
ServerSelector $serverSelector,
Config $config,
Amount $amountService
) {
$this->serverSelector = $serverSelector;
$this->config = $config;
$this->amountService = $amountService;
}
/**
* Get url for sending request.
*
* @return ServerSelector|string
*/
public function getUrl()
{
if ($this->url === null) {
$this->url = $this->serverSelector->find($this->type);
}
return $this->url;
}
/**
* Set amount and currency code.
*
* @param float $amount
* @param string $currencyCode
*
* @return $this
*/
public function setAmount($amount, $currencyCode = Currency::EUR)
{
$this->amount = $this->amountService->get($amount, $this->amountFill);
$this->currencyCode = $currencyCode;
return $this;
}
/**
* Set payment number.
*
* @param string $number
*
* @return $this
*/
public function setPaymentNumber($number)
{
$this->paymentNumber = $number;
return $this;
}
/**
* Set time.
*
* @param Carbon $date
*
* @return $this
*/
public function setTime(Carbon $date)
{
$this->time = $date;
return $this;
}
}