/
HttpPostRedirect.php
79 lines (69 loc) · 1.67 KB
/
HttpPostRedirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Payum\Core\Reply;
class HttpPostRedirect extends HttpResponse
{
/**
* @var string
*/
protected $url;
/**
* @var array
*/
protected $fields;
/**
* @param string $url
* @param int $statusCode
* @param string[] $headers
*/
public function __construct($url, array $fields = [], $statusCode = 200, array $headers = [])
{
$this->url = $url;
$this->fields = $fields;
parent::__construct($this->prepareContent($url, $fields), $statusCode, $headers);
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @return array
*/
public function getFields()
{
return $this->fields;
}
/**
* @param string $url
*
* @return string
*/
protected function prepareContent($url, array $fields)
{
$formInputs = '';
foreach ($fields as $name => $value) {
$formInputs .= sprintf(
'<input type="hidden" name="%1$s" value="%2$s" />',
htmlspecialchars((string) $name, ENT_QUOTES, 'UTF-8'),
htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8')
) . "\n";
}
$content = <<<'HTML'
<!DOCTYPE html>
<html>
<head>
<title>Redirecting...</title>
</head>
<body onload="document.forms[0].submit();">
<form action="%1$s" method="post">
<p>Redirecting to payment page...</p>
<p>%2$s</p>
</form>
</body>
</html>
HTML;
return sprintf($content, htmlspecialchars((string) $url, ENT_QUOTES, 'UTF-8'), $formInputs);
}
}