shipping_easy - Version 2.0.0

Version Notes

Easily integrate your Magento store with ShippingEasy to allow your order, tracking and fulfillment data to populate in real-time across all systems. Plug in your UPS and FedEx accounts or other marketplaces like eBay or Amazon to download all new orders and easily assign shipping preferences, rates and delivery options in real-time.

Download this release

Release Info

Developer Kevin Cogill
Extension shipping_easy
Version 2.0.0
Comparing to
See all releases


Code changes from version 0.1.0 to 2.0.0

Files changed (32) hide show
  1. app/code/community/Shippingeasy/Fulfilment/Block/Adminhtml/Sales/Order/View.php +0 -44
  2. app/code/community/Shippingeasy/Fulfilment/Block/Adminhtml/System/Config/Error/Log.php +0 -37
  3. app/code/community/Shippingeasy/Fulfilment/Block/Adminhtml/System/Config/Links/Api.php +48 -0
  4. app/code/community/Shippingeasy/Fulfilment/Helper/Data.php +9 -9
  5. app/code/community/Shippingeasy/Fulfilment/Model/Fulfilment.php +0 -138
  6. app/code/community/Shippingeasy/Fulfilment/Model/Mysql4/Setup.php +0 -12
  7. app/code/community/Shippingeasy/Fulfilment/Model/Observer.php +0 -258
  8. app/code/community/Shippingeasy/Fulfilment/controllers/Adminhtml/FulfilmentController.php +0 -45
  9. app/code/community/Shippingeasy/Fulfilment/controllers/CallbackController.php +0 -47
  10. app/code/community/Shippingeasy/Fulfilment/controllers/IndexController.php +38 -10
  11. app/code/community/Shippingeasy/Fulfilment/etc/config.xml +53 -126
  12. app/code/community/Shippingeasy/Fulfilment/etc/system.xml +65 -109
  13. app/code/community/Shippingeasy/Fulfilment/sql/fulfilment_setup/mysql4-install-0.1.0.php +0 -25
  14. app/design/adminhtml/default/default/template/shippingeasy/system/config/button.phtml +10 -0
  15. app/etc/modules/Shippingeasy_Fulfilment.xml +8 -8
  16. lib/ShippingEasy/ShippingEasy.php +33 -0
  17. lib/ShippingEasy/ShippingEasy/ApiConnectionError.php +5 -0
  18. lib/ShippingEasy/ShippingEasy/ApiError.php +5 -0
  19. lib/ShippingEasy/ShippingEasy/ApiRequestor.php +175 -0
  20. lib/ShippingEasy/ShippingEasy/AuthenticationError.php +5 -0
  21. lib/ShippingEasy/ShippingEasy/Authenticator.php +37 -0
  22. lib/ShippingEasy/ShippingEasy/Cancellation.php +16 -0
  23. lib/ShippingEasy/ShippingEasy/Error.php +27 -0
  24. lib/ShippingEasy/ShippingEasy/InvalidRequestError.php +9 -0
  25. lib/ShippingEasy/ShippingEasy/Object.php +12 -0
  26. lib/ShippingEasy/ShippingEasy/Order.php +30 -0
  27. lib/ShippingEasy/ShippingEasy/PartnerAccount.php +9 -0
  28. lib/ShippingEasy/ShippingEasy/PartnerSession.php +9 -0
  29. lib/ShippingEasy/ShippingEasy/ShippingEasy.php +57 -0
  30. lib/ShippingEasy/ShippingEasy/Signature.php +67 -0
  31. lib/ShippingEasy/ShippingEasy/SignedUrl.php +35 -0
  32. package.xml +9 -12
