1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Parser\Controller; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Parser\Foxy\Transaction; |
6
|
|
|
use SilverStripe\Control\Controller; |
7
|
|
|
use SilverStripe\Control\HTTPRequest; |
8
|
|
|
use SilverStripe\ORM\ValidationException; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class FoxyController |
12
|
|
|
* @package Dynamic\Foxy\Parser\Controller |
13
|
|
|
*/ |
14
|
|
|
class FoxyController extends Controller |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* |
18
|
|
|
*/ |
19
|
|
|
public const URLSEGMENT = 'foxy'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private static $allowed_actions = [ |
|
|
|
|
25
|
|
|
'index', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function getURLSegment() |
32
|
|
|
{ |
33
|
|
|
return self::URLSEGMENT; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return string |
38
|
|
|
* @throws ValidationException |
39
|
|
|
*/ |
40
|
|
|
public function index() |
41
|
|
|
{ |
42
|
|
|
$request = $this->getRequest(); |
43
|
|
|
if ($request->postVar('FoxyData') || $request->postVar('FoxySubscriptionData')) { |
44
|
|
|
$this->processFoxyRequest($request); |
45
|
|
|
|
46
|
|
|
return 'foxy'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return 'No FoxyData or FoxySubscriptionData received.'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Process a request after a transaction is completed via Foxy |
54
|
|
|
* |
55
|
|
|
* @param HTTPRequest $request |
56
|
|
|
* @throws ValidationException |
57
|
|
|
*/ |
58
|
|
|
protected function processFoxyRequest(HTTPRequest $request) |
59
|
|
|
{ |
60
|
|
|
$encryptedData = $request->postVar('FoxyData') |
61
|
|
|
? urldecode($request->postVar('FoxyData')) |
|
|
|
|
62
|
|
|
: urldecode($request->postVar('FoxySubscriptionData')); |
63
|
|
|
$this->parseFeedData($encryptedData); |
64
|
|
|
|
65
|
|
|
$encryptedData = urlencode($encryptedData); |
66
|
|
|
|
67
|
|
|
$this->extend('addIntegrations', $encryptedData); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Parse the XML data feed from Foxy to a SimpleXMLElement object |
72
|
|
|
* |
73
|
|
|
* @param $encryptedData |
74
|
|
|
* @param $decryptedData |
75
|
|
|
* @throws ValidationException |
76
|
|
|
*/ |
77
|
|
|
private function parseFeedData($encryptedData) |
78
|
|
|
{ |
79
|
|
|
$transaction = Transaction::create($encryptedData); |
80
|
|
|
|
81
|
|
|
$this->extend('doAdditionalParse', $transaction); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|