1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\FoxyStripe\Controller; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Dynamic\FoxyStripe\Model\FoxyCart; |
7
|
|
|
use Dynamic\FoxyStripe\Model\Order; |
8
|
|
|
use SilverStripe\Control\Controller; |
9
|
|
|
use SilverStripe\Control\Director; |
10
|
|
|
use SilverStripe\Core\Config\Config; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class DataTestController |
14
|
|
|
* @package Dynamic\FoxyStripe\Controller |
15
|
|
|
*/ |
16
|
|
|
class DataTestController extends Controller |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private static $transaction_date = "now"; |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string|int |
26
|
|
|
*/ |
27
|
|
|
private static $order_id = "auto"; |
|
|
|
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @throws \SilverStripe\ORM\ValidationException |
33
|
|
|
*/ |
34
|
|
|
public function index() { |
35
|
|
|
|
36
|
|
|
$rules = Director::config()->get('rules'); |
37
|
|
|
$rule = array_search(FoxyStripeController::class, $rules); |
38
|
|
|
$myURL = Director::absoluteBaseURL() . explode('//', $rule)[0]; |
|
|
|
|
39
|
|
|
$myKey = FoxyCart::getStoreKey(); |
40
|
|
|
|
41
|
|
|
$this->updateConfig(); |
42
|
|
|
|
43
|
|
|
$XMLOutput = $this->renderWith( |
44
|
|
|
'TestData', |
45
|
|
|
Config::inst()->get(static::class) |
46
|
|
|
)->RAW(); |
47
|
|
|
|
48
|
|
|
$XMLOutput_encrypted = \rc4crypt::encrypt($myKey, $XMLOutput); |
|
|
|
|
49
|
|
|
$XMLOutput_encrypted = urlencode($XMLOutput_encrypted); |
50
|
|
|
|
51
|
|
|
$ch = curl_init(); |
52
|
|
|
curl_setopt($ch, CURLOPT_URL, $myURL); |
53
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, array("FoxyData" => $XMLOutput_encrypted)); |
54
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
55
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
56
|
|
|
|
57
|
|
|
$response = curl_exec($ch); |
58
|
|
|
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
59
|
|
|
curl_close($ch); |
60
|
|
|
|
61
|
|
|
if ($responseCode <= 400) { |
62
|
|
|
header("content-type:text/plain"); |
63
|
|
|
} |
64
|
|
|
print $response; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* |
69
|
|
|
*/ |
70
|
|
|
private function updateConfig() |
71
|
|
|
{ |
72
|
|
|
$transaction_date = static::config()->get('transaction_date'); |
73
|
|
|
static::config()->update('transaction_date', strtotime($transaction_date)); |
74
|
|
|
|
75
|
|
|
$order_id = static::config()->get('order_id'); |
76
|
|
|
if ($order_id === 'auto' || $order_id < 1) { |
77
|
|
|
$lastOrderID = Order::get()->sort('Order_ID')->last()->Order_ID; |
78
|
|
|
static::config()->update('order_id', $lastOrderID + 1); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|