Completed
Push — dev ( b4e4a1...d62ac6 )
by Andrey
11s
created

IpnController::convertHeaders()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Apache OSL-2
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\AmazonPay\Communication\Controller;
9
10
use Spryker\Shared\Log\LoggerTrait;
11
use Spryker\Zed\Kernel\Communication\Controller\AbstractController;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
15
/**
16
 * @method \SprykerEco\Zed\AmazonPay\Business\AmazonPayFacadeInterface getFacade()
17
 */
18
class IpnController extends AbstractController
19
{
20
    use LoggerTrait;
21
22
    /**
23
     * @param \Symfony\Component\HttpFoundation\Request $request
24
     *
25
     * @return \Symfony\Component\HttpFoundation\Response
26
     */
27
    public function endpointAction(Request $request)
28
    {
29
        $headers = $this->convertHeaders($request->headers->all());
30
        $body = file_get_contents('php://input');
31
32
        $ipnRequestTransfer = $this->getFacade()->convertAmazonPayIpnRequest($headers, $body);
33
        $this->getFacade()->handleAmazonPayIpnRequest($ipnRequestTransfer);
34
35
        return new Response('Request has been processed');
36
    }
37
38
    /**
39
     * @param array $headers
40
     *
41
     * @return array
42
     */
43
    protected function convertHeaders(array $headers)
44
    {
45
        $assocHeaders = [];
46
47
        foreach ($headers as $key => $headerValues) {
48
            $assocHeaders[$key] = $headerValues[0];
49
        }
50
51
        return $assocHeaders;
52
    }
53
}
54