Payson - Version 1.0.0

Version Notes

* When order is cancelled product is credited to inventory
* Cart is now restored when returning from Payson and payment failed

Download this release

Release Info

Developer Oscar Villegas
Extension Payson
Version 1.0.0
Comparing to
See all releases


Code changes from version 0.1.3 to 1.0.0

Files changed (32) hide show
  1. app/code/community/Payson/Payson/Block/Form.php +8 -7
  2. app/code/community/Payson/Payson/Block/Invoice/Form.php +8 -7
  3. app/code/community/Payson/Payson/Block/Order/Totals/Fee.php +17 -17
  4. app/code/community/Payson/Payson/Block/Standard/Form.php +8 -7
  5. app/code/community/Payson/Payson/Helper/Api.php +1031 -1180
  6. app/code/community/Payson/Payson/Helper/Api/Response/Interface.php +16 -15
  7. app/code/community/Payson/Payson/Helper/Api/Response/Standard.php +128 -150
  8. app/code/community/Payson/Payson/Helper/Api/Response/Standard/Parameters.php +55 -67
  9. app/code/community/Payson/Payson/Helper/Api/Response/Validate.php +43 -46
  10. app/code/community/Payson/Payson/Helper/Data.php +2 -2
  11. app/code/community/Payson/Payson/Model/Config.php +217 -232
  12. app/code/community/Payson/Payson/Model/Method/Abstract.php +159 -174
  13. app/code/community/Payson/Payson/Model/Method/Invoice.php +109 -129
  14. app/code/community/Payson/Payson/Model/Method/Standard.php +36 -37
  15. app/code/community/Payson/Payson/Model/Mysql4/Setup.php +3 -2
  16. app/code/community/Payson/Payson/Model/Order/Creditmemo/Total/Invoice.php +31 -32
  17. app/code/community/Payson/Payson/Model/Order/Invoice/Total/Invoice.php +30 -32
  18. app/code/community/Payson/Payson/Model/Quote/Address/Total/Invoice.php +45 -49
  19. app/code/community/Payson/Payson/Model/Standard.php +115 -128
  20. app/code/community/Payson/Payson/controllers/CheckoutController.php +135 -133
  21. app/code/community/Payson/Payson/controllers/IpnController.php +22 -26
  22. app/code/community/Payson/Payson/etc/config.xml +18 -16
  23. app/code/community/Payson/Payson/etc/system.xml +159 -139
  24. app/code/community/Payson/Payson/sql/payson_setup/mysql4-install-0.1.0.php +3 -14
  25. app/code/community/Payson/Payson/sql/payson_setup/mysql4-upgrade-0.1.0-0.1.2.php +1 -0
  26. app/design/adminhtml/default/default/Payson/Payson/total.phtml +2 -2
  27. app/design/adminhtml/default/default/layout/Payson.xml +20 -30
  28. app/design/frontend/base/default/layout/Payson.xml +41 -41
  29. app/design/frontend/base/default/template/Payson/Payson/invoice_form.phtml +9 -9
  30. app/design/frontend/base/default/template/Payson/Payson/standard_form.phtml +4 -4
  31. app/etc/modules/Payson_Payson.xml +10 -10
  32. package.xml +8 -12
app/code/community/Payson/Payson/Block/Form.php CHANGED
@@ -1,10 +1,11 @@
1
  <?php
2
- class Payson_Payson_Block_Form extends Mage_Payment_Block_Form
3
- {
4
- protected function _construct()
5
- {
6
- $this->setTemplate('Payson/Payson/form.phtml');
7
- parent::_construct();
8
- }
 
9
  }
10
 
1
  <?php
2
+
3
+ class Payson_Payson_Block_Form extends Mage_Payment_Block_Form {
4
+
5
+ protected function _construct() {
6
+ $this->setTemplate('Payson/Payson/form.phtml');
7
+ parent::_construct();
8
+ }
9
+
10
  }
11
 
app/code/community/Payson/Payson/Block/Invoice/Form.php CHANGED
@@ -1,10 +1,11 @@
1
  <?php
2
- class Payson_Payson_Block_Invoice_Form extends Mage_Payment_Block_Form
3
- {
4
- protected function _construct()
5
- {
6
- $this->setTemplate('Payson/Payson/invoice_form.phtml');
7
- parent::_construct();
8
- }
 
9
  }
10
 
1
  <?php
2
+
3
+ class Payson_Payson_Block_Invoice_Form extends Mage_Payment_Block_Form {
4
+
5
+ protected function _construct() {
6
+ $this->setTemplate('Payson/Payson/invoice_form.phtml');
7
+ parent::_construct();
8
+ }
9
+
10
  }
11
 
app/code/community/Payson/Payson/Block/Order/Totals/Fee.php CHANGED
@@ -1,22 +1,22 @@
1
  <?php
2
- class Payson_Payson_Block_Order_Totals_Fee extends Mage_Core_Block_Abstract
3
- {
4
- public function initTotals()
5
- {
6
- $parent = $this->getParentBlock();
7
- $this->_order = $parent->getOrder();
8
 
9
- if($this->_order->getPayment()->getMethod() === 'payson_invoice')
10
- {
11
- $parent->addTotalBefore(new Varien_Object(array
12
- (
13
- 'code' => 'payson_invoice',
14
- 'label' => Mage::helper('payson')->__('Invoice fee'),
15
- 'value' => $this->_order->getPaysonInvoiceFee()
16
- )), 'tax');
17
- }
 
 
 
 
 
 
 
 
18
 
19
- return $this;
20
- }
21
  }
22
 
1
  <?php
 
 
 
 
 
 
2
 
3
+ class Payson_Payson_Block_Order_Totals_Fee extends Mage_Core_Block_Abstract {
4
+
5
+ public function initTotals() {
6
+ $parent = $this->getParentBlock();
7
+ $this->_order = $parent->getOrder();
8
+
9
+ if ($this->_order->getPayment()->getMethod() === 'payson_invoice') {
10
+ $parent->addTotalBefore(new Varien_Object(array
11
+ (
12
+ 'code' => 'payson_invoice',
13
+ 'label' => Mage::helper('payson')->__('Invoice fee'),
14
+ 'value' => $this->_order->getPaysonInvoiceFee()
15
+ )), 'tax');
16
+ }
17
+
18
+ return $this;
19
+ }
20
 
 
 
21
  }
22
 
app/code/community/Payson/Payson/Block/Standard/Form.php CHANGED
@@ -1,10 +1,11 @@
1
  <?php
2
- class Payson_Payson_Block_Standard_Form extends Mage_Payment_Block_Form
3
- {
4
- protected function _construct()
5
- {
6
- $this->setTemplate('Payson/Payson/standard_form.phtml');
7
- parent::_construct();
8
- }
 
9
  }
10
 
1
  <?php
2
+
3
+ class Payson_Payson_Block_Standard_Form extends Mage_Payment_Block_Form {
4
+
5
+ protected function _construct() {
6
+ $this->setTemplate('Payson/Payson/standard_form.phtml');
7
+ parent::_construct();
8
+ }
9
+
10
  }
11
 
app/code/community/Payson/Payson/Helper/Api.php CHANGED
@@ -1,510 +1,458 @@
1
  <?php
