1 | <?php |
||
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); |
||
|
|||
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); |
||
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) |
|
70 | } |
||
71 |
If you suppress an error, we recommend checking for the error condition explicitly: