Qualityunit_Pap - Version 1.0.7

Version Notes

- paypal integration fix
- HTTP to HTTPS redirection in case of API communication fixed
- API tracking fixed based on new HTTP/HTTPS approach

Download this release

Release Info

Developer Quality Unit, LLC
Extension Qualityunit_Pap
Version 1.0.7
Comparing to
See all releases


Code changes from version 1.0.6 to 1.0.7

app/code/local/Qualityunit/Pap/Model/Config.php CHANGED
@@ -48,13 +48,17 @@ class Qualityunit_Pap_Model_Config extends Mage_Core_Model_Config_Base {
48
  }
49
 
50
  // sanitize the URL
51
- $server = str_replace('https', 'http', $server);
52
  $server = str_replace('http://', '', $server);
53
  if (substr($server,-1) == '/') $server = substr($server,0,-1);
54
 
55
  return $server;
56
  }
57
 
 
 
 
 
58
  public function getTrackingMethod() {
59
  return Mage::getStoreConfig('pap_config/tracking/trackingmethod');
60
  }
48
  }
49
 
50
  // sanitize the URL
51
+ $server = str_replace('https://', 'http://', $server);
52
  $server = str_replace('http://', '', $server);
53
  if (substr($server,-1) == '/') $server = substr($server,0,-1);
54
 
55
  return $server;
56
  }
57
 
58
+ public function getAPIPath() {
59
+ return 'http://'.$this->getInstallationPath().'/scripts/server.php';
60
+ }
61
+
62
  public function getTrackingMethod() {
63
  return Mage::getStoreConfig('pap_config/tracking/trackingmethod');
64
  }
