Passed
Pull Request — master (#4)
by Andrey
06:53 queued 03:48
created

IpnController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A endpointDebugAction() 0 17 3
A endpointAction() 0 9 1
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\Zed\Kernel\Communication\Controller\AbstractController;
11
use Symfony\Component\HttpFoundation\Response;
12
13
/**
14
 * @method \SprykerEco\Zed\Amazonpay\Business\AmazonpayFacadeInterface getFacade()
15
 */
16
class IpnController extends AbstractController
17
{
18
19
    /**
20
     * @return \Symfony\Component\HttpFoundation\Response
21
     */
22
    public function endpointAction()
23
    {
24
        $headers = getallheaders();
25
        $body = file_get_contents('php://input');
26
27
        $ipnRequestTransfer = $this->getFacade()->convertAmazonpayIpnRequest($headers, $body);
28
        $this->getFacade()->handleAmazonpayIpnRequest($ipnRequestTransfer);
29
30
        return new Response('Request has been processed');
31
    }
32
33
    /**
34
     * @return \Symfony\Component\HttpFoundation\Response
35
     */
36
    public function endpointDebugAction()
37
    {
38
        $headersRaw = unserialize(file_get_contents('./header.txt'), []);
39
40
        $headers = [];
41
        foreach ($headersRaw as $headerKey => $headerValue) {
42
            if (strpos($headerKey, 'Amz')) {
43
                $headers[strtolower($headerKey)] = $headerValue;
44
            }
45
        }
46
47
        $body = unserialize(file_get_contents('./body.txt'), []);
48
49
        $ipnRequestTransfer = $this->getFacade()->convertAmazonpayIpnRequest($headers, $body);
50
        $this->getFacade()->handleAmazonpayIpnRequest($ipnRequestTransfer);
51
52
        return new Response('Request has been processed');
53
    }
54
55
}
56