@@ -38,6 +38,9 @@ |
||
38 | 38 | } |
39 | 39 | } |
40 | 40 | |
41 | + /** |
|
42 | + * @param string $encrypted |
|
43 | + */ |
|
41 | 44 | public function handleDataFeed($encrypted, $decrypted){ |
42 | 45 | |
43 | 46 | $orders = new SimpleXMLElement($decrypted); |
@@ -2,41 +2,41 @@ discard block |
||
2 | 2 | |
3 | 3 | class FoxyStripe_Controller extends Page_Controller { |
4 | 4 | |
5 | - const URLSegment = 'foxystripe'; |
|
5 | + const URLSegment = 'foxystripe'; |
|
6 | 6 | |
7 | - public function getURLSegment() { |
|
8 | - return self::URLSegment; |
|
9 | - } |
|
7 | + public function getURLSegment() { |
|
8 | + return self::URLSegment; |
|
9 | + } |
|
10 | 10 | |
11 | - static $allowed_actions = array( |
|
12 | - 'index', |
|
11 | + static $allowed_actions = array( |
|
12 | + 'index', |
|
13 | 13 | 'sso' |
14 | - ); |
|
14 | + ); |
|
15 | 15 | |
16 | - public function index() { |
|
16 | + public function index() { |
|
17 | 17 | |
18 | - // handle POST from FoxyCart API transaction |
|
19 | - if ((isset($_POST["FoxyData"]) OR isset($_POST['FoxySubscriptionData']))) { |
|
18 | + // handle POST from FoxyCart API transaction |
|
19 | + if ((isset($_POST["FoxyData"]) OR isset($_POST['FoxySubscriptionData']))) { |
|
20 | 20 | |
21 | - $FoxyData_encrypted = (isset($_POST["FoxyData"])) ? |
|
21 | + $FoxyData_encrypted = (isset($_POST["FoxyData"])) ? |
|
22 | 22 | urldecode($_POST["FoxyData"]) : |
23 | 23 | urldecode($_POST["FoxySubscriptionData"]); |
24 | - $FoxyData_decrypted = rc4crypt::decrypt(FoxyCart::getStoreKey(),$FoxyData_encrypted); |
|
24 | + $FoxyData_decrypted = rc4crypt::decrypt(FoxyCart::getStoreKey(),$FoxyData_encrypted); |
|
25 | 25 | |
26 | 26 | // parse the response and save the order |
27 | - self::handleDataFeed($FoxyData_encrypted, $FoxyData_decrypted); |
|
27 | + self::handleDataFeed($FoxyData_encrypted, $FoxyData_decrypted); |
|
28 | 28 | |
29 | - // extend to allow for additional integrations with Datafeed |
|
30 | - $this->extend('addIntegrations', $FoxyData_encrypted); |
|
29 | + // extend to allow for additional integrations with Datafeed |
|
30 | + $this->extend('addIntegrations', $FoxyData_encrypted); |
|
31 | 31 | |
32 | - return 'foxy'; |
|
32 | + return 'foxy'; |
|
33 | 33 | |
34 | - } else { |
|
34 | + } else { |
|
35 | 35 | |
36 | - return "No FoxyData or FoxySubscriptionData received."; |
|
36 | + return "No FoxyData or FoxySubscriptionData received."; |
|
37 | 37 | |
38 | - } |
|
39 | - } |
|
38 | + } |
|
39 | + } |
|
40 | 40 | |
41 | 41 | public function handleDataFeed($encrypted, $decrypted){ |
42 | 42 | |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | |
66 | - // Single Sign on integration with FoxyCart |
|
66 | + // Single Sign on integration with FoxyCart |
|
67 | 67 | public function sso() { |
68 | 68 | |
69 | - // GET variables from FoxyCart Request |
|
69 | + // GET variables from FoxyCart Request |
|
70 | 70 | $fcsid = $this->request->getVar('fcsid'); |
71 | 71 | $timestampNew = strtotime('+30 days'); |
72 | 72 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $redirect_complete = 'https://' . FoxyCart::getFoxyCartStoreName() . '.foxycart.com/checkout?fc_auth_token=' . $auth_token . |
86 | 86 | '&fcsid=' . $fcsid . '&fc_customer_id=' . $Member->Customer_ID . '×tamp=' . $timestampNew; |
87 | 87 | |
88 | - $this->redirect($redirect_complete); |
|
88 | + $this->redirect($redirect_complete); |
|
89 | 89 | |
90 | 90 | } |
91 | 91 |
@@ -19,9 +19,8 @@ discard block |
||
19 | 19 | if ((isset($_POST["FoxyData"]) OR isset($_POST['FoxySubscriptionData']))) { |
20 | 20 | |
21 | 21 | $FoxyData_encrypted = (isset($_POST["FoxyData"])) ? |
22 | - urldecode($_POST["FoxyData"]) : |
|
23 | - urldecode($_POST["FoxySubscriptionData"]); |
|
24 | - $FoxyData_decrypted = rc4crypt::decrypt(FoxyCart::getStoreKey(),$FoxyData_encrypted); |
|
22 | + urldecode($_POST["FoxyData"]) : urldecode($_POST["FoxySubscriptionData"]); |
|
23 | + $FoxyData_decrypted = rc4crypt::decrypt(FoxyCart::getStoreKey(), $FoxyData_encrypted); |
|
25 | 24 | |
26 | 25 | // parse the response and save the order |
27 | 26 | self::handleDataFeed($FoxyData_encrypted, $FoxyData_decrypted); |
@@ -31,14 +30,14 @@ discard block |
||
31 | 30 | |
32 | 31 | return 'foxy'; |
33 | 32 | |
34 | - } else { |
|
33 | + }else { |
|
35 | 34 | |
36 | 35 | return "No FoxyData or FoxySubscriptionData received."; |
37 | 36 | |
38 | 37 | } |
39 | 38 | } |
40 | 39 | |
41 | - public function handleDataFeed($encrypted, $decrypted){ |
|
40 | + public function handleDataFeed($encrypted, $decrypted) { |
|
42 | 41 | |
43 | 42 | $orders = new SimpleXMLElement($decrypted); |
44 | 43 | |
@@ -48,12 +47,11 @@ discard block |
||
48 | 47 | // if FoxyCart order id, then parse order |
49 | 48 | if (isset($transaction->id)) { |
50 | 49 | |
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(); |
|
50 | + ($order = Order::get()->filter('Order_ID', (int)$transaction->id)->First()) ? |
|
51 | + $order = Order::get()->filter('Order_ID', (int)$transaction->id)->First() : $order = Order::create(); |
|
54 | 52 | |
55 | 53 | // save base order info |
56 | - $order->Order_ID = (int) $transaction->id; |
|
54 | + $order->Order_ID = (int)$transaction->id; |
|
57 | 55 | $order->Response = urlencode($encrypted); |
58 | 56 | $order->write(); |
59 | 57 | |
@@ -73,17 +71,17 @@ discard block |
||
73 | 71 | // get current member if logged in. If not, create a 'fake' user with Customer_ID = 0 |
74 | 72 | // fake user will redirect to FC checkout, ask customer to log in |
75 | 73 | // to do: consider a login/registration form here if not logged in |
76 | - if($Member = Member::currentUser()) { |
|
74 | + if ($Member = Member::currentUser()) { |
|
77 | 75 | $Member = Member::currentUser(); |
78 | - } else { |
|
76 | + }else { |
|
79 | 77 | $Member = new Member(); |
80 | 78 | $Member->Customer_ID = 0; |
81 | 79 | } |
82 | 80 | |
83 | - $auth_token = sha1($Member->Customer_ID . '|' . $timestampNew . '|' . FoxyCart::getStoreKey()); |
|
81 | + $auth_token = sha1($Member->Customer_ID.'|'.$timestampNew.'|'.FoxyCart::getStoreKey()); |
|
84 | 82 | |
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; |
|
83 | + $redirect_complete = 'https://'.FoxyCart::getFoxyCartStoreName().'.foxycart.com/checkout?fc_auth_token='.$auth_token. |
|
84 | + '&fcsid='.$fcsid.'&fc_customer_id='.$Member->Customer_ID.'×tamp='.$timestampNew; |
|
87 | 85 | |
88 | 86 | $this->redirect($redirect_complete); |
89 | 87 |
@@ -90,6 +90,9 @@ discard block |
||
90 | 90 | return $obj; |
91 | 91 | } |
92 | 92 | |
93 | + /** |
|
94 | + * @return string |
|
95 | + */ |
|
93 | 96 | public function getDecryptedResponse() { |
94 | 97 | $decrypted = urldecode($this->Response); |
95 | 98 | return rc4crypt::decrypt(FoxyCart::getStoreKey(), $decrypted); |
@@ -120,6 +123,9 @@ discard block |
||
120 | 123 | } |
121 | 124 | } |
122 | 125 | |
126 | + /** |
|
127 | + * @param SimpleXMLElement $response |
|
128 | + */ |
|
123 | 129 | public function parseOrderInfo($response) { |
124 | 130 | |
125 | 131 | foreach ($response->transactions->transaction as $transaction) { |
@@ -138,6 +144,9 @@ discard block |
||
138 | 144 | } |
139 | 145 | } |
140 | 146 | |
147 | + /** |
|
148 | + * @param SimpleXMLElement $response |
|
149 | + */ |
|
141 | 150 | public function parseOrderCustomer($response) { |
142 | 151 | |
143 | 152 | foreach ($response->transactions->transaction as $transaction) { |
@@ -179,6 +188,9 @@ discard block |
||
179 | 188 | } |
180 | 189 | } |
181 | 190 | |
191 | + /** |
|
192 | + * @param SimpleXMLElement $response |
|
193 | + */ |
|
182 | 194 | public function parseOrderDetails($response) { |
183 | 195 | |
184 | 196 | // remove previous OrderDetails and OrderOptions so we don't end up with duplicates |
@@ -241,14 +241,14 @@ |
||
241 | 241 | } |
242 | 242 | |
243 | 243 | |
244 | - public function canView($member = false) { |
|
245 | - return Permission::check('Product_ORDERS'); |
|
246 | - } |
|
244 | + public function canView($member = false) { |
|
245 | + return Permission::check('Product_ORDERS'); |
|
246 | + } |
|
247 | 247 | |
248 | - public function canEdit($member = null) { |
|
248 | + public function canEdit($member = null) { |
|
249 | 249 | return false; |
250 | 250 | //return Permission::check('Product_ORDERS'); |
251 | - } |
|
251 | + } |
|
252 | 252 | |
253 | 253 | public function canDelete($member = null) |
254 | 254 | { |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | |
86 | 86 | public function getReceiptLink() |
87 | 87 | { |
88 | - $obj= HTMLVarchar::create(); |
|
89 | - $obj->setValue('<a href="' . $this->ReceiptURL . '" target="_blank" class="cms-panel-link action external-link">view</a>'); |
|
88 | + $obj = HTMLVarchar::create(); |
|
89 | + $obj->setValue('<a href="'.$this->ReceiptURL.'" target="_blank" class="cms-panel-link action external-link">view</a>'); |
|
90 | 90 | return $obj; |
91 | 91 | } |
92 | 92 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | return true; |
115 | 115 | |
116 | - } else { |
|
116 | + }else { |
|
117 | 117 | |
118 | 118 | return false; |
119 | 119 | |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | foreach ($response->transactions->transaction as $transaction) { |
126 | 126 | |
127 | 127 | // Record transaction data from FoxyCart Datafeed: |
128 | - $this->Store_ID = (int) $transaction->store_id; |
|
129 | - $this->TransactionDate = (string) $transaction->transaction_date; |
|
130 | - $this->ProductTotal = (float) $transaction->product_total; |
|
131 | - $this->TaxTotal = (float) $transaction->tax_total; |
|
132 | - $this->ShippingTotal = (float) $transaction->shipping_total; |
|
133 | - $this->OrderTotal = (float) $transaction->order_total; |
|
134 | - $this->ReceiptURL = (string) $transaction->receipt_url; |
|
135 | - $this->OrderStatus = (string) $transaction->status; |
|
128 | + $this->Store_ID = (int)$transaction->store_id; |
|
129 | + $this->TransactionDate = (string)$transaction->transaction_date; |
|
130 | + $this->ProductTotal = (float)$transaction->product_total; |
|
131 | + $this->TaxTotal = (float)$transaction->tax_total; |
|
132 | + $this->ShippingTotal = (float)$transaction->shipping_total; |
|
133 | + $this->OrderTotal = (float)$transaction->order_total; |
|
134 | + $this->ReceiptURL = (string)$transaction->receipt_url; |
|
135 | + $this->OrderStatus = (string)$transaction->status; |
|
136 | 136 | |
137 | 137 | $this->extend('handleOrderInfo', $order, $response); |
138 | 138 | } |
@@ -146,24 +146,24 @@ discard block |
||
146 | 146 | if (isset($transaction->customer_email) && $transaction->is_anonymous == 0) { |
147 | 147 | |
148 | 148 | // if Customer is existing member, associate with current order |
149 | - if(Member::get()->filter('Email', $transaction->customer_email)->First()) { |
|
149 | + if (Member::get()->filter('Email', $transaction->customer_email)->First()) { |
|
150 | 150 | |
151 | 151 | $customer = Member::get()->filter('Email', $transaction->customer_email)->First(); |
152 | 152 | |
153 | 153 | // if new customer, create account with data from FoxyCart |
154 | - } else { |
|
154 | + }else { |
|
155 | 155 | |
156 | 156 | // set PasswordEncryption to 'none' so imported, encrypted password is not encrypted again |
157 | 157 | Config::inst()->update('Security', 'password_encryption_algorithm', 'none'); |
158 | 158 | |
159 | 159 | // create new Member, set password info from FoxyCart |
160 | 160 | $customer = Member::create(); |
161 | - $customer->Customer_ID = (int) $transaction->customer_id; |
|
162 | - $customer->FirstName = (string) $transaction->customer_first_name; |
|
163 | - $customer->Surname = (string) $transaction->customer_last_name; |
|
164 | - $customer->Email = (string) $transaction->customer_email; |
|
165 | - $customer->Password = (string) $transaction->customer_password; |
|
166 | - $customer->Salt = (string) $transaction->customer_password_salt; |
|
161 | + $customer->Customer_ID = (int)$transaction->customer_id; |
|
162 | + $customer->FirstName = (string)$transaction->customer_first_name; |
|
163 | + $customer->Surname = (string)$transaction->customer_last_name; |
|
164 | + $customer->Email = (string)$transaction->customer_email; |
|
165 | + $customer->Password = (string)$transaction->customer_password; |
|
166 | + $customer->Salt = (string)$transaction->customer_password_salt; |
|
167 | 167 | $customer->PasswordEncryption = 'none'; |
168 | 168 | |
169 | 169 | // record member record |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | |
197 | 197 | $OrderDetail = OrderDetail::create(); |
198 | 198 | |
199 | - $OrderDetail->Quantity = (int) $detail->product_quantity; |
|
200 | - $OrderDetail->ProductName = (string) $detail->product_name; |
|
201 | - $OrderDetail->ProductCode = (string) $detail->product_code; |
|
202 | - $OrderDetail->ProductImage = (string) $detail->image; |
|
203 | - $OrderDetail->ProductCategory = (string) $detail->category_code; |
|
199 | + $OrderDetail->Quantity = (int)$detail->product_quantity; |
|
200 | + $OrderDetail->ProductName = (string)$detail->product_name; |
|
201 | + $OrderDetail->ProductCode = (string)$detail->product_code; |
|
202 | + $OrderDetail->ProductImage = (string)$detail->image; |
|
203 | + $OrderDetail->ProductCategory = (string)$detail->category_code; |
|
204 | 204 | $priceModifier = 0; |
205 | 205 | |
206 | 206 | // parse OrderOptions |
@@ -210,14 +210,14 @@ discard block |
||
210 | 210 | if ($option->product_option_name == 'product_id') { |
211 | 211 | |
212 | 212 | // if product is found, set relation to OrderDetail |
213 | - $OrderProduct = ProductPage::get()->byID((int) $option->product_option_value); |
|
213 | + $OrderProduct = ProductPage::get()->byID((int)$option->product_option_value); |
|
214 | 214 | if ($OrderProduct) $OrderDetail->ProductID = $OrderProduct->ID; |
215 | 215 | |
216 | - } else { |
|
216 | + }else { |
|
217 | 217 | |
218 | 218 | $OrderOption = OrderOption::create(); |
219 | - $OrderOption->Name = (string) $option->product_option_name; |
|
220 | - $OrderOption->Value = (string) $option->product_option_value; |
|
219 | + $OrderOption->Name = (string)$option->product_option_name; |
|
220 | + $OrderOption->Value = (string)$option->product_option_value; |
|
221 | 221 | $OrderOption->write(); |
222 | 222 | $OrderDetail->OrderOptions()->add($OrderOption); |
223 | 223 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | |
227 | 227 | } |
228 | 228 | |
229 | - $OrderDetail->Price = (float) $detail->product_price + (float) $priceModifier; |
|
229 | + $OrderDetail->Price = (float)$detail->product_price + (float)$priceModifier; |
|
230 | 230 | |
231 | 231 | // extend OrderDetail parsing, allowing for recording custom fields from FoxyCart |
232 | 232 | $this->extend('handleOrderItem', $order, $response, $OrderDetail); |
@@ -211,7 +211,9 @@ |
||
211 | 211 | |
212 | 212 | // if product is found, set relation to OrderDetail |
213 | 213 | $OrderProduct = ProductPage::get()->byID((int) $option->product_option_value); |
214 | - if ($OrderProduct) $OrderDetail->ProductID = $OrderProduct->ID; |
|
214 | + if ($OrderProduct) { |
|
215 | + $OrderDetail->ProductID = $OrderProduct->ID; |
|
216 | + } |
|
215 | 217 | |
216 | 218 | } else { |
217 | 219 |
@@ -101,14 +101,14 @@ |
||
101 | 101 | { |
102 | 102 | return false; |
103 | 103 | //return Permission::check('Product_ORDERS'); |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | - public function canDelete($member = null) { |
|
107 | - return Permission::check('Product_ORDERS'); |
|
108 | - } |
|
106 | + public function canDelete($member = null) { |
|
107 | + return Permission::check('Product_ORDERS'); |
|
108 | + } |
|
109 | 109 | |
110 | - public function canCreate($member = null) { |
|
111 | - return false; |
|
112 | - } |
|
110 | + public function canCreate($member = null) { |
|
111 | + return false; |
|
112 | + } |
|
113 | 113 | |
114 | 114 | } |
115 | 115 | \ No newline at end of file |