app/code/local/Qualityunit/Pap/Model/Pap.php CHANGED
@@ -1,320 +1,323 @@
1
- <?php
2
- class Qualityunit_Pap_Model_Pap extends Mage_Core_Model_Abstract {
3
- protected $papSession;
4
- public $declined = 'D';
5
- public $pending = 'P';
6
- public $approved = 'A';
7
-
8
- public function getSession() {
9
- if (($this->papSession != '') && ($this->papSession != null)) {
10
- return $this->papSession;
11
- }
12
-
13
- Mage::getSingleton('pap/config')->includePapAPI();
14
- $config = Mage::getSingleton('pap/config');
15
- $url = $config->getInstallationPath().'/scripts/server.php';
16
- $username = $config->getAPICredential('username');
17
- $password = $config->getAPICredential('pass');
18
-
19
- $session = new Gpf_Api_Session($url);
20
- if (!$session->login($username, $password)) {
21
- Mage::log('Postaffiliatepro: Could not initiate API session: '.$session->getMessage());
22
- return null;
23
- }
24
-
25
- $this->papSession = $session;
26
- return $this->papSession;
27
- }
28
-
29
- public function setOrderStatus($order, $status, $refunded = array()) {
30
- Mage::log('Postaffiliatepro: Changing status of order '.$order->getIncrementId()." to '$status'");
31
- $session = $this->getSession();
32
-
33
- if (empty($session)) {
34
- Mage::log('Postaffiliatepro: The module is still not configured!');
35
- return;
36
- }
37
-
38
- $request = new Pap_Api_TransactionsGrid($session);
39
- $request->addFilter('orderid', Gpf_Data_Filter::LIKE, $order->getIncrementId().'(%');
40
- $request->setLimit(0, 900);
41
- try {
42
- $request->sendNow();
43
- $grid = $request->getGrid();
44
- $recordset = $grid->getRecordset();
45
-
46
- $ids = array();
47
- $refundIDs = array();
48
- $approveIDs = array();
49
- foreach($recordset as $record) {
50
- if (count($refunded)) {
51
- if ($status == 'A') {
52
- if (in_array($record->get('productid'), $refunded)) {
53
- $refundIDs[] = $record->get('id');
54
- }
55
- else {
56
- $approveIDs[] = $record->get('id');
57
- }
58
- continue;
59
- }
60
- elseif ($status == 'D') {
61
- if (in_array($record->get('productid'), $refunded)) {
62
- $refundIDs[] = $record->get('id');
63
- }
64
- continue;
65
- }
66
- }
67
- $ids[] = $record->get('id');
68
- }
69
- }
70
- catch (Exception $e) {
71
- Mage::log('An API error while searching for the order with postfix: '.$e->getMessage());
72
- return false;
73
- }
74
-
75
- $transaction = new Pap_Api_Transaction($session);
76
- if (count($refundIDs) == 0 && count($approveIDs) == 0 && count($ids) == 0) {
77
- $items = $order->getAllVisibleItems();
78
- foreach ($items as $i => $item) {
79
- $productid = $item->getProductId();
80
- $product = Mage::getModel('catalog/product')->load($productid);
81
-
82
- $transaction->setOrderID($order->getIncrementId()."($i)");
83
- if ($status == $this->approved) {
84
- if (count($refunded) && in_array($product->getSku(), $refunded)) { // if we are refunding only specific order items
85
- $transaction->declineByOrderId('');
86
- continue;
87
- }
88
- $transaction->approveByOrderId('');
89
- }
90
- if ($status == $this->declined) {
91
- if (count($refunded) && !in_array($product->getSku(), $refunded)) { // if we are refunding only specific order items
92
- continue;
93
- }
94
- $transaction->declineByOrderId('');
95
- }
96
- }
97
- return;
98
- }
99
-
100
- try {
101
- Mage::log('We will be changing status of IDs: '.print_r($ids,true));
102
- $request = new Gpf_Rpc_FormRequest('Pap_Merchants_Transaction_TransactionsForm', 'changeStatus', $session);
103
- if (!empty($refundIDs)) {
104
- $request->addParam('ids',new Gpf_Rpc_Array($refundIDs));
105
- $request->addParam('status','D');
106
- $request->sendNow();
107
- }
108
- if (!empty($approveIDs)) {
109
- $request->addParam('ids',new Gpf_Rpc_Array($approveIDs));
110
- $request->addParam('status','A');
111
- $request->sendNow();
112
- }
113
- $request->addParam('ids',new Gpf_Rpc_Array($ids));
114
- $request->addParam('status',$status);
115
- $request->sendNow();
116
- return true;
117
- }
118
- catch (Exception $e) {
119
- Mage::log('API error while status changing: '.$e->getMessage());
120
- return false;
121
- }
122
- }
123
-
124
- private function getStatus($state) {
125
- if ($state === Mage_Sales_Model_Order::STATE_PENDING_PAYMENT || $state === Mage_Sales_Model_Order::STATE_NEW || $state === Mage_Sales_Model_Order::STATE_PROCESSING) {
126
- return $this->pending;
127
- }
128
- if ($state === Mage_Sales_Model_Order::STATE_COMPLETE) {
129
- return $this->approved;
130
- }
131
- return $this->declined;
132
- }
133
-
134
- public function getOrderSaleDetails($order) {
135
- $config = Mage::getSingleton('pap/config');
136
-
137
- $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
138
- $couponcode = $quote->getCouponCode();
139
-
140
- $sales = array();
141
- $status = $this->getStatus($order->getState());
142
-
143
- if ($config->getPerProduct()) { // per product tracking
144
- $items = $order->getAllVisibleItems();
145
-
146
- foreach($items as $i=>$item) {
147
- $productid = $item->getProductId();
148
- $product = Mage::getModel('catalog/product')->load($productid);
149
-
150
- $sales[$i] = array();
151
- $subtotal = ($item->getBaseRowTotal() == '') ? $item->getBasePrice() : $item->getBaseRowTotal();
152
- $discount = abs($item->getBaseDiscountAmount());
153
-
154
- $sales[$i]['totalcost'] = $subtotal - $discount;
155
- $sales[$i]['orderid'] = $order->getIncrementId();
156
- $sales[$i]['productid'] = $product->getSku();
157
- $sales[$i]['couponcode'] = $couponcode;
158
- $sales[$i]['status'] = $status;
159
-
160
- for ($n = 1; $n < 6; $n++) {
161
- if ($config->getData($n)) {
162
- $sales[$i]['data'.$n] = $this->changeExtraData($config->getData($n), $order, $item, $product);
163
- }
164
- }
165
- }
166
- }
167
- else { // per order tracking
168
- $sales[0] = array();
169
-
170
- $subtotal = $order->getBaseSubtotal();
171
- $discount = abs($order->getBaseDiscountAmount());
172
-
173
- $sales[0]['totalcost'] = $subtotal - $discount;
174
- $sales[0]['orderid'] = $order->getIncrementId();
175
- $sales[0]['productid'] = null;
176
- $sales[0]['couponcode'] = $couponcode;
177
- $sales[0]['status'] = $status;
178
-
179
- for ($n = 1; $n < 6; $n++) {
180
- if ($config->getData($n)) {
181
- $sales[0]['data'.$n] = $this->changeExtraData($config->getData($n), $order, $item, $product);
182
- }
183
- }
184
- }
185
-
186
- return $sales;
187
- }
188
-
189
- public function registerOrderByID($orderid, $realid = true) { // called from the checkout observer
190
- $order = Mage::getModel('sales/order')->load($orderid);
191
- if ($realid) {
192
- $order->load($orderid);
193
- }
194
- else {
195
- $order->loadByIncrementId($orderid);
196
- }
197
-
198
- $this->registerOrder($order);
199
- }
200
-
201
- public function registerOrder($order, $visitorID = '') {
202
- if ($order) {
203
- $orderid = $order->getId();
204
- }
205
- else {
206
- Mage::log('Postaffiliatepro: Order empty');
207
- return false;
208
- }
209
- Mage::log("Postaffiliatepro: Loading details of order $orderid");
210
-
211
- $items = $this->getOrderSaleDetails($order);
212
- $this->registerSaleDetails($items, $visitorID);
213
- }
214
-
215
- public function registerSaleDetails($items, $visitorID = '') {
216
- $config = Mage::getSingleton('pap/config');
217
- $config->includePapAPI();
218
-
219
- $saleTracker = new Pap_Api_SaleTracker($config->getInstallationPath().'/scripts/sale.php');
220
- $saleTracker->setAccountId($config->getAPICredential('account'));
221
- if (!empty($visitorID)) {
222
- $saleTracker->setVisitorId($visitorID);
223
- }
224
-
225
- foreach ($items as $i => $item) {
226
- Mage::log('Postaffiliatepro: Registering sale '.$item['orderid']."($i)");
227
-
228
- $sale = $saleTracker->createSale();
229
- $sale->setTotalCost($item['totalcost']);
230
- $sale->setOrderID($item['orderid']."($i)");
231
- $sale->setProductID($item['productid']);
232
- $sale->setStatus($item['status']);
233
- if ($item['couponcode']) $sale->setCouponCode($item['couponcode']);
234
- if ($item['data1']) $sale->setData1($item['data1']);
235
- if ($item['data2']) $sale->setData2($item['data2']);
236
- if ($item['data3']) $sale->setData3($item['data3']);
237
- if ($item['data4']) $sale->setData4($item['data4']);
238
- if ($item['data5']) $sale->setData5($item['data5']);
239
- }
240
-
241
- $saleTracker->register();
242
- }
243
-
244
- public function changeExtraData($data, $order, $item, $product) {
245
- switch ($data) {
246
- case 'empty':
247
- return null;
248
- break;
249
- case 'itemName':
250
- return (!empty($item)) ? $item->getName() : null;
251
- break;
252
- case 'itemQuantity':
253
- return (!empty($item)) ? $item->getQtyOrdered() : null;
254
- break;
255
- case 'itemPrice':
256
- if (!empty($item)) {
257
- $rowtotal = $item->getBaseRowTotal();
258
- if (empty($rowtotal)) {
259
- return $item->getBasePrice();
260
- }
261
- return $rowtotal;
262
- }
263
- return null;
264
- break;
265
- case 'itemSKU':
266
- return (!empty($item)) ? $item->getSku() : null;
267
- break;
268
- case 'itemWeight':
269
- return (!empty($item)) ? $item->getWeight() : null;
270
- break;
271
- case 'itemWeightAll':
272
- return (!empty($item)) ? $item->getRowWeight() : null;
273
- break;
274
- case 'itemCost':
275
- return (!empty($item)) ? $item->getCost() : null;
276
- break;
277
- case 'itemDiscount':
278
- return (!empty($item)) ? abs($item->getBaseDiscountAmount()) : null;
279
- break;
280
- case 'itemDiscountPercent':
281
- return (!empty($item)) ? $item->getDiscountPercent() : null;
282
- break;
283
- case 'itemTax':
284
- return (!empty($item)) ? $item->getTaxAmount() : null;
285
- break;
286
- case 'itemTaxPercent':
287
- return (!empty($item)) ? $item->getTaxPercent() : null;
288
- break;
289
- case 'productCategoryID':
290
- return (!empty($product)) ? $product->getCategoryId() : null;
291
- break;
292
- case 'productURL':
293
- return (!empty($product)) ? $product->getProductUrl(false) : null;
294
- break;
295
- case 'storeID':
296
- return (!empty($order)) ? $order->getStoreId() : null;
297
- break;
298
- case 'internalOrderID':
299
- return (!empty($order)) ? $order->getId() : null;
300
- break;
301
- case 'customerID':
302
- return (!empty($order) && $order->getCustomerId()) ? $order->getCustomerId() : null;
303
- break;
304
- case 'customerEmail':
305
- return (!empty($order) && $order->getCustomerEmail()) ? $order->getCustomerEmail() : null;
306
- break;
307
- case 'customerName':
308
- $name = '';
309
- if (!empty($order)) {
310
- $name = $order->getCustomerFirstname().' '.$order->getCustomerMiddlename().' '.$order->getCustomerLastname();
311
- }
312
- return (!empty($name)) ? $name : null;
313
- break;
314
- case 'couponCode':
315
- return (!empty($order) && $order->getQuoteId()) ? Mage::getModel('sales/quote')->load($order->getQuoteId())->getCouponCode() : null;
316
- break;
317
- default: return $data;
318
- }
319
- }
320
- }
 
 
 
