shippo - Version 0.0.2

Version Notes

Initial release of the Shippo app, subject to ongoing development.

Download this release

Release Info

Developer Tobias Schottdorf
Extension shippo
Version 0.0.2
Comparing to
See all releases


Version 0.0.2

app/code/community/Shippo/Api/controllers/ShippoController.php ADDED
@@ -0,0 +1,155 @@
1
+ <?php
2
+ class Shippo_Api_ShippoController extends Mage_Adminhtml_Controller_Action
3
+ {
4
+ const APIUSER = 'shippo';
5
+ const APIMAIL = 'support@goshippo.com';
6
+ const APIROLE = 'shippo';
7
+ const LOGOURL = 'https://shippo-static.s3.amazonaws.com/img/logo/logo-magento.png';
8
+ const SETUPURL = 'https://goshippo.com/magento/setup';
9
+
10
+ public function postAction()
11
+ {
12
+ $this->loadLayout();
13
+ $post = $this->getRequest()->getPost();
14
+ $block = $this->getLayout()->createBlock('adminhtml/template');
15
+ try {
16
+ if (empty($post)) {
17
+ Mage::throwException($this->__('Invalid form data.'));
18
+ }
19
+ if($post['confirm'])
20
+ {
21
+ $apikey = $this->_setupAccess();
22
+ $message = $this->__("Credentials successfully created.");
23
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
24
+ if($apikey) {
25
+ $block->setData("apiuser", self::APIUSER);
26
+ $block->setData("apikey", $apikey);
27
+ }
28
+ else {
29
+ throw new Exception("User was not created: No API key obtained");
30
+ }
31
+ $block->setData('logoUrl', self::LOGOURL);
32
+ $block->setData('setupUrl', self::SETUPURL);
33
+ $block->setTemplate('shippo/active.phtml');
34
+ $this->_addContent($block);
35
+ $this->renderLayout();
36
+ return;
37
+ }
38
+ elseif ($post['remove_access']) {
39
+ $this->_removeAccess();
40
+ $message = 'Shippo credentials successfully removed';
41
+ Mage::getSingleton('adminhtml/session')->addSuccess($message);
42
+ }
43
+ } catch (Exception $e) {
44
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
45
+ }
46
+ $this->_redirect('adminhtml/shippo');
47
+ }
48
+
49
+ private function _makeApiKey()
50
+ {
51
+ return Mage::getModel('customer/customer')->generatePassword(12);;
52
+ }
53
+
54
+ public function getUserByEmail($email)
55
+ {
56
+ return Mage::getModel('api/user')->load($email, "email");
57
+ }
58
+ public function getRoleByName($name)
59
+ {
60
+ return Mage::getModel('api/roles')->load($name, 'role_name');
61
+ }
62
+
63
+ private function _staticUserData()
64
+ {
65
+ return array(
66
+ "username" => self::APIUSER,
67
+ "firstname" => "Shippo",
68
+ "lastname" => "Shippo",
69
+ "email" => self::APIMAIL,
70
+ "password" => '',
71
+ "confirmation" => ''
72
+ );
73
+ }
74
+
75
+ private function _removeAccess()
76
+ {
77
+ $role = $this->getRoleByName(self::APIROLE);
78
+ $user = $this->getUserByEmail(self::APIMAIL);
79
+ if($user->getId()) {
80
+ $user->delete();
81
+ }
82
+ if($role->getId()) {
83
+ $role->delete();
84
+ }
85
+ $this->_redirect('adminhtml/shippo');
86
+ }
87
+
88
+ private function _setupAccess()
89
+ {
90
+ $apikey = $this->_makeApiKey();
91
+ $userData = $this->_staticUserData();
92
+ $userData['new_api_key'] = $apikey;
93
+ $userData['api_key_confirmation'] = $apikey;
94
+
95
+ $resources = explode(",", "__root__,sales,sales/order,sales/order/creditmemo,sales/order/creditmemo/list,sales/order/creditmemo/info,sales/order/creditmemo/cancel,sales/order/creditmemo/comment,sales/order/creditmemo/create,sales/order/invoice,sales/order/invoice/cancel,sales/order/invoice/info,sales/order/invoice/void,sales/order/invoice/capture,sales/order/invoice/comment,sales/order/invoice/create,sales/order/shipment,sales/order/shipment/send,sales/order/shipment/info,sales/order/shipment/track,sales/order/shipment/comment,sales/order/shipment/create,sales/order/info,sales/order/change");
96
+
97
+
98
+ $role = $this->getRoleByName(self::APIROLE);
99
+ $user = $this->getUserByEmail(self::APIMAIL);
100
+
101
+ if(!$role->getId())
102
+ {
103
+ $role = Mage::getModel('api/roles')->load($roleId);
104
+ $role->setName(self::APIROLE)->setRoleType('G');
105
+ $role->save();
106
+ $roleId = $role->getId();
107
+
108
+ Mage::getModel("api/rules")
109
+ ->setRoleId($role->getId())
110
+ ->setResources($resources)
111
+ ->saveRel();
112
+ }
113
+
114
+
115
+ if(!$user->getId())
116
+ {
117
+
118
+ $user = Mage::getModel('api/user')->load($userId);
119
+
120
+ $user->setData($userData);
121
+ $user->save();
122
+ $userId = $user->getId();
123
+
124
+ $user->setRoleIds([$roleId])
125
+ ->setRoleUserId($user->getUserId())
126
+ ->saveRelations();
127
+ return $apikey;
128
+ }
129
+ return false;
130
+ }
131
+
132
+ public function indexAction()
133
+ {
134
+ // let's go
135
+ $this->loadLayout();
136
+
137
+ $role = $this->getRoleByName(self::APIROLE);
138
+ $user = $this->getUserByEmail(self::APIMAIL);
139
+
140
+ $block = $this->getLayout()->createBlock('adminhtml/template');
141
+ if($user->getId()) {
142
+ $block->setData("apiuser", $user->getUsername());
143
+ $block->setData("apikey", "");
144
+ $block->setData('logoUrl', self::LOGOURL);
145
+ //echo var_dump($user);
146
+ $block->setTemplate('shippo/active.phtml');
147
+ }
148
+ else {
149
+ $block->setTemplate('shippo/form.phtml');
150
+ }
151
+ $this->_addContent($block);
152
+ $this->renderLayout();
153
+ }
154
+ }
155
+
app/code/community/Shippo/Api/etc/adminhtml.xml ADDED
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <config>
3
+ <menu>
4
+ <sales>
5
+ <!--<title>Shippo</title>
6
+ <sort_order>99</sort_order>-->
7
+ <children>
8
+ <shippomain>
9
+ <title>Shippo</title>
10
+ <sort_order>31</sort_order>
11
+ <action>adminhtml/shippo/index</action>
12
+ </shippomain>
13
+ </children>
14
+ </sales>
15
+ </menu>
16
+ <!--<acl>
17
+ <resources>
18
+ <admin>
19
+ <children>
20
+ <system>
21
+ <sort_order>1</sort_order>
22
+ <children>
23
+ <shippomain>
24
+ <title>Shippo Configuration</title>
25
+ </shippomain>
26
+ </children>
27
+ </system>
28
+ </children>
29
+ </admin>
30
+ </resources>
31
+ </acl>-->
32
+ </config>
app/code/community/Shippo/Api/etc/config.xml ADDED
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!--
3
+ * Shippo
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to info@goshippo.com so we can send you a copy immediately.
14
+ *
15
+ * @category Shipping
16
+ * @package Shippo_Api
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ -->
19
+ <config>
20
+ <modules>
21
+ <Shippo_Api>
22
+ <version>0.0.1</version>
23
+ </Shippo_Api>
24
+ </modules>
25
+ <admin>
26
+ <routers>
27
+ <adminhtml>
28
+ <args>
29
+ <modules>
30
+ <Shippo_Api after="Mage_Adminhtml">Shippo_Api</Shippo_Api>
31
+ </modules>
32
+ </args>
33
+ </adminhtml>
34
+ </routers>
35
+ </admin>
36
+ <default>
37
+ <shippoapi>
38
+ <config>
39
+ <realm>Shippo</realm>
40
+ </config>
41
+ </shippoapi>
42
+ </default>
43
+ </config>
44
+
app/design/adminhtml/default/default/template/shippo/active.phtml ADDED
@@ -0,0 +1,66 @@
1
+ <?php if(!$this->getData('apikey')): ?>
2
+ <div class="content-header">
3
+ <table cellspacing="0" class="grid-header">
4
+ <tr>
5
+ <td colspan="2"><h3><?=$this->__('Shippo')?></h3></td>
6
+ </tr>
7
+ <tr>
8
+ <td><h4><?=$this->__('Your account is set up')?>. <a href="https://goshippo.com/magento/" target="_blank"></h4><br /><?=$this->__('Visit Shippo here!') ?></a></td>
9
+ <td style="text-align:right;"><a href="https://goshippo.com/magento" title="Visit Shippo" target="_blank"><img style="max-width:100px;" src="<?=$this->getData('logoUrl')?>" alt="Visit Shippo" /></a></td>
10
+ </tr>
11
+ </table>
12
+ </div>
13
+ <?php endif; ?>
14
+ <div class="entry-edit">
15
+ <form id="dummy_form" name="dummy_form" method="post" action="<?=$this->getUrl('*/*/post')?>">
16
+ <h4 class="icon-head head-edit-form fieldset-legend"><?=$this->__('Credentials')?></h4>
17
+ <?php if($this->getData('apikey')): ?>
18
+ <p>We've set you up! <strong>Do not close this page yet.</strong>
19
+ <h5><a href="<?=$this->getData('setupUrl')?>" target="_blank">To complete the process, open this link in a new window and follow the instructions.</a></h5>
20
+ <p>You'll need the <strong>API User</strong> and <strong>API Key</strong> below.</p>
21
+ <?php else: ?>
22
+ <p>Shippo is set up for your Magento shop. If you have entered the information below in your <a href="https://goshippo.com/magento/" target="_blank">Shippo account</a>, your orders will be shown in your <a href="https://goshippo.com/user/orders">Shippo Orders</a>. Please note that for security reasons, we cannot retrieve your password in clear text any more. If you forgot the password, you can simply remove access via the button below, and create new credentials afterwards. </p>
23
+ <?php endif; ?>
24
+ <fieldset id="my-fieldset">
25
+ <table cellspacing="0" class="form-list">
26
+ <tr>
27
+ <td class="label"><?=$this->__('API User')?></td>
28
+ <td class="input-ele"><input type="text" value="<?php echo $this->getData('apiuser'); ?>"/></td>
29
+ </tr>
30
+ <tr>
31
+ <td class="label"><?=$this->__('API Key')?></td>
32
+ <td class="input-ele"><input type="text" value="<?php echo $this->getData('apikey') ? $this->getData('apikey') : "**************"; ?>"/></td>
33
+ </tr>
34
+ </table>
35
+ </fieldset>
36
+ </form>
37
+ </div>
38
+ <?php if(!$this->getData('apikey')): ?>
39
+ <div class="content-header">
40
+ <table cellspacing="0" class="grid-header">
41
+ <tr>
42
+ <td><h3><?=$this->__('Shippo Setup')?></h3></td>
43
+ <td class="a-right">
44
+ <button onclick="editForm.submit()" class="scalable save" type="button"><span>Remove access</span></button>
45
+ </td>
46
+ </tr>
47
+ </table>
48
+ </div>
49
+ <div class="entry-edit">
50
+ <form id="remove_form" name="remove_form" method="post" action="<?=$this->getUrl('*/*/post')?>">
51
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
52
+ <h4 class="icon-head head-edit-form fieldset-legend">Check the box below and submit the form in order to remove the credentials we set up to import your orders to Shippo. You will be able to create new credentials afterwards, but it will be necessary that you enter the new API key <a href="https://goshippo.com/magento/">on our website</a> if you would like us to import your orders again.</h4>
53
+ <fieldset id="my-fieldset">
54
+ <table cellspacing="0" class="form-list">
55
+ <tr>
56
+ <td class="label"><?=$this->__('I would like to remove Shippo\'s access to my store')?><span class="required">*</span></td>
57
+ <td class="input-ele"><input type="checkbox" class="checkbox required-entry" name="remove_access" /></td>
58
+ </tr>
59
+ </table>
60
+ </fieldset>
61
+ </form>
62
+ </div>
63
+ <script type="text/javascript">
64
+ var editForm = new varienForm('remove_form');
65
+ </script>
66
+ <?php endif; ?>
app/design/adminhtml/default/default/template/shippo/form.phtml ADDED
@@ -0,0 +1,29 @@
1
+ <div class="content-header">
2
+ <table cellspacing="0" class="grid-header">
3
+ <tr>
4
+ <td><h3><?=$this->__('Shippo Setup')?></h3></td>
5
+ <td class="a-right">
6
+ <button onclick="editForm.submit()" class="scalable save" type="button"><span>Get me started!</span></button>
7
+ </td>
8
+ </tr>
9
+ </table>
10
+ </div>
11
+ <div class="entry-edit">
12
+ <form id="setup_form" name="setup_form" method="post" action="<?=$this->getUrl('*/*/post')?>">
13
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
14
+ <h4 class="icon-head head-edit-form fieldset-legend"><?=$this->__('Credentials')?></h4>
15
+ <p>In order to make your orders available in Shippo we need to allow it to access your orders. We'll set this up for you, simply confirm and submit this form.</p>
16
+ <fieldset id="my-fieldset">
17
+ <table cellspacing="0" class="form-list">
18
+ <tr>
19
+ <td class="label"><?=$this->__('Allow Shippo to import my orders')?> <span class="required">*</span></td>
20
+ <td class="input-ele"><input type="checkbox" class="checkbox required-entry" name="confirm" /></td>
21
+ </tr>
22
+ </table>
23
+ </fieldset>
24
+ </form>
25
+ </div>
26
+ <script type="text/javascript">
27
+ var editForm = new varienForm('setup_form');
28
+ </script>
29
+
app/etc/modules/Shippo_Api.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <config>
3
+ <modules>
4
+ <Shippo_Api>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Shippo_Api>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>shippo</name>
4
+ <version>0.0.2</version>
5
+ <stability>stable</stability>
6
+ <license>OSL 3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Print your shipping labels with one click. Shippo imports your orders and allows you to print discounted shipping labels right away.</summary>
10
+ <description>Print your shipping labels with one click. Shippo imports your Magento orders and allows you to print labels right away. It's as easy as it should be. Choose your parcel dimension, pickup date, service type and preferred carrier and you will get your label within seconds. Comfortable, easy, reliable.&#xD;
11
+ &#xD;
12
+ Always find the cheapest rate. By comparing the express delivery rates of all courier services, we always find the best prices for your package shipments. Shippo offers both an API and a web interface that makes comparing carriers and finding the cheapest or fastest rates for shipments easy.&#xD;
13
+ &#xD;
14
+ It's FREE! As a Magento shop owner, you don't have to pay any setup or monthly fees. We will never charge any hidden fees or subscription costs. You only pay $0.05 per shipping label printed through our services.</description>
15
+ <notes>Initial release of the Shippo app, subject to ongoing development.</notes>
16
+ <authors><author><name>Tobias Schottdorf</name><user>TobiasShippo</user><email>tobias@goshippo.com</email></author></authors>
17
+ <date>2014-04-23</date>
18
+ <time>01:07:33</time>
19
+ <contents><target name="magecommunity"><dir name="Shippo"><dir name="Api"><dir name="controllers"><file name="ShippoController.php" hash="ebb156078ad821bad4f3e573e6d5c2a5"/></dir><dir name="etc"><file name="adminhtml.xml" hash="21b0c98edca061e05fcc4c4765bb93f6"/><file name="config.xml" hash="b5be2580a263b72d4a3513f46faf145e"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Shippo_Api.xml" hash="e4a32a86871013b47dcabfbeef249887"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="shippo"><file name="active.phtml" hash="dd496b954b68a4c652d914d5ad5198d8"/><file name="form.phtml" hash="e899ebdfa55589f7e60b8a6383f55d64"/></dir></dir></dir></dir></dir></target></contents>
20
+ <compatible/>
21
+ <dependencies><required><php><min>0.0.1</min><max>9.9.9</max></php></required></dependencies>
22
+ </package>