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); |
|
|
|
|
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) |
67
|
|
|
{ |
68
|
1 |
|
return $this->response = new CompletePurchaseResponse($this, $data); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: