Test Setup Failed
Push — master ( 4c62c0...259020 )
by Bruce Pinheiro de
02:12
created
src/Traits/PropertyHandler.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -11,48 +11,48 @@
 block discarded – undo
11 11
 
12 12
 trait PropertyHandler
13 13
 {
14
-	/**
15
-	 * @param array $data
16
-	 */
17
-	function fillProperties(array $data)
18
-	{
19
-		foreach ($data as $p => $v)
20
-		{
21
-			$this->fillProperty($p, $v);
22
-		}
23
-	}
14
+    /**
15
+     * @param array $data
16
+     */
17
+    function fillProperties(array $data)
18
+    {
19
+        foreach ($data as $p => $v)
20
+        {
21
+            $this->fillProperty($p, $v);
22
+        }
23
+    }
24 24
 
25
-	/**
26
-	 * @param string $property
27
-	 * @param mixed $value
28
-	 */
29
-	function fillProperty(string $property, $value)
30
-	{
31
-		$property = lcfirst(str_replace('_', '', ucwords($property, '_')));
32
-		if(property_exists(__CLASS__, $property))
33
-		{
34
-			$method = sprintf('set%s', ucfirst($property));
35
-			$this->{$method}($value);
36
-		}
37
-	}
25
+    /**
26
+     * @param string $property
27
+     * @param mixed $value
28
+     */
29
+    function fillProperty(string $property, $value)
30
+    {
31
+        $property = lcfirst(str_replace('_', '', ucwords($property, '_')));
32
+        if(property_exists(__CLASS__, $property))
33
+        {
34
+            $method = sprintf('set%s', ucfirst($property));
35
+            $this->{$method}($value);
36
+        }
37
+    }
38 38
 
39
-	/**
40
-	 * @return array
41
-	 */
42
-	function getPropertyArray(): array
43
-	{
44
-		$reflection = new \ReflectionClass(__CLASS__);
45
-		$properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED);
46
-		$data = [];
47
-		foreach($properties as $property){
48
-			$prop_name = $property->getName();
49
-			$method = sprintf('get%s', ucfirst($prop_name));
50
-			$form_name = strtolower(preg_replace('/[A-Z]/', '_$0', $prop_name));
51
-			if($reflection->hasMethod($method)){
52
-				$data[$form_name] = $this->{$method}();
53
-			}
54
-		}
55
-		return $data;
56
-	}
39
+    /**
40
+     * @return array
41
+     */
42
+    function getPropertyArray(): array
43
+    {
44
+        $reflection = new \ReflectionClass(__CLASS__);
45
+        $properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED);
46
+        $data = [];
47
+        foreach($properties as $property){
48
+            $prop_name = $property->getName();
49
+            $method = sprintf('get%s', ucfirst($prop_name));
50
+            $form_name = strtolower(preg_replace('/[A-Z]/', '_$0', $prop_name));
51
+            if($reflection->hasMethod($method)){
52
+                $data[$form_name] = $this->{$method}();
53
+            }
54
+        }
55
+        return $data;
56
+    }
57 57
 