2
- class Payson_Payson_Helper_Api
3
- {
4
- /*
5
- * Constants
6
- */
7
-
8
- const DEBUG_MODE = false;
9
- const API_CALL_PAY = '%s://%sapi.payson.%s/%s/Pay/';
10
- const API_CALL_VALIDATE = '%s://%sapi.payson.%s/%s/Validate/';
11
- const API_CALL_PAYMENT_DETAILS = '%s://%sapi.payson.%s/%s/%sDetails/';
12
- const API_CALL_PAYMENT_UPDATE = '%s://%sapi.payson.%s/%s/%sUpdate/';
13
-
14
- const PAY_FORWARD_URL = '%s://%s%s.payson.%s/paySecure/';
15
-
16
- const APPLICATION_ID = 'Magento Module 0.1.3';
17
- const MODULE_NAME = 'payson_magento';
18
- const MODULE_VERSION = '0.1.3';
19
-
20
- const DEBUG_MODE_MAIL = 'testagent-1@payson.se';
21
- const DEBUG_MODE_AGENT_ID = '1';
22
- const DEBUG_MODE_MD5 = 'fddb19ac-7470-42b6-a91d-072cb1495f0a';
23
-
24
- const STATUS_CREATED = 'CREATED';
25
- const STATUS_PENDING = 'PENDING';
26
- const STATUS_PROCESSING = 'PROCESSING';
27
- const STATUS_COMPLETED = 'COMPLETED';
28
- const STATUS_CREDITED = 'CREDITED';
29
- const STATUS_INCOMPLETE = 'INCOMPLETE';
30
- const STATUS_ERROR = 'ERROR';
31
- const STATUS_EXPIRED = 'EXPIRED';
32
- const STATUS_REVERSALERROR = 'REVERSALERROR';
33
-
34
- const PAYMENT_METHOD_BANK = 'BANK';
35
- const PAYMENT_METHOD_CREDITCARD = 'CREDITCARD';
36
- const PAYMENT_METHOD_INVOICE = 'INVOICE';
37
-
38
- const GUARANTEE_STATUS_WAITINGFORSEND = 'WAITINGFORSEND';
39
- const GUARANTEE_STATUS_WAITINGFORACCEPTANCE = 'WAITINGFORACCEPTANCE';
40
- const GUARANTEE_STATUS_WAITINGFORRETURN = 'WAITINGFORRETURN';
41
- const GUARANTEE_STATUS_WAITINGFORRETURNACCEPTANCE = 'WAITINGFORRETURNACCEPTANCE';
42
- const GUARANTEE_STATUS_RETURNNOTACCEPTED = 'RETURNNOTACCEPTED';
43
- const GUARANTEE_STATUS_NOTRECEIVED = 'NOTRECEIVED';
44
- const GUARANTEE_STATUS_RETURNNOTRECEIVED = 'RETURNNOTRECEIVED';
45
- const GUARANTEE_STATUS_MONEYRETURNEDTOSENDER = 'MONEYRETURNEDTOSENDER';
46
- const GUARANTEE_STATUS_RETURNACCEPTED = 'RETURNACCEPTED';
47
-
48
- const INVOICE_STATUS_PENDING = 'PENDING';
49
- const INVOICE_STATUS_ORDERCREATED = 'ORDERCREATED';
50
- const INVOICE_STATUS_ORDERCANCELLED = 'ORDERCANCELLED';
51
- const INVOICE_STATUS_SHIPPED = 'SHIPPED';
52
- const INVOICE_STATUS_DONE = 'DONE';
53
-
54
- const UPDATE_ACTION_CANCELORDER = 'CANCELORDER';
55
- const UPDATE_ACTION_SHIPORDER = 'SHIPORDER';
56
- const UPDATE_ACTION_CREDITORDER = 'CREDITORDER';
57
- const UPDATE_ACTION_REFUNDORDER = 'REFUND';
58
-
59
- const GUARANTEE_REQUIRED = 'REQUIRED';
60
- const GUARANTEE_OPTIONAL = 'OPTIONAL';
61
- const GUARANTEE_NO = 'NO';
62
-
63
- /*
64
- * Private properties
65
- */
66
-
67
- private $response;
68
-
69
- private $order_discount_item = 0.0;
70
-
71
- /*
72
- * Private methods
73
- */
74
-
75
- private function GetHttpClient($url)
76
- {
77
- $config = Mage::getModel('payson/config');
78
-
79
- $http_client = new Zend_Http_Client($url);
80
-
81
- $http_client->setMethod(Zend_Http_Client::POST)
82
- ->setHeaders(array
83
- (
84
- 'PAYSON-SECURITY-USERID' => $config->get('test_mode') ? self::DEBUG_MODE_AGENT_ID : $config->Get('agent_id'),
85
- 'PAYSON-SECURITY-PASSWORD' => $config->get('test_mode') ? self::DEBUG_MODE_MD5 : $config->Get('md5_key'),
86
- 'PAYSON-APPLICATION-ID' => self::APPLICATION_ID,
87
- 'PAYSON-MODULE-INFO' => self::MODULE_NAME.'|'.self::MODULE_VERSION.'|'.Mage::getVersion()
88
- ));
89
-
90
- return $http_client->resetParameters();
91
- }
92
-
93
- private function SetResponse(
94
- Payson_Payson_Helper_Api_Response_Interface $response)
95
- {
96
- $this->response = $response;
97
-
98
- return $this;
99
- }
100
-
101
- private function SetOrderDiscountItem($item, &$total)
102
- {
103
- $total -= $item->getData('discount_amount');
104
- $this->order_discount_item += $item->getData('discount_amount');
105
-
 
 
 
 
 
 
 
 
106
  }
107
 
108
- /**
109
- * Helper for Pay()
110
- *
111
- * @param object $item
112
- * @param int $i
113
- * @param int $total
114
- * @return array
115
- */
116
- private function GetOrderItemInfo($item, $i, &$total)
117
- {
118
- $product = Mage::getModel('catalog/product')
119
- ->load($item->getProductId());
120
- $children = $item->getChildrenItems();
121
-
122
- if(!$product->isConfigurable() && count($children) &&
123
- !$item->isChildrenCalculated())
124
- {
125
- $args = array();
126
- foreach($children as $child)
127
- {
128
- $args += $this->GetOrderItemInfo($child, $i++, $total);
129
- }
130
- return $args;
131
- }
132
-
133
- if($product->isConfigurable() && (count($children) === 1))
134
- {
135
- $name = $children[0]->getData('name');
136
- $sku = $children[0]->getData('sku');
137
- }
138
- else
139
- {
140
- $name = $product->getData('name');
141
- $sku = $item->getData('sku');
142
- }
143
-
144
- /* TODO: If tax_percent is not set?
145
- Mage::getSingleton('tax/calculation')->getRate(
146
- $tax_rate_req->setProductClassId($product->getTaxClassId()))
147
- */
148
- $tax_mod = (float)$item->getData('tax_percent');
149
- $tax_mod /= 100;
150
- $tax_mod = round($tax_mod, 5);
151
-
152
- $qty = (float)$item->getData('qty_ordered');
153
- $qty = round($qty, 2);
154
-
155
- $price = (float)$item->getData('row_total_incl_tax');
156
- /* print_r($item->getData('base_price'));
157
- echo '<br />';
158
- echo '<br />';
159
- print_r($item);exit;*/
160
- //$price -= (float)$item->getData('discount_amount');
161
-
162
- $base_price = (($price / (1 + $tax_mod)) / $qty);
163
- $base_price = round($base_price, 3);
164
-
165
- $total += (($base_price * (1 + $tax_mod)) * $qty);
166
-
167
- return array
168
- (
169
- 'orderItemList.orderItem(' . $i . ').description' =>
170
- $name,
171
- 'orderItemList.orderItem(' . $i . ').sku' =>
172
- $sku,
173
- 'orderItemList.orderItem(' . $i . ').quantity' =>
174
- $qty,
175
- 'orderItemList.orderItem(' . $i . ').unitPrice' =>
176
- $item->getData('base_price'),
177
- 'orderItemList.orderItem(' . $i . ').taxPercentage' =>
178
- $tax_mod
179
- );
180
- }
181
-
182
- /**
183
- * Helper for Pay()
184
- *
185
- * @param object $order
186
- * @param object $customer
187
- * @param object $store
188
- * @param int $i
189
- * @param int $total
190
- * @return array
191
- */
192
- private function GetOrderShippingInfo($order, $customer, $store, $i,
193
- &$total)
194
- {
195
- $tax_calc = Mage::getSingleton('tax/calculation');
196
-
197
- $tax_rate_req = $tax_calc->getRateRequest(
198
- $order->getShippingAddress(),
199
- $order->getBillingAddress(),
200
- $customer->getTaxClassId(),
201
- $store);
202
-
203
- $args = array();
204
-
205
- if(($price = (float)$order->getData('shipping_incl_tax')) > 0)
206
- {
207
- $tax_mod = $tax_calc->getRate($tax_rate_req->setProductClassId(
208
- Mage::getStoreConfig('tax/classes/shipping_tax_class')));
209
- $tax_mod /= 100;
210
- $tax_mod = round($tax_mod, 5);
211
-
212
- $price -= (float)$order->getData('shipping_discount_amount');
213
-
214
- $base_price = ($price / (1 + $tax_mod));
215
- $base_price = round($base_price, 3);
216
-
217
- $total += ($base_price * (1 + $tax_mod));
218
-
219
- $args = array
220
- (
221
- 'orderItemList.orderItem(' . $i . ').description' =>
222
- $order->getData('shipping_description'),
223
- 'orderItemList.orderItem(' . $i . ').sku' =>
224
- $order->getData('shipping_method'),
225
- 'orderItemList.orderItem(' . $i . ').quantity' =>
226
- 1,
227
- 'orderItemList.orderItem(' . $i . ').unitPrice' =>
228
- $base_price,
229
- 'orderItemList.orderItem(' . $i . ').taxPercentage' =>
230
- $tax_mod
231
- );
232
- }
233
- return $args;
234
- }
235
-
236
- /*
237
- * Public methods
238
- */
239
-
240
- /**
241
- * Get API response
242
- *
243
- * @return object
244
- */
245
- public function GetResponse()
246
- {
247
- return $this->response;
248
- }
249
-
250
- /**
251
- * Get forward/redirect url after a successful Pay() call
252
- *
253
- * @return string
254
- */
255
- public function GetPayForwardUrl()
256
- {
257
- $url = vsprintf(self::PAY_FORWARD_URL . '?token=' . $this->GetResponse()->TOKEN, $this->GetFormatIfTest(null, true));
258
- return $url;
259
- }
260
-
261
- /**
262
- * http://api.payson.se/#title8
263
- *
264
- * @param object $order
265
- * @return object $this
266
- */
267
- public function Pay(Mage_Sales_Model_Order $order)
268
- {
269
- $payment_method = $order->getPayment()->getMethod();
270
- $helper = Mage::helper('payson');
271
- $config = Mage::getModel('payson/config');
272
- $store = Mage::app()->getStore($order->getStoreId());
273
- $customer = Mage::getModel('customer/customer')
274
- ->load($order->getCustomerId());
275
- $billing_address = $order->getBillingAddress();
276
-
277
- // Need a two character locale code
278
- $locale_code = Mage::getSingleton('core/locale')->getLocaleCode();
279
- $locale_code = strtoupper(substr($locale_code, 0, 2));
280
-
281
- if(!in_array($locale_code, array('SV', 'FI', 'EN')))
282
- {
283
- switch($locale_code)
284
- {
285
- case 'DA':
286
- case 'NO':
287
- {
288
- $locale_code = 'SV';
289
- break;
290
- }
291
- default:
292
- {
293
- $locale_code = 'EN';
294
- }
295
- }
296
- }
297
-
298
- // $args will contain the arguments of the API request to Payson
299
- $args = array
300
- (
301
- 'returnUrl' =>
302
- Mage::getUrl('payson/checkout/return',
303
- array('_secure' => true)),
304
- 'cancelUrl' =>
305
- Mage::getUrl('payson/checkout/cancel',
306
- array('_secure' => true)),
307
- 'ipnNotificationUrl' =>
308
- Mage::getUrl('payson/ipn/notify',
309
- array('_secure' => true)),
310
- 'localeCode' =>
311
- $locale_code,
312
- 'currencyCode' =>
313
- //$order->getOrderCurrency()->getCode(),
314
- //$order->getBaseCurrencyCode(),
315
- strtoupper(substr($order->getOrderCurrency()->getCode(), 0, 3)),
316
- 'memo' =>
317
- sprintf($helper->__('Order from %s'), $store->getUrl()),
318
- 'senderEmail' =>
319
- $order->getCustomerEmail(),
320
- 'senderFirstName' =>
321
- $billing_address->getFirstname(),
322
- 'senderLastName' =>
323
- $billing_address->getLastname(),
324
- 'receiverList.receiver(0).email' =>
325
- $config->get('test_mode') ? self::DEBUG_MODE_MAIL : $config->Get('email'),
326
- 'trackingId' => $order->getRealOrderId()
327
- );
328
-
329
- if(!$config->CanPaymentGuarantee())
330
- {
331
- $args['guaranteeOffered'] = self::GUARANTEE_NO;
332
- }
333
-
334
- if(($payment_method === 'payson_invoice'))
335
- {
336
- if(!$config->CanInvoicePayment())
337
- {
338
- Mage::throwException('Invoice payment is disabled');
339
- }
340
-
341
- $args['fundingList.fundingConstraint(0).constraint'] =
342
- self::PAYMENT_METHOD_INVOICE;
343
- }
344
-
345
- $i = 0;
346
- $total = 0;
347
-
348
- // Calculate price of each item in the order
349
- foreach($order->getAllVisibleItems() as $item)
350
- {
351
- $args += $this->GetOrderItemInfo($item, $i++, $total);
352
- }
353
-
354
- foreach($order->getAllVisibleItems() as $item)
355
- {
356
- $this->SetOrderDiscountItem($item, $total);
357
- }
358
- if($this->order_discount_item >> 0){
359
- $args += array
360
- (
361
- 'orderItemList.orderItem(' . $i . ').description' =>
362
- 'discount',
363
- 'orderItemList.orderItem(' . $i . ').sku' =>
364
- 'discount',
365
- 'orderItemList.orderItem(' . $i . ').quantity' =>
366
- 1,
367
- 'orderItemList.orderItem(' . $i . ').unitPrice' =>
368
- -$this->order_discount_item,
369
- 'orderItemList.orderItem(' . $i . ').taxPercentage' =>
370
- 0.0
371
- );
372
- }
373
- // Calculate price for shipping
374
- $args += $this->GetOrderShippingInfo($order, $customer, $store, $i++,
375
- $total);
376
- /* echo '<pre>';
377
- print_r($args);
378
- echo '</pre>';exit;*/
379
- if($order->getPaysonInvoiceFee() > 0)
380
- {
381
- $fee = $order->getPaysonInvoiceFee();
382
- /*$args += array
383
- (
384
- 'orderItemList.orderItem(' . $i . ').description' =>
385
- $helper->__('Invoice fee'),
386
- 'orderItemList.orderItem(' . $i . ').sku' =>
387
- 'invoice_fee',
388
- 'orderItemList.orderItem(' . $i . ').quantity' =>
389
- 1,
390
- 'orderItemList.orderItem(' . $i . ').unitPrice' =>
391
- $config->GetInvoiceFee($order),
392
- 'orderItemList.orderItem(' . $i . ').taxPercentage' =>
393
- $config->GetInvoiceFeeTaxMod($order)
394
- );
395
-
396
- $total += $config->GetInvoiceFeeInclTax($order);*/
397
-
398
- $args['invoiceFee'] = round((float)$fee, 3);
399
- $total += $fee;
400
- }
401
-
402
- $total = round($total, 2);
403
-
404
- $args['receiverList.receiver(0).amount'] = $total;
405
-
406
- //echo('<pre>');print_r($args);exit(PHP_EOL . $order->getData('grand_total') . '</pre>');
407
- $url = vsprintf(self::API_CALL_PAY, $this->GetFormatIfTest($order->getStoreId()));
408
- $client = $this->GetHttpClient($url)
409
- ->setParameterPost($args);
410
-
411
- $response = Payson_Payson_Helper_Api_Response_Standard
412
- ::FromHttpBody($client->request()->getBody());
413
-
414
- $this->SetResponse($response);
415
-
416
- $resource = Mage::getSingleton('core/resource');
417
- $db = $resource->getConnection('core_write');
418
-
419
- $order_table = $resource->getTableName('payson_order');
420
- $order_log_table = $resource->getTableName('payson_order_log');
421
-
422
- $db->insert($order_table, array
423
- (
424
- 'order_id' => $order->getRealOrderId(),
425
- 'added' => new Zend_Db_Expr('NOW()'),
426
- 'updated' => new Zend_Db_Expr('NOW()'),
427
- 'valid' => (int)$response->IsValid(),
428
- 'token' => (isset($response->TOKEN) ? $response->TOKEN :
429
- new Zend_Db_Expr('NULL')),
430
- 'store_id' => $order->getStoreId()
431
- ));
432
-
433
- $payson_order_id = $db->lastInsertId();
434
-
435
- $db->insert($order_log_table, array
436
- (
437
- 'payson_order_id' => $payson_order_id,
438
- 'added' => new Zend_Db_Expr('NOW()'),
439
- 'api_call' => 'pay',
440
- 'valid' => (int)$response->IsValid(),
441
- 'response' => serialize($response->ToArray())
442
- ));
443
-
444
- if(!$response->IsValid())
445
- {
446
-
447
- throw new Mage_Core_Exception(sprintf($helper->__(
448
- 'Failed to initialize payment. Payson replied: %s'),
449
- $response->GetError()), $response->GetErrorId());
450
- }
451
-
452
- return $this;
453
- }
454
-
455
- /**
456
- * Implements the IPN procedure
457
- *
458
- * http://api.payson.se/#title11
459
- *
460
- * @param string $http_body
461
- * @param string $content_type
462
- * @return object $this
463
- */
464
- public function Validate($http_body, $content_type)
465
- {
466
- $helper = Mage::helper('payson');
467
- $config = Mage::getModel('payson/config');
468
- // Parse request done by Payson to our IPN controller
469
- $ipn_response = Payson_Payson_Helper_Api_Response_Standard
470
- ::FromHttpBody($http_body);
471
-
472
- // Get the database connection
473
- $resource = Mage::getSingleton('core/resource');
474
- $db = $resource->getConnection('core_write');
475
-
476
- $order_table = $resource->getTableName('payson_order');
477
- $order_log_table = $resource->getTableName('payson_order_log');
478
-
479
- /* Save data sent by Payson, log entry as invalid by default, this
480
- value will be changed later in this method if successful. No payson
481
- order id is set, because we dont have one yet */
482
- $db->insert($order_log_table,
483
- array
484
- (
485
- 'added' => new Zend_Db_Expr('NOW()'),
486
- 'api_call' => 'validate',
487
- 'valid' => 0,
488
- 'response' => serialize($ipn_response->ToArray())
489
- ));
490
-
491
- $order_log_id = $db->lastInsertId();
492
-
493
- /* $ipn_response will never contain responseEnvelope.ack, as I first
494
- thought it would */
495
- /*if(!$ipn_response->IsValid())
496
- {
497
- Mage::throwException('Invalid request');
498
- }*/
499
-
500
- /* Save fetch mode so that we can reset it and not mess up Magento
501
- functionality */
502
- $old_fetch_mode = $db->getFetchMode();
503
- $db->setFetchMode(Zend_Db::FETCH_OBJ);
504
-
505
- // Get payson order information and validate token
506
- $payson_order = $db->fetchRow(
507
- 'SELECT
508
  id,
509
  order_id,
510
  store_id
@@ -517,534 +465,448 @@ AND
517
  LIMIT
518
  0,1', $ipn_response->token);
519
 
520
- if($payson_order === false)
521
- {
522
- Mage::throwException('Invalid token');
523
- }
524
-
525
- // Do the validate API call
526
- $client = $this->GetHttpClient(vsprintf(self::API_CALL_VALIDATE, $this->GetFormatIfTest($payson_order->store_id)))
527
- ->setRawData($http_body, $content_type);
528
-
529
- $response = Payson_Payson_Helper_Api_Response_Validate
530
- ::FromHttpBody($client->request()->getBody());
531
-
532
- $this->SetResponse($response);
533
-
534
- if(!$response->IsValid())
535
- {
536
- Mage::throwException('Validate call was unsuccessful');
537
- }
538
-
539
-
540
-
541
- // Update order log with payson order id
542
- $db->update($order_log_table,
543
- array
544
- (
545
- 'payson_order_id' => $payson_order->id
546
- ),
547
- array
548
- (
549
- 'id = ?' => $order_log_id
550
- ));
551
-
552
- // the order model does not expect FETCH_OBJ!
553
- $db->setFetchMode($old_fetch_mode);
554
-
555
- $order = Mage::getModel('sales/order')
556
- ->loadByIncrementId($payson_order->order_id);
557
-
558
- // Stop if order dont exist
559
- if(is_null($order->getId()))
560
- {
561
- Mage::throwException('Invalid order');
562
- }
563
-
564
- // If its not pending payment its either cancelled or completed
565
- //if($order->getState() !== Mage_Sales_Model_Order::STATE_PENDING_PAYMENT)
566
- // Or... hmm...
567
- if($order->getState() === Mage_Sales_Model_Order::STATE_COMPLETE)
568
- {
569
- Mage::throwException('Order is no longer active');
570
- }
571
-
572
- $receivers = $ipn_response->receiverList->receiver->ToArray();
573
-
574
- /* Verify payment amount. floor() since there might be a precision
575
- difference */
576
- if(floor((float)$receivers[0]['amount']) !==
577
- floor((float)$order->getTotalDue()))
578
- {
579
- Mage::throwException('Invalid amount');
580
- }
581
-
582
- switch($ipn_response->status)
583
- {
584
- case self::STATUS_COMPLETED:
585
- {
586
- //Changes the status of the order from pending_payment to processing
587
- $order->setState(
588
- Mage_Sales_Model_Order::STATE_PROCESSING,
589
- Mage_Sales_Model_Order::STATE_PROCESSING,
590
- //$helper->__('Payson completed the order payment XXXXXXX'));
591
- $config->get('test_mode') ? $helper->__('Payson test completed the order payment') : $helper->__('Payson completed the order payment'));
592
-
593
- //It creates the invoice to the order
594
- $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
595
- $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
596
- $invoice->register();
597
- $transactionSave = Mage::getModel('core/resource_transaction')
598
- ->addObject($invoice)
599
- ->addObject($invoice->getOrder());
600
- $transactionSave->save();
601
- /*try
602
- {
603
- echo('<p>Order id: ' . $order->getId() . '</p>');
604
-
605
- if(!$order->canInvoice())
606
- {
607
- exit('<p>Cant invoice!</p>');
608
- }
609
-
610
- $invoice = Mage::getModel('sales/service_order', $order)
611
- ->prepareInvoice();
612
-
613
- if(!$invoice->getTotalQty())
614
- {
615
- exit('<p>No products!</p>');
616
- }
617
-
618
- $invoice->setRequestedCaptureCase(
619
- Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE)
620
- ->register();
621
-
622
- $transaction_save = Mage::getModel('core/resource_transaction')
623
- ->addObject($invoice)
624
- ->addObject($invoice->getOrder());
625
-
626
- $transaction_save->save();
627
- }
628
- catch(Exception $e)
629
- {
630
- exit($e->getMessage());
631
- }*/
632
- break;
633
- }
634
- case self::STATUS_CREATED:
635
- case self::STATUS_PENDING:
636
- case self::STATUS_PROCESSING:
637
- case self::STATUS_CREDITED:
638
- {
639
- if(($ipn_response->status === self::STATUS_PENDING) &&
640
- ($ipn_response->type === self::PAYMENT_METHOD_INVOICE) &&
641
- ($ipn_response->invoiceStatus ===
642
- self::INVOICE_STATUS_ORDERCREATED))
643
- {
644
- //Changes the status of the order from pending to processing
645
- $order->setState(
646
- Mage_Sales_Model_Order::STATE_PROCESSING,
647
- Mage_Sales_Model_Order::STATE_PROCESSING,
648
- //$helper->__('Payson created an invoice'));
649
- $config->get('test_mode') ? $helper->__('Payson test created an invoice'): $helper->__('Payson created an invoice'));
650
-
651
- //It creates the invoice to the order
652
- /*if($config->ActivateInvoiceOnPurchase())
653
- {
654
- $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
655
- $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
656
- $invoice->register();
657
- $transactionSave = Mage::getModel('core/resource_transaction')
658
- ->addObject($invoice)
659
- ->addObject($invoice->getOrder());
660
- $transactionSave->save();
661
- }*/
662
-
663
- if(isset($ipn_response->shippingAddress))
664
- {
665
- $address_info = $ipn_response->shippingAddress
666
- ->ToArray();
667
- //$address = $order->getBillingAddress();
668
- $address = $order->getShippingAddress();
669
-
670
- if(isset($address_info['name']))
671
- {
672
- $address->setFirstname($address_info['name']);
673
- $address->setMiddlename('');
674
- $address->setLastname('');
675
- }
676
-
677
- if(isset($address_info['streetAddress']))
678
- {
679
- $address->setStreet($address_info['streetAddress']);
680
- }
681
-
682
- if(isset($address_info['postalCode']))
683
- {
684
- $address->setPostcode($address_info['streetAddress']);
685
- }
686
-
687
- if(isset($address_info['city']))
688
- {
689
- $address->setCity($address_info['city']);
690
- }
691
-
692
- if(isset($address_info['country']))
693
- {
694
- // :(
695
- $foo = array
696
- (
697
- 'afghanistan' => 'AF',
698
- 'albania' => 'AL',
699
- 'algeria' => 'DZ',
700
- 'american samoa' => 'AS',
701
- 'andorra' => 'AD',
702
- 'angola' => 'AO',
703
- 'anguilla' => 'AI',
704
- 'antarctica' => 'AQ',
705
- 'antigua and barbuda' => 'AG',
706
- 'argentina' => 'AR',
707
- 'armenia' => 'AM',
708
- 'aruba' => 'AW',
709
- 'australia' => 'AU',
710
- 'austria' => 'AT',
711
- 'azerbaijan' => 'AZ',
712
- 'bahamas' => 'BS',
713
- 'bahrain' => 'BH',
714
- 'bangladesh' => 'BD',
715
- 'barbados' => 'BB',
716
- 'belarus' => 'BY',
717
- 'belgium' => 'BE',
718
- 'belize' => 'BZ',
719
- 'benin' => 'BJ',
720
- 'bermuda' => 'BM',
721
- 'bhutan' => 'BT',
722
- 'bolivia' => 'BO',
723
- 'bosnia and herzegovina' => 'BA',
724
- 'botswana' => 'BW',
725
- 'bouvet island' => 'BV',
726
- 'brazil' => 'BR',
727
- 'british indian ocean territory' => 'IO',
728
- 'brunei darussalam' => 'BN',
729
- 'bulgaria' => 'BG',
730
- 'burkina faso' => 'BF',
731
- 'burundi' => 'BI',
732
- 'cambodia' => 'KH',
733
- 'cameroon' => 'CM',
734
- 'canada' => 'CA',
735
- 'cape verde' => 'CV',
736
- 'cayman islands' => 'KY',
737
- 'central african republic' => 'CF',
738
- 'chad' => 'TD',
739
- 'chile' => 'CL',
740
- 'china' => 'CN',
741
- 'christmas island' => 'CX',
742
- 'cocos (keeling) islands' => 'CC',
743
- 'colombia' => 'CO',
744
- 'comoros' => 'KM',
745
- 'congo' => 'CG',
746
- 'congo, the democratic republic of the' => 'CD',
747
- 'cook islands' => 'CK',
748
- 'costa rica' => 'CR',
749
- 'cote d ivoire' => 'CI',
750
- 'croatia' => 'HR',
751
- 'cuba' => 'CU',
752
- 'cyprus' => 'CY',
753
- 'czech republic' => 'CZ',
754
- 'denmark' => 'DK',
755
- 'djibouti' => 'DJ',
756
- 'dominica' => 'DM',
757
- 'dominican republic' => 'DO',
758
- 'east timor' => 'TP',
759
- 'ecuador' => 'EC',
760
- 'egypt' => 'EG',
761
- 'el salvador' => 'SV',
762
- 'equatorial guinea' => 'GQ',
763
- 'eritrea' => 'ER',
764
- 'estonia' => 'EE',
765
- 'ethiopia' => 'ET',
766
- 'falkland islands (malvinas)' => 'FK',
767
- 'faroe islands' => 'FO',
768
- 'fiji' => 'FJ',
769
- 'finland' => 'FI',
770
- 'france' => 'FR',
771
- 'french guiana' => 'GF',
772
- 'french polynesia' => 'PF',
773
- 'french southern territories' => 'TF',
774
- 'gabon' => 'GA',
775
- 'gambia' => 'GM',
776
- 'georgia' => 'GE',
777
- 'germany' => 'DE',
778
- 'ghana' => 'GH',
779
- 'gibraltar' => 'GI',
780
- 'greece' => 'GR',
781
- 'greenland' => 'GL',
782
- 'grenada' => 'GD',
783
- 'guadeloupe' => 'GP',
784
- 'guam' => 'GU',
785
- 'guatemala' => 'GT',
786
- 'guinea' => 'GN',
787
- 'guinea-bissau' => 'GW',
788
- 'guyana' => 'GY',
789
- 'haiti' => 'HT',
790
- 'heard island and mcdonald islands' => 'HM',
791
- 'holy see (vatican city state)' => 'VA',
792
- 'honduras' => 'HN',
793
- 'hong kong' => 'HK',
794
- 'hungary' => 'HU',
795
- 'iceland' => 'IS',
796
- 'india' => 'IN',
797
- 'indonesia' => 'ID',
798
- 'iran, islamic republic of' => 'IR',
799
- 'iraq' => 'IQ',
800
- 'ireland' => 'IE',
801
- 'israel' => 'IL',
802
- 'italy' => 'IT',
803
- 'jamaica' => 'JM',
804
- 'japan' => 'JP',
805
- 'jordan' => 'JO',
806
- 'kazakstan' => 'KZ',
807
- 'kenya' => 'KE',
808
- 'kiribati' => 'KI',
809
- 'korea democratic peoples republic of' => 'KP',
810
- 'korea republic of' => 'KR',
811
- 'kuwait' => 'KW',
812
- 'kyrgyzstan' => 'KG',
813
- 'lao peoples democratic republic' => 'LA',
814
- 'latvia' => 'LV',
815
- 'lebanon' => 'LB',
816
- 'lesotho' => 'LS',
817
- 'liberia' => 'LR',
818
- 'libyan arab jamahiriya' => 'LY',
819
- 'liechtenstein' => 'LI',
820
- 'lithuania' => 'LT',
821
- 'luxembourg' => 'LU',
822
- 'macau' => 'MO',
823
- 'macedonia, the former yugoslav republic of' => 'MK',
824
- 'madagascar' => 'MG',
825
- 'malawi' => 'MW',
826
- 'malaysia' => 'MY',
827
- 'maldives' => 'MV',
828
- 'mali' => 'ML',
829
- 'malta' => 'MT',
830
- 'marshall islands' => 'MH',
831
- 'martinique' => 'MQ',
832
- 'mauritania' => 'MR',
833
- 'mauritius' => 'MU',
834
- 'mayotte' => 'YT',
835
- 'mexico' => 'MX',
836
- 'micronesia, federated states of' => 'FM',
837
- 'moldova, republic of' => 'MD',
838
- 'monaco' => 'MC',
839
- 'mongolia' => 'MN',
840
- 'montserrat' => 'MS',
841
- 'morocco' => 'MA',
842
- 'mozambique' => 'MZ',
843
- 'myanmar' => 'MM',
844
- 'namibia' => 'NA',
845
- 'nauru' => 'NR',
846
- 'nepal' => 'NP',
847
- 'netherlands' => 'NL',
848
- 'netherlands antilles' => 'AN',
849
- 'new caledonia' => 'NC',
850
- 'new zealand' => 'NZ',
851
- 'nicaragua' => 'NI',
852
- 'niger' => 'NE',
853
- 'nigeria' => 'NG',
854
- 'niue' => 'NU',
855
- 'norfolk island' => 'NF',
856
- 'northern mariana islands' => 'MP',
857
- 'norway' => 'NO',
858
- 'oman' => 'OM',
859
- 'pakistan' => 'PK',
860
- 'palau' => 'PW',
861
- 'palestinian territory, occupied' => 'PS',
862
- 'panama' => 'PA',
863
- 'papua new guinea' => 'PG',
864
- 'paraguay' => 'PY',
865
- 'peru' => 'PE',
866
- 'philippines' => 'PH',
867
- 'pitcairn' => 'PN',
868
- 'poland' => 'PL',
869
- 'portugal' => 'PT',
870
- 'puerto rico' => 'PR',
871
- 'qatar' => 'QA',
872
- 'reunion' => 'RE',
873
- 'romania' => 'RO',
874
- 'russian federation' => 'RU',
875
- 'rwanda' => 'RW',
876
- 'saint helena' => 'SH',
877
- 'saint kitts and nevis' => 'KN',
878
- 'saint lucia' => 'LC',
879
- 'saint pierre and miquelon' => 'PM',
880
- 'saint vincent and the grenadines' => 'VC',
881
- 'samoa' => 'WS',
882
- 'san marino' => 'SM',
883
- 'sao tome and principe' => 'ST',
884
- 'saudi arabia' => 'SA',
885
- 'senegal' => 'SN',
886
- 'seychelles' => 'SC',
887
- 'sierra leone' => 'SL',
888
- 'singapore' => 'SG',
889
- 'slovakia' => 'SK',
890
- 'slovenia' => 'SI',
891
- 'solomon islands' => 'SB',
892
- 'somalia' => 'SO',
893
- 'south africa' => 'ZA',
894
- 'south georgia and the south sandwich islands' => 'GS',
895
- 'spain' => 'ES',
896
- 'sri lanka' => 'LK',
897
- 'sudan' => 'SD',
898
- 'suriname' => 'SR',
899
- 'svalbard and jan mayen' => 'SJ',
900
- 'swaziland' => 'SZ',
901
- 'sweden' => 'SE',
902
- 'switzerland' => 'CH',
903
- 'syrian arab republic' => 'SY',
904
- 'taiwan, province of china' => 'TW',
905
- 'tajikistan' => 'TJ',
906
- 'tanzania, united republic of' => 'TZ',
907
- 'thailand' => 'TH',
908
- 'togo' => 'TG',
909
- 'tokelau' => 'TK',
910
- 'tonga' => 'TO',
911
- 'trinidad and tobago' => 'TT',
912
- 'tunisia' => 'TN',
913
- 'turkey' => 'TR',
914
- 'turkmenistan' => 'TM',
915
- 'turks and caicos islands' => 'TC',
916
- 'tuvalu' => 'TV',
917
- 'uganda' => 'UG',
918
- 'ukraine' => 'UA',
919
- 'united arab emirates' => 'AE',
920
- 'united kingdom' => 'GB',
921
- 'united states' => 'US',
922
- 'united states minor outlying islands' => 'UM',
923
- 'uruguay' => 'UY',
924
- 'uzbekistan' => 'UZ',
925
- 'vanuatu' => 'VU',
926
- 'venezuela' => 'VE',
927
- 'viet nam' => 'VN',
928
- 'virgin islands, british' => 'VG',
929
- 'virgin islands, u.s.' => 'VI',
930
- 'wallis and futuna' => 'WF',
931
- 'western sahara' => 'EH',
932
- 'yemen' => 'YE',
933
- 'yugoslavia' => 'YU',
934
- 'zambia' => 'ZM',
935
- 'zimbabwe' => 'ZW'
936
- );
937
-
938
- $address_info['country'] = strtolower(
939
- $address_info['country']);
940
-
941
- if(isset($foo[$address_info['country']]))
942
- {
943
- $address->setCountryId(
944
- $foo[$address_info['country']]);
945
- }
946
- }
947
-
948
- $address->save();
949
- $order->addStatusHistoryComment(sprintf($helper->__(
950
- 'Payson updated the shipping address')));
951
- }
952
- }
953
- else
954
- {
955
- $order->addStatusHistoryComment(sprintf(
956
- $helper->__('Payson pinged the order with status %s'),
957
- $ipn_response->status));
958
- }
959
-
960
- break;
961
- }
962
-
963
-
964
-
965
- case self::STATUS_ERROR:
966
- // throw new Mage_Core_Exception(sprintf($helper->__('Denaid.')));
967
-
968
- //Mage::throwException('Invalid order id (' . $order->getId() . ')');
969
-
970
- $order->setState(
971
- Mage_Sales_Model_Order::STATE_CANCELED,
972
- Mage_Sales_Model_Order::STATE_CANCELED,
973
- sprintf($helper->__(
974
- 'Ther order was denied by Payson.')))
975
- ->cancel();
976
- //throw new Mage_Core_Exception(sprintf($helper->__('Denaid.')));
977
- break;
978
-
979
-
980
-
981
- case self::STATUS_INCOMPLETE:
982
- case self::STATUS_EXPIRED:
983
- case self::STATUS_REVERSALERROR:
984
- default:
985
- {
986
- /*$order->setState(
987
- Mage_Sales_Model_Order::STATE_CANCELED,
988
- Mage_Sales_Model_Order::STATE_CANCELED,
989
- sprintf($helper->__(
990
- 'Payson cancelled the order with status %s'),
991
- $ipn_response->status))
992
- ->cancel();*/
993
- $order->cancel();
994
- }
995
- }
996
-
997
- $order->save();
998
-
999
- // Update the database tables
1000
- $db->update($order_log_table,
1001
- array
1002
- (
1003
- 'valid' => 1
1004
- ),
1005
- array
1006
- (
1007
- 'id = ?' => $order_log_id
1008
- ));
1009
-
1010
- $db->update($order_table,
1011
- array
1012
- (
1013
- 'ipn_status' => $ipn_response->status
1014
- ),
1015
- array
1016
- (
1017
- 'id = ?' => $payson_order->id
1018
- ));
1019
-
1020
- return $this;
1021
- }
1022
-
1023
- /**
1024
- * http://api.payson.se/#title12
1025
- *
1026
- * @params int $order_id Real order id
1027
- * @return object $this
1028
- */
1029
- public function PaymentDetails($order_id)
1030
- {
1031
- $helper = Mage::helper('payson');
1032
-
1033
- // Get the database connection
1034
- $resource = Mage::getSingleton('core/resource');
1035
- $db = $resource->getConnection('core_write');
1036
-
1037
- $order_table = $resource->getTableName('payson_order');
1038
- $order_log_table = $resource->getTableName('payson_order_log');
1039
-
1040
- /* Save fetch mode so that we can reset it and not mess up Magento
1041
- functionality */
1042
- $old_fetch_mode = $db->getFetchMode();
1043
- $db->setFetchMode(Zend_Db::FETCH_OBJ);
1044
-
1045
- // Get payson order information and validate token
1046
- $payson_order = $db->fetchRow(
1047
- 'SELECT
1048
  id,
1049
  token,
1050
  store_id
@@ -1057,72 +919,68 @@ AND
1057
  LIMIT
1058
  0,1', $order_id);
1059
 
1060
- if($payson_order === false)
1061
- {
1062
- Mage::throwException('Invalid order id (' . $order_id . ')');
1063
- }
1064
-
1065
- $db->setFetchMode($old_fetch_mode);
1066
-
1067
- $args = array
1068
- (
1069
- 'token' => $payson_order->token
1070
- );
1071
- $url = vsprintf(self::API_CALL_PAYMENT_DETAILS, $this->GetFormatIfTest($payson_order->store_id));
1072
- print_r($url);exit;
1073
- $client = $this->GetHttpClient($url)
1074
- ->setParameterPost($args);
1075
-
1076
- $response = Payson_Payson_Helper_Api_Response_Standard
1077
- ::FromHttpBody($client->request()->getBody());
1078
-
1079
- $this->SetResponse($response);
1080
-
1081
- $db->insert($order_log_table, array
1082
- (
1083
- 'payson_order_id' => $payson_order->id,
1084
- 'added' => new Zend_Db_Expr('NOW()'),
1085
- 'api_call' => 'payment_details',
1086
- 'valid' => (int)$response->IsValid(),
1087
- 'response' => serialize($response->ToArray())
1088
- ));
1089
-
1090
- if(!$response->IsValid())
1091
- {
1092
- throw new Mage_Core_Exception(sprintf($helper->__(
1093
- 'Failed to retrieve payment details. Payson replied: %s'),
1094
- $response->GetError()), $response->GetErrorId());
1095
- }
1096
-
1097
- return $this;
1098
- }
1099
-
1100
- /**
1101
- * http://api.payson.se/#title13
1102
- *
1103
- * @params int $order_id Real order id
1104
- * @params string $action
1105
- * @return object $this
1106
- */
1107
- public function PaymentUpdate($order_id, $action)
1108
- {
1109
- $helper = Mage::helper('payson');
1110
-
1111
- // Get the database connection
1112
- $resource = Mage::getSingleton('core/resource');
1113
- $db = $resource->getConnection('core_write');
1114
-
1115
- $order_table = $resource->getTableName('payson_order');
1116
- $order_log_table = $resource->getTableName('payson_order_log');
1117
-
1118
- /* Save fetch mode so that we can reset it and not mess up Magento
1119
- functionality */
1120
- $old_fetch_mode = $db->getFetchMode();
1121
- $db->setFetchMode(Zend_Db::FETCH_OBJ);
1122
-
1123
- // Get payson order information and validate token
1124
- $payson_order = $db->fetchRow(
1125
- 'SELECT
1126
  id,
1127
  token,
1128
  store_id
@@ -1135,95 +993,88 @@ AND
1135
  LIMIT
1136
  0,1', $order_id);
1137
 
1138
- if($payson_order === false)
1139
- {
1140
- Mage::throwException('Invalid order id (' . $order_id . ')');
1141
- }
1142
-
1143
- $db->setFetchMode($old_fetch_mode);
1144
-
1145
- $args = array
1146
- (
1147
- 'token' => $payson_order->token,
1148
- 'action' => $action
1149
- );
1150
-
1151
- $client = $this->GetHttpClient(vsprintf(self::API_CALL_PAYMENT_UPDATE, $this->GetFormatIfTest($payson_order->store_id)))
1152
- ->setParameterPost($args);
1153
-
1154
- $response = Payson_Payson_Helper_Api_Response_Standard
1155
- ::FromHttpBody($client->request()->getBody());
1156
-
1157
- $this->SetResponse($response);
1158
-
1159
- $db->insert($order_log_table, array
1160
- (
1161
- 'payson_order_id' => $payson_order->id,
1162
- 'added' => new Zend_Db_Expr('NOW()'),
1163
- 'api_call' => 'payment_update',
1164
- 'valid' => (int)$response->IsValid(),
1165
- 'response' => serialize($response->ToArray())
1166
- ));
1167
-
1168
- /*if(!$response->IsValid())
1169
- {
1170
- // TODO: don't seem to return an errorList
1171
- throw new Mage_Core_Exception(sprintf($helper->__(
1172
- 'Failed to update payment. Payson replied: %s'),
1173
- $response->GetError()), $response->GetErrorId());
1174
- }*/
1175
-
1176
- return $this;
1177
- }
1178
-
1179
- private function GetFormatIfTest($storeID = null, $isForwardURL = FALSE)
1180
- {
1181
- $config = Mage::getModel('payson/config');
1182
- $stack = array();
1183
- /* @var $isTest bool */
1184
- $isTest = ($config->get('test_mode', $storeID) == "1");
1185
-
1186
- array_push($stack, self::DEBUG_MODE ? "http" : "https");
1187
- array_push($stack, $isTest && !self::DEBUG_MODE ? "test-" : (self::DEBUG_MODE && !$isForwardURL ? "mvc" : ""));
1188
-
1189
- if($isForwardURL == true)
1190
- {
1191
- array_push($stack, self::DEBUG_MODE ? "app" : "www");
1192
- }
1193
-
1194
- array_push($stack, self::DEBUG_MODE ? "local" : "se");
1195
- array_push($stack, self::DEBUG_MODE ? "Payment" : "1.0");
1196
-
1197
- array_push($stack, self::DEBUG_MODE ? "" : "Payment");
1198
- //print_r($stack);exit;
1199
- return $stack;
1200
-
1201
-
1202
  }
1203
-
1204
- public function getIpnStatus($order_id)
1205
- {
1206
- $resource = Mage::getSingleton('core/resource');
1207
- $db = $resource->getConnection('core_write');
1208
- $order_table = $resource->getTableName('payson_order');
1209
- $query = 'SELECT ipn_status FROM `' . $order_table . '` WHERE order_id = ' . $order_id;
1210
- return $db->fetchRow($query);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1211
  }
1212
-
1213
- public function paysonApiError($error)
1214
- {
1215
- $error_code = '<html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1216
  <head>
1217
  <meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
1218
  <script type="text/javascript">
1219
- alert("'.$error.'");
1220
- window.location="'.('/index.php').'";
1221
  </script>
1222
  </head>
1223
  </html>';
1224
- echo $error_code;
1225
- exit;
1226
-
1227
- }
1228
  }
1229
 
1
  <?php
2
+
3
+ class Payson_Payson_Helper_Api {
4
+ /*
5
+ * Constants
6
+ */
7
+
8
+ const DEBUG_MODE = false;
9
+ const API_CALL_PAY = '%s://%sapi.payson.%s/%s/Pay/';
10
+ const API_CALL_VALIDATE = '%s://%sapi.payson.%s/%s/Validate/';
11
+ const API_CALL_PAYMENT_DETAILS = '%s://%sapi.payson.%s/%s/%sDetails/';
12
+ const API_CALL_PAYMENT_UPDATE = '%s://%sapi.payson.%s/%s/%sUpdate/';
13
+ const PAY_FORWARD_URL = '%s://%s%s.payson.%s/paySecure/';
14
+ const APPLICATION_ID = 'Magento Module 1.0';
15
+ const MODULE_NAME = 'payson_magento';
16
+ const MODULE_VERSION = '1.0';
17
+ const DEBUG_MODE_MAIL = 'testagent-1@payson.se';
18
+ const DEBUG_MODE_AGENT_ID = '1';
19
+ const DEBUG_MODE_MD5 = 'fddb19ac-7470-42b6-a91d-072cb1495f0a';
20
+ const STATUS_CREATED = 'CREATED';
21
+ const STATUS_PENDING = 'PENDING';
22
+ const STATUS_PROCESSING = 'PROCESSING';
23
+ const STATUS_COMPLETED = 'COMPLETED';
24
+ const STATUS_CREDITED = 'CREDITED';
25
+ const STATUS_INCOMPLETE = 'INCOMPLETE';
26
+ const STATUS_ERROR = 'ERROR';
27
+ const STATUS_EXPIRED = 'EXPIRED';
28
+ const STATUS_REVERSALERROR = 'REVERSALERROR';
29
+ const PAYMENT_METHOD_BANK = 'BANK';
30
+ const PAYMENT_METHOD_CREDITCARD = 'CREDITCARD';
31
+ const PAYMENT_METHOD_INVOICE = 'INVOICE';
32
+ const GUARANTEE_STATUS_WAITINGFORSEND = 'WAITINGFORSEND';
33
+ const GUARANTEE_STATUS_WAITINGFORACCEPTANCE = 'WAITINGFORACCEPTANCE';
34
+ const GUARANTEE_STATUS_WAITINGFORRETURN = 'WAITINGFORRETURN';
35
+ const GUARANTEE_STATUS_WAITINGFORRETURNACCEPTANCE = 'WAITINGFORRETURNACCEPTANCE';
36
+ const GUARANTEE_STATUS_RETURNNOTACCEPTED = 'RETURNNOTACCEPTED';
37
+ const GUARANTEE_STATUS_NOTRECEIVED = 'NOTRECEIVED';
38
+ const GUARANTEE_STATUS_RETURNNOTRECEIVED = 'RETURNNOTRECEIVED';
39
+ const GUARANTEE_STATUS_MONEYRETURNEDTOSENDER = 'MONEYRETURNEDTOSENDER';
40
+ const GUARANTEE_STATUS_RETURNACCEPTED = 'RETURNACCEPTED';
41
+ const INVOICE_STATUS_PENDING = 'PENDING';
42
+ const INVOICE_STATUS_ORDERCREATED = 'ORDERCREATED';
43
+ const INVOICE_STATUS_ORDERCANCELLED = 'ORDERCANCELLED';
44
+ const INVOICE_STATUS_SHIPPED = 'SHIPPED';
45
+ const INVOICE_STATUS_DONE = 'DONE';
46
+ const UPDATE_ACTION_CANCELORDER = 'CANCELORDER';
47
+ const UPDATE_ACTION_SHIPORDER = 'SHIPORDER';
48
+ const UPDATE_ACTION_CREDITORDER = 'CREDITORDER';
49
+ const UPDATE_ACTION_REFUNDORDER = 'REFUND';
50
+ const GUARANTEE_REQUIRED = 'REQUIRED';
51
+ const GUARANTEE_OPTIONAL = 'OPTIONAL';
52
+ const GUARANTEE_NO = 'NO';
53
+
54
+ /*
55
+ * Private properties
56
+ */
57
+
58
+ private $response;
59
+ private $order_discount_item = 0.0;
60
+
61
+ /*
62
+ * Private methods
63
+ */
64
+
65
+ private function GetHttpClient($url) {
66
+ $config = Mage::getModel('payson/config');
67
+
68
+ $http_client = new Zend_Http_Client($url);
69
+
70
+ $http_client->setMethod(Zend_Http_Client::POST)
71
+ ->setHeaders(array
72
+ (
73
+ 'PAYSON-SECURITY-USERID' => $config->get('test_mode') ? self::DEBUG_MODE_AGENT_ID : $config->Get('agent_id'),
74
+ 'PAYSON-SECURITY-PASSWORD' => $config->get('test_mode') ? self::DEBUG_MODE_MD5 : $config->Get('md5_key'),
75
+ 'PAYSON-APPLICATION-ID' => self::APPLICATION_ID,
76
+ 'PAYSON-MODULE-INFO' => self::MODULE_NAME . '|' . self::MODULE_VERSION . '|' . Mage::getVersion()
77
+ ));
78
+
79
+ return $http_client->resetParameters();
80
+ }
81
+
82
+ private function SetResponse(
83
+ Payson_Payson_Helper_Api_Response_Interface $response) {
84
+ $this->response = $response;
85
+
86
+ return $this;
87
+ }
88
+
89
+ private function SetOrderDiscountItem($item, &$total) {
90
+ $total -= $item->getData('discount_amount');
91
+ $this->order_discount_item += $item->getData('discount_amount');
92
+ }
93
+
94
+ /**
95
+ * Helper for Pay()
96
+ *
97
+ * @param object $item
98
+ * @param int $i
99
+ * @param int $total
100
+ * @return array
101
+ */
102
+ private function GetOrderItemInfo($item, $i, &$total) {
103
+ $product = Mage::getModel('catalog/product')
104
+ ->load($item->getProductId());
105
+ $children = $item->getChildrenItems();
106
+
107
+ if (!$product->isConfigurable() && count($children) &&
108
+ !$item->isChildrenCalculated()) {
109
+ $args = array();
110
+ foreach ($children as $child) {
111
+ $args += $this->GetOrderItemInfo($child, $i++, $total);
112
+ }
113
+ return $args;
114
  }
115
 
116
+ if ($product->isConfigurable() && (count($children) === 1)) {
117
+ $name = $children[0]->getData('name');
118
+ $sku = $children[0]->getData('sku');
119
+ } else {
120
+ $name = $product->getData('name');
121
+ $sku = $item->getData('sku');
122
+ }
123
+
124
+ /* TODO: If tax_percent is not set?
125
+ Mage::getSingleton('tax/calculation')->getRate(
126
+ $tax_rate_req->setProductClassId($product->getTaxClassId()))
127
+ */
128
+ $tax_mod = (float) $item->getData('tax_percent');
129
+ $tax_mod /= 100;
130
+ $tax_mod = round($tax_mod, 5);
131
+
132
+ $qty = (float) $item->getData('qty_ordered');
133
+ $qty = round($qty, 2);
134
+
135
+ $price = (float) $item->getData('row_total_incl_tax');
136
+
137
+ $base_price = (($price / (1 + $tax_mod)) / $qty);
138
+ $base_price = round($base_price, 3);
139
+
140
+ $total += (($base_price * (1 + $tax_mod)) * $qty);
141
+
142
+ return array
143
+ (
144
+ 'orderItemList.orderItem(' . $i . ').description' =>
145
+ $name,
146
+ 'orderItemList.orderItem(' . $i . ').sku' =>
147
+ $sku,
148
+ 'orderItemList.orderItem(' . $i . ').quantity' =>
149
+ $qty,
150
+ 'orderItemList.orderItem(' . $i . ').unitPrice' =>
151
+ $base_price,
152
+ 'orderItemList.orderItem(' . $i . ').taxPercentage' =>
153
+ $tax_mod
154
+ );
155
+ }
156
+
157
+ /**
158
+ * Helper for Pay()
159
+ *
160
+ * @param object $order
161
+ * @param object $customer
162
+ * @param object $store
163
+ * @param int $i
164
+ * @param int $total
165
+ * @return array
166
+ */
167
+ private function GetOrderShippingInfo($order, $customer, $store, $i, &$total) {
168
+ $tax_calc = Mage::getSingleton('tax/calculation');
169
+
170
+ $tax_rate_req = $tax_calc->getRateRequest(
171
+ $order->getShippingAddress(), $order->getBillingAddress(), $customer->getTaxClassId(), $store);
172
+
173
+ $args = array();
174
+
175
+ if (($price = (float) $order->getData('shipping_incl_tax')) > 0) {
176
+ $tax_mod = $tax_calc->getRate($tax_rate_req->setProductClassId(
177
+ Mage::getStoreConfig('tax/classes/shipping_tax_class')));
178
+ $tax_mod /= 100;
179
+ $tax_mod = round($tax_mod, 5);
180
+
181
+ $price -= (float) $order->getData('shipping_discount_amount');
182
+
183
+ $base_price = ($price / (1 + $tax_mod));
184
+ $base_price = round($base_price, 3);
185
+
186
+ $total += ($base_price * (1 + $tax_mod));
187
+
188
+ $args = array
189
+ (
190
+ 'orderItemList.orderItem(' . $i . ').description' =>
191
+ $order->getData('shipping_description'),
192
+ 'orderItemList.orderItem(' . $i . ').sku' =>
193
+ $order->getData('shipping_method'),
194
+ 'orderItemList.orderItem(' . $i . ').quantity' =>
195
+ 1,
196
+ 'orderItemList.orderItem(' . $i . ').unitPrice' =>
197
+ $base_price,
198
+ 'orderItemList.orderItem(' . $i . ').taxPercentage' =>
199
+ $tax_mod
200
+ );
201
+ }
202
+ return $args;
203
+ }
204
+
205
+ /*
206
+ * Public methods
207
+ */
208
+
209
+ /**
210
+ * Get API response
211
+ *
212
+ * @return object
213
+ */
214
+ public function GetResponse() {
215
+ return $this->response;
216
+ }
217
+
218
+ /**
219
+ * Get forward/redirect url after a successful Pay() call
220
+ *
221
+ * @return string
222
+ */
223
+ public function GetPayForwardUrl() {
224
+ $url = vsprintf(self::PAY_FORWARD_URL . '?token=' . $this->GetResponse()->TOKEN, $this->GetFormatIfTest(null, true));
225
+ return $url;
226
+ }
227
+
228
+ /**
229
+ * http://api.payson.se/#title8
230
+ *
231
+ * @param object $order
232
+ * @return object $this
233
+ */
234
+ public function Pay(Mage_Sales_Model_Order $order) {
235
+ $payment_method = $order->getPayment()->getMethod();
236
+ $helper = Mage::helper('payson');
237
+ $config = Mage::getModel('payson/config');
238
+ $store = Mage::app()->getStore($order->getStoreId());
239
+ $customer = Mage::getModel('customer/customer')
240
+ ->load($order->getCustomerId());
241
+ $billing_address = $order->getBillingAddress();
242
+
243
+ // Need a two character locale code
244
+ $locale_code = Mage::getSingleton('core/locale')->getLocaleCode();
245
+ $locale_code = strtoupper(substr($locale_code, 0, 2));
246
+
247
+ if (!in_array($locale_code, array('SV', 'FI', 'EN'))) {
248
+ switch ($locale_code) {
249
+ case 'DA':
250
+ case 'NO': {
251
+ $locale_code = 'SV';
252
+ break;
253
+ }
254
+ default: {
255
+ $locale_code = 'EN';
256
+ }
257
+ }
258
+ }
259
+
260
+ // $args will contain the arguments of the API request to Payson
261
+ $args = array
262
+ (
263
+ 'returnUrl' =>
264
+ Mage::getUrl('payson/checkout/return', array('_secure' => true)),
265
+ 'cancelUrl' =>
266
+ Mage::getUrl('payson/checkout/cancel', array('_secure' => true)),
267
+ 'ipnNotificationUrl' =>
268
+ Mage::getUrl('payson/ipn/notify', array('_secure' => true)),
269
+ 'localeCode' =>
270
+ $locale_code,
271
+ 'currencyCode' =>
272
+ //$order->getOrderCurrency()->getCode(),
273
+ //$order->getBaseCurrencyCode(),
274
+ strtoupper(substr($order->getOrderCurrency()->getCode(), 0, 3)),
275
+ 'memo' =>
276
+ sprintf($helper->__('Order from %s'), $store->getUrl()),
277
+ 'senderEmail' =>
278
+ $order->getCustomerEmail(),
279
+ 'senderFirstName' =>
280
+ $billing_address->getFirstname(),
281
+ 'senderLastName' =>
282
+ $billing_address->getLastname(),
283
+ 'receiverList.receiver(0).email' =>
284
+ $config->get('test_mode') ? self::DEBUG_MODE_MAIL : $config->Get('email'),
285
+ 'trackingId' => $order->getRealOrderId()
286
+ );
287
+
288
+ if (!$config->CanPaymentGuarantee()) {
289
+ $args['guaranteeOffered'] = self::GUARANTEE_NO;
290
+ }
291
+
292
+ if (($payment_method === 'payson_invoice')) {
293
+ if (!$config->CanInvoicePayment()) {
294
+ Mage::throwException('Invoice payment is disabled');
295
+ }
296
+
297
+ $args['fundingList.fundingConstraint(0).constraint'] =
298
+ self::PAYMENT_METHOD_INVOICE;
299
+ }
300
+
301
+ $i = 0;
302
+ $total = 0;
303
+
304
+ // Calculate price of each item in the order
305
+ foreach ($order->getAllVisibleItems() as $item) {
306
+ $args += $this->GetOrderItemInfo($item, $i++, $total);
307
+ }
308
+
309
+ foreach ($order->getAllVisibleItems() as $item) {
310
+ $this->SetOrderDiscountItem($item, $total);
311
+ }
312
+ if ($this->order_discount_item >> 0) {
313
+ $args += array
314
+ (
315
+ 'orderItemList.orderItem(' . $i . ').description' =>
316
+ 'discount',
317
+ 'orderItemList.orderItem(' . $i . ').sku' =>
318
+ 'discount',
319
+ 'orderItemList.orderItem(' . $i . ').quantity' =>
320
+ 1,
321
+ 'orderItemList.orderItem(' . $i . ').unitPrice' =>
322
+ -$this->order_discount_item,
323
+ 'orderItemList.orderItem(' . $i . ').taxPercentage' =>
324
+ 0.0
325
+ );
326
+ }
327
+ // Calculate price for shipping
328
+ $args += $this->GetOrderShippingInfo($order, $customer, $store, $i++, $total);
329
+ /* echo '<pre>';
330
+ print_r($args);
331
+ echo '</pre>';exit; */
332
+ if ($order->getPaysonInvoiceFee() > 0) {
333
+ $fee = $order->getPaysonInvoiceFee();
334
+ /* $args += array
335
+ (
336
+ 'orderItemList.orderItem(' . $i . ').description' =>
337
+ $helper->__('Invoice fee'),
338
+ 'orderItemList.orderItem(' . $i . ').sku' =>
339
+ 'invoice_fee',
340
+ 'orderItemList.orderItem(' . $i . ').quantity' =>
341
+ 1,
342
+ 'orderItemList.orderItem(' . $i . ').unitPrice' =>
343
+ $config->GetInvoiceFee($order),
344
+ 'orderItemList.orderItem(' . $i . ').taxPercentage' =>
345
+ $config->GetInvoiceFeeTaxMod($order)
346
+ );
347
+
348
+ $total += $config->GetInvoiceFeeInclTax($order); */
349
+
350
+ $args['invoiceFee'] = round((float) $fee, 3);
351
+ $total += $fee;
352
+ }
353
+
354
+ $total = round($total, 2);
355
+
356
+ $args['receiverList.receiver(0).amount'] = $total;
357
+
358
+ //echo('<pre>');print_r($args);exit(PHP_EOL . $order->getData('grand_total') . '</pre>');
359
+ $url = vsprintf(self::API_CALL_PAY, $this->GetFormatIfTest($order->getStoreId()));
360
+ $client = $this->GetHttpClient($url)
361
+ ->setParameterPost($args);
362
+
363
+ $response = Payson_Payson_Helper_Api_Response_Standard
364
+ ::FromHttpBody($client->request()->getBody());
365
+
366
+ $this->SetResponse($response);
367
+
368
+ $resource = Mage::getSingleton('core/resource');
369
+ $db = $resource->getConnection('core_write');
370
+
371
+ $order_table = $resource->getTableName('payson_order');
372
+ $order_log_table = $resource->getTableName('payson_order_log');
373
+
374
+ $db->insert($order_table, array
375
+ (
376
+ 'order_id' => $order->getRealOrderId(),
377
+ 'added' => new Zend_Db_Expr('NOW()'),
378
+ 'updated' => new Zend_Db_Expr('NOW()'),
379
+ 'valid' => (int) $response->IsValid(),
380
+ 'token' => (isset($response->TOKEN) ? $response->TOKEN :
381
+ new Zend_Db_Expr('NULL')),
382
+ 'store_id' => $order->getStoreId()
383
+ ));
384
+
385
+ $payson_order_id = $db->lastInsertId();
386
+
387
+ $db->insert($order_log_table, array
388
+ (
389
+ 'payson_order_id' => $payson_order_id,
390
+ 'added' => new Zend_Db_Expr('NOW()'),
391
+ 'api_call' => 'pay',
392
+ 'valid' => (int) $response->IsValid(),
393
+ 'response' => serialize($response->ToArray())
394
+ ));
395
+
396
+ if (!$response->IsValid()) {
397
+
398
+ throw new Mage_Core_Exception(sprintf($helper->__(
399
+ 'Failed to initialize payment. Payson replied: %s'), $response->GetError()), $response->GetErrorId());
400
+ }
401
+
402
+ return $this;
403
+ }
404
+
405
+ /**
406
+ * Implements the IPN procedure
407
+ *
408
+ * http://api.payson.se/#title11
409
+ *
410
+ * @param string $http_body
411
+ * @param string $content_type
412
+ * @return object $this
413
+ */
414
+ public function Validate($http_body, $content_type) {
415
+ $helper = Mage::helper('payson');
416
+ $config = Mage::getModel('payson/config');
417
+ // Parse request done by Payson to our IPN controller
418
+ $ipn_response = Payson_Payson_Helper_Api_Response_Standard
419
+ ::FromHttpBody($http_body);
420
+
421
+ // Get the database connection
422
+ $resource = Mage::getSingleton('core/resource');
423
+ $db = $resource->getConnection('core_write');
424
+
425
+ $order_table = $resource->getTableName('payson_order');
426
+ $order_log_table = $resource->getTableName('payson_order_log');
427
+
428
+ /* Save data sent by Payson, log entry as invalid by default, this
429
+ value will be changed later in this method if successful. No payson
430
+ order id is set, because we dont have one yet */
431
+ $db->insert($order_log_table, array
432
+ (
433
+ 'added' => new Zend_Db_Expr('NOW()'),
434
+ 'api_call' => 'validate',
435
+ 'valid' => 0,
436
+ 'response' => serialize($ipn_response->ToArray())
437
+ ));
438
+
439
+ $order_log_id = $db->lastInsertId();
440
+
441
+ /* $ipn_response will never contain responseEnvelope.ack, as I first
442
+ thought it would */
443
+ /* if(!$ipn_response->IsValid())
444
+ {
445
+ Mage::throwException('Invalid request');
446
+ } */
447
+
448
+ /* Save fetch mode so that we can reset it and not mess up Magento
449
+ functionality */
450
+ $old_fetch_mode = $db->getFetchMode();
451
+ $db->setFetchMode(Zend_Db::FETCH_OBJ);
452
+
453
+ // Get payson order information and validate token
454
+ $payson_order = $db->fetchRow(
455
+ 'SELECT
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
456
  id,
457
  order_id,
458
  store_id
465
  LIMIT
466
  0,1', $ipn_response->token);
467
 
468
+ if ($payson_order === false) {
469
+ Mage::throwException('Invalid token');
470
+ }
471
+
472
+ // Do the validate API call
473
+ $client = $this->GetHttpClient(vsprintf(self::API_CALL_VALIDATE, $this->GetFormatIfTest($payson_order->store_id)))
474
+ ->setRawData($http_body, $content_type);
475
+
476
+ $response = Payson_Payson_Helper_Api_Response_Validate
477
+ ::FromHttpBody($client->request()->getBody());
478
+
479
+ $this->SetResponse($response);
480
+
481
+ if (!$response->IsValid()) {
482
+ Mage::throwException('Validate call was unsuccessful');
483
+ }
484
+
485
+
486
+
487
+ // Update order log with payson order id
488
+ $db->update($order_log_table, array
489
+ (
490
+ 'payson_order_id' => $payson_order->id
491
+ ), array
492
+ (
493
+ 'id = ?' => $order_log_id
494
+ ));
495
+
496
+ // the order model does not expect FETCH_OBJ!
497
+ $db->setFetchMode($old_fetch_mode);
498
+
499
+ /**
500
+ * @var Mage_Sales_Model_Order
501
+ */
502
+ $order = Mage::getModel('sales/order')
503
+ ->loadByIncrementId($payson_order->order_id);
504
+
505
+ // Stop if order dont exist
506
+ if (is_null($order->getId())) {
507
+ Mage::throwException('Invalid order');
508
+ }
509
+
510
+ if ($order->getState() === Mage_Sales_Model_Order::STATE_COMPLETE) {
511
+ Mage::throwException('Order is no longer active');
512
+ }
513
+
514
+ $receivers = $ipn_response->receiverList->receiver->ToArray();
515
+
516
+ /* Verify payment amount. floor() since there might be a precision
517
+ difference */
518
+ if (floor((float) $receivers[0]['amount']) !==
519
+ floor((float) $order->getTotalDue())) {
520
+ Mage::throwException('Invalid amount');
521
+ }
522
+
523
+ switch ($ipn_response->status) {
524
+ case self::STATUS_COMPLETED: {
525
+ //Changes the status of the order from pending_payment to processing
526
+ $order->setState(
527
+ Mage_Sales_Model_Order::STATE_PROCESSING, Mage_Sales_Model_Order::STATE_PROCESSING,
528
+ //$helper->__('Payson completed the order payment XXXXXXX'));
529
+ $config->get('test_mode') ? $helper->__('Payson test completed the order payment') : $helper->__('Payson completed the order payment'));
530
+
531
+ //It creates the invoice to the order
532
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
533
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
534
+ $invoice->register();
535
+ $transactionSave = Mage::getModel('core/resource_transaction')
536
+ ->addObject($invoice)
537
+ ->addObject($invoice->getOrder());
538
+ $transactionSave->save();
539
+
540
+ break;
541
+ }
542
+ case self::STATUS_CREATED:
543
+ case self::STATUS_PENDING:
544
+ case self::STATUS_PROCESSING:
545
+ case self::STATUS_CREDITED: {
546
+ if (($ipn_response->status === self::STATUS_PENDING) &&
547
+ ($ipn_response->type === self::PAYMENT_METHOD_INVOICE) &&
548
+ ($ipn_response->invoiceStatus ===
549
+ self::INVOICE_STATUS_ORDERCREATED)) {
550
+ //Changes the status of the order from pending to processing
551
+ $order->setState(
552
+ Mage_Sales_Model_Order::STATE_PROCESSING, Mage_Sales_Model_Order::STATE_PROCESSING,
553
+ //$helper->__('Payson created an invoice'));
554
+ $config->get('test_mode') ? $helper->__('Payson test created an invoice') : $helper->__('Payson created an invoice'));
555
+
556
+
557
+
558
+ if (isset($ipn_response->shippingAddress)) {
559
+ $address_info = $ipn_response->shippingAddress
560
+ ->ToArray();
561
+
562
+ $address = $order->getShippingAddress();
563
+
564
+ if (isset($address_info['name'])) {
565
+ $address->setFirstname($address_info['name']);
566
+ $address->setMiddlename('');
567
+ $address->setLastname('');
568
+ }
569
+
570
+ if (isset($address_info['streetAddress'])) {
571
+ $address->setStreet($address_info['streetAddress']);
572
+ }
573
+
574
+ if (isset($address_info['postalCode'])) {
575
+ $address->setPostcode($address_info['streetAddress']);
576
+ }
577
+
578
+ if (isset($address_info['city'])) {
579
+ $address->setCity($address_info['city']);
580
+ }
581
+
582
+ if (isset($address_info['country'])) {
583
+ // :(
584
+ $foo = array
585
+ (
586
+ 'afghanistan' => 'AF',
587
+ 'albania' => 'AL',
588
+ 'algeria' => 'DZ',
589
+ 'american samoa' => 'AS',
590
+ 'andorra' => 'AD',
591
+ 'angola' => 'AO',
592
+ 'anguilla' => 'AI',
593
+ 'antarctica' => 'AQ',
594
+ 'antigua and barbuda' => 'AG',
595
+ 'argentina' => 'AR',
596
+ 'armenia' => 'AM',
597
+ 'aruba' => 'AW',
598
+ 'australia' => 'AU',
599
+ 'austria' => 'AT',
600
+ 'azerbaijan' => 'AZ',
601
+ 'bahamas' => 'BS',
602
+ 'bahrain' => 'BH',
603
+ 'bangladesh' => 'BD',
604
+ 'barbados' => 'BB',
605
+ 'belarus' => 'BY',
606
+ 'belgium' => 'BE',
607
+ 'belize' => 'BZ',
608
+ 'benin' => 'BJ',
609
+ 'bermuda' => 'BM',
610
+ 'bhutan' => 'BT',
611
+ 'bolivia' => 'BO',
612
+ 'bosnia and herzegovina' => 'BA',
613
+ 'botswana' => 'BW',
614
+ 'bouvet island' => 'BV',
615
+ 'brazil' => 'BR',
616
+ 'british indian ocean territory' => 'IO',
617
+ 'brunei darussalam' => 'BN',
618
+ 'bulgaria' => 'BG',
619
+ 'burkina faso' => 'BF',
620
+ 'burundi' => 'BI',
621
+ 'cambodia' => 'KH',
622
+ 'cameroon' => 'CM',
623
+ 'canada' => 'CA',
624
+ 'cape verde' => 'CV',
625
+ 'cayman islands' => 'KY',
626
+ 'central african republic' => 'CF',
627
+ 'chad' => 'TD',
628
+ 'chile' => 'CL',
629
+ 'china' => 'CN',
630
+ 'christmas island' => 'CX',
631
+ 'cocos (keeling) islands' => 'CC',
632
+ 'colombia' => 'CO',
633
+ 'comoros' => 'KM',
634
+ 'congo' => 'CG',
635
+ 'congo, the democratic republic of the' => 'CD',
636
+ 'cook islands' => 'CK',
637
+ 'costa rica' => 'CR',
638
+ 'cote d ivoire' => 'CI',
639
+ 'croatia' => 'HR',
640
+ 'cuba' => 'CU',
641
+ 'cyprus' => 'CY',
642
+ 'czech republic' => 'CZ',
643
+ 'denmark' => 'DK',
644
+ 'djibouti' => 'DJ',
645
+ 'dominica' => 'DM',
646
+ 'dominican republic' => 'DO',
647
+ 'east timor' => 'TP',
648
+ 'ecuador' => 'EC',
649
+ 'egypt' => 'EG',
650
+ 'el salvador' => 'SV',
651
+ 'equatorial guinea' => 'GQ',
652
+ 'eritrea' => 'ER',
653
+ 'estonia' => 'EE',
654
+ 'ethiopia' => 'ET',
655
+ 'falkland islands (malvinas)' => 'FK',
656
+ 'faroe islands' => 'FO',
657
+ 'fiji' => 'FJ',
658
+ 'finland' => 'FI',
659
+ 'france' => 'FR',
660
+ 'french guiana' => 'GF',
661
+ 'french polynesia' => 'PF',
662
+ 'french southern territories' => 'TF',
663
+ 'gabon' => 'GA',
664
+ 'gambia' => 'GM',
665
+ 'georgia' => 'GE',
666
+ 'germany' => 'DE',
667
+ 'ghana' => 'GH',
668
+ 'gibraltar' => 'GI',
669
+ 'greece' => 'GR',
670
+ 'greenland' => 'GL',
671
+ 'grenada' => 'GD',
672
+ 'guadeloupe' => 'GP',
673
+ 'guam' => 'GU',
674
+ 'guatemala' => 'GT',
675
+ 'guinea' => 'GN',
676
+ 'guinea-bissau' => 'GW',
677
+ 'guyana' => 'GY',
678
+ 'haiti' => 'HT',
679
+ 'heard island and mcdonald islands' => 'HM',
680
+ 'holy see (vatican city state)' => 'VA',
681
+ 'honduras' => 'HN',
682
+ 'hong kong' => 'HK',
683
+ 'hungary' => 'HU',
684
+ 'iceland' => 'IS',
685
+ 'india' => 'IN',
686
+ 'indonesia' => 'ID',
687
+ 'iran, islamic republic of' => 'IR',
688
+ 'iraq' => 'IQ',
689
+ 'ireland' => 'IE',
690
+ 'israel' => 'IL',
691
+ 'italy' => 'IT',
692
+ 'jamaica' => 'JM',
693
+ 'japan' => 'JP',
694
+ 'jordan' => 'JO',
695
+ 'kazakstan' => 'KZ',
696
+ 'kenya' => 'KE',
697
+ 'kiribati' => 'KI',
698
+ 'korea democratic peoples republic of' => 'KP',
699
+ 'korea republic of' => 'KR',
700
+ 'kuwait' => 'KW',
701
+ 'kyrgyzstan' => 'KG',
702
+ 'lao peoples democratic republic' => 'LA',
703
+ 'latvia' => 'LV',
704
+ 'lebanon' => 'LB',
705
+ 'lesotho' => 'LS',
706
+ 'liberia' => 'LR',
707
+ 'libyan arab jamahiriya' => 'LY',
708
+ 'liechtenstein' => 'LI',
709
+ 'lithuania' => 'LT',
710
+ 'luxembourg' => 'LU',
711
+ 'macau' => 'MO',
712
+ 'macedonia, the former yugoslav republic of' => 'MK',
713
+ 'madagascar' => 'MG',
714
+ 'malawi' => 'MW',
715
+ 'malaysia' => 'MY',
716
+ 'maldives' => 'MV',
717
+ 'mali' => 'ML',
718
+ 'malta' => 'MT',
719
+ 'marshall islands' => 'MH',
720
+ 'martinique' => 'MQ',
721
+ 'mauritania' => 'MR',
722
+ 'mauritius' => 'MU',
723
+ 'mayotte' => 'YT',
724
+ 'mexico' => 'MX',
725
+ 'micronesia, federated states of' => 'FM',
726
+ 'moldova, republic of' => 'MD',
727
+ 'monaco' => 'MC',
728
+ 'mongolia' => 'MN',
729
+ 'montserrat' => 'MS',
730
+ 'morocco' => 'MA',
731
+ 'mozambique' => 'MZ',
732
+ 'myanmar' => 'MM',
733
+ 'namibia' => 'NA',
734
+ 'nauru' => 'NR',
735
+ 'nepal' => 'NP',
736
+ 'netherlands' => 'NL',
737
+ 'netherlands antilles' => 'AN',
738
+ 'new caledonia' => 'NC',
739
+ 'new zealand' => 'NZ',
740
+ 'nicaragua' => 'NI',
741
+ 'niger' => 'NE',
742
+ 'nigeria' => 'NG',
743
+ 'niue' => 'NU',
744
+ 'norfolk island' => 'NF',
745
+ 'northern mariana islands' => 'MP',
746
+ 'norway' => 'NO',
747
+ 'oman' => 'OM',
748
+ 'pakistan' => 'PK',
749
+ 'palau' => 'PW',
750
+ 'palestinian territory, occupied' => 'PS',
751
+ 'panama' => 'PA',
752
+ 'papua new guinea' => 'PG',
753
+ 'paraguay' => 'PY',
754
+ 'peru' => 'PE',
755
+ 'philippines' => 'PH',
756
+ 'pitcairn' => 'PN',
757
+ 'poland' => 'PL',
758
+ 'portugal' => 'PT',
759
+ 'puerto rico' => 'PR',
760
+ 'qatar' => 'QA',
761
+ 'reunion' => 'RE',
762
+ 'romania' => 'RO',
763
+ 'russian federation' => 'RU',
764
+ 'rwanda' => 'RW',
765
+ 'saint helena' => 'SH',
766
+ 'saint kitts and nevis' => 'KN',
767
+ 'saint lucia' => 'LC',
768
+ 'saint pierre and miquelon' => 'PM',
769
+ 'saint vincent and the grenadines' => 'VC',
770
+ 'samoa' => 'WS',
771
+ 'san marino' => 'SM',
772
+ 'sao tome and principe' => 'ST',
773
+ 'saudi arabia' => 'SA',
774
+ 'senegal' => 'SN',
775
+ 'seychelles' => 'SC',
776
+ 'sierra leone' => 'SL',
777
+ 'singapore' => 'SG',
778
+ 'slovakia' => 'SK',
779
+ 'slovenia' => 'SI',
780
+ 'solomon islands' => 'SB',
781
+ 'somalia' => 'SO',
782
+ 'south africa' => 'ZA',
783
+ 'south georgia and the south sandwich islands' => 'GS',
784
+ 'spain' => 'ES',
785
+ 'sri lanka' => 'LK',
786
+ 'sudan' => 'SD',
787
+ 'suriname' => 'SR',
788
+ 'svalbard and jan mayen' => 'SJ',
789
+ 'swaziland' => 'SZ',
790
+ 'sweden' => 'SE',
791
+ 'switzerland' => 'CH',
792
+ 'syrian arab republic' => 'SY',
793
+ 'taiwan, province of china' => 'TW',
794
+ 'tajikistan' => 'TJ',
795
+ 'tanzania, united republic of' => 'TZ',
796
+ 'thailand' => 'TH',
797
+ 'togo' => 'TG',
798
+ 'tokelau' => 'TK',
799
+ 'tonga' => 'TO',
800
+ 'trinidad and tobago' => 'TT',
801
+ 'tunisia' => 'TN',
802
+ 'turkey' => 'TR',
803
+ 'turkmenistan' => 'TM',
804
+ 'turks and caicos islands' => 'TC',
805
+ 'tuvalu' => 'TV',
806
+ 'uganda' => 'UG',
807
+ 'ukraine' => 'UA',
808
+ 'united arab emirates' => 'AE',
809
+ 'united kingdom' => 'GB',
810
+ 'united states' => 'US',
811
+ 'united states minor outlying islands' => 'UM',
812
+ 'uruguay' => 'UY',
813
+ 'uzbekistan' => 'UZ',
814
+ 'vanuatu' => 'VU',
815
+ 'venezuela' => 'VE',
816
+ 'viet nam' => 'VN',
817
+ 'virgin islands, british' => 'VG',
818
+ 'virgin islands, u.s.' => 'VI',
819
+ 'wallis and futuna' => 'WF',
820
+ 'western sahara' => 'EH',
821
+ 'yemen' => 'YE',
822
+ 'yugoslavia' => 'YU',
823
+ 'zambia' => 'ZM',
824
+ 'zimbabwe' => 'ZW'
825
+ );
826
+
827
+ $address_info['country'] = strtolower(
828
+ $address_info['country']);
829
+
830
+ if (isset($foo[$address_info['country']])) {
831
+ $address->setCountryId(
832
+ $foo[$address_info['country']]);
833
+ }
834
+ }
835
+
836
+ $address->save();
837
+ $order->addStatusHistoryComment(sprintf($helper->__(
838
+ 'Payson updated the shipping address')));
839
+ }
840
+ } else {
841
+ $order->addStatusHistoryComment(sprintf(
842
+ $helper->__('Payson pinged the order with status %s'), $ipn_response->status));
843
+ }
844
+
845
+ break;
846
+ }
847
+
848
+ case self::STATUS_ERROR:
849
+
850
+ $order->cancel();
851
+
852
+ $order->addStatusHistoryComment($helper->__('The order was denied by Payson.'));
853
+
854
+ break;
855
+
856
+ case self::STATUS_INCOMPLETE:
857
+ case self::STATUS_EXPIRED:
858
+ case self::STATUS_REVERSALERROR:
859
+ default: {
860
+ $order->cancel();
861
+ }
862
+ }
863
+
864
+ $order->save();
865
+
866
+ // Update the database tables
867
+ $db->update($order_log_table, array
868
+ (
869
+ 'valid' => 1
870
+ ), array
871
+ (
872
+ 'id = ?' => $order_log_id
873
+ ));
874
+
875
+ $db->update($order_table, array
876
+ (
877
+ 'ipn_status' => $ipn_response->status
878
+ ), array
879
+ (
880
+ 'id = ?' => $payson_order->id
881
+ ));
882
+
883
+ return $this;
884
+ }
885
+
886
+ /**
887
+ * http://api.payson.se/#title12
888
+ *
889
+ * @params int $order_id Real order id
890
+ * @return object $this
891
+ */
892
+ public function PaymentDetails($order_id) {
893
+ $helper = Mage::helper('payson');
894
+
895
+ // Get the database connection
896
+ $resource = Mage::getSingleton('core/resource');
897
+ $db = $resource->getConnection('core_write');
898
+
899
+ $order_table = $resource->getTableName('payson_order');
900
+ $order_log_table = $resource->getTableName('payson_order_log');
901
+
902
+ /* Save fetch mode so that we can reset it and not mess up Magento
903
+ functionality */
904
+ $old_fetch_mode = $db->getFetchMode();
905
+ $db->setFetchMode(Zend_Db::FETCH_OBJ);
906
+
907
+ // Get payson order information and validate token
908
+ $payson_order = $db->fetchRow(
909
+ 'SELECT
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
910
  id,
911
  token,
912
  store_id
919
  LIMIT
920
  0,1', $order_id);
921
 
922
+ if ($payson_order === false) {
923
+ Mage::throwException('Invalid order id (' . $order_id . ')');
924
+ }
925
+
926
+ $db->setFetchMode($old_fetch_mode);
927
+
928
+ $args = array
929
+ (
930
+ 'token' => $payson_order->token
931
+ );
932
+ $url = vsprintf(self::API_CALL_PAYMENT_DETAILS, $this->GetFormatIfTest($payson_order->store_id));
933
+
934
+ $client = $this->GetHttpClient($url)
935
+ ->setParameterPost($args);
936
+
937
+ $response = Payson_Payson_Helper_Api_Response_Standard
938
+ ::FromHttpBody($client->request()->getBody());
939
+
940
+ $this->SetResponse($response);
941
+
942
+ $db->insert($order_log_table, array
943
+ (
944
+ 'payson_order_id' => $payson_order->id,
945
+ 'added' => new Zend_Db_Expr('NOW()'),
946
+ 'api_call' => 'payment_details',
947
+ 'valid' => (int) $response->IsValid(),
948
+ 'response' => serialize($response->ToArray())
949
+ ));
950
+
951
+ if (!$response->IsValid()) {
952
+ throw new Mage_Core_Exception(sprintf($helper->__(
953
+ 'Failed to retrieve payment details. Payson replied: %s'), $response->GetError()), $response->GetErrorId());
954
+ }
955
+
956
+ return $this;
957
+ }
958
+
959
+ /**
960
+ * http://api.payson.se/#title13
961
+ *
962
+ * @params int $order_id Real order id
963
+ * @params string $action
964
+ * @return object $this
965
+ */
966
+ public function PaymentUpdate($order_id, $action) {
967
+ $helper = Mage::helper('payson');
968
+
969
+ // Get the database connection
970
+ $resource = Mage::getSingleton('core/resource');
971
+ $db = $resource->getConnection('core_write');
972
+
973
+ $order_table = $resource->getTableName('payson_order');
974
+ $order_log_table = $resource->getTableName('payson_order_log');
975
+
976
+ /* Save fetch mode so that we can reset it and not mess up Magento
977
+ functionality */
978
+ $old_fetch_mode = $db->getFetchMode();
979
+ $db->setFetchMode(Zend_Db::FETCH_OBJ);
980
+
981
+ // Get payson order information and validate token
982
+ $payson_order = $db->fetchRow(
983
+ 'SELECT
 
 
 
 
984
  id,
985
  token,
986
  store_id
993
  LIMIT
994
  0,1', $order_id);
995
 
996
+ if ($payson_order === false) {
997
+ Mage::throwException('Invalid order id (' . $order_id . ')');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
998
  }
999
+
1000
+ $db->setFetchMode($old_fetch_mode);
1001
+
1002
+ $args = array
1003
+ (
1004
+ 'token' => $payson_order->token,
1005
+ 'action' => $action
1006
+ );
1007
+
1008
+ $client = $this->GetHttpClient(vsprintf(self::API_CALL_PAYMENT_UPDATE, $this->GetFormatIfTest($payson_order->store_id)))
1009
+ ->setParameterPost($args);
1010
+
1011
+ $response = Payson_Payson_Helper_Api_Response_Standard
1012
+ ::FromHttpBody($client->request()->getBody());
1013
+
1014
+ $this->SetResponse($response);
1015
+
1016
+ $db->insert($order_log_table, array
1017
+ (
1018
+ 'payson_order_id' => $payson_order->id,
1019
+ 'added' => new Zend_Db_Expr('NOW()'),
1020
+ 'api_call' => 'payment_update',
1021
+ 'valid' => (int) $response->IsValid(),
1022
+ 'response' => serialize($response->ToArray())
1023
+ ));
1024
+
1025
+ /* if(!$response->IsValid())
1026
+ {
1027
+ // TODO: don't seem to return an errorList
1028
+ throw new Mage_Core_Exception(sprintf($helper->__(
1029
+ 'Failed to update payment. Payson replied: %s'),
1030
+ $response->GetError()), $response->GetErrorId());
1031
+ } */
1032
+
1033
+ return $this;
1034
+ }
1035
+
1036
+ private function GetFormatIfTest($storeID = null, $isForwardURL = FALSE) {
1037
+ $config = Mage::getModel('payson/config');
1038
+ $stack = array();
1039
+ /* @var $isTest bool */
1040
+ $isTest = ($config->get('test_mode', $storeID) == "1");
1041
+
1042
+ array_push($stack, self::DEBUG_MODE ? "http" : "https");
1043
+ array_push($stack, $isTest && !self::DEBUG_MODE ? "test-" : (self::DEBUG_MODE && !$isForwardURL ? "mvc" : ""));
1044
+
1045
+ if ($isForwardURL == true) {
1046
+ array_push($stack, self::DEBUG_MODE ? "app" : "www");
1047
  }
1048
+
1049
+ array_push($stack, self::DEBUG_MODE ? "local" : "se");
1050
+ array_push($stack, self::DEBUG_MODE ? "Payment" : "1.0");
1051
+
1052
+ array_push($stack, self::DEBUG_MODE ? "" : "Payment");
1053
+ //print_r($stack);exit;
1054
+ return $stack;
1055
+ }
1056
+
1057
+ public function getIpnStatus($order_id) {
1058
+ $resource = Mage::getSingleton('core/resource');
1059
+ $db = $resource->getConnection('core_write');
1060
+ $order_table = $resource->getTableName('payson_order');
1061
+ $query = 'SELECT ipn_status FROM `' . $order_table . '` WHERE order_id = ' . $order_id;
1062
+ return $db->fetchRow($query);
1063
+ }
1064
+
1065
+ public function paysonApiError($error) {
1066
+ $error_code = '<html>
1067
  <head>
1068
  <meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
1069
  <script type="text/javascript">
1070
+ alert("' . $error . '");
1071
+ window.location="' . ('/index.php') . '";
1072
  </script>
1073
  </head>
1074
  </html>';
1075
+ echo $error_code;
1076
+ exit;
1077
+ }
1078
+
1079
  }
1080
 
app/code/community/Payson/Payson/Helper/Api/Response/Interface.php CHANGED
@@ -1,19 +1,20 @@
1
  <?php
2
- interface Payson_Payson_Helper_Api_Response_Interface
3
- {
4
- /**
5
- * Construct a response object from a string
6
- *
7
- * @param string $body
8
- * @return object
9
- */
10
- public static function FromHttpBody($body);
11
 
12
- /**
13
- * Whether this response is valid
14
- *
15
- * @return bool
16
- */
17
- public function IsValid();
 
 
 
 
 
 
 
 
 
 
18
  }
19
 
1
  <?php
 
 
 
 
 
 
 
 
 
2
 
3
+ interface Payson_Payson_Helper_Api_Response_Interface {
4
+
5
+ /**
6
+ * Construct a response object from a string
7
+ *
8
+ * @param string $body
9
+ * @return object
10
+ */
11
+ public static function FromHttpBody($body);
12
+
13
+ /**
14
+ * Whether this response is valid
15
+ *
16
+ * @return bool
17
+ */
18
+ public function IsValid();
19
  }
20
 
app/code/community/Payson/Payson/Helper/Api/Response/Standard.php CHANGED
@@ -1,153 +1,131 @@
1
  <?php
2
- class Payson_Payson_Helper_Api_Response_Standard
3
- extends Payson_Payson_Helper_Api_Response_Standard_Parameters
4
- implements Payson_Payson_Helper_Api_Response_Interface
5
- {
6
- /*
7
- * Constants
8
- */
9
-
10
- const ACK_SUCCESS = 'SUCCESS';
11
- const ACK_FAILURE = 'FAILURE';
12
-
13
- /*
14
- * Public methods
15
- */
16
-
17
- /**
18
- * Parse response object and instantiate
19
- *
20
- * @param string $response
21
- * @return object
22
- */
23
- static public function FromHttpBody($body)
24
- {
25
- $params = array();
26
- parse_str($body, $params);
27
-
28
- foreach($params as $key => $value)
29
- {
30
- $sub_key = strtok($key, '_');
31
-
32
- if($sub_key === $key)
33
- {
34
- continue;
35
- }
36
-
37
- $current = &$params;
38
-
39
- do
40
- {
41
- $matches = array();
42
-
43
- if(preg_match('/\((\d)\)$/', $sub_key, $matches) === 1)
44
- {
45
- $sub_key = substr($sub_key, 0, -3);
46
-
47
- if(!strlen($sub_key))
48
- {
49
- continue;
50
- }
51
- }
52
-
53
- if(!isset($current[$sub_key]) || !is_array($current[$sub_key]))
54
- {
55
- $current[$sub_key] = array();
56
- }
57
-
58
- $current = &$current[$sub_key];
59
-
60
- if(isset($matches[1]))
61
- {
62
- if(!isset($current[$matches[1]]) ||
63
- !is_array($current[$matches[1]]))
64
- {
65
- $current[$matches[1]] = array();
66
- }
67
-
68
- $current = &$current[$matches[1]];
69
- }
70
- }
71
- while(($sub_key = strtok('_')) !== false);
72
-
73
- $current = $value;
74
-
75
- unset($params[$key]);
76
- }
77
-
78
- return new self($params);
79
- }
80
-
81
- /**
82
- * Populate parameters
83
- *
84
- * @param array $params
85
- * @return void
86
- */
87
- public function __construct(array $params)
88
- {
89
- if(empty($params))
90
- {
91
- Mage::throwException('Invalid response');
92
- }
93
-
94
- parent::__construct($params);
95
- }
96
-
97
- /**
98
- * @inheritDoc
99
- */
100
- public function IsValid()
101
- {
102
- return (isset($this->responseEnvelope->ack) &&
103
- ($this->responseEnvelope->ack === self::ACK_SUCCESS));
104
- }
105
-
106
- /**
107
- * Compile all errors into a string
108
- *
109
- * @return string
110
- */
111
- public function GetError()
112
- {
113
- $ret = '';
114
-
115
- if(isset($this->errorList->error))
116
- {
117
- foreach($this->errorList->error->ToArray() as $error)
118
- {
119
- if(isset($error['parameter']))
120
- {
121
- $ret .= $error['parameter'] . ' ';
122
- }
123
-
124
- $ret .= '(' . $error['errorId'] . ') ' .
125
- $error['message'] . ' ';
126
- }
127
- }
128
-
129
- return rtrim($ret);
130
- }
131
-
132
- /**
133
- * Get first error id
134
- *
135
- * @return int|null
136
- */
137
- public function GetErrorId()
138
- {
139
- if(isset($this->errorList->error))
140
- {
141
- foreach($this->errorList->error->ToArray() as $error)
142
- {
143
- if(isset($error['errorId']))
144
- {
145
- return (int)$error['errorId'];
146
- }
147
- }
148
- }
149
-
150
- return null;
151
- }
152
  }
153
 
1
  <?php
2
+
3
+ class Payson_Payson_Helper_Api_Response_Standard extends Payson_Payson_Helper_Api_Response_Standard_Parameters implements Payson_Payson_Helper_Api_Response_Interface {
4
+ /*
5
+ * Constants
6
+ */
7
+
8
+ const ACK_SUCCESS = 'SUCCESS';
9
+ const ACK_FAILURE = 'FAILURE';
10
+
11
+ /*
12
+ * Public methods
13
+ */
14
+
15
+ /**
16
+ * Parse response object and instantiate
17
+ *
18
+ * @param string $response
19
+ * @return object
20
+ */
21
+ static public function FromHttpBody($body) {
22
+ $params = array();
23
+ parse_str($body, $params);
24
+
25
+ foreach ($params as $key => $value) {
26
+ $sub_key = strtok($key, '_');
27
+
28
+ if ($sub_key === $key) {
29
+ continue;
30
+ }
31
+
32
+ $current = &$params;
33
+
34
+ do {
35
+ $matches = array();
36
+
37
+ if (preg_match('/\((\d)\)$/', $sub_key, $matches) === 1) {
38
+ $sub_key = substr($sub_key, 0, -3);
39
+
40
+ if (!strlen($sub_key)) {
41
+ continue;
42
+ }
43
+ }
44
+
45
+ if (!isset($current[$sub_key]) || !is_array($current[$sub_key])) {
46
+ $current[$sub_key] = array();
47
+ }
48
+
49
+ $current = &$current[$sub_key];
50
+
51
+ if (isset($matches[1])) {
52
+ if (!isset($current[$matches[1]]) ||
53
+ !is_array($current[$matches[1]])) {
54
+ $current[$matches[1]] = array();
55
+ }
56
+
57
+ $current = &$current[$matches[1]];
58
+ }
59
+ } while (($sub_key = strtok('_')) !== false);
60
+
61
+ $current = $value;
62
+
63
+ unset($params[$key]);
64
+ }
65
+
66
+ return new self($params);
67
+ }
68
+
69
+ /**
70
+ * Populate parameters
71
+ *
72
+ * @param array $params
73
+ * @return void
74
+ */
75
+ public function __construct(array $params) {
76
+ if (empty($params)) {
77
+ Mage::throwException('Invalid response');
78
+ }
79
+
80
+ parent::__construct($params);
81
+ }
82
+
83
+ /**
84
+ * @inheritDoc
85
+ */
86
+ public function IsValid() {
87
+ return (isset($this->responseEnvelope->ack) &&
88
+ ($this->responseEnvelope->ack === self::ACK_SUCCESS));
89
+ }
90
+
91
+ /**
92
+ * Compile all errors into a string
93
+ *
94
+ * @return string
95
+ */
96
+ public function GetError() {
97
+ $ret = '';
98
+
99
+ if (isset($this->errorList->error)) {
100
+ foreach ($this->errorList->error->ToArray() as $error) {
101
+ if (isset($error['parameter'])) {
102
+ $ret .= $error['parameter'] . ' ';
103
+ }
104
+
105
+ $ret .= '(' . $error['errorId'] . ') ' .
106
+ $error['message'] . ' ';
107
+ }
108
+ }
109
+
110
+ return rtrim($ret);
111
+ }
112
+
113
+ /**
114
+ * Get first error id
115
+ *
116
+ * @return int|null
117
+ */
118
+ public function GetErrorId() {
119
+ if (isset($this->errorList->error)) {
120
+ foreach ($this->errorList->error->ToArray() as $error) {
121
+ if (isset($error['errorId'])) {
122
+ return (int) $error['errorId'];
123
+ }
124
+ }
125
+ }
126
+
127
+ return null;
128
+ }
129
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  }
131
 
app/code/community/Payson/Payson/Helper/Api/Response/Standard/Parameters.php CHANGED
@@ -1,78 +1,66 @@
1
  <?php
2
- class Payson_Payson_Helper_Api_Response_Standard_Parameters
3
- {
4
- /*
5
- * Protected properties
6
- */
7
 
8
- /**
9
- * Multi-dimensional array containing parameters from the response
10
- *
11
- * @var array
12
- */
13
- protected $params = array();
14
 
15
- /*
16
- * Public methods
17
- */
 
 
 
18
 
19
- /**
20
- * Constructor!
21
- *
22
- * @param arary $params
23
- * @return void
24
- */
25
- public function __construct(array $params)
26
- {
27
- foreach($params as $key => $value)
28
- {
29
- if(is_array($value))
30
- {
31
- $this->params[$key] = new self($value);
32
- }
33
- else
34
- {
35
- $this->params[$key] = $value;
36
- }
37
- }
38
- }
39
 
40
- public function __get($name)
41
- {
42
- return (isset($this->params[$name]) ? $this->params[$name] : null);
43
- }
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- public function __set($name, $value)
46
- {
47
- $this->params[$name] = $value;
48
- }
49
 
50
- public function __isset($name)
51
- {
52
- return isset($this->params[$name]);
53
- }
54
 
55
- /**
56
- * Compile the parameters into an array
57
- *
58
- * @return array
59
- */
60
- public function ToArray()
61
- {
62
- foreach($this->params as $key => $value)
63
- {
64
- if($value instanceof
65
- Payson_Payson_Helper_Api_Response_Standard_Parameters)
66
- {
67
- $arr[$key] = $value->ToArray();
68
- }
69
- else
70
- {
71
- $arr[$key] = $value;
72
- }
73
- }
 
 
74
 
75
- return $arr;
76
- }
77
  }
78
 
1
  <?php
 
 
 
 
 
2
 
3
+ class Payson_Payson_Helper_Api_Response_Standard_Parameters {
4
+ /*
5
+ * Protected properties
6
+ */
 
 
7
 
8
+ /**
9
+ * Multi-dimensional array containing parameters from the response
10
+ *
11
+ * @var array
12
+ */
13
+ protected $params = array();
14
 
15
+ /*
16
+ * Public methods
17
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
+ /**
20
+ * Constructor!
21
+ *
22
+ * @param arary $params
23
+ * @return void
24
+ */
25
+ public function __construct(array $params) {
26
+ foreach ($params as $key => $value) {
27
+ if (is_array($value)) {
28
+ $this->params[$key] = new self($value);
29
+ } else {
30
+ $this->params[$key] = $value;
31
+ }
32
+ }
33
+ }
34
 
35
+ public function __get($name) {
36
+ return (isset($this->params[$name]) ? $this->params[$name] : null);
37
+ }
 
38
 
39
+ public function __set($name, $value) {
40
+ $this->params[$name] = $value;
41
+ }
 
42
 
43
+ public function __isset($name) {
44
+ return isset($this->params[$name]);
45
+ }
46
+
47
+ /**
48
+ * Compile the parameters into an array
49
+ *
50
+ * @return array
51
+ */
52
+ public function ToArray() {
53
+ foreach ($this->params as $key => $value) {
54
+ if ($value instanceof
55
+ Payson_Payson_Helper_Api_Response_Standard_Parameters) {
56
+ $arr[$key] = $value->ToArray();
57
+ } else {
58
+ $arr[$key] = $value;
59
+ }
60
+ }
61
+
62
+ return $arr;
63
+ }
64
 
 
 
65
  }
66
 
app/code/community/Payson/Payson/Helper/Api/Response/Validate.php CHANGED
@@ -1,49 +1,46 @@
1
  <?php
2
- class Payson_Payson_Helper_Api_Response_Validate
3
- implements Payson_Payson_Helper_Api_Response_Interface
4
- {
5
- /*
6
- * Constants
7
- */
8
-
9
- const VERIFIED = 'VERIFIED';
10
- const INVALID = 'INVALID';
11
-
12
- /*
13
- * Private properties
14
- */
15
-
16
- private $data;
17
-
18
- /*
19
- * Public methods
20
- */
21
-
22
- /**
23
- * @inheritDoc
24
- */
25
- static public function FromHttpBody($data)
26
- {
27
- return new self($data);
28
- }
29
-
30
- /**
31
- * Constructor!
32
- *
33
- * @param string $data
34
- * @return void
35
- */
36
- public function __construct($data)
37
- {
38
- $this->data = $data;
39
- }
40
-
41
- /**
42
- * @inheritDoc
43
- */
44
- public function IsValid()
45
- {
46
- return ($this->data === self::VERIFIED);
47
- }
48
  }
49
 
1
  <?php
2
+
3
+ class Payson_Payson_Helper_Api_Response_Validate implements Payson_Payson_Helper_Api_Response_Interface {
4
+ /*
5
+ * Constants
6
+ */
7
+
8
+ const VERIFIED = 'VERIFIED';
9
+ const INVALID = 'INVALID';
10
+
11
+ /*
12
+ * Private properties
13
+ */
14
+
15
+ private $data;
16
+
17
+ /*
18
+ * Public methods
19
+ */
20
+
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static public function FromHttpBody($data) {
25
+ return new self($data);
26
+ }
27
+
28
+ /**
29
+ * Constructor!
30
+ *
31
+ * @param string $data
32
+ * @return void
33
+ */
34
+ public function __construct($data) {
35
+ $this->data = $data;
36
+ }
37
+
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ public function IsValid() {
42
+ return ($this->data === self::VERIFIED);
43
+ }
44
+
 
 
 
45
  }
46
 
app/code/community/Payson/Payson/Helper/Data.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
- class Payson_Payson_Helper_Data extends Mage_Core_Helper_Abstract
3
- {
4
 
 
 
5
  }
6
 
1
  <?php
 
 
2
 
3
+ class Payson_Payson_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
  }
6
 
app/code/community/Payson/Payson/Model/Config.php CHANGED
@@ -1,235 +1,220 @@
1
  <?php
2
- class Payson_Payson_Model_Config
3
- {
4
- /*
5
- * Constants
6
- */
7
-
8
- //const PAYMENT_GUARANTEE = 'payment_guarantee';
9
- const PAYMENT_GUARANTEE = 'NO';
10
-
11
- const DIRECT_PAYMENT = 'direct_payment';
12
- const CREDIT_CARD_PAYMENT = 'credit_card_payment';
13
- const INVOICE_PAYMENT = 'invoice_payment';
14
-
15
- /*
16
- * Private properties
17
- */
18
-
19
- /**
20
- * Default store id used in GetConfig()
21
- *
22
- * @var int
23
- */
24
- private $default_store_id;
25
-
26
- /**
27
- * Supported currency codes
28
- *
29
- * @var array
30
- */
31
- private $supported_currencies = array
32
- (
33
- 'SEK', 'EUR'
34
- );
35
-
36
- /*
37
- * Public methods
38
- */
39
-
40
- /**
41
- * Constructor!
42
- *
43
- * @return void
44
- */
45
- public function __construct()
46
- {
47
- $this->SetDefaultStoreId(Mage::app()->getStore()->getId());
48
- }
49
-
50
- /**
51
- * Set default store id
52
- *
53
- * @param int $store
54
- * @return object $this
55
- */
56
- public function SetDefaultStoreId($store)
57
- {
58
- $this->default_store_id = $store;
59
-
60
- return $this;
61
- }
62
-
63
- /**
64
- * Get default store id
65
- *
66
- * @return int
67
- */
68
- public function GetDefaultStoreId()
69
- {
70
- return $this->default_store_id;
71
- }
72
-
73
- /**
74
- * Whether $currency is supported
75
- *
76
- * @param string $currency
77
- * @return bool
78
- */
79
- public function IsCurrencySupported($currency)
80
- {
81
- return in_array(strtoupper($currency), $this->supported_currencies);
82
- }
83
-
84
- /**
85
- * Get configuration value
86
- *
87
- * @param mixed $name
88
- * @param int|null $store [optional]
89
- * @param mixed $default [optional]
90
- * @param string $prefix [optional]
91
- */
92
- public function GetConfig($name, $store = null, $default = null,
93
- $prefix = 'payment/payson_standard/')
94
- {
95
- if(!isset($store))
96
- {
97
- $store = $this->GetDefaultStoreId();
98
- }
99
-
100
- $name = $prefix . $name;
101
- // Mage::getStoreConfigFlag
102
- $value = Mage::getStoreConfig($name, $store);
103
-
104
- return (isset($value) ? $value : $default);
105
- }
106
-
107
- /**
108
- * @see GetConfig
109
- */
110
- public function Get($name, $store = null, $default = null,
111
- $prefix = 'payment/payson_standard/')
112
- {
113
- return $this->GetConfig($name, $store, $default, $prefix);
114
- }
115
-
116
- /**
117
- * Get Payson specific invoice fee excluding tax
118
- *
119
- * @param object $order
120
- * @return float
121
- */
122
- public function GetInvoiceFee($order)
123
- {
124
- $currency = $order->getBaseCurrencyCode();
125
- $currency = strtolower($currency);
126
-
127
- if(!$this->IsCurrencySupported($currency))
128
- {
129
- return 0;
130
- }
131
-
132
- $store = Mage::app()->getStore($order->getStoreId());
133
-
134
- $fee = $this->GetConfig('invoice_fee_' . $currency, $store->getId(), 0,
135
- 'payment/payson_invoice/');
136
- $fee = round((float)$fee, 3);
137
-
138
- return $fee;
139
- }
140
-
141
- /**
142
- * Get Payson specific invoice fee including tax
143
- *
144
- * @param object $order
145
- * @return float
146
- */
147
- public function GetInvoiceFeeInclTax($order)
148
- {
149
- $fee = $this->GetInvoiceFee($order);
150
- $fee *= (1 + $this->GetInvoiceFeeTaxMod($order));
151
- $fee = round($fee, 3);
152
-
153
- return $fee;
154
- }
155
-
156
- /**
157
- * Get Payson specific invoice fee tax modifier
158
- *
159
- * @param object $order
160
- * @return float
161
- */
162
- public function GetInvoiceFeeTaxMod($order)
163
- {
164
- $store = Mage::app()->getStore($order->getStoreId());
165
-
166
- $tax_calc = Mage::getSingleton('tax/calculation');
167
- $customer = Mage::getModel('customer/customer')
168
- ->load($order->getCustomerId());
169
-
170
- $tax_class = $this->GetConfig('invoice_fee_tax', $store->getId(), 0,
171
- 'payment/payson_invoice/');
172
-
173
- $tax_rate_req = $tax_calc->getRateRequest(
174
- $order->getShippingAddress(),
175
- $order->getBillingAddress(),
176
- $customer->getTaxClassId(),
177
- $store)
178
- ->setProductClassId($tax_class);
179
-
180
- $tax_mod = (float)$tax_calc->getRate($tax_rate_req);
181
- $tax_mod /= 100;
182
- $tax_mod = round($tax_mod, 5);
183
-
184
- return $tax_mod;
185
- }
186
-
187
- /**
188
- * Does this store support payment guarantee?
189
- *
190
- * @param int|null $store [optional]
191
- * @return bool
192
- */
193
- public function CanPaymentGuarantee($store = null)
194
- {
195
- return (bool)$this->GetConfig(self::PAYMENT_GUARANTEE, $store, false);
196
- }
197
-
198
- /**
199
- * Is standard payment enabled?
200
- *
201
- * @param int|null $store [optional]
202
- * @return bool
203
- */
204
- public function CanStandardPayment($store = null)
205
- {
206
- return $this->GetConfig('active', $store, false,
207
- 'payment/payson_standard/');
208
- }
209
-
210
- /**
211
- * Is invoice payment enabled?
212
- *
213
- * @param int|null $store [optional]
214
- * @return bool
215
- */
216
- public function CanInvoicePayment($store = null)
217
- {
218
- /*if(!$this->CanStandardPayment($store))
219
- {
220
- return false;
221
- }*/
222
-
223
- return $this->GetConfig('active', $store, false,
224
- 'payment/payson_invoice/');
225
- }
226
-
227
- /* public function ActivateInvoiceOnPurchase($store = null)
228
- {
229
- return $this->GetConfig('activate_invoice', $store, false,
230
- 'payment/payson_invoice/');
231
- }*/
232
-
233
-
234
  }
235
 
1
  <?php
2
+
3
+ class Payson_Payson_Model_Config {
4
+ /*
5
+ * Constants
6
+ */
7
+
8
+ //const PAYMENT_GUARANTEE = 'payment_guarantee';
9
+
10
+ const PAYMENT_GUARANTEE = 'NO';
11
+ const DIRECT_PAYMENT = 'direct_payment';
12
+ const CREDIT_CARD_PAYMENT = 'credit_card_payment';
13
+ const INVOICE_PAYMENT = 'invoice_payment';
14
+
15
+ /*
16
+ * Private properties
17
+ */
18
+
19
+ /**
20
+ * Default store id used in GetConfig()
21
+ *
22
+ * @var int
23
+ */
24
+ private $default_store_id;
25
+
26
+ /**
27
+ * Supported currency codes
28
+ *
29
+ * @var array
30
+ */
31
+ private $supported_currencies = array
32
+ (
33
+ 'SEK', 'EUR'
34
+ );
35
+
36
+ /*
37
+ * Public methods
38
+ */
39
+
40
+ /**
41
+ * Constructor!
42
+ *
43
+ * @return void
44
+ */
45
+ public function __construct() {
46
+ $this->SetDefaultStoreId(Mage::app()->getStore()->getId());
47
+ }
48
+
49
+ /**
50
+ * Set default store id
51
+ *
52
+ * @param int $store
53
+ * @return object $this
54
+ */
55
+ public function SetDefaultStoreId($store) {
56
+ $this->default_store_id = $store;
57
+
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * Get default store id
63
+ *
64
+ * @return int
65
+ */
66
+ public function GetDefaultStoreId() {
67
+ return $this->default_store_id;
68
+ }
69
+
70
+ /**
71
+ * Whether $currency is supported
72
+ *
73
+ * @param string $currency
74
+ * @return bool
75
+ */
76
+ public function IsCurrencySupported($currency) {
77
+ return in_array(strtoupper($currency), $this->supported_currencies);
78
+ }
79
+
80
+ /**
81
+ * Get configuration value
82
+ *
83
+ * @param mixed $name
84
+ * @param int|null $store [optional]
85
+ * @param mixed $default [optional]
86
+ * @param string $prefix [optional]
87
+ */
88
+ public function GetConfig($name, $store = null, $default = null, $prefix = 'payment/payson_standard/') {
89
+ if (!isset($store)) {
90
+ $store = $this->GetDefaultStoreId();
91
+ }
92
+
93
+ $name = $prefix . $name;
94
+ // Mage::getStoreConfigFlag
95
+ $value = Mage::getStoreConfig($name, $store);
96
+
97
+ return (isset($value) ? $value : $default);
98
+ }
99
+
100
+ /**
101
+ * @see GetConfig
102
+ */
103
+ public function Get($name, $store = null, $default = null, $prefix = 'payment/payson_standard/') {
104
+ return $this->GetConfig($name, $store, $default, $prefix);
105
+ }
106
+
107
+ /**
108
+ * Get Payson specific invoice fee excluding tax
109
+ *
110
+ * @param object $order
111
+ * @return float
112
+ */
113
+ public function GetInvoiceFee($order) {
114
+ $currency = $order->getBaseCurrencyCode();
115
+ $currency = strtolower($currency);
116
+
117
+ if (!$this->IsCurrencySupported($currency)) {
118
+ return 0;
119
+ }
120
+
121
+ $store = Mage::app()->getStore($order->getStoreId());
122
+
123
+ $fee = $this->GetConfig('invoice_fee_' . $currency, $store->getId(), 0, 'payment/payson_invoice/');
124
+ $fee = round((float) $fee, 3);
125
+
126
+ return $fee;
127
+ }
128
+
129
+ /**
130
+ * Get Payson specific invoice fee including tax
131
+ *
132
+ * @param object $order
133
+ * @return float
134
+ */
135
+ public function GetInvoiceFeeInclTax($order) {
136
+ $fee = $this->GetInvoiceFee($order);
137
+ $fee *= (1 + $this->GetInvoiceFeeTaxMod($order));
138
+ $fee = round($fee, 3);
139
+
140
+ return $fee;
141
+ }
142
+
143
+ /**
144
+ * Get Payson specific invoice fee tax modifier
145
+ *
146
+ * @param object $order
147
+ * @return float
148
+ */
149
+ public function GetInvoiceFeeTaxMod($order) {
150
+ $store = Mage::app()->getStore($order->getStoreId());
151
+
152
+ $tax_calc = Mage::getSingleton('tax/calculation');
153
+ $customer = Mage::getModel('customer/customer')
154
+ ->load($order->getCustomerId());
155
+
156
+ $tax_class = $this->GetConfig('invoice_fee_tax', $store->getId(), 0, 'payment/payson_invoice/');
157
+
158
+ $tax_rate_req = $tax_calc->getRateRequest(
159
+ $order->getShippingAddress(), $order->getBillingAddress(), $customer->getTaxClassId(), $store)
160
+ ->setProductClassId($tax_class);
161
+
162
+ $tax_mod = (float) $tax_calc->getRate($tax_rate_req);
163
+ $tax_mod /= 100;
164
+ $tax_mod = round($tax_mod, 5);
165
+
166
+ return $tax_mod;
167
+ }
168
+
169
+ /**
170
+ * Does this store support payment guarantee?
171
+ *
172
+ * @param int|null $store [optional]
173
+ * @return bool
174
+ */
175
+ public function CanPaymentGuarantee($store = null) {
176
+ return (bool) $this->GetConfig(self::PAYMENT_GUARANTEE, $store, false);
177
+ }
178
+
179
+ /**
180
+ * Is standard payment enabled?
181
+ *
182
+ * @param int|null $store [optional]
183
+ * @return bool
184
+ */
185
+ public function CanStandardPayment($store = null) {
186
+ return $this->GetConfig('active', $store, false, 'payment/payson_standard/');
187
+ }
188
+
189
+ /**
190
+ * Is invoice payment enabled?
191
+ *
192
+ * @param int|null $store [optional]
193
+ * @return bool
194
+ */
195
+ public function CanInvoicePayment($store = null) {
196
+ /* if(!$this->CanStandardPayment($store))
197
+ {
198
+ return false;
199
+ } */
200
+
201
+ return $this->GetConfig('active', $store, false, 'payment/payson_invoice/');
202
+ }
203
+
204
+ public function restoreCartOnCancel($store = null) {
205
+ if (!$store)
206
+ $store = Mage::app()->getStore()->getId();
207
+ $configValue = $this->GetConfig("restore_on_cancel", $store);
208
+
209
+ return $configValue == 1;
210
+ }
211
+
212
+ public function restoreCartOnError($store = null) {
213
+ if (!$store)
214
+ $store = Mage::app()->getStore()->getId();
215
+ $configValue = $this->GetConfig("restore_on_error", $store);
216
+
217
+ return $configValue == 1;
218
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  }
220
 
app/code/community/Payson/Payson/Model/Method/Abstract.php CHANGED
@@ -1,179 +1,164 @@
1
  <?php
2
- abstract class Payson_Payson_Model_Method_Abstract
3
- extends Mage_Payment_Model_Method_Abstract
4
- {
5
- /**
6
- * @inheritDoc
7
- */
8
- protected $_isGateway = false;
9
- protected $_canAuthorize = false;
10
- protected $_canCapture = false;
11
- protected $_canCapturePartial = false;
12
- protected $_canRefund = false;
13
- protected $_canRefundInvoicePartial = false;
14
- protected $_canVoid = false;
15
- protected $_canUseInternal = false; // true
16
- protected $_canUseCheckout = true; // true
17
- protected $_canUseForMultishipping = false; // true
18
- protected $_isInitializeNeeded = false;
19
- protected $_canFetchTransactionInfo = false;
20
- protected $_canReviewPayment = false;
21
- protected $_canCreateBillingAgreement = false;
22
- protected $_canManageRecurringProfiles = false; // true
23
-
24
- /**
25
- * @inheritDoc
26
- */
27
- protected $_canCancelInvoice = false;
28
-
29
- /*
30
- * Protected methods
31
- */
32
-
33
- protected function GetCheckout()
34
- {
35
- return Mage::getSingleton('checkout/session');
36
- }
37
-
38
- protected function GetQuote()
39
- {
40
- return $this->GetCheckout()->getQuote();
41
- }
42
-
43
- /*
44
- * Public methods
45
- */
46
-
47
- /**
48
- * Redirect url when user place order
49
- *
50
- * @return string
51
- */
52
- public function getOrderPlaceRedirectUrl()
53
- {
54
- return Mage::getUrl('payson/checkout/redirect',
55
- array('_secure' => true));
56
- }
57
-
58
- /**
59
- * @inheritDoc
60
- */
61
- /*public function initialize($payment_action, $state_object)
62
- {
63
- $state_object->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
64
- $state_object->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
65
- $state_object->setIsNotified(false);
66
-
67
- return $this;
68
- }*/
69
-
70
- /**
71
- * Whether this paymend method is available for specified currency
72
- *
73
- * @param string $currency
74
- * @return bool
75
- */
76
- public function canUseForCurrency($currency)
77
- {
78
- return Mage::getModel('payson/config')->IsCurrencySupported($currency);
79
- }
80
-
81
- /**
82
- * @inheritDoc
83
- */
84
- public function refund(Varien_Object $payment, $amount)
85
- {
86
-
87
- /* @var $order Mage_Sales_Model_Order */
88
- $order = $payment->getOrder();
89
-
90
- $method = $payment->getMethod();
91
-
92
- if($order->getBaseGrandTotal() != $amount)
93
- {
94
- Mage::throwException('Invalid amount');
95
- }
96
-
97
- $helper = Mage::helper('payson');
98
- $order_id = $order->getData('increment_id');
99
- $api = Mage::helper('payson/api');
100
-
101
- $api->PaymentUpdate($order_id, $method == "payson_invoice" ?
102
- Payson_Payson_Helper_Api::UPDATE_ACTION_CREDITORDER :
103
  Payson_Payson_Helper_Api::UPDATE_ACTION_REFUNDORDER);
104
 
105
- $order->addStatusHistoryComment($helper->__(
106
- 'Payment was credited at Payson'));
107
-
108
- return $this;
109
- }
110
-
111
- /**
112
- * @inheritDoc
113
- */
114
- public function void(Varien_Object $payment)
115
- {
116
- $payment->setTransactionId('auth')
117
- ->setIsTransactionClosed(0);
118
- return $this;
119
- }
120
-
121
-
122
- /**
123
- * @inheritDoc
124
- */
125
- public function cancel(Varien_Object $payment)
126
- {
127
- $order = $payment->getOrder();
128
- $order_id = $order->getData('increment_id');
129
-
130
- $api = Mage::helper('payson/api');
131
- $helper = Mage::helper('payson');
132
- $api->PaymentDetails($order_id);
133
- $details = $api->GetResponse();
134
-
135
- if(($details->type === Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
136
- ($details->invoiceStatus === Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED) ||
137
- ($details->type !== Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE && $details->status === Payson_Payson_Helper_Api::STATUS_CREATED) ||
138
- $order->getState() === Mage_Sales_Model_Order::STATE_PROCESSING)
139
- {
140
- $api->PaymentUpdate($order_id,
141
- Payson_Payson_Helper_Api::UPDATE_ACTION_CANCELORDER);
142
-
143
- $order->addStatusHistoryComment($helper->__(
144
- 'Order was canceled at Payson'));
145
-
146
- $payment->setTransactionId('auth')
147
- ->setIsTransactionClosed(1);
148
- //->setShouldCloseParentTransaction(1);
149
- }
150
- else
151
- {
152
- Mage::throwException($helper->__('Payson is not ready to cancel the order. Please try again later.'));
153
- }
154
-
155
- return $this;
156
- }
157
-
158
-
159
- /**
160
- * Is run when payment method is selected
161
- *
162
- * @return void
163
- */
164
- /*public function validate()
165
- {
166
- $session = Mage::getSingleton('checkout/session');
167
-
168
- if(isset($_POST['payment']['method']))
169
- {
170
- $session->setData('payson_payment_method',
171
- $_POST['payment']['method']);
172
- }
173
- else
174
- {
175
- $session->unsetData('payson_payment_method');
176
- }
177
- }*/
178
  }
179
 
1
  <?php
2
+
3
+ abstract class Payson_Payson_Model_Method_Abstract extends Mage_Payment_Model_Method_Abstract {
4
+
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ protected $_isGateway = false;
9
+ protected $_canAuthorize = false;
10
+ protected $_canCapture = false;
11
+ protected $_canCapturePartial = false;
12
+ protected $_canRefund = false;
13
+ protected $_canRefundInvoicePartial = false;
14
+ protected $_canVoid = false;
15
+ protected $_canUseInternal = false; // true
16
+ protected $_canUseCheckout = true; // true
17
+ protected $_canUseForMultishipping = false; // true
18
+ protected $_isInitializeNeeded = false;
19
+ protected $_canFetchTransactionInfo = false;
20
+ protected $_canReviewPayment = false;
21
+ protected $_canCreateBillingAgreement = false;
22
+ protected $_canManageRecurringProfiles = false; // true
23
+
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ protected $_canCancelInvoice = false;
28
+
29
+ /*
30
+ * Protected methods
31
+ */
32
+
33
+ protected function GetCheckout() {
34
+ return Mage::getSingleton('checkout/session');
35
+ }
36
+
37
+ protected function GetQuote() {
38
+ return $this->GetCheckout()->getQuote();
39
+ }
40
+
41
+ /*
42
+ * Public methods
43
+ */
44
+
45
+ /**
46
+ * Redirect url when user place order
47
+ *
48
+ * @return string
49
+ */
50
+ public function getOrderPlaceRedirectUrl() {
51
+ return Mage::getUrl('payson/checkout/redirect', array('_secure' => true));
52
+ }
53
+
54
+ /**
55
+ * @inheritDoc
56
+ */
57
+ /* public function initialize($payment_action, $state_object)
58
+ {
59
+ $state_object->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
60
+ $state_object->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
61
+ $state_object->setIsNotified(false);
62
+
63
+ return $this;
64
+ } */
65
+
66
+ /**
67
+ * Whether this paymend method is available for specified currency
68
+ *
69
+ * @param string $currency
70
+ * @return bool
71
+ */
72
+ public function canUseForCurrency($currency) {
73
+ return Mage::getModel('payson/config')->IsCurrencySupported($currency);
74
+ }
75
+
76
+ /**
77
+ * @inheritDoc
78
+ */
79
+ public function refund(Varien_Object $payment, $amount) {
80
+
81
+ /* @var $order Mage_Sales_Model_Order */
82
+ $order = $payment->getOrder();
83
+
84
+ $method = $payment->getMethod();
85
+
86
+ if ($order->getBaseGrandTotal() != $amount) {
87
+ Mage::throwException('Invalid amount');
88
+ }
89
+
90
+ $helper = Mage::helper('payson');
91
+ $order_id = $order->getData('increment_id');
92
+ $api = Mage::helper('payson/api');
93
+
94
+ $api->PaymentUpdate($order_id, $method == "payson_invoice" ?
95
+ Payson_Payson_Helper_Api::UPDATE_ACTION_CREDITORDER :
 
 
 
 
 
 
 
96
  Payson_Payson_Helper_Api::UPDATE_ACTION_REFUNDORDER);
97
 
98
+ $order->addStatusHistoryComment($helper->__(
99
+ 'Payment was credited at Payson'));
100
+
101
+ return $this;
102
+ }
103
+
104
+ /**
105
+ * @inheritDoc
106
+ */
107
+ public function void(Varien_Object $payment) {
108
+ $payment->setTransactionId('auth')
109
+ ->setIsTransactionClosed(0);
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * @inheritDoc
115
+ */
116
+ public function cancel(Varien_Object $payment) {
117
+ $order = $payment->getOrder();
118
+ $order_id = $order->getData('increment_id');
119
+
120
+ $api = Mage::helper('payson/api');
121
+ $helper = Mage::helper('payson');
122
+ $api->PaymentDetails($order_id);
123
+ $details = $api->GetResponse();
124
+
125
+ if (($details->type === Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
126
+ ($details->invoiceStatus === Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED) ||
127
+ ($details->type !== Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE && $details->status === Payson_Payson_Helper_Api::STATUS_CREATED) ||
128
+ $order->getState() === Mage_Sales_Model_Order::STATE_PROCESSING) {
129
+ $api->PaymentUpdate($order_id, Payson_Payson_Helper_Api::UPDATE_ACTION_CANCELORDER);
130
+
131
+ $order->addStatusHistoryComment($helper->__(
132
+ 'Order was canceled at Payson'));
133
+
134
+ $payment->setTransactionId('auth')
135
+ ->setIsTransactionClosed(1);
136
+ //->setShouldCloseParentTransaction(1);
137
+ } else {
138
+ Mage::throwException($helper->__('Payson is not ready to cancel the order. Please try again later.'));
139
+ }
140
+
141
+ return $this;
142
+ }
143
+
144
+ /**
145
+ * Is run when payment method is selected
146
+ *
147
+ * @return void
148
+ */
149
+ /* public function validate()
150
+ {
151
+ $session = Mage::getSingleton('checkout/session');
152
+
153
+ if(isset($_POST['payment']['method']))
154
+ {
155
+ $session->setData('payson_payment_method',
156
+ $_POST['payment']['method']);
157
+ }
158
+ else
159
+ {
160
+ $session->unsetData('payson_payment_method');
161
+ }
162
+ } */
 
 
 
 
 
 
 
 
163
  }
164
 
app/code/community/Payson/Payson/Model/Method/Invoice.php CHANGED
@@ -1,138 +1,118 @@
1
  <?php
2
- class Payson_Payson_Model_Method_Invoice
3
- extends Payson_Payson_Model_Method_Abstract
4
- {
5
- /*
6
- * Protected properties
7
- */
8
-
9
- /**
10
- * @inheritDoc
11
- */
12
- protected $_code = 'payson_invoice';
13
- protected $_formBlockType = 'payson/invoice_form';
14
-
15
- /**
16
- * @inheritDoc
17
- */
18
- protected $_canCapture = true;
19
- protected $_canRefund = true;
20
- protected $_canVoid = true;
21
- //protected $_canUseCheckout = true;
22
- private $invoiceAmountMinLimit = 30;
23
-
24
- /*
25
- * Public methods
26
- */
27
-
28
- /**
29
- * @inheritDoc
30
- */
31
- public function capture(Varien_Object $payment, $amount)
32
- {
33
- $order = $payment->getOrder();
34
- $order_id = $order->getData('increment_id');
35
-
36
- $api = Mage::helper('payson/api');
37
- $helper = Mage::helper('payson');
38
- $api->PaymentDetails($order_id);
39
- $details = $api->GetResponse();
40
-
41
- if(($details->type ===
42
- Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
43
- ($details->invoiceStatus ===
44
- Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED))
45
- {
46
- $api->PaymentUpdate($order_id,
47
- Payson_Payson_Helper_Api::UPDATE_ACTION_SHIPORDER);
48
-
49
- $order->addStatusHistoryComment($helper->__(
50
- 'Order was activated at Payson'));
51
- }
52
- else
53
- {
54
- Mage::throwException($helper->__('Payson is not ready to create an invoice. Please try again later.'));
55
- }
56
-
57
- return $this;
58
- }
59
-
60
- /**
61
- * @inheritDoc
62
- */
63
- public function authorize(Varien_Object $payment, $amount)
64
- {
65
- $payment->setTransactionId('auth')->setIsTransactionClosed(0);
66
-
67
- return $this;
68
- }
69
-
70
-
71
-
72
- /**
73
- * @inheritDoc
74
- */
75
- public function getTitle()
76
- {
77
- //if(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal() >> 30)
78
- // echo Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal(); //$this->_canUseCheckout = false;
79
- $order = Mage::registry('current_order');
80
-
81
- if(!isset($order) && ($invoice = Mage::registry('current_invoice')))
82
- {
83
- $order = $invoice->getOrder();
84
- }
85
-
86
- if(isset($order))
87
- {
88
- $invoice_fee = $order->getPaysonInvoiceFee();
89
-
90
- if($invoice_fee)
91
- {
92
- $invoice_fee = $order->formatPrice($invoice_fee);
93
- }
94
- }
95
- else
96
- {
97
- $invoice_fee = Mage::getModel('payson/config')
98
- ->GetInvoiceFeeInclTax($this->getQuote());
99
-
100
- if($invoice_fee)
101
- {
102
- $invoice_fee = Mage::app()->getStore()
103
- ->formatPrice($invoice_fee);
104
- }
105
- }
106
-
107
- $invoice_fee = strip_tags($invoice_fee);
108
-
109
- return sprintf(Mage::helper('payson')
110
- ->__('Checkout with Payson invoice %s invoice fee'),
111
- ($invoice_fee ? '+' . $invoice_fee : ''));
112
- }
113
-
114
- public function canUseCheckout()
115
- {
116
- if($this->isSweden()){
117
- if(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal() < $this->invoiceAmountMinLimit)
118
- return false;
119
- else
120
- return true;
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  }
123
- return false;
124
  }
125
-
126
- public function isSweden()
127
- {
128
- $checkout = Mage::getSingleton('checkout/session')->getQuote();
129
- $billing = $checkout->getBillingAddress();
130
- //$shipping = $checkout->getShippingAddress();
131
- if(strtoupper($billing->getCountry()) != 'SE')
 
 
 
132
  return false;
133
- else
134
  return true;
135
-
136
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  }
138
 
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ class Payson_Payson_Model_Method_Invoice extends Payson_Payson_Model_Method_Abstract {
4
+ /*
5
+ * Protected properties
6
+ */
7
+
8
+ /**
9
+ * @inheritDoc
10
+ */
11
+ protected $_code = 'payson_invoice';
12
+ protected $_formBlockType = 'payson/invoice_form';
13
+
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ protected $_canCapture = true;
18
+ protected $_canRefund = true;
19
+ protected $_canVoid = true;
20
+ //protected $_canUseCheckout = true;
21
+ private $invoiceAmountMinLimit = 30;
22
+
23
+ /*
24
+ * Public methods
25
+ */
26
+
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ public function capture(Varien_Object $payment, $amount) {
31
+ $order = $payment->getOrder();
32
+ $order_id = $order->getData('increment_id');
33
+
34
+ $api = Mage::helper('payson/api');
35
+ $helper = Mage::helper('payson');
36
+ $api->PaymentDetails($order_id);
37
+ $details = $api->GetResponse();
38
+
39
+ if (($details->type ===
40
+ Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
41
+ ($details->invoiceStatus ===
42
+ Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED)) {
43
+ $api->PaymentUpdate($order_id, Payson_Payson_Helper_Api::UPDATE_ACTION_SHIPORDER);
44
+
45
+ $order->addStatusHistoryComment($helper->__(
46
+ 'Order was activated at Payson'));
47
+ } else {
48
+ Mage::throwException($helper->__('Payson is not ready to create an invoice. Please try again later.'));
49
+ }
50
+
51
+ return $this;
52
+ }
53
+
54
+ /**
55
+ * @inheritDoc
56
+ */
57
+ public function authorize(Varien_Object $payment, $amount) {
58
+ $payment->setTransactionId('auth')->setIsTransactionClosed(0);
59
+
60
+ return $this;
61
+ }
62
+
63
+ /**
64
+ * @inheritDoc
65
+ */
66
+ public function getTitle() {
67
+ //if(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal() >> 30)
68
+ // echo Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal(); //$this->_canUseCheckout = false;
69
+ $order = Mage::registry('current_order');
70
+
71
+ if (!isset($order) && ($invoice = Mage::registry('current_invoice'))) {
72
+ $order = $invoice->getOrder();
73
+ }
74
+
75
+ if (isset($order)) {
76
+ $invoice_fee = $order->getPaysonInvoiceFee();
77
+
78
+ if ($invoice_fee) {
79
+ $invoice_fee = $order->formatPrice($invoice_fee);
80
+ }
81
+ } else {
82
+ $invoice_fee = Mage::getModel('payson/config')
83
+ ->GetInvoiceFeeInclTax($this->getQuote());
84
+
85
+ if ($invoice_fee) {
86
+ $invoice_fee = Mage::app()->getStore()
87
+ ->formatPrice($invoice_fee);
88
  }
 
89
  }
90
+
91
+ $invoice_fee = strip_tags($invoice_fee);
92
+
93
+ return sprintf(Mage::helper('payson')
94
+ ->__('Checkout with Payson invoice %s invoice fee'), ($invoice_fee ? '+' . $invoice_fee : ''));
95
+ }
96
+
97
+ public function canUseCheckout() {
98
+ if ($this->isSweden()) {
99
+ if (Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal() < $this->invoiceAmountMinLimit)
100
  return false;
101
+ else
102
  return true;
 
103
  }
104
+ return false;
105
+ }
106
+
107
+ public function isSweden() {
108
+ $checkout = Mage::getSingleton('checkout/session')->getQuote();
109
+ $billing = $checkout->getBillingAddress();
110
+ //$shipping = $checkout->getShippingAddress();
111
+ if (strtoupper($billing->getCountry()) != 'SE')
112
+ return false;
113
+ else
114
+ return true;
115
+ }
116
+
117
  }
118
 
app/code/community/Payson/Payson/Model/Method/Standard.php CHANGED
@@ -1,40 +1,39 @@
1
  <?php
2
- class Payson_Payson_Model_Method_Standard
3
- extends Payson_Payson_Model_Method_Abstract
4
- {
5
- /*
6
- * Protected properties
7
- */
8
- protected $_canCapture = true;
9
- protected $_canRefund = true;
10
- protected $_canVoid = true;
11
-
12
- /**
13
- * @inheritDoc
14
- */
15
- protected $_code = 'payson_standard';
16
- protected $_formBlockType = 'payson/standard_form';
17
-
18
- /*
19
- * Public methods
20
- */
21
-
22
- /**
23
- * @inheritDoc
24
- */
25
- public function getTitle()
26
- {
27
- return Mage::helper('payson')->__('Checkout with Payson');
28
- }
29
-
30
- /**
31
- * @inheritDoc
32
- */
33
- public function authorize(Varien_Object $payment, $amount)
34
- {
35
- $payment->setTransactionId('auth')->setIsTransactionClosed(0);
36
-
37
- return $this;
38
- }
39
  }
40
 
1
  <?php
2
+
3
+ class Payson_Payson_Model_Method_Standard extends Payson_Payson_Model_Method_Abstract {
4
+ /*
5
+ * Protected properties
6
+ */
7
+
8
+ protected $_canCapture = true;
9
+ protected $_canRefund = true;
10
+ protected $_canVoid = true;
11
+
12
+ /**
13
+ * @inheritDoc
14
+ */
15
+ protected $_code = 'payson_standard';
16
+ protected $_formBlockType = 'payson/standard_form';
17
+
18
+ /*
19
+ * Public methods
20
+ */
21
+
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ public function getTitle() {
26
+ return Mage::helper('payson')->__('Checkout with Payson');
27
+ }
28
+
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ public function authorize(Varien_Object $payment, $amount) {
33
+ $payment->setTransactionId('auth')->setIsTransactionClosed(0);
34
+
35
+ return $this;
36
+ }
37
+
 
38
  }
39
 
app/code/community/Payson/Payson/Model/Mysql4/Setup.php CHANGED
@@ -1,5 +1,6 @@
1
  <?php
2
- class Payson_Payson_Model_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup
3
- {
 
4
  }
5
 
1
  <?php
2
+
3
+ class Payson_Payson_Model_Mysql4_Setup extends Mage_Sales_Model_Mysql4_Setup {
4
+
5
  }
6
 
app/code/community/Payson/Payson/Model/Order/Creditmemo/Total/Invoice.php CHANGED
@@ -1,45 +1,44 @@
1
  <?php
2
- class Payson_Payson_Model_Order_Creditmemo_Total_Invoice extends
3
- Mage_Sales_Model_Order_Creditmemo_Total_Abstract
4
- {
5
- protected $_code = 'payson_invoice';
6
 
7
- public function collect(Mage_Sales_Model_Order_Creditmemo $invoice)
8
- {
9
- $order = $invoice->getOrder();
10
 
11
- $method = $order->getPayment()->getMethodInstance()->getCode(); /* Should be getMethod() */
12
 
13
- if($method !== 'payson_invoice')
14
- {
15
- return $this;
16
- }
17
 
18
- /*if($order->hasInvoices() !== 0)
19
- {
20
- return $this;
21
- }*/
22
 
23
- $base_fee = $order->getBasePaysonInvoiceFee();
24
- $fee = $order->getPaysonInvoiceFee();
 
25
 
26
- if(!$base_fee || !$fee)
27
- {
28
- return $this;
29
- }
30
 
31
- $base_grand_total = $invoice->getBaseGrandTotal();
32
- $base_grand_total += $base_fee;
33
- $grand_total = $invoice->getGrandTotal();
34
- $grand_total += $fee;
35
 
36
- $invoice->setBasePaysonInvoiceFee($base_fee);
37
- $invoice->setPaysonInvoiceFee($fee);
 
38
 
39
- $invoice->setBaseGrandTotal($base_grand_total);
40
- $invoice->setGrandTotal($grand_total);
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- return $this;
43
- }
44
  }
45
 
1
  <?php
 
 
 
 
2
 
3
+ class Payson_Payson_Model_Order_Creditmemo_Total_Invoice extends
4
+ Mage_Sales_Model_Order_Creditmemo_Total_Abstract {
 
5
 
6
+ protected $_code = 'payson_invoice';
7
 
8
+ public function collect(Mage_Sales_Model_Order_Creditmemo $invoice) {
9
+ $order = $invoice->getOrder();
 
 
10
 
11
+ $method = $order->getPayment()->getMethodInstance()->getCode(); /* Should be getMethod() */
 
 
 
12
 
13
+ if ($method !== 'payson_invoice') {
14
+ return $this;
15
+ }
16
 
17
+ /* if($order->hasInvoices() !== 0)
18
+ {
19
+ return $this;
20
+ } */
21
 
22
+ $base_fee = $order->getBasePaysonInvoiceFee();
23
+ $fee = $order->getPaysonInvoiceFee();
 
 
24
 
25
+ if (!$base_fee || !$fee) {
26
+ return $this;
27
+ }
28
 
29
+ $base_grand_total = $invoice->getBaseGrandTotal();
30
+ $base_grand_total += $base_fee;
31
+ $grand_total = $invoice->getGrandTotal();
32
+ $grand_total += $fee;
33
+
34
+ $invoice->setBasePaysonInvoiceFee($base_fee);
35
+ $invoice->setPaysonInvoiceFee($fee);
36
+
37
+ $invoice->setBaseGrandTotal($base_grand_total);
38
+ $invoice->setGrandTotal($grand_total);
39
+
40
+ return $this;
41
+ }
42
 
 
 
43
  }
44
 
app/code/community/Payson/Payson/Model/Order/Invoice/Total/Invoice.php CHANGED
@@ -1,45 +1,43 @@
1
  <?php
2
- class Payson_Payson_Model_Order_Invoice_Total_Invoice extends
3
- Mage_Sales_Model_Order_Invoice_Total_Abstract
4
- {
5
- protected $_code = 'payson_invoice';
6
 
7
- public function collect(Mage_Sales_Model_Order_Invoice $invoice)
8
- {
9
- $order = $invoice->getOrder();
10
 
11
- $method = $order->getPayment()->getMethodInstance()->getCode(); /* Should be getMethod() */
12
 
13
- if($method !== 'payson_invoice')
14
- {
15
- return $this;
16
- }
17
 
18
- if($order->hasInvoices() == 0)
19
- {
20
- return $this;
21
- }
22
 
23
- $base_fee = $order->getBasePaysonInvoiceFee();
24
- $fee = $order->getPaysonInvoiceFee();
 
25
 
26
- if(!$base_fee || !$fee)
27
- {
28
- return $this;
29
- }
30
 
31
- $base_grand_total = $invoice->getBaseGrandTotal();
32
- $base_grand_total += $base_fee;
33
- $grand_total = $invoice->getGrandTotal();
34
- $grand_total += $fee;
35
 
36
- $invoice->setBasePaysonInvoiceFee($base_fee);
37
- $invoice->setPaysonInvoiceFee($fee);
 
38
 
39
- $invoice->setBaseGrandTotal($base_grand_total);
40
- $invoice->setGrandTotal($grand_total);
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- return $this;
43
- }
44
  }
45
 
1
  <?php
 
 
 
 
2
 
3
+ class Payson_Payson_Model_Order_Invoice_Total_Invoice extends
4
+ Mage_Sales_Model_Order_Invoice_Total_Abstract {
 
5
 
6
+ protected $_code = 'payson_invoice';
7
 
8
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice) {
9
+ $order = $invoice->getOrder();
 
 
10
 
11
+ $method = $order->getPayment()->getMethodInstance()->getCode(); /* Should be getMethod() */
 
 
 
12
 
13
+ if ($method !== 'payson_invoice') {
14
+ return $this;
15
+ }
16
 
17
+ if ($order->hasInvoices() == 0) {
18
+ return $this;
19
+ }
 
20
 
21
+ $base_fee = $order->getBasePaysonInvoiceFee();
22
+ $fee = $order->getPaysonInvoiceFee();
 
 
23
 
24
+ if (!$base_fee || !$fee) {
25
+ return $this;
26
+ }
27
 
28
+ $base_grand_total = $invoice->getBaseGrandTotal();
29
+ $base_grand_total += $base_fee;
30
+ $grand_total = $invoice->getGrandTotal();
31
+ $grand_total += $fee;
32
+
33
+ $invoice->setBasePaysonInvoiceFee($base_fee);
34
+ $invoice->setPaysonInvoiceFee($fee);
35
+
36
+ $invoice->setBaseGrandTotal($base_grand_total);
37
+ $invoice->setGrandTotal($grand_total);
38
+
39
+ return $this;
40
+ }
41
 
 
 
42
  }
43
 
app/code/community/Payson/Payson/Model/Quote/Address/Total/Invoice.php CHANGED
@@ -1,68 +1,64 @@
1
  <?php
2
- class Payson_Payson_Model_Quote_Address_Total_Invoice extends
3
- Mage_Sales_Model_Quote_Address_Total_Abstract
4
- {
5
- protected $_code = 'payson_invoice';
6
 
7
- public function collect(Mage_Sales_Model_Quote_Address $address)
8
- {
9
- if($address->getAddressType() !== 'shipping')
10
- {
11
- return $this;
12
- }
13
 
14
- $address->setBasePaysonInvoiceFee(0);
15
- $address->setPaysonInvoiceFee(0);
16
 
17
- $quote = $address->getQuote();
 
 
 
18
 
19
- if(is_null($quote->getId()))
20
- {
21
- return $this;
22
- }
23
 
24
- $method = $address->getQuote()->getPayment()->getMethod();
25
 
26
- if($method !== 'payson_invoice')
27
- {
28
- return $this;
29
- }
30
 
31
- $store = $quote->getStore();
32
- $config = Mage::getModel('payson/config');
33
 
34
- $fee = $config->GetInvoiceFeeInclTax($quote);
 
 
35
 
36
- $base_grand_total = $address->getBaseGrandTotal();
37
- $base_grand_total += $fee;
38
 
39
- // TODO: update tax in another model?
40
 
41
- $address->setBasePaysonInvoiceFee($fee);
42
- $address->setPaysonInvoiceFee($store->convertPrice($fee, false));
43
 
44
- $address->setBaseGrandTotal($base_grand_total);
45
- $address->setGrandTotal($store->convertPrice($base_grand_total, false));
46
 
47
- //$this->_addBaseAmount($fee);
48
- //$this->_addAmount($fee);
49
 
50
- return $this;
51
- }
52
 
53
- public function fetch(Mage_Sales_Model_Quote_Address $address)
54
- {
55
- if(($fee = $address->getPaysonInvoiceFee()) > 0)
56
- {
57
- $address->addTotal(array
58
- (
59
- 'code' => $this->getCode(),
60
- 'title' => Mage::helper('payson')->__('Invoice fee'),
61
- 'value' => $fee
62
- ));
63
- }
 
 
 
 
 
 
 
64
 
65
- return $this;
66
- }
67
  }
68
 
1
  <?php
 
 
 
 
2
 
3
+ class Payson_Payson_Model_Quote_Address_Total_Invoice extends
4
+ Mage_Sales_Model_Quote_Address_Total_Abstract {
 
 
 
 
5
 
6
+ protected $_code = 'payson_invoice';
 
7
 
8
+ public function collect(Mage_Sales_Model_Quote_Address $address) {
9
+ if ($address->getAddressType() !== 'shipping') {
10
+ return $this;
11
+ }
12
 
13
+ $address->setBasePaysonInvoiceFee(0);
14
+ $address->setPaysonInvoiceFee(0);
 
 
15
 
16
+ $quote = $address->getQuote();
17
 
18
+ if (is_null($quote->getId())) {
19
+ return $this;
20
+ }
 
21
 
22
+ $method = $address->getQuote()->getPayment()->getMethod();
 
23
 
24
+ if ($method !== 'payson_invoice') {
25
+ return $this;
26
+ }
27
 
28
+ $store = $quote->getStore();
29
+ $config = Mage::getModel('payson/config');
30
 
31
+ $fee = $config->GetInvoiceFeeInclTax($quote);
32
 
33
+ $base_grand_total = $address->getBaseGrandTotal();
34
+ $base_grand_total += $fee;
35
 
36
+ // TODO: update tax in another model?
 
37
 
38
+ $address->setBasePaysonInvoiceFee($fee);
39
+ $address->setPaysonInvoiceFee($store->convertPrice($fee, false));
40
 
41
+ $address->setBaseGrandTotal($base_grand_total);
42
+ $address->setGrandTotal($store->convertPrice($base_grand_total, false));
43
 
44
+ //$this->_addBaseAmount($fee);
45
+ //$this->_addAmount($fee);
46
+
47
+ return $this;
48
+ }
49
+
50
+ public function fetch(Mage_Sales_Model_Quote_Address $address) {
51
+ if (($fee = $address->getPaysonInvoiceFee()) > 0) {
52
+ $address->addTotal(array
53
+ (
54
+ 'code' => $this->getCode(),
55
+ 'title' => Mage::helper('payson')->__('Invoice fee'),
56
+ 'value' => $fee
57
+ ));
58
+ }
59
+
60
+ return $this;
61
+ }
62
 
 
 
63
  }
64
 
app/code/community/Payson/Payson/Model/Standard.php CHANGED
@@ -1,131 +1,118 @@
1
  <?php
2
- class Payson_Payson_Model_Standard extends Mage_Payment_Model_Method_Abstract
3
- {
4
- /*
5
- * Protected properties
6
- */
7
-
8
- /**
9
- * @inheritDoc
10
- */
11
- protected $_code = 'payson';
12
- protected $_formBlockType = 'payson/form';
13
- //protected $_infoBlockType = 'payson/info';
14
-
15
- /**
16
- * @inheritDoc
17
- */
18
- protected $_isGateway = false;
19
- protected $_canAuthorize = false;
20
- protected $_canCapture = true;
21
- protected $_canCapturePartial = false;
22
- protected $_canRefund = false;
23
- protected $_canRefundInvoicePartial = false;
24
- protected $_canVoid = false;
25
- protected $_canUseInternal = true;
26
- protected $_canUseCheckout = true;
27
- protected $_canUseForMultishipping = false;
28
- protected $_isInitializeNeeded = false;
29
- protected $_canFetchTransactionInfo = false;
30
- protected $_canReviewPayment = false;
31
- protected $_canCreateBillingAgreement = false;
32
- protected $_canManageRecurringProfiles = false;
33
-
34
-
35
- /**
36
- * @inheritDoc
37
- */
38
- protected $_canCancelInvoice = false;
39
-
40
- /*
41
- * Public methods
42
- */
43
-
44
- /**
45
- * @inheritDoc
46
- */
47
- public function initialize($payment_action, $state_object)
48
- {
49
- $state_object->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
50
- $state_object->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
51
- $state_object->setIsNotified(false);
52
-
53
- return $this;
54
- }
55
-
56
- /**
57
- * @inheritDoc
58
- */
59
- public function capture(Varien_Object $payment, $amount)
60
- {
61
- $order = $payment->getOrder();
62
- $order_id = $order->getData('increment_id');
63
-
64
- $api = Mage::helper('payson/api');
65
-
66
- $api->PaymentDetails($order_id);
67
- $details = $api->GetResponse();
68
-
69
- if(($details->type ===
70
- Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
71
- ($details->invoiceStatus ===
72
- Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED))
73
- {
74
- $api->PaymentUpdate($order_id,
75
- Payson_Payson_Helper_Api::UPDATE_ACTION_SHIPORDER);
76
- }
77
-
78
- return $this;
79
- }
80
-
81
- /**
82
- * Redirect url when user place order
83
- *
84
- * @return string
85
- */
86
- public function getOrderPlaceRedirectUrl()
87
- {
88
- return Mage::getUrl('payson/checkout/redirect',
89
- array('_secure' => true));
90
- }
91
-
92
- /**
93
- * Whether this paymend method is available for specified currency
94
- *
95
- * @param string $currency
96
- * @return bool
97
- */
98
- public function canUseForCurrency($currency)
99
- {
100
- return Mage::getModel('payson/config')->IsCurrencySupported($currency);
101
- }
102
-
103
- /**
104
- * Is run when payment method is selected
105
- *
106
- * @return void
107
- */
108
- public function validate()
109
- {
110
- $session = Mage::getSingleton('checkout/session');
111
-
112
- if(isset($_POST['payment']['payson_payment_method']))
113
- {
114
- $session->setData('payson_payment_method',
115
- $_POST['payment']['payson_payment_method']);
116
- }
117
- else
118
- {
119
- $session->unsetData('payson_payment_method');
120
- }
121
- }
122
-
123
- /**
124
- * @inheritDoc
125
- */
126
- public function getTitle()
127
- {
128
- return Mage::Helper('payson')->__('Checkout with Payson');
129
- }
130
  }
131
 
1
  <?php
2
+
3
+ class Payson_Payson_Model_Standard extends Mage_Payment_Model_Method_Abstract {
4
+ /*
5
+ * Protected properties
6
+ */
7
+
8
+ /**
9
+ * @inheritDoc
10
+ */
11
+ protected $_code = 'payson';
12
+ protected $_formBlockType = 'payson/form';
13
+ //protected $_infoBlockType = 'payson/info';
14
+
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ protected $_isGateway = false;
19
+ protected $_canAuthorize = false;
20
+ protected $_canCapture = true;
21
+ protected $_canCapturePartial = false;
22
+ protected $_canRefund = false;
23
+ protected $_canRefundInvoicePartial = false;
24
+ protected $_canVoid = false;
25
+ protected $_canUseInternal = true;
26
+ protected $_canUseCheckout = true;
27
+ protected $_canUseForMultishipping = false;
28
+ protected $_isInitializeNeeded = false;
29
+ protected $_canFetchTransactionInfo = false;
30
+ protected $_canReviewPayment = false;
31
+ protected $_canCreateBillingAgreement = false;
32
+ protected $_canManageRecurringProfiles = false;
33
+
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ protected $_canCancelInvoice = false;
38
+
39
+ /*
40
+ * Public methods
41
+ */
42
+
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ public function initialize($payment_action, $state_object) {
47
+ $state_object->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
48
+ $state_object->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
49
+ $state_object->setIsNotified(false);
50
+
51
+ return $this;
52
+ }
53
+
54
+ /**
55
+ * @inheritDoc
56
+ */
57
+ public function capture(Varien_Object $payment, $amount) {
58
+ $order = $payment->getOrder();
59
+ $order_id = $order->getData('increment_id');
60
+
61
+ $api = Mage::helper('payson/api');
62
+
63
+ $api->PaymentDetails($order_id);
64
+ $details = $api->GetResponse();
65
+
66
+ if (($details->type ===
67
+ Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
68
+ ($details->invoiceStatus ===
69
+ Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED)) {
70
+ $api->PaymentUpdate($order_id, Payson_Payson_Helper_Api::UPDATE_ACTION_SHIPORDER);
71
+ }
72
+
73
+ return $this;
74
+ }
75
+
76
+ /**
77
+ * Redirect url when user place order
78
+ *
79
+ * @return string
80
+ */
81
+ public function getOrderPlaceRedirectUrl() {
82
+ return Mage::getUrl('payson/checkout/redirect', array('_secure' => true));
83
+ }
84
+
85
+ /**
86
+ * Whether this paymend method is available for specified currency
87
+ *
88
+ * @param string $currency
89
+ * @return bool
90
+ */
91
+ public function canUseForCurrency($currency) {
92
+ return Mage::getModel('payson/config')->IsCurrencySupported($currency);
93
+ }
94
+
95
+ /**
96
+ * Is run when payment method is selected
97
+ *
98
+ * @return void
99
+ */
100
+ public function validate() {
101
+ $session = Mage::getSingleton('checkout/session');
102
+
103
+ if (isset($_POST['payment']['payson_payment_method'])) {
104
+ $session->setData('payson_payment_method', $_POST['payment']['payson_payment_method']);
105
+ } else {
106
+ $session->unsetData('payson_payment_method');
107
+ }
108
+ }
109
+
110
+ /**
111
+ * @inheritDoc
112
+ */
113
+ public function getTitle() {
114
+ return Mage::Helper('payson')->__('Checkout with Payson');
115
+ }
116
+
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  }
118
 
app/code/community/Payson/Payson/controllers/CheckoutController.php CHANGED
@@ -1,135 +1,137 @@
1
  <?php
2
- class Payson_Payson_CheckoutController extends Mage_Core_Controller_Front_Action
3
- {
4
- /*
5
- * Private properties
6
- */
7
-
8
- private $session;
9
- private $order = null;
10
-
11
- /*
12
- * Private methods
13
- */
14
-
15
- private function GetSession()
16
- {
17
- if(!isset($this->session))
18
- {
19
- $this->session = Mage::getSingleton('checkout/session');
20
- }
21
-
22
- return $this->session;
23
- }
24
-
25
- /**
26
- *
27
- * @return Mage_Sales_Model_Order
28
- */
29
- private function GetOrder()
30
- {
31
- if(!isset($this->order))
32
- {
33
- $increment_id = $this->GetSession()->getData('last_real_order_id');
34
-
35
- if($increment_id)
36
- {
37
- $this->order = Mage::getModel('sales/order')
38
- ->loadByIncrementId($increment_id);
39
-
40
- if(is_null($this->order->getId()))
41
- {
42
- $this->order = null;
43
- }
44
- }
45
- }
46
-
47
- return $this->order;
48
- }
49
-
50
- private function CancelOrder($message = '')
51
- {
52
- $order = $this->GetOrder();
53
-
54
- if(!is_null($order = $this->GetOrder()))
55
- {
56
- $order->setState(
57
- Mage_Sales_Model_Order::STATE_CANCELED,
58
- Mage_Sales_Model_Order::STATE_CANCELED,
59
- $message)
60
- ->cancel()->save();
61
- }
62
-
63
- return $this;
64
- }
65
-
66
- /*
67
- * Public methods
68
- */
69
-
70
- public function redirectAction()
71
- {
72
- $order = $this->GetOrder();
73
-
74
- if(is_null($order))
75
- {
76
- $this->_redirect('checkout/cart');
77
-
78
- return;
79
- }
80
-
81
- try
82
- {
83
- $api = Mage::helper('payson/api')->Pay($order);
84
-
85
- $order->addStatusHistoryComment(Mage::helper('payson')->__(
86
- 'The customer was redirected to Payson'))
87
- ->save();
88
-
89
- $this->GetResponse()->setRedirect($api->GetPayForwardUrl());
90
- }
91
- catch(Exception $e)
92
- {
93
- $this->CancelOrder($e->getMessage());
94
-
95
- Mage::logException($e);
96
-
97
- Mage::getSingleton('core/session')->addError($e->getMessage());
98
- $this->_redirect('checkout/cart');
99
- }
100
- }
101
-
102
- public function returnAction()
103
- {
104
-
105
- $ipnStatus = Mage::helper('payson/api')->getIpnStatus(Mage::getSingleton('checkout/session')->getLastRealOrderId());
106
- //print_r($ipnStatus);exit;
107
- switch($ipnStatus['ipn_status'])
108
- {
109
- case 'COMPLETED':
110
- case 'PENDING':
111
- case 'PROCESSING':
112
- case 'CREDITED':
113
- {
114
- $this->GetOrder()->sendNewOrderEmail();
115
- $this->_redirect('checkout/onepage/success');
116
- break;
117
- }
118
- case 'ERROR':
119
- {
120
- Mage::helper('payson/api')->paysonApiError(sprintf(Mage::helper('payson')->__('The payment was denied by Payson. Please, try a different payment method')));
121
- break;
122
- }
123
- default:
124
- {
125
- Mage::helper('payson/api')->paysonApiError(sprintf(Mage::helper('payson')->__('Something went wrong with the payment. Please, try a different payment method')));
126
- break;
127
- }
128
- }
129
- }
130
-
131
- public function cancelAction()
132
- {
133
- $this->CancelOrder()->_redirect('checkout/cart');
134
- }
 
 
135
  }
1
  <?php
2
+
3
+ class Payson_Payson_CheckoutController extends Mage_Core_Controller_Front_Action {
4
+ /*
5
+ * Private properties
6
+ */
7
+
8
+ private $session;
9
+ private $order = null;
10
+
11
+ /*
12
+ * Private methods
13
+ */
14
+
15
+ private function GetSession() {
16
+ if (!isset($this->session)) {
17
+ $this->session = Mage::getSingleton('checkout/session');
18
+ }
19
+
20
+ return $this->session;
21
+ }
22
+
23
+ /**
24
+ *
25
+ * @return Mage_Sales_Model_Order
26
+ */
27
+ private function GetOrder() {
28
+ if (!isset($this->order)) {
29
+ $increment_id = $this->GetSession()->getData('last_real_order_id');
30
+
31
+ if ($increment_id) {
32
+ $this->order = Mage::getModel('sales/order')
33
+ ->loadByIncrementId($increment_id);
34
+
35
+ if (is_null($this->order->getId())) {
36
+ $this->order = null;
37
+ }
38
+ }
39
+ }
40
+
41
+ return $this->order;
42
+ }
43
+
44
+ private function CancelOrder($message = '') {
45
+ $order = $this->GetOrder();
46
+
47
+ if (!is_null($order = $this->GetOrder())) {
48
+ $order->cancel();
49
+
50
+ if ($message != '')
51
+ $order->addStatusHistoryComment($message);
52
+ }
53
+
54
+ $order->save();
55
+ return $this;
56
+ }
57
+
58
+ /*
59
+ * Public methods
60
+ */
61
+
62
+ public function redirectAction() {
63
+ $order = $this->GetOrder();
64
+
65
+ if (is_null($order)) {
66
+ $this->_redirect('checkout/cart');
67
+
68
+ return;
69
+ }
70
+
71
+ try {
72
+ $api = Mage::helper('payson/api')->Pay($order);
73
+
74
+ $order->addStatusHistoryComment(Mage::helper('payson')->__(
75
+ 'The customer was redirected to Payson'))
76
+ ->save();
77
+
78
+ $this->GetResponse()->setRedirect($api->GetPayForwardUrl());
79
+ } catch (Exception $e) {
80
+ $this->CancelOrder($e->getMessage());
81
+
82
+ Mage::logException($e);
83
+
84
+ Mage::getSingleton('core/session')->addError($e->getMessage());
85
+ $this->_redirect('checkout/cart');
86
+ }
87
+ }
88
+
89
+ public function returnAction() {
90
+ $config = Mage::getModel('payson/config');
91
+ $paymentDetailsResponse = Mage::helper('payson/api')->PaymentDetails(Mage::getSingleton('checkout/session')->getLastRealOrderId())->getResponse();
92
+ $paymentStatus = $paymentDetailsResponse->status;
93
+ switch ($paymentStatus) {
94
+ case 'COMPLETED':
95
+ case 'PENDING':
96
+ case 'PROCESSING':
97
+ case 'CREDITED': {
98
+ $this->GetOrder()->sendNewOrderEmail();
99
+ $this->_redirect('checkout/onepage/success');
100
+ break;
101
+ }
102
+ case 'ERROR': {
103
+ $errorMessage = Mage::helper('payson')->__('The payment was denied by Payson. Please, try a different payment method');
104
+ Mage::getSingleton('core/session')->addError($errorMessage);
105
+ if ($config->restoreCartOnError())
106
+ $this->restoreCart();
107
+
108
+ $this->_redirect('checkout');
109
+ break;
110
+ }
111
+ default: {
112
+ Mage::getSingleton('core/session')->addError(sprintf(Mage::helper('payson')->__('Something went wrong with the payment. Please, try a different payment method')));
113
+ $this->_redirect('checkout');
114
+ break;
115
+ }
116
+ }
117
+ }
118
+
119
+ public function cancelAction() {
120
+ $config = Mage::getModel('payson/config');
121
+ $cancelMessage = Mage::helper('payson')->__('Something went wrong with the payment. Please, try a different payment method');
122
+ Mage::getSingleton('core/session')->addError($cancelMessage);
123
+ $this->CancelOrder($cancelMessage);
124
+ if ($config->restoreCartOnCancel())
125
+ $this->restoreCart();
126
+
127
+
128
+ $this->_redirect('checkout');
129
+ }
130
+
131
+ private function restoreCart() {
132
+ $quoteId = $this->GetOrder()->getQuoteId();
133
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
134
+ $quote->setIsActive(true)->save();
135
+ }
136
+
137
  }
app/code/community/Payson/Payson/controllers/IpnController.php CHANGED
@@ -1,29 +1,25 @@
1
  <?php
2
- class Payson_Payson_IpnController extends Mage_Core_Controller_Front_Action
3
- {
4
- public function notifyAction()
5
- {
6
- $request = $this->getRequest();
7
- $response = $this->getResponse();
8
-
9
- if(!$request->isPost())
10
- {
11
- $response->setHttpResponseCode(503)->setBody('No!');
12
-
13
- return;
14
- }
15
-
16
- try
17
- {
18
- $api = Mage::helper('payson/api')->Validate($request->getRawBody(),
19
- $request->getHeader('Content-Type'));
20
- }
21
- catch(Exception $e)
22
- {
23
- $response->setHttpResponseCode(503)->setBody($e->getMessage());
24
-
25
- return;
26
- }
27
- }
28
  }
29
 
1
  <?php
2
+
3
+ class Payson_Payson_IpnController extends Mage_Core_Controller_Front_Action {
4
+
5
+ public function notifyAction() {
6
+ $request = $this->getRequest();
7
+ $response = $this->getResponse();
8
+
9
+ if (!$request->isPost()) {
10
+ $response->setHttpResponseCode(503)->setBody('No!');
11
+
12
+ return;
13
+ }
14
+
15
+ try {
16
+ $api = Mage::helper('payson/api')->Validate($request->getRawBody(), $request->getHeader('Content-Type'));
17
+ } catch (Exception $e) {
18
+ $response->setHttpResponseCode(503)->setBody($e->getMessage());
19
+
20
+ return;
21
+ }
22
+ }
23
+
 
 
 
 
24
  }
25
 
app/code/community/Payson/Payson/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Payson_Payson>
5
- <version>0.1.3</version>
6
  </Payson_Payson>
7
  </modules>
8
  <admin>
@@ -92,21 +92,21 @@
92
  </payson_invoice_fee>
93
  </sales_convert_quote_address>
94
  <!--<sales_convert_order>
95
- <base_payson_invoice_fee>
96
- <to_quote>*</to_quote>
97
- </base_payson_invoice_fee>
98
- <payson_invoice_fee>
99
- <to_quote>*</to_quote>
100
- </payson_invoice_fee>
101
- </sales_convert_order>
102
- <sales_convert_quote>
103
- <base_payson_invoice_fee>
104
- <to_order>*</to_order>
105
- </base_payson_invoice_fee>
106
- <payson_invoice_fee>
107
- <to_order>*</to_order>
108
- </payson_invoice_fee>
109
- </sales_convert_quote>-->
110
  </fieldsets>
111
  </global>
112
  <frontend>
@@ -166,6 +166,8 @@
166
  <payment_action>authorize</payment_action>
167
  <order_status>pending_payment</order_status>
168
  <payment_guarantee>1</payment_guarantee>
 
 
169
  </payson_standard>
170
  <payson_invoice>
171
  <active>0</active>
2
  <config>
3
  <modules>
4
  <Payson_Payson>
5
+ <version>1.0</version>
6
  </Payson_Payson>
7
  </modules>
8
  <admin>
92
  </payson_invoice_fee>
93
  </sales_convert_quote_address>
94
  <!--<sales_convert_order>
95
+ <base_payson_invoice_fee>
96
+ <to_quote>*</to_quote>
97
+ </base_payson_invoice_fee>
98
+ <payson_invoice_fee>
99
+ <to_quote>*</to_quote>
100
+ </payson_invoice_fee>
101
+ </sales_convert_order>
102
+ <sales_convert_quote>
103
+ <base_payson_invoice_fee>
104
+ <to_order>*</to_order>
105
+ </base_payson_invoice_fee>
106
+ <payson_invoice_fee>
107
+ <to_order>*</to_order>
108
+ </payson_invoice_fee>
109
+ </sales_convert_quote>-->
110
  </fieldsets>
111
  </global>
112
  <frontend>
166
  <payment_action>authorize</payment_action>
167
  <order_status>pending_payment</order_status>
168
  <payment_guarantee>1</payment_guarantee>
169
+ <restore_on_cancel>1</restore_on_cancel>
170
+ <restore_on_error>1</restore_on_error>
171
  </payson_standard>
172
  <payson_invoice>
173
  <active>0</active>
app/code/community/Payson/Payson/etc/system.xml CHANGED
@@ -1,144 +1,164 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <config>
3
- <sections>
4
- <payment>
5
- <groups>
6
- <payson_standard translate="label" module="payson">
7
- <label>Payson</label>
8
- <sort_order>-100</sort_order>
9
- <show_in_default>1</show_in_default>
10
- <show_in_website>1</show_in_website>
11
- <show_in_store>1</show_in_store>
12
- <fields>
13
- <test_mode translate="label,comment">
14
- <label>Test mode</label>
15
- <comment>Enable/disable test mode.</comment>
16
- <frontend_type>select</frontend_type>
17
- <source_model>adminhtml/system_config_source_yesno</source_model>
18
- <sort_order>5</sort_order>
19
- <show_in_default>1</show_in_default>
20
- <show_in_website>1</show_in_website>
21
- <show_in_store>1</show_in_store>
22
- </test_mode>
23
- <active translate="label,comment">
24
- <label>Enabled</label>
25
- <comment>Enable/disable payment with Payson.</comment>
26
- <frontend_type>select</frontend_type>
27
- <source_model>adminhtml/system_config_source_yesno</source_model>
28
- <sort_order>10</sort_order>
29
- <show_in_default>1</show_in_default>
30
- <show_in_website>1</show_in_website>
31
- <show_in_store>1</show_in_store>
32
- </active>
33
- <email translate="label,comment">
34
- <label>Email</label>
35
- <comment>Email address bound to your Payson account.</comment>
36
- <frontend_type>text</frontend_type>
37
- <validate>validate-email</validate>
38
- <sort_order>20</sort_order>
39
- <show_in_default>1</show_in_default>
40
- <show_in_website>0</show_in_website>
41
- <show_in_store>0</show_in_store>
42
- </email>
43
- <agent_id translate="label,comment">
44
- <label>Agent ID</label>
45
- <comment>Agent ID is found on your Payson profile page.</comment>
46
- <frontend_type>text</frontend_type>
47
- <sort_order>30</sort_order>
48
- <show_in_default>1</show_in_default>
49
- <show_in_website>0</show_in_website>
50
- <show_in_store>0</show_in_store>
51
- </agent_id>
52
- <md5_key translate="label,comment">
53
- <label>MD5 key</label>
54
- <comment>MD5 key is found on your Payson profile page.</comment>
55
- <frontend_type>text</frontend_type>
56
- <sort_order>40</sort_order>
57
- <show_in_default>1</show_in_default>
58
- <show_in_website>0</show_in_website>
59
- <show_in_store>0</show_in_store>
60
- </md5_key>
61
- <payment_guarantee translate="label,comment">
62
- <label>Enable payment guarantee</label>
63
- <comment>Enable/disable payment guarantee.</comment>
64
- <frontend_type>select</frontend_type>
65
- <source_model>adminhtml/system_config_source_yesno</source_model>
66
- <sort_order>50</sort_order>
67
- <show_in_default>0</show_in_default>
68
- <show_in_website>0</show_in_website>
69
- <show_in_store>0</show_in_store>
70
- </payment_guarantee>
71
- </fields>
72
- </payson_standard>
73
- <payson_invoice translate="label" module="payson">
74
- <label>Payson invoice</label>
75
- <sort_order>-99</sort_order>
76
- <show_in_default>1</show_in_default>
77
- <show_in_website>1</show_in_website>
78
- <show_in_store>1</show_in_store>
79
- <fields>
80
- <active translate="label,comment">
81
- <label>Enabled</label>
82
- <comment>Enable/disable invoice payment with Payson.</comment>
83
- <frontend_type>select</frontend_type>
84
- <source_model>adminhtml/system_config_source_yesno</source_model>
85
- <sort_order>10</sort_order>
86
- <show_in_default>1</show_in_default>
87
- <show_in_website>1</show_in_website>
88
- <show_in_store>1</show_in_store>
89
- </active>
90
- <!--<activate_invoice translate="label,comment">
91
- <label>Activate invoice on purchase</label>
92
- <comment>Enable this to send Payson invoice to customer instantly after purchase. Disabling this means you have to mark the goods as Shipped in Admin to activate the invoice</comment>
93
- <frontend_type>select</frontend_type>
94
- <source_model>adminhtml/system_config_source_yesno</source_model>
95
- <sort_order>15</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
- </activate_invoice>-->
100
- <invoice_fee_tax translate="label,comment">
101
- <label>Invoice fee tax</label>
102
- <comment>Tax class for invoice fees.</comment>
103
- <frontend_type>select</frontend_type>
104
- <source_model>adminhtml/system_config_source_shipping_taxclass</source_model>
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
- </invoice_fee_tax>
110
- <invoice_fee_sek translate="label,comment">
111
- <label>Invoice fee (SEK)</label>
112
- <comment>Invoice fee for SEK excluding tax.</comment>
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
- </invoice_fee_sek>
119
- <invoice_fee_eur translate="label,comment">
120
- <label>Invoice fee (EUR)</label>
121
- <comment>Invoice fee for EUR excluding tax.</comment>
122
- <frontend_type>text</frontend_type>
123
- <sort_order>40</sort_order>
124
- <show_in_default>1</show_in_default>
125
- <show_in_website>1</show_in_website>
126
- <show_in_store>1</show_in_store>
127
- </invoice_fee_eur>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
- <!--<invoice_minimum_amount translate="label,comment">
130
- <label>Invoice minimum amount (SEK)</label>
131
- <comment>Invoice minimum amount</comment>
132
- <frontend_type>text</frontend_type>
133
- <sort_order>42</sort_order>
134
- <show_in_default>1</show_in_default>
135
- <show_in_website>1</show_in_website>
136
- <show_in_store>1</show_in_store>
137
- </invoice_minimum_amount>-->
138
- </fields>
139
- </payson_invoice>
140
- </groups>
141
- </payment>
142
- </sections>
143
  </config>
144
 
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <payson_standard translate="label" module="payson">
7
+ <label>Payson</label>
8
+ <sort_order>-100</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <fields>
13
+ <test_mode translate="label,comment">
14
+ <label>Test mode</label>
15
+ <comment>Enable/disable test mode.</comment>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>5</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ </test_mode>
23
+ <active translate="label,comment">
24
+ <label>Enabled</label>
25
+ <comment>Enable/disable payment with Payson.</comment>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_yesno</source_model>
28
+ <sort_order>10</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ </active>
33
+ <email translate="label,comment">
34
+ <label>Email</label>
35
+ <comment>Email address bound to your Payson account.</comment>
36
+ <frontend_type>text</frontend_type>
37
+ <validate>validate-email</validate>
38
+ <sort_order>20</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>0</show_in_website>
41
+ <show_in_store>0</show_in_store>
42
+ </email>
43
+ <agent_id translate="label,comment">
44
+ <label>Agent ID</label>
45
+ <comment>Agent ID is found on your Payson profile page.</comment>
46
+ <frontend_type>text</frontend_type>
47
+ <sort_order>30</sort_order>
48
+ <show_in_default>1</show_in_default>
49
+ <show_in_website>0</show_in_website>
50
+ <show_in_store>0</show_in_store>
51
+ </agent_id>
52
+ <md5_key translate="label,comment">
53
+ <label>MD5 key</label>
54
+ <comment>MD5 key is found on your Payson profile page.</comment>
55
+ <frontend_type>text</frontend_type>
56
+ <sort_order>40</sort_order>
57
+ <show_in_default>1</show_in_default>
58
+ <show_in_website>0</show_in_website>
59
+ <show_in_store>0</show_in_store>
60
+ </md5_key>
61
+ <payment_guarantee translate="label,comment">
62
+ <label>Enable payment guarantee</label>
63
+ <comment>Enable/disable payment guarantee.</comment>
64
+ <frontend_type>select</frontend_type>
65
+ <source_model>adminhtml/system_config_source_yesno</source_model>
66
+ <sort_order>50</sort_order>
67
+ <show_in_default>0</show_in_default>
68
+ <show_in_website>0</show_in_website>
69
+ <show_in_store>0</show_in_store>
70
+ </payment_guarantee>
71
+ <restore_on_cancel translate="label,comment">
72
+ <label>Restore cart on cancel</label>
73
+ <comment>Restore cart when customer cancel the payment</comment>
74
+ <frontend_type>select</frontend_type>
75
+ <source_model>adminhtml/system_config_source_yesno</source_model>
76
+ <sort_order>100</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>1</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ </restore_on_cancel>
81
+ <restore_on_error translate="label,comment">
82
+ <label>Restore cart on error</label>
83
+ <comment>Restore cart when status from Payson is error</comment>
84
+ <frontend_type>select</frontend_type>
85
+ <source_model>adminhtml/system_config_source_yesno</source_model>
86
+ <sort_order>150</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>1</show_in_website>
89
+ <show_in_store>1</show_in_store>
90
+ </restore_on_error>
91
+ </fields>
92
+ </payson_standard>
93
+ <payson_invoice translate="label" module="payson">
94
+ <label>Payson invoice</label>
95
+ <sort_order>-99</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
+ <fields>
100
+ <active translate="label,comment">
101
+ <label>Enabled</label>
102
+ <comment>Enable/disable invoice payment with Payson.</comment>
103
+ <frontend_type>select</frontend_type>
104
+ <source_model>adminhtml/system_config_source_yesno</source_model>
105
+ <sort_order>10</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
+ </active>
110
+ <!--<activate_invoice translate="label,comment">
111
+ <label>Activate invoice on purchase</label>
112
+ <comment>Enable this to send Payson invoice to customer instantly after purchase. Disabling this means you have to mark the goods as Shipped in Admin to activate the invoice</comment>
113
+ <frontend_type>select</frontend_type>
114
+ <source_model>adminhtml/system_config_source_yesno</source_model>
115
+ <sort_order>15</sort_order>
116
+ <show_in_default>1</show_in_default>
117
+ <show_in_website>1</show_in_website>
118
+ <show_in_store>1</show_in_store>
119
+ </activate_invoice>-->
120
+ <invoice_fee_tax translate="label,comment">
121
+ <label>Invoice fee tax</label>
122
+ <comment>Tax class for invoice fees.</comment>
123
+ <frontend_type>select</frontend_type>
124
+ <source_model>adminhtml/system_config_source_shipping_taxclass</source_model>
125
+ <sort_order>20</sort_order>
126
+ <show_in_default>1</show_in_default>
127
+ <show_in_website>1</show_in_website>
128
+ <show_in_store>1</show_in_store>
129
+ </invoice_fee_tax>
130
+ <invoice_fee_sek translate="label,comment">
131
+ <label>Invoice fee (SEK)</label>
132
+ <comment>Invoice fee for SEK excluding tax.</comment>
133
+ <frontend_type>text</frontend_type>
134
+ <sort_order>30</sort_order>
135
+ <show_in_default>1</show_in_default>
136
+ <show_in_website>1</show_in_website>
137
+ <show_in_store>1</show_in_store>
138
+ </invoice_fee_sek>
139
+ <invoice_fee_eur translate="label,comment">
140
+ <label>Invoice fee (EUR)</label>
141
+ <comment>Invoice fee for EUR excluding tax.</comment>
142
+ <frontend_type>text</frontend_type>
143
+ <sort_order>40</sort_order>
144
+ <show_in_default>1</show_in_default>
145
+ <show_in_website>1</show_in_website>
146
+ <show_in_store>1</show_in_store>
147
+ </invoice_fee_eur>
148
 
149
+ <!--<invoice_minimum_amount translate="label,comment">
150
+ <label>Invoice minimum amount (SEK)</label>
151
+ <comment>Invoice minimum amount</comment>
152
+ <frontend_type>text</frontend_type>
153
+ <sort_order>42</sort_order>
154
+ <show_in_default>1</show_in_default>
155
+ <show_in_website>1</show_in_website>
156
+ <show_in_store>1</show_in_store>
157
+ </invoice_minimum_amount>-->
158
+ </fields>
159
+ </payson_invoice>
160
+ </groups>
161
+ </payment>
162
+ </sections>
163
  </config>
164
 
app/code/community/Payson/Payson/sql/payson_setup/mysql4-install-0.1.0.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  $this->startSetup();
3
  $this->run('
4
  CREATE TABLE IF NOT EXISTS `' . $this->getTable('payson_order') . '`
@@ -24,20 +25,8 @@ CREATE TABLE IF NOT EXISTS `' . $this->getTable('payson_order_log') . '`
24
  PRIMARY KEY (`id`)
25
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
26
 
27
- /*$this->addAttribute('quote', 'payson_invoice_fee',
28
- array('type' => 'decimal(12,4)', 'grid' => false));
29
- $this->addAttribute('quote', 'base_payson_invoice_fee',
30
- array('type' => 'decimal(12,4)', 'grid' => false));*/
31
-
32
- $this->addAttribute('order', 'payson_invoice_fee',
33
- array('type' => 'decimal', 'grid' => false));
34
- $this->addAttribute('order', 'base_payson_invoice_fee',
35
- array('type' => 'decimal', 'grid' => false));
36
-
37
- /*$this->addAttribute('invoice', 'payson_invoice_fee',
38
- array('type' => 'decimal', 'grid' => false));
39
- $this->addAttribute('invoice', 'base_payson_invoice_fee',
40
- array('type' => 'decimal', 'grid' => false));*/
41
 
42
  $this->endSetup();
43
 
1
  <?php
2
+
3
  $this->startSetup();
4
  $this->run('
5
  CREATE TABLE IF NOT EXISTS `' . $this->getTable('payson_order') . '`
25
  PRIMARY KEY (`id`)
26
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
27
 
28
+ $this->addAttribute('order', 'payson_invoice_fee', array('type' => 'decimal', 'grid' => false));
29
+ $this->addAttribute('order', 'base_payson_invoice_fee', array('type' => 'decimal', 'grid' => false));
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  $this->endSetup();
32
 
app/code/community/Payson/Payson/sql/payson_setup/mysql4-upgrade-0.1.0-0.1.2.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  $this->startSetup();
3
  $this->run('alter table `' . $this->getTable('payson_order') . '` add store_id int;
4
  ');
1
  <?php
2
+
3
  $this->startSetup();
4
  $this->run('alter table `' . $this->getTable('payson_order') . '` add store_id int;
5
  ');
app/design/adminhtml/default/default/Payson/Payson/total.phtml CHANGED
@@ -1,5 +1,5 @@
1
  <tr>
2
- <td class="label"><?php echo($this->__('Invoice Fee')); ?></td>
3
- <td><?php echo($this->displayPriceAttribute('payson_invoice_fee')); ?></td>
4
  </tr>
5
 
1
  <tr>
2
+ <td class="label"><?php echo($this->__('Invoice Fee')); ?></td>
3
+ <td><?php echo($this->displayPriceAttribute('payson_invoice_fee')); ?></td>
4
  </tr>
5
 
app/design/adminhtml/default/default/layout/Payson.xml CHANGED
@@ -1,34 +1,24 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <layout>
3
- <!--<adminhtml_sales_order_new>
4
- <reference name="order_totals">
5
- <block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
6
- </reference>
7
- </adminhtml_sales_order_new>-->
8
- <adminhtml_sales_order_view>
9
- <reference name="order_totals">
10
- <block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
11
- </reference>
12
- </adminhtml_sales_order_view>
13
- <adminhtml_sales_order_invoice_new>
14
- <reference name="invoice_totals">
15
- <block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
16
- </reference>
17
- </adminhtml_sales_order_invoice_new>
18
- <adminhtml_sales_order_invoice_view>
19
- <reference name="invoice_totals">
20
- <block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
21
- </reference>
22
- </adminhtml_sales_order_invoice_view>
23
- <adminhtml_sales_order_creditmemo_new>
24
- <reference name="creditmemo_totals">
25
- <block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
26
- </reference>
27
- </adminhtml_sales_order_creditmemo_new>
28
- <!--<adminhtml_sales_order_creditmemo_view>
29
- <reference name="creditmemo_totals">
30
- <block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
31
- </reference>
32
- </adminhtml_sales_order_creditmemo_view>-->
33
  </layout>
34
 
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <layout>
3
+ <adminhtml_sales_order_view>
4
+ <reference name="order_totals">
5
+ <block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
6
+ </reference>
7
+ </adminhtml_sales_order_view>
8
+ <adminhtml_sales_order_invoice_new>
9
+ <reference name="invoice_totals">
10
+ <block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
11
+ </reference>
12
+ </adminhtml_sales_order_invoice_new>
13
+ <adminhtml_sales_order_invoice_view>
14
+ <reference name="invoice_totals">
15
+ <block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
16
+ </reference>
17
+ </adminhtml_sales_order_invoice_view>
18
+ <adminhtml_sales_order_creditmemo_new>
19
+ <reference name="creditmemo_totals">
20
+ <block type="adminhtml/sales_order_totals_item" name="payson_invoice_fee" template="Payson/Payson/total.phtml" />
21
+ </reference>
22
+ </adminhtml_sales_order_creditmemo_new>
 
 
 
 
 
 
 
 
 
 
23
  </layout>
24
 
app/design/frontend/base/default/layout/Payson.xml CHANGED
@@ -1,45 +1,45 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <layout version="0.1.0">
3
- <sales_order_print>
4
- <reference name="order_totals">
5
- <block type="payson/order_totals_fee" name="payson_invoice_fee" />
6
- </reference>
7
- </sales_order_print>
8
- <sales_order_view>
9
- <reference name="order_totals">
10
- <block type="payson/order_totals_fee" name="payson_invoice_fee" />
11
- </reference>
12
- </sales_order_view>
13
- <sales_order_invoice>
14
- <reference name="invoice_totals">
15
- <block type="payson/order_totals_fee" name="payson_invoice_fee" />
16
- </reference>
17
- </sales_order_invoice>
18
- <sales_order_printinvoice>
19
- <reference name="invoice_totals">
20
- <block type="payson/order_totals_fee" name="payson_invoice_fee" />
21
- </reference>
22
- </sales_order_printinvoice>
23
- <sales_order_creditmemo>
24
- <reference name="creditmemo_totals">
25
- <block type="payson/order_totals_fee" name="payson_invoice_fee" />
26
- </reference>
27
- </sales_order_creditmemo>
28
- <sales_order_printcreditmemo>
29
- <reference name="creditmemo_totals">
30
- <block type="payson/order_totals_fee" name="payson_invoice_fee" />
31
- </reference>
32
- </sales_order_printcreditmemo>
33
- <sales_email_order_items>
34
- <reference name="order_totals">
35
- <block type="payson/order_totals_fee" name="payson_invoice_fee" />
36
- </reference>
37
- </sales_email_order_items>
38
- <sales_email_order_invoice_items>
39
- <reference name="invoice_totals">
40
- <block type="payson/order_totals_fee" name="payson_invoice_fee" />
41
- </reference>
42
- </sales_email_order_invoice_items>
43
- <!-- sales_email_order_shipment_items sales_email_order_creditmemo_items -->
44
  </layout>
45
 
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <layout version="0.1.0">
3
+ <sales_order_print>
4
+ <reference name="order_totals">
5
+ <block type="payson/order_totals_fee" name="payson_invoice_fee" />
6
+ </reference>
7
+ </sales_order_print>
8
+ <sales_order_view>
9
+ <reference name="order_totals">
10
+ <block type="payson/order_totals_fee" name="payson_invoice_fee" />
11
+ </reference>
12
+ </sales_order_view>
13
+ <sales_order_invoice>
14
+ <reference name="invoice_totals">
15
+ <block type="payson/order_totals_fee" name="payson_invoice_fee" />
16
+ </reference>
17
+ </sales_order_invoice>
18
+ <sales_order_printinvoice>
19
+ <reference name="invoice_totals">
20
+ <block type="payson/order_totals_fee" name="payson_invoice_fee" />
21
+ </reference>
22
+ </sales_order_printinvoice>
23
+ <sales_order_creditmemo>
24
+ <reference name="creditmemo_totals">
25
+ <block type="payson/order_totals_fee" name="payson_invoice_fee" />
26
+ </reference>
27
+ </sales_order_creditmemo>
28
+ <sales_order_printcreditmemo>
29
+ <reference name="creditmemo_totals">
30
+ <block type="payson/order_totals_fee" name="payson_invoice_fee" />
31
+ </reference>
32
+ </sales_order_printcreditmemo>
33
+ <sales_email_order_items>
34
+ <reference name="order_totals">
35
+ <block type="payson/order_totals_fee" name="payson_invoice_fee" />
36
+ </reference>
37
+ </sales_email_order_items>
38
+ <sales_email_order_invoice_items>
39
+ <reference name="invoice_totals">
40
+ <block type="payson/order_totals_fee" name="payson_invoice_fee" />
41
+ </reference>
42
+ </sales_email_order_invoice_items>
43
+ <!-- sales_email_order_shipment_items sales_email_order_creditmemo_items -->
44
  </layout>
45
 
app/design/frontend/base/default/template/Payson/Payson/invoice_form.phtml CHANGED
@@ -1,15 +1,15 @@
1
  <?php
2
- $helper = Mage::Helper('payson');
3
- $code = $this->getMethodCode();
4
  ?>
5
  <fieldset class="form-list">
6
- <label for="p_method_<?php echo($code); ?>" style="float: none"><img src="<?php echo(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)); ?>frontend/base/default/Payson/Payson/payson_faktura.png" alt="Payson" style="margin: 10px 0; display: block" /></label>
7
- <p id="payment_form_<?php echo($code); ?>" style="display: none">
8
- <?php
9
- echo($helper->__('You will be redirected to Payson\'s website.'));
10
- echo '<br /><br />';
11
- echo($helper->__('If you choose to pay by Paysoninvoice so there is a fee. Payment terms are 10 days and the invoice will be sent separately by email to the email address you specify. To pay by Paysoninvoice You must be 18 years old and be registered in Sweden as well as authorized in the credit assessment carried out at purchase.'));
12
  ?>
13
- </p>
14
  </fieldset>
15
 
1
  <?php
2
+ $helper = Mage::Helper('payson');
3
+ $code = $this->getMethodCode();
4
  ?>
5
  <fieldset class="form-list">
6
+ <label for="p_method_<?php echo($code); ?>" style="float: none"><img src="<?php echo(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)); ?>frontend/base/default/Payson/Payson/payson_faktura.png" alt="Payson" style="margin: 10px 0; display: block" /></label>
7
+ <p id="payment_form_<?php echo($code); ?>" style="display: none">
8
+ <?php
9
+ echo($helper->__('You will be redirected to Payson\'s website.'));
10
+ echo '<br /><br />';
11
+ echo($helper->__('If you choose to pay by Paysoninvoice so there is a fee. Payment terms are 10 days and the invoice will be sent separately by email to the email address you specify. To pay by Paysoninvoice You must be 18 years old and be registered in Sweden as well as authorized in the credit assessment carried out at purchase.'));
12
  ?>
13
+ </p>
14
  </fieldset>
15
 
app/design/frontend/base/default/template/Payson/Payson/standard_form.phtml CHANGED
@@ -1,9 +1,9 @@
1
  <?php
2
- $helper = Mage::Helper('payson');
3
- $code = $this->getMethodCode();
4
  ?>
5
  <fieldset class="form-list">
6
- <label for="p_method_<?php echo($code); ?>" style="float: none"><img src="<?php echo(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)); ?>frontend/base/default/Payson/Payson/payson.png" alt="Payson" style="margin: 10px 0; display: block" /></label>
7
- <p id="payment_form_<?php echo($code); ?>" style="display: none"><?php echo($helper->__('You will be redirected to Payson\'s website.')); ?></p>
8
  </fieldset>
9
 
1
  <?php
2
+ $helper = Mage::Helper('payson');
3
+ $code = $this->getMethodCode();
4
  ?>
5
  <fieldset class="form-list">
6
+ <label for="p_method_<?php echo($code); ?>" style="float: none"><img src="<?php echo(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)); ?>frontend/base/default/Payson/Payson/payson.png" alt="Payson" style="margin: 10px 0; display: block" /></label>
7
+ <p id="payment_form_<?php echo($code); ?>" style="display: none"><?php echo($helper->__('You will be redirected to Payson\'s website.')); ?></p>
8
  </fieldset>
9
 
app/etc/modules/Payson_Payson.xml CHANGED
@@ -1,14 +1,14 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <config>
3
- <modules>
4
- <Payson_Payson>
5
- <active>true</active>
6
- <codePool>community</codePool>
7
- <version>0.1.3</version>
8
- <depends>
9
- <Mage_Payment />
10
- </depends>
11
- </Payson_Payson>
12
- </modules>
13
  </config>
14
 
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <config>
3
+ <modules>
4
+ <Payson_Payson>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>1.0</version>
8
+ <depends>
9
+ <Mage_Payment />
10
+ </depends>
11
+ </Payson_Payson>
12
+ </modules>
13
  </config>
14
 
package.xml CHANGED
@@ -1,27 +1,23 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Payson</name>
4
- <version>0.1.3</version>
5
  <stability>stable</stability>
6
  <license>BSD</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Official Payson module for Magento. Use this to be able to handle invoice, card and direct bank transfers in your store. &#xD;
10
  &#xD;
11
- ! Requires a contract with Payson. Read more here (https://www.payson.se/ebutik)</summary>
12
  <description>Make it easy to charge your customers. Chose Payson.&#xD;
13
  &#xD;
14
- This module integrates with Payson and allows you to charge your customers via Invoice, Card and direct bank transfers.</description>
15
- <notes>* Invoice will not be available in checkout on purchases below 30SEK or for customers with a delivery address outside of sweden.&#xD;
16
- &lt;br /&gt;&#xD;
17
- * An issue with the cancel URL has been fixed&#xD;
18
- &lt;br /&gt;&#xD;
19
- * When selecting test mode the module will be using test credentials automatically&#xD;
20
- </notes>
21
  <authors><author><name>Daniel Hansen</name><user>PaysonAB</user><email>integration@payson.se</email></author></authors>
22
- <date>2013-04-09</date>
23
- <time>03:48:40</time>
24
- <contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="Payson"><dir name="Payson"><dir name="Block"><file name="Form.php" hash="7a7c6e5ae4e2e8e72fa2c40a22c88440"/><dir name="Invoice"><file name="Form.php" hash="11483752cd4555f47445a92371e7c1b5"/></dir><dir name="Order"><dir name="Totals"><file name="Fee.php" hash="808261ee19df9146756160cb6cd53b6a"/></dir></dir><dir name="Standard"><file name="Form.php" hash="9d013602be74f2c74de0ccdb6dbf8675"/></dir></dir><dir name="Helper"><dir name="Api"><dir name="Response"><file name="Interface.php" hash="9e4776fe054757f2d2739bcd9616e2fb"/><dir name="Standard"><file name="Parameters.php" hash="626604b19b85f17d1be40f3623cedc43"/></dir><file name="Standard.php" hash="06999c14ae62726117b0c37a0e974b5f"/><file name="Validate.php" hash="aa3a364583c8d75c2faa22f43142db19"/></dir></dir><file name="Api.php" hash="f02aa052f1d383cc273cc5e834a80fd4"/><file name="Data.php" hash="89f829357cfdbefdabb46dff8d52228c"/></dir><dir name="Model"><file name="Config.php" hash="28a902246b058cfe772a05e8da631011"/><dir name="Method"><file name="Abstract.php" hash="c4b83dd7d16e2a409d4be0345e6f30e5"/><file name="Invoice.php" hash="28a54397e43394116b0088e836ca6c45"/><file name="Standard.php" hash="a0d41d559429cf7713ee6bba59733cb9"/></dir><dir name="Mysql4"><file name="Setup.php" hash="9023463718548c8a5ed7faed6aa40a3c"/></dir><dir name="Order"><dir name="Creditmemo"><dir name="Total"><file name="Invoice.php" hash="86748e75794e73df7d0b25091a19fbad"/></dir></dir><dir name="Invoice"><dir name="Total"><file name="Invoice.php" hash="050af7c18f19f6e036b582c2bb56f332"/></dir></dir></dir><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Invoice.php" hash="09522f6537a78461cf737e232317463e"/></dir></dir></dir><file name="Standard.php" hash="2f44109bfcc19c28764e1e9acd6e6422"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="ShipmentController.php" hash="56118704e788b2b53086f7c9be71c996"/></dir></dir></dir><file name="CheckoutController.php" hash="443622cc8a285dbdbb05951c195fa611"/><file name="IpnController.php" hash="48e3d7683632647568817548c9bd0a66"/></dir><dir name="etc"><file name="config.xml" hash="b3c5d3d97413eeb81a670321265fd4b9"/><file name="system.xml" hash="bd6e55c97130c0569b187a7cbf9779b7"/></dir><dir name="sql"><dir name="payson_setup"><file name="mysql4-install-0.1.0.php" hash="98b5bdd98a21255e334b843ecd998dc3"/><file name="mysql4-upgrade-0.1.0-0.1.2.php" hash="a18c999031bce6579e6fc0add977ea04"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="Payson"><dir name="Payson"><file name="total.phtml" hash="a6f06816114cda260573492e4db22238"/></dir></dir><dir name="layout"><file name="Payson.xml" hash=""/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="Payson"><dir name="Payson"><file name="invoice_form.phtml" hash="8084033612634d80aca0d2526b356f4f"/><file name="standard_form.phtml" hash="5b9a8817c94fcbced0ce06edbaf5c3b9"/></dir></dir></dir><dir name="layout"><file name="Payson.xml" hash=""/></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Payson_Payson.xml" hash=""/></dir></dir><dir name="locale"><dir name="sv_SE"><file name="Payson_Payson.csv" hash=""/></dir></dir></dir><dir name="skin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="Payson"><dir name="Payson"><file name="payson.gif" hash="638d0055cbc1a4bdc32e9fa1156b722a"/><file name="payson.png" hash="308916345711a4520313c94218c5bda7"/><file name="payson_faktura.png" hash="fa218c9949c05c6f3452d9f4c541da2c"/></dir></dir></dir></dir></dir></dir></target></contents>
25
  <compatible/>
26
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
27
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Payson</name>
4
+ <version>1.0.0</version>
5
  <stability>stable</stability>
6
  <license>BSD</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Official Payson module for Magento. Use this to be able to handle invoice, card and direct bank transfers in your store. &#xD;
10
  &#xD;
11
+ ! Requires a contract with Payson. Read more here (https://www.payson.se/ebutik)</summary>
12
  <description>Make it easy to charge your customers. Chose Payson.&#xD;
13
  &#xD;
14
+ This module integrates with Payson and allows you to charge your customers via Invoice, Card and direct bank transfers.</description>
15
+ <notes>* When order is cancelled product is credited to inventory&#xD;
16
+ * Cart is now restored when returning from Payson and payment failed</notes>
 
 
 
 
17
  <authors><author><name>Daniel Hansen</name><user>PaysonAB</user><email>integration@payson.se</email></author></authors>
18
+ <date>2013-05-28</date>
19
+ <time>13:26:26</time>
20
+ <contents><target name="mage"><dir name="app"><dir name="code"><dir name="community"><dir name="Payson"><dir name="Payson"><dir name="Block"><file name="Form.php" hash="5ad3b8115583fbd8b5fd0ac24440325b"/><dir name="Invoice"><file name="Form.php" hash="8e9bc849ecbb21c3cdf709b2ba074a87"/></dir><dir name="Order"><dir name="Totals"><file name="Fee.php" hash="0ea99606a8f5e80a2a5f80208c683e44"/></dir></dir><dir name="Standard"><file name="Form.php" hash="eb63196829d96c6da7309eadd87c707e"/></dir></dir><dir name="Helper"><dir name="Api"><dir name="Response"><file name="Interface.php" hash="50bda3e73b646165c325e5aa38811554"/><dir name="Standard"><file name="Parameters.php" hash="3fa48fd19ca86ce96613047038e70a2f"/></dir><file name="Standard.php" hash="8d4a4960a8110338a2a0f9b162b52b37"/><file name="Validate.php" hash="35d82eef0cf69983f3ffd9fcc3692e25"/></dir></dir><file name="Api.php" hash="2f85ea4724e4fad6ea6cd15f7ddf55ed"/><file name="Data.php" hash="3e3492d7136d77ff61876d2b4d729c20"/></dir><dir name="Model"><file name="Config.php" hash="d39090c646bc4d973d30084a21ca0353"/><dir name="Method"><file name="Abstract.php" hash="55be4eda8833b5434ffb30beb61e32f5"/><file name="Invoice.php" hash="4a97c381dc250e1b0e0e3084057c356a"/><file name="Standard.php" hash="48b4aa062bf5490937c6c68de0b79a2b"/></dir><dir name="Mysql4"><file name="Setup.php" hash="64d97efb592c665290ae4a13015c2df5"/></dir><dir name="Order"><dir name="Creditmemo"><dir name="Total"><file name="Invoice.php" hash="883c7d27f035a9284c6624a741a3fe31"/></dir></dir><dir name="Invoice"><dir name="Total"><file name="Invoice.php" hash="c357815cc2eeb6836946ea3a13528029"/></dir></dir></dir><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Invoice.php" hash="423a7c2f9a61e47b8d8a0155d624488a"/></dir></dir></dir><file name="Standard.php" hash="a154909d27639455270b9c2d1a22b1bc"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="ShipmentController.php" hash="56118704e788b2b53086f7c9be71c996"/></dir></dir></dir><file name="CheckoutController.php" hash="d8dfb135ada18c213052e3dc613c34e7"/><file name="IpnController.php" hash="9b724b278793d5fc8e64f0a49f7914c7"/></dir><dir name="etc"><file name="config.xml" hash="c2ac51d643757dc151591b2834088378"/><file name="system.xml" hash="80254a7bf100e003d15b3f47ffbe06e5"/></dir><dir name="sql"><dir name="payson_setup"><file name="mysql4-install-0.1.0.php" hash="8422dccd6ccb5ce214f17bfa8ae08bd3"/><file name="mysql4-upgrade-0.1.0-0.1.2.php" hash="cc846d866a93167c79d3286f512e6bf6"/></dir></dir></dir></dir></dir></dir><dir name="design"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="Payson"><dir name="Payson"><file name="total.phtml" hash="795e38fb672ffd23f38ed28578c7ee2f"/></dir></dir><dir name="layout"><file name="Payson.xml" hash=""/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="Payson"><dir name="Payson"><file name="invoice_form.phtml" hash="2b69133eb3c04f582535e3a80ba76229"/><file name="standard_form.phtml" hash="147fd545564940747b2e8a85a23c1dd6"/></dir></dir></dir><dir name="layout"><file name="Payson.xml" hash=""/></dir></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="Payson_Payson.xml" hash=""/></dir></dir><dir name="locale"><dir name="sv_SE"><file name="Payson_Payson.csv" hash=""/></dir></dir></dir><dir name="skin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="Payson"><dir name="Payson"><file name="payson.gif" hash="638d0055cbc1a4bdc32e9fa1156b722a"/><file name="payson.png" hash="308916345711a4520313c94218c5bda7"/><file name="payson_faktura.png" hash="fa218c9949c05c6f3452d9f4c541da2c"/></dir></dir></dir></dir></dir></dir></target></contents>
21
  <compatible/>
22
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
23
  </package>