Version Notes
The initial release version with minimum production test time.
Download this release
Release Info
Developer | Konstantin Kiritsenko |
Extension | KProject_ShareASale |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/KProject/ShareASale/Block/Pixel.php +76 -0
- app/code/community/KProject/ShareASale/Helper/Customer.php +54 -0
- app/code/community/KProject/ShareASale/Helper/Data.php +121 -0
- app/code/community/KProject/ShareASale/Helper/Pixel.php +50 -0
- app/code/community/KProject/ShareASale/Helper/Product.php +49 -0
- app/code/community/KProject/ShareASale/Helper/Status.php +194 -0
- app/code/community/KProject/ShareASale/Helper/Transaction.php +139 -0
- app/code/community/KProject/ShareASale/Model/Cron.php +134 -0
- app/code/community/KProject/ShareASale/Model/Mysql4/Orders.php +27 -0
- app/code/community/KProject/ShareASale/Model/Mysql4/Orders/Collection.php +28 -0
- app/code/community/KProject/ShareASale/Model/Observer.php +172 -0
- app/code/community/KProject/ShareASale/Model/Orders.php +124 -0
- app/code/community/KProject/ShareASale/Model/Session.php +61 -0
- app/code/community/KProject/ShareASale/etc/adminhtml.xml +23 -0
- app/code/community/KProject/ShareASale/etc/config.xml +123 -0
- app/code/community/KProject/ShareASale/etc/system.xml +125 -0
- app/code/community/KProject/ShareASale/sql/kproject_sas_setup/mysql4-install-1.0.0.php +80 -0
- app/design/frontend/base/default/layout/kproject/sas/checkout.xml +8 -0
- app/design/frontend/base/default/template/kproject/sas/pixel.phtml +23 -0
- app/etc/modules/KProject_ShareASale.xml +10 -0
- lib/KProject/ShareASale/Api.php +178 -0
- lib/KProject/ShareASale/Credentials.php +101 -0
- package.xml +18 -0
app/code/community/KProject/ShareASale/Block/Pixel.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Block_Pixel extends Mage_Core_Block_Template
|
22 |
+
{
|
23 |
+
/**
|
24 |
+
* Returns the full pixel html
|
25 |
+
* to print in the body of frontend
|
26 |
+
*
|
27 |
+
* @return string
|
28 |
+
*/
|
29 |
+
public function printPixel()
|
30 |
+
{
|
31 |
+
$img = '';
|
32 |
+
if (!Mage::helper('kproject_sas')->isEnabled()) {
|
33 |
+
return $img;
|
34 |
+
}
|
35 |
+
|
36 |
+
$order = Mage::getSingleton('checkout/session')->getLastRealOrder();
|
37 |
+
|
38 |
+
if (!$order->getId()) {
|
39 |
+
$orderId = Mage::getSingleton('checkout/type_onepage')->getLastOrderId();
|
40 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
|
41 |
+
}
|
42 |
+
|
43 |
+
$params = Mage::helper('kproject_sas/transaction')->getNewTransactionParams($order);
|
44 |
+
try {
|
45 |
+
$client = $this->getPixelHelper()->getBaseClientSetup($order);
|
46 |
+
$client->getUri()->addReplaceQueryParameters($params);
|
47 |
+
$link = $client->getUri(true);
|
48 |
+
$img = $this->getImageHtml($link);
|
49 |
+
} catch (Exception $e) {
|
50 |
+
Mage::throwException($e->getMessage());
|
51 |
+
}
|
52 |
+
|
53 |
+
return $img;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* @return KProject_ShareASale_Helper_Pixel
|
58 |
+
*/
|
59 |
+
public function getPixelHelper()
|
60 |
+
{
|
61 |
+
return Mage::helper('kproject_sas/pixel');
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Creates the pixel html <img> wrapper
|
66 |
+
*
|
67 |
+
* @param string $uri
|
68 |
+
*
|
69 |
+
* @return string
|
70 |
+
*/
|
71 |
+
private function getImageHtml($uri)
|
72 |
+
{
|
73 |
+
/** @noinspection HtmlUnknownTarget */
|
74 |
+
return $this->__('<img src="%s" width="1" height="1"/>', $uri);
|
75 |
+
}
|
76 |
+
}
|
app/code/community/KProject/ShareASale/Helper/Customer.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Helper_Customer extends Mage_Core_Helper_Abstract
|
22 |
+
{
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Retrieves an answer if the customer
|
26 |
+
* is new or not. If guest will return an
|
27 |
+
* empty string.
|
28 |
+
*
|
29 |
+
* @param string | int $customerId
|
30 |
+
*
|
31 |
+
* @return int | string
|
32 |
+
*/
|
33 |
+
public function getIsNewParam($customerId = null)
|
34 |
+
{
|
35 |
+
if (!$customerId) {
|
36 |
+
return '';
|
37 |
+
}
|
38 |
+
|
39 |
+
return $this->isNew($customerId) ? 1 : 0;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @param int | string $customerId
|
44 |
+
*
|
45 |
+
* @return bool
|
46 |
+
*/
|
47 |
+
public function isNew($customerId)
|
48 |
+
{
|
49 |
+
$orders = Mage::getResourceModel('sales/order_collection')
|
50 |
+
->addFieldToFilter('customer_id', $customerId);
|
51 |
+
|
52 |
+
return $orders->getSize() <= 1;
|
53 |
+
}
|
54 |
+
}
|
app/code/community/KProject/ShareASale/Helper/Data.php
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Helper_Data extends Mage_Core_Helper_Abstract
|
22 |
+
{
|
23 |
+
const XML_PATH_ENABLED = 'kproject_sas/general/enabled';
|
24 |
+
const XML_PATH_MERCHANT_ID = 'kproject_sas/general/merchant_id';
|
25 |
+
const XML_PATH_TOKEN = 'kproject_sas/api/token';
|
26 |
+
const XML_PATH_SECRET_KEY = 'kproject_sas/api/secret_key';
|
27 |
+
const XML_PATH_API_NEW_ENABLED = 'kproject_sas/api_new/enabled';
|
28 |
+
const XML_PATH_AFFILIATE_KEY = 'kproject_sas/api_new/affiliate_key';
|
29 |
+
const XML_PATH_CLICK_KEY = 'kproject_sas/api_new/click_key';
|
30 |
+
|
31 |
+
/**
|
32 |
+
* @param null $storeId
|
33 |
+
*
|
34 |
+
* @return KProject_ShareASale_Credentials
|
35 |
+
*/
|
36 |
+
public function getCredentials($storeId = null)
|
37 |
+
{
|
38 |
+
$credentials = new KProject_ShareASale_Credentials();
|
39 |
+
$credentials->setMerchantId(Mage::getStoreConfig(self::XML_PATH_MERCHANT_ID, $storeId));
|
40 |
+
|
41 |
+
$eToken = Mage::getStoreConfig(self::XML_PATH_TOKEN, $storeId);
|
42 |
+
$token = $this->getCoreHelper()->decrypt($eToken);
|
43 |
+
$credentials->setToken($token);
|
44 |
+
|
45 |
+
$eSKey = Mage::getStoreConfig(self::XML_PATH_SECRET_KEY, $storeId);
|
46 |
+
$key = $this->getCoreHelper()->decrypt($eSKey);
|
47 |
+
$credentials->setSecretKey($key);
|
48 |
+
|
49 |
+
return $credentials;
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Just checks if plugin is enabled via config
|
54 |
+
*
|
55 |
+
* @param null $storeId
|
56 |
+
*
|
57 |
+
* @return bool
|
58 |
+
*/
|
59 |
+
public function isEnabled($storeId = null)
|
60 |
+
{
|
61 |
+
return Mage::getStoreConfigFlag(self::XML_PATH_ENABLED, $storeId);
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Check if the new transactions are allowed
|
66 |
+
* to be made via API
|
67 |
+
*
|
68 |
+
* @param null $storeId
|
69 |
+
*
|
70 |
+
* @return bool
|
71 |
+
*/
|
72 |
+
public function newTransactionViaApiEnabled($storeId = null)
|
73 |
+
{
|
74 |
+
return Mage::getStoreConfigFlag(self::XML_PATH_API_NEW_ENABLED, $storeId);
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Checks if the library is accessible
|
79 |
+
* and plugin is enabled
|
80 |
+
*
|
81 |
+
* @param null $storeId
|
82 |
+
*
|
83 |
+
* @return bool
|
84 |
+
*/
|
85 |
+
public function isActive($storeId = null)
|
86 |
+
{
|
87 |
+
return class_exists('KProject_ShareASale_Api') && $this->isEnabled($storeId);
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* @return string
|
92 |
+
*/
|
93 |
+
public function getAffiliateIdentifierKey($storeId = null)
|
94 |
+
{
|
95 |
+
return Mage::getStoreConfig(self::XML_PATH_AFFILIATE_KEY, $storeId);
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* @return string
|
100 |
+
*/
|
101 |
+
public function getClickIdentifierKey($storeId = null)
|
102 |
+
{
|
103 |
+
return Mage::getStoreConfig(self::XML_PATH_CLICK_KEY, $storeId);
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* @return KProject_ShareASale_Helper_Status
|
108 |
+
*/
|
109 |
+
protected function statusHelper()
|
110 |
+
{
|
111 |
+
return Mage::helper('kproject_sas/status');
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* @return Mage_Core_Helper_Abstract|Mage_Core_Helper_Data
|
116 |
+
*/
|
117 |
+
protected function getCoreHelper()
|
118 |
+
{
|
119 |
+
return Mage::helper('core');
|
120 |
+
}
|
121 |
+
}
|
app/code/community/KProject/ShareASale/Helper/Pixel.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Helper_Pixel extends KProject_ShareASale_Helper_Data
|
22 |
+
{
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Create base client
|
26 |
+
*
|
27 |
+
* @param Mage_Sales_Model_Order $order
|
28 |
+
*
|
29 |
+
* @return Zend_Http_Client
|
30 |
+
*/
|
31 |
+
public function getBaseClientSetup(Mage_Sales_Model_Order $order)
|
32 |
+
{
|
33 |
+
$client = new Zend_Http_Client();
|
34 |
+
$credentials = Mage::helper('kproject_sas/transaction')->getCredentials($order->getStoreId());
|
35 |
+
$uri = $this->getPixelUrl() . '?merchantId=' . $credentials->getMerchantId();
|
36 |
+
|
37 |
+
return $client->setUri($uri);
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Hardcoded for now, just prepping for
|
42 |
+
* when it becomes part of the config.
|
43 |
+
*
|
44 |
+
* @return string
|
45 |
+
*/
|
46 |
+
public function getPixelUrl()
|
47 |
+
{
|
48 |
+
return 'https://shareasale.com/sale.cfm';
|
49 |
+
}
|
50 |
+
}
|
app/code/community/KProject/ShareASale/Helper/Product.php
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Helper_Product extends Mage_Core_Helper_Abstract
|
22 |
+
{
|
23 |
+
/**
|
24 |
+
* @param Mage_Sales_Model_Order $order
|
25 |
+
*
|
26 |
+
* @return array
|
27 |
+
*/
|
28 |
+
public function getItemParams(Mage_Sales_Model_Order $order)
|
29 |
+
{
|
30 |
+
/** @var Mage_Sales_Model_Order_Item[] $items */
|
31 |
+
$items = $order->getAllVisibleItems();
|
32 |
+
$skuList = $quantityList = $priceList = '';
|
33 |
+
|
34 |
+
$last_index = array_search(end($items), $items, true);
|
35 |
+
foreach ($items as $index => $item) {
|
36 |
+
$delimiter = $index === $last_index ? '' : ',';
|
37 |
+
$skuList .= $item->getSku() . $delimiter;
|
38 |
+
$quantityList .= ceil($item->getQtyOrdered()) . $delimiter;
|
39 |
+
$priceList .= ($item->getProduct()->getFinalPrice() - ($item->getDiscountAmount() / $item->getQtyOrdered()))
|
40 |
+
. $delimiter;
|
41 |
+
}
|
42 |
+
|
43 |
+
return array(
|
44 |
+
'skulist' => $skuList,
|
45 |
+
'pricelist' => $priceList,
|
46 |
+
'quantitylist' => $quantityList
|
47 |
+
);
|
48 |
+
}
|
49 |
+
}
|
app/code/community/KProject/ShareASale/Helper/Status.php
ADDED
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Helper_Status extends Mage_Core_Helper_Abstract
|
22 |
+
{
|
23 |
+
const STATUS_SUCCESS = 1;
|
24 |
+
const STATUS_PARTIAL_REFUND = 2;
|
25 |
+
const STATUS_FULL_REFUND = 3;
|
26 |
+
const STATUS_SAS_ERROR = 4;
|
27 |
+
const STATUS_MAGE_ERROR = 5;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* @var array - error text that can come back from the API
|
31 |
+
*/
|
32 |
+
private $errorMap = array(
|
33 |
+
'Error Code',
|
34 |
+
'Transaction Not Found'
|
35 |
+
);
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Figure out if the response is an error or not
|
39 |
+
*
|
40 |
+
* @param Zend_Http_Response $response
|
41 |
+
*
|
42 |
+
* @return bool
|
43 |
+
*/
|
44 |
+
public function isSuccessful(Zend_Http_Response $response)
|
45 |
+
{
|
46 |
+
if ($response->isSuccessful() && !$this->strposArray($response->getBody(), $this->errorMap)) {
|
47 |
+
return true;
|
48 |
+
}
|
49 |
+
|
50 |
+
return false;
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* @param Zend_Http_Response $response
|
55 |
+
*
|
56 |
+
* @return bool | string
|
57 |
+
*/
|
58 |
+
public function getErrorCode($response)
|
59 |
+
{
|
60 |
+
$code = $this->parseErrorCode($response->getBody());
|
61 |
+
|
62 |
+
if (is_numeric($code)) {
|
63 |
+
return $code;
|
64 |
+
}
|
65 |
+
|
66 |
+
return false;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Checks if the passed status is an error
|
71 |
+
*
|
72 |
+
* @param int $status
|
73 |
+
*
|
74 |
+
* @return bool
|
75 |
+
*/
|
76 |
+
public function isError($status)
|
77 |
+
{
|
78 |
+
return $status === self::STATUS_SAS_ERROR || $status === self::STATUS_MAGE_ERROR;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Just returns the mage error code
|
83 |
+
*
|
84 |
+
* @return int
|
85 |
+
*/
|
86 |
+
public function getMageErrorCode()
|
87 |
+
{
|
88 |
+
return self::STATUS_MAGE_ERROR;
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* @param Zend_Http_Response $response
|
93 |
+
* @param int $successStatus
|
94 |
+
*
|
95 |
+
* @return int
|
96 |
+
*/
|
97 |
+
public function getStatusFromResponse($response, $successStatus = self::STATUS_SUCCESS)
|
98 |
+
{
|
99 |
+
return $this->isSuccessful($response)
|
100 |
+
? $successStatus
|
101 |
+
: self::STATUS_SAS_ERROR;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Helps set status for edit & void calls as
|
106 |
+
* they could be running without New Transaction
|
107 |
+
* API enabled
|
108 |
+
*
|
109 |
+
* @param Mage_Sales_Model_Order $order
|
110 |
+
* @param int $successStatus - 1,2,3
|
111 |
+
* @param Zend_Http_Response|null $response
|
112 |
+
*
|
113 |
+
* @return mixed
|
114 |
+
*/
|
115 |
+
public function setKOrderStatus(Mage_Sales_Model_Order $order, $successStatus, Zend_Http_Response $response = null)
|
116 |
+
{
|
117 |
+
if (!Mage::helper('kproject_sas')->newTransactionViaApiEnabled($order->getStoreId())) {
|
118 |
+
return false;
|
119 |
+
}
|
120 |
+
|
121 |
+
$kOrder = Mage::getModel('kproject_sas/orders')->load($order->getIncrementId(), 'order_number');
|
122 |
+
|
123 |
+
if (!$kOrder->getId()) {
|
124 |
+
$kOrder->setOrderNumber($order->getIncrementId());
|
125 |
+
}
|
126 |
+
|
127 |
+
if (!$response) {
|
128 |
+
$status = $this->getMageErrorCode();
|
129 |
+
} else {
|
130 |
+
$status = $this->getStatusFromResponse($response, $successStatus);
|
131 |
+
$error = $this->getErrorCode($response);
|
132 |
+
$kOrder->setErrorCode($error);
|
133 |
+
}
|
134 |
+
$parameters = Mage::getSingleton('kproject_sas/session')->getParameters();
|
135 |
+
|
136 |
+
try {
|
137 |
+
$kOrder->setParameters($parameters)
|
138 |
+
->setApiStatus($status)
|
139 |
+
->save();
|
140 |
+
} catch (Exception $e) {
|
141 |
+
Mage::logException($e);
|
142 |
+
}
|
143 |
+
|
144 |
+
return $kOrder;
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Parses out the error code from the
|
149 |
+
* response
|
150 |
+
*
|
151 |
+
* @param string $body
|
152 |
+
*
|
153 |
+
* @return mixed
|
154 |
+
*/
|
155 |
+
private function parseErrorCode($body)
|
156 |
+
{
|
157 |
+
$body = trim($body);
|
158 |
+
preg_match('/Code\s(.*)/', $body, $matches);
|
159 |
+
|
160 |
+
if (!empty($matches[1])) {
|
161 |
+
return $matches[1];
|
162 |
+
}
|
163 |
+
|
164 |
+
return $body;
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* @param string $haystack
|
169 |
+
* @param array | string $needles
|
170 |
+
*
|
171 |
+
* @return int|false
|
172 |
+
*/
|
173 |
+
private function strposArray($haystack, $needles)
|
174 |
+
{
|
175 |
+
$haystack = trim($haystack);
|
176 |
+
|
177 |
+
if (is_array($needles)) {
|
178 |
+
foreach ($needles as $str) {
|
179 |
+
if (is_array($str)) {
|
180 |
+
$pos = $this->strposArray($haystack, $str);
|
181 |
+
} else {
|
182 |
+
$pos = strpos($haystack, $str);
|
183 |
+
}
|
184 |
+
if ($pos !== false) {
|
185 |
+
return $pos;
|
186 |
+
}
|
187 |
+
}
|
188 |
+
} else {
|
189 |
+
return strpos($haystack, $needles);
|
190 |
+
}
|
191 |
+
|
192 |
+
return false;
|
193 |
+
}
|
194 |
+
}
|
app/code/community/KProject/ShareASale/Helper/Transaction.php
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Helper_Transaction extends KProject_ShareASale_Helper_Data
|
22 |
+
{
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Create new transaction using the ShareASale API
|
26 |
+
*
|
27 |
+
* @param Mage_Sales_Model_Order $order
|
28 |
+
*
|
29 |
+
* @return bool | Mage_Sales_Model_Order
|
30 |
+
*/
|
31 |
+
public function create(Mage_Sales_Model_Order $order)
|
32 |
+
{
|
33 |
+
$parameters = $this->getSession()->getParameters();
|
34 |
+
if (!$this->isActive($order->getStoreId()) || !$parameters) {
|
35 |
+
return false;
|
36 |
+
}
|
37 |
+
|
38 |
+
$credentials = $this->getCredentials($order->getStoreId());
|
39 |
+
$api = new KProject_ShareASale_Api($credentials);
|
40 |
+
|
41 |
+
try {
|
42 |
+
$response = $api->createNewTransaction($order, $parameters);
|
43 |
+
} catch (Exception $e) {
|
44 |
+
$response = null;
|
45 |
+
Mage::logException($e);
|
46 |
+
}
|
47 |
+
|
48 |
+
return $response;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Fully void a transaction using ShareASale API
|
53 |
+
*
|
54 |
+
* @param Mage_Sales_Model_Order $order
|
55 |
+
*
|
56 |
+
* @return bool | Mage_Sales_Model_Order
|
57 |
+
*/
|
58 |
+
public function void(Mage_Sales_Model_Order $order)
|
59 |
+
{
|
60 |
+
if (!$this->isActive($order->getStoreId())) {
|
61 |
+
return false;
|
62 |
+
}
|
63 |
+
|
64 |
+
$credentials = $this->getCredentials($order->getStoreId());
|
65 |
+
$api = new KProject_ShareASale_Api($credentials);
|
66 |
+
$parameters = $this->getSession()->getParameters();
|
67 |
+
|
68 |
+
try {
|
69 |
+
$response = $api->voidTransaction($order, $parameters);
|
70 |
+
} catch (Exception $e) {
|
71 |
+
$response = null;
|
72 |
+
Mage::getSingleton('core/session')->addError(
|
73 |
+
'Error when calling ShareASale Void Transaction API: ' . $e->getMessage()
|
74 |
+
);
|
75 |
+
}
|
76 |
+
|
77 |
+
return $response;
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Make an edit to a transaction using ShareASale API
|
82 |
+
*
|
83 |
+
* @param Mage_Sales_Model_Order $order
|
84 |
+
*
|
85 |
+
* @return bool | Mage_Sales_Model_Order
|
86 |
+
*/
|
87 |
+
public function edit(Mage_Sales_Model_Order $order)
|
88 |
+
{
|
89 |
+
if (!$this->isActive($order->getStoreId())) {
|
90 |
+
return false;
|
91 |
+
}
|
92 |
+
|
93 |
+
$credentials = $this->getCredentials($order->getStoreId());
|
94 |
+
$api = new KProject_ShareASale_Api($credentials);
|
95 |
+
$parameters = $this->getSession()->getParameters();
|
96 |
+
|
97 |
+
try {
|
98 |
+
$response = $api->editTransaction($order, $parameters);
|
99 |
+
} catch (Exception $e) {
|
100 |
+
$response = null;
|
101 |
+
Mage::getSingleton('core/session')->addError(
|
102 |
+
'Error when calling ShareASale Edit Transaction API: ' . $e->getMessage()
|
103 |
+
);
|
104 |
+
}
|
105 |
+
|
106 |
+
return $response;
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Returns a list of parameters to use for
|
111 |
+
* new order transactions
|
112 |
+
*
|
113 |
+
* @param Mage_Sales_Model_Order $order
|
114 |
+
*
|
115 |
+
* @return array
|
116 |
+
*/
|
117 |
+
public function getNewTransactionParams(Mage_Sales_Model_Order $order)
|
118 |
+
{
|
119 |
+
return array_merge(
|
120 |
+
array(
|
121 |
+
'transtype' => 'sale',
|
122 |
+
'tracking' => $order->getIncrementId(),
|
123 |
+
'amount' => $order->getSubtotal() + $order->getDiscountAmount(),
|
124 |
+
'couponcode' => $order->getCouponCode(),
|
125 |
+
'newcustomer' => Mage::helper('kproject_sas/customer')->getIsNewParam($order->getCustomerId()),
|
126 |
+
'currency' => $order->getOrderCurrencyCode(),
|
127 |
+
),
|
128 |
+
Mage::helper('kproject_sas/product')->getItemParams($order)
|
129 |
+
);
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* @return KProject_ShareASale_Model_Session
|
134 |
+
*/
|
135 |
+
private function getSession()
|
136 |
+
{
|
137 |
+
return Mage::getSingleton('kproject_sas/session');
|
138 |
+
}
|
139 |
+
}
|
app/code/community/KProject/ShareASale/Model/Cron.php
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Model_Cron
|
22 |
+
{
|
23 |
+
/**
|
24 |
+
* Attempt to send previously failed transactions
|
25 |
+
* that are in status pending or specific error_code.
|
26 |
+
* Also keeps track of previous attempts. On 5+ attempts
|
27 |
+
* it removes the entry and continues to the next one.
|
28 |
+
*/
|
29 |
+
public function submitFailedTransactions()
|
30 |
+
{
|
31 |
+
/** @var KProject_ShareASale_Model_Orders $item */
|
32 |
+
foreach ($this->getFailedOrders() as $item) {
|
33 |
+
if ($item->getOrderNumber()) {
|
34 |
+
$item->incrementRetryCount()->save();
|
35 |
+
/** @var Mage_Sales_Model_Order $mageOrder */
|
36 |
+
$mageOrder = Mage::getModel('sales/order')->loadByIncrementId($item->getOrderNumber());
|
37 |
+
|
38 |
+
if (!Mage::helper('kproject_sas')->newTransactionViaApiEnabled($mageOrder->getStoreId())
|
39 |
+
|| $item->removeOnTooManyRetries()
|
40 |
+
) {
|
41 |
+
continue;
|
42 |
+
}
|
43 |
+
|
44 |
+
Mage::getSingleton('kproject_sas/session')->setParameters($item->getParameters());
|
45 |
+
$response = Mage::helper('kproject_sas/transaction')->create($mageOrder);
|
46 |
+
Mage::helper('kproject_sas/status')->setKOrderStatus(
|
47 |
+
$mageOrder,
|
48 |
+
KProject_ShareASale_Helper_Status::STATUS_SUCCESS,
|
49 |
+
$response
|
50 |
+
);
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
return $this;
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Removes all the old successful transactions
|
59 |
+
*/
|
60 |
+
public function deleteSuccessfulTransactions()
|
61 |
+
{
|
62 |
+
/** @var KProject_ShareASale_Model_Mysql4_Orders_Collection $collection */
|
63 |
+
$collection = Mage::getModel('kproject_sas/orders')
|
64 |
+
->getCollection()
|
65 |
+
->addFieldToFilter(
|
66 |
+
'api_status',
|
67 |
+
array(
|
68 |
+
'nin' => array(
|
69 |
+
KProject_ShareASale_Helper_Status::STATUS_SAS_ERROR,
|
70 |
+
KProject_ShareASale_Helper_Status::STATUS_MAGE_ERROR
|
71 |
+
)
|
72 |
+
)
|
73 |
+
);
|
74 |
+
|
75 |
+
foreach ($collection as $order) {
|
76 |
+
$order->delete();
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Get enabled store Id's
|
82 |
+
*
|
83 |
+
* @return array
|
84 |
+
*/
|
85 |
+
private function getStoreIds()
|
86 |
+
{
|
87 |
+
$storeIds = array();
|
88 |
+
$helper = Mage::helper('kproject_sas');
|
89 |
+
|
90 |
+
/** @var Mage_Core_Model_Website $website */
|
91 |
+
foreach (Mage::app()->getWebsites() as $website) {
|
92 |
+
/** @var Mage_Core_Model_Store_Group $group */
|
93 |
+
foreach ($website->getGroups() as $group) {
|
94 |
+
$stores = $group->getStores();
|
95 |
+
/** @var Mage_Core_Model_Store $store */
|
96 |
+
foreach ($stores as $store) {
|
97 |
+
if (!$helper->isEnabled($store->getId())
|
98 |
+
|| !$helper->newTransactionViaApiEnabled($store->getId())
|
99 |
+
) {
|
100 |
+
continue;
|
101 |
+
}
|
102 |
+
$storeIds[] = $store->getId();
|
103 |
+
}
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
+
return $storeIds;
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* @return KProject_ShareASale_Model_Mysql4_Orders_Collection
|
112 |
+
*/
|
113 |
+
private function getFailedOrders()
|
114 |
+
{
|
115 |
+
$storeIds = $this->getStoreIds();
|
116 |
+
$collection = Mage::getModel('kproject_sas/orders')
|
117 |
+
->getCollection()
|
118 |
+
->addFieldToFilter(
|
119 |
+
'api_status',
|
120 |
+
array(
|
121 |
+
'in' => array(
|
122 |
+
KProject_ShareASale_Helper_Status::STATUS_SAS_ERROR,
|
123 |
+
KProject_ShareASale_Helper_Status::STATUS_MAGE_ERROR
|
124 |
+
)
|
125 |
+
)
|
126 |
+
);
|
127 |
+
$collection
|
128 |
+
->getSelect()
|
129 |
+
->join(array('mage_order' => 'sales_flat_order'), 'mage_order.increment_id = order_number')
|
130 |
+
->where('mage_order.store_id', array('in' => $storeIds));
|
131 |
+
|
132 |
+
return $collection;
|
133 |
+
}
|
134 |
+
}
|
app/code/community/KProject/ShareASale/Model/Mysql4/Orders.php
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Model_Mysql4_Orders extends Mage_Core_Model_Mysql4_Abstract
|
22 |
+
{
|
23 |
+
protected function _construct()
|
24 |
+
{
|
25 |
+
$this->_init('kproject_sas/orders', 'id');
|
26 |
+
}
|
27 |
+
}
|
app/code/community/KProject/ShareASale/Model/Mysql4/Orders/Collection.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Model_Mysql4_Orders_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
22 |
+
{
|
23 |
+
|
24 |
+
public function _construct()
|
25 |
+
{
|
26 |
+
$this->_init('kproject_sas/orders');
|
27 |
+
}
|
28 |
+
}
|
app/code/community/KProject/ShareASale/Model/Observer.php
ADDED
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Model_Observer
|
22 |
+
{
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Send new order transaction to the API
|
26 |
+
*
|
27 |
+
* @param Varien_Event_Observer $observer
|
28 |
+
*
|
29 |
+
* @return $this
|
30 |
+
*/
|
31 |
+
public function newOrderTransaction(Varien_Event_Observer $observer)
|
32 |
+
{
|
33 |
+
/** @var Mage_Sales_Model_Order $magentoOrder */
|
34 |
+
$magentoOrder = $observer->getEvent()->getData('order');
|
35 |
+
$parameters = Mage::getSingleton('kproject_sas/session')->getParameters();
|
36 |
+
|
37 |
+
if (!$magentoOrder
|
38 |
+
|| Mage::registry('kproject_sas_observer_disable')
|
39 |
+
|| !Mage::helper('kproject_sas')->newTransactionViaApiEnabled($magentoOrder->getStoreId())
|
40 |
+
|| empty($parameters)
|
41 |
+
|| $this->isCheckout()
|
42 |
+
) {
|
43 |
+
return $this;
|
44 |
+
}
|
45 |
+
|
46 |
+
$response = $this->getTransactionHelper()->create($magentoOrder);
|
47 |
+
Mage::helper('kproject_sas/status')->setKOrderStatus(
|
48 |
+
$magentoOrder,
|
49 |
+
KProject_ShareASale_Helper_Status::STATUS_SUCCESS,
|
50 |
+
$response
|
51 |
+
);
|
52 |
+
|
53 |
+
return $this;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* @param Varien_Event_Observer $observer
|
58 |
+
*
|
59 |
+
* @return $this
|
60 |
+
*/
|
61 |
+
public function refundOrderTransaction(Varien_Event_Observer $observer)
|
62 |
+
{
|
63 |
+
/** @var Mage_Sales_Model_Order_Creditmemo $creditMemo */
|
64 |
+
$creditMemo = $observer->getData('creditmemo');
|
65 |
+
|
66 |
+
if (!$creditMemo || Mage::registry('kproject_sas_observer_disable')) {
|
67 |
+
return $this;
|
68 |
+
}
|
69 |
+
|
70 |
+
$magentoOrder = $creditMemo->getOrder();
|
71 |
+
if ($this->isFullCancellation($magentoOrder)) {
|
72 |
+
$response = $this->getTransactionHelper()->void($magentoOrder);
|
73 |
+
$status = KProject_ShareASale_Helper_Status::STATUS_FULL_REFUND;
|
74 |
+
} else {
|
75 |
+
$response = $this->getTransactionHelper()->edit($magentoOrder);
|
76 |
+
$status = KProject_ShareASale_Helper_Status::STATUS_PARTIAL_REFUND;
|
77 |
+
}
|
78 |
+
Mage::helper('kproject_sas/status')->setKOrderStatus($magentoOrder, $status, $response);
|
79 |
+
|
80 |
+
return $this;
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Helper that saves the GET params into session to be pulled
|
85 |
+
* later when an order is placed. Can be rewritten easily
|
86 |
+
* with newer values.
|
87 |
+
*
|
88 |
+
* @note This is a helper observer that will not ship with
|
89 |
+
* the initial version as that version was meant to
|
90 |
+
* utilize the script tag on the success page instead
|
91 |
+
* of the new transaction API
|
92 |
+
*
|
93 |
+
* @param Varien_Event_Observer $observer
|
94 |
+
*
|
95 |
+
* @return $this
|
96 |
+
*/
|
97 |
+
public function setParameters(Varien_Event_Observer $observer)
|
98 |
+
{
|
99 |
+
if (!Mage::helper('kproject_sas')->newTransactionViaApiEnabled()
|
100 |
+
|| Mage::app()->getStore()->isAdmin()
|
101 |
+
) {
|
102 |
+
return $this;
|
103 |
+
}
|
104 |
+
|
105 |
+
/** @var Mage_Core_Controller_Request_Http $request */
|
106 |
+
$request = $observer->getData('controller_action')->getRequest();
|
107 |
+
$userKey = $this->getTransactionHelper()->getAffiliateIdentifierKey();
|
108 |
+
$clickKey = $this->getTransactionHelper()->getClickIdentifierKey();
|
109 |
+
$userId = $request->getParam($userKey);
|
110 |
+
$clickId = $request->getParam($clickKey);
|
111 |
+
|
112 |
+
if ($userId && $clickId) {
|
113 |
+
Mage::getSingleton('kproject_sas/session')->setParameters(
|
114 |
+
array(
|
115 |
+
$userKey => $userId,
|
116 |
+
$clickKey => $clickId
|
117 |
+
)
|
118 |
+
);
|
119 |
+
}
|
120 |
+
|
121 |
+
return $this;
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Checks if it's a full cancellation of the order
|
126 |
+
* or a partial one
|
127 |
+
* - All product qty's were refunded
|
128 |
+
* - Amount refunded >= affiliate amount
|
129 |
+
*
|
130 |
+
* @param Mage_Sales_Model_Order $order
|
131 |
+
*
|
132 |
+
* @return bool
|
133 |
+
*/
|
134 |
+
private function isFullCancellation(Mage_Sales_Model_Order $order)
|
135 |
+
{
|
136 |
+
$qtyCancelled = 0;
|
137 |
+
$orderItems = $order->getItemsCollection();
|
138 |
+
/** @var Mage_Sales_Model_Order_Item $orderItem */
|
139 |
+
foreach ($orderItems as $orderItem) {
|
140 |
+
if ($orderItem->getProductType() != Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
|
141 |
+
&& $orderItem->getQtyCanceled() + $orderItem->getQtyRefunded() > 0
|
142 |
+
&& !$orderItem->getIsVirtual()
|
143 |
+
) {
|
144 |
+
$qtyCancelled += intval($orderItem->getQtyCanceled()) + intval($orderItem->getQtyRefunded());
|
145 |
+
}
|
146 |
+
}
|
147 |
+
|
148 |
+
$quantityRefunded = $qtyCancelled == $order->getTotalQtyOrdered();
|
149 |
+
$amountRefunded = $order->getTotalRefunded() >= ($order->getSubtotal() + $order->getDiscountAmount());
|
150 |
+
|
151 |
+
return $quantityRefunded && $amountRefunded;
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Checks if current observer is firing
|
156 |
+
* from the checkout page
|
157 |
+
*
|
158 |
+
* @return bool
|
159 |
+
*/
|
160 |
+
private function isCheckout()
|
161 |
+
{
|
162 |
+
return strpos(Mage::app()->getRequest()->getRequestUri(), 'saveOrder') !== false;
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* @return KProject_ShareASale_Helper_Transaction
|
167 |
+
*/
|
168 |
+
private function getTransactionHelper()
|
169 |
+
{
|
170 |
+
return Mage::helper('kproject_sas/transaction');
|
171 |
+
}
|
172 |
+
}
|
app/code/community/KProject/ShareASale/Model/Orders.php
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*
|
21 |
+
* @method string getId()
|
22 |
+
* @method KProject_ShareASale_Model_Orders setId($int_id)
|
23 |
+
* @method string getOrderNumber()
|
24 |
+
* @method KProject_ShareASale_Model_Orders setOrderNumber($str_order_number)
|
25 |
+
* @method int getApiStatus()
|
26 |
+
* @method KProject_ShareASale_Model_Orders setApiStatus($int_status)
|
27 |
+
* @method string getErrorCode()
|
28 |
+
* @method int getRetryCount()
|
29 |
+
* @method KProject_ShareASale_Model_Orders setRetryCount($int_retry_count)
|
30 |
+
*/
|
31 |
+
class KProject_ShareASale_Model_Orders extends Mage_Core_Model_Abstract
|
32 |
+
{
|
33 |
+
const MAX_RETRY_COUNT = 5;
|
34 |
+
|
35 |
+
protected function _construct()
|
36 |
+
{
|
37 |
+
$this->_init('kproject_sas/orders');
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Helps set the parameters with serializing
|
42 |
+
* if needed
|
43 |
+
*
|
44 |
+
* @param array | string $parameters
|
45 |
+
*
|
46 |
+
* @return $this
|
47 |
+
*/
|
48 |
+
public function setParameters($parameters)
|
49 |
+
{
|
50 |
+
if (empty($parameters)) {
|
51 |
+
return $this;
|
52 |
+
} elseif (is_array($parameters)) {
|
53 |
+
$parameters = Zend_Serializer::serialize($parameters);
|
54 |
+
}
|
55 |
+
$this->setData('parameters', $parameters);
|
56 |
+
|
57 |
+
return $this;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* If parameters are set, then it returns
|
62 |
+
* an un-serialized array
|
63 |
+
*
|
64 |
+
* @return array
|
65 |
+
* @throws Zend_Serializer_Exception
|
66 |
+
*/
|
67 |
+
public function getParameters()
|
68 |
+
{
|
69 |
+
$parameters = $this->getData('parameters');
|
70 |
+
|
71 |
+
if (!empty($parameters)) {
|
72 |
+
$parameters = Zend_Serializer::unserialize($parameters);
|
73 |
+
} else {
|
74 |
+
$parameters = array();
|
75 |
+
}
|
76 |
+
|
77 |
+
return $parameters;
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* @param int $errorCode
|
82 |
+
*
|
83 |
+
* @return $this
|
84 |
+
*/
|
85 |
+
public function setErrorCode($errorCode)
|
86 |
+
{
|
87 |
+
if ($errorCode) {
|
88 |
+
$this->setData('error_code', $errorCode);
|
89 |
+
}
|
90 |
+
|
91 |
+
return $this;
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Increment retry counter by one
|
96 |
+
*
|
97 |
+
* @return $this
|
98 |
+
*/
|
99 |
+
public function incrementRetryCount()
|
100 |
+
{
|
101 |
+
$count = $this->getRetryCount();
|
102 |
+
$count++;
|
103 |
+
$this->setRetryCount($count);
|
104 |
+
|
105 |
+
return $this;
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Removes entry if max retry attempts
|
110 |
+
* were reached
|
111 |
+
*
|
112 |
+
* @return bool
|
113 |
+
*/
|
114 |
+
public function removeOnTooManyRetries()
|
115 |
+
{
|
116 |
+
if ($this->getRetryCount() >= self::MAX_RETRY_COUNT) {
|
117 |
+
$this->delete();
|
118 |
+
|
119 |
+
return true;
|
120 |
+
}
|
121 |
+
|
122 |
+
return false;
|
123 |
+
}
|
124 |
+
}
|
app/code/community/KProject/ShareASale/Model/Session.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Model_Session extends Mage_Core_Model_Session_Abstract
|
22 |
+
{
|
23 |
+
const KEY = 'kproject_parameters';
|
24 |
+
|
25 |
+
public function __construct()
|
26 |
+
{
|
27 |
+
$this->init('kproject_sas');
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* @return array
|
32 |
+
*/
|
33 |
+
public function getParameters()
|
34 |
+
{
|
35 |
+
$params = $this->getData(self::KEY);
|
36 |
+
|
37 |
+
if (empty($params)) {
|
38 |
+
$params = array();
|
39 |
+
}
|
40 |
+
|
41 |
+
return $params;
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* @param array $parameters
|
46 |
+
*
|
47 |
+
* @return Varien_Object
|
48 |
+
*/
|
49 |
+
public function setParameters($parameters)
|
50 |
+
{
|
51 |
+
return $this->setData(self::KEY, $parameters);
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* @return Varien_Object
|
56 |
+
*/
|
57 |
+
public function unsetParameters()
|
58 |
+
{
|
59 |
+
return $this->unsetData(self::KEY);
|
60 |
+
}
|
61 |
+
}
|
app/code/community/KProject/ShareASale/etc/adminhtml.xml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<acl>
|
4 |
+
<resources>
|
5 |
+
<admin>
|
6 |
+
<children>
|
7 |
+
<system>
|
8 |
+
<children>
|
9 |
+
<config>
|
10 |
+
<children>
|
11 |
+
<kproject_sas translate="title" module="kproject_sas">
|
12 |
+
<title>KProject: ShareASale</title>
|
13 |
+
<sort_order>200</sort_order>
|
14 |
+
</kproject_sas>
|
15 |
+
</children>
|
16 |
+
</config>
|
17 |
+
</children>
|
18 |
+
</system>
|
19 |
+
</children>
|
20 |
+
</admin>
|
21 |
+
</resources>
|
22 |
+
</acl>
|
23 |
+
</config>
|
app/code/community/KProject/ShareASale/etc/config.xml
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<KProject_ShareASale>
|
5 |
+
<version>1.0.0</version>
|
6 |
+
</KProject_ShareASale>
|
7 |
+
</modules>
|
8 |
+
<global>
|
9 |
+
<blocks>
|
10 |
+
<kproject_sas>
|
11 |
+
<class>KProject_ShareASale_Block</class>
|
12 |
+
</kproject_sas>
|
13 |
+
</blocks>
|
14 |
+
<helpers>
|
15 |
+
<kproject_sas>
|
16 |
+
<class>KProject_ShareASale_Helper</class>
|
17 |
+
</kproject_sas>
|
18 |
+
</helpers>
|
19 |
+
<models>
|
20 |
+
<kproject_sas>
|
21 |
+
<class>KProject_ShareASale_Model</class>
|
22 |
+
<resourceModel>kproject_sas_mysql4</resourceModel>
|
23 |
+
</kproject_sas>
|
24 |
+
<kproject_sas_mysql4>
|
25 |
+
<class>KProject_ShareASale_Model_Mysql4</class>
|
26 |
+
<entities>
|
27 |
+
<orders>
|
28 |
+
<table>kproject_sas_orders</table>
|
29 |
+
</orders>
|
30 |
+
</entities>
|
31 |
+
</kproject_sas_mysql4>
|
32 |
+
</models>
|
33 |
+
<resources>
|
34 |
+
<kproject_sas_setup>
|
35 |
+
<setup>
|
36 |
+
<module>KProject_ShareASale</module>
|
37 |
+
</setup>
|
38 |
+
<connection>
|
39 |
+
<use>core_setup</use>
|
40 |
+
</connection>
|
41 |
+
</kproject_sas_setup>
|
42 |
+
<shareasale_write>
|
43 |
+
<connection>
|
44 |
+
<use>core_write</use>
|
45 |
+
</connection>
|
46 |
+
</shareasale_write>
|
47 |
+
<shareasale_read>
|
48 |
+
<connection>
|
49 |
+
<use>core_read</use>
|
50 |
+
</connection>
|
51 |
+
</shareasale_read>
|
52 |
+
</resources>
|
53 |
+
<events>
|
54 |
+
<sales_order_place_after>
|
55 |
+
<observers>
|
56 |
+
<kproject_shareasale_new_order>
|
57 |
+
<type>singleton</type>
|
58 |
+
<class>kproject_sas/observer</class>
|
59 |
+
<method>newOrderTransaction</method>
|
60 |
+
</kproject_shareasale_new_order>
|
61 |
+
</observers>
|
62 |
+
</sales_order_place_after>
|
63 |
+
<sales_order_creditmemo_refund>
|
64 |
+
<observers>
|
65 |
+
<kproject_shareasale_refund_order>
|
66 |
+
<type>singleton</type>
|
67 |
+
<class>kproject_sas/observer</class>
|
68 |
+
<method>refundOrderTransaction</method>
|
69 |
+
</kproject_shareasale_refund_order>
|
70 |
+
</observers>
|
71 |
+
</sales_order_creditmemo_refund>
|
72 |
+
</events>
|
73 |
+
</global>
|
74 |
+
<frontend>
|
75 |
+
<layout>
|
76 |
+
<updates>
|
77 |
+
<kproject_sas>
|
78 |
+
<file>kproject/sas/checkout.xml</file>
|
79 |
+
</kproject_sas>
|
80 |
+
</updates>
|
81 |
+
</layout>
|
82 |
+
<!--<events>
|
83 |
+
<controller_action_predispatch>
|
84 |
+
<observers>
|
85 |
+
<kproject_shareasale_set_params>
|
86 |
+
<type>singleton</type>
|
87 |
+
<class>kproject_sas/observer</class>
|
88 |
+
<method>setParameters</method>
|
89 |
+
</kproject_shareasale_set_params>
|
90 |
+
</observers>
|
91 |
+
</controller_action_predispatch>
|
92 |
+
</events>-->
|
93 |
+
</frontend>
|
94 |
+
<default>
|
95 |
+
<kproject_sas>
|
96 |
+
<api_new>
|
97 |
+
<enabled>0</enabled>
|
98 |
+
<affiliate_key>userID</affiliate_key>
|
99 |
+
<click_key>sscid</click_key>
|
100 |
+
</api_new>
|
101 |
+
</kproject_sas>
|
102 |
+
</default>
|
103 |
+
<crontab>
|
104 |
+
<jobs>
|
105 |
+
<shareasale_submit_failed_transactions>
|
106 |
+
<schedule>
|
107 |
+
<cron_expr>0 2 * * *</cron_expr><!-- Every day at 2 am -->
|
108 |
+
</schedule>
|
109 |
+
<run>
|
110 |
+
<model>kproject_sas/cron::submitFailedTransactions</model>
|
111 |
+
</run>
|
112 |
+
</shareasale_submit_failed_transactions>
|
113 |
+
<shareasale_remove_successful_transactions>
|
114 |
+
<schedule>
|
115 |
+
<cron_expr>0 2 * * 6</cron_expr><!-- Saturday at 2am -->
|
116 |
+
</schedule>
|
117 |
+
<run>
|
118 |
+
<model>kproject_sas/cron::deleteSuccessfulTransactions</model>
|
119 |
+
</run>
|
120 |
+
</shareasale_remove_successful_transactions>
|
121 |
+
</jobs>
|
122 |
+
</crontab>
|
123 |
+
</config>
|
app/code/community/KProject/ShareASale/etc/system.xml
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<tabs>
|
4 |
+
<kproject translate="label" module="kproject_sas">
|
5 |
+
<label>KProject</label>
|
6 |
+
<sort_order>200</sort_order>
|
7 |
+
</kproject>
|
8 |
+
</tabs>
|
9 |
+
<sections>
|
10 |
+
<kproject_sas translate="label" module="kproject_sas">
|
11 |
+
<label>ShareASale</label>
|
12 |
+
<tab>kproject</tab>
|
13 |
+
<frontend_type>text</frontend_type>
|
14 |
+
<sort_order>100</sort_order>
|
15 |
+
<show_in_default>1</show_in_default>
|
16 |
+
<show_in_website>1</show_in_website>
|
17 |
+
<show_in_store>1</show_in_store>
|
18 |
+
<groups>
|
19 |
+
<general translate="label">
|
20 |
+
<label>General</label>
|
21 |
+
<frontend_type>text</frontend_type>
|
22 |
+
<sort_order>10</sort_order>
|
23 |
+
<show_in_default>1</show_in_default>
|
24 |
+
<show_in_website>1</show_in_website>
|
25 |
+
<show_in_store>1</show_in_store>
|
26 |
+
<expanded>1</expanded>
|
27 |
+
<fields>
|
28 |
+
<enabled translate="label">
|
29 |
+
<label>Enabled</label>
|
30 |
+
<frontend_type>select</frontend_type>
|
31 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
32 |
+
<sort_order>10</sort_order>
|
33 |
+
<show_in_default>1</show_in_default>
|
34 |
+
<show_in_website>1</show_in_website>
|
35 |
+
<show_in_store>1</show_in_store>
|
36 |
+
</enabled>
|
37 |
+
<merchant_id translate="label">
|
38 |
+
<label>Merchant ID</label>
|
39 |
+
<frontend_type>text</frontend_type>
|
40 |
+
<sort_order>20</sort_order>
|
41 |
+
<show_in_default>1</show_in_default>
|
42 |
+
<show_in_website>1</show_in_website>
|
43 |
+
<show_in_store>1</show_in_store>
|
44 |
+
<comment>Your ShareASale merchant ID number</comment>
|
45 |
+
</merchant_id>
|
46 |
+
</fields>
|
47 |
+
</general>
|
48 |
+
<api translate="label">
|
49 |
+
<label>API (General)</label>
|
50 |
+
<frontend_type>text</frontend_type>
|
51 |
+
<sort_order>20</sort_order>
|
52 |
+
<show_in_default>1</show_in_default>
|
53 |
+
<show_in_website>1</show_in_website>
|
54 |
+
<show_in_store>1</show_in_store>
|
55 |
+
<comment><![CDATA[ Allows new transaction recording as well as full & partial refunds ]]></comment>
|
56 |
+
<expanded>1</expanded>
|
57 |
+
<fields>
|
58 |
+
<token translate="label">
|
59 |
+
<label>Token</label>
|
60 |
+
<frontend_type>obscure</frontend_type>
|
61 |
+
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
|
62 |
+
<sort_order>30</sort_order>
|
63 |
+
<show_in_default>1</show_in_default>
|
64 |
+
<show_in_website>1</show_in_website>
|
65 |
+
<show_in_store>1</show_in_store>
|
66 |
+
<comment>Found listed at Tools >> Merchant API</comment>
|
67 |
+
</token>
|
68 |
+
<secret_key translate="label">
|
69 |
+
<label>Secret Key</label>
|
70 |
+
<frontend_type>obscure</frontend_type>
|
71 |
+
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
|
72 |
+
<sort_order>40</sort_order>
|
73 |
+
<show_in_default>1</show_in_default>
|
74 |
+
<show_in_website>1</show_in_website>
|
75 |
+
<show_in_store>1</show_in_store>
|
76 |
+
<comment>Found listed at Tools >> Merchant API</comment>
|
77 |
+
</secret_key>
|
78 |
+
</fields>
|
79 |
+
</api>
|
80 |
+
<api_new translate="label">
|
81 |
+
<label>API (New Transactions)</label>
|
82 |
+
<frontend_type>text</frontend_type>
|
83 |
+
<sort_order>30</sort_order>
|
84 |
+
<show_in_default>1</show_in_default>
|
85 |
+
<show_in_website>1</show_in_website>
|
86 |
+
<show_in_store>1</show_in_store>
|
87 |
+
<comment>This is for special case usage to integrate with 3rd party plugins.
|
88 |
+
Please consult ShareASale if you feel like you need this feature.</comment>
|
89 |
+
<expanded>0</expanded>
|
90 |
+
<fields>
|
91 |
+
<enabled translate="label">
|
92 |
+
<label>Enabled</label>
|
93 |
+
<frontend_type>select</frontend_type>
|
94 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
95 |
+
<sort_order>10</sort_order>
|
96 |
+
<show_in_default>1</show_in_default>
|
97 |
+
<show_in_website>1</show_in_website>
|
98 |
+
<show_in_store>1</show_in_store>
|
99 |
+
<comment>Recommended to keep this at No as you will need ShareASale to enable this</comment>
|
100 |
+
<tooltip>Enables 3rd party plugins to make ShareASale new transaction API calls</tooltip>
|
101 |
+
</enabled>
|
102 |
+
<affiliate_key translate="label">
|
103 |
+
<label>Affiliate ID key</label>
|
104 |
+
<frontend_type>text</frontend_type>
|
105 |
+
<sort_order>20</sort_order>
|
106 |
+
<show_in_default>1</show_in_default>
|
107 |
+
<show_in_website>1</show_in_website>
|
108 |
+
<show_in_store>1</show_in_store>
|
109 |
+
<comment>This custom key will need to be requested from ShareASale</comment>
|
110 |
+
</affiliate_key>
|
111 |
+
<click_key translate="label">
|
112 |
+
<label>Click-through ID key</label>
|
113 |
+
<frontend_type>text</frontend_type>
|
114 |
+
<sort_order>30</sort_order>
|
115 |
+
<show_in_default>1</show_in_default>
|
116 |
+
<show_in_website>1</show_in_website>
|
117 |
+
<show_in_store>1</show_in_store>
|
118 |
+
<comment>This custom key will need to be requested from ShareASale</comment>
|
119 |
+
</click_key>
|
120 |
+
</fields>
|
121 |
+
</api_new>
|
122 |
+
</groups>
|
123 |
+
</kproject_sas>
|
124 |
+
</sections>
|
125 |
+
</config>
|
app/code/community/KProject/ShareASale/sql/kproject_sas_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* This program is free software: you can redistribute it and/or modify
|
4 |
+
* it under the terms of the GNU General Public License as published by
|
5 |
+
* the Free Software Foundation, either version 3 of the License, or
|
6 |
+
* (at your option) any later version.
|
7 |
+
*
|
8 |
+
* This program is distributed in the hope that it will be useful,
|
9 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11 |
+
* GNU General Public License for more details.
|
12 |
+
*
|
13 |
+
* You should have received a copy of the GNU General Public License
|
14 |
+
* along with this program. If not, see the license tag below.
|
15 |
+
*
|
16 |
+
* @author KProject <support@kproject.pro>
|
17 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
18 |
+
* @copyright 2016 KProject.pro
|
19 |
+
*
|
20 |
+
* @var $installer Mage_Core_Model_Resource_Setup
|
21 |
+
*/
|
22 |
+
$installer = $this;
|
23 |
+
$installer->startSetup();
|
24 |
+
$table = $installer->getConnection()
|
25 |
+
->newTable($installer->getTable('kproject_sas/orders'))
|
26 |
+
->addColumn(
|
27 |
+
'id',
|
28 |
+
Varien_Db_Ddl_Table::TYPE_INTEGER,
|
29 |
+
null,
|
30 |
+
array(
|
31 |
+
'identity' => true,
|
32 |
+
'unsigned' => false,
|
33 |
+
'nullable' => false,
|
34 |
+
'primary' => true,
|
35 |
+
),
|
36 |
+
'Unique identifier'
|
37 |
+
)
|
38 |
+
->addColumn(
|
39 |
+
'order_number',
|
40 |
+
Varien_Db_Ddl_Table::TYPE_INTEGER,
|
41 |
+
null,
|
42 |
+
array(),
|
43 |
+
'Mage Order Increment ID'
|
44 |
+
)
|
45 |
+
->addColumn(
|
46 |
+
'parameters',
|
47 |
+
Varien_Db_Ddl_Table::TYPE_TEXT,
|
48 |
+
1000,
|
49 |
+
array(),
|
50 |
+
'Parameters passed'
|
51 |
+
)
|
52 |
+
->addColumn(
|
53 |
+
'api_status',
|
54 |
+
Varien_Db_Ddl_Table::TYPE_TINYINT,
|
55 |
+
2,
|
56 |
+
array(),
|
57 |
+
'Status'
|
58 |
+
)
|
59 |
+
->addColumn(
|
60 |
+
'error_code',
|
61 |
+
Varien_Db_Ddl_Table::TYPE_SMALLINT,
|
62 |
+
null,
|
63 |
+
array(),
|
64 |
+
'API error code'
|
65 |
+
)
|
66 |
+
->addColumn(
|
67 |
+
'retry_count',
|
68 |
+
Varien_Db_Ddl_Table::TYPE_TINYINT,
|
69 |
+
3,
|
70 |
+
array(
|
71 |
+
'default' => 0
|
72 |
+
),
|
73 |
+
'# of resend attempts'
|
74 |
+
);
|
75 |
+
|
76 |
+
if (!$installer->getConnection()->isTableExists($table->getName())) {
|
77 |
+
$installer->getConnection()->createTable($table);
|
78 |
+
}
|
79 |
+
|
80 |
+
$installer->endSetup();
|
app/design/frontend/base/default/layout/kproject/sas/checkout.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<layout>
|
3 |
+
<checkout_onepage_success>
|
4 |
+
<reference name="before_body_end">
|
5 |
+
<block type="kproject_sas/pixel" name="kproject.sas.pixel" template="kproject/sas/pixel.phtml" />
|
6 |
+
</reference>
|
7 |
+
</checkout_onepage_success>
|
8 |
+
</layout>
|
app/design/frontend/base/default/template/kproject/sas/pixel.phtml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
*This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*
|
21 |
+
* @var KProject_ShareASale_Block_Pixel $this
|
22 |
+
*/
|
23 |
+
echo $this->printPixel();
|
app/etc/modules/KProject_ShareASale.xml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<KProject_ShareASale>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
<version>0.1.0</version>
|
8 |
+
</KProject_ShareASale>
|
9 |
+
</modules>
|
10 |
+
</config>
|
lib/KProject/ShareASale/Api.php
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Api
|
22 |
+
{
|
23 |
+
|
24 |
+
const API_VERSION = 2.8;
|
25 |
+
const ACTION_NEW = 'new';
|
26 |
+
const ACTION_VOID = 'void';
|
27 |
+
const ACTION_EDIT = 'edit';
|
28 |
+
|
29 |
+
/** @var KProject_ShareASale_Credentials */
|
30 |
+
private $credentials;
|
31 |
+
|
32 |
+
public function __construct(KProject_ShareASale_Credentials $credentials)
|
33 |
+
{
|
34 |
+
$this->credentials = $credentials;
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Creates a new ShareASale API transaction
|
39 |
+
*
|
40 |
+
* @param Mage_Sales_Model_Order $order
|
41 |
+
* @param array $params - optional extra params that can rewrite the originals
|
42 |
+
*
|
43 |
+
* @return Zend_Http_Response
|
44 |
+
*/
|
45 |
+
public function createNewTransaction(Mage_Sales_Model_Order $order, $params = array())
|
46 |
+
{
|
47 |
+
$action = self::ACTION_NEW;
|
48 |
+
$queryParams = $this->getTransactionHelper()->getNewTransactionParams($order);
|
49 |
+
$queryParams = array_merge($queryParams, $params);
|
50 |
+
|
51 |
+
$client = $this->getBaseClientSetup($action);
|
52 |
+
$client->getUri()->addReplaceQueryParameters($queryParams);
|
53 |
+
|
54 |
+
return $client->request();
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* @param Mage_Sales_Model_Order $order
|
59 |
+
* @param array $params - optional extra params that can rewrite the originals
|
60 |
+
*
|
61 |
+
* @return Zend_Http_Response
|
62 |
+
*/
|
63 |
+
public function voidTransaction(Mage_Sales_Model_Order $order, $params = array())
|
64 |
+
{
|
65 |
+
$action = self::ACTION_VOID;
|
66 |
+
$queryParams = array(
|
67 |
+
'date' => $this->getOrderDate($order),
|
68 |
+
'ordernumber' => $order->getIncrementId(),
|
69 |
+
'reason' => 'Full Refund'
|
70 |
+
);
|
71 |
+
$queryParams = array_merge($queryParams, $params);
|
72 |
+
|
73 |
+
$client = $this->getBaseClientSetup($action);
|
74 |
+
$client->getUri()->addReplaceQueryParameters($queryParams);
|
75 |
+
|
76 |
+
return $client->request();
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* @param Mage_Sales_Model_Order $kOrder
|
81 |
+
* @param array $params - optional extra params that can rewrite the originals
|
82 |
+
*
|
83 |
+
* @return Zend_Http_Response
|
84 |
+
*/
|
85 |
+
public function editTransaction(Mage_Sales_Model_Order $order, $params = array())
|
86 |
+
{
|
87 |
+
$action = self::ACTION_EDIT;
|
88 |
+
$queryParams = array(
|
89 |
+
'date' => $this->getOrderDate($order),
|
90 |
+
'ordernumber' => $order->getIncrementId(),
|
91 |
+
'newamount' => $order->getGrandTotal() - $order->getTotalRefunded(),
|
92 |
+
'newcomment' => 'Partial Refund'
|
93 |
+
);
|
94 |
+
$queryParams = array_merge($queryParams, $params);
|
95 |
+
|
96 |
+
$client = $this->getBaseClientSetup($action);
|
97 |
+
$client->getUri()->addReplaceQueryParameters($queryParams);
|
98 |
+
|
99 |
+
return $client->request();
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* @param string $action
|
104 |
+
*
|
105 |
+
* @return Zend_Http_Client
|
106 |
+
*/
|
107 |
+
protected function getBaseClientSetup($action)
|
108 |
+
{
|
109 |
+
$client = $this->getZendClient();
|
110 |
+
$uri =
|
111 |
+
'https://api.shareasale.com/w.cfm' .
|
112 |
+
'?merchantId=' . $this->credentials->getMerchantId() .
|
113 |
+
'&token=' . $this->credentials->getToken() .
|
114 |
+
'&version=' . self::API_VERSION .
|
115 |
+
'&action=' . $action;
|
116 |
+
|
117 |
+
return $client
|
118 |
+
->setHeaders('x-ShareASale-Date', $this->getTimeStamp())
|
119 |
+
->setHeaders('x-ShareASale-Authentication', $this->getSignature($action))
|
120 |
+
->setMethod()
|
121 |
+
->setUri($uri);
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Returns the signature to pass in the
|
126 |
+
* header for authentication purposes
|
127 |
+
*
|
128 |
+
* @param string $actionVerb
|
129 |
+
*
|
130 |
+
* @return string
|
131 |
+
*/
|
132 |
+
private function getSignature($actionVerb)
|
133 |
+
{
|
134 |
+
$APIToken = $this->credentials->getToken();
|
135 |
+
$APISecretKey = $this->credentials->getSecretKey();
|
136 |
+
$sig = $APIToken . ':' . $this->getTimeStamp() . ':' . $actionVerb . ':' . $APISecretKey;
|
137 |
+
|
138 |
+
return hash('sha256', $sig);
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* @return string
|
143 |
+
*/
|
144 |
+
private function getTimeStamp()
|
145 |
+
{
|
146 |
+
return gmdate(DATE_RFC1123);
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* @return Zend_Http_Client
|
151 |
+
*/
|
152 |
+
public function getZendClient()
|
153 |
+
{
|
154 |
+
return new Zend_Http_Client();
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* @return KProject_ShareASale_Helper_Transaction|Mage_Core_Helper_Abstract
|
159 |
+
*/
|
160 |
+
private function getTransactionHelper()
|
161 |
+
{
|
162 |
+
return Mage::helper('kproject_sas/transaction');
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* @param Mage_Sales_Model_Order $order
|
167 |
+
*
|
168 |
+
* @return string
|
169 |
+
*/
|
170 |
+
private function getOrderDate(Mage_Sales_Model_Order $order)
|
171 |
+
{
|
172 |
+
$date = new Zend_Date($order->getCreatedAtDate());
|
173 |
+
$date->setTimezone('EST5EDT');
|
174 |
+
$orderDate = date('m/d/Y', $date->getTimestamp());
|
175 |
+
|
176 |
+
return $orderDate ? $orderDate : '';
|
177 |
+
}
|
178 |
+
}
|
lib/KProject/ShareASale/Credentials.php
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This program is free software: you can redistribute it and/or modify
|
5 |
+
* it under the terms of the GNU General Public License as published by
|
6 |
+
* the Free Software Foundation, either version 3 of the License, or
|
7 |
+
* (at your option) any later version.
|
8 |
+
*
|
9 |
+
* This program is distributed in the hope that it will be useful,
|
10 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
+
* GNU General Public License for more details.
|
13 |
+
*
|
14 |
+
* You should have received a copy of the GNU General Public License
|
15 |
+
* along with this program. If not, see the license tag below.
|
16 |
+
*
|
17 |
+
* @author KProject <support@kproject.pro>
|
18 |
+
* @license http://www.gnu.org/licenses/ GNU General Public License, version 3
|
19 |
+
* @copyright 2016 KProject.pro
|
20 |
+
*/
|
21 |
+
class KProject_ShareASale_Credentials
|
22 |
+
{
|
23 |
+
/** @var string $token */
|
24 |
+
protected $token;
|
25 |
+
/** @var string $merchantId */
|
26 |
+
protected $merchantId;
|
27 |
+
/** @var string $secretKey */
|
28 |
+
protected $secretKey;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* @param string $token
|
32 |
+
*
|
33 |
+
* @return KProject_ShareASale_Credentials
|
34 |
+
*/
|
35 |
+
public function setToken($token)
|
36 |
+
{
|
37 |
+
$this->token = $token;
|
38 |
+
|
39 |
+
return $this;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @return string
|
44 |
+
*/
|
45 |
+
public function getToken()
|
46 |
+
{
|
47 |
+
return $this->token;
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* @param string $merchantId
|
52 |
+
*
|
53 |
+
* @return KProject_ShareASale_Credentials
|
54 |
+
*/
|
55 |
+
public function setMerchantId($merchantId)
|
56 |
+
{
|
57 |
+
$this->merchantId = $merchantId;
|
58 |
+
|
59 |
+
return $this;
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @return string
|
64 |
+
*/
|
65 |
+
public function getMerchantId()
|
66 |
+
{
|
67 |
+
return $this->merchantId;
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* @param string $secretKey
|
72 |
+
*
|
73 |
+
* @return KProject_ShareASale_Credentials
|
74 |
+
*/
|
75 |
+
public function setSecretKey($secretKey)
|
76 |
+
{
|
77 |
+
$this->secretKey = $secretKey;
|
78 |
+
|
79 |
+
return $this;
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* @return string
|
84 |
+
*/
|
85 |
+
public function getSecretKey()
|
86 |
+
{
|
87 |
+
return $this->secretKey;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* @return array
|
92 |
+
*/
|
93 |
+
public function toArray()
|
94 |
+
{
|
95 |
+
return array(
|
96 |
+
'token' => $this->getToken(),
|
97 |
+
'merchantID' => $this->getMerchantId(),
|
98 |
+
'secret_key' => $this->getSecretKey()
|
99 |
+
);
|
100 |
+
}
|
101 |
+
}
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>KProject_ShareASale</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://www.gnu.org/licenses/">GPL</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>This **unofficial** ShareASale Magento plugin is designed to provide a communication link between Magento and ShareASale affiliate API.</summary>
|
10 |
+
<description>As before, the new transaction recorder is the small image pixel code printed on the order success page. In addition to simplifying the integration process of ShareASale, the main reason for this project is to help with refunds/voiding of transactions using Magento observers. Moreover, the module also allows external plugins to call ShareASale New Transaction API when importing orders.</description>
|
11 |
+
<notes>The initial release version with minimum production test time.</notes>
|
12 |
+
<authors><author><name>Konstantin Kiritsenko</name><user>KProjectPro</user><email>support@kproject.pro</email></author></authors>
|
13 |
+
<date>2016-09-12</date>
|
14 |
+
<time>02:26:36</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="KProject"><dir name="ShareASale"><dir name="Block"><file name="Pixel.php" hash="f09b41c293b2ef169aecca6c1fd26f38"/></dir><dir name="Helper"><file name="Customer.php" hash="37f47b7991c362fa8d4b7627ae2dd58f"/><file name="Data.php" hash="1595213351b5a9bfce9ea082aca480f5"/><file name="Pixel.php" hash="f00d63b35d332c1f38b6853441b634e6"/><file name="Product.php" hash="2e3c2680472d9bb0dc41708651ab7383"/><file name="Status.php" hash="4be217156acd84fc30fa54cfb579769a"/><file name="Transaction.php" hash="42e3c8665d255452efcca9fa8dc7fa82"/></dir><dir name="Model"><file name="Cron.php" hash="1da6b0f9dfb3c5d1a5ac0f1ce5e49527"/><dir name="Mysql4"><dir name="Orders"><file name="Collection.php" hash="b0d1c3ceabe42a5244540f7ab4983dba"/></dir><file name="Orders.php" hash="052729f4247f8f78bc1deef666f9a893"/></dir><file name="Observer.php" hash="eab4e6e431a442953b5dc5b2a6bc63ac"/><file name="Orders.php" hash="c6eed5bd9281c3a1c8cb1b2af5f2691e"/><file name="Session.php" hash="293df8c098782e49ab241f0e45c9f616"/></dir><dir name="etc"><file name="adminhtml.xml" hash="0e7ff0f0bd8b5a7c0f272f9de76a7e90"/><file name="config.xml" hash="8612d42bdfaaedd55fe4586c9ef43ac9"/><file name="system.xml" hash="e7ee62806f4642c662762b9f771e71eb"/></dir><dir name="sql"><dir name="kproject_sas_setup"><file name="mysql4-install-1.0.0.php" hash="3096cc709c1e48006a42d348a60c1753"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="kproject"><dir name="sas"><file name="checkout.xml" hash="7059064fc329f3551e17b59f341b82bc"/></dir></dir></dir><dir name="template"><dir name="kproject"><dir name="sas"><file name="pixel.phtml" hash="283d77b2d847e4293e84e7c177123952"/></dir></dir></dir></dir></dir></dir></target><target name="magelib"><dir name="KProject"><dir name="ShareASale"><file name="Api.php" hash="d9d991a9365897d3442d0b65bbdef6d5"/><file name="Credentials.php" hash="ce6de41de84e3d2384d59418bf6ecd21"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="KProject_ShareASale.xml" hash="bb2b64daa3fda44aec9d71855ab084de"/></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.3.0</min><max>5.6.0</max></php></required></dependencies>
|
18 |
+
</package>
|