1
+ <?php
2
+ class Qualityunit_Pap_Model_Pap extends Mage_Core_Model_Abstract {
3
+ protected $papSession;
4
+ public $declined = 'D';
5
+ public $pending = 'P';
6
+ public $approved = 'A';
7
+
8
+ public function getSession() {
9
+ if (($this->papSession != '') && ($this->papSession != null)) {
10
+ return $this->papSession;
11
+ }
12
+
13
+ Mage::getSingleton('pap/config')->includePapAPI();
14
+ $config = Mage::getSingleton('pap/config');
15
+ $url = $config->getAPIPath();
16
+ $username = $config->getAPICredential('username');
17
+ $password = $config->getAPICredential('pass');
18
+
19
+ $session = new Gpf_Api_Session($url);
20
+ if (!$session->login($username, $password)) {
21
+ $session = new Gpf_Api_Session(str_replace('http://','https://',$url));
22
+ if (!$session->login($username, $password)) {
23
+ Mage::log('Postaffiliatepro: Could not initiate API session: '.$session->getMessage());
24
+ return null;
25
+ }
26
+ }
27
+
28
+ $this->papSession = $session;
29
+ return $this->papSession;
30
+ }
31
+
32
+ public function setOrderStatus($order, $status, $refunded = array()) {
33
+ Mage::log('Postaffiliatepro: Changing status of order '.$order->getIncrementId()." to '$status'");
34
+ $session = $this->getSession();
35
+
36
+ if (empty($session)) {
37
+ Mage::log('Postaffiliatepro: The module is still not configured!');
38
+ return;
39
+ }
40
+
41
+ $request = new Pap_Api_TransactionsGrid($session);
42
+ $request->addFilter('orderid', Gpf_Data_Filter::LIKE, $order->getIncrementId().'(%');
43
+ $request->setLimit(0, 900);
44
+ try {
45
+ $request->sendNow();
46
+ $grid = $request->getGrid();
47
+ $recordset = $grid->getRecordset();
48
+
49
+ $ids = array();
50
+ $refundIDs = array();
51
+ $approveIDs = array();
52
+ foreach($recordset as $record) {
53
+ if (count($refunded)) {
54
+ if ($status == 'A') {
55
+ if (in_array($record->get('productid'), $refunded)) {
56
+ $refundIDs[] = $record->get('id');
57
+ }
58
+ else {
59
+ $approveIDs[] = $record->get('id');
60
+ }
61
+ continue;
62
+ }
63
+ elseif ($status == 'D') {
64
+ if (in_array($record->get('productid'), $refunded)) {
65
+ $refundIDs[] = $record->get('id');
66
+ }
67
+ continue;
68
+ }
69
+ }
70
+ $ids[] = $record->get('id');
71
+ }
72
+ }
73
+ catch (Exception $e) {
74
+ Mage::log('An API error while searching for the order with postfix: '.$e->getMessage());
75
+ return false;
76
+ }
77
+
78
+ $transaction = new Pap_Api_Transaction($session);
79
+ if (count($refundIDs) == 0 && count($approveIDs) == 0 && count($ids) == 0) {
80
+ $items = $order->getAllVisibleItems();
81
+ foreach ($items as $i => $item) {
82
+ $productid = $item->getProductId();
83
+ $product = Mage::getModel('catalog/product')->load($productid);
84
+
85
+ $transaction->setOrderID($order->getIncrementId()."($i)");
86
+ if ($status == $this->approved) {
87
+ if (count($refunded) && in_array($product->getSku(), $refunded)) { // if we are refunding only specific order items
88
+ $transaction->declineByOrderId('');
89
+ continue;
90
+ }
91
+ $transaction->approveByOrderId('');
92
+ }
93
+ if ($status == $this->declined) {
94
+ if (count($refunded) && !in_array($product->getSku(), $refunded)) { // if we are refunding only specific order items
95
+ continue;
96
+ }
97
+ $transaction->declineByOrderId('');
98
+ }
99
+ }
100
+ return;
101
+ }
102
+
103
+ try {
104
+ Mage::log('We will be changing status of IDs: '.print_r($ids,true));
105
+ $request = new Gpf_Rpc_FormRequest('Pap_Merchants_Transaction_TransactionsForm', 'changeStatus', $session);
106
+ if (!empty($refundIDs)) {
107
+ $request->addParam('ids',new Gpf_Rpc_Array($refundIDs));
108
+ $request->addParam('status','D');
109
+ $request->sendNow();
110
+ }
111
+ if (!empty($approveIDs)) {
112
+ $request->addParam('ids',new Gpf_Rpc_Array($approveIDs));
113
+ $request->addParam('status','A');
114
+ $request->sendNow();
115
+ }
116
+ $request->addParam('ids',new Gpf_Rpc_Array($ids));
117
+ $request->addParam('status',$status);
118
+ $request->sendNow();
119
+ return true;
120
+ }
121
+ catch (Exception $e) {
122
+ Mage::log('API error while status changing: '.$e->getMessage());
123
+ return false;
124
+ }
125
+ }
126
+
127
+ private function getStatus($state) {
128
+ if ($state === Mage_Sales_Model_Order::STATE_PENDING_PAYMENT || $state === Mage_Sales_Model_Order::STATE_NEW || $state === Mage_Sales_Model_Order::STATE_PROCESSING) {
129
+ return $this->pending;
130
+ }
131
+ if ($state === Mage_Sales_Model_Order::STATE_COMPLETE) {
132
+ return $this->approved;
133
+ }
134
+ return $this->declined;
135
+ }
136
+
137
+ public function getOrderSaleDetails($order) {
138
+ $config = Mage::getSingleton('pap/config');
139
+
140
+ $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
141
+ $couponcode = $quote->getCouponCode();
142
+
143
+ $sales = array();
144
+ $status = $this->getStatus($order->getState());
145
+
146
+ if ($config->getPerProduct()) { // per product tracking
147
+ $items = $order->getAllVisibleItems();
148
+
149
+ foreach($items as $i=>$item) {
150
+ $productid = $item->getProductId();
151
+ $product = Mage::getModel('catalog/product')->load($productid);
152
+
153
+ $sales[$i] = array();
154
+ $subtotal = ($item->getBaseRowTotal() == '') ? $item->getBasePrice() : $item->getBaseRowTotal();
155
+ $discount = abs($item->getBaseDiscountAmount());
156
+
157
+ $sales[$i]['totalcost'] = $subtotal - $discount;
158
+ $sales[$i]['orderid'] = $order->getIncrementId();
159
+ $sales[$i]['productid'] = $product->getSku();
160
+ $sales[$i]['couponcode'] = $couponcode;
161
+ $sales[$i]['status'] = $status;
162
+
163
+ for ($n = 1; $n < 6; $n++) {
164
+ if ($config->getData($n)) {
165
+ $sales[$i]['data'.$n] = $this->changeExtraData($config->getData($n), $order, $item, $product);
166
+ }
167
+ }
168
+ }
169
+ }
170
+ else { // per order tracking
171
+ $sales[0] = array();
172
+
173
+ $subtotal = $order->getBaseSubtotal();
174
+ $discount = abs($order->getBaseDiscountAmount());
175
+
176
+ $sales[0]['totalcost'] = $subtotal - $discount;
177
+ $sales[0]['orderid'] = $order->getIncrementId();
178
+ $sales[0]['productid'] = null;
179
+ $sales[0]['couponcode'] = $couponcode;
180
+ $sales[0]['status'] = $status;
181
+
182
+ for ($n = 1; $n < 6; $n++) {
183
+ if ($config->getData($n)) {
184
+ $sales[0]['data'.$n] = $this->changeExtraData($config->getData($n), $order, $item, $product);
185
+ }
186
+ }
187
+ }
188
+
189
+ return $sales;
190
+ }
191
+
192
+ public function registerOrderByID($orderid, $realid = true) { // called from the checkout observer
193
+ $order = Mage::getModel('sales/order')->load($orderid);
194
+ if ($realid) {
195
+ $order->load($orderid);
196
+ }
197
+ else {
198
+ $order->loadByIncrementId($orderid);
199
+ }
200
+
201
+ $this->registerOrder($order);
202
+ }
203
+
204
+ public function registerOrder($order, $visitorID = '') {
205
+ if ($order) {
206
+ $orderid = $order->getId();
207
+ }
208
+ else {
209
+ Mage::log('Postaffiliatepro: Order empty');
210
+ return false;
211
+ }
212
+ Mage::log("Postaffiliatepro: Loading details of order $orderid");
213
+
214
+ $items = $this->getOrderSaleDetails($order);
215
+ $this->registerSaleDetails($items, $visitorID);
216
+ }
217
+
218
+ public function registerSaleDetails($items, $visitorID = '') {
219
+ $config = Mage::getSingleton('pap/config');
220
+ $config->includePapAPI();
221
+
222
+ $saleTracker = new Pap_Api_SaleTracker($config->getInstallationPath().'/scripts/sale.php');
223
+ $saleTracker->setAccountId($config->getAPICredential('account'));
224
+ if (!empty($visitorID)) {
225
+ $saleTracker->setVisitorId($visitorID);
226
+ }
227
+
228
+ foreach ($items as $i => $item) {
229
+ Mage::log('Postaffiliatepro: Registering sale '.$item['orderid']."($i)");
230
+
231
+ $sale = $saleTracker->createSale();
232
+ $sale->setTotalCost($item['totalcost']);
233
+ $sale->setOrderID($item['orderid']."($i)");
234
+ $sale->setProductID($item['productid']);
235
+ $sale->setStatus($item['status']);
236
+ if ($item['couponcode']) $sale->setCouponCode($item['couponcode']);
237
+ if ($item['data1']) $sale->setData1($item['data1']);
238
+ if ($item['data2']) $sale->setData2($item['data2']);
239
+ if ($item['data3']) $sale->setData3($item['data3']);
240
+ if ($item['data4']) $sale->setData4($item['data4']);
241
+ if ($item['data5']) $sale->setData5($item['data5']);
242
+ }
243
+
244
+ $saleTracker->register();
245
+ }
246
+
247
+ public function changeExtraData($data, $order, $item, $product) {
248
+ switch ($data) {
249
+ case 'empty':
250
+ return null;
251
+ break;
252
+ case 'itemName':
253
+ return (!empty($item)) ? $item->getName() : null;
254
+ break;
255
+ case 'itemQuantity':
256
+ return (!empty($item)) ? $item->getQtyOrdered() : null;
257
+ break;
258
+ case 'itemPrice':
259
+ if (!empty($item)) {
260
+ $rowtotal = $item->getBaseRowTotal();
261
+ if (empty($rowtotal)) {
262
+ return $item->getBasePrice();
263
+ }
264
+ return $rowtotal;
265
+ }
266
+ return null;
267
+ break;
268
+ case 'itemSKU':
269
+ return (!empty($item)) ? $item->getSku() : null;
270
+ break;
271
+ case 'itemWeight':
272
+ return (!empty($item)) ? $item->getWeight() : null;
273
+ break;
274
+ case 'itemWeightAll':
275
+ return (!empty($item)) ? $item->getRowWeight() : null;
276
+ break;
277
+ case 'itemCost':
278
+ return (!empty($item)) ? $item->getCost() : null;
279
+ break;
280
+ case 'itemDiscount':
281
+ return (!empty($item)) ? abs($item->getBaseDiscountAmount()) : null;
282
+ break;
283
+ case 'itemDiscountPercent':
284
+ return (!empty($item)) ? $item->getDiscountPercent() : null;
285
+ break;
286
+ case 'itemTax':
287
+ return (!empty($item)) ? $item->getTaxAmount() : null;
288
+ break;
289
+ case 'itemTaxPercent':
290
+ return (!empty($item)) ? $item->getTaxPercent() : null;
291
+ break;
292
+ case 'productCategoryID':
293
+ return (!empty($product)) ? $product->getCategoryId() : null;
294
+ break;
295
+ case 'productURL':
296
+ return (!empty($product)) ? $product->getProductUrl(false) : null;
297
+ break;
298
+ case 'storeID':
299
+ return (!empty($order)) ? $order->getStoreId() : null;
300
+ break;
301
+ case 'internalOrderID':
302
+ return (!empty($order)) ? $order->getId() : null;
303
+ break;
304
+ case 'customerID':
305
+ return (!empty($order) && $order->getCustomerId()) ? $order->getCustomerId() : null;
306
+ break;
307
+ case 'customerEmail':
308
+ return (!empty($order) && $order->getCustomerEmail()) ? $order->getCustomerEmail() : null;
309
+ break;
310
+ case 'customerName':
311
+ $name = '';
312
+ if (!empty($order)) {
313
+ $name = $order->getCustomerFirstname().' '.$order->getCustomerMiddlename().' '.$order->getCustomerLastname();
314
+ }
315
+ return (!empty($name)) ? $name : null;
316
+ break;
317
+ case 'couponCode':
318
+ return (!empty($order) && $order->getQuoteId()) ? Mage::getModel('sales/quote')->load($order->getQuoteId())->getCouponCode() : null;
319
+ break;
320
+ default: return $data;
321
+ }
322
+ }
323
+ }
app/code/local/Qualityunit/Pap/Model/{Ipn.php → PaypalIpn.php} RENAMED
File without changes
app/code/local/Qualityunit/Pap/Model/Validateapi.php CHANGED
@@ -22,9 +22,16 @@ class Qualityunit_Pap_Model_Validateapi extends Mage_Core_Model_Config_Data {
22
  $password = $_POST['groups']['api']['fields']['password']['value'];
23
 
24
  $session = new Gpf_Api_Session($url);
 
25
  if (!@$session->login($username, $password)) {
26
- Mage::getSingleton('adminhtml/session')->addError('Credential are probably not correct: '.$session->getMessage());
27
- return null;
 
 
 
 
 
 
28
  } else {
29
  Mage::getSingleton('core/session')->addSuccess('API Connection tested successfully!');
30
  }
22
  $password = $_POST['groups']['api']['fields']['password']['value'];
23
 
24
  $session = new Gpf_Api_Session($url);
25
+ // check HTTP
26
  if (!@$session->login($username, $password)) {
27
+ // check HTTPS
28
+ $session = new Gpf_Api_Session(str_replace('http://','https://',$url));
29
+ if (!@$session->login($username, $password)) {
30
+ Mage::getSingleton('adminhtml/session')->addError('Credentials are probably not correct: '.$session->getMessage());
31
+ return null;
32
+ } else {
33
+ Mage::getSingleton('core/session')->addSuccess('API Connection tested successfully!');
34
+ }
35
  } else {
36
  Mage::getSingleton('core/session')->addSuccess('API Connection tested successfully!');
37
  }
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Qualityunit_Pap</name>
4
- <version>1.0.6</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/gpl-license.php">GNU General Public License (GPL)</license>
7
  <channel>community</channel>
@@ -9,11 +9,13 @@
9
  <summary>The module makes an integration with Post Affiliate Pro or Post Affiliate Network an easy thing. A simple configuration with all the needed options helps you to make it working in seconds.</summary>
10
  <description>The module makes an integration with Post Affiliate Pro or Post Affiliate Network an easy thing. A simple configuration with all the needed options helps you to make it working in seconds.&#xD;
11
  The module integrates sales, supports per product tracking, Coupon tracking and Lifetime Commission tracking. It also automatically approves and declines commissions when transaction status is changed.</description>
12
- <notes>- XML layout changes</notes>
 
 
13
  <authors><author><name>Quality Unit, LLC</name><user>support</user><email>support@qualityunit.com</email></author></authors>
14
- <date>2016-02-04</date>
15
- <time>07:25:46</time>
16
- <contents><target name="magelocal"><dir name="Qualityunit"><dir name="Pap"><dir><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Fieldset"><file name="Hint.php" hash="a1a70e021c623040796d925afbf52324"/></dir></dir></dir></dir><file name="Clicktracking.php" hash="8ee426151206030457e080ef23ce953b"/><dir name="Paypal"><file name="Redirect.php" hash="6c48219eb2e6f37ef50570e90c904639"/></dir><file name="Saletracking.php" hash="b7e5c50972b856a87c2d24903235e502"/></dir><dir name="Helper"><file name="Data.php" hash="6418f45f1484fd4f676933a8af96cef5"/></dir><dir name="Model"><dir name="Checkout"><file name="Observer.php" hash="eeeb25d90b801c6352568c25e3154942"/></dir><dir name="Config"><dir name="Source"><file name="CustomVariables.php" hash="1419c44e2e174e368f69ac9c12701b63"/><file name="TrackSales.php" hash="1af0c801457e4b31f55fde6ad12e7b67"/></dir></dir><file name="Config.php" hash="0a6d8bf59b6b89bb23305bdbb0a593c6"/><file name="Ipn.php" hash="410b6493a4f3fd451698d56bc0eced94"/><file name="Observer.php" hash="82e1daf72693410bc4619151d03554e7"/><file name="Pap.php" hash="239ed108cdef69b7ae0800279b29fd26"/><file name="Paypal.php" hash="39cbba74d089c1460f2404d8128cfb0b"/><file name="Validateapi.php" hash="8f4e945fcbcf29e72c1b914ede455cb3"/></dir><dir name="etc"><file name="config.xml" hash="fc1d64d6b62a1823e98ee8c327d6bffd"/><file name="system.xml" hash="737444ec24bd0a18af630327f025b03c"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="pap.xml" hash="600ebb26e9af1c78ac0a5d22717d2cd2"/></dir><dir name="template"><dir name="pap"><dir name="system"><dir name="config"><dir name="fieldset"><file name="hint.phtml" hash="cebb98c5c843a2921debea7cf98fdfe2"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="pap.xml" hash="167eddd9fa705fba71f8d3d2992a43cc"/></dir></dir></dir><dir name="default"><dir name="default"><dir name="layout"><file name="pap.xml" hash="167eddd9fa705fba71f8d3d2992a43cc"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Qualityunit_Pap.xml" hash="78a58f4a3a637e027e42b74838b56607"/></dir></target><target name="magelib"><dir name="PAP"><file name="PapApi.class.php" hash="f1bae43744873b540b98e448caf7e205"/></dir></target><target name="mage"><dir name="lib"><dir name="PAP"><file name="README.txt" hash="2a279f64825e116dfd29c73fee9dabc8"/></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="pap"><file name="pap.css" hash="ff8a88a99075753b4a0ea9004d579a42"/><file name="pap-tab.png" hash="eef09c5b3777189e05b1702c463a9a33"/><file name="pap-logo.png" hash="e9053c44287a8d84801451ed69ef2f09"/></dir></dir></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.0</min><max>7.5.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Qualityunit_Pap</name>
4
+ <version>1.0.7</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/gpl-license.php">GNU General Public License (GPL)</license>
7
  <channel>community</channel>
9
  <summary>The module makes an integration with Post Affiliate Pro or Post Affiliate Network an easy thing. A simple configuration with all the needed options helps you to make it working in seconds.</summary>
10
  <description>The module makes an integration with Post Affiliate Pro or Post Affiliate Network an easy thing. A simple configuration with all the needed options helps you to make it working in seconds.&#xD;
11
  The module integrates sales, supports per product tracking, Coupon tracking and Lifetime Commission tracking. It also automatically approves and declines commissions when transaction status is changed.</description>
12
+ <notes>- paypal integration fix&#xD;
13
+ - HTTP to HTTPS redirection in case of API communication fixed&#xD;
14
+ - API tracking fixed based on new HTTP/HTTPS approach</notes>
15
  <authors><author><name>Quality Unit, LLC</name><user>support</user><email>support@qualityunit.com</email></author></authors>
16
+ <date>2016-02-23</date>
17
+ <time>08:22:23</time>
18
+ <contents><target name="magelocal"><dir name="Qualityunit"><dir name="Pap"><dir><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Fieldset"><file name="Hint.php" hash="a1a70e021c623040796d925afbf52324"/></dir></dir></dir></dir><file name="Clicktracking.php" hash="8ee426151206030457e080ef23ce953b"/><dir name="Paypal"><file name="Redirect.php" hash="6c48219eb2e6f37ef50570e90c904639"/></dir><file name="Saletracking.php" hash="b7e5c50972b856a87c2d24903235e502"/></dir><dir name="Helper"><file name="Data.php" hash="6418f45f1484fd4f676933a8af96cef5"/></dir><dir name="Model"><dir name="Checkout"><file name="Observer.php" hash="eeeb25d90b801c6352568c25e3154942"/></dir><dir name="Config"><dir name="Source"><file name="CustomVariables.php" hash="1419c44e2e174e368f69ac9c12701b63"/><file name="TrackSales.php" hash="1af0c801457e4b31f55fde6ad12e7b67"/></dir></dir><file name="Config.php" hash="75852918132ca6300c3a381574c5404d"/><file name="Observer.php" hash="82e1daf72693410bc4619151d03554e7"/><file name="Pap.php" hash="1010ab29b52c34277397a5b5aeadd7eb"/><file name="Paypal.php" hash="39cbba74d089c1460f2404d8128cfb0b"/><file name="PaypalIpn.php" hash="410b6493a4f3fd451698d56bc0eced94"/><file name="Validateapi.php" hash="2a90e74dc6a137a8960df465f17711ca"/></dir><dir name="etc"><file name="config.xml" hash="fc1d64d6b62a1823e98ee8c327d6bffd"/><file name="system.xml" hash="737444ec24bd0a18af630327f025b03c"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="pap.xml" hash="600ebb26e9af1c78ac0a5d22717d2cd2"/></dir><dir name="template"><dir name="pap"><dir name="system"><dir name="config"><dir name="fieldset"><file name="hint.phtml" hash="cebb98c5c843a2921debea7cf98fdfe2"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="pap.xml" hash="167eddd9fa705fba71f8d3d2992a43cc"/></dir></dir></dir><dir name="default"><dir name="default"><dir name="layout"><file name="pap.xml" hash="167eddd9fa705fba71f8d3d2992a43cc"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Qualityunit_Pap.xml" hash="78a58f4a3a637e027e42b74838b56607"/></dir></target><target name="magelib"><dir name="PAP"><file name="PapApi.class.php" hash="f1bae43744873b540b98e448caf7e205"/></dir></target><target name="mage"><dir name="lib"><dir name="PAP"><file name="README.txt" hash="2a279f64825e116dfd29c73fee9dabc8"/></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="pap"><file name="pap.css" hash="ff8a88a99075753b4a0ea9004d579a42"/><file name="pap-tab.png" hash="eef09c5b3777189e05b1702c463a9a33"/><file name="pap-logo.png" hash="e9053c44287a8d84801451ed69ef2f09"/></dir></dir></dir></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.2.0</min><max>7.5.0</max></php></required></dependencies>
21
  </package>