app/code/community/Shippingeasy/Fulfilment/Block/Adminhtml/Sales/Order/View.php DELETED
@@ -1,44 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Adminhtml sales order view
5
- *
6
- * @category Mage
7
- * @package Shippingeasy_Fulfilment
8
- */
9
- class Shippingeasy_Fulfilment_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {
10
-
11
- public function __construct() {
12
-
13
- parent::__construct();
14
-
15
- if (Mage::getModel('fulfilment/fulfilment')->isEnabled()):
16
-
17
- if ($this->getOrder()->getIsExported() == '0'):
18
- $message = Mage::helper('fulfilment')->__('Are you sure you want to send this order to ShippingEasy?');
19
- $this->_addButton('shippingeasy_id', array(
20
- 'label' => Mage::helper('fulfilment')->__('Export to ShippingEasy'),
21
- 'onclick' => "confirmSetLocation('{$message}', '{$this->getshippingEastUrl()}')",
22
- 'class' => 'go'), 0, 100, 'header', 'header');
23
- endif;
24
-
25
- if ($this->getOrder()->getIsExported() == '1'):
26
- $messageCancel = Mage::helper('fulfilment')->__('Are you sure you want to cancel this order in ShippingEasy?');
27
- $this->_addButton('shippingeasy_cancel', array(
28
- 'label' => Mage::helper('fulfilment')->__('Cancel Order in ShippingEasy'),
29
- 'onclick' => "confirmSetLocation('{$messageCancel}', '{$this->getshippingEastCancelUrl()}')",
30
- 'class' => 'go'), 1, 110, 'header', 'header');
31
- endif;
32
- endif;
33
- }
34
-
35
- public function getshippingEastUrl() {
36
- return $this->getUrl('shippingeasy/adminhtml_fulfilment/export/');
37
- }
38
-
39
- public function getshippingEastCancelUrl() {
40
- return $this->getUrl('shippingeasy/adminhtml_fulfilment/cancel/');
41
- }
42
-
43
- }
44
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Shippingeasy/Fulfilment/Block/Adminhtml/System/Config/Error/Log.php DELETED
@@ -1,37 +0,0 @@
1
- <?php
2
- /**
3
- * @category Shippingeasy
4
- * @package Shippingeasy_Fulfilment
5
- *
6
- */
7
-
8
- class Shippingeasy_Fulfilment_Block_Adminhtml_System_Config_Error_Log
9
- extends Mage_Adminhtml_Block_System_Config_Form_Field
10
- {
11
- /*
12
- * Set template
13
- */
14
- protected function _construct()
15
- {
16
- parent::_construct();
17
- $this->setTemplate('shippingeasy/errorlog.phtml');
18
- }
19
-
20
- public function render(Varien_Data_Form_Element_Abstract $element)
21
- {
22
- $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
23
- return parent::render($element);
24
- }
25
-
26
- /**
27
- * Return element html
28
- *
29
- * @param Varien_Data_Form_Element_Abstract $element
30
- * @return string
31
- */
32
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
33
- {
34
- return $this->_toHtml();
35
- }
36
-
37
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Shippingeasy/Fulfilment/Block/Adminhtml/System/Config/Links/Api.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shippingeasy
4
+ * @package Shippingeasy_Fulfilment
5
+ *
6
+ */
7
+
8
+ class Shippingeasy_Fulfilment_Block_Adminhtml_System_Config_Links_Api
9
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
10
+ {
11
+ /*
12
+ * Set template
13
+ */
14
+ protected function _construct()
15
+ {
16
+ parent::_construct();
17
+ $this->setTemplate('shippingeasy/system/config/button.phtml');
18
+ }
19
+
20
+ /**
21
+ * Return element html
22
+ *
23
+ * @param Varien_Data_Form_Element_Abstract $element
24
+ * @return string
25
+ */
26
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
27
+ {
28
+ return $this->_toHtml();
29
+ }
30
+
31
+ /**
32
+ * Generate button html
33
+ *
34
+ * @return string
35
+ */
36
+ public function getButtonHtml()
37
+ {
38
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')
39
+ ->setData(array(
40
+ 'id' => 'shipeasy_get_api_values',
41
+ 'label' => $this->helper('adminhtml')->__('Get Values'),
42
+ 'onclick' => 'javascript:getValues(); return false;'
43
+ ));
44
+
45
+ return $button->toHtml();
46
+ }
47
+
48
+ }
app/code/community/Shippingeasy/Fulfilment/Helper/Data.php CHANGED
@@ -1,10 +1,10 @@
1
- <?php
2
-
3
- /**
4
- * @category Shippingeasy
5
- * @package Shippingeasy_Fulfilment
6
- *
7
- */
8
- class Shippingeasy_Fulfilment_Helper_Data extends Mage_Core_Helper_Abstract {
9
-
10
  }
1
+ <?php
2
+
3
+ /**
4
+ * @category Shippingeasy
5
+ * @package Shippingeasy_Fulfilment
6
+ *
7
+ */
8
+ class Shippingeasy_Fulfilment_Helper_Data extends Mage_Core_Helper_Abstract {
9
+
10
  }
app/code/community/Shippingeasy/Fulfilment/Model/Fulfilment.php DELETED
@@ -1,138 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * @category Shippingeasy
5
- * @package Shippingeasy_Fulfilment
6
- *
7
- */
8
- require_once(Mage::getBaseDir('lib') . '/ShippingEasy.php');
9
-
10
- class Shippingeasy_Fulfilment_Model_Fulfilment extends Mage_Core_Model_Abstract {
11
-
12
- const SHIPEASY_ENABLED = 'shippingeasy/fulfilment/active';
13
- const SHIPEASY_STORE_APIKEY = 'shippingeasy/fulfilment/apikey';
14
- const SHIPEASY_SECRET_APIKEY = 'shippingeasy/fulfilment/secretkey';
15
- const SHIPEASY_STORE_URL = 'shippingeasy/fulfilment/url';
16
- const STORE_APIKEY = 'shippingeasy/fulfilment/store_apikey';
17
- const WEIGHT_UNIT = 'shippingeasy/fulfilment/weight_unit';
18
-
19
- public function _construct() {
20
- parent::_construct();
21
- $this->_init('fulfilment/fulfilment');
22
- }
23
-
24
- public function isEnabled() {
25
- if (Mage::getStoreConfig(self::SHIPEASY_ENABLED) == false):
26
- return FALSE;
27
- else:
28
- return TRUE;
29
- endif;
30
- }
31
-
32
- public function exportMissingProcessedOrders() {
33
- Mage::getModel('fulfilment/observer')->submitOrder('36', true);
34
- }
35
-
36
- public function cancelOrder($orderId) {
37
- $order = Mage::getModel('sales/order')->load($orderId);
38
-
39
- if ($order) {
40
- Mage::getModel('fulfilment/observer')->setShippingEasyConfiguration();
41
-
42
- $cancellation = new ShippingEasy_Cancellation(Mage::getStoreConfig(Shippingeasy_Fulfilment_Model_Observer::STORE_APIKEY), $order->getIncrementId());
43
- $response = $cancellation->create();
44
-
45
- if (isset($response)):
46
- if ($response['order']['external_order_identifier'] == $order->getIncrementId()):
47
- $comment = 'Order successfully cancelled in ShippingEasy';
48
- $order->addStatusHistoryComment($comment, false);
49
- $order->setIsExported('2')->save();
50
- return true;
51
- else:
52
- return false;
53
- endif;
54
- else:
55
- return false;
56
- endif;
57
- }
58
- }
59
-
60
- public function createShipment($orderIncrementId, $trackingNo, $carrierKey, $carrierServiceKey) {
61
- $itemsToship = array();
62
- $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
63
- if ($order) {
64
- if ($order->canShip()) { /// Making shipments
65
- $convertor = Mage::getModel('sales/convert_order');
66
- $shipment = $convertor->toShipment($order);
67
- $totalToShip = count($order->getAllItems());
68
- foreach ($order->getAllItems() as $orderItem) {
69
- if (!$orderItem->getQtyToShip()) {
70
- continue;
71
- }
72
- if ($orderItem->getIsVirtual()) {
73
- continue;
74
- }
75
- $item = $convertor->itemToShipmentItem($orderItem);
76
- $qty = $orderItem->getQtyToShip();
77
- $item->setQty($qty);
78
- $shipment->addItem($item);
79
- } //end of foreach
80
-
81
- if ($shipment && $totalToShip != '') {
82
- $shipment->register();
83
- $order->setIsInProcess(true);
84
- $transactionSave = Mage::getModel('core/resource_transaction')
85
- ->addObject($shipment)
86
- ->addObject($shipment->getOrder())
87
- ->save();
88
-
89
- Mage::log('New Shipment created for ' . $incId, 'shippingEasy.log');
90
- $shipment = Mage::getModel('sales/order_shipment')->load($shipment->getEntityId());
91
- } else { //echo "BBB"; exit;
92
- $shipment = Mage::getResourceModel('sales/order_shipment_collection')
93
- ->addAttributeToSelect('*')
94
- ->setOrderFilter($order->getData('entity_id'));
95
- $shipment = $shipment->getFirstItem(); // loading collection and get 1st shipment
96
- }
97
- } else { // shipment already added -load shipment Object and add tracking information only.
98
- $shipment = Mage::getResourceModel('sales/order_shipment_collection')
99
- ->addAttributeToSelect('*')
100
- ->setOrderFilter($order->getData('entity_id'));
101
- $shipment = $shipment->getFirstItem(); // loading collection and get 1st shipment
102
- }
103
-
104
- // add tracking information ///
105
- if ($shipment)
106
- $trackingCodes = array();
107
- if ($shipment->getData('entity_id')) {
108
- $shipment = Mage::getModel('sales/order_shipment')->load($shipment->getEntityId());
109
- if ($this->checkAlreadyAdded($trackingNo) && !in_array($trackingNo, $trackingCodes)) {
110
- $sendEmail = true;
111
- $track = Mage::getModel('sales/order_shipment_track')
112
- ->setNumber($trackingNo)
113
- ->setCarrierCode(strtolower($carrierKey))
114
- ->setTitle($carrierKey . " - " . $carrierServiceKey);
115
- $shipment->addTrack($track);
116
- array_push($trackingCodes, $trackingNo);
117
- unset($track);
118
- }
119
- if ($sendEmail == true) {
120
- $shipment->save();
121
- $shipment->sendEmail(true)->setEmailSent(true)->save();
122
- $order->save();
123
- }
124
- }
125
- }
126
- }
127
-
128
- public function checkAlreadyAdded($trackingCode) {
129
- $track = Mage::getModel('sales/order_shipment_track')->getCollection();
130
- $track->addFieldtoFilter('track_number', $trackingCode);
131
- if ($track->getSize() == 0) {
132
- return true;
133
- } else {
134
- return false;
135
- }
136
- }
137
-
138
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Shippingeasy/Fulfilment/Model/Mysql4/Setup.php DELETED
@@ -1,12 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Shippingeasy Setup
5
- *
6
- * @category Shippingeasy
7
- * @package Shippingeasy_Fulfilment
8
- *
9
- */
10
- class Shippingeasy_Fulfilment_Model_Mysql4_Setup extends Mage_Core_Model_Resource_Setup {
11
-
12
- }
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Shippingeasy/Fulfilment/Model/Observer.php DELETED
@@ -1,258 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * @category Shippingeasy
5
- * @package Shippingeasy_Fulfilment
6
- *
7
- */
8
- require_once(Mage::getBaseDir('lib') . '/ShippingEasy.php');
9
-
10
- class Shippingeasy_Fulfilment_Model_Observer {
11
-
12
- const SHIPEASY_ENABLED = 'shippingeasy/fulfilment/active';
13
- const SHIPEASY_STORE_APIKEY = 'shippingeasy/fulfilment/apikey';
14
- const SHIPEASY_SECRET_APIKEY = 'shippingeasy/fulfilment/secretkey';
15
- const SHIPEASY_STORE_URL = 'shippingeasy/fulfilment/url';
16
- const STORE_APIKEY = 'shippingeasy/fulfilment/store_apikey';
17
- const WEIGHT_UNIT = 'shippingeasy/fulfilment/weight_unit';
18
- const BIN_PICKING_NUMBER = 'shippingeasy/fulfilment/bin_picking_number';
19
-
20
- public function multiShippingOrders($observer) {
21
-
22
- $orderIds = $observer->getOrderIds();
23
- if (is_array($orderIds)):
24
- foreach ($orderIds as $i => $id):
25
- $this->submitOrder($id, TRUE);
26
- endforeach;
27
- endif;
28
- }
29
-
30
- public function submitOrder($observer, $missing = false) {
31
-
32
- if (Mage::getStoreConfig(self::SHIPEASY_ENABLED) == false):
33
- return;
34
- endif;
35
-
36
- $orderId = Mage::getSingleton('checkout/type_onepage')->getCheckout()->getLastOrderId();
37
- $checkOutType = Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod();
38
- if ($missing == true) {
39
- $orderId = $observer;
40
- } else if (empty($orderId)) { // backend order
41
- $order = $observer->getEvent()->getOrder();
42
- $orderId = $order->getData('entity_id');
43
- }
44
-
45
- $shipEasy = new Varien_Object();
46
-
47
- $order = Mage::getModel('sales/order')->load($orderId);
48
- $shipping = $order->getShippingAddress();
49
-
50
- $shipEasy->setExternalOrderIdentifier($order->getIncrementId());
51
- $shipEasy->setOrderedAt($order->getCreatedAt());
52
- $shipEasy->setOrderStatus('awaiting_shipment');
53
- $shipEasy->setSubtotalIncludingTax($this->fnumb($order->getSubtotalInclTax()));
54
- $shipEasy->setTotalIncludingTax($this->fnumb($order->getGrandTotal()));
55
- $shipEasy->setTotalExcludingTax($this->fnumb( ($order->getGrandTotal() - $order->getTaxAmount() ) ));
56
-
57
- $shipEasy->setDiscountAmount($this->fnumb( $order->getDiscountAmount() ));
58
- $shipEasy->setCouponDiscount($this->fnumb(0));
59
- $shipEasy->setSubtotalIncludingTax($this->fnumb($order->getSubtotalInclTax() ));
60
- $shipEasy->setSubtotalExcludingTax($this->fnumb($order->getSubtotal() ));
61
- $shipEasy->setSubtotalTax($this->fnumb($order->getTaxAmount() ));
62
-
63
- $shipEasy->setTotalTax($this->fnumb( $order->getTaxAmount()));
64
- $shipEasy->setBaseShippingCost($this->fnumb($order->getBaseShippingAmount()));
65
- $shipEasy->setShippingCostIncludingTax($this->fnumb($order->getShippingAmount()));
66
- $shipEasy->setShippingCostExcludingTax($this->fnumb($order->getShippingAmount()));
67
-
68
- $shipEasy->setShippingCostTax($this->fnumb($order->getBaseShippingTaxAmount()));
69
- $shipEasy->setBaseHandlingCost(0.00);
70
- $shipEasy->setHandlingCostExcludingTax(0.00);
71
- $shipEasy->setHandlingCostIncludingTax(0.00);
72
- $shipEasy->setHandlingCostTax(0.00);
73
- $shipEasy->setBaseWrappingCost(0.00);
74
- $shipEasy->setWrappingCostExcludingTax(0.00);
75
- $shipEasy->setWrappingCostIncludingTax(0.00);
76
- $shipEasy->setWrappingCostTax(0.00);
77
- $shipEasy->setNotes("");
78
-
79
-
80
- //billing
81
- $billing = $order->getBillingAddress();
82
- //$bill_country = Mage::getModel('directory/country')->load($billing->getCountryId())->getData('iso3_code');
83
- $bill_country = Mage::getModel('directory/country')->load($billing->getCountryId())->getName();
84
- if (is_array($billing->getStreet())):
85
- $billAddress = $billing->getStreet();
86
- if (isset($billAddress[1])):
87
- $shipEasy->setBillingAddress($billAddress[0]);
88
- $shipEasy->setBillingAddress2($billAddress[1]);
89
- else:
90
- $shipEasy->setBillingAddress($billAddress[0]);
91
- endif;
92
- else:
93
- $shipEasy->setBillingAddress($billing->getStreet());
94
- endif;
95
-
96
- $shipEasy->setBillingCompany($billing->getCompany());
97
- $shipEasy->setBillingFirstName($billing->getFirstname());
98
- $shipEasy->setBillingLastName($billing->getLastname());
99
- $shipEasy->setBillingCity($billing->getCity());
100
- $shipEasy->setBillingState($billing->getRegion());
101
- $shipEasy->setBillingPostalCode($billing->getPostcode());
102
-
103
- $shipEasy->setBillingCountry($bill_country);
104
- $shipEasy->setBillingPhoneNumber($billing->getTelephone());
105
- $shipEasy->setBillingEmail($billing->getEmail());
106
-
107
- // shipping
108
- $recipients = new Varien_Object();
109
- $shipping = $order->getShippingAddress();
110
- $shipCountry = Mage::getModel('directory/country')->load($shipping->getCountryId())->getData('iso3_code');
111
- $shipCountry = Mage::getModel('directory/country')->load($shipping->getCountryId())->getName();
112
- if (is_array($shipping->getStreet())):
113
- $shipAddress = $shipping->getStreet();
114
- if (isset($shipAddress[1])):
115
- $recipients->setAddress($shipAddress[0]);
116
- $recipients->setAddress2($shipAddress[1]);
117
- else:
118
- $recipients->setAddress($shipAddress[0]);
119
- endif;
120
- else:
121
- $recipients->setAddress($shipping->getStreet());
122
- endif;
123
-
124
- $recipients->setCompany($shipping->getCompany());
125
- $recipients->setFirstName($shipping->getFirstname());
126
- $recipients->setLastName($shipping->getLastname());
127
- $recipients->setCity($shipping->getCity());
128
- $recipients->setState($shipping->getRegion());
129
- $recipients->setPostalCode($shipping->getPostcode());
130
-
131
- $recipients->setCountry($shipCountry);
132
- $recipients->setPhoneNumber($shipping->getTelephone());
133
- $recipients->setEmail($shipping->getEmail());
134
- $recipients->setResidential(true);
135
- $recipients->setShippingMethod($order->getShippingDescription());
136
- $recipients->setBaseCost($this->fnumb( $order->getBaseShippingInclTax()));
137
- $recipients->setCostExcludingTax($this->fnumb(($order->getBaseShippingAmount() - $order->getBaseShippingTaxAmount())));
138
- $recipients->setCostTax($this->fnumb($order->getBaseShippingTaxAmount()));
139
- $recipients->setBaseHandlingCost(0.00);
140
- $recipients->setHandlingCostExcludingTax(0.00);
141
- $recipients->setHandlingCostIncludingTax(0.00);
142
- $recipients->setHandlingCostTax(0.00);
143
- $recipients->setShippingZoneId("123");
144
- $recipients->setShippingZoneName("XYZ");
145
-
146
-
147
-
148
- // line items
149
- $lineItems = array();
150
- $items = $order->getAllVisibleItems();
151
- foreach ($items as $i => $item):
152
-
153
- // if ($item->getData('product_type') == 'simple') :
154
- $_unit = Mage::getStoreConfig(self::WEIGHT_UNIT);
155
- if ($_unit == 'KGS')
156
- $weight = $item->getWeight() * "35.274";
157
- if ($_unit == 'LBS')
158
- $weight = $item->getWeight() * "16";
159
-
160
- $lineItem = new Varien_Object();
161
- $lineItem->setItemName($item->getName());
162
- $lineItem->setSku($item->getSku());
163
- $lineItem->setBinPickingNumber(Mage::getStoreConfig(self::BIN_PICKING_NUMBER));
164
- $lineItem->setUnitPrice($this->fnumb($item->getPrice()));
165
- $lineItem->setTotalExcludingTax($this->fnumb($item->getPrice()));
166
- $lineItem->setWeightInOunces($weight);
167
- $lineItem->setQuantity((int) $item->getQtyOrdered());
168
- /*
169
- if ($item->getData('product_type') == 'configurable') :
170
- $_option = $this->getItemOptions($item);
171
- $optStr = "";
172
- foreach($_option as $lb=>$vall) {
173
- $optStr .= "#".$vall['label']."=".$vall['value'].":";
174
- }
175
- $lineItem->setProductOptions($optStr);
176
- endif;
177
- */
178
-
179
- $lineItems[] = $lineItem->toArray();
180
-
181
-
182
- //array_push($lineItems, $lineItem->toArray());
183
- //endif;
184
- endforeach;
185
-
186
- $recipients->setItemsTotal(count($lineItems));
187
- $recipients->setItemsShipped(0);
188
- $recipients->setLineItems($lineItems);
189
- $recpArray = array();
190
- $recpArray[] = $recipients->toArray();
191
- $shipEasy->setRecipients($recpArray);
192
-
193
- $_succ = false;
194
- try {
195
- $this->setShippingEasyConfiguration();
196
- $_shippingEasy = new ShippingEasy_Order(Mage::getStoreConfig(self::STORE_APIKEY), $shipEasy->toArray());
197
- $result = $_shippingEasy->create();
198
- $_succ = true;
199
- Mage::log("Order #" . $order->getData('increment_id') . " exported to shipping Easy", null, 'shippingEasy.log');
200
- } catch (Exception $e) {
201
- $_succ = false;
202
- $_errorMsg = "Unable to connect with shippingEasy " . $e->getMessage();
203
- Mage::log("Unable to connect with shippingEasy " . $e->getMessage().".Order #".$order->getData('increment_id')." failed to export.", null, 'shippingEasy.log');
204
- Mage::log("Unable to connect with shippingEasy " . $e->getMessage().".Order #".$order->getData('increment_id')." failed to export.".print_r($shipEasy->toArray(), true), null, 'shippingEasyDetails.log');
205
-
206
- }
207
-
208
- if($_succ == true) {
209
- $order->setData('is_exported', '1');
210
- $comment = 'Order successfully exported to Shipping Easy';
211
- $order->addStatusHistoryComment($comment, false);
212
- $order->save();
213
- } else {
214
- $comment = $_errorMsg;
215
- $order->addStatusHistoryComment($comment, false);
216
- $order->save();
217
- }
218
- if($missing == true)
219
- return $_succ;
220
- }
221
-
222
- public function cancelOrder($observer) {
223
-
224
- try {
225
- $_orderId = $observer->getOrder()->getEntityId();
226
- Mage::getModel('fulfilment/fulfilment')->cancelOrder($_orderId);
227
- } catch (Exception $e) {
228
- Mage::log("Unable to connect with shippingEasy " . $e->getMessage(), null, 'shippingEasy.log');
229
- }
230
- }
231
-
232
- public function setShippingEasyConfiguration() {
233
- ShippingEasy::setApiKey(Mage::getStoreConfig(self::SHIPEASY_STORE_APIKEY)); //api key
234
- ShippingEasy::setApiSecret(Mage::getStoreConfig(self::SHIPEASY_SECRET_APIKEY));
235
- ShippingEasy::setApiBase(Mage::getStoreConfig(self::SHIPEASY_STORE_URL));
236
- }
237
-
238
- public function fnumb($number) {
239
- return number_format($number, 2, '.', '');
240
- }
241
-
242
- public function getItemOptions($item)
243
- {
244
- $result = array();
245
- if ($options = $item->getProductOptions()) {
246
- if (isset($options['options'])) {
247
- $result = array_merge($result, $options['options']);
248
- }
249
- if (isset($options['additional_options'])) {
250
- $result = array_merge($result, $options['additional_options']);
251
- }
252
- if (isset($options['attributes_info'])) {
253
- $result = array_merge($result, $options['attributes_info']);
254
- }
255
- }
256
- return $result;
257
- }
258
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Shippingeasy/Fulfilment/controllers/Adminhtml/FulfilmentController.php DELETED
@@ -1,45 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * @category Shippingeasy
5
- * @package Shippingeasy_Fulfilment
6
- *
7
- */
8
- class Shippingeasy_Fulfilment_Adminhtml_FulfilmentController extends Mage_Adminhtml_Controller_action {
9
-
10
- public function exportAction() {
11
- $_orderId = $this->getRequest()->getParam('order_id');
12
- if ($_orderId) {
13
- try {
14
- $resp = Mage::getModel('fulfilment/observer')->submitOrder($_orderId, true);
15
- if($resp == true)
16
- $this->_getSession()->addSuccess($this->__('The order has been sent to ShippingEasy.'));
17
- else
18
- $this->_getSession()->addError($this->__('Failed to send the order to ShippingEasy.'));
19
- } catch (Mage_Core_Exception $e) {
20
- $this->_getSession()->addError($e->getMessage());
21
- } catch (Exception $e) {
22
- $this->_getSession()->addError($this->__('Failed to send the order to ShippingEasy. %s', $e->getMessage()));
23
- Mage::logException($e);
24
- }
25
- }
26
- Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl("adminhtml/sales_order/view", array('order_id' => $_orderId)));
27
- }
28
-
29
- public function cancelAction() {
30
- $_orderId = $this->getRequest()->getParam('order_id');
31
- if ($_orderId) {
32
- try {
33
- Mage::getModel('fulfilment/fulfilment')->cancelOrder($_orderId);
34
- $this->_getSession()->addSuccess($this->__('The order has been successfully cancelled in ShippingEasy.'));
35
- } catch (Mage_Core_Exception $e) {
36
- $this->_getSession()->addError($e->getMessage());
37
- } catch (Exception $e) {
38
- $this->_getSession()->addError($this->__('Unable to cancel the order in ShippingEasy. %s', $e->getMessage()));
39
- Mage::logException($e);
40
- }
41
- }
42
- Mage::app()->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl("adminhtml/sales_order/view", array('order_id' => $_orderId)));
43
- }
44
-
45
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Shippingeasy/Fulfilment/controllers/CallbackController.php DELETED
@@ -1,47 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * @category Shippingeasy
5
- * @package Shippingeasy_Fulfilment
6
- *
7
- */
8
- require_once(Mage::getBaseDir('lib') . '/ShippingEasy.php');
9
-
10
- class Shippingeasy_Fulfilment_CallbackController extends Mage_Core_Controller_Front_Action {
11
-
12
- const SHIPEASY_ENABLED = 'shippingeasy/fulfilment/active';
13
- const SHIPEASY_STORE_APIKEY = 'shippingeasy/fulfilment/apikey';
14
- const SHIPEASY_SECRET_APIKEY = 'shippingeasy/fulfilment/secretkey';
15
- const SHIPEASY_STORE_URL = 'shippingeasy/fulfilment/url';
16
- const STORE_APIKEY = 'shippingeasy/fulfilment/store_apikey';
17
- const WEIGHT_UNIT = 'shippingeasy/fulfilment/weight_unit';
18
-
19
- public function indexAction() {
20
-
21
- $this->setShippingEasyConfiguration();
22
- $values = file_get_contents('php://input');
23
- $output = json_decode($values, true);
24
- $params = $_REQUEST;
25
- $authenticator = new ShippingEasy_Authenticator("get", "/magento/shippingeasy/callback", $params, $values, Mage::getStoreConfig(self::SHIPEASY_SECRET_APIKEY));
26
- Mage::log($values, null, "shippingEasy.log");
27
- Mage::log($output, null, "shippingEasy.log");
28
- Mage::log($authenticator, null, "shippingEasy.log");
29
-
30
- Mage::log("====" . $authenticator->getExpectedSignature() . "======" . $authenticator->getSuppliedSignatureString(), null, "shippingEasy.log");
31
- Mage::log("====" . $authenticator->isAuthenticated(), null, "shippingEasy.log");
32
- $orderIncrementId = $output['shipment']['orders']['0']['external_order_identifier'];
33
- $trackingNo = $output['shipment']['tracking_number'];
34
- $carrierKey = $output['shipment']['carrier_key'];
35
- $carrierServiceKey = $output['shipment']['carrier_service_key'];
36
-
37
- Mage::log($orderIncrementId . "===" . $trackingNo . "===" . $carrierKey . "===" . $carrierServiceKey, null, "shippingEasy.log");
38
- Mage::getModel('fulfilment/fulfilment')->createShipment($orderIncrementId, $trackingNo, $carrierKey, $carrierServiceKey);
39
- }
40
-
41
- public function setShippingEasyConfiguration() {
42
- ShippingEasy::setApiKey(Mage::getStoreConfig(self::SHIPEASY_STORE_APIKEY)); //api key
43
- ShippingEasy::setApiSecret(Mage::getStoreConfig(self::SHIPEASY_SECRET_APIKEY));
44
- ShippingEasy::setApiBase(Mage::getStoreConfig(self::SHIPEASY_STORE_URL));
45
- }
46
-
47
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Shippingeasy/Fulfilment/controllers/IndexController.php CHANGED
@@ -1,10 +1,38 @@
1
- <?php
2
-
3
- class Shippingeasy_Fulfilment_IndexController extends Mage_Core_Controller_Front_Action {
4
-
5
- public function indexAction() {
6
- $this->loadLayout();
7
- $this->renderLayout();
8
- }
9
-
10
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(Mage::getBaseDir('lib') . '/ShippingEasy/ShippingEasy.php');
4
+
5
+ class Shippingeasy_Fulfilment_IndexController extends Mage_Core_Controller_Front_Action {
6
+
7
+ const SHIPEASY_API_KEY = 'shippingeasy/fulfilment/apikey';
8
+ const SHIPEASY_API_SECRET = 'shippingeasy/fulfilment/secretkey';
9
+ const SHIPEASY_API_URL = 'shippingeasy/fulfilment/baseurl';
10
+
11
+ public function indexAction() {
12
+
13
+ $response = array();
14
+
15
+ ShippingEasy::setApiKey(Mage::getStoreConfig(self::SHIPEASY_API_KEY));
16
+ ShippingEasy::setApiSecret(Mage::getStoreConfig(self::SHIPEASY_API_SECRET));
17
+ ShippingEasy::setApiBase(Mage::getStoreConfig(self::SHIPEASY_API_URL));
18
+
19
+ //$json_payload = json_decode(file_get_contents('php://input'));
20
+ //$authenticator = new ShippingEasy_Authenticator('POST', '/shippingeasy_fetch', $_REQUEST);
21
+ $authenticator = new ShippingEasy_Authenticator('GET', '/shippingeasy_fetch', $_REQUEST);
22
+
23
+ if ($authenticator->isAuthenticated()) {
24
+ $response['response'] = 'VALID REQUEST';
25
+ //$response['apikey'] = Mage::getStoreConfig(self::SHIPEASY_API_KEY);
26
+ //$response['secretkey'] = Mage::getStoreConfig(self::SHIPEASY_API_SECRET);
27
+ //$response['url'] = Mage::getStoreConfig(self::SHIPEASY_API_URL);
28
+ } else {
29
+ $response['response'] = 'INVALID REQUEST';
30
+ }
31
+
32
+ echo json_encode($response);
33
+
34
+ }
35
+
36
+ }
37
+
38
+ ?>
app/code/community/Shippingeasy/Fulfilment/etc/config.xml CHANGED
@@ -1,127 +1,54 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Shippingeasy_Fulfilment>
5
- <version>0.1.0</version>
6
- </Shippingeasy_Fulfilment>
7
- </modules>
8
- <frontend>
9
- <secure_url>
10
- <customer>/shippingeasy/</customer>
11
- </secure_url>
12
- <routers>
13
- <fulfilment>
14
- <use>standard</use>
15
- <args>
16
- <module>Shippingeasy_Fulfilment</module>
17
- <frontName>shippingeasy</frontName>
18
- </args>
19
- </fulfilment>
20
- </routers>
21
- <events>
22
- <checkout_onepage_controller_success_action>
23
- <observers>
24
- <shippingeasy_order_success>
25
- <type>singleton</type>
26
- <class>fulfilment/observer</class>
27
- <method>submitOrder</method>
28
- </shippingeasy_order_success>
29
- </observers>
30
- </checkout_onepage_controller_success_action>
31
-
32
- <checkout_multishipping_controller_success_action>
33
- <observers>
34
- <shippingeasy_order_success>
35
- <type>singleton</type>
36
- <class>fulfilment/observer</class>
37
- <method>multiShippingOrders</method>
38
- </shippingeasy_order_success>
39
- </observers>
40
- </checkout_multishipping_controller_success_action>
41
- </events>
42
- </frontend>
43
- <admin>
44
- <routers>
45
- <fulfilment>
46
- <use>admin</use>
47
- <args>
48
- <module>Shippingeasy_Fulfilment</module>
49
- <frontName>shippingeasy</frontName>
50
- </args>
51
- </fulfilment>
52
- </routers>
53
- </admin>
54
- <adminhtml>
55
- <acl>
56
- <resources>
57
- <admin>
58
- <children>
59
- <system>
60
- <children>
61
- <config>
62
- <children>
63
- <shippingeasy>
64
- <title>Shipping Easy Integration Configuration</title>
65
- </shippingeasy>
66
- </children>
67
- </config>
68
- </children>
69
- </system>
70
- </children>
71
- </admin>
72
- </resources>
73
- </acl>
74
-
75
-
76
- <events>
77
- <checkout_submit_all_after>
78
- <observers>
79
- <adminhtml_order_success>
80
- <type>singleton</type>
81
- <class>fulfilment/observer</class>
82
- <method>submitOrder</method>
83
- </adminhtml_order_success>
84
- </observers>
85
- </checkout_submit_all_after>
86
- <order_cancel_after>
87
- <observers>
88
- <shippingeasy_order_cancel_after>
89
- <type>singleton</type>
90
- <class>fulfilment/observer</class>
91
- <method>cancelOrder</method>
92
- </shippingeasy_order_cancel_after>
93
- </observers>
94
- </order_cancel_after>
95
- </events>
96
- </adminhtml>
97
-
98
- <global>
99
- <blocks>
100
- <adminhtml>
101
- <rewrite>
102
- <sales_order_view>Shippingeasy_Fulfilment_Block_Adminhtml_Sales_Order_View</sales_order_view>
103
- </rewrite>
104
- </adminhtml>
105
- </blocks>
106
- <models>
107
- <fulfilment>
108
- <class>Shippingeasy_Fulfilment_Model</class>
109
- <resourceModel>fulfilment_mysql4</resourceModel>
110
- </fulfilment>
111
- </models>
112
- <resources>
113
- <fulfilment_setup>
114
- <setup>
115
- <module>Shippingeasy_Fulfilment</module>
116
- <class>Shippingeasy_Fulfilment_Model_Mysql4_Setup</class>
117
- </setup>
118
- </fulfilment_setup>
119
- </resources>
120
-
121
- <helpers>
122
- <fulfilment>
123
- <class>Shippingeasy_Fulfilment_Helper</class>
124
- </fulfilment>
125
- </helpers>
126
- </global>
127
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shippingeasy_Fulfilment>
5
+ <version>0.1.0</version>
6
+ </Shippingeasy_Fulfilment>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <fetchkeys>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Shippingeasy_Fulfilment</module>
14
+ <frontName>shippingeasy_fetch</frontName>
15
+ </args>
16
+ </fetchkeys>
17
+ </routers>
18
+ </frontend>
19
+ <adminhtml>
20
+ <acl>
21
+ <resources>
22
+ <admin>
23
+ <children>
24
+ <system>
25
+ <children>
26
+ <config>
27
+ <children>
28
+ <shippingeasy>
29
+ <title>Shipping Easy Integration Configuration</title>
30
+ </shippingeasy>
31
+ </children>
32
+ </config>
33
+ </children>
34
+ </system>
35
+ </children>
36
+ </admin>
37
+ </resources>
38
+ </acl>
39
+ </adminhtml>
40
+ <global>
41
+ <helpers>
42
+ <fulfilment>
43
+ <class>Shippingeasy_Fulfilment_Helper</class>
44
+ </fulfilment>
45
+ </helpers>
46
+ </global>
47
+ <default>
48
+ <shippingeasy>
49
+ <fulfilment>
50
+ <baseurl>https://app.shippingeasy.com</baseurl>
51
+ </fulfilment>
52
+ </shippingeasy>
53
+ </default>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  </config>
app/code/community/Shippingeasy/Fulfilment/etc/system.xml CHANGED
@@ -1,110 +1,66 @@
1
- <?xml version="1.0"?>
2
- <!--
3
- /**
4
- * @category Shippingeasy
5
- * @package Shippingeasy_Fulfilment
6
- */
7
- -->
8
-
9
-
10
- <config>
11
- <sections>
12
- <shippingeasy>
13
- <label>ShippingEasy Configuration</label>
14
- <tab>sales</tab>
15
- <frontend_type>text</frontend_type>
16
- <sort_order>306</sort_order>
17
- <show_in_default>1</show_in_default>
18
- <show_in_website>1</show_in_website>
19
- <show_in_store>1</show_in_store>
20
- <groups>
21
- <fulfilment translate="label" module="fulfilment">
22
- <label>ShippingEasy Configuration</label>
23
- <frontend_type>text</frontend_type>
24
- <sort_order>1</sort_order>
25
- <show_in_default>1</show_in_default>
26
- <show_in_website>1</show_in_website>
27
- <show_in_store>0</show_in_store>
28
- <fields>
29
- <active translate="label">
30
- <label>Enabled</label>
31
- <frontend_type>select</frontend_type>
32
- <source_model>adminhtml/system_config_source_yesno</source_model>
33
- <sort_order>0</sort_order>
34
- <show_in_default>1</show_in_default>
35
- <show_in_website>1</show_in_website>
36
- <show_in_store>0</show_in_store>
37
- </active>
38
-
39
- <apikey translate="label">
40
- <label>ShippingEasy API Key</label>
41
- <frontend_type>text</frontend_type>
42
- <sort_order>1</sort_order>
43
- <show_in_default>1</show_in_default>
44
- <show_in_website>1</show_in_website>
45
- <show_in_store>0</show_in_store>
46
- </apikey>
47
-
48
- <secretkey translate="label">
49
- <label>ShippingEasy Secret Key</label>
50
- <frontend_type>text</frontend_type>
51
- <sort_order>2</sort_order>
52
- <show_in_default>1</show_in_default>
53
- <show_in_website>1</show_in_website>
54
- <show_in_store>0</show_in_store>
55
- </secretkey>
56
-
57
- <url translate="label">
58
- <label>ShippingEasy URL</label>
59
- <frontend_type>text</frontend_type>
60
- <sort_order>2</sort_order>
61
- <show_in_default>1</show_in_default>
62
- <show_in_website>1</show_in_website>
63
- <show_in_store>0</show_in_store>
64
- </url>
65
-
66
- <store_apikey translate="label">
67
- <label>Store API Key</label>
68
- <frontend_type>text</frontend_type>
69
- <sort_order>3</sort_order>
70
- <show_in_default>1</show_in_default>
71
- <show_in_website>1</show_in_website>
72
- <show_in_store>0</show_in_store>
73
- </store_apikey>
74
-
75
- <weight_unit translate="label">
76
- <label>Product Weight Unit</label>
77
- <!-- <frontend_type>text</frontend_type>-->
78
- <frontend_type>select</frontend_type>
79
- <source_model>usa/shipping_carrier_ups_source_unitofmeasure</source_model>
80
- <sort_order>3</sort_order>
81
- <show_in_default>1</show_in_default>
82
- <show_in_website>1</show_in_website>
83
- <show_in_store>0</show_in_store>
84
- <!-- <comment>Either KG/LB/Ounce</comment>-->
85
- </weight_unit>
86
-
87
- <bin_picking_number translate="label">
88
- <label>Bin Picking Number</label>
89
- <frontend_type>text</frontend_type>
90
- <sort_order>3</sort_order>
91
- <show_in_default>1</show_in_default>
92
- <show_in_website>1</show_in_website>
93
- <show_in_store>0</show_in_store>
94
- </bin_picking_number>
95
- <errorlogs translate="label comment">
96
- <label>ShippingEasy Log Information</label>
97
- <frontend_type>textarea</frontend_type>
98
- <frontend_model>Shippingeasy_Fulfilment_Block_Adminhtml_System_Config_Error_Log</frontend_model>
99
- <sort_order>300</sort_order>
100
- <show_in_default>1</show_in_default>
101
- <show_in_website>0</show_in_website>
102
- <show_in_store>0</show_in_store>
103
- <comment>Displays error.</comment>
104
- </errorlogs>
105
- </fields>
106
- </fulfilment>
107
- </groups>
108
- </shippingeasy>
109
- </sections>
110
  </config>
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Shippingeasy
5
+ * @package Shippingeasy_Fulfilment
6
+ */
7
+ -->
8
+
9
+ <config>
10
+ <sections>
11
+ <shippingeasy>
12
+ <label>ShippingEasy Configuration</label>
13
+ <tab>sales</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>306</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <fulfilment translate="label" module="fulfilment">
21
+ <label>ShippingEasy Configuration</label>
22
+ <frontend_type>text</frontend_type>
23
+ <sort_order>1</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>1</show_in_website>
26
+ <show_in_store>0</show_in_store>
27
+ <fields>
28
+ <apikey translate="label">
29
+ <label>ShippingEasy API Key</label>
30
+ <frontend_type>text</frontend_type>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>0</show_in_store>
35
+ </apikey>
36
+ <secretkey translate="label">
37
+ <label>ShippingEasy Secret Key</label>
38
+ <frontend_type>text</frontend_type>
39
+ <sort_order>2</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>1</show_in_website>
42
+ <show_in_store>0</show_in_store>
43
+ </secretkey>
44
+ <baseurl translate="label">
45
+ <label>ShippingEasy Base URL</label>
46
+ <frontend_type>text</frontend_type>
47
+ <sort_order>3</sort_order>
48
+ <show_in_default>1</show_in_default>
49
+ <show_in_website>1</show_in_website>
50
+ <show_in_store>0</show_in_store>
51
+ </baseurl>
52
+ <getvalues_button translate="label">
53
+ <label>Get ShippingEasy API Keys</label>
54
+ <frontend_type>button</frontend_type>
55
+ <frontend_model>Shippingeasy_Fulfilment_Block_Adminhtml_System_Config_Links_Api</frontend_model>
56
+ <sort_order>4</sort_order>
57
+ <show_in_default>1</show_in_default>
58
+ <show_in_website>1</show_in_website>
59
+ <show_in_store>0</show_in_store>
60
+ </getvalues_button>
61
+ </fields>
62
+ </fulfilment>
63
+ </groups>
64
+ </shippingeasy>
65
+ </sections>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  </config>
app/code/community/Shippingeasy/Fulfilment/sql/fulfilment_setup/mysql4-install-0.1.0.php DELETED
@@ -1,25 +0,0 @@
1
- <?php
2
-
3
- /**
4
- *
5
- * adding an order level attribute for Shipping Easy module in order Module
6
- *
7
- *
8
- */
9
- $installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('sales_setup');
10
- $installer->startSetup();
11
- $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'is_exported', "TINYINT(1) UNSIGNED DEFAULT '0'");
12
-
13
- $installer->addAttribute('order', 'is_exported', array(
14
- 'type' => 'int',
15
- 'label' => 'Exported to Shipping Easy',
16
- 'input' => 'select',
17
- 'source' => 'eav/entity_attribute_source_boolean',
18
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
19
- 'required' => false,
20
- 'default' => '0'
21
- ));
22
-
23
-
24
- $installer->endSetup();
25
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/design/adminhtml/default/default/template/shippingeasy/system/config/button.phtml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <script type="text/javascript">
2
+ //<![CDATA[
3
+ function getValues() {
4
+ var redirector = window.open("https://app.shippingeasy.com/settings/api_credentials", '_blank');
5
+ redirector.location;
6
+ }
7
+ //]]>
8
+ </script>
9
+
10
+ <?php echo $this->getButtonHtml() ?>
app/etc/modules/Shippingeasy_Fulfilment.xml CHANGED
@@ -1,9 +1,9 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Shippingeasy_Fulfilment>
5
- <active>true</active>
6
- <codePool>community</codePool>
7
- </Shippingeasy_Fulfilment>
8
- </modules>
9
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shippingeasy_Fulfilment>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Shippingeasy_Fulfilment>
8
+ </modules>
9
  </config>
lib/ShippingEasy/ShippingEasy.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Tested on PHP 5.2, 5.3
4
+
5
+ // This snippet (and some of the curl code) due to the Facebook SDK.
6
+ if (!function_exists('curl_init')) {
7
+ throw new Exception('ShippingEasy needs the CURL PHP extension.');
8
+ }
9
+ if (!function_exists('json_decode')) {
10
+ throw new Exception('ShippingEasy needs the JSON PHP extension.');
11
+ }
12
+ if (!function_exists('mb_detect_encoding')) {
13
+ throw new Exception('ShippingEasy needs the Multibyte String PHP extension.');
14
+ }
15
+
16
+ require(dirname(__FILE__) . '/ShippingEasy/ShippingEasy.php');
17
+
18
+ // Errors
19
+ require(dirname(__FILE__) . '/ShippingEasy/Error.php');
20
+ require(dirname(__FILE__) . '/ShippingEasy/ApiError.php');
21
+ require(dirname(__FILE__) . '/ShippingEasy/ApiConnectionError.php');
22
+ require(dirname(__FILE__) . '/ShippingEasy/AuthenticationError.php');
23
+ require(dirname(__FILE__) . '/ShippingEasy/InvalidRequestError.php');
24
+
25
+ require(dirname(__FILE__) . '/ShippingEasy/ApiRequestor.php');
26
+ require(dirname(__FILE__) . '/ShippingEasy/Authenticator.php');
27
+ require(dirname(__FILE__) . '/ShippingEasy/Object.php');
28
+ require(dirname(__FILE__) . '/ShippingEasy/Order.php');
29
+ require(dirname(__FILE__) . '/ShippingEasy/PartnerSession.php');
30
+ require(dirname(__FILE__) . '/ShippingEasy/PartnerAccount.php');
31
+ require(dirname(__FILE__) . '/ShippingEasy/Signature.php');
32
+ require(dirname(__FILE__) . '/ShippingEasy/SignedUrl.php');
33
+ require(dirname(__FILE__) . '/ShippingEasy/Cancellation.php');
lib/ShippingEasy/ShippingEasy/ApiConnectionError.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_ApiConnectionError extends ShippingEasy_Error
4
+ {
5
+ }
lib/ShippingEasy/ShippingEasy/ApiError.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_ApiError extends ShippingEasy_Error
4
+ {
5
+ }
lib/ShippingEasy/ShippingEasy/ApiRequestor.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_ApiRequestor
4
+ {
5
+ public $apiKey;
6
+ public $apiSecret;
7
+
8
+ public static function utf8($value)
9
+ {
10
+ if (is_string($value) && mb_detect_encoding($value, "UTF-8", TRUE) != "UTF-8")
11
+ return utf8_encode($value);
12
+ else
13
+ return $value;
14
+ }
15
+
16
+ public static function encode($arr, $prefix=null)
17
+ {
18
+ if (!is_array($arr))
19
+ return $arr;
20
+
21
+ $r = array();
22
+ foreach ($arr as $k => $v) {
23
+ if (is_null($v))
24
+ continue;
25
+
26
+ if ($prefix && $k && !is_int($k))
27
+ $k = $prefix."[".$k."]";
28
+ else if ($prefix)
29
+ $k = $prefix."[]";
30
+
31
+ if (is_array($v)) {
32
+ $r[] = self::encode($v, $k, true);
33
+ } else {
34
+ $r[] = urlencode($k)."=".urlencode($v);
35
+ }
36
+ }
37
+
38
+ return implode("&", $r);
39
+ }
40
+
41
+ public function request($meth, $path, $params=null, $payload = null, $apiKey = null, $apiSecret = null)
42
+ {
43
+ list($rbody, $rcode) = $this->_requestRaw($meth, $path, $params, $payload, $apiKey, $apiSecret);
44
+ $resp = $this->_interpretResponse($rbody, $rcode);
45
+ return $resp;
46
+ }
47
+
48
+ public function handleApiError($rbody, $rcode, $resp)
49
+ {
50
+
51
+ if (!is_array($resp) || !isset($resp['errors']))
52
+ throw new ShippingEasy_ApiError("Invalid response object from API: $rbody (HTTP response code was $rcode)", $rcode, $rbody, $resp);
53
+
54
+ $error = $resp['errors'];
55
+ $message = isset($error[0]['message']) ? $error[0]['message'] : null;
56
+
57
+ switch ($rcode) {
58
+ case 400:
59
+ throw new ShippingEasy_InvalidRequestError(json_encode($error), $rcode, $rbody, $resp);
60
+ case 404:
61
+ throw new ShippingEasy_InvalidRequestError($message, $rcode, $rbody, $resp);
62
+ case 401:
63
+ throw new ShippingEasy_AuthenticationError($message, $rcode, $rbody, $resp);
64
+ default:
65
+ throw new ShippingEasy_ApiError($message, $rcode, $rbody, $resp);
66
+ }
67
+ }
68
+
69
+ private function _requestRaw($http_method, $path, $params, $payload, $apiKey, $apiSecret)
70
+ {
71
+ $url = new ShippingEasy_SignedUrl($http_method, $path, $params, $payload, null, $apiKey, $apiSecret);
72
+ $absUrl = $url->toString();
73
+
74
+ $langVersion = phpversion();
75
+ $uname = php_uname();
76
+
77
+ $ua = array('bindings_version' => ShippingEasy::VERSION,
78
+ 'lang' => 'php',
79
+ 'lang_version' => $langVersion,
80
+ 'publisher' => 'ShippingEasy',
81
+ 'uname' => $uname);
82
+
83
+ $headers = array('X-ShippingEasy-Client-User-Agent: ' . json_encode($ua),
84
+ 'User-Agent: ShippingEasy/v1 PhpBindings/' . ShippingEasy::VERSION,
85
+ 'Authorization: Bearer ' . $apiKey);
86
+
87
+ if (ShippingEasy::$apiVersion)
88
+ $headers[] = 'ShippingEasy-Version: ' . ShippingEasy::$apiVersion;
89
+
90
+ list($rbody, $rcode) = $this->_curlRequest($http_method, $absUrl, $headers, $payload);
91
+ return array($rbody, $rcode);
92
+ }
93
+
94
+ private function _interpretResponse($rbody, $rcode)
95
+ {
96
+ try {
97
+ $resp = json_decode($rbody, true);
98
+ } catch (Exception $e) {
99
+ throw new ShippingEasy_ApiError("Invalid response body from API: $rbody (HTTP response code was $rcode)", $rcode, $rbody);
100
+ }
101
+ if ($rcode < 200 || $rcode >= 300) {
102
+ $this->handleApiError($rbody, $rcode, $resp);
103
+ }
104
+ return $resp;
105
+ }
106
+
107
+ private function _curlRequest($meth, $absUrl, $headers, $payload)
108
+ {
109
+ $curl = curl_init();
110
+ $meth = strtolower($meth);
111
+ $opts = array();
112
+
113
+ if ($meth == 'get') {
114
+ $opts[CURLOPT_HTTPGET] = 1;
115
+ } else if ($meth == 'post') {
116
+ $opts[CURLOPT_POST] = 1;
117
+ if ($payload)
118
+ $payload = json_encode($payload);
119
+
120
+ $headers[] = 'Content-Type: application/json';
121
+ $headers[] = 'Content-Length: ' . strlen($payload);
122
+ $opts[CURLOPT_POSTFIELDS] = $payload;
123
+ } else if ($meth == 'delete') {
124
+ $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';
125
+ if (count($params) > 0) {
126
+ $encoded = self::encode($params);
127
+ $absUrl = "$absUrl?$encoded";
128
+ }
129
+ } else {
130
+ throw new ShippingEasy_ApiError("Unrecognized method $meth");
131
+ }
132
+
133
+ $opts[CURLOPT_URL] = $absUrl;
134
+ $opts[CURLOPT_RETURNTRANSFER] = true;
135
+ $opts[CURLOPT_CONNECTTIMEOUT] = 30;
136
+ $opts[CURLOPT_TIMEOUT] = 80;
137
+ $opts[CURLOPT_HTTPHEADER] = $headers;
138
+
139
+ curl_setopt_array($curl, $opts);
140
+ $rbody = curl_exec($curl);
141
+ $errno = curl_errno($curl);
142
+
143
+ if ($rbody === false) {
144
+ $errno = curl_errno($curl);
145
+ $message = curl_error($curl);
146
+ curl_close($curl);
147
+ $this->handleCurlError($errno, $message);
148
+ }
149
+
150
+ $rcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
151
+ curl_close($curl);
152
+ return array($rbody, $rcode);
153
+ }
154
+
155
+ public function handleCurlError($errno, $message)
156
+ {
157
+ $apiBase = ShippingEasy::$apiBase;
158
+ switch ($errno) {
159
+ case CURLE_COULDNT_CONNECT:
160
+ case CURLE_COULDNT_RESOLVE_HOST:
161
+ case CURLE_OPERATION_TIMEOUTED:
162
+ $msg = "Could not connect to ShippingEasy ($apiBase). Please check your internet connection and try again. If this problem persists, let us know at support@shippingeasy.com.";
163
+ break;
164
+ case CURLE_SSL_CACERT:
165
+ case CURLE_SSL_PEER_CERTIFICATE:
166
+ $msg = "Could not verify ShippingEasy's SSL certificate. Please make sure that your network is not intercepting certificates. (Try going to $apiBase in your browser.) If this problem persists, let us know at support@shippingeasy.com.";
167
+ break;
168
+ default:
169
+ $msg = "Unexpected error communicating with ShippingEasy. If this problem persists, let us know at support@shippingeasy.com.";
170
+ }
171
+
172
+ $msg .= "\n\n(Network error [errno $errno]: $message)";
173
+ throw new ShippingEasy_ApiConnectionError($msg);
174
+ }
175
+ }
lib/ShippingEasy/ShippingEasy/AuthenticationError.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_AuthenticationError extends ShippingEasy_Error
4
+ {
5
+ }
lib/ShippingEasy/ShippingEasy/Authenticator.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_Authenticator
4
+ {
5
+
6
+ # Instantiates a new authenticator object.
7
+ #
8
+ # http_method - The method of the http request. E.g. "post" or "get".
9
+ # path - The path of the request's uri. E.g. "/orders/callback"
10
+ # params - An associative array of the request's query string parameters. E.g. array("api_signature" => "asdsadsad", "api_timestamp" => "1234567899")
11
+ # json_body - The request body as a JSON string.
12
+ # api_secret - The ShippingEasy API secret for the store. Defaults to the global configuration if set.
13
+ #
14
+ public function __construct($http_method=null, $path=null, $params=null, $json_body=null, $api_secret=null)
15
+ {
16
+ $api_secret = isset($api_secret) ? $api_secret : ShippingEasy::$apiSecret;
17
+ $this->supplied_signature_string = $params["api_signature"];
18
+ unset($params["api_signature"]);
19
+ $this->expected_signature = new ShippingEasy_Signature($api_secret, $http_method, $path, $params, $json_body);
20
+ }
21
+
22
+ public function getExpectedSignature()
23
+ {
24
+ return $this->expected_signature;
25
+ }
26
+
27
+ public function getSuppliedSignatureString()
28
+ {
29
+ return $this->supplied_signature_string;
30
+ }
31
+
32
+ public function isAuthenticated()
33
+ {
34
+ return $this->getExpectedSignature()->equals($this->getSuppliedSignatureString());
35
+ }
36
+
37
+ }
lib/ShippingEasy/ShippingEasy/Cancellation.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_Cancellation extends ShippingEasy_Object
4
+ {
5
+
6
+ public function __construct($store_api_key, $external_order_identifier) {
7
+ $this->store_api_key = $store_api_key;
8
+ $this->external_order_identifier = $external_order_identifier;
9
+ }
10
+
11
+ public function create()
12
+ {
13
+ return $this->request("post", "/api/stores/$this->store_api_key/orders/$this->external_order_identifier/cancellations");
14
+ }
15
+
16
+ }
lib/ShippingEasy/ShippingEasy/Error.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_Error extends Exception
4
+ {
5
+ public function __construct($message=null, $http_status=null, $http_body=null, $json_body=null)
6
+ {
7
+ parent::__construct($message);
8
+ $this->http_status = $http_status;
9
+ $this->http_body = $http_body;
10
+ $this->json_body = $json_body;
11
+ }
12
+
13
+ public function getHttpStatus()
14
+ {
15
+ return $this->http_status;
16
+ }
17
+
18
+ public function getHttpBody()
19
+ {
20
+ return $this->http_body;
21
+ }
22
+
23
+ public function getJsonBody()
24
+ {
25
+ return $this->json_body;
26
+ }
27
+ }
lib/ShippingEasy/ShippingEasy/InvalidRequestError.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_InvalidRequestError extends ShippingEasy_Error
4
+ {
5
+ public function __construct($message, $http_status=null, $http_body=null, $json_body=null)
6
+ {
7
+ parent::__construct($message, $http_status, $http_body, $json_body);
8
+ }
9
+ }
lib/ShippingEasy/ShippingEasy/Object.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_Object
4
+ {
5
+ public function request($meth, $path, $params=null, $payload = null, $apiKey = null, $apiSecret = null)
6
+ {
7
+ $requestor = new ShippingEasy_ApiRequestor();
8
+ return $requestor->request($meth, $path, $params, $payload, $apiKey, $apiSecret);
9
+ }
10
+
11
+ }
12
+
lib/ShippingEasy/ShippingEasy/Order.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_Order extends ShippingEasy_Object
4
+ {
5
+ public function __construct($store_api_key=null, $values=null) {
6
+ $this->store_api_key = $store_api_key;
7
+ $this->values = $values;
8
+ }
9
+
10
+ public function create()
11
+ {
12
+ return $this->request("post", "/api/stores/$this->store_api_key/orders", null, array("order" => $this->values));
13
+ }
14
+
15
+ public function find($id)
16
+ {
17
+ return $this->request("get", "/api/orders/$id");
18
+ }
19
+
20
+ public function findAllByStore($params=array())
21
+ {
22
+ return $this->request("get", "/api/stores/$this->store_api_key/orders", $params);
23
+ }
24
+
25
+ public function findAll($params=array())
26
+ {
27
+ print_r($params);
28
+ return $this->request("get", "/api/orders", $params);
29
+ }
30
+ }
lib/ShippingEasy/ShippingEasy/PartnerAccount.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_PartnerAccount extends ShippingEasy_Object
4
+ {
5
+ public function create($data = array())
6
+ {
7
+ return $this->request("post", "/partners/api/accounts", null, array("account" => $data), ShippingEasy::$partnerApiKey, ShippingEasy::$partnerApiSecret);
8
+ }
9
+ }
lib/ShippingEasy/ShippingEasy/PartnerSession.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_PartnerSession extends ShippingEasy_Object
4
+ {
5
+ public function create($data = array())
6
+ {
7
+ return $this->request("post", "/partners/api/sessions", null, array("session" => $data), ShippingEasy::$partnerApiKey, ShippingEasy::$partnerApiSecret);
8
+ }
9
+ }
lib/ShippingEasy/ShippingEasy/ShippingEasy.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class ShippingEasy
4
+ {
5
+ public static $apiKey;
6
+ public static $apiSecret;
7
+ public static $partnerApiKey;
8
+ public static $partnerApiSecret;
9
+ public static $apiBase = 'https://app.shippingeasy.com';
10
+ public static $apiVersion = null;
11
+ const VERSION = '0.4.0';
12
+
13
+ public static function getApiKey()
14
+ {
15
+ return self::$apiKey;
16
+ }
17
+
18
+ public static function setApiKey($apiKey)
19
+ {
20
+ self::$apiKey = $apiKey;
21
+ }
22
+
23
+ public static function getPartnerApiKey()
24
+ {
25
+ return self::$partnerApiKey;
26
+ }
27
+
28
+ public static function setPartnerApiKey($partnerApiKey)
29
+ {
30
+ self::$partnerApiKey = $partnerApiKey;
31
+ }
32
+
33
+ public static function setApiSecret($apiSecret)
34
+ {
35
+ self::$apiSecret = $apiSecret;
36
+ }
37
+
38
+ public static function setPartnerApiSecret($partnerApiSecret)
39
+ {
40
+ self::$partnerApiSecret = $partnerApiSecret;
41
+ }
42
+
43
+ public static function getApiVersion()
44
+ {
45
+ return self::$apiVersion;
46
+ }
47
+
48
+ public static function setApiVersion($apiVersion)
49
+ {
50
+ self::$apiVersion = $apiVersion;
51
+ }
52
+
53
+ public static function setApiBase($apiBase)
54
+ {
55
+ self::$apiBase = $apiBase;
56
+ }
57
+ }
lib/ShippingEasy/ShippingEasy/Signature.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_Signature
4
+ {
5
+ public function __construct($api_secret=null, $http_method=null, $path=null, $params=null, $json_body=null)
6
+ {
7
+ $this->api_secret = $api_secret;
8
+ $this->http_method = strtoupper($http_method);
9
+ $this->path = $path;
10
+ ksort($params);
11
+ $this->params = $params;
12
+
13
+ if (is_string($json_body)) {
14
+ $this->json_body = str_replace("\/","/", $json_body);
15
+ } else {
16
+ $this->json_body = json_encode($json_body);
17
+ }
18
+ }
19
+
20
+ public function getApiSecret()
21
+ {
22
+ return $this->api_secret;
23
+ }
24
+
25
+ public function getHttpMethod()
26
+ {
27
+ return $this->http_method;
28
+ }
29
+
30
+ public function getPath()
31
+ {
32
+ return $this->path;
33
+ }
34
+
35
+ public function getParams()
36
+ {
37
+ return $this->params;
38
+ }
39
+
40
+ public function getJsonBody()
41
+ {
42
+ return $this->json_body;
43
+ }
44
+
45
+ public function plaintext()
46
+ {
47
+ $parts = array($this->getHttpMethod());
48
+ $parts[] = $this->getPath();
49
+ $parts[] = http_build_query($this->getParams());
50
+
51
+ if ($this->getJsonBody() != "null")
52
+ $parts[] = $this->getJsonBody();
53
+
54
+ return implode("&", $parts);
55
+ }
56
+
57
+ public function encrypted()
58
+ {
59
+ return hash_hmac('sha256', $this->plaintext(), $this->getApiSecret());
60
+ }
61
+
62
+ public function equals($signature)
63
+ {
64
+ return $this->encrypted() == $signature;
65
+ }
66
+
67
+ }
lib/ShippingEasy/ShippingEasy/SignedUrl.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class ShippingEasy_SignedUrl
4
+ {
5
+ public function __construct($http_method=null, $path=null, $params=null, $json_body=null, $api_timestamp=null, $api_key = null, $api_secret = null)
6
+ {
7
+ $api_secret = isset($api_secret) ? $api_secret : ShippingEasy::$apiSecret;
8
+ $params["api_key"] = isset($api_key) ? $api_key : ShippingEasy::$apiKey;
9
+ $params["api_timestamp"] = isset($api_timestamp) ? $api_timestamp : time();
10
+ $signature_object = new ShippingEasy_Signature($api_secret, $http_method, $path, $params, $json_body);
11
+ $params["api_signature"] = $signature_object->encrypted();
12
+
13
+ $this->params = $params;
14
+ $this->path = $path;
15
+ }
16
+
17
+ public function getParams()
18
+ {
19
+ return $this->params;
20
+ }
21
+
22
+ public function getPath()
23
+ {
24
+ return $this->path;
25
+ }
26
+
27
+ public function toString()
28
+ {
29
+ $url = ShippingEasy::$apiBase;
30
+ $url .= $this->getPath();
31
+ $url .= "?" . http_build_query($this->getParams());
32
+ return $url;
33
+ }
34
+
35
+ }
package.xml CHANGED
@@ -1,21 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>shipping_easy</name>
4
- <version>0.1.0</version>
5
  <stability>stable</stability>
6
  <license>OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Multi-carrier and platform shipping. Best USPS rates, easy batching, endless support. Save time &amp; money today.&#xD;
10
- </summary>
11
- <description>Easily integrate your Magento store with ShippingEasy to allow your order, tracking and fulfillment data to populate in real-time across all systems. Plug in your UPS and FedEx accounts or other marketplaces like eBay or Amazon to download all new orders and easily assign shipping preferences, rates and delivery options in real-time.&#xD;
12
- </description>
13
- <notes>Easily integrate your Magento store with ShippingEasy to allow your order, tracking and fulfillment data to populate in real-time across all systems. Plug in your UPS and FedEx accounts or other marketplaces like eBay or Amazon to download all new orders and easily assign shipping preferences, rates and delivery options in real-time.&#xD;
14
- </notes>
15
- <authors><author><name>Jack</name><user>shippingdev</user><email>product@shippingeasy.com</email></author></authors>
16
- <date>2014-06-25</date>
17
- <time>08:52:58</time>
18
- <contents><target name="magecommunity"><dir name="Shippingeasy"><dir name="Fulfilment"><dir name="Block"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="View.php" hash="4b07d6ef2eb76152552a8779396fd497"/></dir></dir><dir name="System"><dir name="Config"><dir name="Error"><file name="Log.php" hash="670c7844e74c77edbf8e107302bec459"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="35389df0229decf33cc6edbc40fe9a8e"/></dir><dir name="Model"><file name="Fulfilment.php" hash="0dab199d609570acc1a739d78fb1c16f"/><dir name="Mysql4"><file name="Setup.php" hash="65f5bfe931f05bb7e6a909945139f8a6"/></dir><file name="Observer.php" hash="2b53bf77d3621dff01365997653caf69"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="FulfilmentController.php" hash="20a95b5004ec6f4a4ebc69701e1a447e"/></dir><file name="CallbackController.php" hash="1bf5faf00175da8caeab358ee589ff57"/><file name="IndexController.php" hash="9eb94acf7209f47c88b3422fb91a419d"/></dir><dir name="etc"><file name="config.xml" hash="863312552edc2cb323a2cb5d98c5301a"/><file name="system.xml" hash="b21e5500f85c2bc96bead2ef1d63d39a"/></dir><dir name="sql"><dir name="fulfilment_setup"><file name="mysql4-install-0.1.0.php" hash="421334e32d1cf529edfbfd4120d36239"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Shippingeasy_Fulfilment.xml" hash="02b8c2b545259a8f5a0ae457f5690ed7"/></dir></target><target name="magelocal"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><file name="shippingeasy.phtml" hash=""/></dir></dir></dir></dir></target></contents>
19
  <compatible/>
20
- <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>shipping_easy</name>
4
+ <version>2.0.0</version>
5
  <stability>stable</stability>
6
  <license>OSL</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Multi-carrier and platform shipping. Best USPS rates, easy batching, endless support. Save time &amp; money today.</summary>
10
+ <description>Easily integrate your Magento store with ShippingEasy to allow your order, tracking and fulfillment data to populate in real-time across all systems. Plug in your UPS and FedEx accounts or other marketplaces like eBay or Amazon to download all new orders and easily assign shipping preferences, rates and delivery options in real-time.</description>
11
+ <notes>Easily integrate your Magento store with ShippingEasy to allow your order, tracking and fulfillment data to populate in real-time across all systems. Plug in your UPS and FedEx accounts or other marketplaces like eBay or Amazon to download all new orders and easily assign shipping preferences, rates and delivery options in real-time.</notes>
12
+ <authors><author><name>Kevin Cogill</name><user>skwerl</user><email>skwerl@gmail.com</email></author></authors>
13
+ <date>2015-07-02</date>
14
+ <time>00:06:16</time>
15
+ <contents><target name="mage"><dir name="lib"><dir name="ShippingEasy"><dir name="ShippingEasy"><file name="ApiConnectionError.php" hash="970c3474dd2117df18c06ef9796776c3"/><file name="ApiError.php" hash="dddc54704c2efab1dff5910c8cfeb1ed"/><file name="ApiRequestor.php" hash="c302ec9023e67b7b64b13d9bb03f2c7e"/><file name="AuthenticationError.php" hash="9267d2a96c79e8ce85bd66ae5291d046"/><file name="Authenticator.php" hash="95ee778bd71cd7a750b51bd3b72bd823"/><file name="Cancellation.php" hash="7a5068bb4c79a34935b92a8eadc4902d"/><file name="Error.php" hash="a8238dfdc1bc975ef4803f1529447d28"/><file name="InvalidRequestError.php" hash="4760cc5aea86f7e48e601f11bc91cb45"/><file name="Object.php" hash="3ce899f97dd3bec21173fcffefba15c6"/><file name="Order.php" hash="d8954dbc2a8f2ae3547177ed45d961f4"/><file name="PartnerAccount.php" hash="bfc07627b36246fec0fdfbc575f0e19c"/><file name="PartnerSession.php" hash="510d94b4e2949c5a8f0973b57209eebd"/><file name="ShippingEasy.php" hash="7ab0f7272b6c294346d02ec2b4859e5d"/><file name="Signature.php" hash="dceae7f35853e19e4e07b56e42fb28a9"/><file name="SignedUrl.php" hash="57f5803fba9ec8d26f0335062e317d5f"/></dir><file name="ShippingEasy.php" hash="f0c7a50d5ff46b93ca9ad7a7672abc95"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Shippingeasy_Fulfilment.xml" hash="dbdc4045fbd6ae6fe42324f5e981a671"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="shippingeasy"><dir name="system"><dir name="config"><file name="button.phtml" hash="81a1c7307019321f0443792115a0371f"/></dir></dir></dir></dir></dir></dir></dir></target><target name="magecommunity"><dir name="Shippingeasy"><dir name="Fulfilment"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Links"><file name="Api.php" hash="b8bca29282bb4188cf51a7614dde96c7"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="80f3c2be270920a249634e37878a89ea"/></dir><dir name="controllers"><file name="IndexController.php" hash="31ab76f8a44b28c325f6e1d73d61c1fe"/></dir><dir name="etc"><file name="config.xml" hash="5cf127da71e3e964e7f9ff40855c1e98"/><file name="system.xml" hash="f2dd2cff07d1c26353c3fcd336c5f14a"/></dir></dir></dir></target></contents>
 
 
 
16
  <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.1.0</max></php></required></dependencies>
18
  </package>