58 58
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	function fillProperty(string $property, $value)
30 30
 	{
31 31
 		$property = lcfirst(str_replace('_', '', ucwords($property, '_')));
32
-		if(property_exists(__CLASS__, $property))
32
+		if (property_exists(__CLASS__, $property))
33 33
 		{
34 34
 			$method = sprintf('set%s', ucfirst($property));
35 35
 			$this->{$method}($value);
@@ -44,11 +44,11 @@  discard block
 block discarded – undo
44 44
 		$reflection = new \ReflectionClass(__CLASS__);
45 45
 		$properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED);
46 46
 		$data = [];
47
-		foreach($properties as $property){
47
+		foreach ($properties as $property) {
48 48
 			$prop_name = $property->getName();
49 49
 			$method = sprintf('get%s', ucfirst($prop_name));
50 50
 			$form_name = strtolower(preg_replace('/[A-Z]/', '_$0', $prop_name));
51
-			if($reflection->hasMethod($method)){
51
+			if ($reflection->hasMethod($method)) {
52 52
 				$data[$form_name] = $this->{$method}();
53 53
 			}
54 54
 		}
Please login to merge, or discard this patch.
src/SumUpClientInterface.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -5,11 +5,11 @@  discard block
 block discarded – undo
5 5
 
6 6
 interface SumUpClientInterface
7 7
 {
8
-	/**
9
-	 * CheckoutClientInterface constructor.
10
-	 * @param ContextInterface $context
11
-	 */
12
-	function __construct(ContextInterface $context);
8
+    /**
9
+     * CheckoutClientInterface constructor.
10
+     * @param ContextInterface $context
11
+     */
12
+    function __construct(ContextInterface $context);
13 13
 
14 14
     /**
15 15
      * Shows in an array all scopes required by the client
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
      */
19 19
     static function getScopes(): array;
20 20
 
21
-	/**
22
-	 * Return last response of client
23
-	 * @return ResponseInterface
24
-	 */
25
-	function getLastResponse(): ResponseInterface;
21
+    /**
22
+     * Return last response of client
23
+     * @return ResponseInterface
24
+     */
25
+    function getLastResponse(): ResponseInterface;
26 26
 
27
-	/**
28
-	 * return the context used to created the client.
29
-	 * @return ContextInterface
30
-	 */
31
-	function getContext(): ContextInterface;
27
+    /**
28
+     * return the context used to created the client.
29
+     * @return ContextInterface
30
+     */
31
+    function getContext(): ContextInterface;
32 32
 }
Please login to merge, or discard this patch.
src/SumUp.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,25 +7,25 @@
 block discarded – undo
7 7
 
8 8
 class SumUp
9 9
 {
10
-	const VERSION = 'v0.1';
11
-	const ENTRYPOINT = 'https://api.sumup.com/';
10
+    const VERSION = 'v0.1';
11
+    const ENTRYPOINT = 'https://api.sumup.com/';
12 12
 
13
-	/**
14
-	 * @return ClientInterface
15
-	 */
16
-	static function getClient(): ClientInterface
17
-	{
18
-		return new Client(
19
-			[
20
-				'base_uri' => self::getEntrypoint(),
21
-				'timeout' => 2
22
-			]
23
-		);
24
-	}
13
+    /**
14
+     * @return ClientInterface
15
+     */
16
+    static function getClient(): ClientInterface
17
+    {
18
+        return new Client(
19
+            [
20
+                'base_uri' => self::getEntrypoint(),
21
+                'timeout' => 2
22
+            ]
23
+        );
24
+    }
25 25
 
26
-	static function getEntrypoint(): string
27
-	{
28
-		return self::ENTRYPOINT.self::VERSION.'/';
29
-	}
26
+    static function getEntrypoint(): string
27
+    {
28
+        return self::ENTRYPOINT.self::VERSION.'/';
29
+    }
30 30
 }
31 31
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 
26 26
 	static function getEntrypoint(): string
27 27
 	{
28
-		return self::ENTRYPOINT.self::VERSION.'/';
28
+		return self::ENTRYPOINT . self::VERSION . '/';
29 29
 	}
30 30
 }
31 31
 
Please login to merge, or discard this patch.
src/Checkout/CheckoutClientInterface.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 interface CheckoutClientInterface extends SumUpClientInterface
10 10
 {
11 11
 
12
-	/**
12
+    /**
13 13
      * Create a checkout
14 14
      *
15 15
      * @param CheckoutInterface $checkout
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
      */
45 45
     static function getCheckoutBody(CheckoutInterface $checkout): array;
46 46
 
47
-	/**
48
-	 * Generate a body to a complete checkout request.
49
-	 *
50
-	 * @param CheckoutInterface $checkout
51
-	 * @return array
52
-	 */
47
+    /**
48
+     * Generate a body to a complete checkout request.
49
+     *
50
+     * @param CheckoutInterface $checkout
51
+     * @return array
52
+     */
53 53
     static function getCompleteCheckoutBody(CheckoutInterface $checkout): array;
54 54
 
55 55
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
      * @param AccessToken $accessToken
17 17
      * @return CheckoutInterface
18 18
      */
19
-    public function create(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface;
19
+    public function create(CheckoutInterface $checkout, AccessToken $accessToken = null): ? CheckoutInterface;
20 20
 
21 21
     /**
22 22
      * Retrieve a checkout from sumup.com server
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      * @param AccessToken $accessToken
26 26
      * @return CheckoutInterface
27 27
      */
28
-    public function get(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface;
28
+    public function get(CheckoutInterface $checkout, AccessToken $accessToken = null): ? CheckoutInterface;
29 29
 
30 30
     /**
31 31
      * Complete a checkout
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      * @param AccessToken $accessToken
35 35
      * @return CheckoutInterface
36 36
      */
37
-    public function complete(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface;
37
+    public function complete(CheckoutInterface $checkout, AccessToken $accessToken = null): ? CheckoutInterface;
38 38
 
39 39
     /**
40 40
      * Generate body to request a new checkout.
Please login to merge, or discard this patch.
src/Checkout/Checkout.php 2 patches
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -19,377 +19,377 @@
 block discarded – undo
19 19
  */
20 20
 class Checkout implements CheckoutInterface
21 21
 {
22
-	use PropertyHandler;
23
-
24
-	const PENDING = 'PENDING';
25
-	const COMPLETED = 'COMPLETED';
26
-	const FAILED = 'FAILED';
27
-
28
-	protected $id;
29
-	protected $status;
30
-	protected $amount;
31
-	protected $feeAmount;
32
-	protected $currency;
33
-	protected $payToEmail;
34
-	protected $payFromEmail;
35
-	protected $description;
36
-	protected $redirectUrl;
37
-	protected $validUntil;
38
-	protected $token;
39
-	protected $transactionId;
40
-	protected $transactionCode;
41
-	protected $type;
42
-	protected $installments;
43
-
44
-	/**
45
-	 * Checkout reference
46
-	 *
47
-	 * @var string
48
-	 */
49
-	protected $reference;
50
-
51
-	/**
52
-	 * Customer
53
-	 *
54
-	 * @var null|Customer
55
-	 */
56
-	protected $customer;
57
-
58
-	/**
59
-	 * Card
60
-	 *
61
-	 *
62
-	 * @var null|Card
63
-	 */
64
-	protected $card;
65
-
66
-
67
-	/**
68
-	 * checkout constructor
69
-	 *
70
-	 * @param array $data
71
-	 */
72
-	public function __construct(array $data = null) {
73
-		if ($data !== null) {
74
-			$this->setAmount($data['amount']??null);
75
-			$this->setPayToEmail($data['pay_to_email']??null);
76
-			$this->setCheckoutReference($data['checkout_reference']??null);
77
-			$this->setCurrency($data['currency']??null);
78
-			$this->setDescription($data['description']??null);
79
-			$this->setFeeAmount($data['fee_amount']??null);
80
-			$this->setPayFromEmail($data['pay_from_mail']??null);
81
-			$this->setId($data['id']??null);
82
-			$this->setRedirectUrl($data['redirect_url']??null);
83
-			$this->setStatus($data['status']??null);
84
-		}
85
-	}
86
-
87
-	/**
88
-	 * @inheritDoc
89
-	 */
90
-	public function isValid(): bool {
91
-		return $this->getReference() !== null
92
-			&& $this->getAmount() !== null
93
-			&& $this->getPayToEmail() !== null
94
-			&& Currency::isValid($this->getCurrency());
95
-	}
96
-
97
-	/**
98
-	 * @inheritDoc
99
-	 */
100
-	public function getId():? string {
101
-		return $this->id;
102
-	}
103
-
104
-	/**
105
-	 * @inheritDoc
106
-	 */
107
-	public function setId(?string $id): CheckoutInterface {
108
-		$this->id = $id;
109
-		return $this;
110
-	}
111
-
112
-	/**
113
-	 * @inheritDoc
114
-	 */
115
-	public function getStatus():? string {
116
-		return $this->status;
117
-	}
118
-
119
-	/**
120
-	 * @inheritDoc
121
-	 */
122
-	public function setStatus(?string $status): CheckoutInterface {
123
-		$this->status = $status;
124
-		return $this;
125
-	}
126
-
127
-	/**
128
-	 * @inheritDoc
129
-	 */
130
-	public function getAmount():? float {
131
-		return $this->amount;
132
-	}
133
-
134
-	/**
135
-	 * @inheritDoc
136
-	 */
137
-	public function setAmount(float $amount): CheckoutInterface {
138
-		$this->amount = $amount > 0 ? $amount : null;
139
-		return $this;
140
-	}
141
-
142
-	/**
143
-	 * @inheritDoc
144
-	 */
145
-	public function getCurrency():? string {
146
-		return $this->currency;
147
-	}
148
-
149
-	/**
150
-	 * @inheritDoc
151
-	 */
152
-	public function setCurrency(?string $currency): CheckoutInterface {
153
-		$this->currency = $currency;
154
-		return $this;
155
-	}
156
-
157
-	/**
158
-	 * @inheritDoc
159
-	 */
160
-	public function getPayToEmail():? string {
161
-		return $this->payToEmail;
162
-	}
163
-
164
-	/**
165
-	 * @inheritDoc
166
-	 */
167
-	public function setPayToEmail(string $email): CheckoutInterface {
168
-		$this->payToEmail = trim($email) === '' ? null : $email;
169
-		return $this;
170
-	}
171
-
172
-	/**
173
-	 * @inheritDoc
174
-	 */
175
-	public function getCheckoutReference():? string {
176
-		return $this->reference;
177
-	}
178
-
179
-	/**
180
-	 * @inheritDoc
181
-	 */
182
-	public function setCheckoutReference(string $reference): CheckoutInterface {
183
-		$this->reference = trim($reference) === '' ? null : $reference;
184
-		return $this;
185
-	}
186
-
187
-	/**
188
-	 * @inheritDoc
189
-	 */
190
-	public function getDescription():? string {
191
-		return $this->description;
192
-	}
193
-
194
-	/**
195
-	 * @inheritDoc
196
-	 */
197
-	public function setDescription(?string $description): CheckoutInterface {
198
-		$this->description = $description;
199
-		return $this;
200
-	}
201
-
202
-	/**
203
-	 * @inheritDoc
204
-	 */
205
-	public function getFeeAmount():? float {
206
-		return $this->feeAmount;
207
-	}
208
-
209
-	/**
210
-	 * @inheritDoc
211
-	 */
212
-	public function setFeeAmount(?float $fee): CheckoutInterface {
213
-		$this->feeAmount = $fee;
214
-		return $this;
215
-	}
216
-
217
-	/**
218
-	 * @inheritDoc
219
-	 */
220
-	public function getPayFromEmail():? string {
221
-		return $this->payFromEmail;
222
-	}
223
-
224
-	/**
225
-	 * @inheritDoc
226
-	 */
227
-	public function setPayFromEmail(?string $email): CheckoutInterface {
228
-		$this->payFromEmail = $email;
229
-		return $this;
230
-	}
231
-
232
-	/**
233
-	 * @inheritDoc
234
-	 */
235
-	public function getRedirectUrl():? string {
236
-		return $this->redirectUrl;
237
-	}
238
-
239
-	/**
240
-	 * @inheritDoc
241
-	 */
242
-	public function setRedirectUrl(?string $url): CheckoutInterface {
243
-		$this->redirectUrl = $url;
244
-		return $this;
245
-	}
246
-
247
-	function getValidUntil():? string {
248
-		return $this->validUntil;
249
-	}
250
-
251
-	function setValidUntil(?string $timestamp): CheckoutInterface {
252
-		$this->validUntil = $timestamp;
253
-		return $this;
254
-	}
255
-
256
-	function getTransactionCode():? string {
257
-		return $this->transactionCode;
258
-	}
259
-
260
-	function setTransactionCode(?string $code): CheckoutInterface {
261
-		$this->transactionCode = $code;
262
-		return $this;
263
-	}
264
-
265
-	function getTransactionId():? string {
266
-		return $this->transactionId;
267
-	}
268
-
269
-	function setTransactionId(?string $id): CheckoutInterface {
270
-		$this->transactionId = $id;
271
-		return $this;
272
-	}
273
-
274
-	function getTransactions():? array {
22
+    use PropertyHandler;
23
+
24
+    const PENDING = 'PENDING';
25
+    const COMPLETED = 'COMPLETED';
26
+    const FAILED = 'FAILED';
27
+
28
+    protected $id;
29
+    protected $status;
30
+    protected $amount;
31
+    protected $feeAmount;
32
+    protected $currency;
33
+    protected $payToEmail;
34
+    protected $payFromEmail;
35
+    protected $description;
36
+    protected $redirectUrl;
37
+    protected $validUntil;
38
+    protected $token;
39
+    protected $transactionId;
40
+    protected $transactionCode;
41
+    protected $type;
42
+    protected $installments;
43
+
44
+    /**
45
+     * Checkout reference
46
+     *
47
+     * @var string
48
+     */
49
+    protected $reference;
50
+
51
+    /**
52
+     * Customer
53
+     *
54
+     * @var null|Customer
55
+     */
56
+    protected $customer;
57
+
58
+    /**
59
+     * Card
60
+     *
61
+     *
62
+     * @var null|Card
63
+     */
64
+    protected $card;
65
+
66
+
67
+    /**
68
+     * checkout constructor
69
+     *
70
+     * @param array $data
71
+     */
72
+    public function __construct(array $data = null) {
73
+        if ($data !== null) {
74
+            $this->setAmount($data['amount']??null);
75
+            $this->setPayToEmail($data['pay_to_email']??null);
76
+            $this->setCheckoutReference($data['checkout_reference']??null);
77
+            $this->setCurrency($data['currency']??null);
78
+            $this->setDescription($data['description']??null);
79
+            $this->setFeeAmount($data['fee_amount']??null);
80
+            $this->setPayFromEmail($data['pay_from_mail']??null);
81
+            $this->setId($data['id']??null);
82
+            $this->setRedirectUrl($data['redirect_url']??null);
83
+            $this->setStatus($data['status']??null);
84
+        }
85
+    }
86
+
87
+    /**
88
+     * @inheritDoc
89
+     */
90
+    public function isValid(): bool {
91
+        return $this->getReference() !== null
92
+            && $this->getAmount() !== null
93
+            && $this->getPayToEmail() !== null
94
+            && Currency::isValid($this->getCurrency());
95
+    }
96
+
97
+    /**
98
+     * @inheritDoc
99
+     */
100
+    public function getId():? string {
101
+        return $this->id;
102
+    }
103
+
104
+    /**
105
+     * @inheritDoc
106
+     */
107
+    public function setId(?string $id): CheckoutInterface {
108
+        $this->id = $id;
109
+        return $this;
110
+    }
111
+
112
+    /**
113
+     * @inheritDoc
114
+     */
115
+    public function getStatus():? string {
116
+        return $this->status;
117
+    }
118
+
119
+    /**
120
+     * @inheritDoc
121
+     */
122
+    public function setStatus(?string $status): CheckoutInterface {
123
+        $this->status = $status;
124
+        return $this;
125
+    }
126
+
127
+    /**
128
+     * @inheritDoc
129
+     */
130
+    public function getAmount():? float {
131
+        return $this->amount;
132
+    }
133
+
134
+    /**
135
+     * @inheritDoc
136
+     */
137
+    public function setAmount(float $amount): CheckoutInterface {
138
+        $this->amount = $amount > 0 ? $amount : null;
139
+        return $this;
140
+    }
141
+
142
+    /**
143
+     * @inheritDoc
144
+     */
145
+    public function getCurrency():? string {
146
+        return $this->currency;
147
+    }
148
+
149
+    /**
150
+     * @inheritDoc
151
+     */
152
+    public function setCurrency(?string $currency): CheckoutInterface {
153
+        $this->currency = $currency;
154
+        return $this;
155
+    }
156
+
157
+    /**
158
+     * @inheritDoc
159
+     */
160
+    public function getPayToEmail():? string {
161
+        return $this->payToEmail;
162
+    }
163
+
164
+    /**
165
+     * @inheritDoc
166
+     */
167
+    public function setPayToEmail(string $email): CheckoutInterface {
168
+        $this->payToEmail = trim($email) === '' ? null : $email;
169
+        return $this;
170
+    }
171
+
172
+    /**
173
+     * @inheritDoc
174
+     */
175
+    public function getCheckoutReference():? string {
176
+        return $this->reference;
177
+    }
178
+
179
+    /**
180
+     * @inheritDoc
181
+     */
182
+    public function setCheckoutReference(string $reference): CheckoutInterface {
183
+        $this->reference = trim($reference) === '' ? null : $reference;
184
+        return $this;
185
+    }
186
+
187
+    /**
188
+     * @inheritDoc
189
+     */
190
+    public function getDescription():? string {
191
+        return $this->description;
192
+    }
193
+
194
+    /**
195
+     * @inheritDoc
196
+     */
197
+    public function setDescription(?string $description): CheckoutInterface {
198
+        $this->description = $description;
199
+        return $this;
200
+    }
201
+
202
+    /**
203
+     * @inheritDoc
204
+     */
205
+    public function getFeeAmount():? float {
206
+        return $this->feeAmount;
207
+    }
208
+
209
+    /**
210
+     * @inheritDoc
211
+     */
212
+    public function setFeeAmount(?float $fee): CheckoutInterface {
213
+        $this->feeAmount = $fee;
214
+        return $this;
215
+    }
216
+
217
+    /**
218
+     * @inheritDoc
219
+     */
220
+    public function getPayFromEmail():? string {
221
+        return $this->payFromEmail;
222
+    }
223
+
224
+    /**
225
+     * @inheritDoc
226
+     */
227
+    public function setPayFromEmail(?string $email): CheckoutInterface {
228
+        $this->payFromEmail = $email;
229
+        return $this;
230
+    }
231
+
232
+    /**
233
+     * @inheritDoc
234
+     */
235
+    public function getRedirectUrl():? string {
236
+        return $this->redirectUrl;
237
+    }
238
+
239
+    /**
240
+     * @inheritDoc
241
+     */
242
+    public function setRedirectUrl(?string $url): CheckoutInterface {
243
+        $this->redirectUrl = $url;
244
+        return $this;
245
+    }
246
+
247
+    function getValidUntil():? string {
248
+        return $this->validUntil;
249
+    }
250
+
251
+    function setValidUntil(?string $timestamp): CheckoutInterface {
252
+        $this->validUntil = $timestamp;
253
+        return $this;
254
+    }
255
+
256
+    function getTransactionCode():? string {
257
+        return $this->transactionCode;
258
+    }
259
+
260
+    function setTransactionCode(?string $code): CheckoutInterface {
261
+        $this->transactionCode = $code;
262
+        return $this;
263
+    }
264
+
265
+    function getTransactionId():? string {
266
+        return $this->transactionId;
267
+    }
268
+
269
+    function setTransactionId(?string $id): CheckoutInterface {
270
+        $this->transactionId = $id;
271
+        return $this;
272
+    }
273
+
274
+    function getTransactions():? array {
275 275
 //        return $this->transactions;
276
-		//TODO remember myself whats is it.
277
-		return [];
278
-	}
276
+        //TODO remember myself whats is it.
277
+        return [];
278
+    }
279 279
 
280
-	function setTransactions(?Array $transactions): CheckoutInterface {
280
+    function setTransactions(?Array $transactions): CheckoutInterface {
281 281
 //        $this->transactions = $transactions;
282
-		//TODO remember myself whats is it.
283
-		return $this;
284
-	}
285
-
286
-	function getToken():? string {
287
-		return $this->token;
288
-	}
289
-
290
-	function setToken(?string $token): CheckoutInterface {
291
-		$this->token = $token;
292
-		return $this;
293
-	}
294
-
295
-	/**
296
-	 * Get customer
297
-	 * @return CustomerInterface|null
298
-	 */
299
-	public function getCustomer(): ?CustomerInterface
300
-	{
301
-		return $this->customer;
302
-	}
303
-
304
-	/**
305
-	 * Set customer
306
-	 *
307
-	 * @param  null|CustomerInterface  $customer  Customer
308
-	 *
309
-	 * @return  CheckoutInterface
310
-	 */
311
-	public function setCustomer(?CustomerInterface $customer): CheckoutInterface
312
-	{
313
-		$this->customer = $customer;
314
-
315
-		return $this;
316
-	}
317
-
318
-	/**
319
-	 * Get card
320
-	 *
321
-	 * @return  null|CardInterface
322
-	 */
323
-	public function getCard(): ?CardInterface
324
-	{
325
-		return $this->card;
326
-	}
327
-
328
-	/**
329
-	 * Set card
330
-	 *
331
-	 * @param  null|CardInterface  $card
332
-	 *
333
-	 * @return  CheckoutInterface
334
-	 */
335
-	public function setCard(?CardInterface $card): CheckoutInterface
336
-	{
337
-		$this->card = $card;
338
-
339
-		return $this;
340
-	}
341
-
342
-	/**
343
-	 * Get checkout reference
344
-	 *
345
-	 * @return  string
346
-	 */
347
-	public function getReference(): ?string
348
-	{
349
-		return $this->reference;
350
-	}
351
-
352
-	/**
353
-	 * Set checkout reference
354
-	 *
355
-	 * @param  string  $reference  Checkout reference
356
-	 *
357
-	 * @return  CheckoutInterface
358
-	 */
359
-	public function setReference(?string $reference): CheckoutInterface
360
-	{
361
-		$this->reference = $reference;
362
-
363
-		return $this;
364
-	}
365
-
366
-	/**
367
-	 * @return mixed
368
-	 */
369
-	public function getType():? string
370
-	{
371
-		return $this->type;
372
-	}
373
-
374
-	/**
375
-	 * @param mixed $type
376
-	 * @return CheckoutInterface
377
-	 */
378
-	public function setType(?string $type = null): CheckoutInterface
379
-	{
380
-		$this->type = $type;
381
-
382
-		return $this;
383
-	}
384
-
385
-	public function setInstallments(?string $installments): CheckoutInterface{
386
-		$this->installments = $installments;
387
-		return $this;
388
-	}
389
-
390
-	public function getInstallments(): string
391
-	{
392
-		return $this->installments;
393
-	}
282
+        //TODO remember myself whats is it.
283
+        return $this;
284
+    }
285
+
286
+    function getToken():? string {
287
+        return $this->token;
288
+    }
289
+
290
+    function setToken(?string $token): CheckoutInterface {
291
+        $this->token = $token;
292
+        return $this;
293
+    }
294
+
295
+    /**
296
+     * Get customer
297
+     * @return CustomerInterface|null
298
+     */
299
+    public function getCustomer(): ?CustomerInterface
300
+    {
301
+        return $this->customer;
302
+    }
303
+
304
+    /**
305
+     * Set customer
306
+     *
307
+     * @param  null|CustomerInterface  $customer  Customer
308
+     *
309
+     * @return  CheckoutInterface
310
+     */
311
+    public function setCustomer(?CustomerInterface $customer): CheckoutInterface
312
+    {
313
+        $this->customer = $customer;
314
+
315
+        return $this;
316
+    }
317
+
318
+    /**
319
+     * Get card
320
+     *
321
+     * @return  null|CardInterface
322
+     */
323
+    public function getCard(): ?CardInterface
324
+    {
325
+        return $this->card;
326
+    }
327
+
328
+    /**
329
+     * Set card
330
+     *
331
+     * @param  null|CardInterface  $card
332
+     *
333
+     * @return  CheckoutInterface
334
+     */
335
+    public function setCard(?CardInterface $card): CheckoutInterface
336
+    {
337
+        $this->card = $card;
338
+
339
+        return $this;
340
+    }
341
+
342
+    /**
343
+     * Get checkout reference
344
+     *
345
+     * @return  string
346
+     */
347
+    public function getReference(): ?string
348
+    {
349
+        return $this->reference;
350
+    }
351
+
352
+    /**
353
+     * Set checkout reference
354
+     *
355
+     * @param  string  $reference  Checkout reference
356
+     *
357
+     * @return  CheckoutInterface
358
+     */
359
+    public function setReference(?string $reference): CheckoutInterface
360
+    {
361
+        $this->reference = $reference;
362
+
363
+        return $this;
364
+    }
365
+
366
+    /**
367
+     * @return mixed
368
+     */
369
+    public function getType():? string
370
+    {
371
+        return $this->type;
372
+    }
373
+
374
+    /**
375
+     * @param mixed $type
376
+     * @return CheckoutInterface
377
+     */
378
+    public function setType(?string $type = null): CheckoutInterface
379
+    {
380
+        $this->type = $type;
381
+
382
+        return $this;
383
+    }
384
+
385
+    public function setInstallments(?string $installments): CheckoutInterface{
386
+        $this->installments = $installments;
387
+        return $this;
388
+    }
389
+
390
+    public function getInstallments(): string
391
+    {
392
+        return $this->installments;
393
+    }
394 394
 
395 395
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	/**
98 98
 	 * @inheritDoc
99 99
 	 */
100
-	public function getId():? string {
100
+	public function getId(): ? string {
101 101
 		return $this->id;
102 102
 	}
103 103
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	/**
113 113
 	 * @inheritDoc
114 114
 	 */
115
-	public function getStatus():? string {
115
+	public function getStatus(): ? string {
116 116
 		return $this->status;
117 117
 	}
118 118
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	/**
128 128
 	 * @inheritDoc
129 129
 	 */
130
-	public function getAmount():? float {
130
+	public function getAmount(): ? float {
131 131
 		return $this->amount;
132 132
 	}
133 133
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	/**
143 143
 	 * @inheritDoc
144 144
 	 */
145
-	public function getCurrency():? string {
145
+	public function getCurrency(): ? string {
146 146
 		return $this->currency;
147 147
 	}
148 148
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	/**
158 158
 	 * @inheritDoc
159 159
 	 */
160
-	public function getPayToEmail():? string {
160
+	public function getPayToEmail(): ? string {
161 161
 		return $this->payToEmail;
162 162
 	}
163 163
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	/**
173 173
 	 * @inheritDoc
174 174
 	 */
175
-	public function getCheckoutReference():? string {
175
+	public function getCheckoutReference(): ? string {
176 176
 		return $this->reference;
177 177
 	}
178 178
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	/**
188 188
 	 * @inheritDoc
189 189
 	 */
190
-	public function getDescription():? string {
190
+	public function getDescription(): ? string {
191 191
 		return $this->description;
192 192
 	}
193 193
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	/**
203 203
 	 * @inheritDoc
204 204
 	 */
205
-	public function getFeeAmount():? float {
205
+	public function getFeeAmount(): ? float {
206 206
 		return $this->feeAmount;
207 207
 	}
208 208
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	/**
218 218
 	 * @inheritDoc
219 219
 	 */
220
-	public function getPayFromEmail():? string {
220
+	public function getPayFromEmail(): ? string {
221 221
 		return $this->payFromEmail;
222 222
 	}
223 223
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	/**
233 233
 	 * @inheritDoc
234 234
 	 */
235
-	public function getRedirectUrl():? string {
235
+	public function getRedirectUrl(): ? string {
236 236
 		return $this->redirectUrl;
237 237
 	}
238 238
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 		return $this;
245 245
 	}
246 246
 
247
-	function getValidUntil():? string {
247
+	function getValidUntil(): ? string {
248 248
 		return $this->validUntil;
249 249
 	}
250 250
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 		return $this;
254 254
 	}
255 255
 
256
-	function getTransactionCode():? string {
256
+	function getTransactionCode(): ? string {
257 257
 		return $this->transactionCode;
258 258
 	}
259 259
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 		return $this;
263 263
 	}
264 264
 
265
-	function getTransactionId():? string {
265
+	function getTransactionId(): ? string {
266 266
 		return $this->transactionId;
267 267
 	}
268 268
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 		return $this;
272 272
 	}
273 273
 
274
-	function getTransactions():? array {
274
+	function getTransactions(): ? array {
275 275
 //        return $this->transactions;
276 276
 		//TODO remember myself whats is it.
277 277
 		return [];
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 		return $this;
284 284
 	}
285 285
 
286
-	function getToken():? string {
286
+	function getToken(): ? string {
287 287
 		return $this->token;
288 288
 	}
289 289
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	/**
367 367
 	 * @return mixed
368 368
 	 */
369
-	public function getType():? string
369
+	public function getType(): ? string
370 370
 	{
371 371
 		return $this->type;
372 372
 	}
Please login to merge, or discard this patch.
src/Checkout/CheckoutClient.php 2 patches
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -16,169 +16,169 @@
 block discarded – undo
16 16
  */
17 17
 class CheckoutClient implements CheckoutClientInterface
18 18
 {
19
-	const ENDPOINT = 'checkouts';
20
-	protected $context;
21
-	protected $lastResponse;
22
-
23
-	function __construct(ContextInterface $context)
24
-	{
25
-		$this->context = $context;
26
-	}
27
-
28
-	/**
29
-	 * @inheritDoc
30
-	 * @throws BadResponseException
31
-	 * @throws ConnectException
32
-	 */
33
-	public function create(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface
34
-	{
35
-		return $this->request('post', $checkout, $accessToken, self::getScopes())? $checkout: null;
36
-	}
37
-
38
-	/**
39
-	 * @inheritDoc
40
-	 * @throws BadResponseException
41
-	 * @throws ConnectException
42
-	 */
43
-	public function get(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface
44
-	{
45
-		return $this->request('get', $checkout, $accessToken, self::getScopes())? $checkout: null;
46
-	}
47
-
48
-
49
-	/**
50
-	 * @inheritDoc
51
-	 * @throws BadResponseException
52
-	 * @throws ConnectException
53
-	 */
54
-	public function complete(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface
55
-	{
56
-		return $this->request('put', $checkout, $accessToken, self::getScopes())? $checkout: null;
57
-	}
58
-
59
-	/**
60
-	 * @param string $action
61
-	 * @param CheckoutInterface $checkout
62
-	 * @param AccessToken $accessToken
63
-	 * @param array $scopes
64
-	 * @return bool|null
65
-	 * @throws BadResponseException
66
-	 * @throws ConnectException
67
-	 */
68
-	protected function request(string $action, CheckoutInterface $checkout, AccessToken $accessToken, array $scopes):? bool
69
-	{
70
-		$accessToken = AuthenticationHelper::getValidToken($this->context, $accessToken, $scopes??self::getScopes());
71
-
72
-		$client = SumUp::getClient();
73
-		$options = AuthenticationHelper::getOAuthHeader($accessToken);
74
-		$options['form_params'] = self::getCheckoutBody($checkout);
75
-
76
-		$uri = self::ENDPOINT . '/' . $checkout->getId();
77
-		if($action=='post'){
78
-			$uri = self::ENDPOINT;
79
-		}
80
-
81
-		/** @var Response $response */
82
-		$response = $client->{$action}($uri, $options);
83
-		$this->lastResponse = $response;
84
-		if($response->getStatusCode() < 300 && $response->getStatusCode() >= 200){
85
-			$hydrator = SumUp::getHydrator();
86
-			$data = \GuzzleHttp\json_decode($response->getBody(), true);
87
-			$hydrator->hydrate($data, $checkout);
88
-			return true;
89
-		}
90
-
91
-		return false;
92
-	}
93
-
94
-	/**
95
-	 * Generate a body to create a new checkout
96
-	 *
97
-	 * @param CheckoutInterface $checkout
98
-	 * @return array
99
-	 */
100
-	public static function getCheckoutBody(CheckoutInterface $checkout): array
101
-	{
102
-		return [
103
-			"checkout_reference" => $checkout->getReference(),
104
-			"amount" => $checkout->getAmount(),
105
-			"currency" => $checkout->getCurrency(),
106
-			"fee_amount" => $checkout->getFeeAmount(),
107
-			"pay_to_email" => $checkout->getPayToEmail(),
108
-			"pay_from_email" => $checkout->getPayFromEmail(),
109
-			"description" => $checkout->getDescription(),
110
-			"return_url" => $checkout->getRedirectUrl(),
111
-		];
112
-	}
113
-
114
-	public static function getCompleteCheckoutBody(CheckoutInterface $checkout): array
115
-	{
116
-		$defaultBody = self::getCheckoutBody($checkout);
117
-		switch ($checkout->getType()) {
118
-			case 'card':
119
-				$completeBody = self::getCardBody($checkout);
120
-				break;
121
-
122
-			case 'boleto':
123
-				$completeBody = self::getBoletoBody($checkout);
124
-				break;
125
-
126
-			default:
127
-				$completeBody = [];
128
-		}
129
-
130
-		return array_merge($defaultBody, $completeBody);
131
-	}
132
-
133
-	private static function getCardBody(CheckoutInterface $checkout): array
134
-	{
135
-		return [
136
-			'payment_type' => $checkout->getType(),
137
-			'token' => $checkout->getCard()->getToken(),
138
-			'customer_id' => $checkout->getCustomer()->getCustomerId()
139
-		];
140
-	}
141
-
142
-	private static function getBoletoBody(CheckoutInterface $checkout): array
143
-	{
144
-		$customer = $checkout->getCustomer();
145
-		return [
146
-			'payment_type' => $checkout->getType(),
147
-			'description' => $checkout->getDescription(),
148
-			'boleto_details' => [
149
-				'cpf_cnpj' => $customer->getCpfCnpj(),
150
-				'payer_name' => $customer->getName(),
151
-				'payer_address' => $customer->getAddress(),
152
-				'payer_city' => $customer->getAddress()->getCity(),
153
-				'payer_state_code' => $customer->getAddress()->getState(),
154
-				'payer_post_code' => $customer->getAddress()->getPostalCode()
155
-			],
156
-		];
157
-	}
158
-
159
-	/**
160
-	 * @inheritDoc
161
-	 */
162
-	public static function getScopes(): array
163
-	{
164
-		return [
165
-			'payments',
166
-			'boleto'
167
-		];
168
-	}
169
-
170
-	function getLastResponse(): ResponseInterface
171
-	{
172
-		return $this->lastResponse;
173
-	}
174
-
175
-	/**
176
-	 * return the context used to created the client.
177
-	 * @return ContextInterface
178
-	 */
179
-	function getContext(): ContextInterface
180
-	{
181
-		return $this->context;
182
-	}
19
+    const ENDPOINT = 'checkouts';
20
+    protected $context;
21
+    protected $lastResponse;
22
+
23
+    function __construct(ContextInterface $context)
24
+    {
25
+        $this->context = $context;
26
+    }
27
+
28
+    /**
29
+     * @inheritDoc
30
+     * @throws BadResponseException
31
+     * @throws ConnectException
32
+     */
33
+    public function create(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface
34
+    {
35
+        return $this->request('post', $checkout, $accessToken, self::getScopes())? $checkout: null;
36
+    }
37
+
38
+    /**
39
+     * @inheritDoc
40
+     * @throws BadResponseException
41
+     * @throws ConnectException
42
+     */
43
+    public function get(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface
44
+    {
45
+        return $this->request('get', $checkout, $accessToken, self::getScopes())? $checkout: null;
46
+    }
47
+
48
+
49
+    /**
50
+     * @inheritDoc
51
+     * @throws BadResponseException
52
+     * @throws ConnectException
53
+     */
54
+    public function complete(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface
55
+    {
56
+        return $this->request('put', $checkout, $accessToken, self::getScopes())? $checkout: null;
57
+    }
58
+
59
+    /**
60
+     * @param string $action
61
+     * @param CheckoutInterface $checkout
62
+     * @param AccessToken $accessToken
63
+     * @param array $scopes
64
+     * @return bool|null
65
+     * @throws BadResponseException
66
+     * @throws ConnectException
67
+     */
68
+    protected function request(string $action, CheckoutInterface $checkout, AccessToken $accessToken, array $scopes):? bool
69
+    {
70
+        $accessToken = AuthenticationHelper::getValidToken($this->context, $accessToken, $scopes??self::getScopes());
71
+
72
+        $client = SumUp::getClient();
73
+        $options = AuthenticationHelper::getOAuthHeader($accessToken);
74
+        $options['form_params'] = self::getCheckoutBody($checkout);
75
+
76
+        $uri = self::ENDPOINT . '/' . $checkout->getId();
77
+        if($action=='post'){
78
+            $uri = self::ENDPOINT;
79
+        }
80
+
81
+        /** @var Response $response */
82
+        $response = $client->{$action}($uri, $options);
83
+        $this->lastResponse = $response;
84
+        if($response->getStatusCode() < 300 && $response->getStatusCode() >= 200){
85
+            $hydrator = SumUp::getHydrator();
86
+            $data = \GuzzleHttp\json_decode($response->getBody(), true);
87
+            $hydrator->hydrate($data, $checkout);
88
+            return true;
89
+        }
90
+
91
+        return false;
92
+    }
93
+
94
+    /**
95
+     * Generate a body to create a new checkout
96
+     *
97
+     * @param CheckoutInterface $checkout
98
+     * @return array
99
+     */
100
+    public static function getCheckoutBody(CheckoutInterface $checkout): array
101
+    {
102
+        return [
103
+            "checkout_reference" => $checkout->getReference(),
104
+            "amount" => $checkout->getAmount(),
105
+            "currency" => $checkout->getCurrency(),
106
+            "fee_amount" => $checkout->getFeeAmount(),
107
+            "pay_to_email" => $checkout->getPayToEmail(),
108
+            "pay_from_email" => $checkout->getPayFromEmail(),
109
+            "description" => $checkout->getDescription(),
110
+            "return_url" => $checkout->getRedirectUrl(),
111
+        ];
112
+    }
113
+
114
+    public static function getCompleteCheckoutBody(CheckoutInterface $checkout): array
115
+    {
116
+        $defaultBody = self::getCheckoutBody($checkout);
117
+        switch ($checkout->getType()) {
118
+            case 'card':
119
+                $completeBody = self::getCardBody($checkout);
120
+                break;
121
+
122
+            case 'boleto':
123
+                $completeBody = self::getBoletoBody($checkout);
124
+                break;
125
+
126
+            default:
127
+                $completeBody = [];
128
+        }
129
+
130
+        return array_merge($defaultBody, $completeBody);
131
+    }
132
+
133
+    private static function getCardBody(CheckoutInterface $checkout): array
134
+    {
135
+        return [
136
+            'payment_type' => $checkout->getType(),
137
+            'token' => $checkout->getCard()->getToken(),
138
+            'customer_id' => $checkout->getCustomer()->getCustomerId()
139
+        ];
140
+    }
141
+
142
+    private static function getBoletoBody(CheckoutInterface $checkout): array
143
+    {
144
+        $customer = $checkout->getCustomer();
145
+        return [
146
+            'payment_type' => $checkout->getType(),
147
+            'description' => $checkout->getDescription(),
148
+            'boleto_details' => [
149
+                'cpf_cnpj' => $customer->getCpfCnpj(),
150
+                'payer_name' => $customer->getName(),
151
+                'payer_address' => $customer->getAddress(),
152
+                'payer_city' => $customer->getAddress()->getCity(),
153
+                'payer_state_code' => $customer->getAddress()->getState(),
154
+                'payer_post_code' => $customer->getAddress()->getPostalCode()
155
+            ],
156
+        ];
157
+    }
158
+
159
+    /**
160
+     * @inheritDoc
161
+     */
162
+    public static function getScopes(): array
163
+    {
164
+        return [
165
+            'payments',
166
+            'boleto'
167
+        ];
168
+    }
169
+
170
+    function getLastResponse(): ResponseInterface
171
+    {
172
+        return $this->lastResponse;
173
+    }
174
+
175
+    /**
176
+     * return the context used to created the client.
177
+     * @return ContextInterface
178
+     */
179
+    function getContext(): ContextInterface
180
+    {
181
+        return $this->context;
182
+    }
183 183
 
184 184
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 	 * @throws BadResponseException
31 31
 	 * @throws ConnectException
32 32
 	 */
33
-	public function create(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface
33
+	public function create(CheckoutInterface $checkout, AccessToken $accessToken = null): ? CheckoutInterface
34 34
 	{
35
-		return $this->request('post', $checkout, $accessToken, self::getScopes())? $checkout: null;
35
+		return $this->request('post', $checkout, $accessToken, self::getScopes()) ? $checkout : null;
36 36
 	}
37 37
 
38 38
 	/**
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 	 * @throws BadResponseException
41 41
 	 * @throws ConnectException
42 42
 	 */
43
-	public function get(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface
43
+	public function get(CheckoutInterface $checkout, AccessToken $accessToken = null): ? CheckoutInterface
44 44
 	{
45
-		return $this->request('get', $checkout, $accessToken, self::getScopes())? $checkout: null;
45
+		return $this->request('get', $checkout, $accessToken, self::getScopes()) ? $checkout : null;
46 46
 	}
47 47
 
48 48
 
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 	 * @throws BadResponseException
52 52
 	 * @throws ConnectException
53 53
 	 */
54
-	public function complete(CheckoutInterface $checkout, AccessToken $accessToken = null):? CheckoutInterface
54
+	public function complete(CheckoutInterface $checkout, AccessToken $accessToken = null): ? CheckoutInterface
55 55
 	{
56
-		return $this->request('put', $checkout, $accessToken, self::getScopes())? $checkout: null;
56
+		return $this->request('put', $checkout, $accessToken, self::getScopes()) ? $checkout : null;
57 57
 	}
58 58
 
59 59
 	/**
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 * @throws BadResponseException
66 66
 	 * @throws ConnectException
67 67
 	 */
68
-	protected function request(string $action, CheckoutInterface $checkout, AccessToken $accessToken, array $scopes):? bool
68
+	protected function request(string $action, CheckoutInterface $checkout, AccessToken $accessToken, array $scopes): ? bool
69 69
 	{
70 70
 		$accessToken = AuthenticationHelper::getValidToken($this->context, $accessToken, $scopes??self::getScopes());
71 71
 
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 		$options['form_params'] = self::getCheckoutBody($checkout);
75 75
 
76 76
 		$uri = self::ENDPOINT . '/' . $checkout->getId();
77
-		if($action=='post'){
77
+		if ($action == 'post') {
78 78
 			$uri = self::ENDPOINT;
79 79
 		}
80 80
 
81 81
 		/** @var Response $response */
82 82
 		$response = $client->{$action}($uri, $options);
83 83
 		$this->lastResponse = $response;
84
-		if($response->getStatusCode() < 300 && $response->getStatusCode() >= 200){
84
+		if ($response->getStatusCode() < 300 && $response->getStatusCode() >= 200) {
85 85
 			$hydrator = SumUp::getHydrator();
86 86
 			$data = \GuzzleHttp\json_decode($response->getBody(), true);
87 87
 			$hydrator->hydrate($data, $checkout);
Please login to merge, or discard this patch.
src/Checkout/CheckoutInterface.php 2 patches
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -10,211 +10,211 @@
 block discarded – undo
10 10
  */
11 11
 interface CheckoutInterface
12 12
 {
13
-	/**
14
-	 * @return null|string
15
-	 */
16
-	function getId(): ?string;
17
-
18
-	/**
19
-	 * @param string $id
20
-	 * @return CheckoutInterface
21
-	 */
22
-	function setId(string $id): self;
23
-
24
-	/**
25
-	 * @return null|string
26
-	 */
27
-	function getStatus(): ?string;
28
-
29
-	/**
30
-	 * @param string $status
31
-	 * @return CheckoutInterface
32
-	 */
33
-	function setStatus(string $status): self;
34
-
35
-
36
-	/**
37
-	 * @param float $amount
38
-	 * @return CheckoutInterface
39
-	 */
40
-	function setAmount(float $amount): self;
41
-
42
-	/**
43
-	 * @return float
44
-	 */
45
-	function getAmount():? float;
46
-
47
-	/**
48
-	 * @return float|null
49
-	 */
50
-	function getFeeAmount(): ?float;
51
-
52
-	/**
53
-	 * @param float $amount
54
-	 * @return CheckoutInterface
55
-	 */
56
-	function setFeeAmount(float $amount): self;
57
-
58
-	/**
59
-	 * @return null|string
60
-	 */
61
-	function getCurrency(): ?string;
62
-
63
-	/**
64
-	 * @param string $currency
65
-	 * @return CheckoutInterface
66
-	 */
67
-	function setCurrency(string $currency): self;
68
-
69
-	/**
70
-	 * @return CustomerInterface|null
71
-	 */
72
-	function getCustomer(): ?CustomerInterface;
73
-
74
-	/**
75
-	 * @param CustomerInterface $customer
76
-	 * @return CheckoutInterface
77
-	 */
78
-	function setCustomer(CustomerInterface $customer): self;
79
-
80
-	/**
81
-	 * @return CardInterface|null
82
-	 */
83
-	function getCard(): ?CardInterface;
84
-
85
-	/**
86
-	 * @param CardInterface $card
87
-	 * @return CheckoutInterface
88
-	 */
89
-	function setCard(CardInterface $card): self;
90
-
91
-	/**
92
-	 * @return null|string
93
-	 */
94
-	function getPayToEmail(): ?string;
95
-
96
-	/**
97
-	 * @param string $email
98
-	 * @return CheckoutInterface
99
-	 */
100
-	function setPayToEmail(string $email): self;
101
-
102
-	/**
103
-	 * @return null|string
104
-	 */
105
-	function getPayFromEmail(): ?string;
106
-
107
-	/**
108
-	 * @param string $email
109
-	 * @return CheckoutInterface
110
-	 */
111
-	function setPayFromEmail(string $email): self;
112
-
113
-	/**
114
-	 * @return null|string
115
-	 */
116
-	function getReference(): ?string;
117
-
118
-	/**
119
-	 * @param string $reference
120
-	 * @return CheckoutInterface
121
-	 */
122
-	function setReference(string $reference): self;
123
-
124
-	/**
125
-	 * @return null|string
126
-	 */
127
-	function getDescription(): ?string;
128
-
129
-	/**
130
-	 * @param string $description
131
-	 * @return CheckoutInterface
132
-	 */
133
-	function setDescription(string $description): self;
134
-
135
-	/**
136
-	 * @return null|string
137
-	 */
138
-	function getRedirectUrl(): ?string;
139
-
140
-	/**
141
-	 * @param string $url
142
-	 * @return CheckoutInterface
143
-	 */
144
-	function setRedirectUrl(string $url): self;
145
-
146
-	/**
147
-	 * @return string
148
-	 */
149
-	function getValidUntil():? string;
150
-
151
-	/**
152
-	 * @param string $timestamp
153
-	 * @return CheckoutInterface
154
-	 */
155
-	function setValidUntil(string $timestamp): self;
156
-
157
-	/**
158
-	 * @return null|string
159
-	 */
160
-	function getTransactionCode(): ?string;
161
-
162
-	/**
163
-	 * @param string $code
164
-	 * @return CheckoutInterface
165
-	 */
166
-	function setTransactionCode(string $code): self;
167
-
168
-	/**
169
-	 * @return null|string
170
-	 */
171
-	function getTransactionId(): ?string;
172
-
173
-	/**
174
-	 * @param string $id
175
-	 * @return CheckoutInterface
176
-	 */
177
-	function setTransactionId(string $id): self;
178
-
179
-	/**
180
-	 * @return array|null
181
-	 */
182
-	function getTransactions(): ?array;
183
-
184
-	/**
185
-	 * @param array $transactions
186
-	 * @return CheckoutInterface
187
-	 */
188
-	function setTransactions(array $transactions): self;
189
-
190
-	/**
191
-	 * @return null|string
192
-	 */
193
-	function getToken(): ?string;
194
-
195
-	/**
196
-	 * @param string $token
197
-	 * @return CheckoutInterface
198
-	 */
199
-	function setToken(string $token): self;
200
-
201
-	/**
202
-	 * @return bool|null
203
-	 */
204
-	function isValid(): ?bool;
205
-
206
-	/**
207
-	 * @param string|null $type
208
-	 * @return CheckoutInterface
209
-	 */
210
-	function setType(string $type = null): self;
211
-
212
-	/**
213
-	 * @return null|string
214
-	 */
215
-	function getType():? string;
216
-
217
-	function setInstallments(?string $installments):? self;
218
-	function getInstallments():? string;
13
+    /**
14
+     * @return null|string
15
+     */
16
+    function getId(): ?string;
17
+
18
+    /**
19
+     * @param string $id
20
+     * @return CheckoutInterface
21
+     */
22
+    function setId(string $id): self;
23
+
24
+    /**
25
+     * @return null|string
26
+     */
27
+    function getStatus(): ?string;
28
+
29
+    /**
30
+     * @param string $status
31
+     * @return CheckoutInterface
32
+     */
33
+    function setStatus(string $status): self;
34
+
35
+
36
+    /**
37
+     * @param float $amount
38
+     * @return CheckoutInterface
39
+     */
40
+    function setAmount(float $amount): self;
41
+
42
+    /**
43
+     * @return float
44
+     */
45
+    function getAmount():? float;
46
+
47
+    /**
48
+     * @return float|null
49
+     */
50
+    function getFeeAmount(): ?float;
51
+
52
+    /**
53
+     * @param float $amount
54
+     * @return CheckoutInterface
55
+     */
56
+    function setFeeAmount(float $amount): self;
57
+
58
+    /**
59
+     * @return null|string
60
+     */
61
+    function getCurrency(): ?string;
62
+
63
+    /**
64
+     * @param string $currency
65
+     * @return CheckoutInterface
66
+     */
67
+    function setCurrency(string $currency): self;
68
+
69
+    /**
70
+     * @return CustomerInterface|null
71
+     */
72
+    function getCustomer(): ?CustomerInterface;
73
+
74
+    /**
75
+     * @param CustomerInterface $customer
76
+     * @return CheckoutInterface
77
+     */
78
+    function setCustomer(CustomerInterface $customer): self;
79
+
80
+    /**
81
+     * @return CardInterface|null
82
+     */
83
+    function getCard(): ?CardInterface;
84
+
85
+    /**
86
+     * @param CardInterface $card
87
+     * @return CheckoutInterface
88
+     */
89
+    function setCard(CardInterface $card): self;
90
+
91
+    /**
92
+     * @return null|string
93
+     */
94
+    function getPayToEmail(): ?string;
95
+
96
+    /**
97
+     * @param string $email
98
+     * @return CheckoutInterface
99
+     */
100
+    function setPayToEmail(string $email): self;
101
+
102
+    /**
103
+     * @return null|string
104
+     */
105
+    function getPayFromEmail(): ?string;
106
+
107
+    /**
108
+     * @param string $email
109
+     * @return CheckoutInterface
110
+     */
111
+    function setPayFromEmail(string $email): self;
112
+
113
+    /**
114
+     * @return null|string
115
+     */
116
+    function getReference(): ?string;
117
+
118
+    /**
119
+     * @param string $reference
120
+     * @return CheckoutInterface
121
+     */
122
+    function setReference(string $reference): self;
123
+
124
+    /**
125
+     * @return null|string
126
+     */
127
+    function getDescription(): ?string;
128
+
129
+    /**
130
+     * @param string $description
131
+     * @return CheckoutInterface
132
+     */
133
+    function setDescription(string $description): self;
134
+
135
+    /**
136
+     * @return null|string
137
+     */
138
+    function getRedirectUrl(): ?string;
139
+
140
+    /**
141
+     * @param string $url
142
+     * @return CheckoutInterface
143
+     */
144
+    function setRedirectUrl(string $url): self;
145
+
146
+    /**
147
+     * @return string
148
+     */
149
+    function getValidUntil():? string;
150
+
151
+    /**
152
+     * @param string $timestamp
153
+     * @return CheckoutInterface
154
+     */
155
+    function setValidUntil(string $timestamp): self;
156
+
157
+    /**
158
+     * @return null|string
159
+     */
160
+    function getTransactionCode(): ?string;
161
+
162
+    /**
163
+     * @param string $code
164
+     * @return CheckoutInterface
165
+     */
166
+    function setTransactionCode(string $code): self;
167
+
168
+    /**
169
+     * @return null|string
170
+     */
171
+    function getTransactionId(): ?string;
172
+
173
+    /**
174
+     * @param string $id
175
+     * @return CheckoutInterface
176
+     */
177
+    function setTransactionId(string $id): self;
178
+
179
+    /**
180
+     * @return array|null
181
+     */
182
+    function getTransactions(): ?array;
183
+
184
+    /**
185
+     * @param array $transactions
186
+     * @return CheckoutInterface
187
+     */
188
+    function setTransactions(array $transactions): self;
189
+
190
+    /**
191
+     * @return null|string
192
+     */
193
+    function getToken(): ?string;
194
+
195
+    /**
196
+     * @param string $token
197
+     * @return CheckoutInterface
198
+     */
199
+    function setToken(string $token): self;
200
+
201
+    /**
202
+     * @return bool|null
203
+     */
204
+    function isValid(): ?bool;
205
+
206
+    /**
207
+     * @param string|null $type
208
+     * @return CheckoutInterface
209
+     */
210
+    function setType(string $type = null): self;
211
+
212
+    /**
213
+     * @return null|string
214
+     */
215
+    function getType():? string;
216
+
217
+    function setInstallments(?string $installments):? self;
218
+    function getInstallments():? string;
219 219
 
220 220
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	/**
43 43
 	 * @return float
44 44
 	 */
45
-	function getAmount():? float;
45
+	function getAmount(): ? float;
46 46
 
47 47
 	/**
48 48
 	 * @return float|null
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	/**
147 147
 	 * @return string
148 148
 	 */
149
-	function getValidUntil():? string;
149
+	function getValidUntil(): ? string;
150 150
 
151 151
 	/**
152 152
 	 * @param string $timestamp
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 	/**
213 213
 	 * @return null|string
214 214
 	 */
215
-	function getType():? string;
215
+	function getType(): ? string;
216 216
 
217
-	function setInstallments(?string $installments):? self;
218
-	function getInstallments():? string;
217
+	function setInstallments(?string $installments): ? self;
218
+	function getInstallments(): ? string;
219 219
 
220 220
 }
Please login to merge, or discard this patch.
src/OAuth/AuthenticationHelper.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -10,108 +10,108 @@
 block discarded – undo
10 10
 
11 11
 class AuthenticationHelper
12 12
 {
13
-	const OAUTH_AUTHORIZATION = 'authorize';
14
-	const OAUTH_TOKEN = 'token';
15
-
16
-	/**
17
-	 * Generate an url to merchant authorization.
18
-	 *
19
-	 * @param ContextInterface $context
20
-	 * @param boolean $minimal
21
-	 * @return string
22
-	 */
23
-	public static function getAuthorizationURL(ContextInterface $context, $minimal = true)
24
-	{
25
-		$queryString = [
26
-			'client_id' => $context->getClientId(),
27
-			'client_secret' => $context->getClientSecret(),
28
-			'redirect_uri' => $context->getRedirectUri(),
29
-			'response_type' => 'code',
30
-		];
31
-
32
-		if (!$minimal) {
33
-			$queryString = array_merge($queryString, [
34
-				'scope' => $context->getScope(),
35
-				'state' => $context->getState(),
36
-			]);
37
-		}
38
-
39
-		return SumUp::ENTRYPOINT . self::OAUTH_AUTHORIZATION . '?' . http_build_query($queryString);
40
-	}
41
-
42
-	/**
43
-	 * Request an acess token from sumup services.
44
-	 *
45
-	 * @param Context $context
46
-	 * @param Array|null $scopes
47
-	 * @return AccessToken
48
-	 * @throws BadRequestException
49
-	 */
50
-	public static function getAccessToken(ContextInterface $context, array $scopes = null): AccessToken
51
-	{
52
-		$formParams = [
53
-			'grant_type' => 'client_credentials',
54
-			'client_id' => $context->getClientId(),
55
-			'client_secret' => $context->getClientSecret(),
56
-		];
57
-
58
-		if ($scopes !== null) {
59
-			$formParams['scope'] = implode(',', $scopes);
60
-		}
61
-
62
-		$client = new Client(['base_uri' => SumUp::ENTRYPOINT]);
63
-
64
-		$response = $client->request(
65
-			'POST',
66
-			self::OAUTH_TOKEN,
67
-			[
68
-				'form_params' => $formParams,
69
-			]);
70
-
71
-		$code = $response->getStatusCode();
72
-		if ($code !== 200) {
73
-			$message = " Request code: $code \n Message: " . $response->getReasonPhrase();
74
-			throw new BadRequestException($message);
75
-		}
76
-
77
-		$body = json_decode($response->getBody()->getContents(), true);
78
-		$token_params = [
79
-			$body['access_token'],
80
-			$body['token_type'],
81
-			$body['expires_in'],
82
-		];
83
-
84
-		if (isset($body['scope'])) {
85
-			$token_params[] = $body['scope'];
86
-		}
87
-
88
-		return new AccessToken(...$token_params);
89
-	}
90
-
91
-	/**
92
-	 * If available check token or generate a new token
93
-	 *
94
-	 * @param ContextInterface $context
95
-	 * @param AccessToken $token
96
-	 * @param array $scopes
97
-	 *
98
-	 * @return AccessToken
99
-	 */
100
-	public static function getValidToken(ContextInterface $context, AccessToken $token = null, array $scopes = null): AccessToken
101
-	{
102
-		if ($token === null || !$token->isValid()) {
103
-			$token = AuthenticationHelper::getAccessToken($context, $scopes);
104
-		}
105
-
106
-		return $token;
107
-	}
108
-
109
-	public static function getOAuthHeader(AccessToken $token): array
110
-	{
111
-		return [
112
-			'headers' => [
113
-				'Authorization' => $token->getType() . ' ' . $token->getToken(),
114
-			],
115
-		];
116
-	}
13
+    const OAUTH_AUTHORIZATION = 'authorize';
14
+    const OAUTH_TOKEN = 'token';
15
+
16
+    /**
17
+     * Generate an url to merchant authorization.
18
+     *
19
+     * @param ContextInterface $context
20
+     * @param boolean $minimal
21
+     * @return string
22
+     */
23
+    public static function getAuthorizationURL(ContextInterface $context, $minimal = true)
24
+    {
25
+        $queryString = [
26
+            'client_id' => $context->getClientId(),
27
+            'client_secret' => $context->getClientSecret(),
28
+            'redirect_uri' => $context->getRedirectUri(),
29
+            'response_type' => 'code',
30
+        ];
31
+
32
+        if (!$minimal) {
33
+            $queryString = array_merge($queryString, [
34
+                'scope' => $context->getScope(),
35
+                'state' => $context->getState(),
36
+            ]);
37
+        }
38
+
39
+        return SumUp::ENTRYPOINT . self::OAUTH_AUTHORIZATION . '?' . http_build_query($queryString);
40
+    }
41
+
42
+    /**
43
+     * Request an acess token from sumup services.
44
+     *
45
+     * @param Context $context
46
+     * @param Array|null $scopes
47
+     * @return AccessToken
48
+     * @throws BadRequestException
49
+     */
50
+    public static function getAccessToken(ContextInterface $context, array $scopes = null): AccessToken
51
+    {
52
+        $formParams = [
53
+            'grant_type' => 'client_credentials',
54
+            'client_id' => $context->getClientId(),
55
+            'client_secret' => $context->getClientSecret(),
56
+        ];
57
+
58
+        if ($scopes !== null) {
59
+            $formParams['scope'] = implode(',', $scopes);
60
+        }
61
+
62
+        $client = new Client(['base_uri' => SumUp::ENTRYPOINT]);
63
+
64
+        $response = $client->request(
65
+            'POST',
66
+            self::OAUTH_TOKEN,
67
+            [
68
+                'form_params' => $formParams,
69
+            ]);
70
+
71
+        $code = $response->getStatusCode();
72
+        if ($code !== 200) {
73
+            $message = " Request code: $code \n Message: " . $response->getReasonPhrase();
74
+            throw new BadRequestException($message);
75
+        }
76
+
77
+        $body = json_decode($response->getBody()->getContents(), true);
78
+        $token_params = [
79
+            $body['access_token'],
80
+            $body['token_type'],
81
+            $body['expires_in'],
82
+        ];
83
+
84
+        if (isset($body['scope'])) {
85
+            $token_params[] = $body['scope'];
86
+        }
87
+
88
+        return new AccessToken(...$token_params);
89
+    }
90
+
91
+    /**
92
+     * If available check token or generate a new token
93
+     *
94
+     * @param ContextInterface $context
95
+     * @param AccessToken $token
96
+     * @param array $scopes
97
+     *
98
+     * @return AccessToken
99
+     */
100
+    public static function getValidToken(ContextInterface $context, AccessToken $token = null, array $scopes = null): AccessToken
101
+    {
102
+        if ($token === null || !$token->isValid()) {
103
+            $token = AuthenticationHelper::getAccessToken($context, $scopes);
104
+        }
105
+
106
+        return $token;
107
+    }
108
+
109
+    public static function getOAuthHeader(AccessToken $token): array
110
+    {
111
+        return [
112
+            'headers' => [
113
+                'Authorization' => $token->getType() . ' ' . $token->getToken(),
114
+            ],
115
+        ];
116
+    }
117 117
 }
Please login to merge, or discard this patch.
src/Exception/InvalidCheckoutException.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,16 +6,16 @@
 block discarded – undo
6 6
 
7 7
 class InvalidCheckoutException extends \RuntimeException
8 8
 {
9
-	public function __construct($message = "",CheckoutInterface $checkout, $code = 0, Throwable $previous = null)
10
-	{
11
-		$message = sprintf(<<<MSG
9
+    public function __construct($message = "",CheckoutInterface $checkout, $code = 0, Throwable $previous = null)
10
+    {
11
+        $message = sprintf(<<<MSG
12 12
 		%s
13 13
 		Something is wrong with this checkout:
14 14
 		 checkout_reference: %s
15 15
 		 amount: %s
16 16
 		 pay_to_email: %s
17 17
 MSG
18
-		, $message, $checkout->getReference(), $checkout->getAmount(), $checkout->getPayToEmail());
19
-		parent::__construct($message, $code, $previous);
20
-	}
18
+        , $message, $checkout->getReference(), $checkout->getAmount(), $checkout->getPayToEmail());
19
+        parent::__construct($message, $code, $previous);
20
+    }
21 21
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 
7 7
 class InvalidCheckoutException extends \RuntimeException
8 8
 {
9
-	public function __construct($message = "",CheckoutInterface $checkout, $code = 0, Throwable $previous = null)
9
+	public function __construct($message = "", CheckoutInterface $checkout, $code = 0, Throwable $previous = null)
10 10
 	{
11 11
 		$message = sprintf(<<<MSG
12 12
 		%s
Please login to merge, or discard this patch.