1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class FoxyStripe_Controller extends Page_Controller { |
4
|
|
|
|
5
|
|
|
const URLSegment = 'foxystripe'; |
6
|
|
|
|
7
|
|
|
public function getURLSegment() { |
8
|
|
|
return self::URLSegment; |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
static $allowed_actions = array( |
|
|
|
|
12
|
|
|
'index', |
13
|
|
|
'sso' |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
public function index() { |
|
|
|
|
17
|
|
|
|
18
|
|
|
// handle POST from FoxyCart API transaction |
19
|
|
|
if ((isset($_POST["FoxyData"]) OR isset($_POST['FoxySubscriptionData']))) { |
|
|
|
|
20
|
|
|
|
21
|
|
|
$FoxyData_encrypted = (isset($_POST["FoxyData"])) ? |
22
|
|
|
urldecode($_POST["FoxyData"]) : |
23
|
|
|
urldecode($_POST["FoxySubscriptionData"]); |
24
|
|
|
$FoxyData_decrypted = rc4crypt::decrypt(FoxyCart::getStoreKey(),$FoxyData_encrypted); |
25
|
|
|
|
26
|
|
|
// parse the response and save the order |
27
|
|
|
self::handleDataFeed($FoxyData_encrypted, $FoxyData_decrypted); |
28
|
|
|
|
29
|
|
|
// extend to allow for additional integrations with Datafeed |
30
|
|
|
$this->extend('addIntegrations', $FoxyData_encrypted); |
31
|
|
|
|
32
|
|
|
return 'foxy'; |
33
|
|
|
|
34
|
|
|
} else { |
35
|
|
|
|
36
|
|
|
return "No FoxyData or FoxySubscriptionData received."; |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function handleDataFeed($encrypted, $decrypted){ |
42
|
|
|
|
43
|
|
|
$orders = new SimpleXMLElement($decrypted); |
44
|
|
|
|
45
|
|
|
// loop over each transaction to find FoxyCart Order ID |
46
|
|
|
foreach ($orders->transactions->transaction as $transaction) { |
47
|
|
|
|
48
|
|
|
// if FoxyCart order id, then parse order |
49
|
|
|
if (isset($transaction->id)) { |
50
|
|
|
|
51
|
|
|
($order = Order::get()->filter('Order_ID', (int) $transaction->id)->First()) ? |
52
|
|
|
$order = Order::get()->filter('Order_ID', (int) $transaction->id)->First() : |
53
|
|
|
$order = Order::create(); |
54
|
|
|
|
55
|
|
|
// save base order info |
56
|
|
|
$order->Order_ID = (int) $transaction->id; |
57
|
|
|
$order->Response = urlencode($encrypted); |
58
|
|
|
$order->write(); |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
// Single Sign on integration with FoxyCart |
67
|
|
|
public function sso() { |
68
|
|
|
|
69
|
|
|
// GET variables from FoxyCart Request |
70
|
|
|
$fcsid = $this->request->getVar('fcsid'); |
71
|
|
|
$timestampNew = strtotime('+30 days'); |
72
|
|
|
|
73
|
|
|
// get current member if logged in. If not, create a 'fake' user with Customer_ID = 0 |
74
|
|
|
// fake user will redirect to FC checkout, ask customer to log in |
75
|
|
|
// to do: consider a login/registration form here if not logged in |
76
|
|
|
if($Member = Member::currentUser()) { |
|
|
|
|
77
|
|
|
$Member = Member::currentUser(); |
78
|
|
|
} else { |
79
|
|
|
$Member = new Member(); |
80
|
|
|
$Member->Customer_ID = 0; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$auth_token = sha1($Member->Customer_ID . '|' . $timestampNew . '|' . FoxyCart::getStoreKey()); |
84
|
|
|
|
85
|
|
|
$redirect_complete = 'https://' . FoxyCart::getFoxyCartStoreName() . '.foxycart.com/checkout?fc_auth_token=' . $auth_token . |
86
|
|
|
'&fcsid=' . $fcsid . '&fc_customer_id=' . $Member->Customer_ID . '×tamp=' . $timestampNew; |
87
|
|
|
|
88
|
|
|
$this->redirect($redirect_complete); |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
} |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.