Version Notes
Supports all versions of Magento
Download this release
Release Info
Developer | Magento Core Team |
Extension | Signifyd_Connect |
Version | 3.10.0 |
Comparing to | |
See all releases |
Code changes from version 3.9.0 to 3.10.0
- app/code/community/Signifyd/Connect/Helper/Data.php +416 -5
- app/code/community/Signifyd/Connect/Model/Observer.php +27 -481
- app/code/community/Signifyd/Connect/controllers/Adminhtml/SignifydController.php +30 -1
- app/code/community/Signifyd/Connect/controllers/ConnectController.php +17 -18
- app/code/community/Signifyd/Connect/etc/config.xml +9 -1
- package.xml +4 -4
app/code/community/Signifyd/Connect/Helper/Data.php
CHANGED
@@ -2,6 +2,422 @@
|
|
2 |
|
3 |
class Signifyd_Connect_Helper_Data extends Mage_Core_Helper_Abstract
|
4 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
5 |
public function getProductUrl($product)
|
6 |
{
|
7 |
$url = null;
|
@@ -68,11 +484,6 @@ class Signifyd_Connect_Helper_Data extends Mage_Core_Helper_Abstract
|
|
68 |
return false;
|
69 |
}
|
70 |
|
71 |
-
public function generateCase($order)
|
72 |
-
{
|
73 |
-
return $this->markProcessed($order);
|
74 |
-
}
|
75 |
-
|
76 |
public function markProcessed($order)
|
77 |
{
|
78 |
$case = Mage::getModel('signifyd_connect/case');
|
2 |
|
3 |
class Signifyd_Connect_Helper_Data extends Mage_Core_Helper_Abstract
|
4 |
{
|
5 |
+
public function getProducts($quote)
|
6 |
+
{
|
7 |
+
$products = array();
|
8 |
+
|
9 |
+
foreach ($quote->getAllItems() as $item) {
|
10 |
+
$product_type = $item->getProductType();
|
11 |
+
|
12 |
+
if (!$product_type || $product_type == 'simple' || $product_type == 'downloadable' || $product_type == 'grouped') {
|
13 |
+
$product_object = $item->getData('product');
|
14 |
+
|
15 |
+
if (!$product_object || !$product_object->getId()) {
|
16 |
+
$product_object = Mage::getModel('catalog/product')->load($product_type);
|
17 |
+
}
|
18 |
+
|
19 |
+
if ($product_object) {
|
20 |
+
$product = array();
|
21 |
+
|
22 |
+
$product['itemId'] = $item->getSku();
|
23 |
+
$product['itemName'] = $item->getName();
|
24 |
+
$product['itemUrl'] = $this->getProductUrl($product_object);
|
25 |
+
$product['itemImage'] = $this->getProductImage($product_object);
|
26 |
+
|
27 |
+
$qty = 1;
|
28 |
+
if ($item->getQty()) {
|
29 |
+
$qty = $item->getQty();
|
30 |
+
} else if ($item->getQtyOrdered()) {
|
31 |
+
$qty = $item->getQtyOrdered();
|
32 |
+
}
|
33 |
+
|
34 |
+
$price = 0;
|
35 |
+
if ($item->getPrice() > 0) {
|
36 |
+
$price = $item->getPrice();
|
37 |
+
} else if ($item->getBasePrice() > 0) {
|
38 |
+
$price = $item->getBasePrice();
|
39 |
+
} else if ($product_object->getData('price') > 0) {
|
40 |
+
$price = $product_object->getData('price');
|
41 |
+
} else {
|
42 |
+
$parent = $item->getData('parent');
|
43 |
+
|
44 |
+
if (!$parent) {
|
45 |
+
$parent = $item->getParentItem();
|
46 |
+
}
|
47 |
+
|
48 |
+
if ($parent) {
|
49 |
+
if ($parent->getBasePrice() > 0) {
|
50 |
+
$price = $parent->getBasePrice();
|
51 |
+
} else if ($parent->getPrice()) {
|
52 |
+
$price = $parent->getPrice();
|
53 |
+
}
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
$weight = 0;
|
58 |
+
if ($item->hasWeight()) {
|
59 |
+
$weight = $item->getWeight();
|
60 |
+
} else if ($product_object->hasWeight()) {
|
61 |
+
$weight = $product_object->getWeight();
|
62 |
+
}
|
63 |
+
|
64 |
+
$product['itemQuantity'] = intval($qty);
|
65 |
+
$product['itemPrice'] = floatval($price);
|
66 |
+
$product['itemWeight'] = floatval($weight);
|
67 |
+
|
68 |
+
$products[] = $product;
|
69 |
+
}
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
return $products;
|
74 |
+
}
|
75 |
+
|
76 |
+
public function getIPAddress($order)
|
77 |
+
{
|
78 |
+
if ($order->getRemoteIp()) {
|
79 |
+
if ($order->getXForwardedFor()) {
|
80 |
+
return $this->filterIp($order->getXForwardedFor());
|
81 |
+
}
|
82 |
+
|
83 |
+
return $this->filterIp($order->getRemoteIp());
|
84 |
+
}
|
85 |
+
|
86 |
+
// Checks each configured value in app/etc/local.xml & falls back to REMOTE_ADDR. See app/etc/local.xml.additional for examples.
|
87 |
+
return $this->filterIp(Mage::helper('core/http')->getRemoteAddr(false));
|
88 |
+
}
|
89 |
+
|
90 |
+
public function filterIp($ip)
|
91 |
+
{
|
92 |
+
$matches = array();
|
93 |
+
|
94 |
+
if (preg_match('/[0-9]{1,3}(?:\.[0-9]{1,3}){3}/', $ip, $matches)) { //ipv4
|
95 |
+
return current($matches);
|
96 |
+
}
|
97 |
+
|
98 |
+
if (preg_match('/[a-f0-9]{0,4}(?:\:[a-f0-9]{0,4}){2,7}/', strtolower($ip), $matches)) { //ipv6
|
99 |
+
return current($matches);
|
100 |
+
}
|
101 |
+
|
102 |
+
return preg_replace('/[^0-9a-zA-Z:\.]/', '', strtok(str_replace($ip, ',', "\n"), "\n"));
|
103 |
+
}
|
104 |
+
|
105 |
+
public function formatAvs($value)
|
106 |
+
{
|
107 |
+
// http://www.emsecommerce.net/avs_cvv2_response_codes.htm
|
108 |
+
$codes = array('X', 'Y', 'A', 'W', 'Z', 'N', 'U', 'R', 'E', 'S', 'D', 'M', 'B', 'P', 'C', 'I', 'G');
|
109 |
+
|
110 |
+
if ($value) {
|
111 |
+
$value = strtoupper($value);
|
112 |
+
|
113 |
+
if (strlen($value) > 1) {
|
114 |
+
if (preg_match('/\([A-Z]\)/', $value)) {
|
115 |
+
$matches = array();
|
116 |
+
|
117 |
+
preg_match('/\([A-Z]\)/', $value, $matches);
|
118 |
+
|
119 |
+
foreach ($matches as $match) {
|
120 |
+
$match = preg_replace('/[^A-Z]/', '', $match);
|
121 |
+
|
122 |
+
if (in_array($match, $codes)) {
|
123 |
+
$value = $match;
|
124 |
+
}
|
125 |
+
}
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
if (strlen($value) > 1) {
|
130 |
+
$value = substr($value, 0, 1);
|
131 |
+
}
|
132 |
+
|
133 |
+
if (!in_array($value, $codes)) {
|
134 |
+
$value = null;
|
135 |
+
}
|
136 |
+
}
|
137 |
+
|
138 |
+
return $value;
|
139 |
+
}
|
140 |
+
|
141 |
+
public function getAvsResponse($payment)
|
142 |
+
{
|
143 |
+
$value = null;
|
144 |
+
|
145 |
+
if ($payment->getAdditionalInformation('paypal_avs_code')) {
|
146 |
+
$value = $payment->getAdditionalInformation('paypal_avs_code');
|
147 |
+
} else if ($payment->getAdditionalInformation('cc_avs_status')) {
|
148 |
+
$value = $payment->getAdditionalInformation('cc_avs_status');
|
149 |
+
}
|
150 |
+
|
151 |
+
return $this->formatAvs($value);
|
152 |
+
}
|
153 |
+
|
154 |
+
public function getCvvResponse($payment)
|
155 |
+
{
|
156 |
+
if ($payment->getAdditionalInformation('paypal_cvv2_match')) {
|
157 |
+
return $payment->getAdditionalInformation('paypal_cvv2_match');
|
158 |
+
}
|
159 |
+
|
160 |
+
return null;
|
161 |
+
}
|
162 |
+
|
163 |
+
public function getPurchase($order)
|
164 |
+
{
|
165 |
+
$purchase = array();
|
166 |
+
$payment = $order->getPayment();
|
167 |
+
|
168 |
+
// T715: Send null rather than false when we can't get the IP Address
|
169 |
+
$purchase['browserIpAddress'] = ($this->getIpAddress($order) ? $this->getIpAddress($order) : null);
|
170 |
+
$purchase['orderId'] = $order->getIncrementId();
|
171 |
+
$purchase['createdAt'] = date('c', strtotime($order->getCreatedAt())); // e.g: 2004-02-12T15:19:21+00:00
|
172 |
+
$purchase['currency'] = $order->getOrderCurrencyCode();
|
173 |
+
$purchase['totalPrice'] = floatval($order->getGrandTotal());
|
174 |
+
$purchase['shippingPrice'] = floatval($order->getShippingAmount());
|
175 |
+
$purchase['products'] = $this->getProducts($order);
|
176 |
+
$purchase['paymentGateway'] = $payment->getMethod();
|
177 |
+
$purchase['transactionId'] = $payment->getTransactionId();
|
178 |
+
|
179 |
+
$purchase['avsResponseCode'] = $this->getAvsResponse($payment);
|
180 |
+
$purchase['cvvResponseCode'] = $this->getCvvResponse($payment);
|
181 |
+
|
182 |
+
return $purchase;
|
183 |
+
}
|
184 |
+
|
185 |
+
public function isPaymentCC($payment)
|
186 |
+
{
|
187 |
+
// Although the payment structure only has the entity data for the payment
|
188 |
+
// the original payment method object is stored within the entity data.
|
189 |
+
// It's not a requirement, but every CC handler I've found subclasses
|
190 |
+
// from Mage_Payment_Model_Method_Cc, so we are using that as an
|
191 |
+
// assumption for whether a method is based on CC data
|
192 |
+
$method = $payment->getData('method_instance');
|
193 |
+
if($method)
|
194 |
+
{
|
195 |
+
return is_subclass_of($method, 'Mage_Payment_Model_Method_Cc');
|
196 |
+
}
|
197 |
+
return false;
|
198 |
+
}
|
199 |
+
|
200 |
+
public function getCard($order, $payment)
|
201 |
+
{
|
202 |
+
$billing = $order->getBillingAddress();
|
203 |
+
|
204 |
+
$card = array();
|
205 |
+
|
206 |
+
$card['cardHolderName'] = null;
|
207 |
+
$card['bin'] = null;
|
208 |
+
$card['last4'] = null;
|
209 |
+
$card['expiryMonth'] = null;
|
210 |
+
$card['expiryYear'] = null;
|
211 |
+
$card['hash'] = null;
|
212 |
+
|
213 |
+
$card['billingAddress'] = $this->getSignifydAddress($billing);
|
214 |
+
|
215 |
+
if ($payment->getCcOwner()) {
|
216 |
+
$card['cardHolderName'] = $payment->getCcOwner();
|
217 |
+
} else {
|
218 |
+
$card['cardHolderName'] = $billing->getFirstname() . ' ' . $billing->getLastname();
|
219 |
+
}
|
220 |
+
|
221 |
+
// Card data may be set on payment even if payment was not with card.
|
222 |
+
// If it is, we want to ignore the data
|
223 |
+
if(!$this->isPaymentCC($payment)) return $card;
|
224 |
+
|
225 |
+
if ($payment->getData('cc_last4')) {
|
226 |
+
$card['last4'] = $payment->getData('cc_last4');
|
227 |
+
}
|
228 |
+
|
229 |
+
if ($payment->getData('cc_exp_year')) {
|
230 |
+
$card['expiryYear'] = $payment->getData('cc_exp_year');
|
231 |
+
}
|
232 |
+
|
233 |
+
if ($payment->getData('cc_exp_month')) {
|
234 |
+
$card['expiryMonth'] = $payment->getData('cc_exp_month');
|
235 |
+
}
|
236 |
+
|
237 |
+
if ($payment->getData('cc_number_enc')) {
|
238 |
+
$card['hash'] = $payment->getData('cc_number_enc');
|
239 |
+
}
|
240 |
+
|
241 |
+
if ($payment->getData('cc_number') && is_numeric($payment->getData('cc_number')) && strlen((string)$payment->getData('cc_number')) > 6) {
|
242 |
+
$card['bin'] = substr((string)$payment->getData('cc_number'), 0, 6);
|
243 |
+
}
|
244 |
+
|
245 |
+
return $card;
|
246 |
+
}
|
247 |
+
|
248 |
+
public function getSignifydAddress($address_object)
|
249 |
+
{
|
250 |
+
$address = array();
|
251 |
+
|
252 |
+
$address['streetAddress'] = $address_object->getStreet1();
|
253 |
+
$address['unit'] = null;
|
254 |
+
|
255 |
+
if ($address_object->getStreet2()) {
|
256 |
+
$address['unit'] = $address_object->getStreet2();
|
257 |
+
}
|
258 |
+
|
259 |
+
$address['city'] = $address_object->getCity();
|
260 |
+
|
261 |
+
$address['provinceCode'] = $address_object->getRegionCode();
|
262 |
+
$address['postalCode'] = $address_object->getPostcode();
|
263 |
+
$address['countryCode'] = $address_object->getCountryId();
|
264 |
+
|
265 |
+
$address['latitude'] = null;
|
266 |
+
$address['longitude'] = null;
|
267 |
+
|
268 |
+
return $address;
|
269 |
+
}
|
270 |
+
|
271 |
+
public function getRecipient($order)
|
272 |
+
{
|
273 |
+
$recipient = array();
|
274 |
+
|
275 |
+
// In the case of non-shipped (ex: downloadable) orders, shipping address will be null so
|
276 |
+
// in that case, we need to avoid the exception.
|
277 |
+
$shipping_address = $order->getShippingAddress();
|
278 |
+
if($shipping_address) {
|
279 |
+
$recipient['deliveryAddress'] = $this->getSignifydAddress($shipping_address);
|
280 |
+
$recipient['fullName'] = $shipping_address->getFirstname() . ' ' . $shipping_address->getLastname();
|
281 |
+
$recipient['confirmationPhone'] = $shipping_address->getTelephone();
|
282 |
+
// Email: Note that this field is always the same for both addresses
|
283 |
+
$recipient['confirmationEmail'] = $shipping_address->getEmail();
|
284 |
+
}
|
285 |
+
// Some customers have reported seeing "n/a@na.na" come through instead of a valid or null address
|
286 |
+
// We suspect that it is due to an older version of Magento. If it becomes unnecessary, do remove the extra check.
|
287 |
+
if (!$recipient['confirmationEmail'] || $recipient['confirmationEmail'] == 'n/a@na.na') {
|
288 |
+
$recipient['confirmationEmail'] = $order->getCustomerEmail();
|
289 |
+
}
|
290 |
+
|
291 |
+
return $recipient;
|
292 |
+
}
|
293 |
+
|
294 |
+
public function getUserAccount($customer, $order)
|
295 |
+
{
|
296 |
+
$user = array(
|
297 |
+
"emailAddress" => null,
|
298 |
+
"username" => null,
|
299 |
+
"phone" => null,
|
300 |
+
"createdDate" => null,
|
301 |
+
"accountNumber" => null,
|
302 |
+
"lastOrderId" => null,
|
303 |
+
"aggregateOrderCount" => null,
|
304 |
+
"aggregateOrderDollars" => null,
|
305 |
+
"lastUpdateDate" => null
|
306 |
+
);
|
307 |
+
|
308 |
+
if ($customer && $customer->getId()) {
|
309 |
+
$user['emailAddress'] = $customer->getEmail();
|
310 |
+
|
311 |
+
$user['phone'] = $order->getBillingAddress()->getTelephone();
|
312 |
+
|
313 |
+
$user['createdDate'] = date('c', strtotime($customer->getCreatedAt()));
|
314 |
+
$user['lastUpdateDate'] = date('c', strtotime($customer->getUpdatedAt()));
|
315 |
+
|
316 |
+
$user['accountNumber'] = $customer->getId();
|
317 |
+
|
318 |
+
$last_order_id = null;
|
319 |
+
|
320 |
+
$orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $customer->getId());
|
321 |
+
$orders->getSelect()->order('created_at DESC');
|
322 |
+
|
323 |
+
$aggregate_total = 0.;
|
324 |
+
$order_count = 0;
|
325 |
+
|
326 |
+
foreach ($orders as $order) {
|
327 |
+
if ($last_order_id === null) {
|
328 |
+
$last_order_id = $order->getIncrementId();
|
329 |
+
}
|
330 |
+
|
331 |
+
$aggregate_total += floatval($order->getGrandTotal());
|
332 |
+
$order_count += 1;
|
333 |
+
}
|
334 |
+
|
335 |
+
$user['lastOrderId'] = $last_order_id;
|
336 |
+
$user['aggregateOrderCount'] = $order_count;
|
337 |
+
$user['aggregateOrderDollars'] = floatval($aggregate_total);
|
338 |
+
}
|
339 |
+
|
340 |
+
return $user;
|
341 |
+
}
|
342 |
+
|
343 |
+
public function generateCase($order, $payment, $customer)
|
344 |
+
{
|
345 |
+
$case = array();
|
346 |
+
|
347 |
+
$case['purchase'] = $this->getPurchase($order);
|
348 |
+
$case['recipient'] = $this->getRecipient($order);
|
349 |
+
$case['card'] = $this->getCard($order, $payment);
|
350 |
+
$case['userAccount'] = $this->getUserAccount($customer, $order);
|
351 |
+
|
352 |
+
return $case;
|
353 |
+
}
|
354 |
+
|
355 |
+
public function submitCase($case, $url, $auth)
|
356 |
+
{
|
357 |
+
$case = json_encode($case);
|
358 |
+
|
359 |
+
return $this->request($url, $case, $auth, 'application/json');
|
360 |
+
}
|
361 |
+
|
362 |
+
public function getUrl()
|
363 |
+
{
|
364 |
+
return Mage::getStoreConfig('signifyd_connect/settings/url') . '/cases';
|
365 |
+
}
|
366 |
+
|
367 |
+
public function getAuth()
|
368 |
+
{
|
369 |
+
return Mage::getStoreConfig('signifyd_connect/settings/key');
|
370 |
+
}
|
371 |
+
|
372 |
+
public function buildAndSendOrderToSignifyd($order, $forceSend = false)
|
373 |
+
{
|
374 |
+
if ($order && $order->getId()) {
|
375 |
+
if ($this->isProcessed($order) && !$forceSend) {
|
376 |
+
return "exists";
|
377 |
+
}
|
378 |
+
|
379 |
+
$payments = $order->getPaymentsCollection();
|
380 |
+
$last_payment = null;
|
381 |
+
foreach ($payments as $payment) {
|
382 |
+
$last_payment = $payment;
|
383 |
+
}
|
384 |
+
|
385 |
+
$state = $order->getState();
|
386 |
+
|
387 |
+
if (!$state || $state == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) {
|
388 |
+
return "notready"; // Note: would not be in the order grid if this were the case
|
389 |
+
}
|
390 |
+
|
391 |
+
$customer = null;
|
392 |
+
if ($order->getCustomer()) {
|
393 |
+
$customer = $order->getCustomer();
|
394 |
+
}
|
395 |
+
|
396 |
+
$case = $this->generateCase($order, $last_payment, $customer);
|
397 |
+
|
398 |
+
$case_object = $this->markProcessed($order);
|
399 |
+
|
400 |
+
$response = $this->submitCase($case, $this->getUrl(), $this->getAuth());
|
401 |
+
|
402 |
+
try {
|
403 |
+
$response_code = $response->getHttpCode();
|
404 |
+
|
405 |
+
if (substr($response_code, 0, 1) == '2') {
|
406 |
+
$response_data = json_decode($response->getRawResponse(), true);
|
407 |
+
|
408 |
+
$case_object = Mage::getModel('signifyd_connect/case')->load($case_object->getOrderIncrement());
|
409 |
+
$case_object->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time()));
|
410 |
+
$case_object->setCode($response_data['investigationId']);
|
411 |
+
$case_object->save();
|
412 |
+
return "sent";
|
413 |
+
}
|
414 |
+
} catch (Exception $e) {
|
415 |
+
Mage::log($e->__toString(), null, 'signifyd_connect.log');
|
416 |
+
return "error";
|
417 |
+
}
|
418 |
+
}
|
419 |
+
}
|
420 |
+
|
421 |
public function getProductUrl($product)
|
422 |
{
|
423 |
$url = null;
|
484 |
return false;
|
485 |
}
|
486 |
|
|
|
|
|
|
|
|
|
|
|
487 |
public function markProcessed($order)
|
488 |
{
|
489 |
$case = Mage::getModel('signifyd_connect/case');
|
app/code/community/Signifyd/Connect/Model/Observer.php
CHANGED
@@ -2,427 +2,8 @@
|
|
2 |
|
3 |
class Signifyd_Connect_Model_Observer extends Varien_Object
|
4 |
{
|
5 |
-
public $customer = null;
|
6 |
-
public $order = null;
|
7 |
-
public $payment = null;
|
8 |
-
public $quote = null;
|
9 |
-
public $shipping_address = null;
|
10 |
-
public $billing_address = null;
|
11 |
-
|
12 |
public $joins = 0;
|
13 |
|
14 |
-
public function getProducts()
|
15 |
-
{
|
16 |
-
$products = array();
|
17 |
-
$helper = Mage::helper('signifyd_connect');
|
18 |
-
|
19 |
-
foreach ($this->quote->getAllItems() as $item) {
|
20 |
-
$product_type = $item->getProductType();
|
21 |
-
if (!$product_type || $product_type == 'simple' || $product_type == 'downloadable') {
|
22 |
-
$product_object = $item->getData('product');
|
23 |
-
|
24 |
-
if (!$product_object || !$product_object->getId()) {
|
25 |
-
$product_object = Mage::getModel('catalog/product')->load($product_type);
|
26 |
-
}
|
27 |
-
|
28 |
-
if ($product_object) {
|
29 |
-
$product = array();
|
30 |
-
|
31 |
-
$product['itemId'] = $item->getSku();
|
32 |
-
$product['itemName'] = $item->getName();
|
33 |
-
$product['itemUrl'] = $helper->getProductUrl($product_object);
|
34 |
-
$product['itemImage'] = $helper->getProductImage($product_object);
|
35 |
-
|
36 |
-
$qty = 1;
|
37 |
-
if ($item->getQty()) {
|
38 |
-
$qty = $item->getQty();
|
39 |
-
} else if ($item->getQtyOrdered()) {
|
40 |
-
$qty = $item->getQtyOrdered();
|
41 |
-
}
|
42 |
-
|
43 |
-
$price = 0;
|
44 |
-
if ($item->getBasePrice() > 0) {
|
45 |
-
$price = $item->getBasePrice();
|
46 |
-
} else if ($item->getPrice() > 0) {
|
47 |
-
$price = $item->getPrice();
|
48 |
-
} else if ($product_object->getData('price') > 0) {
|
49 |
-
$price = $product_object->getData('price');
|
50 |
-
} else {
|
51 |
-
$parent = $item->getData('parent');
|
52 |
-
|
53 |
-
if (!$parent) {
|
54 |
-
$parent = $item->getParentItem();
|
55 |
-
}
|
56 |
-
|
57 |
-
if ($parent) {
|
58 |
-
if ($parent->getBasePrice() > 0) {
|
59 |
-
$price = $parent->getBasePrice();
|
60 |
-
} else if ($parent->getPrice()) {
|
61 |
-
$price = $parent->getPrice();
|
62 |
-
}
|
63 |
-
}
|
64 |
-
}
|
65 |
-
|
66 |
-
$weight = 0;
|
67 |
-
if ($item->hasWeight()) {
|
68 |
-
$weight = $item->getWeight();
|
69 |
-
} else if ($product_object->hasWeight()) {
|
70 |
-
$weight = $product_object->getWeight();
|
71 |
-
}
|
72 |
-
|
73 |
-
$product['itemQuantity'] = intval($qty);
|
74 |
-
$product['itemPrice'] = floatval($price);
|
75 |
-
$product['itemWeight'] = floatval($weight);
|
76 |
-
|
77 |
-
$products[] = $product;
|
78 |
-
}
|
79 |
-
}
|
80 |
-
}
|
81 |
-
|
82 |
-
return $products;
|
83 |
-
}
|
84 |
-
|
85 |
-
public function getIPAddress()
|
86 |
-
{
|
87 |
-
if ($this->order->getRemoteIp()) {
|
88 |
-
if ($this->order->getXForwardedFor()) {
|
89 |
-
return $this->filterIp($this->order->getXForwardedFor());
|
90 |
-
}
|
91 |
-
|
92 |
-
return $this->filterIp($this->order->getRemoteIp());
|
93 |
-
}
|
94 |
-
|
95 |
-
// Checks each configured value in app/etc/local.xml & falls back to REMOTE_ADDR. See app/etc/local.xml.additional for examples.
|
96 |
-
return $this->filterIp(Mage::helper('core/http')->getRemoteAddr(false));
|
97 |
-
}
|
98 |
-
|
99 |
-
public function filterIp($ip)
|
100 |
-
{
|
101 |
-
$matches = array();
|
102 |
-
|
103 |
-
if (preg_match('/[0-9]{1,3}(?:\.[0-9]{1,3}){3}/', $ip, $matches)) { //ipv4
|
104 |
-
return current($matches);
|
105 |
-
}
|
106 |
-
|
107 |
-
if (preg_match('/[a-f0-9]{0,4}(?:\:[a-f0-9]{0,4}){2,7}/', strtolower($ip), $matches)) { //ipv6
|
108 |
-
return current($matches);
|
109 |
-
}
|
110 |
-
|
111 |
-
return preg_replace('/[^0-9a-zA-Z:\.]/', '', strtok(str_replace($ip, ',', "\n"), "\n"));
|
112 |
-
}
|
113 |
-
|
114 |
-
public function formatAvs($value)
|
115 |
-
{
|
116 |
-
// http://www.emsecommerce.net/avs_cvv2_response_codes.htm
|
117 |
-
$codes = array('X', 'Y', 'A', 'W', 'Z', 'N', 'U', 'R', 'E', 'S', 'D', 'M', 'B', 'P', 'C', 'I', 'G');
|
118 |
-
|
119 |
-
if ($value) {
|
120 |
-
$value = strtoupper($value);
|
121 |
-
|
122 |
-
if (strlen($value) > 1) {
|
123 |
-
if (preg_match('/\([A-Z]\)/', $value)) {
|
124 |
-
$matches = array();
|
125 |
-
|
126 |
-
preg_match('/\([A-Z]\)/', $value, $matches);
|
127 |
-
|
128 |
-
foreach ($matches as $match) {
|
129 |
-
$match = preg_replace('/[^A-Z]/', '', $match);
|
130 |
-
|
131 |
-
if (in_array($match, $codes)) {
|
132 |
-
$value = $match;
|
133 |
-
}
|
134 |
-
}
|
135 |
-
}
|
136 |
-
}
|
137 |
-
|
138 |
-
if (strlen($value) > 1) {
|
139 |
-
$value = substr($value, 0, 1);
|
140 |
-
}
|
141 |
-
|
142 |
-
if (!in_array($value, $codes)) {
|
143 |
-
$value = null;
|
144 |
-
}
|
145 |
-
}
|
146 |
-
|
147 |
-
return $value;
|
148 |
-
}
|
149 |
-
|
150 |
-
public function getAvsResponse()
|
151 |
-
{
|
152 |
-
$payment = $this->payment;
|
153 |
-
|
154 |
-
$value = null;
|
155 |
-
|
156 |
-
if ($payment->getAdditionalInformation('paypal_avs_code')) {
|
157 |
-
$value = $payment->getAdditionalInformation('paypal_avs_code');
|
158 |
-
} else if ($payment->getAdditionalInformation('cc_avs_status')) {
|
159 |
-
$value = $payment->getAdditionalInformation('cc_avs_status');
|
160 |
-
}
|
161 |
-
|
162 |
-
return $this->formatAvs($value);
|
163 |
-
}
|
164 |
-
|
165 |
-
public function getCvvResponse()
|
166 |
-
{
|
167 |
-
$payment = $this->payment;
|
168 |
-
|
169 |
-
if ($payment->getAdditionalInformation('paypal_cvv2_match')) {
|
170 |
-
return $payment->getAdditionalInformation('paypal_cvv2_match');
|
171 |
-
}
|
172 |
-
|
173 |
-
return null;
|
174 |
-
}
|
175 |
-
|
176 |
-
public function getPaymentMethod()
|
177 |
-
{
|
178 |
-
return $this->payment->getMethod();
|
179 |
-
}
|
180 |
-
|
181 |
-
private function getTransactionId()
|
182 |
-
{
|
183 |
-
return $this->payment->getTransactionId();
|
184 |
-
}
|
185 |
-
|
186 |
-
public function getPurchase()
|
187 |
-
{
|
188 |
-
$purchase = array();
|
189 |
-
|
190 |
-
// T715: Send null rather than false when we can't get the IP Address
|
191 |
-
$purchase['browserIpAddress'] = ($this->getIpAddress() ? $this->getIpAddress() : null);
|
192 |
-
$purchase['orderId'] = $this->order->getIncrementId();
|
193 |
-
$purchase['createdAt'] = date('c', strtotime($this->order->getCreatedAt())); // e.g: 2004-02-12T15:19:21+00:00
|
194 |
-
$purchase['currency'] = $this->order->getBaseCurrencyCode();
|
195 |
-
$purchase['totalPrice'] = floatval($this->order->getGrandTotal());
|
196 |
-
$purchase['shippingPrice'] = floatval($this->order->getShippingAmount());
|
197 |
-
$purchase['products'] = $this->getProducts();
|
198 |
-
$purchase['paymentGateway'] = $this->getPaymentMethod();
|
199 |
-
$purchase['transactionId'] = $this->getTransactionId();
|
200 |
-
|
201 |
-
$purchase['avsResponseCode'] = $this->getAvsResponse();
|
202 |
-
$purchase['cvvResponseCode'] = $this->getCvvResponse();
|
203 |
-
|
204 |
-
return $purchase;
|
205 |
-
}
|
206 |
-
|
207 |
-
public function isPaymentCC($payment)
|
208 |
-
{
|
209 |
-
// Although the payment structure only has the entity data for the payment
|
210 |
-
// the original payment method object is stored within the entity data.
|
211 |
-
// It's not a requirement, but every CC handler I've found subclasses
|
212 |
-
// from Mage_Payment_Model_Method_Cc, so we are using that as an
|
213 |
-
// assumption for whether a method is based on CC data
|
214 |
-
$method = $payment->getData('method_instance');
|
215 |
-
if($method)
|
216 |
-
{
|
217 |
-
return is_subclass_of($method, 'Mage_Payment_Model_Method_Cc');
|
218 |
-
}
|
219 |
-
return false;
|
220 |
-
}
|
221 |
-
|
222 |
-
public function getCard()
|
223 |
-
{
|
224 |
-
$payment = $this->payment;
|
225 |
-
$billing = $this->billing_address;
|
226 |
-
|
227 |
-
$card = array();
|
228 |
-
|
229 |
-
$card['cardHolderName'] = null;
|
230 |
-
$card['bin'] = null;
|
231 |
-
$card['last4'] = null;
|
232 |
-
$card['expiryMonth'] = null;
|
233 |
-
$card['expiryYear'] = null;
|
234 |
-
$card['hash'] = null;
|
235 |
-
|
236 |
-
$card['billingAddress'] = $this->getBillingAddress();
|
237 |
-
|
238 |
-
if ($payment->getCcOwner()) {
|
239 |
-
$card['cardHolderName'] = $payment->getCcOwner();
|
240 |
-
} else {
|
241 |
-
$card['cardHolderName'] = $billing->getFirstname() . ' ' . $billing->getLastname();
|
242 |
-
}
|
243 |
-
|
244 |
-
// Card data may be set on payment even if payment was not with card.
|
245 |
-
// If it is, we want to ignore the data
|
246 |
-
if(!$this->isPaymentCC($payment)) return $card;
|
247 |
-
|
248 |
-
if ($payment->getData('cc_last4')) {
|
249 |
-
$card['last4'] = $payment->getData('cc_last4');
|
250 |
-
}
|
251 |
-
|
252 |
-
if ($payment->getData('cc_exp_year')) {
|
253 |
-
$card['expiryYear'] = $payment->getData('cc_exp_year');
|
254 |
-
}
|
255 |
-
|
256 |
-
if ($payment->getData('cc_exp_month')) {
|
257 |
-
$card['expiryMonth'] = $payment->getData('cc_exp_month');
|
258 |
-
}
|
259 |
-
|
260 |
-
if ($payment->getData('cc_number_enc')) {
|
261 |
-
$card['hash'] = $payment->getData('cc_number_enc');
|
262 |
-
}
|
263 |
-
|
264 |
-
if ($payment->getData('cc_number') && is_numeric($payment->getData('cc_number')) && strlen((string)$payment->getData('cc_number')) > 6) {
|
265 |
-
$card['bin'] = substr((string)$payment->getData('cc_number'), 0, 6);
|
266 |
-
}
|
267 |
-
|
268 |
-
return $card;
|
269 |
-
}
|
270 |
-
|
271 |
-
public function getAddress($address_object)
|
272 |
-
{
|
273 |
-
$address = array();
|
274 |
-
|
275 |
-
$address['streetAddress'] = $address_object->getStreet1();
|
276 |
-
$address['unit'] = null;
|
277 |
-
|
278 |
-
if ($address_object->getStreet2()) {
|
279 |
-
$address['unit'] = $address_object->getStreet2();
|
280 |
-
}
|
281 |
-
|
282 |
-
$address['city'] = $address_object->getCity();
|
283 |
-
|
284 |
-
$address['provinceCode'] = $address_object->getRegionCode();
|
285 |
-
$address['postalCode'] = $address_object->getPostcode();
|
286 |
-
$address['countryCode'] = $address_object->getCountryId();
|
287 |
-
|
288 |
-
$address['latitude'] = null;
|
289 |
-
$address['longitude'] = null;
|
290 |
-
|
291 |
-
return $address;
|
292 |
-
}
|
293 |
-
|
294 |
-
public function getBillingAddress()
|
295 |
-
{
|
296 |
-
return $this->getAddress($this->billing_address);
|
297 |
-
}
|
298 |
-
|
299 |
-
public function getShippingAddress()
|
300 |
-
{
|
301 |
-
return $this->getAddress($this->shipping_address);
|
302 |
-
}
|
303 |
-
|
304 |
-
public function getRecipient()
|
305 |
-
{
|
306 |
-
$recipient = array();
|
307 |
-
|
308 |
-
// In the case of non-shipped (ex: downloadable) orders, shipping address will be null so
|
309 |
-
// in that case, we need to avoid the exception.
|
310 |
-
if($this->shipping_address) {
|
311 |
-
$recipient['deliveryAddress'] = $this->getShippingAddress();
|
312 |
-
$recipient['fullName'] = $this->shipping_address->getFirstname() . ' ' . $this->shipping_address->getLastname();
|
313 |
-
$recipient['confirmationPhone'] = $this->shipping_address->getTelephone();
|
314 |
-
// Email: Note that this field is always the same for both addresses
|
315 |
-
$recipient['confirmationEmail'] = $this->shipping_address->getEmail();
|
316 |
-
}
|
317 |
-
// Some customers have reported seeing "n/a@na.na" come through instead of a valid or null address
|
318 |
-
// We suspect that it is due to an older version of Magento. If it becomes unnecessary, do remove the extra check.
|
319 |
-
if (!$recipient['confirmationEmail'] || $recipient['confirmationEmail'] == 'n/a@na.na') {
|
320 |
-
$recipient['confirmationEmail'] = $this->order->getCustomerEmail();
|
321 |
-
}
|
322 |
-
|
323 |
-
|
324 |
-
return $recipient;
|
325 |
-
}
|
326 |
-
|
327 |
-
public function getUserAccount()
|
328 |
-
{
|
329 |
-
$customer = $this->customer;
|
330 |
-
|
331 |
-
$user = array(
|
332 |
-
"emailAddress" => null,
|
333 |
-
"username" => null,
|
334 |
-
"phone" => null,
|
335 |
-
"createdDate" => null,
|
336 |
-
"accountNumber" => null,
|
337 |
-
"lastOrderId" => null,
|
338 |
-
"aggregateOrderCount" => null,
|
339 |
-
"aggregateOrderDollars" => null,
|
340 |
-
"lastUpdateDate" => null
|
341 |
-
);
|
342 |
-
|
343 |
-
if ($customer && $customer->getId()) {
|
344 |
-
$user['emailAddress'] = $customer->getEmail();
|
345 |
-
|
346 |
-
$user['phone'] = $this->billing_address->getTelephone();
|
347 |
-
|
348 |
-
$user['createdDate'] = date('c', strtotime($customer->getCreatedAt()));
|
349 |
-
$user['lastUpdateDate'] = date('c', strtotime($customer->getUpdatedAt()));
|
350 |
-
|
351 |
-
$user['accountNumber'] = $customer->getId();
|
352 |
-
|
353 |
-
$last_order_id = null;
|
354 |
-
|
355 |
-
$orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $customer->getId());
|
356 |
-
$orders->getSelect()->order('created_at DESC');
|
357 |
-
|
358 |
-
$aggregate_total = 0.;
|
359 |
-
$order_count = 0;
|
360 |
-
|
361 |
-
foreach ($orders as $order) {
|
362 |
-
if ($last_order_id === null) {
|
363 |
-
$last_order_id = $order->getIncrementId();
|
364 |
-
}
|
365 |
-
|
366 |
-
$aggregate_total += floatval($order->getGrandTotal());
|
367 |
-
$order_count += 1;
|
368 |
-
}
|
369 |
-
|
370 |
-
$user['lastOrderId'] = $last_order_id;
|
371 |
-
$user['aggregateOrderCount'] = $order_count;
|
372 |
-
$user['aggregateOrderDollars'] = floatval($aggregate_total);
|
373 |
-
}
|
374 |
-
|
375 |
-
return $user;
|
376 |
-
}
|
377 |
-
|
378 |
-
public function getUrl()
|
379 |
-
{
|
380 |
-
if ($this->hasData('url')) {
|
381 |
-
return $this->getData('url');
|
382 |
-
}
|
383 |
-
|
384 |
-
return Mage::getStoreConfig('signifyd_connect/settings/url') . '/cases';
|
385 |
-
}
|
386 |
-
|
387 |
-
public function getAuth()
|
388 |
-
{
|
389 |
-
if ($this->hasData('auth')) {
|
390 |
-
return $this->getData('auth');
|
391 |
-
}
|
392 |
-
|
393 |
-
return Mage::getStoreConfig('signifyd_connect/settings/key');
|
394 |
-
}
|
395 |
-
|
396 |
-
public function submitCase($case)
|
397 |
-
{
|
398 |
-
$case = json_encode($case);
|
399 |
-
|
400 |
-
return Mage::helper('signifyd_connect')->request($this->getUrl(), $case, $this->getAuth(), 'application/json');
|
401 |
-
}
|
402 |
-
|
403 |
-
public function generateCase()
|
404 |
-
{
|
405 |
-
$case = array();
|
406 |
-
|
407 |
-
$case['purchase'] = $this->getPurchase();
|
408 |
-
$case['recipient'] = $this->getRecipient();
|
409 |
-
$case['card'] = $this->getCard();
|
410 |
-
$case['userAccount'] = $this->getUserAccount();
|
411 |
-
|
412 |
-
return $case;
|
413 |
-
}
|
414 |
-
|
415 |
-
public function getInvoiced($order)
|
416 |
-
{
|
417 |
-
$collection = $order->getInvoiceCollection();
|
418 |
-
|
419 |
-
foreach ($collection as $invoice) {
|
420 |
-
return true;
|
421 |
-
}
|
422 |
-
|
423 |
-
return false;
|
424 |
-
}
|
425 |
-
|
426 |
public function openCase($observer)
|
427 |
{
|
428 |
try {
|
@@ -443,77 +24,28 @@ class Signifyd_Connect_Model_Observer extends Varien_Object
|
|
443 |
if (!($order instanceof $order_model)) {
|
444 |
return;
|
445 |
}
|
446 |
-
|
447 |
-
if ($order && $order->getId()) {
|
448 |
-
if (Mage::helper('signifyd_connect')->isProcessed($order)) {
|
449 |
-
return;
|
450 |
-
}
|
451 |
-
$payments = $order->getPaymentsCollection();
|
452 |
-
|
453 |
-
foreach ($payments as $payment) {
|
454 |
-
$this->payment = $payment;
|
455 |
-
}
|
456 |
-
|
457 |
-
$state = $order->getState();
|
458 |
-
|
459 |
-
if (!$state || $state == Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) {
|
460 |
-
return;
|
461 |
-
}
|
462 |
-
|
463 |
-
$this->order = $order;
|
464 |
-
$this->billing_address = $order->getBillingAddress();
|
465 |
-
$this->shipping_address = $order->getShippingAddress();
|
466 |
-
|
467 |
-
if ($order->getCustomer()) {
|
468 |
-
$this->customer = $order->getCustomer();
|
469 |
-
}
|
470 |
-
|
471 |
-
$this->quote = $order->getQuote();
|
472 |
-
|
473 |
-
if (!$this->quote) {
|
474 |
-
$this->quote = $order;
|
475 |
-
}
|
476 |
-
|
477 |
-
$case = $this->generateCase();
|
478 |
-
|
479 |
-
$case_object = Mage::helper('signifyd_connect')->markProcessed($order);
|
480 |
|
481 |
-
|
482 |
-
|
483 |
-
try {
|
484 |
-
$response_code = $response->getHttpCode();
|
485 |
-
|
486 |
-
if (substr($response_code, 0, 1) == '2') {
|
487 |
-
$response_data = json_decode($response->getRawResponse(), true);
|
488 |
|
489 |
-
$case_object = Mage::getModel('signifyd_connect/case')->load($case_object->getOrderIncrement());
|
490 |
-
$case_object->setUpdated(strftime('%Y-%m-%d %H:%M:%S', time()));
|
491 |
-
$case_object->setCode($response_data['investigationId']);
|
492 |
-
$case_object->save();
|
493 |
-
}
|
494 |
-
} catch (Exception $e) {
|
495 |
-
Mage::log($e->__toString(), null, 'signifyd_connect.log');
|
496 |
-
}
|
497 |
-
}
|
498 |
} catch (Exception $e) {
|
499 |
Mage::log($e->__toString(), null, 'signifyd_connect.log');
|
500 |
}
|
501 |
}
|
502 |
|
503 |
-
public function logData()
|
504 |
{
|
505 |
// Used to capture data for testing with
|
506 |
|
507 |
-
$order_data = json_encode($
|
508 |
-
$billing_data = json_encode($
|
509 |
-
$shipping_data = json_encode($
|
510 |
-
$customer_data = json_encode($
|
511 |
-
$payment_data = json_encode($
|
512 |
-
$quote_data = json_encode($
|
513 |
$items = array();
|
514 |
$products = array();
|
515 |
|
516 |
-
foreach ($
|
517 |
$items[$item->getId()] = $item->getData();
|
518 |
$product = Mage::getModel('catalog/product')->load($item->getProductId());
|
519 |
$products[$item->getId()] = $product->getData();
|
@@ -561,7 +93,6 @@ class Signifyd_Connect_Model_Observer extends Varien_Object
|
|
561 |
$request = Mage::app()->getRequest();
|
562 |
$module = $request->getModuleName();
|
563 |
$controller = $request->getControllerName();
|
564 |
-
$action = $request->getActionName();
|
565 |
|
566 |
if ($module != $this->getAdminRoute() || $controller != 'sales_order') {
|
567 |
return;
|
@@ -581,7 +112,6 @@ class Signifyd_Connect_Model_Observer extends Varien_Object
|
|
581 |
$request = Mage::app()->getRequest();
|
582 |
$module = $request->getModuleName();
|
583 |
$controller = $request->getControllerName();
|
584 |
-
$action = $request->getActionName();
|
585 |
|
586 |
if ($module != $this->getAdminRoute() || $controller != 'sales_order') {
|
587 |
return;
|
@@ -651,11 +181,27 @@ class Signifyd_Connect_Model_Observer extends Varien_Object
|
|
651 |
'guarantee' => 'guarantee'));
|
652 |
$this->joins++;
|
653 |
}
|
654 |
-
|
655 |
-
Mage::log('joined');
|
656 |
}
|
657 |
}
|
658 |
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
Mage::helper('signifyd_connect')->buildAndSendOrderToSignifyd($order);
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
} catch (Exception $e) {
|
31 |
Mage::log($e->__toString(), null, 'signifyd_connect.log');
|
32 |
}
|
33 |
}
|
34 |
|
35 |
+
public function logData($order, $payment, $quote)
|
36 |
{
|
37 |
// Used to capture data for testing with
|
38 |
|
39 |
+
$order_data = json_encode($order->getData());
|
40 |
+
$billing_data = json_encode($order->getBillingAddress()->getData());
|
41 |
+
$shipping_data = json_encode($order->getShippingAddress()->getData());
|
42 |
+
$customer_data = json_encode($order->getCustomer()->getData());
|
43 |
+
$payment_data = json_encode($payment->getData());
|
44 |
+
$quote_data = json_encode($quote->getData());
|
45 |
$items = array();
|
46 |
$products = array();
|
47 |
|
48 |
+
foreach ($quote->getAllItems() as $item) {
|
49 |
$items[$item->getId()] = $item->getData();
|
50 |
$product = Mage::getModel('catalog/product')->load($item->getProductId());
|
51 |
$products[$item->getId()] = $product->getData();
|
93 |
$request = Mage::app()->getRequest();
|
94 |
$module = $request->getModuleName();
|
95 |
$controller = $request->getControllerName();
|
|
|
96 |
|
97 |
if ($module != $this->getAdminRoute() || $controller != 'sales_order') {
|
98 |
return;
|
112 |
$request = Mage::app()->getRequest();
|
113 |
$module = $request->getModuleName();
|
114 |
$controller = $request->getControllerName();
|
|
|
115 |
|
116 |
if ($module != $this->getAdminRoute() || $controller != 'sales_order') {
|
117 |
return;
|
181 |
'guarantee' => 'guarantee'));
|
182 |
$this->joins++;
|
183 |
}
|
|
|
|
|
184 |
}
|
185 |
}
|
186 |
}
|
187 |
+
|
188 |
+
public function coreBlockAbstractPrepareLayoutBefore(Varien_Event_Observer $observer)
|
189 |
+
{
|
190 |
+
if (!Mage::getStoreConfig('signifyd_connect/settings/enabled') && !$this->getEnabled()) {
|
191 |
+
return;
|
192 |
+
}
|
193 |
+
|
194 |
+
$block = $observer->getEvent()->getBlock();
|
195 |
+
if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
|
196 |
+
&& $block->getRequest()->getControllerName() == 'sales_order')
|
197 |
+
{
|
198 |
+
$block->setFormFieldName('increment_id');
|
199 |
+
$block->addItem('signifyd_connect', array(
|
200 |
+
'label' => 'Send order(s) to Signifyd',
|
201 |
+
'url' => Mage::helper("adminhtml")->getUrl('signifyd/adminhtml_signifyd/send'),
|
202 |
+
));
|
203 |
+
}
|
204 |
+
}
|
205 |
|
206 |
public function coreBlockAbstractToHtmlBefore(Varien_Event_Observer $observer)
|
207 |
{
|
app/code/community/Signifyd/Connect/controllers/Adminhtml/SignifydController.php
CHANGED
@@ -18,4 +18,33 @@ class Signifyd_Connect_Adminhtml_SignifydController extends Mage_Adminhtml_Contr
|
|
18 |
$this->getLayout()->createBlock('signifyd_connect/adminhtml_sales_order_grid')->toHtml()
|
19 |
);
|
20 |
}
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
$this->getLayout()->createBlock('signifyd_connect/adminhtml_sales_order_grid')->toHtml()
|
19 |
);
|
20 |
}
|
21 |
+
|
22 |
+
public function sendAction()
|
23 |
+
{
|
24 |
+
try {
|
25 |
+
$orderIds = $this->getRequest()->getParam('order_ids');
|
26 |
+
if (!is_array($orderIds)) {
|
27 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select order(s)'));
|
28 |
+
} else {
|
29 |
+
$collection = Mage::getModel('sales/order')->getCollection()
|
30 |
+
->addFieldToSelect('*')
|
31 |
+
->addFieldToFilter('entity_id', array('in' => $orderIds));
|
32 |
+
|
33 |
+
foreach ($collection as $order) {
|
34 |
+
$result = Mage::helper('signifyd_connect')->buildAndSendOrderToSignifyd($order, /*forceSend*/ true);
|
35 |
+
if($result == "sent") {
|
36 |
+
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Successfully sent order ' . $order->getIncrementId() . '.'));
|
37 |
+
} else if ($result == "exists") {
|
38 |
+
Mage::getSingleton('adminhtml/session')->addWarning(Mage::helper('adminhtml')->__('Order ' . $order->getIncrementId() . ' has already been sent to Signifyd.'));
|
39 |
+
} else {
|
40 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Order ' . $order->getIncrementId() . ' failed to send. See log for details.'));
|
41 |
+
}
|
42 |
+
}
|
43 |
+
}
|
44 |
+
} catch(Exception $ex) {
|
45 |
+
Mage::log($ex->__toString(), null, 'signifyd_connect.log');
|
46 |
+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Send failed. See log for details'));
|
47 |
+
}
|
48 |
+
$this->_redirectReferer();
|
49 |
+
}
|
50 |
+
}
|
app/code/community/Signifyd/Connect/controllers/ConnectController.php
CHANGED
@@ -282,24 +282,23 @@ class Signifyd_Connect_ConnectController extends Mage_Core_Controller_Front_Acti
|
|
282 |
$negativeAction = $this->negativeGuaranteeAction();
|
283 |
$positiveAction = $this->positiveGuaranteeAction();
|
284 |
|
285 |
-
if ($this->_request['guaranteeDisposition']
|
286 |
-
if($
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
}
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
Mage::log("Unknown action $positiveAction", null, 'signifyd_connect.log');
|
303 |
}
|
304 |
}
|
305 |
|
282 |
$negativeAction = $this->negativeGuaranteeAction();
|
283 |
$positiveAction = $this->positiveGuaranteeAction();
|
284 |
|
285 |
+
if (isset($this->_request ['guaranteeDisposition'])) {
|
286 |
+
if ($this->_request ['guaranteeDisposition'] == 'DECLINED' && $negativeAction != 'nothing') {
|
287 |
+
if ($negativeAction == 'hold') {
|
288 |
+
$this->holdOrder($order);
|
289 |
+
$impeded = true;
|
290 |
+
} else if ($negativeAction == 'cancel') {
|
291 |
+
$this->cancelOrder($order);
|
292 |
+
$impeded = true;
|
293 |
+
} else {
|
294 |
+
Mage::log("Unknown action $negativeAction", null, 'signifyd_connect.log');
|
295 |
+
}
|
296 |
+
} else if ($this->_request ['guaranteeDisposition'] == 'APPROVED' && $positiveAction != 'nothing') {
|
297 |
+
if ($positiveAction == 'unhold') {
|
298 |
+
$this->unholdOrder($order);
|
299 |
+
} else {
|
300 |
+
Mage::log("Unknown action $positiveAction", null, 'signifyd_connect.log');
|
301 |
+
}
|
|
|
302 |
}
|
303 |
}
|
304 |
|
app/code/community/Signifyd/Connect/etc/config.xml
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<config>
|
4 |
<modules>
|
5 |
<Signifyd_Connect>
|
6 |
-
<version>3.
|
7 |
</Signifyd_Connect>
|
8 |
</modules>
|
9 |
<global>
|
@@ -170,6 +170,14 @@
|
|
170 |
</signifyd_connect>
|
171 |
</observers>
|
172 |
</core_block_abstract_to_html_before>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
</events>
|
174 |
</adminhtml>
|
175 |
</config>
|
3 |
<config>
|
4 |
<modules>
|
5 |
<Signifyd_Connect>
|
6 |
+
<version>3.10.0</version>
|
7 |
</Signifyd_Connect>
|
8 |
</modules>
|
9 |
<global>
|
170 |
</signifyd_connect>
|
171 |
</observers>
|
172 |
</core_block_abstract_to_html_before>
|
173 |
+
<core_block_abstract_prepare_layout_before>
|
174 |
+
<observers>
|
175 |
+
<signifyd_connect>
|
176 |
+
<model>signifyd_connect/observer</model>
|
177 |
+
<method>coreBlockAbstractPrepareLayoutBefore</method>
|
178 |
+
</signifyd_connect>
|
179 |
+
</observers>
|
180 |
+
</core_block_abstract_prepare_layout_before>
|
181 |
</events>
|
182 |
</adminhtml>
|
183 |
</config>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Signifyd_Connect</name>
|
4 |
-
<version>3.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
|
7 |
<channel>community</channel>
|
@@ -10,9 +10,9 @@
|
|
10 |
<description>Supports all versions of Magento</description>
|
11 |
<notes>Supports all versions of Magento</notes>
|
12 |
<authors><author><name>signifyd</name><user>auto-converted</user><email>manelis@signifyd.com</email></author></authors>
|
13 |
-
<date>2015-07
|
14 |
-
<time>
|
15 |
-
<contents><target name="mageetc"><dir name="modules"><file name="Signifyd_Connect.xml" hash="bcd998a24567eba8a20423c40fba2adf"/></dir></target><target name="magecommunity"><dir name="Signifyd"><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Grid.php" hash="52843fc84cdb65214bb3469b6390bee5"/></dir><file name="Order.php" hash="e49f869c0aa5fb3ab6b70fb5752049ac"/></dir></dir><file name="Renderer.php" hash="5564e9c6926afbbdade26a6fe746948a"/></dir><dir name="Helper"><file name="Data.php" hash="
|
16 |
<compatible/>
|
17 |
<dependencies/>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Signifyd_Connect</name>
|
4 |
+
<version>3.10.0</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
|
7 |
<channel>community</channel>
|
10 |
<description>Supports all versions of Magento</description>
|
11 |
<notes>Supports all versions of Magento</notes>
|
12 |
<authors><author><name>signifyd</name><user>auto-converted</user><email>manelis@signifyd.com</email></author></authors>
|
13 |
+
<date>2015-08-07</date>
|
14 |
+
<time>14:15:54</time>
|
15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Signifyd_Connect.xml" hash="bcd998a24567eba8a20423c40fba2adf"/></dir></target><target name="magecommunity"><dir name="Signifyd"><dir name="Connect"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="Grid.php" hash="52843fc84cdb65214bb3469b6390bee5"/></dir><file name="Order.php" hash="e49f869c0aa5fb3ab6b70fb5752049ac"/></dir></dir><file name="Renderer.php" hash="5564e9c6926afbbdade26a6fe746948a"/></dir><dir name="Helper"><file name="Data.php" hash="ac617c88706180a7a0ac9654efd60989"/></dir><dir name="Model"><dir name="Resource"><dir name="Case"><file name="Collection.php" hash="b7dac9979a0c81db56294d1548570fc2"/></dir><file name="Case.php" hash="60d14407c9c90148aad543ce6868f343"/></dir><dir name="System"><dir name="Config"><dir name="Source"><dir name="Options"><file name="Negative.php" hash="098488fbb0ea84945fdd1e1fe8449b4b"/><file name="Positive.php" hash="80b4cdd2bae6e2a2f3a273fa49d32331"/></dir></dir></dir></dir><file name="Case.php" hash="2a28a63f02df1b9103b89a562c0abe1b"/><file name="Cron.php" hash="51665978bd2bcf67b493f2a2b450d1b8"/><file name="Link.php" hash="ecaf4c403a586b4b5c8b67c77f6ac433"/><file name="Observer.php" hash="c7b1d1439c421ae26152d71886a4550d"/><file name="Setup.php" hash="e803ffb4b86c7d8ec1d149e665d65877"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="SignifydController.php" hash="2907e9b358cde41aef4ea598b3782ee5"/></dir><file name="ConnectController.php" hash="4b1a3b7557e1de259e5e4df9df20e866"/></dir><dir name="etc"><file name="adminhtml.xml" hash="894bd3f5ac76e9f602ab6ab592648b03"/><file name="config.xml" hash="0907ae3071110273f49b4c465c8d5ae6"/><file name="system.xml" hash="c42b2db859506998618701c980c6245f"/></dir><dir name="sql"><dir name="signifyd_connect_setup"><file name="mysql4-install-3.1.1.php" hash="7fb2ccaf8352eea26e626ace6de53d80"/><file name="mysql4-install-3.3.0.php" hash="f61d0c018b28ae04d8d14b38556d18ad"/><file name="mysql4-install-3.4.0.php" hash="109cc5ca60974d0c4755dcb0f5ade3e7"/><file name="mysql4-install-3.4.5.php" hash="401b92235c0e534c941a64c60d24b851"/><file name="mysql4-install-3.7.0.php" hash="48a9d427944a4e63a000343ab329f517"/><file name="mysql4-install-3.8.0.php" hash="0fb3583eb4481c21b84ea674abc200f0"/><file name="mysql4-upgrade-3.2.0-3.2.1.php" hash="9e36c608afd6e30e3052334e085eeff4"/><file name="mysql4-upgrade-3.2.1-3.2.2.php" hash="efcc5d46a41e549e508a693f1e77bf44"/><file name="mysql4-upgrade-3.2.2-3.2.3.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.2.3-3.3.0.php" hash="94b907c2cacde5fb9831408ce9a06190"/><file name="mysql4-upgrade-3.3.0-3.4.0.php" hash="6eb18705081483bb8d9c14adcdefd095"/><file name="mysql4-upgrade-3.4.0-3.4.1.php" hash="79f2064f1fa20d646e66aa3e7912d2a0"/><file name="mysql4-upgrade-3.4.1-3.4.2.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.2-3.4.3.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.3-3.4.4.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.4-3.4.5.php" hash="5b7507d6bb97bf44d27b7a89c56924bb"/><file name="mysql4-upgrade-3.4.5-3.4.6.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.6-3.4.7.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.7-3.4.8.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.4.8-3.5.0.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.5.0-3.5.1.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.5.1-3.5.2.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.5.2-3.5.3.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.5.3-3.6.0.php" hash="3ceb86495f33475774d4fc8727254cfc"/><file name="mysql4-upgrade-3.6.0-3.7.0.php" hash="1456a6d0ddf091be9c87b3bbc91263ba"/><file name="mysql4-upgrade-3.7.0-3.8.0.php" hash="e6fc207541cacc5079e8ea8e4d55f356"/></dir></dir></dir></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies/>
|
18 |
</package>
|