Completed
Push — master ( c9006d...35ee3d )
by Dmitry
01:40
created

CompletePurchaseRequest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 7.14%

Importance

Changes 0
Metric Value
wmc 11
lcom 2
cbo 5
dl 0
loc 56
ccs 2
cts 28
cp 0.0714
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendData() 0 4 1
C getData() 0 48 10
1
<?php
2
/**
3
 * OKPAY driver for Omnipay PHP payment library.
4
 *
5
 * @link      https://github.com/hiqdev/omnipay-okpay
6
 * @package   omnipay-okpay
7
 * @license   MIT
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace Omnipay\OKPAY\Message;
12
13
use Omnipay\Common\Exception\InvalidResponseException;
14
15
class CompletePurchaseRequest extends AbstractRequest
16
{
17
    public function getData()
18
    {
19
        $request = 'ok_verify=true';
20
21
        foreach ($this->httpRequest->request->all() as $key => $value) {
22
            $value = urlencode(stripslashes($value));
23
            $request .= "&$key=$value";
24
        }
25
26
        $fsocket = false;
27
        $result = false;
28
29
        if ($fp = @fsockopen('ssl://www.okpay.com', 443, $errno, $errstr, 30)) {
30
            // Connected via HTTPS
31
            $fsocket = true;
32
        } elseif ($fp = @fsockopen('www.okpay.com', 80, $errno, $errstr, 30)) {
33
            // Connected via HTTP
34
            $fsocket = true;
35
        }
36
37
        // If connected to OKPAY
38
        if ($fsocket === true) {
39
            $header = 'POST /ipn-verify.html HTTP/1.0' . "\r\n" .
40
                'Host: www.okpay.com' . "\r\n" .
41
                'Content-Type: application/x-www-form-urlencoded' . "\r\n" .
42
                'Content-Length: ' . strlen($request) . "\r\n" .
43
                'Connection: close' . "\r\n\r\n";
44
45
            @fputs($fp, $header . $request);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
46
            $string = '';
47
            while (!@feof($fp)) {
48
                $res = @fgets($fp, 1024);
49
                $string .= $res;
50
                // Find verification result in response
51
                if ($res === 'VERIFIED' || $res === 'INVALID' || $res === 'TEST') {
52
                    $result = $res;
53
                    break;
54
                }
55
            }
56
            @fclose($fp);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
57
        }
58
59
        if ($result !== 'VERIFIED') {
60
            throw new InvalidResponseException('IPN verify failed: ' . $result);
61
        }
62
63
        return $this->httpRequest->request->all();
64
    }
65
66 1
    public function sendData($data)
67
    {
68 1
        return $this->response = new CompletePurchaseResponse($this, $data);
69
    }
70
}
71