1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Orders\Tests\TestOnly\Controller; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Orders\Tests\Factory\OrderFactoryTest; |
6
|
|
|
use SilverStripe\Control\Controller; |
7
|
|
|
use SilverStripe\Control\HTTPRequest; |
8
|
|
|
use SilverStripe\Control\HTTPResponse; |
9
|
|
|
use SilverStripe\Dev\TestOnly; |
10
|
|
|
use SilverStripe\ORM\ArrayList; |
11
|
|
|
use SilverStripe\Security\PasswordEncryptor; |
12
|
|
|
use SilverStripe\Security\PasswordEncryptor_NotFoundException; |
13
|
|
|
use SilverStripe\View\ArrayData; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class FoxyDataTestController |
17
|
|
|
* @package Dynamic\Foxy\Orders\Tests\TestOnly\Controller |
18
|
|
|
*/ |
19
|
|
|
class FoxyDataTestController extends Controller implements TestOnly |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string[] |
23
|
|
|
*/ |
24
|
|
|
private static $allowed_actions = [ |
|
|
|
|
25
|
|
|
'foxytestdata', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param null $action |
|
|
|
|
30
|
|
|
* @return string|null |
31
|
|
|
*/ |
32
|
|
|
public function Link($action = null) |
33
|
|
|
{ |
34
|
|
|
return '/foxytestdata'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param HTTPRequest $request |
39
|
|
|
* @return HTTPResponse |
40
|
|
|
* @throws PasswordEncryptor_NotFoundException |
41
|
|
|
*/ |
42
|
|
|
public function index(HTTPRequest $request) |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
return HTTPResponse::create() |
45
|
|
|
->setBody($this->getTransactionData()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param HTTPRequest $request |
50
|
|
|
* @return HTTPResponse |
51
|
|
|
* @throws PasswordEncryptor_NotFoundException |
52
|
|
|
*/ |
53
|
|
|
public function foxytestdata(HTTPRequest $request) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
return HTTPResponse::create() |
56
|
|
|
->setBody($this->getTransactionData()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string |
61
|
|
|
* @throws PasswordEncryptor_NotFoundException |
62
|
|
|
*/ |
63
|
|
|
protected function getTransactionData() |
64
|
|
|
{ |
65
|
|
|
return urlencode(\rc4crypt::encrypt(OrderFactoryTest::DUMMY_KEY, $this->getXML())); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
* @throws PasswordEncryptor_NotFoundException |
71
|
|
|
*/ |
72
|
|
|
protected function getXML() |
73
|
|
|
{ |
74
|
|
|
$xml = Controller::singleton()->renderWith( |
75
|
|
|
'TestData', |
76
|
|
|
[ |
77
|
|
|
'OrderID' => 111111222222333333, |
78
|
|
|
'TransactionDate' => strtotime('now'), |
79
|
|
|
'Email' => '[email protected]', |
80
|
|
|
'HashType' => 'sha1_salted_suffix', |
81
|
|
|
'Salt' => 'faGgWXUTdZ7i42lpA6cljzKeGBeUwShBSNHECwsJmt', |
82
|
|
|
'HashedPassword' => PasswordEncryptor::create_for_algorithm('sha1_v2.4') |
83
|
|
|
->encrypt('MyF00p@$$w0Rd', 'faGgWXUTdZ7i42lpA6cljzKeGBeUwShBSNHECwsJmt'), |
84
|
|
|
'OrderDetails' => $this->getOrderDetails(), |
85
|
|
|
] |
86
|
|
|
)->getValue(); |
87
|
|
|
|
88
|
|
|
return <<<XML |
89
|
|
|
{$xml} |
90
|
|
|
XML; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return ArrayList |
95
|
|
|
*/ |
96
|
|
|
protected function getOrderDetails() |
97
|
|
|
{ |
98
|
|
|
return ArrayList::create([ |
99
|
|
|
ArrayData::create([ |
100
|
|
|
'Options' => $this->getOptions(), |
101
|
|
|
]), |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return ArrayList |
107
|
|
|
*/ |
108
|
|
|
protected function getOptions() |
109
|
|
|
{ |
110
|
|
|
return ArrayList::create(); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|