PaysonCheckout2 - Version 1.0.0.0

Version Notes

New modul PaysonCheckout2

Download this release

Release Info

Developer Oscar Villegas
Extension PaysonCheckout2
Version 1.0.0.0
Comparing to
See all releases


Version 1.0.0.0

Files changed (85) hide show
  1. app/code/community/Payson/Checkout2/Block/Form/Checkout2.php +12 -0
  2. app/code/community/Payson/Checkout2/Block/Info/Checkout2.php +6 -0
  3. app/code/community/Payson/Checkout2/Block/Payment.php +48 -0
  4. app/code/community/Payson/Checkout2/Helper/Data.php +6 -0
  5. app/code/community/Payson/Checkout2/Helper/Order.php +637 -0
  6. app/code/community/Payson/Checkout2/Model/Config.php +134 -0
  7. app/code/community/Payson/Checkout2/Model/Method/Checkout2.php +155 -0
  8. app/code/community/Payson/Checkout2/Model/Notification.php +100 -0
  9. app/code/community/Payson/Checkout2/Model/Observer.php +31 -0
  10. app/code/community/Payson/Checkout2/Model/Order.php +8 -0
  11. app/code/community/Payson/Checkout2/Model/Themes.php +18 -0
  12. app/code/community/Payson/Checkout2/Model/VerificationTypes.php +14 -0
  13. app/code/community/Payson/Checkout2/controllers/Adminhtml/Sales/Order/ShipmentController.php +59 -0
  14. app/code/community/Payson/Checkout2/controllers/ExpressController.php +237 -0
  15. app/code/community/Payson/Checkout2/controllers/NotificationController.php +28 -0
  16. app/code/community/Payson/Checkout2/controllers/PaymentController.php +139 -0
  17. app/code/community/Payson/Checkout2/etc/config.xml +138 -0
  18. app/code/community/Payson/Checkout2/etc/system.xml +116 -0
  19. app/code/community/Payson/Checkout2/sql/payson_checkout2_setup/mysql4-install-1.0.0.php +19 -0
  20. app/code/community/Payson/Payson/Block/Form.php +11 -0
  21. app/code/community/Payson/Payson/Block/Invoice/Form.php +11 -0
  22. app/code/community/Payson/Payson/Block/Order/Totals/Fee.php +22 -0
  23. app/code/community/Payson/Payson/Block/Standard/Form.php +11 -0
  24. app/code/community/Payson/Payson/Helper/Api.php +1328 -0
  25. app/code/community/Payson/Payson/Helper/Api/Response/Interface.php +20 -0
  26. app/code/community/Payson/Payson/Helper/Api/Response/Standard.php +131 -0
  27. app/code/community/Payson/Payson/Helper/Api/Response/Standard/Parameters.php +66 -0
  28. app/code/community/Payson/Payson/Helper/Api/Response/Validate.php +46 -0
  29. app/code/community/Payson/Payson/Helper/Data.php +6 -0
  30. app/code/community/Payson/Payson/Helper/FundingConstraint.php +36 -0
  31. app/code/community/Payson/Payson/Model/Config.php +218 -0
  32. app/code/community/Payson/Payson/Model/Method/Abstract.php +148 -0
  33. app/code/community/Payson/Payson/Model/Method/Invoice.php +65 -0
  34. app/code/community/Payson/Payson/Model/Method/Standard.php +80 -0
  35. app/code/community/Payson/Payson/Model/Mysql4/Setup.php +6 -0
  36. app/code/community/Payson/Payson/Model/Order/Creditmemo/Total/Invoice.php +41 -0
  37. app/code/community/Payson/Payson/Model/Order/Invoice/Total/Invoice.php +42 -0
  38. app/code/community/Payson/Payson/Model/Quote/Address/Total/Invoice.php +44 -0
  39. app/code/community/Payson/Payson/Model/Standard.php +108 -0
  40. app/code/community/Payson/Payson/Model/System/Config/Source/Paysondirectmethod.php +52 -0
  41. app/code/community/Payson/Payson/controllers/Adminhtml/Sales/Order/ShipmentController.php +23 -0
  42. app/code/community/Payson/Payson/controllers/CheckoutController.php +238 -0
  43. app/code/community/Payson/Payson/controllers/IpnController.php +25 -0
  44. app/code/community/Payson/Payson/etc/config.xml +167 -0
  45. app/code/community/Payson/Payson/etc/system.xml +166 -0
  46. app/code/community/Payson/Payson/sql/payson_setup/mysql4-install-0.1.0.php +32 -0
  47. app/code/community/Payson/Payson/sql/payson_setup/mysql4-upgrade-0.1.0-0.1.2.php +8 -0
  48. app/design/frontend/base/default/layout/payson_checkout2.xml +86 -0
  49. app/design/frontend/base/default/template/payson/checkout2/elements/button.phtml +3 -0
  50. app/design/frontend/base/default/template/payson/checkout2/elements/minicartbutton.phtml +5 -0
  51. app/design/frontend/base/default/template/payson/checkout2/form/checkout2.phtml +7 -0
  52. app/design/frontend/base/default/template/payson/checkout2/form/review.phtml +4 -0
  53. app/design/frontend/base/default/template/payson/checkout2/form/shipping.phtml +4 -0
  54. app/design/frontend/base/default/template/payson/checkout2/page/blank.phtml +1 -0
  55. app/design/frontend/base/default/template/payson/checkout2/payment/confirmation.phtml +1 -0
  56. app/design/frontend/base/default/template/payson/checkout2/payment/express.phtml +1 -0
  57. app/design/frontend/base/default/template/payson/checkout2/payment/standard.phtml +1 -0
  58. app/etc/modules/Payson_Checkout2.xml +9 -0
  59. app/locale/sv_SE/payson_checkout2.csv +60 -0
  60. js/payson/checkout2/express.js +78 -0
  61. lib/Payson/Checkout2/PaysonCheckout2PHP/README.md +1 -0
  62. lib/Payson/Checkout2/PaysonCheckout2PHP/cancel_order.php +32 -0
  63. lib/Payson/Checkout2/PaysonCheckout2PHP/example/cancel_order.php +32 -0
  64. lib/Payson/Checkout2/PaysonCheckout2PHP/example/config.php +44 -0
  65. lib/Payson/Checkout2/PaysonCheckout2PHP/example/confirmation.php +22 -0
  66. lib/Payson/Checkout2/PaysonCheckout2PHP/example/index.php +44 -0
  67. lib/Payson/Checkout2/PaysonCheckout2PHP/example/notification.php +19 -0
  68. lib/Payson/Checkout2/PaysonCheckout2PHP/example/update_order.php +29 -0
  69. lib/Payson/Checkout2/PaysonCheckout2PHP/example/validate.php +25 -0
  70. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/account.php +32 -0
  71. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/cancel_order.php +32 -0
  72. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/confirmation.php +45 -0
  73. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/customer.php +46 -0
  74. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/gui.php +29 -0
  75. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/index.php +43 -0
  76. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/orderitem.php +83 -0
  77. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paydata.php +64 -0
  78. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonapi.php +167 -0
  79. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonapierror.php +16 -0
  80. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonapiexception.php +31 -0
  81. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paysoncheckout.php +67 -0
  82. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonmerchant.php +41 -0
  83. lib/Payson/Checkout2/PaysonCheckout2PHP/lib/update_order.php +29 -0
  84. package.xml +18 -0
  85. skin/frontend/base/default/css/payson_checkout2/style.css +45 -0
app/code/community/Payson/Checkout2/Block/Form/Checkout2.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(Mage::getBaseDir('lib') . '/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonapi.php');
4
+
5
+ class Payson_Checkout2_Block_Form_Checkout2 extends Mage_Payment_Block_Form
6
+ {
7
+ protected function _construct()
8
+ {
9
+ parent::_construct();
10
+ $this->setTemplate('payson/checkout2/form/checkout2.phtml');
11
+ }
12
+ }
app/code/community/Payson/Checkout2/Block/Info/Checkout2.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Payson_Checkout2_Block_Info_Checkout2 extends Mage_Payment_Block_Info
5
+ {
6
+ }
app/code/community/Payson/Checkout2/Block/Payment.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(Mage::getBaseDir('lib') . '/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonapi.php');
4
+
5
+ class Payson_Checkout2_Block_Payment extends Mage_Core_Block_Template
6
+ {
7
+ /**
8
+ * Order instance
9
+ */
10
+ protected $_orderHelper;
11
+
12
+ public function _construct() {
13
+ $this->_orderHelper = Mage::helper('checkout2/order');
14
+ }
15
+
16
+ public function standardCheckoutHtml()
17
+ {
18
+ $checkout = $this->_orderHelper->checkout();
19
+
20
+ return $checkout->snippet;
21
+ }
22
+
23
+ public function expressCheckoutHtml()
24
+ {
25
+ $checkout = $this->_orderHelper->expressCheckout();
26
+ $checkoutId = $checkout->id;
27
+ $controlKey = $this->_orderHelper->getCheckoutControlKey($checkoutId);
28
+ $domain = '.' . $_SERVER['SERVER_NAME'];
29
+
30
+ $js = <<<HTML
31
+ <script type="text/javascript">
32
+ PaysonSettings = window.PaysonSettings || {}
33
+ PaysonSettings.checkoutId = "$checkoutId";
34
+ PaysonSettings.controlKey = "$controlKey";
35
+ </script>
36
+ HTML;
37
+
38
+ return $checkout->snippet . $js;
39
+ }
40
+
41
+ public function confirmationHtml()
42
+ {
43
+ $checkoutId = Mage::getSingleton('core/session')->getCheckoutId();
44
+ $checkout = $this->_orderHelper->getCheckout($checkoutId);
45
+
46
+ return $checkout->snippet;
47
+ }
48
+ }
app/code/community/Payson/Checkout2/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/community/Payson/Checkout2/Helper/Order.php ADDED
@@ -0,0 +1,637 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(Mage::getBaseDir('lib') . '/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonapi.php');
4
+
5
+ class Payson_Checkout2_Helper_Order extends Mage_Core_Helper_Abstract
6
+ {
7
+ protected $_order;
8
+ protected $_config;
9
+ protected $_api;
10
+ protected $controlKey;
11
+
12
+ public function checkout() {
13
+ $order = $this->getOrder();
14
+
15
+ $checkoutId = $order->getData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN);
16
+
17
+ if ($checkoutId) {
18
+ // Already have an active checkout
19
+ return $this->getCheckout($checkoutId);
20
+ }
21
+
22
+ $callPaysonApi = $this->getApi();
23
+ $paysonMerchant = $this->_getMerchant();
24
+ $payData = $this->_getOrderPayData();
25
+ $customer = $this->initCustomer();
26
+ $store = Mage::app()->getStore();
27
+ $description = Mage::helper('checkout2')->__('Order from %s', $store->getFrontendName);
28
+
29
+ // Init GUI
30
+ $locale = $this->getLocale();
31
+ $theme = $this->getConfig()->getTheme();
32
+ $extraVerification = $this->getConfig()->getExtraVerification();
33
+ $requestPhone = $this->getConfig()->getRequestPhone() == 1;
34
+
35
+ $gui = new PaysonEmbedded\Gui($locale, $theme, $extraVerification, $requestPhone);
36
+ $checkout = new PaysonEmbedded\Checkout($paysonMerchant, $payData, $gui, $customer, $description);
37
+
38
+ /*
39
+ * Step 2 Create checkout
40
+ */
41
+
42
+ $checkoutId = $callPaysonApi->CreateCheckout($checkout);
43
+ $order->setData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN, $checkoutId);
44
+
45
+ $order->save();
46
+
47
+ /*
48
+ * Step 3 Get checkout object
49
+ */
50
+
51
+ return $callPaysonApi->GetCheckout($checkoutId);
52
+ }
53
+
54
+ public function expressCheckout() {
55
+ $quote = Mage::getModel('checkout/cart')->getQuote();
56
+
57
+ $checkoutId = $quote->getData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN);
58
+
59
+ if ($checkoutId) {
60
+ // Already have an active checkout
61
+ return $this->getCheckout($checkoutId);
62
+ }
63
+
64
+ $this->_setDefaultShipping($quote);
65
+
66
+ $callPaysonApi = $this->getApi();
67
+ $paysonMerchant = $this->_getExpressMerchant();
68
+ $payData = $this->_getQuotePayData();
69
+ $customer = $this->_initExpressCustomer();
70
+ $store = Mage::app()->getStore();
71
+ $description = Mage::helper('checkout2')->__('Order from %s', $store->getFrontendName());
72
+
73
+ // Init GUI
74
+ $locale = $this->getLocale();
75
+ $theme = $this->getConfig()->getTheme();
76
+ $extraVerification = $this->getConfig()->getExtraVerification();
77
+ $requestPhone = true; // Always request phone on checkout since Magento needs a phone number to create an order
78
+
79
+ $gui = new PaysonEmbedded\Gui($locale, $theme, $extraVerification, $requestPhone);
80
+ $checkout = new PaysonEmbedded\Checkout($paysonMerchant, $payData, $gui, $customer, $description);
81
+
82
+ /*
83
+ * Step 2 Create checkout
84
+ */
85
+
86
+ $checkoutId = $callPaysonApi->CreateCheckout($checkout);
87
+ $quote->setData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN, $checkoutId);
88
+ $quote->save();
89
+
90
+ $this->updateCheckoutControlKey($checkoutId);
91
+
92
+ /*
93
+ * Step 3 Get checkout object
94
+ */
95
+
96
+ return $callPaysonApi->GetCheckout($checkoutId);
97
+ }
98
+
99
+ public function updateExpressCheckout() {
100
+ $quote = Mage::getModel('checkout/cart')->getQuote();
101
+ $checkoutId = $quote->getData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN);
102
+
103
+ $callPaysonApi = $this->getApi();
104
+
105
+ // Fetch checkout and set new paydata
106
+ $checkout = $callPaysonApi->GetCheckout($checkoutId);
107
+
108
+ switch ($checkout->status) {
109
+ case 'shipped':
110
+ case 'paidToAccount':
111
+ case 'canceled':
112
+ case 'expired':
113
+ case 'denied':
114
+
115
+ // Don't try to update checkout at this point
116
+ return $checkout;
117
+ }
118
+
119
+ $payData = $this->_getQuotePayData();
120
+ $checkout->payData->items = $payData->items;
121
+
122
+ // Update and return
123
+ $checkout = $callPaysonApi->UpdateCheckout($checkout);
124
+
125
+ return $checkout;
126
+ }
127
+
128
+ public function updateCheckoutControlKey($checkoutId) {
129
+ $this->_controlKey = Mage::helper('core')->getRandomString($length = 8);
130
+ $domain = null;
131
+ Mage::getSingleton('core/cookie')->set($checkoutId, $this->_controlKey, 3600, '/', $domain, false, false);
132
+ }
133
+
134
+ public function removeCheckoutControlKey($checkoutId) {
135
+ Mage::getSingleton('core/cookie')->delete($checkoutId);
136
+ }
137
+
138
+ public function getCheckoutControlKey($checkoutId) {
139
+ $key = Mage::getSingleton('core/cookie')->get($checkoutId);
140
+
141
+ if (!$key) {
142
+ return $this->_controlKey;
143
+ }
144
+
145
+ return $key;
146
+ }
147
+
148
+ private function _getOrderPayData() {
149
+ $order = $this->getOrder();
150
+ $payData = new PaysonEmbedded\PayData($order->getOrderCurrency()->getCode());
151
+
152
+ // Re-create paydata
153
+ $discount = 0;
154
+
155
+ // Add items and discount
156
+ foreach ($order->getAllVisibleItems() as $item) {
157
+ $this->prepareOrderItemData($item, $payData);
158
+ $discount += $item->getDiscountAmount();
159
+ }
160
+
161
+ if ($discount > 0) {
162
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem('discount', -$discount, 1, 0.1, 'a', PaysonEmbedded\OrderItemType::DISCOUNT));
163
+ }
164
+
165
+ // Calculate price for shipping
166
+ $this->prepareOrderShippingData($order, $payData);
167
+
168
+ return $payData;
169
+ }
170
+
171
+ private function _getQuotePayData() {
172
+ $quote = Mage::getModel('checkout/cart')->getQuote();
173
+ $payData = new PaysonEmbedded\PayData($quote->getQuoteCurrencyCode());
174
+
175
+ // Re-create paydata
176
+ $discount = 0;
177
+
178
+ // Add items and discount
179
+ foreach ($quote->getAllVisibleItems() as $item) {
180
+ $this->prepareQuoteItemData($item, $payData);
181
+ $discount += $item->getDiscountAmount();
182
+ }
183
+
184
+ if ($discount > 0) {
185
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem('discount', -$discount, 1, 0.1, 'a', PaysonEmbedded\OrderItemType::DISCOUNT));
186
+ }
187
+
188
+ // Calculate price for shipping
189
+ $this->prepareQuoteShippingData($quote, $payData);
190
+
191
+ return $payData;
192
+ }
193
+
194
+ private function _getMerchant() {
195
+ // URLs used by payson for redirection after a completed/canceled/notification purchase.
196
+ $checkoutUri = Mage::getUrl('checkout2/payment/cancel', array('_secure' => true));
197
+ $confirmationUri = Mage::getUrl('checkout2/payment/return', array('_secure' => true));
198
+ $notificationUri = Mage::getUrl('checkout2/notification/notify', array('_secure' => true));
199
+ $termsUri = $this->getConfig()->getTermsUrl();
200
+
201
+ return new PaysonEmbedded\Merchant($checkoutUri, $confirmationUri, $notificationUri, $termsUri, 1);
202
+ }
203
+
204
+ private function _getExpressMerchant() {
205
+ // URLs used by payson for redirection after a completed/canceled/notification purchase.
206
+ $checkoutUri = Mage::getUrl('checkout2/express/cancel', array('_secure' => true));
207
+ $confirmationUri = Mage::getUrl('checkout2/express/return', array('_secure' => true));
208
+ $notificationUri = Mage::getUrl('checkout2/notification/notify', array('_secure' => true));
209
+ $termsUri = $this->getConfig()->getTermsUrl();
210
+
211
+ return new PaysonEmbedded\Merchant($checkoutUri, $confirmationUri, $notificationUri, $termsUri, 1);
212
+ }
213
+
214
+ /**
215
+ * @return \PaysonEmbedded\PaysonApi
216
+ */
217
+ public function getApi() {
218
+ if (is_null($this->_api)) {
219
+ $testMode = $this->getConfig()->getTestMode();
220
+ $merchantId = $this->getConfig()->getAgentId();
221
+ $apiKey = $this->getConfig()->getApiKey();
222
+
223
+ $this->_api = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $testMode);
224
+ }
225
+
226
+ return $this->_api;
227
+ }
228
+
229
+ /**
230
+ * @param $checkoutId
231
+ * @return PaysonEmbedded\Checkout
232
+ */
233
+ public function getCheckout($checkoutId) {
234
+ return $this->getApi()->GetCheckout($checkoutId);
235
+ }
236
+
237
+ /**
238
+ * Get config
239
+ *
240
+ * @return Payson_Checkout2_Model_Config
241
+ */
242
+ protected function getConfig() {
243
+ if (empty($this->_config)) {
244
+ $this->_config = Mage::getModel('checkout2/config');
245
+ }
246
+ return $this->_config;
247
+ }
248
+
249
+ /**
250
+ * Get order
251
+ *
252
+ * @return Mage_Sales_Model_Order
253
+ */
254
+ public function getOrder() {
255
+ if (!isset($this->_order)) {
256
+ $increment_id = $this->_getSession()->getData('last_real_order_id');
257
+
258
+ if ($increment_id) {
259
+ $this->_order = Mage::getModel('sales/order')
260
+ ->loadByIncrementId($increment_id);
261
+
262
+ if (is_null($this->_order->getId())) {
263
+ $this->_order = null;
264
+ }
265
+ }
266
+ }
267
+
268
+ return $this->_order;
269
+ }
270
+
271
+ public function getQuote() {
272
+ return Mage::getSingleton('checkout/cart')->getQuote();
273
+ }
274
+
275
+ /**
276
+ * Get order status
277
+ *
278
+ * @return boolean
279
+ */
280
+ public function hasOrder() {
281
+ return !is_null($this->getOrder());
282
+ }
283
+
284
+ /**
285
+ * Get quote status
286
+ *
287
+ * @return boolean
288
+ */
289
+ public function hasActiveQuote() {
290
+ return Mage::helper('checkout/cart')->getItemsCount() > 0;
291
+ }
292
+
293
+ /**
294
+ * Gets current locale
295
+ *
296
+ * @return string
297
+ */
298
+ protected function getLocale() {
299
+ $locale = Mage::getSingleton('core/locale')->getLocaleCode();
300
+ $locale = substr($locale, 0, 2);
301
+
302
+ if (!in_array($locale, array('sv', 'fi', 'en'))) {
303
+ switch ($locale) {
304
+ case 'da':
305
+ case 'no': {
306
+ $locale = 'sv';
307
+ break;
308
+ }
309
+ default: {
310
+ $locale = 'en';
311
+ }
312
+ }
313
+ }
314
+
315
+ return $locale;
316
+ }
317
+
318
+ /**
319
+ * Helper for checkout()
320
+ *
321
+ * @param Mage_Sales_Model_Order_Item $item
322
+ * @param PaysonEmbedded\PayData $payData
323
+ * @return void
324
+ */
325
+ protected function prepareOrderItemData($item, &$payData) {
326
+ /* @var $product Mage_Catalog_Model_Product */
327
+ $product = Mage::getModel('catalog/product')
328
+ ->load($item->getProductId());
329
+
330
+ $attributesString = "";
331
+
332
+ if (($children = $item->getChildrenItems()) != null && !$product->isConfigurable()) {
333
+
334
+ foreach ($children as $child) {
335
+ $this->prepareOrderItemData($child, $payData);
336
+ }
337
+ return;
338
+ }
339
+
340
+ $productOptions = $item->getProductOptions();
341
+
342
+ if (array_key_exists('attributes_info', $productOptions)) {
343
+ foreach ($productOptions['attributes_info'] as $attribute) {
344
+ $attributesString .= $attribute['label'] . ": " . $attribute['value'] . ", ";
345
+ }
346
+
347
+ if ($attributesString != "") {
348
+ $attributesString = substr($attributesString, 0, strlen($attributesString) - 2);
349
+ }
350
+ }
351
+
352
+ $name = $item->getName() . ($attributesString != "" ? " - " . $attributesString : "");
353
+ $sku = $item->getSku();
354
+
355
+ $name = strlen($name) <= 128 ? $name : substr($name, 128);
356
+ $sku = strlen($sku) <= 128 ? $sku : substr($sku, 128);
357
+
358
+ $tax_mod = (float) $item->getTaxPercent();
359
+ $tax_mod /= 100;
360
+ $tax_mod = round($tax_mod, 5);
361
+
362
+ $qty = (float) $item->getQtyOrdered();
363
+ $qty = round($qty, 2);
364
+
365
+ $price = (float) $item->getRowTotalInclTax() / $qty;
366
+
367
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem($name, $price, $qty, $tax_mod, $sku));
368
+ }
369
+
370
+ protected function prepareQuoteItemData($item, &$payData) {
371
+ /* @var $product Mage_Catalog_Model_Product */
372
+ $product = Mage::getModel('catalog/product')
373
+ ->load($item->getProductId());
374
+
375
+ $attributesString = "";
376
+
377
+ if (($children = $item->getChildrenItems()) != null && !$product->isConfigurable()) {
378
+
379
+ foreach ($children as $child) {
380
+ $this->prepareQuoteItemData($child, $payData);
381
+ }
382
+ return;
383
+ }
384
+
385
+ $productOptions = $item->getProductOptions();
386
+
387
+ if (is_null($productOptions)) {
388
+ $productOptions = array();
389
+ }
390
+
391
+ if (array_key_exists('attributes_info', $productOptions)) {
392
+ foreach ($productOptions['attributes_info'] as $attribute) {
393
+ $attributesString .= $attribute['label'] . ": " . $attribute['value'] . ", ";
394
+ }
395
+
396
+ if ($attributesString != "") {
397
+ $attributesString = substr($attributesString, 0, strlen($attributesString) - 2);
398
+ }
399
+ }
400
+
401
+ $name = $item->getName() . ($attributesString != "" ? " - " . $attributesString : "");
402
+ $sku = $item->getSku();
403
+
404
+ $name = strlen($name) <= 128 ? $name : substr($name, 128);
405
+ $sku = strlen($sku) <= 128 ? $sku : substr($sku, 128);
406
+
407
+ $tax_mod = (float) $item->getTaxPercent();
408
+ $tax_mod /= 100;
409
+ $tax_mod = round($tax_mod, 5);
410
+
411
+ $qty = $item->getQty();
412
+ $qty = round($qty, 2);
413
+
414
+ $price = (float) $item->getRowTotalInclTax() / $qty;
415
+
416
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem($name, $price, $qty, $tax_mod, $sku));
417
+ }
418
+
419
+ /**
420
+ * Helper for checkout()
421
+ *
422
+ * @param object $order
423
+ * @param object $customer
424
+ * @param object $store
425
+ * @param int $i
426
+ * @param int $total
427
+ */
428
+ protected function prepareOrderShippingData($order, &$payData) {
429
+ $tax_calc = Mage::getSingleton('tax/calculation');
430
+
431
+ $store = Mage::app()->getStore($order->getStoreId());
432
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
433
+
434
+ $tax_rate_req = $tax_calc->getRateRequest(
435
+ $order->getShippingAddress(), $order->getBillingAddress(), $customer->getTaxClassId(), $store);
436
+
437
+
438
+ if (($price = (float) $order->getShippingInclTax()) > 0) {
439
+ $tax_mod = $tax_calc->getRate($tax_rate_req->setProductClassId(
440
+ Mage::getStoreConfig('tax/classes/shipping_tax_class')));
441
+ $tax_mod /= 100;
442
+ $tax_mod = round($tax_mod, 5);
443
+
444
+ $price -= (float) $order->getShippingDiscountAmount();
445
+
446
+ $sku = $order->getShippingMethod();
447
+
448
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem($order->getShippingDescription(), $price, 1, $tax_mod, $sku, PaysonEmbedded\OrderItemType::SERVICE));
449
+ }
450
+ }
451
+
452
+ protected function prepareQuoteShippingData($quote, &$payData) {
453
+ $tax_calc = Mage::getSingleton('tax/calculation');
454
+
455
+ $store = Mage::app()->getStore($quote->getStoreId());
456
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
457
+
458
+ $tax_rate_req = $tax_calc->getRateRequest(
459
+ $quote->getShippingAddress(), $quote->getBillingAddress(), $customer->getTaxClassId(), $store);
460
+
461
+
462
+ if (($price = (float) $quote->getShippingAddress()->getShippingInclTax()) > 0) {
463
+ $tax_mod = $tax_calc->getRate($tax_rate_req->setProductClassId(
464
+ Mage::getStoreConfig('tax/classes/shipping_tax_class')));
465
+ $tax_mod /= 100;
466
+ $tax_mod = round($tax_mod, 5);
467
+
468
+ $price -= (float) $quote->getShippingDiscountAmount();
469
+
470
+ $sku = $quote->getShippingAddress()->getShippingMethod();
471
+
472
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem($quote->getShippingAddress()->getShippingDescription(), $price, 1, $tax_mod, $sku, PaysonEmbedded\OrderItemType::SERVICE));
473
+ }
474
+ }
475
+
476
+ /**
477
+ * Helper for checkout()
478
+ *
479
+ * @return \PaysonEmbedded\Customer
480
+ */
481
+ private function initCustomer() {
482
+ $order = $this->getOrder();
483
+ $testMode = $this->getConfig()->getTestMode();
484
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
485
+
486
+ $firstname = $testMode ? 'Tess T' : $customer->getFirstname();
487
+ $lastname = $testMode ? 'Persson' : $customer->getLastname();
488
+ $email = $testMode ? 'test@payson.se' : $customer->getEmail();
489
+ $telephone = $testMode ? '' : $customer->getTelephone();
490
+ $socialSecurityNo = $testMode ? '4605092222' : '';
491
+ $city = $testMode ? 'Stan' : '';
492
+ $street = $testMode ? 'Testgatan' : '';
493
+ $postCode = $testMode ? '99999' : '';
494
+ $country = $testMode ? 'Sverige' : '';
495
+
496
+ if (!$testMode && $customer->getDefaultBilling()) {
497
+ $billingAddress = Mage::getModel('customer/address')->load($customer->getDefaultBilling());
498
+
499
+ if ($billingAddress->getId()) {
500
+ $firstname = $billingAddress->getData('firstname');
501
+ $lastname = $billingAddress->getData('lastname');
502
+ $telephone = $billingAddress->getData('telephone');
503
+ $street = join(', ', array($billingAddress->getStreet1(), $billingAddress->getStreet2()));
504
+ $city = $billingAddress->getData('city');
505
+ $postCode = $billingAddress->getData('postcode');
506
+ $country = $billingAddress->getData('country_id');
507
+ }
508
+ }
509
+
510
+ return new PaysonEmbedded\Customer($firstname, $lastname, $email, $telephone, $socialSecurityNo, $city, $country, $postCode, $street);
511
+ }
512
+
513
+ private function _initExpressCustomer() {
514
+ $quote = Mage::getModel('checkout/cart')->getQuote();
515
+
516
+ $testMode = $this->getConfig()->getTestMode();
517
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
518
+
519
+ $firstname = $testMode ? 'Tess T' : $customer->getFirstname();
520
+ $lastname = $testMode ? 'Persson' : $customer->getLastname();
521
+ $email = $testMode ? 'test@payson.se' : $customer->getEmail();
522
+ $telephone = $testMode ? '' : $customer->getTelephone();
523
+ $socialSecurityNo = $testMode ? '4605092222' : '';
524
+ $city = $testMode ? 'Stan' : '';
525
+ $street = $testMode ? 'Testgatan' : '';
526
+ $postCode = $testMode ? '99999' : '';
527
+ $country = $testMode ? 'Sverige' : '';
528
+
529
+ if ($quote->getBillingAddress()) {
530
+ $address = $quote->getBillingAddress();
531
+
532
+ if ($address->getId() && $address->getData('postcode')) {
533
+ $email = $address->getData('email');
534
+ $firstname = $address->getData('firstname');
535
+ $lastname = $address->getData('lastname');
536
+ $telephone = $address->getData('telephone');
537
+ $street = join(', ', array_filter(array($address->getStreet1(), $address->getStreet2())));
538
+ $city = $address->getData('city');
539
+ $postCode = $address->getData('postcode');
540
+ $country = $address->getData('country_id');
541
+ }
542
+ }
543
+
544
+ return new PaysonEmbedded\Customer($firstname, $lastname, $email, $telephone, $socialSecurityNo, $city, $country, $postCode, $street);
545
+ }
546
+
547
+ /**
548
+ * Restores cart
549
+ */
550
+ public function restoreCart() {
551
+ $quoteId = $this->getOrder()->getQuoteId();
552
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
553
+ $quote->setIsActive(true)->save();
554
+ }
555
+
556
+ /**
557
+ * Cancels order
558
+ *
559
+ * @param string $message A descriptive message
560
+ *
561
+ */
562
+ public function cancelOrder($message = '') {
563
+
564
+ $order = $this->getOrder();
565
+
566
+ if (!is_null($order)) {
567
+ $order->cancel();
568
+
569
+ if ($this->getConfig()->restoreCartOnCancel()) {
570
+ $this->restoreCart();
571
+ }
572
+
573
+ if ($message != '') {
574
+ $order->addStatusHistoryComment($message);
575
+ }
576
+ }
577
+
578
+ $order->save();
579
+ }
580
+
581
+ private function _getSession() {
582
+ if (!isset($this->_session)) {
583
+ $this->_session = Mage::getSingleton('checkout/session');
584
+ }
585
+
586
+ return $this->_session;
587
+ }
588
+
589
+ public function convertQuoteToOrder() {
590
+ $quote = Mage::getSingleton('checkout/cart')->getQuote();
591
+
592
+ if (is_null($quote)) {
593
+ return null;
594
+ }
595
+
596
+ $quote->collectTotals();
597
+ $service = Mage::getModel('sales/service_quote', $quote);
598
+ $service->submitAll();
599
+ $order = $service->getOrder();
600
+ $quote->setIsActive(false)->save();
601
+ $order->save();
602
+
603
+ return $order;
604
+ }
605
+
606
+ private function _setDefaultShipping($quote) {
607
+ $shippingAddress = $quote->getShippingAddress();
608
+ $shippingMethod = $shippingAddress->getShippingMethod();
609
+
610
+ if ($shippingMethod) {
611
+ return;
612
+ }
613
+
614
+ if (!$shippingAddress->getCountryId()) {
615
+ $shippingAddress->setCountryId('SE');
616
+ }
617
+
618
+ if (!$shippingAddress->getPostCode()) {
619
+ $shippingAddress->setPostcode('169 81');
620
+ }
621
+
622
+ $shippingAddress->setCollectShippingRates(true);
623
+
624
+ // Collect and set default shipping rate
625
+ $shippingAddress->collectShippingRates();
626
+ $rates = $shippingAddress->getAllShippingRates();
627
+
628
+ if (count($rates) > 0) {
629
+ $rate = $rates[0];
630
+ $shippingAddress->setShippingMethod($rate->getCode())
631
+ ->setShippingAmount($rate->getPrice());
632
+ }
633
+
634
+ $quote->getPayment()->setMethod('checkout2');
635
+ $quote->setTotalsCollectedFlag(false)->collectTotals();
636
+ }
637
+ }
app/code/community/Payson/Checkout2/Model/Config.php ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_Model_Config {
4
+ /*
5
+ * Private properties
6
+ */
7
+
8
+ /**
9
+ * Default store id used in GetConfig()
10
+ *
11
+ * @var int
12
+ */
13
+ private $default_store_id;
14
+
15
+ /**
16
+ * Supported currency codes
17
+ *
18
+ * @var array
19
+ */
20
+ private $supported_currencies = array
21
+ (
22
+ 'SEK', 'EUR'
23
+ );
24
+
25
+ /*
26
+ * Public methods
27
+ */
28
+
29
+ /**
30
+ * Constructor
31
+ *
32
+ * @return void
33
+ */
34
+ public function __construct() {
35
+ $this->setDefaultStoreId(Mage::app()->getStore()->getId());
36
+ }
37
+
38
+ /**
39
+ * Set default store id
40
+ *
41
+ * @param int $store
42
+ * @return object $this
43
+ */
44
+ public function setDefaultStoreId($store) {
45
+ $this->default_store_id = $store;
46
+
47
+ return $this;
48
+ }
49
+
50
+ /**
51
+ * Get default store id
52
+ *
53
+ * @return int
54
+ */
55
+ public function getDefaultStoreId() {
56
+ return $this->default_store_id;
57
+ }
58
+
59
+ /**
60
+ * Whether $currency is supported
61
+ *
62
+ * @param string $currency
63
+ * @return bool
64
+ */
65
+ public function isCurrencySupported($currency) {
66
+ return in_array(strtoupper($currency), $this->supported_currencies);
67
+ }
68
+
69
+ /**
70
+ * Get configuration value
71
+ *
72
+ * @param mixed $name
73
+ * @param int|null $store [optional]
74
+ * @param mixed $default [optional]
75
+ * @param string $prefix [optional]
76
+ */
77
+ public function getConfig($name, $store = null, $default = null, $prefix = 'payment/checkout2/') {
78
+ if (!isset($store)) {
79
+ $store = $this->getDefaultStoreId();
80
+ }
81
+
82
+ $name = $prefix . $name;
83
+ $value = Mage::getStoreConfig($name, $store);
84
+
85
+ return (isset($value) ? $value : $default);
86
+ }
87
+
88
+ /**
89
+ * @see getConfig
90
+ */
91
+ public function get($name, $store = null, $default = null, $prefix = 'payment/checkout2/') {
92
+ return $this->getConfig($name, $store, $default, $prefix);
93
+ }
94
+
95
+ public function restoreCartOnCancel() {
96
+ return $this->get('restore_on_cancel');
97
+ }
98
+
99
+ public function restoreCartOnError() {
100
+ return $this->get('restore_on_error');
101
+ }
102
+
103
+ public function getTestMode() {
104
+ return $this->get('test_mode');
105
+ }
106
+
107
+ public function getEnabled() {
108
+ return $this->get('active');
109
+ }
110
+
111
+ public function getAgentID() {
112
+ return $this->get('agent_id');
113
+ }
114
+
115
+ public function getApiKey() {
116
+ return $this->get('md5_key');
117
+ }
118
+
119
+ public function getTermsUrl() {
120
+ return $this->get('terms_and_conditions_url');
121
+ }
122
+
123
+ public function getTheme() {
124
+ return $this->get('checkout_theme');
125
+ }
126
+
127
+ public function getExtraVerification() {
128
+ return $this->get('extra_verification');
129
+ }
130
+
131
+ public function getRequestPhone() {
132
+ return $this->get('request_phone');
133
+ }
134
+ }
app/code/community/Payson/Checkout2/Model/Method/Checkout2.php ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_Model_Method_Checkout2 extends Mage_Payment_Model_Method_Abstract
4
+ {
5
+ protected $_code = 'payson_checkout2';
6
+ protected $_formBlockType = 'checkout2/form_checkout2';
7
+ protected $_infoBlockType = 'checkout2/info_checkout2';
8
+
9
+ protected $_isGateway = false;
10
+ protected $_canAuthorize = true;
11
+ protected $_canCapture = true;
12
+ protected $_canCapturePartial = false;
13
+ protected $_canRefund = true;
14
+ protected $_canRefundInvoicePartial = false;
15
+ protected $_canVoid = true;
16
+ protected $_canCancelInvoice = true;
17
+ protected $_canUseInternal = true; // true
18
+ protected $_canUseCheckout = true; // true
19
+ protected $_canUseForMultishipping = false; // true
20
+ protected $_isInitializeNeeded = false;
21
+ protected $_canFetchTransactionInfo = false;
22
+ protected $_canReviewPayment = false;
23
+ protected $_canCreateBillingAgreement = false;
24
+ protected $_canManageRecurringProfiles = false; // true
25
+
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ public function getTitle()
30
+ {
31
+ return Mage::helper('checkout2')->__('Payson');
32
+ }
33
+
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ public function getOrderPlaceRedirectUrl()
38
+ {
39
+ return Mage::getUrl('checkout2/payment/new');
40
+ }
41
+
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ public function canUseForCurrency($currency)
46
+ {
47
+ return Mage::getModel('checkout2/config')->isCurrencySupported($currency);
48
+ }
49
+
50
+ /**
51
+ * @inheritDoc
52
+ */
53
+ public function canUseCheckout()
54
+ {
55
+ $config = Mage::getModel('checkout2/config');
56
+
57
+ return $config->getEnabled();
58
+ }
59
+
60
+ public function getConfigPaymentAction() {
61
+ return self::ACTION_AUTHORIZE;
62
+ }
63
+
64
+ /**
65
+ * @inheritDoc
66
+ */
67
+ public function authorize(Varien_Object $payment, $amount) {
68
+ $orderHelper = Mage::helper('checkout2/order');
69
+ $api = $orderHelper->getApi();
70
+
71
+ $order = $payment->getOrder();
72
+ $checkoutId = $order->getData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN);
73
+ $checkout = $api->GetCheckout($checkoutId);
74
+
75
+ $payment->setTransactionId($checkout->purchaseId)->setIsTransactionClosed(0);
76
+
77
+ return $this;
78
+ }
79
+
80
+ /**
81
+ * @inheritDoc
82
+ */
83
+ public function capture(Varien_Object $payment, $amount) {
84
+ return $this;
85
+ }
86
+
87
+ /**
88
+ * @inheritDoc
89
+ */
90
+ public function cancel(Varien_Object $payment) {
91
+ $order = $payment->getOrder();
92
+ $orderHelper = Mage::helper('checkout2/order');
93
+ $api = $orderHelper->getApi();
94
+ $helper = Mage::helper('checkout2');
95
+
96
+ if (($order->getPayment()->getMethod() == 'checkout2') && ($order->getState() === Mage_Sales_Model_Order::STATE_PROCESSING || $order->getState() === Mage_Sales_Model_Order::STATE_PENDING_PAYMENT)) {
97
+ $checkoutId = $order->getData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN);
98
+ $checkout = $api->GetCheckout($checkoutId);
99
+ $api->CancelCheckout($checkout);
100
+
101
+ $order->addStatusHistoryComment($helper->__('Order was canceled at Payson'));
102
+ $payment->setIsTransactionClosed(1);
103
+ } else {
104
+ Mage::throwException($helper->__('Payson is not ready to cancel the order. Please try again later.'));
105
+ }
106
+ return $this;
107
+ }
108
+
109
+ /**
110
+ * @inheritDoc
111
+ */
112
+ public function void(Varien_Object $payment) {
113
+ $this->cancel($payment);
114
+ }
115
+
116
+ /**
117
+ * @inheritDoc
118
+ */
119
+ public function refund(Varien_Object $payment, $amount) {
120
+ $order = $payment->getOrder();
121
+ $orderHelper = Mage::helper('checkout2/order');
122
+ $api = $orderHelper->getApi();
123
+ $helper = Mage::helper('checkout2');
124
+
125
+ $checkoutId = $order->getData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN);
126
+ $checkout = $api->GetCheckout($checkoutId);
127
+
128
+ $method = $payment->getMethod();
129
+ $order_id = $order->getData('increment_id');
130
+
131
+ $message = $helper->__('Payment was credited at Payson');
132
+
133
+ if ($order->getBaseGrandTotal() != $amount || $checkout->payData->totalPriceIncludingTax != $amount) {
134
+ Mage::throwException('Invalid amount');
135
+ }
136
+
137
+ if ($method == "checkout2") {
138
+
139
+ if ($checkout->status == 'shipped') {
140
+ // Credits each order item
141
+ foreach ($checkout->payData->items as $item) {
142
+ $item->creditedAmount = $item->unitPrice * $item->quantity;
143
+ }
144
+
145
+ $api->UpdateCheckout($checkout);
146
+ $order->addStatusHistoryComment($message);
147
+ Mage::getSingleton('core/session')->addSuccess($message);
148
+ } else {
149
+ $errorMessage = Mage::helper('payson')->__('Unable to refund order: %s. It must have status "shipped" but it´s current status is: "%s"', $order_id, $checkout->status);
150
+ Mage::getSingleton('core/session')->addError($errorMessage);
151
+ }
152
+ }
153
+ return $this;
154
+ }
155
+ }
app/code/community/Payson/Checkout2/Model/Notification.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_Model_Notification {
4
+ public function process($checkoutId) {
5
+ $orderHelper = Mage::helper('checkout2/order');
6
+ $api = $orderHelper->getApi();
7
+ $checkout = $api->GetCheckout($checkoutId);
8
+
9
+ $order = Mage::getModel('sales/order')->loadByAttribute(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN, $checkoutId);
10
+
11
+ if ($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE || $order->getState() == Mage_Sales_Model_Order::STATE_CANCELED) {
12
+ return;
13
+ }
14
+
15
+ Mage::log('Order (' . $order->getIncrementId() . ') notified status update: ' . $checkout->status);
16
+
17
+ switch ($checkout->status) {
18
+ case 'readyToShip':
19
+ $message = Mage::helper('checkout2')->__('Payson completed the order payment.');
20
+
21
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, Mage_Sales_Model_Order::STATE_PROCESSING, $message);
22
+
23
+ break;
24
+
25
+ case 'shipped':
26
+ $order->addStatusHistoryComment(Mage::helper('checkout2')->__('Order has been marked as shipped at Payson.'));
27
+
28
+ // Create Qty array
29
+ $shipmentItems = array();
30
+
31
+ foreach ($order->getAllItems() as $item) {
32
+ $shipmentItems [$item->getId()] = $item->getQtyToShip();
33
+ }
34
+
35
+ // Prepare shipment and save
36
+ if ($order->getId() && !empty($shipmentItems) && $order->canShip()) {
37
+ $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($shipmentItems);
38
+ $shipment->register();
39
+ }
40
+
41
+ // Crete invoice to complete order
42
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
43
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
44
+ $invoice->register();
45
+ $transactionSave = Mage::getModel('core/resource_transaction')
46
+ ->addObject($invoice)
47
+ ->addObject($invoice->getOrder());
48
+ $transactionSave->save();
49
+
50
+ break;
51
+
52
+ case 'paidToAccount':
53
+ $order->addStatusHistoryComment(Mage::helper('checkout2')->__('Money have been paid to account by Payson.'));
54
+
55
+ break;
56
+
57
+ case 'credited':
58
+ $service = Mage::getModel('sales/service_order', $order);
59
+
60
+ foreach ($order->getInvoiceCollection() as $invoice) {
61
+ $creditmemo = $service->prepareInvoiceCreditmemo($invoice);
62
+ $creditmemo->register();
63
+ $creditmemo->save();
64
+
65
+ $creditmemo->sendEmail();
66
+ $order->addStatusHistoryComment(Mage::helper('checkout2')->__('Notified customer about creditmemo #%s.', $creditmemo->getIncrementId()))
67
+ ->setIsCustomerNotified(true)
68
+ ->save();
69
+ }
70
+
71
+ break;
72
+
73
+ case 'expired':
74
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
75
+ $order->addStatusHistoryComment(Mage::helper('checkout2')->__('The payment was expired by Payson.'));
76
+
77
+ break;
78
+
79
+ case 'canceled': {
80
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
81
+ $order->addStatusHistoryComment(Mage::helper('checkout2')->__('Order was canceled at Payson.'));
82
+
83
+ break;
84
+ }
85
+
86
+ case 'denied': {
87
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
88
+ $order->addStatusHistoryComment(Mage::helper('checkout2')->__('The order was denied by Payson.'));
89
+
90
+ break;
91
+ }
92
+
93
+ default: {
94
+ break;
95
+ }
96
+ }
97
+
98
+ $order->save();
99
+ }
100
+ }
app/code/community/Payson/Checkout2/Model/Observer.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_Model_Observer
4
+ {
5
+ public function checkoutCartSaveAfter(Varien_Event_Observer $observer) {
6
+ $helper = Mage::helper('checkout2/order');
7
+ $event = $observer->getEvent();
8
+ $cart = $observer->getEvent()->getCart();
9
+
10
+ if ($cart) {
11
+ $quote = $cart->getQuote();
12
+ }
13
+
14
+ $item = $event->getQuoteItem();
15
+
16
+ if ($item) {
17
+ $quote = $item->getQuote();
18
+ }
19
+
20
+ if (!$quote) {
21
+ return;
22
+ }
23
+
24
+ $checkoutId = $quote->getData('payson_checkout_id');
25
+
26
+ if ($checkoutId) {
27
+ // Will trigger an automatic update to express checkout
28
+ $helper->updateCheckoutControlKey($checkoutId);
29
+ }
30
+ }
31
+ }
app/code/community/Payson/Checkout2/Model/Order.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_Model_Order
4
+ {
5
+ const CHECKOUT_ID_COLUMN = 'payson_checkout_id';
6
+ }
7
+
8
+ ?>
app/code/community/Payson/Checkout2/Model/Themes.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_Model_Themes
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $helper = Mage::helper('checkout2');
8
+
9
+ return array(
10
+ array('value'=> 'White', 'label' => $helper->__('White')),
11
+ array('value'=> 'Blue', 'label' => $helper->__('Blue')),
12
+ array('value'=> 'Gray', 'label' => $helper->__('Gray')),
13
+ array('value'=> 'WhiteTextLogos', 'label' => $helper->__('White with text logos')),
14
+ array('value'=> 'GrayTextLogos', 'label' => $helper->__('Gray with text logos')),
15
+ array('value'=> 'BlueTextLogos', 'label' => $helper->__('Blue with text logos')),
16
+ );
17
+ }
18
+ }
app/code/community/Payson/Checkout2/Model/VerificationTypes.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_Model_VerificationTypes
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ $helper = Mage::helper('checkout2');
8
+
9
+ return array(
10
+ array('value'=> 'none', 'label' => $helper->__('None')),
11
+ array('value'=> 'bankid', 'label' => $helper->__('BankID')),
12
+ );
13
+ }
14
+ }
app/code/community/Payson/Checkout2/controllers/Adminhtml/Sales/Order/ShipmentController.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php';
4
+
5
+ class Payson_Checkout2_Adminhtml_Sales_Order_ShipmentController extends Mage_Adminhtml_Sales_Order_ShipmentController {
6
+
7
+ public function saveAction() {
8
+
9
+ $order = Mage::getModel('sales/order')->load($this->getRequest()->getParam('order_id'));
10
+
11
+ if (($order->getPayment()->getMethodInstance()->getCode() == "payson_checkout2")) {
12
+
13
+ $orderId = $order->getIncrementId();
14
+ $orderHelper = Mage::helper('checkout2/order');
15
+ $api = $orderHelper->getApi();
16
+
17
+ $checkoutId = $order->getData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN);
18
+
19
+ if ($checkoutId == '') {
20
+ $this->handleNoCheckoutId($orderId);
21
+ return $this;
22
+ }
23
+
24
+ $checkout = $api->GetCheckout($checkoutId);
25
+
26
+ if ($checkout->status === 'readyToShip') {
27
+ // Set order as shipped at Payson
28
+ $api->ShipCheckout($checkout);
29
+
30
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
31
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
32
+ $invoice->register();
33
+ $transactionSave = Mage::getModel('core/resource_transaction')
34
+ ->addObject($invoice)
35
+ ->addObject($invoice->getOrder());
36
+ $transactionSave->save();
37
+ } else {
38
+ $this->handleWrongOrderStatus($orderId, $checkout->status);
39
+
40
+ return $this;
41
+ }
42
+ }
43
+
44
+ parent::saveAction();
45
+ }
46
+
47
+ private function handleWrongOrderStatus($orderId, $currentStatus) {
48
+ $errorMessage = Mage::helper('checkout2')->__('Unable to ship order: %s. It must have status "readyToShip" but it´s current status is: "%s".', $orderId, $currentStatus);
49
+ Mage::getSingleton('core/session')->addError($errorMessage);
50
+ $this->_redirectReferer();
51
+ }
52
+
53
+ private function handleNoCheckoutId($orderId) {
54
+ $errorMessage = Mage::helper('checkout2')->__('Unable to ship order: %s. No Payson checkout ID was found.', $orderId);
55
+ Mage::getSingleton('core/session')->addError($errorMessage);
56
+ $this->_redirectReferer();
57
+ }
58
+
59
+ }
app/code/community/Payson/Checkout2/controllers/ExpressController.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_ExpressController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ private $_orderHelper;
6
+
7
+ public function _construct() {
8
+ $this->_orderHelper = Mage::helper('checkout2/order');
9
+ }
10
+
11
+ public function newAction() {
12
+ if (!$this->_getOrderHelper()->hasActiveQuote()) {
13
+ $this->_redirect('checkout/cart');
14
+
15
+ return;
16
+ }
17
+
18
+ // Resets any previous checkouts
19
+ $quote = $this->_getOrderHelper()->getQuote();
20
+ $quote->setData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN, null);
21
+ $quote->save();
22
+
23
+ $this->_redirect('checkout2/express/index');
24
+ }
25
+
26
+ public function indexAction() {
27
+ if (!$this->_getOrderHelper()->hasActiveQuote()) {
28
+ $this->_redirect('checkout/cart');
29
+
30
+ return;
31
+ }
32
+
33
+ $this->loadLayout();
34
+ $this->renderLayout();
35
+ }
36
+
37
+ public function cancelAction() {
38
+ $cancelMessage = Mage::helper('checkout2')->__('Order was canceled at Payson.');
39
+ Mage::getSingleton('core/session')->addError($cancelMessage);
40
+
41
+ $this->_redirect('checkout2/express/index');
42
+ }
43
+
44
+ public function returnAction() {
45
+ $quote = $this->_getOrderHelper()->getQuote();
46
+
47
+ $checkoutId = $quote->getData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN);
48
+ $api = $this->_getOrderHelper()->getApi();
49
+
50
+ $checkout = $api->GetCheckout($checkoutId);
51
+
52
+ switch ($checkout->status) {
53
+ case 'readyToShip':
54
+ Mage::getSingleton('core/session')->setCheckoutId($checkoutId);
55
+
56
+ $order = $this->_getOrderHelper()->convertQuoteToOrder();
57
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
58
+
59
+ // Send order reference to Payson
60
+ $checkout->merchant->reference = $order->getIncrementId();
61
+ $api->UpdateCheckout($checkout);
62
+
63
+ $successMessage = Mage::helper('checkout2')->__('The payment was successfully completed at Payson.');
64
+
65
+ $order->sendNewOrderEmail()->save();
66
+
67
+ $this->_getOrderHelper()->removeCheckoutControlKey($checkoutId);
68
+
69
+ Mage::getSingleton('core/session')->addSuccess($successMessage);
70
+ $this->_redirect('checkout2/payment/confirmation');
71
+
72
+ break;
73
+
74
+ case 'created':
75
+ case 'processingPayment':
76
+ $order = $this->_getOrderHelper()->convertQuoteToOrder();
77
+ $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true);
78
+
79
+ // Send order reference to Payson
80
+ $checkout->merchant->reference = $order->getIncrementId();
81
+ $api->UpdateCheckout($checkout);
82
+
83
+ $message = Mage::helper('checkout2')->__('Your payment is being processed by Payson.');
84
+
85
+ Mage::getSingleton('core/session')->addError($message);
86
+ $this->_redirect('checkout2/express/index');
87
+ break;
88
+
89
+ case 'denied':
90
+ $errorMessage = Mage::helper('checkout2')->__('The payment was denied by Payson.');
91
+
92
+ Mage::getSingleton('core/session')->addError($errorMessage);
93
+ $quote->setIsActive(true)->save();
94
+ $this->_redirect('checkout2/express/index');
95
+ break;
96
+
97
+ case 'expired':
98
+ $errorMessage = Mage::helper('checkout2')->__('The payment was expired by Payson.');
99
+
100
+ Mage::getSingleton('core/session')->addError($errorMessage);
101
+ $quote->setIsActive(true)->save();
102
+ $this->_redirect('checkout2/express/index');
103
+ break;
104
+
105
+ case 'canceled': {
106
+ $cancelMessage = Mage::helper('checkout2')->__('Order was canceled at Payson.');
107
+ $quote->setIsActive(true)->save();
108
+
109
+ Mage::getSingleton('core/session')->addError($cancelMessage);
110
+ $this->_redirect('checkout2/express/index');
111
+ break;
112
+
113
+ }
114
+ default: {
115
+ $message = Mage::helper('checkout2')->__('Something went wrong with the payment.');
116
+
117
+ Mage::getSingleton('core/session')->addError($message);
118
+ $this->_redirect('checkout2/express/index');
119
+ break;
120
+ }
121
+ }
122
+ }
123
+
124
+ public function updateAction() {
125
+ if (!$this->getRequest()->isXmlHttpRequest()) {
126
+ return;
127
+ }
128
+
129
+ $orderHelper = Mage::helper('checkout2/order');
130
+ $quote = $this->_getQuote();
131
+
132
+ if (!$orderHelper->hasActiveQuote()) {
133
+ $this->getResponse()->setBody('empty_cart');
134
+ return;
135
+ }
136
+
137
+ // Update shipping address if address provided
138
+ $updateAddress = (string) $this->getRequest()->getParam('setAddress');
139
+
140
+ if ($updateAddress) {
141
+ $this->_updateShippingAddress($quote);
142
+ }
143
+
144
+ // Update shipping method if method provided
145
+ $method = (string) $this->getRequest()->getParam('method');
146
+
147
+ if ($method) {
148
+ $this->_updateShippingMethod($quote, $method);
149
+ }
150
+
151
+ $quote->setTotalsCollectedFlag(false)->collectTotals();
152
+ $quote->getPayment()->setMethod('checkout2');
153
+ $quote->save();
154
+
155
+ $orderHelper->updateExpressCheckout();
156
+
157
+ $this->loadLayout();
158
+ $this->renderLayout();
159
+ }
160
+
161
+ private function _updateShippingMethod($quote, $method) {
162
+ $shippingAddress = $quote->getShippingAddress();
163
+ $shippingAddress->setShippingMethod($method);
164
+ }
165
+
166
+ private function _updateShippingAddress($quote) {
167
+ $orderHelper = Mage::helper('checkout2/order');
168
+
169
+ // Update shipping address
170
+ $country = (string) $this->getRequest()->getParam('CountryCode');
171
+ $postcode = (string) $this->getRequest()->getParam('PostalCode');
172
+ $city = (string) $this->getRequest()->getParam('City');
173
+ $firstName = (string) $this->getRequest()->getParam('FirstName');
174
+ $lastName = (string) $this->getRequest()->getParam('LastName');
175
+ $street = (string) $this->getRequest()->getParam('Street');
176
+
177
+ $checkoutId = $quote->getData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN);
178
+ $checkout = $orderHelper->getCheckout($checkoutId);
179
+ $paysonCustomer = $checkout->customer;
180
+
181
+ $shippingAddress = $quote->getShippingAddress();
182
+
183
+ $billingAddress = array(
184
+ 'firstname' => $firstName,
185
+ 'lastname' => $lastName,
186
+ 'street' => $street,
187
+ 'city' => $city,
188
+ 'region_id' => '',
189
+ 'postcode' => $postcode,
190
+ 'country_id' => $country,
191
+ 'use_for_shipping' => '1',
192
+ 'telephone' => $paysonCustomer->phone,
193
+ 'email' => $paysonCustomer->email
194
+ );
195
+
196
+ $quote->getBillingAddress()
197
+ ->addData($billingAddress);
198
+
199
+ $shippingAddress
200
+ ->addData($billingAddress)
201
+ ->setPaymentMethod('checkout2')
202
+ ->setCollectShippingRates(true)
203
+ ->save();
204
+
205
+ // Collect and set default shipping rate
206
+ $quote->collectTotals()->save();
207
+ $rates = $shippingAddress->getAllShippingRates();
208
+
209
+ if (is_null($shippingAddress->getShippingMethod()) || !$this->_isPaymentMethodAmongRates($shippingAddress->getShippingMethod(), $rates)) {
210
+
211
+ if (count($rates) > 0) {
212
+ $rate = $rates[0];
213
+ $shippingAddress->setShippingMethod($rate->getCode())
214
+ ->setShippingAmount($rate->getPrice());
215
+ }
216
+ }
217
+ }
218
+
219
+ private function _isPaymentMethodAmongRates($code, $rates) {
220
+ foreach ($rates as $index => $rate) {
221
+ if ($rate->getCode() == $code) {
222
+ return true;
223
+ }
224
+ }
225
+
226
+ return false;
227
+ }
228
+
229
+ private function _getOrderHelper() {
230
+ return $this->_orderHelper;
231
+ }
232
+
233
+ private function _getQuote() {
234
+ return Mage::getSingleton('checkout/cart')->getQuote();
235
+ }
236
+ }
237
+
app/code/community/Payson/Checkout2/controllers/NotificationController.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_NotificationController 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)->sendResponse();
11
+
12
+ return;
13
+ }
14
+
15
+ try {
16
+ $checkoutId = $request->getParam('checkout');
17
+ Mage::getModel('checkout2/notification')->process($checkoutId);
18
+ } catch (Mage_Core_Exception $e) {
19
+ Mage::logException($e);
20
+ $response->setHttpResponseCode(503)->sendResponse();
21
+ exit;
22
+ } catch (Exception $e) {
23
+ Mage::logException($e);
24
+ $response->setHttpResponseCode(500);
25
+ }
26
+ }
27
+ }
28
+
app/code/community/Payson/Checkout2/controllers/PaymentController.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Checkout2_PaymentController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ private $_orderHelper;
6
+
7
+ public function _construct() {
8
+ $this->_orderHelper = Mage::helper('checkout2/order');
9
+ }
10
+
11
+ public function newAction() {
12
+ if (!$this->_getOrderHelper()->hasOrder()) {
13
+ $this->_redirect('checkout/cart');
14
+
15
+ return;
16
+ }
17
+
18
+ // Resets any previous checkouts
19
+ $order = $this->_getOrderHelper()->getOrder();
20
+ $order->setData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN, null);
21
+ $order->save();
22
+
23
+ $this->_redirect('checkout2/payment/index');
24
+ }
25
+
26
+ public function indexAction() {
27
+ if (!$this->_getOrderHelper()->hasOrder()) {
28
+ $this->_redirect('checkout/cart');
29
+
30
+ return;
31
+ }
32
+
33
+ $this->loadLayout();
34
+ $this->renderLayout();
35
+ }
36
+
37
+ public function confirmationAction() {
38
+ $checkoutId = Mage::getSingleton('core/session')->getCheckoutId();
39
+
40
+ if (!$checkoutId) {
41
+ $this->_redirect('checkout/cart');
42
+ }
43
+
44
+ $this->loadLayout();
45
+ $this->renderLayout();
46
+ }
47
+
48
+ public function cancelAction() {
49
+ $cancelMessage = Mage::helper('checkout2')->__('Order was canceled at Payson.');
50
+ Mage::getSingleton('core/session')->addError($cancelMessage);
51
+
52
+ $this->_getOrderHelper()->cancelOrder($cancelMessage);
53
+
54
+ $this->_redirect('checkout2/payment/index');
55
+ }
56
+
57
+ public function returnAction() {
58
+ $order = $this->_getOrderHelper()->getOrder();
59
+ $checkoutId = $order->getData(Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN);
60
+ $api = $this->_getOrderHelper()->getApi();
61
+
62
+ $checkout = $api->GetCheckout($checkoutId);
63
+
64
+ switch ($checkout->status) {
65
+ case 'readyToShip':
66
+ Mage::getSingleton('core/session')->setCheckoutId($checkoutId);
67
+
68
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
69
+
70
+ // Send order reference to Payson
71
+ $checkout->merchant->reference = $order->getIncrementId();
72
+ $api->UpdateCheckout($checkout);
73
+
74
+ $successMessage = Mage::helper('checkout2')->__('The payment was successfully completed at Payson.');
75
+
76
+ $order->sendNewOrderEmail()->save();
77
+
78
+ Mage::getSingleton('core/session')->addSuccess($successMessage);
79
+ $this->_redirect('checkout2/payment/confirmation');
80
+
81
+ break;
82
+
83
+ case 'created':
84
+ case 'processingPayment':
85
+ $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true);
86
+
87
+ // Send order reference to Payson
88
+ $checkout->merchant->reference = $order->getIncrementId();
89
+ $api->UpdateCheckout($checkout);
90
+
91
+ $message = Mage::helper('checkout2')->__('Your payment is being processed by Payson.');
92
+
93
+ Mage::getSingleton('core/session')->addError($message);
94
+ $this->_redirect('checkout2/payment/index');
95
+ break;
96
+
97
+ case 'denied':
98
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
99
+
100
+ $errorMessage = Mage::helper('checkout2')->__('The payment was denied by Payson.');
101
+
102
+ Mage::getSingleton('core/session')->addError($errorMessage);
103
+ $this->_getOrderHelper()->cancelOrder($errorMessage);
104
+ $this->_redirect('checkout2/payment/index');
105
+ break;
106
+
107
+ case 'expired':
108
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
109
+
110
+ $errorMessage = Mage::helper('checkout2')->__('The payment was expired by Payson.');
111
+
112
+ Mage::getSingleton('core/session')->addError($errorMessage);
113
+ $this->_getOrderHelper()->cancelOrder($errorMessage);
114
+ $this->_redirect('checkout2/payment/index');
115
+ break;
116
+
117
+ case 'canceled': {
118
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
119
+ $cancelMessage = Mage::helper('checkout2')->__('Order was canceled at Payson.');
120
+ $this->_getOrderHelper()->cancelOrder($cancelMessage);
121
+
122
+ Mage::getSingleton('core/session')->addError($cancelMessage);
123
+ $this->_redirect('checkout2/payment/index');
124
+ break;
125
+ }
126
+ default: {
127
+ $message = Mage::helper('checkout2')->__('Something went wrong with the payment.');
128
+
129
+ Mage::getSingleton('core/session')->addError($message);
130
+ $this->_redirect('checkout2/payment/index');
131
+ break;
132
+ }
133
+ }
134
+ }
135
+
136
+ private function _getOrderHelper() {
137
+ return $this->_orderHelper;
138
+ }
139
+ }
app/code/community/Payson/Checkout2/etc/config.xml ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Payson_Checkout2>
5
+ <version>1.0.0</version>
6
+ </Payson_Checkout2>
7
+ </modules>
8
+ <global>
9
+ <fieldsets>
10
+ <sales_convert_quote>
11
+ <payson_checkout_id>
12
+ <to_order>*</to_order>
13
+ </payson_checkout_id>
14
+ </sales_convert_quote>
15
+ </fieldsets>
16
+ <blocks>
17
+ <checkout2>
18
+ <class>Payson_Checkout2_Block</class>
19
+ </checkout2>
20
+ <checkout2_adminhtml>
21
+ <class>Payson_Checkout2_Block_Adminhtml</class>
22
+ </checkout2_adminhtml>
23
+ </blocks>
24
+ <models>
25
+ <checkout2>
26
+ <class>Payson_Checkout2_Model</class>
27
+ </checkout2>
28
+ </models>
29
+ <helpers>
30
+ <checkout2>
31
+ <class>Payson_Checkout2_Helper</class>
32
+ </checkout2>
33
+ </helpers>
34
+ <resources>
35
+ <payson_checkout2_setup>
36
+ <setup>
37
+ <module>Payson_Checkout2</module>
38
+ </setup>
39
+ </payson_checkout2_setup>
40
+ </resources>
41
+
42
+ <events>
43
+ <checkout_cart_save_after>
44
+ <observers>
45
+ <checkout2>
46
+ <class>checkout2/observer</class>
47
+ <method>checkoutCartSaveAfter</method>
48
+ </checkout2>
49
+ </observers>
50
+ </checkout_cart_save_after>
51
+ </events>
52
+ </global>
53
+ <default>
54
+ <payment>
55
+ <checkout2>
56
+ <test_mode>1</test_mode>
57
+ <active>1</active>
58
+ <model>checkout2/method_checkout2</model>
59
+ <title>Payson Checkout2</title>
60
+ <order_status>pending</order_status>
61
+ <allowspecific>0</allowspecific>
62
+ <payment_action>authorize</payment_action>
63
+ <restore_on_cancel>1</restore_on_cancel>
64
+ <restore_on_error>1</restore_on_error>
65
+ <color_theme>Gray</color_theme>
66
+ <extra_verification>none</extra_verification>
67
+ <request_phone>0</request_phone>
68
+ <agent_id>4</agent_id>
69
+ <md5_key>2acab30d-fe50-426f-90d7-8c60a7eb31d4</md5_key>
70
+ </checkout2>
71
+ </payment>
72
+ </default>
73
+ <frontend>
74
+ <routers>
75
+ <checkout2>
76
+ <use>standard</use>
77
+ <args>
78
+ <module>Payson_Checkout2</module>
79
+ <frontName>checkout2</frontName>
80
+ </args>
81
+ </checkout2>
82
+ </routers>
83
+ <translate>
84
+ <modules>
85
+ <payson_checkout2>
86
+ <files>
87
+ <default>payson_checkout2.csv</default>
88
+ </files>
89
+ </payson_checkout2>
90
+ </modules>
91
+ </translate>
92
+ <layout>
93
+ <updates>
94
+ <payson_checkout2>
95
+ <file>payson_checkout2.xml</file>
96
+ </payson_checkout2>
97
+ </updates>
98
+ </layout>
99
+ </frontend>
100
+ <adminhtml>
101
+ <translate>
102
+ <modules>
103
+ <payson_checkout2>
104
+ <files>
105
+ <default>payson_checkout2.csv</default>
106
+ </files>
107
+ </payson_checkout2>
108
+ </modules>
109
+ </translate>
110
+ </adminhtml>
111
+
112
+ <admin>
113
+ <routers>
114
+ <adminhtml>
115
+ <args>
116
+ <modules>
117
+ <Payson_Checkout2 before="Mage_Adminhtml">Payson_Checkout2_Adminhtml</Payson_Checkout2>
118
+ </modules>
119
+ </args>
120
+ </adminhtml>
121
+ </routers>
122
+ </admin>
123
+
124
+ <!--
125
+ <crontab>
126
+ <jobs>
127
+ <payson_checkout2_cron>
128
+ <schedule>
129
+ <cron_expr>0,45 * * * *</cron_expr>
130
+ </schedule>
131
+ <run>
132
+ <model>payson_checkout2/observer::methodName</model>
133
+ </run>
134
+ </payson_checkout2_cron>
135
+ </jobs>
136
+ </crontab>
137
+ -->
138
+ </config>
app/code/community/Payson/Checkout2/etc/system.xml ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <checkout2 translate="label" module="checkout2">
7
+ <label>Payson Checkout2</label>
8
+ <sort_order>10</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
+ <active translate="label,comment">
14
+ <label>Enabled</label>
15
+ <comment>Enable/disable payment with Payson</comment>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>10</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
+ </active>
23
+ <test_mode translate="label,comment">
24
+ <label>Test mode</label>
25
+ <comment>Enable when using a sandboxed test agent</comment>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_yesno</source_model>
28
+ <sort_order>20</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
+ </test_mode>
33
+ <agent_id translate="label,comment">
34
+ <label>Agent ID</label>
35
+ <comment>Agent ID is found on your Payson profile page</comment>
36
+ <frontend_type>text</frontend_type>
37
+ <sort_order>30</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>0</show_in_website>
40
+ <show_in_store>0</show_in_store>
41
+ </agent_id>
42
+ <md5_key translate="label,comment">
43
+ <label>API key</label>
44
+ <comment>API key is found on your Payson profile page</comment>
45
+ <frontend_type>text</frontend_type>
46
+ <sort_order>40</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>0</show_in_website>
49
+ <show_in_store>0</show_in_store>
50
+ </md5_key>
51
+ <terms_and_conditions_url translate="label,comment">
52
+ <label>Terms and Conditions URL</label>
53
+ <comment>These terms will be linked to by the payment form</comment>
54
+ <frontend_type>text</frontend_type>
55
+ <validate>required-entry</validate>
56
+ <sort_order>50</sort_order>
57
+ <show_in_default>1</show_in_default>
58
+ <show_in_website>1</show_in_website>
59
+ <show_in_store>1</show_in_store>
60
+ </terms_and_conditions_url>
61
+ <color_theme translate="label,comment">
62
+ <label>Color theme</label>
63
+ <comment>The color theme of the checkout form</comment>
64
+ <frontend_type>select</frontend_type>
65
+ <sort_order>60</sort_order>
66
+ <source_model>checkout2/themes</source_model>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>0</show_in_website>
69
+ <show_in_store>1</show_in_store>
70
+ </color_theme>
71
+ <extra_verification translate="label,comment">
72
+ <label>Extra customer verification</label>
73
+ <comment>An extra customer verification method</comment>
74
+ <frontend_type>select</frontend_type>
75
+ <sort_order>70</sort_order>
76
+ <source_model>checkout2/verificationTypes</source_model>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>0</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ </extra_verification>
81
+ <request_phone translate="label,comment">
82
+ <label>Request phone</label>
83
+ <comment>Require user to fill in phone number</comment>
84
+ <frontend_type>select</frontend_type>
85
+ <source_model>adminhtml/system_config_source_yesno</source_model>
86
+ <sort_order>80</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>0</show_in_website>
89
+ <show_in_store>1</show_in_store>
90
+ </request_phone>
91
+ <restore_on_cancel translate="label,comment">
92
+ <label>Restore cart on cancel</label>
93
+ <comment>Restore cart when customer cancel the payment</comment>
94
+ <frontend_type>select</frontend_type>
95
+ <source_model>adminhtml/system_config_source_yesno</source_model>
96
+ <sort_order>90</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>1</show_in_store>
100
+ </restore_on_cancel>
101
+ <restore_on_error translate="label,comment">
102
+ <label>Restore cart on error</label>
103
+ <comment>Restore cart when status from Payson is error</comment>
104
+ <frontend_type>select</frontend_type>
105
+ <source_model>adminhtml/system_config_source_yesno</source_model>
106
+ <sort_order>100</sort_order>
107
+ <show_in_default>1</show_in_default>
108
+ <show_in_website>1</show_in_website>
109
+ <show_in_store>1</show_in_store>
110
+ </restore_on_error>
111
+ </fields>
112
+ </checkout2>
113
+ </groups>
114
+ </payment>
115
+ </sections>
116
+ </config>
app/code/community/Payson/Checkout2/sql/payson_checkout2_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN, array(
8
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
9
+ 'comment' => 'Payson Checkout ID',
10
+ 'length' => '255'
11
+ ));
12
+
13
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote'), Payson_Checkout2_Model_Order::CHECKOUT_ID_COLUMN, array(
14
+ 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
15
+ 'comment' => 'Payson Checkout ID',
16
+ 'length' => '255'
17
+ ));
18
+
19
+ $installer->endSetup();
app/code/community/Payson/Payson/Block/Form.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
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/standard_form.phtml');
7
+ parent::_construct();
8
+ }
9
+
10
+ }
11
+
app/code/community/Payson/Payson/Block/Order/Totals/Fee.php ADDED
@@ -0,0 +1,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 ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,1328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ include 'FundingConstraint.php';
4
+
5
+ class Payson_Payson_Helper_Api {
6
+ /*
7
+ * Constants
8
+ */
9
+
10
+ var $invoiceAmountMinLimit = 30;
11
+
12
+ const DEBUG_MODE = false;
13
+ const API_CALL_PAY = '%s://%sapi.payson.%s/%s/Pay/';
14
+ const API_CALL_VALIDATE = '%s://%sapi.payson.%s/%s/Validate/';
15
+ const API_CALL_PAYMENT_DETAILS = '%s://%sapi.payson.%s/%s/%sDetails/';
16
+ const API_CALL_PAYMENT_UPDATE = '%s://%sapi.payson.%s/%s/%sUpdate/';
17
+ const PAY_FORWARD_URL = '%s://%s%s.payson.%s/paySecure/';
18
+ const APPLICATION_ID = 'Magento';
19
+ const MODULE_NAME = 'Payson_AllinOne';
20
+ const MODULE_VERSION = '1.8.3.3';
21
+ const DEBUG_MODE_MAIL = 'testagent-checkout2@payson.se';
22
+ const DEBUG_MODE_AGENT_ID = '4';
23
+ const DEBUG_MODE_MD5 = '2acab30d-fe50-426f-90d7-8c60a7eb31d4';
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_DENIED = 'DENIED';
32
+ const STATUS_ABORTED = 'ABORTED';
33
+ const STATUS_CANCELED = 'CANCELED';
34
+ const STATUS_EXPIRED = 'EXPIRED';
35
+ const STATUS_REVERSALERROR = 'REVERSALERROR';
36
+ const PAYMENT_METHOD_BANK = 'BANK';
37
+ const PAYMENT_METHOD_CREDITCARD = 'CREDITCARD';
38
+ const PAYMENT_METHOD_INVOICE = 'INVOICE';
39
+ const PAYMENT_METHOD_SMS = 'SMS';
40
+ const GUARANTEE_STATUS_WAITINGFORSEND = 'WAITINGFORSEND';
41
+ const GUARANTEE_STATUS_WAITINGFORACCEPTANCE = 'WAITINGFORACCEPTANCE';
42
+ const GUARANTEE_STATUS_WAITINGFORRETURN = 'WAITINGFORRETURN';
43
+ const GUARANTEE_STATUS_WAITINGFORRETURNACCEPTANCE = 'WAITINGFORRETURNACCEPTANCE';
44
+ const GUARANTEE_STATUS_RETURNNOTACCEPTED = 'RETURNNOTACCEPTED';
45
+ const GUARANTEE_STATUS_NOTRECEIVED = 'NOTRECEIVED';
46
+ const GUARANTEE_STATUS_RETURNNOTRECEIVED = 'RETURNNOTRECEIVED';
47
+ const GUARANTEE_STATUS_MONEYRETURNEDTOSENDER = 'MONEYRETURNEDTOSENDER';
48
+ const GUARANTEE_STATUS_RETURNACCEPTED = 'RETURNACCEPTED';
49
+ const INVOICE_STATUS_PENDING = 'PENDING';
50
+ const INVOICE_STATUS_ORDERCREATED = 'ORDERCREATED';
51
+ const INVOICE_STATUS_ORDERCANCELLED = 'ORDERCANCELLED';
52
+ const INVOICE_STATUS_SHIPPED = 'SHIPPED';
53
+ const INVOICE_STATUS_DONE = 'DONE';
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
+ const GUARANTEE_REQUIRED = 'REQUIRED';
59
+ const GUARANTEE_OPTIONAL = 'OPTIONAL';
60
+ const GUARANTEE_NO = 'NO';
61
+
62
+ //const PMETHOD ='';
63
+
64
+ /*
65
+ * Private properties
66
+ */
67
+ private $discountType;
68
+ private $numberofItems;
69
+ private $discountVat = 0.0;
70
+ private $_order = null;
71
+ private $response;
72
+ private $order_discount_item = 0.0;
73
+ /* @var $_config Payson_Payson_Model_Config */
74
+ private $_config;
75
+ /* @var $_helper Payson_Payson_Helper_Data */
76
+ private $_helper;
77
+ private $_products = array();
78
+
79
+ /*
80
+ * Private methods
81
+ */
82
+
83
+ public function __construct() {
84
+ $this->_config = Mage::getModel('payson/config');
85
+ $this->_helper = Mage::helper('payson');
86
+ $this->_invoice = Mage::getModel('payson/method/invoice');
87
+ }
88
+
89
+ private function getHttpClient($url) {
90
+
91
+ $client = new Varien_Http_Client();
92
+
93
+ $client->setUri($url)
94
+ ->setMethod(Zend_Http_Client::POST)
95
+ ->setHeaders(array
96
+ (
97
+ 'PAYSON-SECURITY-USERID' => $this->_config->get('test_mode') ? self::DEBUG_MODE_AGENT_ID : $this->_config->Get('agent_id'),
98
+ 'PAYSON-SECURITY-PASSWORD' => $this->_config->get('test_mode') ? self::DEBUG_MODE_MD5 : $this->_config->Get('md5_key'),
99
+ 'PAYSON-APPLICATION-ID' => self::APPLICATION_ID,
100
+ 'PAYSON-MODULE-INFO' => self::MODULE_NAME . '|' . self::MODULE_VERSION . '|' . Mage::getVersion()
101
+ )
102
+ );
103
+
104
+ return $client->resetParameters();
105
+ }
106
+
107
+ private function setResponse(
108
+ Payson_Payson_Helper_Api_Response_Interface $response) {
109
+ $this->response = $response;
110
+
111
+ return $this;
112
+ }
113
+
114
+ //Private functions for Swedish discount and vat calculations
115
+ private function setAverageVat($vat) {
116
+ $this->discountVat = $vat;
117
+ }
118
+
119
+ private function getAverageVat() {
120
+ return $this->discountVat;
121
+ }
122
+
123
+ private function setDiscountType($type) {
124
+ $this->discountType = $type;
125
+ }
126
+
127
+ private function getDiscountType() {
128
+ return $this->discountType;
129
+ }
130
+
131
+ private function setNumberOfItems($items) {
132
+ $this->numberofItems = $items;
133
+ }
134
+
135
+ private function getNumberOfItems() {
136
+ return $this->numberofItems;
137
+ }
138
+
139
+ private function getStoreCountry() {
140
+ $countryCode = Mage::getStoreConfig('general/country/default');
141
+ $country = Mage::getModel('directory/country')->loadByCode($countryCode);
142
+ return $country->country_id;
143
+ }
144
+
145
+ private function setSwedishDiscountItem($item, &$total, $orderitems, $order) {
146
+
147
+ /*
148
+ * Discount types $item->getAppliedRuleIds():
149
+ * Fixed discount amount for the entire cart
150
+ * Precentage discount for the entire cart
151
+ * Fixed discount amount for each article in cart
152
+ */
153
+ $rule = Mage::getModel('salesrule/rule')->load($item->getAppliedRuleIds());
154
+ $total -= $item->getDiscountAmount();
155
+ $numberOfItem = floor($order->getData('total_qty_ordered'));
156
+ $items = 0;
157
+
158
+ $discountAmount = $item->getDiscountAmount();
159
+ for ($i = 0; $i <= $numberOfItem; $i++) {
160
+ $orderVat = $orderitems['orderItemList.orderItem(' . $i . ').taxPercentage'];
161
+ $moms += $orderVat;
162
+ //counting number of tax rows that is not zero
163
+ if ($orderVat != 0) {
164
+ $items++;
165
+ }
166
+ }
167
+ $this->setNumberOfItems($numberOfItem);
168
+ $this->setDiscountType($rule->simple_action);
169
+ $totalMoms = $moms / $items;
170
+
171
+ $this->setAverageVat($totalMoms);
172
+
173
+ $this->order_discount_item += $discountAmount;
174
+ }
175
+
176
+ private function setInternationalDiscountItem($item, &$total) {
177
+ $total -= $item->getDiscountAmount();
178
+ $this->order_discount_item += $item->getDiscountAmount();
179
+ }
180
+
181
+ /**
182
+ * Helper for Pay()
183
+ *
184
+ * @param Mage_Sales_Model_Order_Item $item
185
+ * @param int $total
186
+ * @return array
187
+ */
188
+ private function getProductOptions($id) {
189
+ $product = new Mage_Catalog_Model_Product();
190
+ $product->load($id);
191
+ $product->getTypeInstance(true)->setStoreFilter(Mage::app()->getStore(), $product);
192
+ return $product;
193
+
194
+ }
195
+ private function prepareOrderItemData($item, &$total, $order) {
196
+ /* @var $product Mage_Catalog_Model_Product */
197
+ $product = Mage::getModel('catalog/product')
198
+ ->load($item->getProductId());
199
+
200
+ $attributesString = "";
201
+ $quoteItems = Mage::getModel('sales/quote_item')->getCollection();
202
+ $quoteItems->addFieldToFilter('quote_id', $order->quote_id);
203
+ $quoteItems->addFieldToFilter('product_type', 'bundle');
204
+
205
+
206
+ if (($children = $item->getChildrenItems()) != null && !$product->isConfigurable()) {
207
+ $args = array();
208
+ $product = $this->getProductOptions($item->getProductId());
209
+
210
+ if ($item->getProductType() != 'bundle'||$product->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
211
+ $this->prepareProductData($item->getName(), $item->getSku(), $item->getQtyOrdered(), 0, 0);
212
+ }
213
+ foreach ($children as $child) {
214
+ $this->prepareOrderItemData($child, $total, $order);
215
+ }
216
+ //checks if there are bundles items is present and if it is dynamic
217
+ if (($quoteItems->getSize() < 1)) {
218
+ return;
219
+ } elseif ($product->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC && $item->getProductType() == 'bundle') {
220
+ return;
221
+ }
222
+ }
223
+
224
+ $productOptions = $item->getProductOptions();
225
+
226
+ if (array_key_exists('attributes_info', $productOptions)) {
227
+ foreach ($productOptions['attributes_info'] as $attribute) {
228
+ $attributesString .= $attribute['label'] . ": " . $attribute['value'] . ", ";
229
+ }
230
+
231
+ if ($attributesString != "") {
232
+ $attributesString = substr($attributesString, 0, strlen($attributesString) - 2);
233
+ }
234
+ }
235
+
236
+ $name = $item->getName() . ($attributesString != "" ? " - " . $attributesString : "");
237
+ $sku = $item->getSku();
238
+ $tax_mod = (float) $item->getTaxPercent();
239
+ $tax_mod /= 100;
240
+ $tax_mod = round($tax_mod, 5);
241
+
242
+ $qty = (float) $item->getQtyOrdered();
243
+ $qty = round($qty, 2);
244
+
245
+ $price = (float) $item->getRowTotalInclTax();
246
+
247
+ $base_price = (($price / (1 + $tax_mod)) / $qty);
248
+ $base_price = round($base_price, 3);
249
+
250
+ $total += (($base_price * (1 + $tax_mod)) * $qty);
251
+
252
+ $this->prepareProductData($name, $sku, $qty, $base_price, $tax_mod);
253
+ }
254
+
255
+ private function generateProductDataForPayson(array $args) {
256
+ $productData = array();
257
+ for ($i = 0; $i < sizeof($this->_products); $i++) {
258
+ $productData += array
259
+ (
260
+ 'orderItemList.orderItem(' . $i . ').description' =>
261
+ $this->_products[$i]['Description'],
262
+ 'orderItemList.orderItem(' . $i . ').sku' =>
263
+ $this->_products[$i]['Sku'],
264
+ 'orderItemList.orderItem(' . $i . ').quantity' =>
265
+ $this->_products[$i]['Quantity'],
266
+ 'orderItemList.orderItem(' . $i . ').unitPrice' =>
267
+ $this->_products[$i]['Price'],
268
+ 'orderItemList.orderItem(' . $i . ').taxPercentage' =>
269
+ $this->_products[$i]['Tax']
270
+ );
271
+ $args += $productData;
272
+ }
273
+
274
+ return $args;
275
+ }
276
+
277
+ private function prepareProductData($description, $sku, $qty, $base_price, $tax_mod) {
278
+ $description = strlen($description) <= 128 ? $description : substr($description, 128);
279
+ $sku = strlen($sku) <= 128 ? $sku : substr($sku, 128);
280
+ $this->_products[] = array("Description" => $description, "Sku" => $sku,
281
+ "Quantity" => $qty, "Price" => $base_price, "Tax" => $tax_mod);
282
+ }
283
+
284
+ /**
285
+ * Helper for Pay()
286
+ *
287
+ * @param object $order
288
+ * @param object $customer
289
+ * @param object $store
290
+ * @param int $i
291
+ * @param int $total
292
+ */
293
+ private function prepareOrderShippingData($order, $customer, $store, &$total) {
294
+ $tax_calc = Mage::getSingleton('tax/calculation');
295
+
296
+ $tax_rate_req = $tax_calc->getRateRequest(
297
+ $order->getShippingAddress(), $order->getBillingAddress(), $customer->getTaxClassId(), $store);
298
+
299
+ if (($price = (float) $order->getShippingInclTax()) > 0) {
300
+ $tax_mod = $tax_calc->getRate($tax_rate_req->setProductClassId(
301
+ Mage::getStoreConfig('tax/classes/shipping_tax_class')));
302
+ $tax_mod /= 100;
303
+ $tax_mod = round($tax_mod, 5);
304
+
305
+ $price -= (float) $order->getShippingDiscountAmount();
306
+
307
+ $base_price = ($price / (1 + $tax_mod));
308
+ $base_price = round($base_price, 3);
309
+
310
+ $total += ($base_price * (1 + $tax_mod));
311
+
312
+ $this->prepareProductData($order->getShippingDescription(), $order->getShippingMethod(), 1, $base_price, $tax_mod);
313
+ }
314
+ }
315
+
316
+ /*
317
+ * Public methods
318
+ */
319
+
320
+ /**
321
+ * Get API response
322
+ *
323
+ * @return object
324
+ */
325
+ public function GetResponse() {
326
+ return $this->response;
327
+ }
328
+
329
+ /**
330
+ * Get forward/redirect url after a successful Pay() call
331
+ *
332
+ * @return string
333
+ */
334
+ public function GetPayForwardUrl() {
335
+ $url = vsprintf(self::PAY_FORWARD_URL . '?token=' . $this->GetResponse()->TOKEN, $this->getFormatIfTest(null, true));
336
+ return $url;
337
+ }
338
+
339
+ /**
340
+ * http://api.payson.se/#title8
341
+ *
342
+ * @param object $order
343
+ * @return object
344
+ */
345
+ public function showReceiptPage() {
346
+ $Config = (int) $this->_config->get('show_receipt_page');
347
+ $reciept2 = 'false';
348
+ if ($Config === 1) {
349
+ $reciept2 = 'true';
350
+ }
351
+ return $reciept2;
352
+ }
353
+
354
+ public function vatDiscount() {
355
+ $inputValue = (int) $this->_config->Get('vat_discount');
356
+ $enableVatDiscount = 'false';
357
+ if ($inputValue === 1) {
358
+ $enableVatDiscount = 'true';
359
+ }
360
+ return $enableVatDiscount;
361
+ }
362
+
363
+ public function Pay(Mage_Sales_Model_Order $order) {
364
+
365
+ $payment_method = $order->getPayment()->getMethod();
366
+
367
+ /* @var $store Mage_Core_Model_Store */
368
+ $store = Mage::app()->getStore($order->getStoreId());
369
+ $customer = Mage::getModel('customer/customer')
370
+ ->load($order->getCustomerId());
371
+ $billing_address = $order->getBillingAddress();
372
+
373
+ // Need a two character locale code. This collects the store chosen language
374
+ $locale_code = Mage::getSingleton('core/locale')->getLocaleCode();
375
+ $locale_code = strtoupper(substr($locale_code, 0, 2));
376
+
377
+
378
+ if (!in_array($locale_code, array('SV', 'FI', 'EN'))) {
379
+ switch ($locale_code) {
380
+ case 'DA':
381
+ case 'NO': {
382
+ $locale_code = 'SV';
383
+ break;
384
+ }
385
+ default: {
386
+ $locale_code = 'EN';
387
+ }
388
+ }
389
+ }
390
+
391
+ // $args will contain the arguments of the API request to Payson
392
+ $args = array
393
+ (
394
+ 'returnUrl' =>
395
+ Mage::getUrl('payson/checkout/return', array('_secure' => true)),
396
+ 'cancelUrl' =>
397
+ Mage::getUrl('payson/checkout/cancel', array('_secure' => true)),
398
+ 'ipnNotificationUrl' =>
399
+ Mage::getUrl('payson/ipn/notify', array('_secure' => true)),
400
+ 'localeCode' =>
401
+ $locale_code,
402
+ 'currencyCode' =>
403
+ strtoupper(substr($order->getOrderCurrency()->getCode(), 0, 3)),
404
+ 'memo' =>
405
+ sprintf($this->_helper->__('Order from %s'), $store->getName()),
406
+ 'senderEmail' =>
407
+ $order->getCustomerEmail(),
408
+ 'senderFirstName' =>
409
+ $billing_address->getFirstname(),
410
+ 'senderLastName' =>
411
+ $billing_address->getLastname(),
412
+ 'receiverList.receiver(0).email' =>
413
+ $this->_config->get('test_mode') ? self::DEBUG_MODE_MAIL : $this->_config->Get('email'),
414
+ 'trackingId' => $order->getRealOrderId(),
415
+ 'showReceiptPage' => $this->showReceiptPage()
416
+ );
417
+
418
+ if (!$this->_config->CanPaymentGuarantee()) {
419
+ $args['guaranteeOffered'] = self::GUARANTEE_NO;
420
+ }
421
+ $isCurrency = strtoupper(Mage::app()->getStore()->getCurrentCurrencyCode());
422
+ $paymentMethod = $this->_config->get('payson_All_in_one');
423
+ //Get Payson paymentmethod
424
+ //Direct Payment
425
+ if ($this->_config->CanStandardPayment() && $isCurrency == 'SEK') {
426
+ $payment = $this->getConstrains($paymentMethod);
427
+ }
428
+ //InvoicePayment with check if invoice amount is above minimum
429
+ if ($this->_config->CanInvoicePayment() && ($order->getSubtotal() >= $this->invoiceAmountMinLimit) && ($isCurrency == 'SEK')) {
430
+ $payment = $this->getConstrains($paymentMethod);
431
+ }
432
+ //Remove invoice if invoice amount is below minimum amount
433
+ if ($this->_config->CanInvoicePayment() && ($order->getSubtotal() < $this->invoiceAmountMinLimit) && ($isCurrency == 'SEK')) {
434
+ $disableInvoice = true;
435
+ $payment = $this->getConstrains($paymentMethod);
436
+ if (in_array(3, $payment)) {
437
+ $newArray = array();
438
+ foreach ($payment as $pkey) {
439
+ if ($pkey != 3)
440
+ $newArray[] = $pkey;
441
+ }
442
+ $payment = $newArray;
443
+ }
444
+ }
445
+ //If other currency than SEK remove payment option Invocie and SMS
446
+ if (($this->_config->CanInvoicePayment() || $this->_config->CanStandardPayment()) && ($isCurrency != 'SEK')) {
447
+ $payment = $this->getConstrains($paymentMethod);
448
+ //Remove Invoice from array
449
+ if (in_array(3, $payment)) {
450
+ $disableInvoice = true;
451
+ $newArray = array();
452
+ foreach ($payment as $pkey) {
453
+ if ($pkey != 3) {
454
+ $newArray[] = $pkey;
455
+ }
456
+ }
457
+ $payment = $newArray;
458
+ }
459
+ //Remove SMS from array
460
+ if (in_array(4, $payment)) {
461
+ $newArray = array();
462
+ foreach ($payment as $pkey) {
463
+ if ($pkey != 4) {
464
+ $newArray[] = $pkey;
465
+ }
466
+ }
467
+ $payment = $newArray;
468
+ }
469
+ }
470
+
471
+ $result = (!isset($payment)) ? $payment = '' : $payment;
472
+
473
+ define("PMETHOD", serialize($result));
474
+ $output = array();
475
+ FundingConstraint::addConstraintsToOutput($result, $output);
476
+ $args = array_merge($args, $output);
477
+
478
+ // Calculate price of each item in the order
479
+ $total = 0;
480
+ foreach ($order->getAllVisibleItems() as $item) {
481
+ $this->prepareOrderItemData($item, $total, $order);
482
+ }
483
+
484
+ $productItems = $this->generateProductDataForPayson($args);
485
+ $customerCountry = $order->getBillingAddress()->country_id;
486
+ if ($this->getStoreCountry() == 'SE' && $customerCountry == 'SE' && $this->vatDiscount() == 'true') {
487
+
488
+ foreach ($order->getAllVisibleItems() as $item) {
489
+ $this->setSwedishDiscountItem($item, $total, $productItems, $order);
490
+ }
491
+ if ($this->order_discount_item > 0) {
492
+ switch ($this->getDiscountType()) {
493
+ case Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION:
494
+ case Mage_SalesRule_Model_Rule::TO_PERCENT_ACTION:
495
+ $this->prepareProductData('Rabatt inkl moms', 'Rabatt', 1, -$this->order_discount_item, $this->getAverageVat());
496
+ break;
497
+ case Mage_SalesRule_Model_Rule::BY_FIXED_ACTION:
498
+ $specialDiscount = $this->order_discount_item / $this->getNumberOfItems();
499
+ $this->prepareProductData('Rabatt inkl moms', 'Rabatt', $this->getNumberOfItems(), -$specialDiscount, $this->getAverageVat());
500
+ break;
501
+ default:
502
+ $this->prepareProductData('Rabatt inkl moms', 'Rabatt', 1, -$this->order_discount_item, $this->getAverageVat());
503
+ break;
504
+ }
505
+ }
506
+ } else {
507
+
508
+ foreach ($order->getAllVisibleItems() as $item) {
509
+ $this->setInternationalDiscountItem($item, $total);
510
+ }
511
+
512
+ if ($this->order_discount_item > 0) {
513
+ $this->prepareProductData('discount', 'discount', 1, -$this->order_discount_item, 0.0);
514
+ }
515
+ }
516
+ //
517
+
518
+ // Calculate price for shipping
519
+ $this->prepareOrderShippingData($order, $customer, $store, $total);
520
+ $args = $this->generateProductDataForPayson($args);
521
+
522
+ if ($this->_config->CanInvoicePayment() && ($order->getSubtotal() >= $this->invoiceAmountMinLimit) && !$disableInvoice) {
523
+
524
+ if ($order->getPaysonInvoiceFee() > 0) {
525
+
526
+ $fee = $order->getPaysonInvoiceFee();
527
+
528
+ $args['invoiceFee'] = round((float) $fee, 3);
529
+ $total += $fee;
530
+ }
531
+ }
532
+ $roundedTotal = round($total, 2);
533
+ if ($this->getStoreCountry() == 'SE' && $customerCountry == 'SE' && $this->vatDiscount() == 'true') {
534
+ if ($this->order_discount_item > 0) {
535
+ switch ($this->getDiscountType()) {
536
+ case Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION:
537
+ case Mage_SalesRule_Model_Rule::TO_PERCENT_ACTION:
538
+ case Mage_SalesRule_Model_Rule::BY_FIXED_ACTION:
539
+ case Mage_SalesRule_Model_Rule::CART_FIXED_ACTION:
540
+ $roundedTotal = $roundedTotal - ($this->order_discount_item * $this->getAverageVat());
541
+ break;
542
+
543
+ default:
544
+ break;
545
+ }
546
+ }
547
+ }
548
+ $args['receiverList.receiver(0).amount'] = $roundedTotal;
549
+
550
+ $url = vsprintf(self::API_CALL_PAY, $this->getFormatIfTest($order->getStoreId()));
551
+
552
+ $client = $this->getHttpClient($url)
553
+ ->setParameterPost($args);
554
+
555
+ $response = Payson_Payson_Helper_Api_Response_Standard
556
+ ::FromHttpBody($client->request('POST')->getBody());
557
+ $this->setResponse($response);
558
+
559
+
560
+ $resource = Mage::getSingleton('core/resource');
561
+ $db = $resource->getConnection('core_write');
562
+
563
+ $order_table = $resource->getTableName('payson_order');
564
+ $order_log_table = $resource->getTableName('payson_order_log');
565
+
566
+ $db->insert($order_table, array
567
+ (
568
+ 'order_id' => $order->getRealOrderId(),
569
+ 'added' => new Zend_Db_Expr('NOW()'),
570
+ 'updated' => new Zend_Db_Expr('NOW()'),
571
+ 'valid' => (int) $response->IsValid(),
572
+ 'token' => (isset($response->TOKEN) ? $response->TOKEN :
573
+ new Zend_Db_Expr('NULL')),
574
+ 'store_id' => $order->getStoreId()
575
+ ));
576
+
577
+ $payson_order_id = $db->lastInsertId();
578
+
579
+ $db->insert($order_log_table, array
580
+ (
581
+ 'payson_order_id' => $payson_order_id,
582
+ 'added' => new Zend_Db_Expr('NOW()'),
583
+ 'api_call' => 'pay',
584
+ 'valid' => (int) $response->IsValid(),
585
+ 'response' => serialize($response->ToArray())
586
+ ));
587
+
588
+ if (!$response->IsValid()) {
589
+
590
+ throw new Mage_Core_Exception(sprintf($this->_helper->__(
591
+ 'Failed to initialize payment. Payson replied: %s'), $response->GetError()), $response->GetErrorId());
592
+ }
593
+
594
+ return $this;
595
+ }
596
+
597
+ public function PaymentMethod() {
598
+
599
+ }
600
+
601
+ private function getConstrains($paymentMethod) {
602
+
603
+ $constraints = array();
604
+ $opts = array(
605
+ -1 => array(''),
606
+ 0 => array('sms'),
607
+ 1 => array('bank'),
608
+ 2 => array('card'),
609
+ 3 => array('bank', 'sms'),
610
+ 4 => array('card', 'sms'),
611
+ 5 => array('card', 'bank'),
612
+ 6 => array('card', 'bank', 'sms'),
613
+ 7 => array(''),
614
+ 8 => array('invoice'),
615
+ 9 => array('invoice', 'sms'),
616
+ 10 => array('invoice', 'bank'),
617
+ 11 => array('invoice', 'card'),
618
+ 12 => array('invoice', 'bank', 'sms'),
619
+ 13 => array('invoice', 'card', 'sms'),
620
+ 14 => array('invoice', 'card', 'bank'),
621
+ 15 => array('invoice', 'card', 'bank', 'sms'),
622
+ );
623
+ $optsStrings = array('' => FundingConstraint::NONE, 'bank' => FundingConstraint::BANK, 'card' => FundingConstraint::CREDITCARD, 'invoice' => FundingConstraint::INVOICE, 'sms' => FundingConstraint::SMS);
624
+ if ($opts[$paymentMethod]) {
625
+ foreach ($opts[$paymentMethod] as $methodStringName) {
626
+ $constraints[] = $optsStrings[$methodStringName];
627
+ }
628
+ }
629
+ return $constraints;
630
+ }
631
+
632
+ /**
633
+ * Implements the IPN procedure
634
+ *
635
+ * http://api.payson.se/#title11
636
+ *
637
+ * @param string $http_body
638
+ * @param string $content_type
639
+ * @return object $this
640
+ */
641
+ public function confirmationEmail($entityId) {
642
+ $resource = Mage::getSingleton('core/resource');
643
+ $db = $resource->getConnection('core_write');
644
+ $order_table = $resource->getTableName('sales_flat_order');
645
+ $status = $db->fetchRow(
646
+ 'SELECT status FROM `' . $order_table . '` WHERE
647
+ entity_id = ? LIMIT 0,1', $entityId);
648
+
649
+ return $status;
650
+ }
651
+
652
+ public function Validate($http_body, $content_type) {
653
+
654
+ // Parse request done by Payson to our IPN controller
655
+ $ipn_response = Payson_Payson_Helper_Api_Response_Standard
656
+ ::FromHttpBody($http_body);
657
+ // Get the database connection
658
+ $resource = Mage::getSingleton('core/resource');
659
+ $db = $resource->getConnection('core_write');
660
+
661
+ $order_table = $resource->getTableName('payson_order');
662
+ $order_log_table = $resource->getTableName('payson_order_log');
663
+
664
+
665
+ /* Save data sent by Payson, log entry as invalid by default, this
666
+ value will be changed later in this method if successful. No payson
667
+ order id is set, because we dont have one yet */
668
+ $db->insert($order_log_table, array
669
+ (
670
+ 'added' => new Zend_Db_Expr('NOW()'),
671
+ 'api_call' => 'validate',
672
+ 'valid' => 0,
673
+ 'response' => serialize($ipn_response->ToArray())
674
+ ));
675
+
676
+ $order_log_id = $db->lastInsertId();
677
+
678
+ /* Save fetch mode so that we can reset it and not mess up Magento
679
+ functionality */
680
+ $old_fetch_mode = $db->getFetchMode();
681
+ $db->setFetchMode(Zend_Db::FETCH_OBJ);
682
+
683
+ // Get payson order information and validate token
684
+ $payson_order = $db->fetchRow(
685
+ 'SELECT
686
+ id,
687
+ order_id,
688
+ store_id
689
+ FROM
690
+ `' . $order_table . '`
691
+ WHERE
692
+ valid = 1
693
+ AND
694
+ token = ?
695
+ LIMIT
696
+ 0,1', $ipn_response->token);
697
+
698
+ if ($payson_order === false) {
699
+ Mage::throwException('Invalid token');
700
+ }
701
+
702
+ // Do the validate API call
703
+ $client = $this->getHttpClient(vsprintf(self::API_CALL_VALIDATE, $this->getFormatIfTest($payson_order->store_id)))
704
+ ->setRawData($http_body, $content_type);
705
+
706
+ $response = Payson_Payson_Helper_Api_Response_Validate
707
+ ::FromHttpBody($client->request('POST')->getBody());
708
+
709
+ $this->setResponse($response);
710
+
711
+ if (!$response->IsValid()) {
712
+ Mage::throwException('Validate call was unsuccessful');
713
+ }
714
+
715
+
716
+
717
+ // Update order log with payson order id
718
+ $db->update($order_log_table, array
719
+ (
720
+ 'payson_order_id' => $payson_order->id
721
+ ), array
722
+ (
723
+ 'id = ?' => $order_log_id
724
+ ));
725
+
726
+ // the order model does not expect FETCH_OBJ!
727
+ $db->setFetchMode($old_fetch_mode);
728
+
729
+ /**
730
+ * @var Mage_Sales_Model_Order
731
+ */
732
+ $order = Mage::getModel('sales/order')
733
+ ->loadByIncrementId($payson_order->order_id);
734
+
735
+ // Stop if order dont exist
736
+ if (is_null($order->getId())) {
737
+ Mage::throwException('Invalid order');
738
+ }
739
+
740
+ if ($order->getState() === Mage_Sales_Model_Order::STATE_COMPLETE) {
741
+ Mage::throwException('Order is no longer active');
742
+ }
743
+ $sendEmail = $this->confirmationEmail($order->getEntityId());
744
+ $receivers = $ipn_response->receiverList->receiver->ToArray();
745
+ $investigatefee = $order['base_payson_invoice_fee'];
746
+
747
+ $new_receivers = array();
748
+ foreach ($receivers as $item) {
749
+ foreach ($item as $key => $value) {
750
+ $new_receivers[$key] = $value;
751
+ }
752
+ }
753
+ $currentAmount = $new_receivers['amount'];
754
+ $newAmount = $currentAmount += $investigatefee;
755
+
756
+ /* Verify payment amount. floor() since there might be a precision
757
+ difference */
758
+ switch ($ipn_response->status) {
759
+ case self::STATUS_COMPLETED: {
760
+ //Changes the status of the order from pending_payment to processing
761
+ if ($sendEmail['status'] == 'pending_payment') {
762
+ $order->sendNewOrderEmail()->save();
763
+ }
764
+ $order->setState(
765
+ Mage_Sales_Model_Order::STATE_PROCESSING, Mage_Sales_Model_Order::STATE_PROCESSING, $this->_config->get('test_mode') ? $this->_helper->__('Payson test completed the order payment') : $this->_helper->__('Payson completed the order payment'));
766
+ $order['payson_invoice_fee'] = 0;
767
+ $order['base_payson_invoice_fee'] = 0;
768
+ //It creates the invoice to the order
769
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
770
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
771
+ $invoice->register();
772
+ $transactionSave = Mage::getModel('core/resource_transaction')
773
+ ->addObject($invoice)
774
+ ->addObject($invoice->getOrder());
775
+ $transactionSave->save();
776
+
777
+ break;
778
+ }
779
+ case self::STATUS_CREATED:
780
+ case self::STATUS_PENDING:
781
+ case self::STATUS_PROCESSING:
782
+ case self::STATUS_CREDITED: {
783
+ if (($ipn_response->status === self::STATUS_PENDING) &&
784
+ ($ipn_response->type === self::PAYMENT_METHOD_INVOICE) &&
785
+ ($ipn_response->invoiceStatus ===
786
+ self::INVOICE_STATUS_ORDERCREATED)) {
787
+ if ($sendEmail['status'] == 'pending_payment') {
788
+ $order->sendNewOrderEmail()->save();
789
+ }
790
+ //Changes the status of the order from pending to processing
791
+ $order->setState(
792
+ Mage_Sales_Model_Order::STATE_PROCESSING, Mage_Sales_Model_Order::STATE_PROCESSING, $this->_config->get('test_mode') ? $this->_helper->__('Payson test created an invoice') : $this->_helper->__('Payson created an invoice'));
793
+ $order->setBaseGrandTotal($newAmount);
794
+ $order->setGrandTotal($newAmount);
795
+ $order->setTotalDue($newAmount);
796
+ $order->save();
797
+
798
+
799
+ if (isset($ipn_response->shippingAddress)) {
800
+ $address_info = $ipn_response->shippingAddress
801
+ ->ToArray();
802
+
803
+ $address = $order->getShippingAddress();
804
+
805
+ if (isset($address_info['name'])) {
806
+ $address->setFirstname($address_info['name']);
807
+ $address->setMiddlename('');
808
+ $address->setLastname('');
809
+ }
810
+
811
+ if (isset($address_info['streetAddress'])) {
812
+ $address->setStreet($address_info['streetAddress']);
813
+ }
814
+
815
+ if (isset($address_info['postalCode'])) {
816
+ $address->setPostcode($address_info['streetAddress']);
817
+ }
818
+
819
+ if (isset($address_info['city'])) {
820
+ $address->setCity($address_info['city']);
821
+ }
822
+
823
+ if (isset($address_info['country'])) {
824
+
825
+ $foo = array
826
+ (
827
+ 'afghanistan' => 'AF',
828
+ 'albania' => 'AL',
829
+ 'algeria' => 'DZ',
830
+ 'american samoa' => 'AS',
831
+ 'andorra' => 'AD',
832
+ 'angola' => 'AO',
833
+ 'anguilla' => 'AI',
834
+ 'antarctica' => 'AQ',
835
+ 'antigua and barbuda' => 'AG',
836
+ 'argentina' => 'AR',
837
+ 'armenia' => 'AM',
838
+ 'aruba' => 'AW',
839
+ 'australia' => 'AU',
840
+ 'austria' => 'AT',
841
+ 'azerbaijan' => 'AZ',
842
+ 'bahamas' => 'BS',
843
+ 'bahrain' => 'BH',
844
+ 'bangladesh' => 'BD',
845
+ 'barbados' => 'BB',
846
+ 'belarus' => 'BY',
847
+ 'belgium' => 'BE',
848
+ 'belize' => 'BZ',
849
+ 'benin' => 'BJ',
850
+ 'bermuda' => 'BM',
851
+ 'bhutan' => 'BT',
852
+ 'bolivia' => 'BO',
853
+ 'bosnia and herzegovina' => 'BA',
854
+ 'botswana' => 'BW',
855
+ 'bouvet island' => 'BV',
856
+ 'brazil' => 'BR',
857
+ 'british indian ocean territory' => 'IO',
858
+ 'brunei darussalam' => 'BN',
859
+ 'bulgaria' => 'BG',
860
+ 'burkina faso' => 'BF',
861
+ 'burundi' => 'BI',
862
+ 'cambodia' => 'KH',
863
+ 'cameroon' => 'CM',
864
+ 'canada' => 'CA',
865
+ 'cape verde' => 'CV',
866
+ 'cayman islands' => 'KY',
867
+ 'central african republic' => 'CF',
868
+ 'chad' => 'TD',
869
+ 'chile' => 'CL',
870
+ 'china' => 'CN',
871
+ 'christmas island' => 'CX',
872
+ 'cocos (keeling) islands' => 'CC',
873
+ 'colombia' => 'CO',
874
+ 'comoros' => 'KM',
875
+ 'congo' => 'CG',
876
+ 'congo, the democratic republic of the' => 'CD',
877
+ 'cook islands' => 'CK',
878
+ 'costa rica' => 'CR',
879
+ 'cote d ivoire' => 'CI',
880
+ 'croatia' => 'HR',
881
+ 'cuba' => 'CU',
882
+ 'cyprus' => 'CY',
883
+ 'czech republic' => 'CZ',
884
+ 'denmark' => 'DK',
885
+ 'djibouti' => 'DJ',
886
+ 'dominica' => 'DM',
887
+ 'dominican republic' => 'DO',
888
+ 'east timor' => 'TP',
889
+ 'ecuador' => 'EC',
890
+ 'egypt' => 'EG',
891
+ 'el salvador' => 'SV',
892
+ 'equatorial guinea' => 'GQ',
893
+ 'eritrea' => 'ER',
894
+ 'estonia' => 'EE',
895
+ 'ethiopia' => 'ET',
896
+ 'falkland islands (malvinas)' => 'FK',
897
+ 'faroe islands' => 'FO',
898
+ 'fiji' => 'FJ',
899
+ 'finland' => 'FI',
900
+ 'france' => 'FR',
901
+ 'french guiana' => 'GF',
902
+ 'french polynesia' => 'PF',
903
+ 'french southern territories' => 'TF',
904
+ 'gabon' => 'GA',
905
+ 'gambia' => 'GM',
906
+ 'georgia' => 'GE',
907
+ 'germany' => 'DE',
908
+ 'ghana' => 'GH',
909
+ 'gibraltar' => 'GI',
910
+ 'greece' => 'GR',
911
+ 'greenland' => 'GL',
912
+ 'grenada' => 'GD',
913
+ 'guadeloupe' => 'GP',
914
+ 'guam' => 'GU',
915
+ 'guatemala' => 'GT',
916
+ 'guinea' => 'GN',
917
+ 'guinea-bissau' => 'GW',
918
+ 'guyana' => 'GY',
919
+ 'haiti' => 'HT',
920
+ 'heard island and mcdonald islands' => 'HM',
921
+ 'holy see (vatican city state)' => 'VA',
922
+ 'honduras' => 'HN',
923
+ 'hong kong' => 'HK',
924
+ 'hungary' => 'HU',
925
+ 'iceland' => 'IS',
926
+ 'india' => 'IN',
927
+ 'indonesia' => 'ID',
928
+ 'iran, islamic republic of' => 'IR',
929
+ 'iraq' => 'IQ',
930
+ 'ireland' => 'IE',
931
+ 'israel' => 'IL',
932
+ 'italy' => 'IT',
933
+ 'jamaica' => 'JM',
934
+ 'japan' => 'JP',
935
+ 'jordan' => 'JO',
936
+ 'kazakstan' => 'KZ',
937
+ 'kenya' => 'KE',
938
+ 'kiribati' => 'KI',
939
+ 'korea democratic peoples republic of' => 'KP',
940
+ 'korea republic of' => 'KR',
941
+ 'kuwait' => 'KW',
942
+ 'kyrgyzstan' => 'KG',
943
+ 'lao peoples democratic republic' => 'LA',
944
+ 'latvia' => 'LV',
945
+ 'lebanon' => 'LB',
946
+ 'lesotho' => 'LS',
947
+ 'liberia' => 'LR',
948
+ 'libyan arab jamahiriya' => 'LY',
949
+ 'liechtenstein' => 'LI',
950
+ 'lithuania' => 'LT',
951
+ 'luxembourg' => 'LU',
952
+ 'macau' => 'MO',
953
+ 'macedonia, the former yugoslav republic of' => 'MK',
954
+ 'madagascar' => 'MG',
955
+ 'malawi' => 'MW',
956
+ 'malaysia' => 'MY',
957
+ 'maldives' => 'MV',
958
+ 'mali' => 'ML',
959
+ 'malta' => 'MT',
960
+ 'marshall islands' => 'MH',
961
+ 'martinique' => 'MQ',
962
+ 'mauritania' => 'MR',
963
+ 'mauritius' => 'MU',
964
+ 'mayotte' => 'YT',
965
+ 'mexico' => 'MX',
966
+ 'micronesia, federated states of' => 'FM',
967
+ 'moldova, republic of' => 'MD',
968
+ 'monaco' => 'MC',
969
+ 'mongolia' => 'MN',
970
+ 'montserrat' => 'MS',
971
+ 'morocco' => 'MA',
972
+ 'mozambique' => 'MZ',
973
+ 'myanmar' => 'MM',
974
+ 'namibia' => 'NA',
975
+ 'nauru' => 'NR',
976
+ 'nepal' => 'NP',
977
+ 'netherlands' => 'NL',
978
+ 'netherlands antilles' => 'AN',
979
+ 'new caledonia' => 'NC',
980
+ 'new zealand' => 'NZ',
981
+ 'nicaragua' => 'NI',
982
+ 'niger' => 'NE',
983
+ 'nigeria' => 'NG',
984
+ 'niue' => 'NU',
985
+ 'norfolk island' => 'NF',
986
+ 'northern mariana islands' => 'MP',
987
+ 'norway' => 'NO',
988
+ 'oman' => 'OM',
989
+ 'pakistan' => 'PK',
990
+ 'palau' => 'PW',
991
+ 'palestinian territory, occupied' => 'PS',
992
+ 'panama' => 'PA',
993
+ 'papua new guinea' => 'PG',
994
+ 'paraguay' => 'PY',
995
+ 'peru' => 'PE',
996
+ 'philippines' => 'PH',
997
+ 'pitcairn' => 'PN',
998
+ 'poland' => 'PL',
999
+ 'portugal' => 'PT',
1000
+ 'puerto rico' => 'PR',
1001
+ 'qatar' => 'QA',
1002
+ 'reunion' => 'RE',
1003
+ 'romania' => 'RO',
1004
+ 'russian federation' => 'RU',
1005
+ 'rwanda' => 'RW',
1006
+ 'saint helena' => 'SH',
1007
+ 'saint kitts and nevis' => 'KN',
1008
+ 'saint lucia' => 'LC',
1009
+ 'saint pierre and miquelon' => 'PM',
1010
+ 'saint vincent and the grenadines' => 'VC',
1011
+ 'samoa' => 'WS',
1012
+ 'san marino' => 'SM',
1013
+ 'sao tome and principe' => 'ST',
1014
+ 'saudi arabia' => 'SA',
1015
+ 'senegal' => 'SN',
1016
+ 'seychelles' => 'SC',
1017
+ 'sierra leone' => 'SL',
1018
+ 'singapore' => 'SG',
1019
+ 'slovakia' => 'SK',
1020
+ 'slovenia' => 'SI',
1021
+ 'solomon islands' => 'SB',
1022
+ 'somalia' => 'SO',
1023
+ 'south africa' => 'ZA',
1024
+ 'south georgia and the south sandwich islands' => 'GS',
1025
+ 'spain' => 'ES',
1026
+ 'sri lanka' => 'LK',
1027
+ 'sudan' => 'SD',
1028
+ 'suriname' => 'SR',
1029
+ 'svalbard and jan mayen' => 'SJ',
1030
+ 'swaziland' => 'SZ',
1031
+ 'sweden' => 'SE',
1032
+ 'switzerland' => 'CH',
1033
+ 'syrian arab republic' => 'SY',
1034
+ 'taiwan, province of china' => 'TW',
1035
+ 'tajikistan' => 'TJ',
1036
+ 'tanzania, united republic of' => 'TZ',
1037
+ 'thailand' => 'TH',
1038
+ 'togo' => 'TG',
1039
+ 'tokelau' => 'TK',
1040
+ 'tonga' => 'TO',
1041
+ 'trinidad and tobago' => 'TT',
1042
+ 'tunisia' => 'TN',
1043
+ 'turkey' => 'TR',
1044
+ 'turkmenistan' => 'TM',
1045
+ 'turks and caicos islands' => 'TC',
1046
+ 'tuvalu' => 'TV',
1047
+ 'uganda' => 'UG',
1048
+ 'ukraine' => 'UA',
1049
+ 'united arab emirates' => 'AE',
1050
+ 'united kingdom' => 'GB',
1051
+ 'united states' => 'US',
1052
+ 'united states minor outlying islands' => 'UM',
1053
+ 'uruguay' => 'UY',
1054
+ 'uzbekistan' => 'UZ',
1055
+ 'vanuatu' => 'VU',
1056
+ 'venezuela' => 'VE',
1057
+ 'viet nam' => 'VN',
1058
+ 'virgin islands, british' => 'VG',
1059
+ 'virgin islands, u.s.' => 'VI',
1060
+ 'wallis and futuna' => 'WF',
1061
+ 'western sahara' => 'EH',
1062
+ 'yemen' => 'YE',
1063
+ 'yugoslavia' => 'YU',
1064
+ 'zambia' => 'ZM',
1065
+ 'zimbabwe' => 'ZW'
1066
+ );
1067
+
1068
+ $address_info['country'] = strtolower(
1069
+ $address_info['country']);
1070
+
1071
+ if (isset($foo[$address_info['country']])) {
1072
+ $address->setCountryId(
1073
+ $foo[$address_info['country']]);
1074
+ }
1075
+ }
1076
+
1077
+ $address->save();
1078
+ $order->addStatusHistoryComment(sprintf($this->_helper->__(
1079
+ 'Payson updated the shipping address')));
1080
+ }
1081
+ } else {
1082
+ $order['payson_invoice_fee'] = 0;
1083
+ $order['base_payson_invoice_fee'] = 0;
1084
+ $order->addStatusHistoryComment(sprintf(
1085
+ $this->_helper->__('Payson pinged the order with status %s'), $ipn_response->status));
1086
+ }
1087
+
1088
+ break;
1089
+ }
1090
+
1091
+ case self::STATUS_ERROR:
1092
+ case self::STATUS_DENIED:
1093
+
1094
+ $order->cancel();
1095
+
1096
+
1097
+ $order->addStatusHistoryComment($this->_helper->__('The order was denied by Payson.'));
1098
+
1099
+ break;
1100
+
1101
+ case self::STATUS_INCOMPLETE:
1102
+ case self::STATUS_EXPIRED:
1103
+ case self::STATUS_CANCELED:
1104
+ case self::STATUS_ABORTED:
1105
+ $order->cancel();
1106
+
1107
+ $order->addStatusHistoryComment($this->_helper->__('The order was canceled or not completed within allocated time'));
1108
+ break;
1109
+
1110
+ case self::STATUS_REVERSALERROR:
1111
+ default: {
1112
+ $order->cancel();
1113
+ }
1114
+ }
1115
+
1116
+ $order->save();
1117
+ $db->update($order_log_table, array
1118
+ (
1119
+ 'valid' => 1
1120
+ ), array
1121
+ (
1122
+ 'id = ?' => $order_log_id
1123
+ ));
1124
+
1125
+ $db->update($order_table, array
1126
+ (
1127
+ 'ipn_status' => $ipn_response->status
1128
+ ), array
1129
+ (
1130
+ 'id = ?' => $payson_order->id
1131
+ ));
1132
+
1133
+
1134
+ return $this;
1135
+ }
1136
+
1137
+ public function PaymentDetails($order_id) {
1138
+
1139
+ // Get the database connection
1140
+ $resource = Mage::getSingleton('core/resource');
1141
+ $db = $resource->getConnection('core_write');
1142
+
1143
+ $order_table = $resource->getTableName('payson_order');
1144
+ $order_log_table = $resource->getTableName('payson_order_log');
1145
+ /* Save fetch mode so that we can reset it and not mess up Magento
1146
+ functionality */
1147
+ $old_fetch_mode = $db->getFetchMode();
1148
+ $db->setFetchMode(Zend_Db::FETCH_OBJ);
1149
+
1150
+ // Get payson order information and validate token
1151
+ $payson_order = $db->fetchRow(
1152
+ 'SELECT
1153
+ id,
1154
+ token,
1155
+ store_id
1156
+ FROM
1157
+ `' . $order_table . '`
1158
+ WHERE
1159
+ valid = 1
1160
+ AND
1161
+ order_id = ?
1162
+ LIMIT
1163
+ 0,1', $order_id);
1164
+
1165
+ try {
1166
+ $payson_order !== false;
1167
+ } catch (Exception $e) {
1168
+ Mage::throwException('Invalid order id (' . $order_id . ')' . $e->getMessage());
1169
+ }
1170
+ $db->setFetchMode($old_fetch_mode);
1171
+
1172
+ $args = array
1173
+ (
1174
+ 'token' => $payson_order->token
1175
+ );
1176
+ $url = vsprintf(self::API_CALL_PAYMENT_DETAILS, $this->getFormatIfTest($payson_order->store_id));
1177
+
1178
+ $client = $this->getHttpClient($url)
1179
+ ->setParameterPost($args);
1180
+
1181
+ $response = Payson_Payson_Helper_Api_Response_Standard
1182
+ ::FromHttpBody($client->request('POST')->getBody());
1183
+
1184
+ $this->setResponse($response);
1185
+
1186
+ $db->insert($order_log_table, array
1187
+ (
1188
+ 'payson_order_id' => $payson_order->id,
1189
+ 'added' => new Zend_Db_Expr('NOW()'),
1190
+ 'api_call' => 'payment_details',
1191
+ 'valid' => (int) $response->IsValid(),
1192
+ 'response' => serialize($response->ToArray())
1193
+ ));
1194
+
1195
+ $payson_validator = $db->fetchRow(
1196
+ 'SELECT ipn_status, token FROM `' . $order_table . '` WHERE order_id = ? LIMIT 0,1', $order_id);
1197
+ if ((!$response->IsValid()) && ($payson_validator->ipn_status == NULL && $payson_validator->token == NULL)) {
1198
+
1199
+ $sales_flat_order = 'sales_flat_order';
1200
+ if ($order_id !== null && $payson_order !== false) {
1201
+ $new_order_id = Mage::getModel('sales/order')->loadByIncrementId($order_id)->getEntityId();
1202
+ $db->update($sales_flat_order, array('state' => 'canceled', 'status' => 'canceled'), array('entity_id = ?' => $new_order_id));
1203
+ }
1204
+ }
1205
+
1206
+ if (!$response->IsValid()) {
1207
+ $redirectUrl = Mage::getUrl('checkout/cart');
1208
+ Mage::getSingleton('checkout/session')->setRedirectUrl($redirectUrl);
1209
+ }
1210
+
1211
+ return $this;
1212
+ }
1213
+
1214
+ /**
1215
+ * http://api.payson.se/#title13
1216
+ *
1217
+ * @params int $order_id Real order id
1218
+ * @params string $action
1219
+ * @return object $this
1220
+ */
1221
+ public function PaymentUpdate($order_id, $action) {
1222
+
1223
+ // Get the database connection
1224
+ $resource = Mage::getSingleton('core/resource');
1225
+ $db = $resource->getConnection('core_write');
1226
+
1227
+ $order_table = $resource->getTableName('payson_order');
1228
+ $order_log_table = $resource->getTableName('payson_order_log');
1229
+
1230
+ /* Save fetch mode so that we can reset it and not mess up Magento
1231
+ functionality */
1232
+ $old_fetch_mode = $db->getFetchMode();
1233
+ $db->setFetchMode(Zend_Db::FETCH_OBJ);
1234
+
1235
+ // Get payson order information and validate token
1236
+ $payson_order = $db->fetchRow(
1237
+ 'SELECT
1238
+ id,
1239
+ token,
1240
+ store_id
1241
+ FROM
1242
+ `' . $order_table . '`
1243
+ WHERE
1244
+ valid = 1
1245
+ AND
1246
+ order_id = ?
1247
+ LIMIT
1248
+ 0,1', $order_id);
1249
+
1250
+
1251
+
1252
+ try {
1253
+ $payson_order !== false;
1254
+ } catch (Exception $e) {
1255
+ Mage::throwException('Invalid order id (' . $order_id . ')' . $e->getMessage());
1256
+ }
1257
+
1258
+ $db->setFetchMode($old_fetch_mode);
1259
+
1260
+ $args = array
1261
+ (
1262
+ 'token' => $payson_order->token,
1263
+ 'action' => $action
1264
+ );
1265
+
1266
+ $client = $this->getHttpClient(vsprintf(self::API_CALL_PAYMENT_UPDATE, $this->getFormatIfTest($payson_order->store_id)))
1267
+ ->setParameterPost($args);
1268
+
1269
+ $response = Payson_Payson_Helper_Api_Response_Standard
1270
+ ::FromHttpBody($client->request('POST')->getBody());
1271
+
1272
+ $this->setResponse($response);
1273
+
1274
+ $db->insert($order_log_table, array
1275
+ (
1276
+ 'payson_order_id' => $payson_order->id,
1277
+ 'added' => new Zend_Db_Expr('NOW()'),
1278
+ 'api_call' => 'payment_update',
1279
+ 'valid' => (int) $response->IsValid(),
1280
+ 'response' => serialize($response->ToArray())
1281
+ ));
1282
+
1283
+ return $this;
1284
+ }
1285
+
1286
+ private function getFormatIfTest($storeID = null, $isForwardURL = FALSE) {
1287
+
1288
+ $stack = array();
1289
+ /* @var $isTest bool */
1290
+ $isTest = ($this->_config->get('test_mode', $storeID) == "1");
1291
+
1292
+ array_push($stack, self::DEBUG_MODE ? "http" : "https");
1293
+ array_push($stack, $isTest && !self::DEBUG_MODE ? "test-" : (self::DEBUG_MODE && !$isForwardURL ? "mvc" : ""));
1294
+
1295
+ if ($isForwardURL == true) {
1296
+ array_push($stack, self::DEBUG_MODE ? "app" : "www");
1297
+ }
1298
+
1299
+ array_push($stack, self::DEBUG_MODE ? "local" : "se");
1300
+ array_push($stack, self::DEBUG_MODE ? "Payment" : "1.0");
1301
+
1302
+ array_push($stack, self::DEBUG_MODE ? "" : "Payment");
1303
+ return $stack;
1304
+ }
1305
+
1306
+ public function getIpnStatus($order_id) {
1307
+ $resource = Mage::getSingleton('core/resource');
1308
+ $db = $resource->getConnection('core_write');
1309
+ $order_table = $resource->getTableName('payson_order');
1310
+ $query = 'SELECT ipn_status FROM `' . $order_table . '` WHERE order_id = ' . $order_id;
1311
+ return $db->fetchRow($query);
1312
+ }
1313
+
1314
+ public function paysonApiError($error) {
1315
+ $error_code = '<html>
1316
+ <head>
1317
+ <meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
1318
+ <script type="text/javascript">
1319
+ alert("' . $error . '");
1320
+ window.location="' . ('/index.php') . '";
1321
+ </script>
1322
+ </head>
1323
+ </html>';
1324
+ echo $error_code;
1325
+ exit;
1326
+ }
1327
+
1328
+ }
app/code/community/Payson/Payson/Helper/Api/Response/Interface.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Payson_Helper_Data extends Mage_Core_Helper_Abstract {
4
+
5
+ }
6
+
app/code/community/Payson/Payson/Helper/FundingConstraint.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class FundingConstraint {
4
+
5
+ const NONE = 0;
6
+ const CREDITCARD = 1;
7
+ const BANK = 2;
8
+ const INVOICE = 3;
9
+ const SMS = 4;
10
+
11
+ public static function addConstraintsToOutput($fundingConstraints, &$output) {
12
+ $formatString = "fundingList.fundingConstraint(%d).constraint";
13
+
14
+ $i = 0;
15
+ foreach ($fundingConstraints as $constraint) {
16
+ if ($constraint != self::NONE) {
17
+ $output[sprintf($formatString, $i)] = self::ConstantToString($constraint);
18
+ $i++;
19
+ }
20
+ }
21
+ }
22
+
23
+ public static function ConstantToString($value) {
24
+ switch ($value) {
25
+ case self::BANK:
26
+ return "BANK";
27
+ case self::CREDITCARD:
28
+ return "CREDITCARD";
29
+ case self::INVOICE:
30
+ return "INVOICE";
31
+ case self::SMS:
32
+ return "SMS";
33
+ }
34
+ }
35
+
36
+ }
app/code/community/Payson/Payson/Model/Config.php ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
46
+ public function __construct() {
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
+ return in_array(strtoupper($currency), $this->supported_currencies);
81
+ }
82
+
83
+ /**
84
+ * Get configuration value
85
+ *
86
+ * @param mixed $name
87
+ * @param int|null $store [optional]
88
+ * @param mixed $default [optional]
89
+ * @param string $prefix [optional]
90
+ */
91
+ public function GetConfig($name, $store = null, $default = null, $prefix = 'payment/payson_standard/') {
92
+ if (!isset($store)) {
93
+ $store = $this->GetDefaultStoreId();
94
+ }
95
+
96
+ $name = $prefix . $name;
97
+ $value = Mage::getStoreConfig($name, $store);
98
+
99
+ return (isset($value) ? $value : $default);
100
+ }
101
+
102
+ /**
103
+ * @see GetConfig
104
+ */
105
+ public function Get($name, $store = null, $default = null, $prefix = 'payment/payson_standard/') {
106
+ return $this->GetConfig($name, $store, $default, $prefix);
107
+ }
108
+
109
+ /**
110
+ * Get Payson specific invoice fee excluding tax
111
+ *
112
+ * @param object $order
113
+ * @return float
114
+ */
115
+ public function GetInvoiceFee($order) {
116
+ $currency = $order->getBaseCurrencyCode();
117
+ $currency = strtolower($currency);
118
+
119
+ if (!$this->IsCurrencySupported($currency)) {
120
+ return 0;
121
+ }
122
+
123
+ $store = Mage::app()->getStore($order->getStoreId());
124
+
125
+ $fee = $this->GetConfig('invoice_fee_' . $currency, $store->getId(), 0, 'payment/payson_invoice/');
126
+ $fee = round((float) $fee, 3);
127
+
128
+ return $fee;
129
+ }
130
+
131
+ /**
132
+ * Get Payson specific invoice fee including tax
133
+ *
134
+ * @param object $order
135
+ * @return float
136
+ */
137
+ public function GetInvoiceFeeInclTax($order) {
138
+ $fee = $this->GetInvoiceFee($order);
139
+ $fee *= (1 + $this->GetInvoiceFeeTaxMod($order));
140
+ $fee = round($fee, 3);
141
+
142
+ return $fee;
143
+ }
144
+
145
+ /**
146
+ * Get Payson specific invoice fee tax modifier
147
+ *
148
+ * @param object $order
149
+ * @return float
150
+ */
151
+ public function GetInvoiceFeeTaxMod($order) {
152
+ $store = Mage::app()->getStore($order->getStoreId());
153
+
154
+ $tax_calc = Mage::getSingleton('tax/calculation');
155
+ $customer = Mage::getModel('customer/customer')
156
+ ->load($order->getCustomerId());
157
+ $tax_class = $this->GetConfig('invoice_fee_tax', $store->getId(), 0, 'payment/payson_invoice/');
158
+
159
+ $tax_rate_req = $tax_calc->getRateRequest(
160
+ $order->getShippingAddress(), $order->getBillingAddress(), $customer->getTaxClassId(), $store)
161
+ ->setProductClassId($tax_class);
162
+
163
+ $tax_mod = (float) $tax_calc->getRate($tax_rate_req);
164
+ $tax_mod /= 100;
165
+ $tax_mod = round($tax_mod, 5);
166
+
167
+ return $tax_mod;
168
+ }
169
+
170
+ /**
171
+ * Does this store support payment guarantee?
172
+ *
173
+ * @param int|null $store [optional]
174
+ * @return bool
175
+ */
176
+ public function CanPaymentGuarantee($store = null) {
177
+ return (bool) $this->GetConfig(self::PAYMENT_GUARANTEE, $store, false);
178
+ }
179
+
180
+ /**
181
+ * Is invoice payment enabled?
182
+ *
183
+ * @param int|null $store [optional]
184
+ * @return bool
185
+ */
186
+
187
+ public function CanInvoicePayment($store = null) {
188
+
189
+ return $this->GetConfig('active_invoice', $store, false, 'payment/payson_invoice/');
190
+ }
191
+ /**
192
+ * Is standard payment enabled?
193
+ *
194
+ * @param int|null $store [optional]
195
+ * @return bool
196
+ */
197
+ public function CanStandardPayment($store = null) {
198
+ return $this->GetConfig('active', $store, false, 'payment/payson_standard/');
199
+ }
200
+
201
+ public function restoreCartOnCancel($store = null) {
202
+ if (!$store)
203
+ $store = Mage::app()->getStore()->getId();
204
+ $configValue = $this->GetConfig("restore_on_cancel", $store);
205
+
206
+ return $configValue == 1;
207
+ }
208
+
209
+ public function restoreCartOnError($store = null) {
210
+ if (!$store)
211
+ $store = Mage::app()->getStore()->getId();
212
+ $configValue = $this->GetConfig("restore_on_error", $store);
213
+
214
+ return $configValue == 1;
215
+ }
216
+
217
+ }
218
+
app/code/community/Payson/Payson/Model/Method/Abstract.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = true;
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(Mage::app()->getStore()->getCurrentCurrencyCode());
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
+ if ($method == "payson_standard") {
94
+ $paysonPaymethod = $method;
95
+ }if ($method == "payson_invoice") {
96
+ $paysonPaymethod = $method;
97
+ }
98
+ $api->PaymentUpdate($order_id, $paysonPaymethod ?
99
+ Payson_Payson_Helper_Api::UPDATE_ACTION_CREDITORDER :
100
+ Payson_Payson_Helper_Api::UPDATE_ACTION_REFUNDORDER);
101
+
102
+ $order->addStatusHistoryComment($helper->__(
103
+ 'Payment was credited at Payson'));
104
+
105
+ return $this;
106
+ }
107
+
108
+ /**
109
+ * @inheritDoc
110
+ */
111
+ public function void(Varien_Object $payment) {
112
+ $payment->setTransactionId('auth')
113
+ ->setIsTransactionClosed(0);
114
+ return $this;
115
+ }
116
+
117
+ /**
118
+ * @inheritDoc
119
+ */
120
+ public function cancel(Varien_Object $payment) {
121
+ $order = $payment->getOrder();
122
+ $order_id = $order->getData('increment_id');
123
+
124
+ $api = Mage::helper('payson/api');
125
+ $helper = Mage::helper('payson');
126
+ $api->PaymentDetails($order_id);
127
+ $details = $api->GetResponse();
128
+
129
+
130
+
131
+ if (($details->type === Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
132
+ ($details->invoiceStatus === Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED) ||
133
+ ($details->type !== Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE && $details->status === Payson_Payson_Helper_Api::STATUS_CREATED) ||
134
+ $order->getState() === Mage_Sales_Model_Order::STATE_PROCESSING) {
135
+ $api->PaymentUpdate($order_id, Payson_Payson_Helper_Api::UPDATE_ACTION_CANCELORDER);
136
+
137
+ $order->addStatusHistoryComment($helper->__(
138
+ 'Order was canceled at Payson'));
139
+
140
+ $payment->setTransactionId('auth')
141
+ ->setIsTransactionClosed(1);
142
+ } else {
143
+ Mage::throwException($helper->__('Payson is not ready to cancel the order. Please try again later.'));
144
+ }
145
+ return $this;
146
+ }
147
+
148
+ }
app/code/community/Payson/Payson/Model/Method/Invoice.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ protected $_canCapture = true;
17
+ protected $_canRefund = true;
18
+ protected $_canVoid = true;
19
+ protected $_canUseCheckout = false;
20
+ protected $_canCancelInvoice = true;
21
+
22
+ /*
23
+ * Public methods
24
+ */
25
+
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ public function capture(Varien_Object $payment, $amount) {
30
+ $order = $payment->getOrder();
31
+ $method = $order->getPayment()->getMethod();
32
+ if (($method !== 'payson_standard') || ($method == "payson_invoice")) {
33
+ return $this;
34
+ }
35
+ $order_id = $order->getData('increment_id');
36
+
37
+ $api = Mage::helper('payson/api');
38
+ $helper = Mage::helper('payson');
39
+ $api->PaymentDetails($order_id);
40
+ $details = $api->GetResponse();
41
+
42
+ if (($details->type ===
43
+ Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
44
+ ($details->invoiceStatus ===
45
+ Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED)) {
46
+ $api->PaymentUpdate($order_id, Payson_Payson_Helper_Api::UPDATE_ACTION_SHIPORDER);
47
+
48
+ $order->addStatusHistoryComment($helper->__(
49
+ 'Order was activated at Payson'));
50
+ } else {
51
+ Mage::throwException($helper->__('Payson is not ready to create an invoice. Please try again later.'));
52
+ }
53
+ return $this;
54
+ }
55
+
56
+ public function authorize(Varien_Object $payment, $amount) {
57
+ $order = $payment->getOrder();
58
+ $method = $order->getPayment()->getMethod();
59
+ if (($method !== 'payson_standard') || ($method == "payson_invoice")) {
60
+ return $this;
61
+ }
62
+ $payment->setTransactionId('auth')->setIsTransactionClosed(0);
63
+ return $this;
64
+ }
65
+ }
app/code/community/Payson/Payson/Model/Method/Standard.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ protected $_canCancelInvoice = true;
12
+
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ protected $_code = 'payson_standard';
17
+ protected $_formBlockType = 'payson/standard_form';
18
+
19
+ /*
20
+ * Public methods
21
+ */
22
+
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ public function getTitle() {
27
+ $this->_config = Mage::getModel('payson/config');
28
+ $order = Mage::registry('current_order');
29
+ if (!isset($order) && ($invoice = Mage::registry('current_invoice'))) {
30
+ $order = $invoice->getOrder();
31
+ }
32
+
33
+ if (isset($order)) {
34
+ $invoice_fee = $order->getPaysonInvoiceFee();
35
+
36
+ if ($invoice_fee) {
37
+ $invoice_fee = $order->formatPrice($invoice_fee);
38
+ }
39
+ } else {
40
+ $invoice_fee = Mage::getModel('payson/config')
41
+ ->GetInvoiceFeeInclTax($this->getQuote());
42
+
43
+ if ($invoice_fee) {
44
+ $invoice_fee = Mage::app()->getStore()
45
+ ->formatPrice($invoice_fee);
46
+ }
47
+ }
48
+
49
+ $invoice_fee = strip_tags($invoice_fee);
50
+ if($this->_config->CanInvoicePayment()){
51
+ return sprintf(Mage::helper('payson')->__('Checkout with Payson. If invoice is choosen as payment method an %s invoice fee will be added.'), ($invoice_fee));
52
+ }else{
53
+ return Mage::helper('payson')->__('Checkout with Payson');
54
+ }
55
+
56
+ }
57
+
58
+ /**
59
+ * @inheritDoc
60
+ */
61
+ public function authorize(Varien_Object $payment, $amount) {
62
+ $payment->setTransactionId('auth')->setIsTransactionClosed(0);
63
+
64
+ return $this;
65
+ }
66
+ public function canUseCheckout() {
67
+ $this->_config = Mage::getModel('payson/config');
68
+
69
+ if ($this->_config->CanInvoicePayment()){
70
+ return true;
71
+ }
72
+ if($this->_config->CanStandardPayment()){
73
+ return true;
74
+ }else{
75
+ return false;
76
+ }
77
+
78
+ }
79
+
80
+ }
app/code/community/Payson/Payson/Model/Mysql4/Setup.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ public function collect(Mage_Sales_Model_Order_Creditmemo $invoice) {
8
+ $order = $invoice->getOrder();
9
+ $this->_config = Mage::getModel('payson/config');
10
+ $method = $order->getPayment()->getMethod();
11
+
12
+ if(!$this->_config->CanInvoicePayment()){
13
+ return $this;
14
+ }
15
+ if (($method !== 'payson_standard')||($method == "payson_invoice")) {
16
+ return $this;
17
+ }
18
+
19
+ $base_fee = $order->getBasePaysonInvoiceFee();
20
+ $fee = $order->getPaysonInvoiceFee();
21
+
22
+ if (!$base_fee || !$fee) {
23
+ return $this;
24
+ }
25
+
26
+ $base_grand_total = $invoice->getBaseGrandTotal();
27
+ $base_grand_total += $base_fee;
28
+ $grand_total = $invoice->getGrandTotal();
29
+ $grand_total += $fee;
30
+
31
+ $invoice->setBasePaysonInvoiceFee($base_fee);
32
+ $invoice->setPaysonInvoiceFee($fee);
33
+
34
+ $invoice->setBaseGrandTotal($base_grand_total);
35
+ $invoice->setGrandTotal($grand_total);
36
+
37
+ return $this;
38
+ }
39
+
40
+ }
41
+
app/code/community/Payson/Payson/Model/Order/Invoice/Total/Invoice.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_standard';
7
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice) {
8
+ $order = $invoice->getOrder();
9
+ $this->_config = Mage::getModel('payson/config');
10
+ if (!$this->_config->CanInvoicePayment()) {
11
+ return $this;
12
+ }
13
+ $method = $order->getPayment()->getMethodInstance()->getCode();
14
+ if (($method !== 'payson_standard')||($method == "payson_invoice")) {
15
+ return $this;
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
+ }
app/code/community/Payson/Payson/Model/Quote/Address/Total/Invoice.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Payson_Payson_Model_Quote_Address_Total_Invoice extends 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
+ if ($address->getAddressType() !== 'shipping') {
9
+ return $this;
10
+ }
11
+ $this->_config = Mage::getModel('payson/config');
12
+ $address->setBasePaysonInvoiceFee(0);
13
+ $address->setPaysonInvoiceFee(0);
14
+ $quote = $address->getQuote();
15
+
16
+ $method = $address->getQuote()->getPayment()->getMethod();
17
+ if (is_null($quote->getId())) {
18
+ return $this;
19
+ }
20
+ if (!$this->_config->CanInvoicePayment()) {
21
+ return $this;
22
+ }
23
+ if (($method !== 'payson_standard')||($method == "payson_invoice")) {
24
+ return $this;
25
+ }
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
+
35
+ $address->setBasePaysonInvoiceFee($fee);
36
+ $address->setPaysonInvoiceFee($store->convertPrice($fee, false));
37
+
38
+ $address->setBaseGrandTotal($base_grand_total);
39
+ $address->setGrandTotal($store->convertPrice($base_grand_total, false));
40
+
41
+ return $this;
42
+ }
43
+
44
+ }
app/code/community/Payson/Payson/Model/Standard.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = true;
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
+ return $this;
51
+ }
52
+
53
+ /**
54
+ * @inheritDoc
55
+ */
56
+ public function capture(Varien_Object $payment, $amount) {
57
+ $order = $payment->getOrder();
58
+ $order_id = $order->getData('increment_id');
59
+
60
+ $api = Mage::helper('payson/api');
61
+
62
+ $api->PaymentDetails($order_id);
63
+ $details = $api->GetResponse();
64
+
65
+ if (($details->type ===
66
+ Payson_Payson_Helper_Api::PAYMENT_METHOD_INVOICE) ||
67
+ ($details->invoiceStatus ===
68
+ Payson_Payson_Helper_Api::INVOICE_STATUS_ORDERCREATED)) {
69
+ $api->PaymentUpdate($order_id, Payson_Payson_Helper_Api::UPDATE_ACTION_SHIPORDER);
70
+ }
71
+
72
+ return $this;
73
+ }
74
+
75
+ /**
76
+ * Redirect url when user place order
77
+ *
78
+ * @return string
79
+ */
80
+ public function getOrderPlaceRedirectUrl() {
81
+ return Mage::getUrl('payson/checkout/redirect', array('_secure' => true));
82
+ }
83
+
84
+ /**
85
+ * Whether this paymend method is available for specified currency
86
+ *
87
+ * @param string $currency
88
+ * @return bool
89
+ */
90
+ public function canUseForCurrency($currency) {
91
+ return Mage::getModel('payson/config')->IsCurrencySupported($currency);
92
+ }
93
+
94
+ /**
95
+ * @inheritDoc
96
+ */
97
+ public function getTitle() {
98
+ $order = Mage::registry('current_order');
99
+ $invoice_fee = $order->getPaysonInvoiceFee();
100
+ $text_invoice_fee = strip_tags($invoice_fee);
101
+ if ($this->_config->CanStandardPayment()) {
102
+ return sprintf(Mage::helper('payson')->__('Checkout with Payson. If invoice is choosen as payment method an %s invoice fee will be added.'), ($text_invoice_fee));
103
+ } elseif ($this->_config->CanStandardPayment()) {
104
+ return Mage::helper('payson')->__('Checkout with Payson');
105
+ }
106
+ }
107
+
108
+ }
app/code/community/Payson/Payson/Model/System/Config/Source/Paysondirectmethod.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * My own options
5
+ *
6
+ */
7
+
8
+ class Payson_Payson_Model_System_Config_Source_Paysondirectmethod {
9
+
10
+ /**
11
+ * Options getter
12
+ *
13
+ * @return array
14
+ *
15
+ */
16
+
17
+ public function toOptionArray() {
18
+
19
+ $this->_config = Mage::getModel('payson/config');
20
+
21
+
22
+ $paysonInvoice = array(
23
+ array('value' => 7, 'label' => Mage::helper('adminhtml')->__('')),
24
+ array('value' => 8, 'label' => Mage::helper('adminhtml')->__('INVOICE')),
25
+ array('value' => 9, 'label' => Mage::helper('adminhtml')->__('INVOICE / SMS')),
26
+ array('value' => 10, 'label' => Mage::helper('adminhtml')->__('INVOICE / BANK')),
27
+ array('value' => 11, 'label' => Mage::helper('adminhtml')->__('INVOICE / CREDITCARD')),
28
+ array('value' => 12, 'label' => Mage::helper('adminhtml')->__('INVOICE / BANK / SMS')),
29
+ array('value' => 13, 'label' => Mage::helper('adminhtml')->__('INVOICE / CREDITCARD / SMS')),
30
+ array('value' => 14, 'label' => Mage::helper('adminhtml')->__('INVOICE / CREDITCARD / BANK')),
31
+ array('value' => 15, 'label' => Mage::helper('adminhtml')->__('INVOICE / CREDITCARD / BANK / SMS'))
32
+
33
+ );
34
+ $paysonDirect = array(
35
+ array('value' => -1, 'label' => Mage::helper('adminhtml')->__('')),
36
+ array('value' => 0, 'label' => Mage::helper('adminhtml')->__('SMS')),
37
+ array('value' => 1, 'label' => Mage::helper('adminhtml')->__('BANK')),
38
+ array('value' => 2, 'label' => Mage::helper('adminhtml')->__('CREDITCARD')),
39
+ array('value' => 3, 'label' => Mage::helper('adminhtml')->__('BANK / SMS')),
40
+ array('value' => 4, 'label' => Mage::helper('adminhtml')->__('CREDITCARD / SMS')),
41
+ array('value' => 5, 'label' => Mage::helper('adminhtml')->__('CREDITCARD / BANK')),
42
+ array('value' => 6, 'label' => Mage::helper('adminhtml')->__('CREDITCARD / BANK / SMS'))
43
+
44
+ );
45
+ if ($this->_config->CanInvoicePayment()) {
46
+ return $paysonInvoice;
47
+ } elseif ($this->_config->CanStandardPayment()) {
48
+ return $paysonDirect;
49
+ }
50
+ }
51
+
52
+ }
app/code/community/Payson/Payson/controllers/Adminhtml/Sales/Order/ShipmentController.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php';
4
+
5
+ class Payson_Payson_Adminhtml_Sales_Order_ShipmentController extends Mage_Adminhtml_Sales_Order_ShipmentController {
6
+
7
+ public function saveAction() {
8
+
9
+ $order = Mage::getModel('sales/order')->load($this->getRequest()->getParam('order_id'));
10
+
11
+ if (($order->getPayment()->getMethodInstance()->getCode() == "payson_standard")||($order->getPayment()->getMethodInstance()->getCode() == "payson_invoice")) {
12
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
13
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
14
+ $invoice->register();
15
+ $transactionSave = Mage::getModel('core/resource_transaction')
16
+ ->addObject($invoice)
17
+ ->addObject($invoice->getOrder());
18
+ $transactionSave->save();
19
+ }
20
+ parent::saveAction();
21
+ }
22
+
23
+ }
app/code/community/Payson/Payson/controllers/CheckoutController.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /* @var $_config Payson_Payson_Model_Config */
11
+ private $_config;
12
+ /* @var $_helper Payson_Payson_Helper_Data */
13
+ private $_helper;
14
+
15
+ /*
16
+ * Private methods
17
+ */
18
+
19
+ public function _construct() {
20
+ $this->_config = Mage::getModel('payson/config');
21
+ $this->_helper = Mage::helper('payson');
22
+ }
23
+
24
+ /*
25
+ * Private methods
26
+ */
27
+
28
+ private function getSession() {
29
+ if (!isset($this->_session)) {
30
+ $this->_session = Mage::getSingleton('checkout/session');
31
+ }
32
+
33
+ return $this->_session;
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @return Mage_Sales_Model_Order
39
+ */
40
+ private function getOrder() {
41
+ if (!isset($this->_order)) {
42
+ $increment_id = $this->getSession()->getData('last_real_order_id');
43
+
44
+ if ($increment_id) {
45
+ $this->_order = Mage::getModel('sales/order')
46
+ ->loadByIncrementId($increment_id);
47
+
48
+ if (is_null($this->_order->getId())) {
49
+ $this->_order = null;
50
+ }
51
+ }
52
+ }
53
+
54
+ return $this->_order;
55
+ }
56
+
57
+ private function cancelOrder($message = '') {
58
+
59
+ $order = $this->getOrder();
60
+
61
+ if (!is_null($order = $this->getOrder())) {
62
+ $order->cancel();
63
+
64
+ if ($message != '') {
65
+ $order->addStatusHistoryComment($message);
66
+ }
67
+ }
68
+
69
+ $order->save();
70
+ return $this;
71
+ }
72
+
73
+ public function redirectAction() {
74
+
75
+ $order = $this->getOrder();
76
+
77
+ if (is_null($order)) {
78
+ $this->_redirect('checkout/cart');
79
+
80
+ return;
81
+ }
82
+
83
+ try {
84
+ $api = Mage::helper('payson/api')->Pay($order);
85
+
86
+ $order->addStatusHistoryComment(Mage::helper('payson')->__(
87
+ 'The customer was redirected to Payson'))
88
+ ->save();
89
+
90
+ $this->GetResponse()->setRedirect($api->GetPayForwardUrl());
91
+ } catch (Exception $e) {
92
+ $this->cancelOrder($e->getMessage());
93
+
94
+ if ($this->_config->restoreCartOnError()) {
95
+ $this->restoreCart();
96
+ }
97
+
98
+ Mage::logException($e);
99
+
100
+ Mage::getSingleton('core/session')->addError($e->getMessage());
101
+ $this->_redirect('checkout/cart');
102
+ }
103
+ }
104
+
105
+ public function returnAction() {
106
+ $api = Mage::helper('payson/api');
107
+ $order = $this->getOrder();
108
+ $paymentDetailsResponse = Mage::helper('payson/api')->PaymentDetails(Mage::getSingleton('checkout/session')->getLastRealOrderId())->getResponse();
109
+ $paymentStatus = $paymentDetailsResponse->status;
110
+ $InvoiceStatus = $paymentDetailsResponse->invoiceStatus;
111
+ isset($InvoiceStatus) ? $InvoiceStatus : 'NONE';
112
+ $paymentDetails = $paymentDetailsResponse->receiverList->receiver->ToArray();
113
+ $new_paymentDetails = array();
114
+ foreach ($paymentDetails as $item) {
115
+ foreach ($item as $key => $value) {
116
+ $new_paymentDetails[$key] = $value;
117
+ }
118
+ }
119
+
120
+ $sendEmail = $api->confirmationEmail($order->getEntityId());
121
+ $investigatefee = $order['base_payson_invoice_fee'];
122
+ $currentAmount = $new_paymentDetails['amount'];
123
+ $newAmount = $currentAmount += $investigatefee;
124
+ switch ($paymentStatus) {
125
+ case 'COMPLETED':
126
+ case 'PENDING':
127
+ case 'PROCESSING':
128
+ case 'CREDITED': {
129
+
130
+ //$paymentDetails->getInvoiceStatus() == 'ORDERCREATED'
131
+ if ($paymentDetailsResponse->type !== 'INVOICE' && $paymentDetailsResponse->status === 'COMPLETED') {
132
+ if ($sendEmail['status'] == 'pending_payment') {
133
+ $order->sendNewOrderEmail()->save();
134
+ }
135
+
136
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
137
+ Mage::helper('payson')->__('Either an bank, card or SMS payment was choosen as payment method');
138
+ $order['payson_invoice_fee'] = 0;
139
+ $order['base_payson_invoice_fee'] = 0;
140
+
141
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
142
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
143
+ $invoice->register();
144
+ $transactionSave = Mage::getModel('core/resource_transaction')
145
+ ->addObject($invoice)
146
+ ->addObject($invoice->getOrder());
147
+
148
+ $transactionSave->save();
149
+ $this->_redirect('checkout/onepage/success');
150
+ break;
151
+ }
152
+ if ($paymentDetailsResponse->type !== 'INVOICE' && $paymentDetailsResponse->status === 'PROCESSING') {
153
+ $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true);
154
+ Mage::getSingleton('core/session')->addError(sprintf(Mage::helper('payson')->__('Your payment is being processed by Payson')));
155
+ $order['payson_invoice_fee'] = 0;
156
+ $order['base_payson_invoice_fee'] = 0;
157
+ $this->_redirect('checkout/onepage/success');
158
+ break;
159
+ }
160
+ if ($paymentDetailsResponse->type !== 'INVOICE' && $paymentDetailsResponse->status === 'PENDING') {
161
+ Mage::getSingleton('core/session')->addError(sprintf(Mage::helper('payson')->__('Something went wrong with the payment. Please, try a different payment method')));
162
+ $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true);
163
+ $order['payson_invoice_fee'] = 0;
164
+ $order['base_payson_invoice_fee'] = 0;
165
+ $this->_redirect('checkout/onepage/failure');
166
+ break;
167
+ }
168
+ if ($paymentDetailsResponse->type === 'INVOICE' && $InvoiceStatus === 'PENDING') {
169
+ Mage::getSingleton('core/session')->addError(sprintf(Mage::helper('payson')->__('Your payment is being processed by Payson')));
170
+ $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true);
171
+ $this->_redirect('checkout/onepage/failure');
172
+ break;
173
+ }
174
+ //Update the order with the true amount
175
+ if ($paymentDetailsResponse->type === 'INVOICE' && $paymentDetailsResponse->type !== 'TRANSFER') {
176
+ if ($sendEmail['status'] == 'pending_payment') {
177
+ $order->sendNewOrderEmail()->save();
178
+ }
179
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
180
+ Mage::helper('payson')->__('Invoice payment was choosen as payment method');
181
+ $order->sendNewOrderEmail()->save();
182
+ $order->setBaseGrandTotal($newAmount);
183
+ $order->setGrandTotal($newAmount);
184
+ $order->setTotalDue($newAmount);
185
+ $order->save();
186
+ $this->_redirect('checkout/onepage/success');
187
+ break;
188
+ }
189
+ }
190
+ case 'ERROR':
191
+ case 'DENIED': {
192
+ $errorMessage = Mage::helper('payson')->__('The payment was denied by Payson. Please, try a different payment method');
193
+ Mage::getSingleton('core/session')->addError($errorMessage);
194
+ $this->cancelOrder($errorMessage);
195
+ $this->_redirect('checkout');
196
+ break;
197
+ }
198
+ case 'ABORTED':
199
+ case 'CANCELED': {
200
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
201
+ $cancelMessage = Mage::helper('payson')->__('Order was canceled at Payson');
202
+ $this->cancelOrder($cancelMessage);
203
+ if ($this->_config->restoreCartOnCancel()) {
204
+ $this->restoreCart();
205
+ }
206
+ $this->_redirect('checkout');
207
+ }
208
+
209
+
210
+ default: {
211
+ Mage::getSingleton('core/session')->addError(sprintf(Mage::helper('payson')->__('Something went wrong with the payment. Please, try a different payment method')));
212
+ $this->_redirect('checkout');
213
+ break;
214
+ }
215
+ }
216
+ }
217
+
218
+ public function cancelAction() {
219
+
220
+ $cancelMessage = Mage::helper('payson')->__('Order was canceled at Payson');
221
+
222
+ $this->cancelOrder($cancelMessage);
223
+
224
+ if ($this->_config->restoreCartOnCancel()) {
225
+ $this->restoreCart();
226
+ }
227
+
228
+ $this->_redirect('checkout');
229
+ }
230
+
231
+ private function restoreCart() {
232
+
233
+ $quoteId = $this->getOrder()->getQuoteId();
234
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
235
+ $quote->setIsActive(true)->save();
236
+ }
237
+
238
+ }
app/code/community/Payson/Payson/controllers/IpnController.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Payson_Payson>
5
+ <version>1.8.3</version>
6
+ </Payson_Payson>
7
+ </modules>
8
+ <admin>
9
+ <routers>
10
+ <adminhtml>
11
+ <args>
12
+ <modules>
13
+ <Payson_Payson before="Mage_Adminhtml">Payson_Payson_Adminhtml</Payson_Payson>
14
+ </modules>
15
+ </args>
16
+ </adminhtml>
17
+ </routers>
18
+ </admin>
19
+ <global>
20
+ <blocks>
21
+ <payson>
22
+ <class>Payson_Payson_Block</class>
23
+ </payson>
24
+ </blocks>
25
+ <models>
26
+ <payson>
27
+ <class>Payson_Payson_Model</class>
28
+ </payson>
29
+ </models>
30
+ <helpers>
31
+ <payson>
32
+ <class>Payson_Payson_Helper</class>
33
+ </payson>
34
+ </helpers>
35
+ <resources>
36
+ <payson_setup>
37
+ <setup>
38
+ <module>Payson_Payson</module>
39
+ <class>Payson_Payson_Model_Mysql4_Setup</class>
40
+ </setup>
41
+ <connection>
42
+ <use>core_setup</use>
43
+ </connection>
44
+ </payson_setup>
45
+ <payson_write>
46
+ <connection>
47
+ <use>core_write</use>
48
+ </connection>
49
+ </payson_write>
50
+ <payson_read>
51
+ <connection>
52
+ <use>core_read</use>
53
+ </connection>
54
+ </payson_read>
55
+ </resources>
56
+ <sales>
57
+ <quote>
58
+ <totals>
59
+ <payson_invoice>
60
+ <class>payson/quote_address_total_invoice</class>
61
+ <after>subtotal,discount,shipping</after>
62
+ <before>tax,grand_total</before>
63
+ </payson_invoice>
64
+ </totals>
65
+ </quote>
66
+ <order_invoice>
67
+ <totals>
68
+ <payson_invoice>
69
+ <class>payson/order_invoice_total_invoice</class>
70
+ <after>subtotal,discount,shipping</after>
71
+ <before>tax,grand_total</before>
72
+ </payson_invoice>
73
+ </totals>
74
+ </order_invoice>
75
+ <order_creditmemo>
76
+ <totals>
77
+ <payson_invoice>
78
+ <class>payson/order_creditmemo_total_invoice</class>
79
+ <after>subtotal,discount,shipping</after>
80
+ <before>tax,grand_total</before>
81
+ </payson_invoice>
82
+ </totals>
83
+ </order_creditmemo>
84
+ </sales>
85
+ <fieldsets>
86
+ <sales_convert_quote_address>
87
+ <base_payson_invoice_fee>
88
+ <to_order>*</to_order>
89
+ </base_payson_invoice_fee>
90
+ <payson_invoice_fee>
91
+ <to_order>*</to_order>
92
+ </payson_invoice_fee>
93
+ </sales_convert_quote_address>
94
+ </fieldsets>
95
+ </global>
96
+ <frontend>
97
+ <secure_url>
98
+ <payson_checkout>/payson/checkout</payson_checkout>
99
+ </secure_url>
100
+ <routers>
101
+ <payson>
102
+ <use>standard</use>
103
+ <args>
104
+ <module>Payson_Payson</module>
105
+ <frontName>payson</frontName>
106
+ </args>
107
+ </payson>
108
+ </routers>
109
+ <translate>
110
+ <modules>
111
+ <Payson_Payson>
112
+ <files>
113
+ <default>Payson_Payson.csv</default>
114
+ </files>
115
+ </Payson_Payson>
116
+ </modules>
117
+ </translate>
118
+ <layout>
119
+ <updates>
120
+ <Payson_Payson>
121
+ <file>Payson.xml</file>
122
+ </Payson_Payson>
123
+ </updates>
124
+ </layout>
125
+ </frontend>
126
+ <adminhtml>
127
+ <translate>
128
+ <modules>
129
+ <Payson_Payson>
130
+ <files>
131
+ <default>Payson_Payson.csv</default>
132
+ </files>
133
+ </Payson_Payson>
134
+ </modules>
135
+ </translate>
136
+ <layout>
137
+ <updates>
138
+ <Payson_Payson>
139
+ <file>Payson.xml</file>
140
+ </Payson_Payson>
141
+ </updates>
142
+ </layout>
143
+ </adminhtml>
144
+ <default>
145
+ <payment>
146
+ <payson_standard>
147
+ <test_mode>0</test_mode>
148
+ <active>0</active>
149
+ <model>payson/method_standard</model>
150
+ <payment_action>authorize</payment_action>
151
+ <order_status>pending_payment</order_status>
152
+ <payment_guarantee>1</payment_guarantee>
153
+ <restore_on_cancel>1</restore_on_cancel>
154
+ <restore_on_error>1</restore_on_error>
155
+ </payson_standard>
156
+ <payson_invoice>
157
+ <active>0</active>
158
+ <activate_invoice>1</activate_invoice>
159
+ <model>payson/method_invoice</model>
160
+ <payment_action>authorize</payment_action>
161
+ <order_status>pending</order_status>
162
+ <invoice_fee_sek>0</invoice_fee_sek>
163
+ </payson_invoice>
164
+ </payment>
165
+ </default>
166
+ </config>
167
+
app/code/community/Payson/Payson/etc/system.xml ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 All in one Payment</label>
8
+ <comment><![CDATA[Payson Invoice requires a separate contract. Please contact Payson for more information<a href="http://payson.se" target="_blank">Click here</a>]]></comment>
9
+ <sort_order>-100</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <test_mode translate="label,comment">
15
+ <label>Test mode</label>
16
+ <comment>Enable/disable test mode.</comment>
17
+ <frontend_type>select</frontend_type>
18
+ <source_model>adminhtml/system_config_source_yesno</source_model>
19
+ <sort_order>5</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>1</show_in_store>
23
+ </test_mode>
24
+ <active translate="label,comment">
25
+ <label>Enabled</label>
26
+ <comment>Enable/disable payment with Payson.</comment>
27
+ <frontend_type>select</frontend_type>
28
+ <source_model>adminhtml/system_config_source_yesno</source_model>
29
+ <sort_order>10</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ </active>
34
+ <email translate="label,comment">
35
+ <label>Email</label>
36
+ <comment>Email address bound to your Payson account.</comment>
37
+ <frontend_type>text</frontend_type>
38
+ <validate>validate-email</validate>
39
+ <sort_order>20</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>0</show_in_website>
42
+ <show_in_store>0</show_in_store>
43
+ </email>
44
+ <agent_id translate="label,comment">
45
+ <label>Agent ID</label>
46
+ <comment>Agent ID is found on your Payson profile page.</comment>
47
+ <frontend_type>text</frontend_type>
48
+ <sort_order>30</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_website>0</show_in_website>
51
+ <show_in_store>0</show_in_store>
52
+ </agent_id>
53
+ <md5_key translate="label,comment">
54
+ <label>API key</label>
55
+ <comment>API key is found on your Payson profile page.</comment>
56
+ <frontend_type>text</frontend_type>
57
+ <sort_order>40</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>0</show_in_website>
60
+ <show_in_store>0</show_in_store>
61
+ </md5_key>
62
+ <payson_All_in_one translate="label">
63
+ <label>Please select the payment method</label>
64
+ <comment>Choose your prefered Payson payment</comment>
65
+ <frontend_type>select</frontend_type>
66
+ <source_model>payson/system_config_source_paysondirectmethod</source_model>
67
+ <sort_order>45</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ </payson_All_in_one>
72
+ <payment_guarantee translate="label,comment">
73
+ <label>Enable payment guarantee</label>
74
+ <comment>Enable/disable payment guarantee.</comment>
75
+ <frontend_type>select</frontend_type>
76
+ <source_model>adminhtml/system_config_source_yesno</source_model>
77
+ <sort_order>50</sort_order>
78
+ <show_in_default>0</show_in_default>
79
+ <show_in_website>0</show_in_website>
80
+ <show_in_store>0</show_in_store>
81
+ </payment_guarantee>
82
+ <restore_on_cancel translate="label,comment">
83
+ <label>Restore cart on cancel</label>
84
+ <comment>Restore cart when customer cancel the payment</comment>
85
+ <frontend_type>select</frontend_type>
86
+ <source_model>adminhtml/system_config_source_yesno</source_model>
87
+ <sort_order>100</sort_order>
88
+ <show_in_default>1</show_in_default>
89
+ <show_in_website>1</show_in_website>
90
+ <show_in_store>1</show_in_store>
91
+ </restore_on_cancel>
92
+ <restore_on_error translate="label,comment">
93
+ <label>Restore cart on error</label>
94
+ <comment>Restore cart when status from Payson is error</comment>
95
+ <frontend_type>select</frontend_type>
96
+ <source_model>adminhtml/system_config_source_yesno</source_model>
97
+ <sort_order>150</sort_order>
98
+ <show_in_default>1</show_in_default>
99
+ <show_in_website>1</show_in_website>
100
+ <show_in_store>1</show_in_store>
101
+ </restore_on_error>
102
+ <show_receipt_page translate="label,comment">
103
+ <label>Show receipt page</label>
104
+ <comment>Here you can enable or disable our receipt page</comment>
105
+ <frontend_type>select</frontend_type>
106
+ <source_model>adminhtml/system_config_source_yesno</source_model>
107
+ <sort_order>200</sort_order>
108
+ <show_in_default>1</show_in_default>
109
+ <show_in_website>0</show_in_website>
110
+ <show_in_store>0</show_in_store>
111
+ </show_receipt_page>
112
+ <vat_discount translate="label,comment">
113
+ <label>Enable average vat on discount</label>
114
+ <comment>Enable/disable average vat on discount</comment>
115
+ <frontend_type>select</frontend_type>
116
+ <source_model>adminhtml/system_config_source_yesno</source_model>
117
+ <sort_order>250</sort_order>
118
+ <show_in_default>1</show_in_default>
119
+ <show_in_website>0</show_in_website>
120
+ <show_in_store>0</show_in_store>
121
+ </vat_discount>
122
+ </fields>
123
+ </payson_standard>
124
+ <payson_invoice translate="label" module="payson">
125
+ <label>Payson invoice setup</label>
126
+ <sort_order>-99</sort_order>
127
+ <show_in_default>1</show_in_default>
128
+ <show_in_website>1</show_in_website>
129
+ <show_in_store>1</show_in_store>
130
+ <comment><![CDATA[Payson Invoice requires a separate contract. Please contact Payson for more information<a href="http://payson.se" target="_blank">Click here</a>]]></comment>
131
+ <fields>
132
+ <active_invoice translate="label,comment">
133
+ <label>Enabled</label>
134
+ <comment>Enable/disable invoice payment with Payson.</comment>
135
+ <frontend_type>select</frontend_type>
136
+ <source_model>adminhtml/system_config_source_yesno</source_model>
137
+ <sort_order>10</sort_order>
138
+ <show_in_default>1</show_in_default>
139
+ <show_in_website>1</show_in_website>
140
+ <show_in_store>1</show_in_store>
141
+ </active_invoice>
142
+ <invoice_fee_tax translate="label,comment">
143
+ <label>Invoice fee tax</label>
144
+ <comment>Tax class for invoice fees.</comment>
145
+ <frontend_type>select</frontend_type>
146
+ <source_model>adminhtml/system_config_source_shipping_taxclass</source_model>
147
+ <sort_order>20</sort_order>
148
+ <show_in_default>1</show_in_default>
149
+ <show_in_website>1</show_in_website>
150
+ <show_in_store>1</show_in_store>
151
+ </invoice_fee_tax>
152
+ <invoice_fee_sek translate="label,comment">
153
+ <label>Invoice fee (SEK)</label>
154
+ <comment>Input an invoice fee within the intervall of 0-40 including Vat.</comment>
155
+ <frontend_type>text</frontend_type>
156
+ <sort_order>30</sort_order>
157
+ <show_in_default>1</show_in_default>
158
+ <show_in_website>1</show_in_website>
159
+ <show_in_store>1</show_in_store>
160
+ </invoice_fee_sek>
161
+ </fields>
162
+ </payson_invoice>
163
+ </groups>
164
+ </payment>
165
+ </sections>
166
+ </config>
app/code/community/Payson/Payson/sql/payson_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $this->startSetup();
4
+ $this->run('
5
+ CREATE TABLE IF NOT EXISTS `' . $this->getTable('payson_order') . '`
6
+ (
7
+ `id` INT NOT NULL AUTO_INCREMENT,
8
+ `order_id` INT NOT NULL,
9
+ `added` DATETIME DEFAULT NULL,
10
+ `updated` DATETIME DEFAULT NULL,
11
+ `valid` TINYINT(1) NOT NULL,
12
+ `ipn_status` VARCHAR(32) DEFAULT NULL,
13
+ `token` VARCHAR(255) DEFAULT NULL,
14
+ PRIMARY KEY (`id`)
15
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
16
+
17
+ CREATE TABLE IF NOT EXISTS `' . $this->getTable('payson_order_log') . '`
18
+ (
19
+ `id` INT NOT NULL AUTO_INCREMENT,
20
+ `payson_order_id` INT DEFAULT NULL,
21
+ `added` DATETIME DEFAULT NULL,
22
+ `api_call` VARCHAR(32) NOT NULL,
23
+ `valid` TINYINT(1) NOT NULL,
24
+ `response` TEXT NOT NULL,
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 ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $this->startSetup();
4
+ $this->run('alter table `' . $this->getTable('payson_order') . '` add store_id int;
5
+ ');
6
+
7
+ $this->endSetup();
8
+
app/design/frontend/base/default/layout/payson_checkout2.xml ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout2_payment_index>
4
+ <remove name="right"/>
5
+ <reference name="content">
6
+ <block type="checkout2/payment" name="payson.checkout2.payment.standard" template="payson/checkout2/payment/standard.phtml" />
7
+ </reference>
8
+ </checkout2_payment_index>
9
+
10
+ <checkout2_payment_confirmation>
11
+ <remove name="right"/>
12
+ <reference name="content">
13
+ <block type="checkout2/payment" name="payson.checkout2.payment.confirmation" template="payson/checkout2/payment/confirmation.phtml" />
14
+ </reference>
15
+ </checkout2_payment_confirmation>
16
+
17
+ <checkout2_express_index>
18
+ <reference name="head">
19
+ <action method="addJs"><script>payson/checkout2/express.js</script></action>
20
+ </reference>
21
+
22
+ <reference name="root">
23
+ <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
24
+ <action method="addBodyClass"><classname>payson-express</classname></action>
25
+ <action method="addBodyClass"><classname>opc</classname></action>
26
+ </reference>
27
+
28
+ <reference name="left">
29
+ <block type="checkout2/payment" name="payson.checkout2.shipping" template="payson/checkout2/form/shipping.phtml">
30
+ <block type="checkout/onepage_shipping_method_available" name="checkout.onepage.shipping_method.available" as="shipping_methods" template="checkout/onepage/shipping_method/available.phtml" />
31
+ </block>
32
+
33
+ <block type="checkout2/payment" name="payson.checkout2.review" template="payson/checkout2/form/review.phtml">
34
+ <block type="checkout/onepage_review_info" name="order_review" template="checkout/onepage/review/info.phtml">
35
+ <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/onepage/review/item.phtml</template></action>
36
+ <block type="checkout/cart_totals" name="checkout.onepage.review.info.totals" as="totals" template="checkout/onepage/review/totals.phtml"/>
37
+ </block>
38
+ </block>
39
+ </reference>
40
+
41
+ <reference name="content">
42
+ <block type="checkout2/payment" name="payson.checkout2.payment.express" template="payson/checkout2/payment/express.phtml" />
43
+ </reference>
44
+ </checkout2_express_index>
45
+
46
+ <checkout2_express_update>
47
+ <reference name="root">
48
+ <action method="setTemplate"><template>payson/checkout2/page/blank.phtml</template></action>
49
+ </reference>
50
+
51
+ <reference name="content">
52
+ <remove name="product.tooltip" />
53
+
54
+ <block type="checkout2/payment" name="payson.checkout2.shipping" template="payson/checkout2/form/shipping.phtml">
55
+ <block type="checkout/onepage_shipping_method_available" name="checkout.onepage.shipping_method.available" as="shipping_methods" template="checkout/onepage/shipping_method/available.phtml" />
56
+ </block>
57
+
58
+ <block type="checkout2/payment" name="payson.checkout2.review" template="payson/checkout2/form/review.phtml">
59
+ <block type="checkout/onepage_review_info" name="order_review" template="checkout/onepage/review/info.phtml">
60
+ <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/onepage/review/item.phtml</template></action>
61
+ <block type="checkout/cart_totals" name="checkout.onepage.review.info.totals" as="totals" template="checkout/onepage/review/totals.phtml"/>
62
+ </block>
63
+ </block>
64
+ </reference>
65
+ </checkout2_express_update>
66
+
67
+ <checkout_cart_index>
68
+ <reference name="checkout.cart.top_methods">
69
+ <block type="checkout2/payment" name="checkout.cart.methods.payson_checkout2.top" after="checkout.cart.methods.onepage.top" template="payson/checkout2/elements/button.phtml" />
70
+ </reference>
71
+
72
+ <reference name="checkout.cart.methods">
73
+ <block type="checkout2/payment" name="checkout.cart.methods.payson_checkout2.bottom" before="checkout.cart.methods.onepage.bottom" template="payson/checkout2/elements/button.phtml" />
74
+ </reference>
75
+ </checkout_cart_index>
76
+
77
+ <default>
78
+ <reference name="cart_sidebar.extra_actions">
79
+ <block type="checkout2/payment" name="checkout.cart.methods.payson_checkout2.minicart" template="payson/checkout2/elements/minicartbutton.phtml" />
80
+ </reference>
81
+
82
+ <reference name="head">
83
+ <action method="addItem"><type>skin_css</type><name>css/payson_checkout2/style.css</name></action>
84
+ </reference>
85
+ </default>
86
+ </layout>
app/design/frontend/base/default/template/payson/checkout2/elements/button.phtml ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <a title="<?php echo $this->__('Fast checkout'); ?>" class="payson button btn-proceed-checkout btn-checkout" href="<?php echo Mage::getUrl('checkout2/express/new') ?>">
2
+ <?php echo $this->__('Fast checkout'); ?>
3
+ </a>
app/design/frontend/base/default/template/payson/checkout2/elements/minicartbutton.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <li>
2
+ <a title="<?php echo $this->__('Fast checkout'); ?>" class="payson button checkout-button" href="<?php echo Mage::getUrl('checkout2/express/new') ?>">
3
+ <?php echo $this->__('Fast checkout'); ?>
4
+ </a>
5
+ </li>
app/design/frontend/base/default/template/payson/checkout2/form/checkout2.phtml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php $helper = Mage::helper('checkout2'); ?>
2
+
3
+ <div class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
4
+ <a title="Payson internetbetalningar" href="https://www.payson.se/" target="_blank"><img src="https://www.payson.se/sites/all/files/images/external/payson150x55_n.png" alt="Payson logo"></img></a>
5
+ <br>
6
+ <p><?php echo $helper->__("The payment is completed on site through Payson's web form") ?></p>
7
+ </div
app/design/frontend/base/default/template/payson/checkout2/form/review.phtml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <div class="payson-review">
2
+ <h3><?php echo $this->__('Order Review'); ?></h3>
3
+ <?php echo $this->getChildHtml('order_review'); ?>
4
+ </div>
app/design/frontend/base/default/template/payson/checkout2/form/shipping.phtml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <div class="payson-shipping">
2
+ <h3><?php echo $this->__('Shipping Method'); ?></h3>
3
+ <?php echo $this->getChildHtml('shipping_methods'); ?>
4
+ </div>
app/design/frontend/base/default/template/payson/checkout2/page/blank.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <?php echo $this->getChildHtml('content') ?>
app/design/frontend/base/default/template/payson/checkout2/payment/confirmation.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <?php echo $this->confirmationHtml(); ?>
app/design/frontend/base/default/template/payson/checkout2/payment/express.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <?php echo $this->expressCheckoutHtml(); ?>
app/design/frontend/base/default/template/payson/checkout2/payment/standard.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <?php echo $this->standardCheckoutHtml(); ?>
app/etc/modules/Payson_Checkout2.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Payson_Checkout2>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Payson_Checkout2>
8
+ </modules>
9
+ </config>
app/locale/sv_SE/payson_checkout2.csv ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Payson", "Payson"
2
+
3
+ "Order was canceled at Payson.", "Beställningen avbröts hos Payson"
4
+ "The payment was successfully completed at Payson.", "Betalningen är avklarad hos Payson"
5
+ "Payson is not ready to cancel the order. Please try again later", "Payson är inte redo att avbryta ordern. Var god försök igen"
6
+ "Your payment is being processed by Payson.", "Er betalning är under behandling hos Payson"
7
+ "The payment was denied by Payson.", "Betalningen blev nekad."
8
+ "Something went wrong with the payment.", "Något gick fel med betalningen."
9
+ "The payment was expired by Payson.", "Betalningen har utgått hos Payson."
10
+ "Payson completed the order payment.", "Betalningen är avklarad hos Payson"
11
+ "The payment is completed on site through Payson's web form", "Betalningen slutförs direkt på sidan genom Paysons webbformulär"
12
+ "Money have been paid to account by Payson.", "Payson har betalat ut pengar till konto"
13
+ "Order has been marked as shipped at Payson.", "Betsällningen har blivit markerad som skickad hos Payson"
14
+ "Payment was credited at Payson", "Betalningen blev krediterad hos Payson"
15
+ "Unable to ship order: %s. It must have status ""readyToShip"" but it´s current status is: ""%s"".", "Kunde inte skicka order: %s. Den måste ha status ""readyToShip"" men nuvarande status är: ""%s""."
16
+ "Unable to ship order: %s. No Payson checkout ID was found.", "Kunde inte skicka order: %s. Hittade inget Payson ID."
17
+ "Unable to refund order: %s. It must have status ""shipped"" but it´s current status is: ""%s""", "Kunde inte kreditera order: %s. Den måste ha status ""paidToAccount"" men nuvarande status är: ""%s"""
18
+ "Order from %s", "Order från %s"
19
+
20
+ "White", "Vit"
21
+ "Blue", "Blå"
22
+ "Gray", "Grå"
23
+ "White with text logos", "Vit med textloggor"
24
+ "Gray with text logos", "Grå med textloggor"
25
+ "Blue with text logos", "Blå med textloggor"
26
+
27
+ "None", "Ingen"
28
+ "BankID", "BankID"
29
+
30
+ "Enabled", "Aktiverad"
31
+ "Enable/disable payment with Payson", "Aktivera eller inaktivera betalning med Payson"
32
+
33
+ "Test mode", "Testläge"
34
+ "Enable when using a sandboxed test agent", "Aktivera för användning av testagent"
35
+
36
+ "Agent ID", "Agent ID"
37
+ "Agent ID is found on your Payson profile page", "Logga in på Paysons webbplats för att hämta ditt Agent ID"
38
+
39
+ "API key", "API-nyckel"
40
+ "API key is found on your Payson profile page", "Logga in på Paysons webbplats för att hämta din MD5-nyckel"
41
+
42
+ "Terms and Conditions URL", "URL till köpvillkor"
43
+ "These terms will be linked to by the payment form", "Betalningsformuläret kommer att länka till denna URL"
44
+
45
+ "Color theme", "Färgtema"
46
+ "The color theme of the checkout form", "Betalningsformulärets färgtema"
47
+
48
+ "Extra customer verification", "Extra verifieringssteg"
49
+ "An extra customer verification method", "Välj ett ett extra verifieringssteg"
50
+
51
+ "Request phone", "Begär telefonnummer"
52
+ "Require user to fill in phone number", "Kräv att användaren fyller i sitt telefonnummer"
53
+
54
+ "Restore cart on cancel", "Återställ kundvagn vid avbryt"
55
+ "Restore cart when customer cancel the payment", "Återställ kundvagnen när kunden avbryter betalningen"
56
+
57
+ "Restore cart on error", "Återställ kundvagn vid fel"
58
+ "Restore cart when status from Payson is error", "Återställ kundvagnen när det upstår ett fel hos Payson"
59
+
60
+ "Fast checkout", "Gå till snabbkassan"
js/payson/checkout2/express.js ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ (function($, settings) {
4
+ var payson = undefined;
5
+ var prevAddress = undefined;
6
+ var controlCookie = undefined;
7
+ var isUpdating = false
8
+
9
+ $(function () {
10
+ payson = document.getElementById('paysonIframe');
11
+
12
+ Mage.Cookies.path = '/';
13
+ Mage.Cookies.set(settings.checkoutId, settings.controlKey);
14
+
15
+ this.checkIfCartWasUpdated = setInterval((function() {
16
+ if (!settings.checkoutId || isUpdating) {
17
+ return true;
18
+ }
19
+
20
+ var controlKey = Mage.Cookies.get(settings.checkoutId);
21
+
22
+ if (controlKey && controlKey != settings.controlKey) {
23
+ updateCheckout();
24
+ settings.controlKey = controlKey;
25
+ }
26
+ }).bind(this), 1000);
27
+ });
28
+
29
+ $(document).on('change', 'input[name=shipping_method]:radio', function () {
30
+ var methodName = $(this).val();
31
+ var postData = { method: methodName };
32
+
33
+ updateCheckout(postData);
34
+ });
35
+
36
+ document.addEventListener('PaysonEmbeddedAddressChanged', function(evt) {
37
+ var address = evt.detail;
38
+ address.setAddress = true
39
+
40
+ if (JSON.stringify(address) === JSON.stringify(prevAddress)) {
41
+ return;
42
+ }
43
+
44
+ prevAddress = address;
45
+
46
+ updateCheckout(address);
47
+ });
48
+
49
+ function updateCheckout(data) {
50
+ lockPaysonForm();
51
+
52
+ // Sidebar is reloaded on updates
53
+ $('.sidebar').load('/checkout2/express/update .payson-shipping, .payson-review', data, function(responseData) {
54
+ if (responseData === 'empty_cart') {
55
+ window.location = '/checkout/cart'
56
+ return;
57
+ }
58
+
59
+ releasePaysonForm();
60
+ updatePaysonForm();
61
+ });
62
+ }
63
+
64
+ function updatePaysonForm() {
65
+ payson.contentWindow.postMessage('updatePage', '*');
66
+ }
67
+
68
+ function lockPaysonForm() {
69
+ payson.contentWindow.postMessage('lock', '*');
70
+ isUpdating = true;
71
+ }
72
+
73
+ function releasePaysonForm() {
74
+ payson.contentWindow.postMessage('release', '*');
75
+ isUpdating = false;
76
+ }
77
+ })($j, window.PaysonSettings = window.PaysonSettings || {});
78
+
lib/Payson/Checkout2/PaysonCheckout2PHP/README.md ADDED
@@ -0,0 +1 @@
 
1
+ # PaysonCheckout2
lib/Payson/Checkout2/PaysonCheckout2PHP/cancel_order.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <body>
3
+ <form method="post">
4
+ CheckoutId to cancel: <input type="text" name="checkoutId" size=40 value="<?php echo isset($_POST['checkoutId'])?$_POST['checkoutId']:"";?>" />
5
+ <button type="submit">Continue</button>
6
+ </form>
7
+
8
+
9
+ <?php
10
+
11
+ require_once 'config.php';
12
+
13
+ // Get the details about this purchase with the checkoutID.
14
+ if(isset($_POST['checkoutId'])) {
15
+ $callPaysonApi = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $environment);
16
+ $checkout = $callPaysonApi->GetCheckout($_POST['checkoutId']);
17
+
18
+ $callPaysonApi->CancelCheckout($checkout);
19
+
20
+ print "<h3>Checkout cancelled</h3>";
21
+
22
+ } else {
23
+ print "<H3>Enter checkoutId</h3>";
24
+ }
25
+
26
+ ?>
27
+
28
+ </body>
29
+ </html>
30
+
31
+
32
+
lib/Payson/Checkout2/PaysonCheckout2PHP/example/cancel_order.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <body>
3
+ <form method="post">
4
+ CheckoutId to cancel: <input type="text" name="checkoutId" size=40 value="<?php echo isset($_POST['checkoutId'])?$_POST['checkoutId']:"";?>" />
5
+ <button type="submit">Continue</button>
6
+ </form>
7
+
8
+
9
+ <?php
10
+
11
+ require_once 'config.php';
12
+
13
+ // Get the details about this purchase with the checkoutID.
14
+ if(isset($_POST['checkoutId'])) {
15
+ $callPaysonApi = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $environment);
16
+ $checkout = $callPaysonApi->GetCheckout($_POST['checkoutId']);
17
+
18
+ $callPaysonApi->CancelCheckout($checkout);
19
+
20
+ print "<h3>Checkout cancelled</h3>";
21
+
22
+ } else {
23
+ print "<H3>Enter checkoutId</h3>";
24
+ }
25
+
26
+ ?>
27
+
28
+ </body>
29
+ </html>
30
+
31
+
32
+
lib/Payson/Checkout2/PaysonCheckout2PHP/example/config.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ error_reporting(E_ALL);
4
+ ini_set("display_errors", 1);
5
+ /*
6
+ * Payson API Integration example for PHP (Payson Checkout 2.0)
7
+ *
8
+ * More information can be found att https://api.payson.se
9
+ *
10
+ */
11
+
12
+ /*
13
+ * On every page you need to use the API you
14
+ * need to include the file lib/paysonapi.php
15
+ * from where you installed it.
16
+ */
17
+ require_once '../lib/paysonapi.php';
18
+
19
+ /*
20
+ * Account information. Below is all the variables needed to perform a purchase with
21
+ * payson. Replace the placeholders with your actual information
22
+ */
23
+
24
+ // Your merchant ID and apikey. Information about the merchant and the integration.
25
+ $merchantId = "";
26
+ $apiKey = "";
27
+ $environment = true;
28
+ if ($environment == false) {
29
+ //$environment = false;
30
+ $merchantId = "ENTER YOUR MERCHANT ID";
31
+ $apiKey = "ENTER YOUR API KEY";
32
+ } else {
33
+ $environment = true;
34
+ $merchantId = "4";
35
+ $apiKey = "2acab30d-fe50-426f-90d7-8c60a7eb31d4";
36
+ }
37
+
38
+ // URLs used by payson for redirection after a completed/canceled/notification purchase.
39
+ $checkoutUri = "http://my.local/phpAPI/example/checkout.php";
40
+ $confirmationUri = "http://my.local/phpAPI/example/confirmation.php";
41
+ $notificationUri = "http://my.local/phpAPI/example/notification.php";
42
+ $termsUri = "http://my.local/phpAPI/example/terms.php";
43
+
44
+ ?>
lib/Payson/Checkout2/PaysonCheckout2PHP/example/confirmation.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'config.php';
4
+
5
+ // Get the details about this purchase with the checkoutID.
6
+ $checkoutId = 'ENTER THE CHECKOUT ID';
7
+ $callPaysonApi = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $environment);
8
+
9
+ $checkout = $callPaysonApi->GetCheckout($checkoutId);
10
+
11
+ if($checkout->status == 'canceled'){
12
+ echo '<H3> canceled .... </H3>';
13
+ }elseif($checkout->status == 'readyToShip'){
14
+ echo "Purchase has been completed <br /><h4>Details</h4><pre>" ;
15
+ echo '<pre>';print_r($checkout);echo '</pre>';
16
+ }elseif($checkout->status == 'denied'){
17
+ echo "The purchase is denied by any reason <br /><h4>Details</h4><pre>" ;
18
+ echo '<pre>';print_r($checkout);echo '</pre>';
19
+ }else {
20
+ echo '<H3>Something happened when .... </H3>';
21
+ }
22
+ ?>
lib/Payson/Checkout2/PaysonCheckout2PHP/example/index.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'config.php';
4
+
5
+ /*
6
+ * Step 1: Set up details
7
+ */
8
+
9
+ $callPaysonApi = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $environment);
10
+ $paysonMerchant = new PaysonEmbedded\Merchant($checkoutUri, $confirmationUri, $notificationUri, $termsUri);
11
+ //$paysonMerchant->reference = '121212';
12
+
13
+ $payData = new PaysonEmbedded\PayData(PaysonEmbedded\CurrencyCode::SEK);
14
+
15
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem('Test product', 500, 1, 0.25, 'MD0', PaysonEmbedded\OrderItemType::PHYSICAL, 0, 'ean12345', 'http://uri', 'http://imageUri'));
16
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem('discount', -20, 1, 0.1, 'a',PaysonEmbedded\OrderItemType::DISCOUNT));
17
+
18
+
19
+ $gui = new PaysonEmbedded\Gui('sv', 'blue', 'none', 0);
20
+ $customer = new PaysonEmbedded\Customer('Firstname', 'Lastname', 'test@test.com', 'Phone', '8765432100', 'City', 'Country', '99999', 'Street');
21
+ $checkout = new PaysonEmbedded\Checkout($paysonMerchant, $payData, $gui,$customer);
22
+
23
+ /*
24
+ * Step 2 Create checkout
25
+ */
26
+
27
+ $checkoutId = $callPaysonApi->CreateCheckout($checkout);
28
+
29
+ /*
30
+ * Step 3 Get checkout object
31
+ */
32
+
33
+ $checkout = $callPaysonApi->GetCheckout($checkoutId);
34
+
35
+ /*
36
+ * Step 4 Print out checkout html
37
+ */
38
+
39
+ print '<h1 style="text-align:center"> CheckoutId:'.$checkout->id.'</h1>';
40
+ print '<div style="width:600px; margin-left:auto; margin-right:auto;">';
41
+ echo $checkout->snippet;
42
+ print "</div>";
43
+
44
+ ?>
lib/Payson/Checkout2/PaysonCheckout2PHP/example/notification.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Fetch the checkoutID that are returned
3
+ $checkoutID = $_GET['checkout'];
4
+ myFile('***** HELLO IPN *****');
5
+ myFile($checkoutID);
6
+
7
+ function myFile($arg, $arg2 = NULL) {
8
+ $myFile = "notificationFile.txt";
9
+ if($myFile == NULL){
10
+ $myFile = fopen($myFile, "w+");
11
+ fwrite($fh, "\r\n".date("Y-m-d H:i:s")."Remove the file notificationFile.txt when you want. The file auto creates by ipn-call");
12
+ }
13
+ $fh = fopen($myFile, 'a') or die("can't open file");
14
+ fwrite($fh, "\r\n".date("Y-m-d H:i:s")." **");
15
+ fwrite($fh, $arg.'**');
16
+ fwrite($fh, $arg2);
17
+ fclose($fh);
18
+ }
19
+ ?>
lib/Payson/Checkout2/PaysonCheckout2PHP/example/update_order.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'config.php';
4
+
5
+ $callPaysonApi = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $environment);
6
+ $paysonMerchant = new PaysonEmbedded\Merchant($checkoutUri, $confirmationUri, $notificationUri, $termsUri);
7
+ $payData = new PaysonEmbedded\PayData(PaysonEmbedded\CurrencyCode::SEK);
8
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem('Test product', 500, 1, 0.25, 'MD0'));
9
+
10
+
11
+ $customer = new PaysonEmbedded\Customer('firstName', 'lastName', 'email', 'phone', 'identityNumber', 'city', 'country', 'postalCode', 'street');
12
+ $gui = new PaysonEmbedded\Gui('sv', 'gray', 'none', 0);
13
+ $checkout = new PaysonEmbedded\Checkout($paysonMerchant, $payData, $gui,$customer);
14
+
15
+ // Update the purchase with the checkoutID.
16
+ $checkoutId = $callPaysonApi->CreateCheckout($checkout);
17
+ $checkout = $callPaysonApi->GetCheckout($checkoutId);
18
+
19
+ $checkout->customer->email = 'test@test.com';
20
+ $checkout->customer->firstName = 'FirstName 2';
21
+ $checkout->customer->identityNumber = '99999999';
22
+ $checkout->gui->colorScheme = 'blue';
23
+
24
+ $checkout = $callPaysonApi->UpdateCheckout($checkout);
25
+
26
+ print $checkout->snippet;
27
+
28
+
29
+
lib/Payson/Checkout2/PaysonCheckout2PHP/example/validate.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'config.php';
4
+
5
+ /*
6
+ * Step 1: Set up details
7
+ */
8
+
9
+ $callPaysonApi = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $environment);
10
+
11
+ /*
12
+ * Step 2 Validate credentials
13
+ */
14
+
15
+ try {
16
+ $account = $callPaysonApi->Validate();
17
+ print_r($account);
18
+ } catch(Exception $ex) {
19
+ print "Wrong credentials";
20
+ }
21
+
22
+
23
+
24
+
25
+ ?>
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/account.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace PaysonEmbedded{
3
+ class Account{
4
+ /** @var string $accountEmail */
5
+ public $accountEmail;
6
+ /** @var string $status */
7
+ public $status;
8
+ /** @var int $merchantId */
9
+ public $merchantId;
10
+ /** @var string $enabledForInvoice */
11
+ public $enabledForInvoice;
12
+ /** @var string $enabledForPaymentPlan */
13
+ public $enabledForPaymentPlan;
14
+
15
+
16
+ public function __construct($accountEmail, $status, $merchantId, $enabledForInvoice, $enabledForpaymentPlan){
17
+ $this->accountEmail = $accountEmail;
18
+ $this->status = $status;
19
+ $this->merchantId = $merchantId;
20
+ $this->enabledForInvoice = $enabledForInvoice;
21
+ $this->enabledForpaymentPlan = $enabledForpaymentPlan;
22
+ }
23
+
24
+ public static function create($data) {
25
+ return new Account($data->accountEmail,$data->status,$data->merchantId,$data->enabledForInvoice,$data->enabledForpaymentPlan);
26
+ }
27
+
28
+ public function toArray(){
29
+ return get_object_vars($this);
30
+ }
31
+ }
32
+ }
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/cancel_order.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <body>
3
+ <form method="post">
4
+ CheckoutId to cancel: <input type="text" name="checkoutId" size=40 value="<?php echo isset($_POST['checkoutId'])?$_POST['checkoutId']:"";?>" />
5
+ <button type="submit">Continue</button>
6
+ </form>
7
+
8
+
9
+ <?php
10
+
11
+ require_once 'config.php';
12
+
13
+ // Get the details about this purchase with the checkoutID.
14
+ if(isset($_POST['checkoutId'])) {
15
+ $callPaysonApi = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $environment);
16
+ $checkout = $callPaysonApi->GetCheckout($_POST['checkoutId']);
17
+
18
+ $callPaysonApi->CancelCheckout($checkout);
19
+
20
+ print "<h3>Checkout cancelled</h3>";
21
+
22
+ } else {
23
+ print "<H3>Enter checkoutId</h3>";
24
+ }
25
+
26
+ ?>
27
+
28
+ </body>
29
+ </html>
30
+
31
+
32
+
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/confirmation.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <body>
3
+ <form method="post">
4
+ CheckoutId: <input type="text" name="checkoutId" size=40 value="<?php echo isset($_POST['checkoutId'])?$_POST['checkoutId']:"";?>" />
5
+ <button type="submit">Continue</button>
6
+ </form>
7
+
8
+
9
+ <?php
10
+
11
+ require_once 'config.php';
12
+
13
+ // Get the details about this purchase with the checkoutID.
14
+ if(isset($_POST['checkoutId'])) {
15
+ $callPaysonApi = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $environment);
16
+ $checkout = $callPaysonApi->GetCheckout($_POST['checkoutId']);
17
+
18
+
19
+ if($checkout->status == 'canceled'){
20
+ echo '<H3> Checkout is canceled .... </H3>';
21
+ }elseif($checkout->status == 'created'){
22
+ echo '<H3> Checkout is created.... </H3>';
23
+
24
+ }elseif($checkout->status == 'readyToPay'){
25
+ echo '<H3> Client is ready to pay.... </H3>';
26
+ }elseif($checkout->status == 'readyToShip'){
27
+ echo "<H3> Purchase has been completed and ready to be shipped. PurchaseId: ".$checkout->purchaseId."</H3>" ;
28
+ }elseif($checkout->status == 'denied'){
29
+ echo "<H3> The purchase is denied by any reason</H3>" ;
30
+ }else {
31
+ echo '<H3>Something happened when .... </H3>';
32
+ }
33
+
34
+ $checkout->snippet = '*removed*';
35
+
36
+ echo '<BR><BR><h4>Details</h4><pre>';print_r($checkout);echo '</pre>';
37
+
38
+ } else {
39
+ print "<H3>Enter checkoutId</h3>";
40
+ }
41
+
42
+ ?>
43
+
44
+ </body>
45
+ </html>
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/customer.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace PaysonEmbedded{
3
+ class Customer{
4
+ /** @var string $city */
5
+ public $city;
6
+ /** @var string $countryCode */
7
+ public $countryCode;
8
+ /** @var int $identityNumber Date of birth YYMMDD (digits). */
9
+ public $identityNumber;
10
+ /** @var string $email */
11
+ public $email;
12
+ /** @var string $firstName */
13
+ public $firstName;
14
+ /** @var string $lastName */
15
+ public $lastName;
16
+ /** @var string $phone Phone number. */
17
+ public $phone;
18
+ /** @var string $postalCode Postal code. */
19
+ public $postalCode;
20
+ /** @var string $street Street address.*/
21
+ public $street;
22
+ /** @var string $type Type of customer ("business", "person" (default)).*/
23
+ public $type;
24
+
25
+ public function __construct($firstName = Null, $lastName = Null, $email = Null, $phone = Null, $identityNumber = Null, $city = Null, $countryCode = Null, $postalCode = Null, $street = Null, $type = 'person'){
26
+ $this->firstName = $firstName;
27
+ $this->lastName = $lastName;
28
+ $this->email = $email;
29
+ $this->phone = $phone;
30
+ $this->identityNumber = $identityNumber;
31
+ $this->city = $city;
32
+ $this->countryCode = $countryCode;
33
+ $this->postalCode = $postalCode;
34
+ $this->street = $street;
35
+ $this->type = $type;
36
+ }
37
+
38
+ public static function create($data) {
39
+ return new Customer($data->firstName,$data->lastName,$data->email,$data->phone,$data->identityNumber,$data->city,$data->countryCode,$data->postalCode,$data->street,$data->type);
40
+ }
41
+
42
+ public function toArray(){
43
+ return get_object_vars($this);
44
+ }
45
+ }
46
+ }
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/gui.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace PaysonEmbedded{
3
+ class Gui{
4
+ /** @var string $colorScheme Color scheme of the checkout snippet("white", "black", "blue" (default), "red"). */
5
+ public $colorScheme;
6
+ /** @var string $locale Used to change the language shown in the checkout snippet ("se", "fi", "en" (default)). */
7
+ public $locale;
8
+ /** @var string $verfication Can be used to add extra customer verfication ("bankid", "none" (default)). */
9
+ public $verfication;
10
+ /** @var bool $requestPhone Can be used to require the user to fill in his phone number. */
11
+ public $requestPhone;
12
+
13
+ public function __construct($locale = "sv", $colorScheme = "gray", $verfication = "none", $requestPhone = NULL){
14
+ $this->colorScheme = $colorScheme;
15
+ $this->locale = $locale;
16
+ $this->verfication = $verfication;
17
+ $this->requestPhone = $requestPhone;
18
+ }
19
+
20
+ public static function create($data) {
21
+ return new Gui($data->locale, $data->colorScheme, $data->verification, $data->requestPhone);
22
+ }
23
+
24
+ public function toArray(){
25
+ return get_object_vars($this);
26
+ }
27
+ }
28
+ }
29
+
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/index.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'config.php';
4
+
5
+ /*
6
+ * Step 1: Set up details
7
+ */
8
+
9
+ $callPaysonApi = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $environment);
10
+ $paysonMerchant = new PaysonEmbedded\Merchant($checkoutUri, $confirmationUri, $notificationUri, $termsUri, 1);
11
+
12
+ $payData = new PaysonEmbedded\PayData(PaysonEmbedded\CurrencyCode::SEK);
13
+
14
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem('Test product', 500, 1, 0.25, 'MD0', PaysonEmbedded\OrderItemType::PHYSICAL, 0, 'ean12345', 'http://uri', 'http://imageUri'));
15
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem('discount', -20, 1, 0.1, 'a',PaysonEmbedded\OrderItemType::DISCOUNT));
16
+
17
+
18
+ $gui = new PaysonEmbedded\Gui('sv', 'gray', 'none', 0);
19
+ $customer = new PaysonEmbedded\Customer('Firstname', 'Lastname', 'test@test.com', 'Phone', '4605092222', 'City', 'Country', '99999', 'Street');
20
+ $checkout = new PaysonEmbedded\Checkout($paysonMerchant, $payData, $gui,$customer);
21
+
22
+ /*
23
+ * Step 2 Create checkout
24
+ */
25
+
26
+ $checkoutId = $callPaysonApi->CreateCheckout($checkout);
27
+
28
+ /*
29
+ * Step 3 Get checkout object
30
+ */
31
+
32
+ $checkout = $callPaysonApi->GetCheckout($checkoutId);
33
+
34
+ /*
35
+ * Step 4 Print out checkout html
36
+ */
37
+
38
+ print '<h1 style="text-align:center"> CheckoutId:'.$checkout->id.'</h1>';
39
+ print '<div style="width:600px; margin-left:auto; margin-right:auto;">';
40
+ echo $checkout->snippet;
41
+ print "</div>";
42
+
43
+ ?>
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/orderitem.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace PaysonEmbedded{
3
+
4
+ abstract class OrderItemType
5
+ {
6
+ const PHYSICAL = 'physical';
7
+ const DISCOUNT = 'discount';
8
+ const SERVICE = 'service';
9
+ }
10
+
11
+ class OrderItem {
12
+
13
+ /** @var string $id */
14
+ public $itemId;
15
+ /** @var float $discountRate Discount rate of the article (Decimal number (0.00-1.00)). */
16
+ public $discountRate;
17
+ /** @var float $creditedAmount Credited amount (Decimal number (with two decimals)). */
18
+ public $creditedAmount;
19
+ /** @var url $imageUri An URI to an image of the article. */
20
+ public $imageUri;
21
+ /** @var string $name Name of the article. */
22
+ public $name;
23
+ /** @var float $unitPrice Unit price of the article (including tax). */
24
+ public $unitPrice ;
25
+ /** @var int $quantity Quantity of the article. */
26
+ public $quantity;
27
+ /** @var float taxRate Tax rate of the article (0.00-1.00). */
28
+ public $taxRate;
29
+ /** @var string $reference Article reference, usually the article number. */
30
+ public $reference;
31
+ /** @var string $type Type of article ("Fee", "Physical" (default), "Service"). */
32
+ public $type;
33
+ /** @var url $uri URI to a the article page of the order item. */
34
+ public $uri;
35
+ /** @var ean $ean European Article Number. Discrete number (13 digits) */
36
+ public $ean;
37
+
38
+ /**
39
+ * Constructs an OrderItem object
40
+ *
41
+ * If any other value than description is provided all of them has to be entered
42
+ *
43
+ * @param string $name Name of order item. Max 128 characters
44
+ * @param float $unitPrice Unit price incl. VAT
45
+ * @param int $quantity Quantity of this item. Can have at most 2 decimal places
46
+ * @param float $taxRate Tax value. Not actual percentage. For example, 25% has to be entered as 0.25
47
+ * @param string $reference Sku of item
48
+ */
49
+ public function __construct($name, $unitPrice, $quantity, $taxRate, $reference, $type=OrderItemType::PHYSICAL, $discountRate=null, $ean = null, $uri=null, $imageUri=null) {
50
+ // Mandatory
51
+ $this->name = $name;
52
+ $this->unitPrice = $unitPrice;
53
+ $this->quantity = $quantity;
54
+ $this->taxRate = $taxRate;
55
+ $this->type = $type;
56
+ $this->reference = $reference;
57
+
58
+ if(!$name || is_null($unitPrice) || !$quantity || is_null($taxRate) || !$type || !$reference) {
59
+ throw new PaysonApiException("Not all of mandatory fields are set for creating of an OrderItem object");
60
+ }
61
+
62
+ // Optional
63
+ $this->discountRate = $discountRate;
64
+ $this->ean = $ean;
65
+ $this->uri = $uri;
66
+ $this->imageUri = $imageUri;
67
+ }
68
+
69
+ public static function create($data) {
70
+ $item = new OrderItem($data->name, $data->unitPrice, $data->quantity, $data->taxRate, $data->reference, $data->type, isset($data->discountRate)?$data->discountRate:null, isset($data->ean)?$data->ean:null, isset($data->uri)?$data->uri:null, isset($data->imageUri)?$data->imageUri:null);
71
+ $item->discountRate=$data->discountRate;
72
+ $item->creditedAmount=$data->creditedAmount;
73
+ if(isset($data->itemId)) {
74
+ $item->itemId = $data->itemId;
75
+ }
76
+ return $item;
77
+ }
78
+
79
+ public function toArray() {
80
+ return get_object_vars($this);
81
+ }
82
+ }
83
+ }
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paydata.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace PaysonEmbedded{
3
+ require_once "orderitem.php";
4
+ abstract class CurrencyCode {
5
+ const SEK = "SEK";
6
+ const EUR = "EUR";
7
+ }
8
+
9
+ class PayData {
10
+ /** @var string $currency Currency of the order ("sek", "eur"). */
11
+ public $currency = NULL;
12
+ /** @var array $items An array with objects of the order items*/
13
+ public $items = array();
14
+
15
+ /** @var float $totalPriceExcludingTax - Read only */
16
+ public $totalPriceExcludingTax;
17
+ /** @var float $totalPriceIncludingTax - Read only */
18
+ public $totalPriceIncludingTax;
19
+ /** @var float $totalTaxAmount - Read only */
20
+ public $totalTaxAmount;
21
+ /** @var float $totalCreditedAmount - Read only */
22
+ public $totalCreditedAmount;
23
+
24
+ public function __construct($currencyCode) {
25
+ $this->currency = $currencyCode;
26
+ $this->items = array();
27
+ }
28
+
29
+ public static function create($data) {
30
+ $payData = new PayData($data->currency);
31
+ $payData->totalPriceExcludingTax = $data->totalPriceExcludingTax;
32
+ $payData->totalPriceIncludingTax = $data->totalPriceIncludingTax;
33
+ $payData->totalTaxAmount = $data->totalTaxAmount;
34
+ $payData->totalCreditedAmount =$data->totalCreditedAmount;
35
+
36
+ foreach($data->items as $item) {
37
+ $payData->items[] = OrderItem::create($item);
38
+ }
39
+
40
+ return $payData;
41
+ }
42
+
43
+ public function AddOrderItem(OrderItem $item) {
44
+ $this->items[] = $item;
45
+ }
46
+
47
+ public function setOrderItems($items) {
48
+ if(!($items instanceof OrderItem))
49
+ throw new PaysonApiException("Parameter must be an object of class Item");
50
+
51
+ $this->items = $items;
52
+ }
53
+
54
+ public function toArray(){
55
+ $items = array();
56
+ foreach($this->items as $item) { $items[] = $item->toArray(); }
57
+ return array( 'currency'=>$this->currency, 'items'=>$items );
58
+ }
59
+
60
+ public function toJson(){
61
+ return json_encode($this->toArray());
62
+ }
63
+ }
64
+ }
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonapi.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace PaysonEmbedded {
4
+ require_once "paysonapiexception.php";
5
+ require_once "paysonapierror.php";
6
+ require_once "paydata.php";
7
+ require_once "paysonmerchant.php";
8
+ require_once "customer.php";
9
+ require_once "gui.php";
10
+ require_once "paysoncheckout.php";
11
+ require_once "account.php";
12
+ }
13
+
14
+ namespace PaysonEmbedded {
15
+
16
+ class PaysonApi {
17
+
18
+ private $merchantId;
19
+ private $apiKey;
20
+ private $protocol = "https://%s";
21
+ const PAYSON_HOST = "api.payson.se/2.0/";
22
+ const ACTION_CHECKOUTS = "Checkouts/";
23
+ const ACTION_ACCOUNTS = "Accounts/";
24
+ private $paysonMerchant = NULL;
25
+ private $payData = NULL;
26
+ private $customer = NULL;
27
+ private $allOrderData = array();
28
+ private $gui = NULL;
29
+ private $useTestEnvironment = NULL;
30
+ private $checkoutId = NULL;
31
+ private $paysonResponse = NULL;
32
+ public $paysonResponseErrors = array();
33
+
34
+ public function __construct($merchantId, $apiKey, $useTestEnvironment = false) {
35
+ $this->useTestEnvironment = $useTestEnvironment;
36
+ $this->merchantId =$merchantId;
37
+ $this->apiKey = $apiKey;
38
+
39
+ if (!function_exists('curl_exec')) {
40
+ throw new PaysonApiException('Curl not installed. Is required for PaysonApi.');
41
+ }
42
+ }
43
+
44
+ public function getMerchantId() {
45
+ return $this->merchantId;
46
+ }
47
+
48
+ public function getApiKey() {
49
+ return $this->apiKey;
50
+ }
51
+
52
+ public function CreateCheckout(Checkout $checkout) {
53
+ $result = $this->doCurlRequest('POST', $this->getUrl(self::ACTION_CHECKOUTS), $checkout->toArray());
54
+ $checkoutId = $this->extractCheckoutId($result);
55
+ if(!$checkoutId) {
56
+ throw new PaysonApiException("Checkout Id not received of unclear reason");
57
+ }
58
+ return $checkoutId;
59
+ }
60
+
61
+ public function UpdateCheckout($checkout) {
62
+ if(!$checkout->id) {
63
+ throw new PaysonApiException("Checkout object which should be updated must have id property set");
64
+ }
65
+ $result = $this->doCurlRequest('PUT', $this->getUrl(self::ACTION_CHECKOUTS).$checkout->id, $checkout->toArray());
66
+ return $checkout;
67
+ }
68
+
69
+ public function GetCheckout($checkoutId) {
70
+ $result = $this->doCurlRequest('GET', $this->getUrl(self::ACTION_CHECKOUTS).$checkoutId, null);
71
+ return Checkout::create(json_decode($result));
72
+ }
73
+
74
+ public function ShipCheckout(Checkout $checkout) {
75
+ $checkout->status = 'shipped';
76
+ return $this->UpdateCheckout($checkout);
77
+ }
78
+
79
+ public function CancelCheckout(Checkout $checkout) {
80
+ $checkout->status = 'canceled';
81
+ return $this->UpdateCheckout($checkout);
82
+ }
83
+
84
+ public function Validate() {
85
+ $result = $this->doCurlRequest('GET', $this->getUrl(self::ACTION_ACCOUNTS), null);
86
+ return Account::create(json_decode($result));
87
+ }
88
+
89
+ private function doCurlRequest($method, $url, $postfields) {
90
+ $ch = curl_init($url);
91
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $this->authorizationHeader());
92
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
93
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
94
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields?json_encode($postfields):null);
95
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
96
+ curl_setopt($ch, CURLOPT_HEADER, TRUE);
97
+ $result = curl_exec($ch);
98
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
99
+ $body = substr($result, $header_size);
100
+ $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
101
+ curl_close($ch);
102
+
103
+ /* This class of status codes indicates the action requested by the client was received, understood, accepted and processed successfully
104
+ * 200 OK
105
+ * 201 Created
106
+ * 202 Accepted
107
+ * 203 Non-Authoritative Information (since HTTP/1.1)
108
+ */
109
+ if ($response_code == 200) {
110
+ return $body;
111
+ } elseif ($response_code == 201) {
112
+ return $result;
113
+ } elseif ($result == false) {
114
+ throw new PaysonApiException('Curl error: '.curl_error($ch));
115
+ } else {
116
+ $errors = array();
117
+
118
+ $data = json_decode($body,true);
119
+ $errors[] = new PaysonApiError('HTTP status code: ' . $response_code.', '.$data['message'], NULL);
120
+
121
+ if(isset($data['errors']) && count($data['errors'])) {
122
+ $errors = array_merge($errors, $this->parseErrors($data['errors'], $response_code));
123
+ }
124
+
125
+ throw new PaysonApiException("Api errors", $errors);
126
+ }
127
+
128
+ }
129
+
130
+ private function authorizationHeader() {
131
+ $header = array();
132
+ $header[] = 'Content-Type: application/json';
133
+ $header[] = 'Authorization: Basic ' . base64_encode($this->merchantId . ':' . $this->apiKey);
134
+ return $header;
135
+ }
136
+
137
+
138
+ private function extractCheckoutId($result) {
139
+ $checkoutId = null;
140
+ if (preg_match('#Location: (.*)#', $result, $res)) {
141
+ $checkoutId = trim($res[1]);
142
+ }
143
+ $checkoutId = explode('/', $checkoutId);
144
+ $checkoutId = $checkoutId[count($checkoutId) - 1];
145
+ return $checkoutId;
146
+ }
147
+
148
+ private function parseErrors($responseErrors, $response_code) {
149
+ $errors = array();
150
+ foreach ($responseErrors as $error) {
151
+ $errors[] = new PaysonApiError($error['message'], (isset($error['property'])?$error['property']:null));
152
+ }
153
+ return $errors;
154
+ }
155
+
156
+ public function setStatus($status) {
157
+ $this->allOrderData['status'] = $status;
158
+ }
159
+
160
+ private function getUrl($action) {
161
+ return (sprintf($this->protocol, ($this->useTestEnvironment ? 'test-' : '')) . self::PAYSON_HOST.$action);
162
+ }
163
+
164
+
165
+ }
166
+
167
+ }
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonapierror.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace PaysonEmbedded{
3
+ class PaysonApiError {
4
+ public $message = NULL;
5
+ public $parameter = NULL;
6
+
7
+ public function __construct($message, $parameter = null) {
8
+ $this->message = $message;
9
+ $this->parameter = $parameter;
10
+ }
11
+ public function __toString() {
12
+ return "Message: " . $this->message . "\t Parameter: " . $this->parameter;
13
+ }
14
+
15
+ }
16
+ }
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonapiexception.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace PaysonEmbedded{
3
+ class PaysonApiException extends \Exception {
4
+ private $errors = array();
5
+
6
+ public function getErrorList() {
7
+ return $this->errors;
8
+ }
9
+
10
+ public function getErrors() {
11
+ $r = '';
12
+ if(count($this->errors)) {
13
+ foreach ($this->errors as $error){
14
+ $r.='<pre>'.$error->message . ($error->parameter?' -- Parameter: ' .$error->parameter:'').'</pre>';
15
+ }
16
+ } else {
17
+ $r .= $this->getMessage();
18
+ }
19
+ return $r;
20
+ }
21
+
22
+ public function __construct($message,array $errors = array()) {
23
+ $this->errors = $errors;
24
+ if(count($errors)) {
25
+ $message .="\n\n"; foreach($errors as $error) { $message .= "\n".$error."\n"; } $message .="\n\n";
26
+ }
27
+ parent::__construct($message);
28
+ }
29
+
30
+ }
31
+ }
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paysoncheckout.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace PaysonEmbedded {
3
+ class Checkout {
4
+ /** @var Merchant $merchant */
5
+ public $merchant;
6
+
7
+ /** @var PayData $order */
8
+ public $payData;
9
+
10
+ /** @var Gui $gui */
11
+ public $gui;
12
+
13
+ /** @var Customer $customer */
14
+ public $customer;
15
+
16
+ /** @var string $status */
17
+ public $status;
18
+
19
+ /** @var string $id */
20
+ public $id;
21
+
22
+ /** @var int $purchaseId */
23
+ public $purchaseId;
24
+
25
+ /** @var string $snippet */
26
+ public $snippet;
27
+
28
+ /** @var string $description */
29
+ public $description;
30
+
31
+ public function __construct(Merchant $merchant, PayData $payData, Gui $gui = null, Customer $customer = null, $description = '') {
32
+ $this->merchant = $merchant;
33
+ $this->payData = $payData;
34
+ $this->gui = $gui?:new Gui();
35
+ $this->customer = $customer?:new Customer();
36
+ $this->purchaseId = null;
37
+ $this->description = $description;
38
+ }
39
+
40
+ public static function create($data) {
41
+ $checkout = new Checkout(Merchant::create($data->merchant), PayData::create($data->order), Gui::create($data->gui), Customer::create($data->customer));
42
+ $checkout->status = $data->status;
43
+ $checkout->id = $data->id;
44
+ $checkout->snippet = $data->snippet;
45
+ if(isset($data->purchaseId)) {
46
+ $checkout->purchaseId = $data->purchaseId;
47
+ }
48
+
49
+ if(isset($data->description)) {
50
+ $checkout->description = $data->description;
51
+ }
52
+ return $checkout;
53
+ }
54
+
55
+ public function toArray() {
56
+ return array(
57
+ 'id' => $this->id,
58
+ 'description' => $this->description,
59
+ 'status' => $this->status,
60
+ 'merchant' => $this->merchant->toArray(),
61
+ 'order' => $this->payData->toArray(),
62
+ 'gui' => $this->gui->toArray(),
63
+ 'customer' => $this->customer->toArray()
64
+ );
65
+ }
66
+ }
67
+ }
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/paysonmerchant.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace PaysonEmbedded {
3
+ class Merchant {
4
+ /** @var url $checkoutUri URI to the merchants checkout page.*/
5
+ public $checkoutUri = NULL;
6
+ /** @var url $confirmationUri URI to the merchants confirmation page. */
7
+ public $confirmationUri;
8
+ /** @var url $notificationUri Notification URI which receives CPR-status updates. */
9
+ public $notificationUri;
10
+ /** @var url $verificationUri Validation URI which is called to verify an order before it can be paid. */
11
+ public $validationUri = NULL;
12
+ /** @var url $termsUri URI leading to the sellers terms. */
13
+ public $termsUri;
14
+ /** @var string $reference Merchants own reference of the checkout.*/
15
+ public $reference = NULL;
16
+ /** @var string $partnerId Partners unique identifier */
17
+ public $partnerId = NULL;
18
+ /** @var string $integrationInfo Information about the integration. */
19
+ public $integrationInfo = NULL;
20
+
21
+ public function __construct($checkoutUri, $confirmationUri, $notificationUri, $termsUri, $partnerId = NULL, $integrationInfo = 'PaysonCheckout2.0|1.0|NONE') {
22
+ $this->checkoutUri = $checkoutUri;
23
+ $this->confirmationUri = $confirmationUri;
24
+ $this->notificationUri = $notificationUri;
25
+ $this->termsUri = $termsUri;
26
+ $this->partnerId = $partnerId;
27
+ $this->integrationInfo = $integrationInfo;
28
+ }
29
+
30
+ public static function create($data) {
31
+ $merchant = new Merchant($data->checkoutUri,$data->confirmationUri,$data->notificationUri,$data->termsUri, $data->partnerId, $data->integrationInfo);
32
+ $merchant->reference=$data->reference;
33
+ $merchant->validationUri=$data->validationUri;
34
+ return $merchant;
35
+ }
36
+
37
+ public function toArray(){
38
+ return get_object_vars($this);
39
+ }
40
+ }
41
+ }
lib/Payson/Checkout2/PaysonCheckout2PHP/lib/update_order.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once 'config.php';
4
+
5
+ $callPaysonApi = new PaysonEmbedded\PaysonApi($merchantId, $apiKey, $environment);
6
+ $paysonMerchant = new PaysonEmbedded\Merchant($checkoutUri, $confirmationUri, $notificationUri, $termsUri, 1);
7
+ $payData = new PaysonEmbedded\PayData(PaysonEmbedded\CurrencyCode::SEK);
8
+ $payData->AddOrderItem(new PaysonEmbedded\OrderItem('Test product', 500, 1, 0.25, 'MD0'));
9
+
10
+
11
+ $customer = new PaysonEmbedded\Customer('firstName', 'lastName', 'email', 'phone', 'identityNumber', 'city', 'country', '99999', 'street');
12
+ $gui = new PaysonEmbedded\Gui('sv', 'gray', 'none', 0);
13
+ $checkout = new PaysonEmbedded\Checkout($paysonMerchant, $payData, $gui,$customer);
14
+
15
+ // Update the purchase with the checkoutID.
16
+ $checkoutId = $callPaysonApi->CreateCheckout($checkout);
17
+ $checkout = $callPaysonApi->GetCheckout($checkoutId);
18
+
19
+ $checkout->customer->email = 'test@test.com';
20
+ $checkout->customer->firstName = 'FirstName 2';
21
+ $checkout->customer->identityNumber = '9999999999';
22
+ $checkout->gui->colorScheme = 'blue';
23
+
24
+ $checkout = $callPaysonApi->UpdateCheckout($checkout);
25
+
26
+ print $checkout->snippet;
27
+
28
+
29
+
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>PaysonCheckout2</name>
4
+ <version>1.0.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://opensource.org/licenses/bsd-license.php">BSD licence</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Official Payson module for Magento.</summary>
10
+ <description>Payson offers a simple way to receive payments from your customers using Visa, MasterCard, Direct bank transfer and WyWallet with one contract.</description>
11
+ <notes>New modul PaysonCheckout2</notes>
12
+ <authors><author><name>Oscar</name><user>PaysonAB</user><email>integration@payson.se</email></author></authors>
13
+ <date>2016-11-29</date>
14
+ <time>14:16:15</time>
15
+ <contents><target name="magecommunity"><dir name="Payson"><dir name="Checkout2"><dir name="Block"><dir name="Form"><file name="Checkout2.php" hash="2b67b75d9478b60388df76b60cbee459"/></dir><dir name="Info"><file name="Checkout2.php" hash="d577097f022794f5cd7a12fa88b17933"/></dir><file name="Payment.php" hash="9d9fd75b69580db7cccd60b225553690"/></dir><dir name="Helper"><file name="Data.php" hash="766f354fc4bccd415301b787b0fbd4f9"/><file name="Order.php" hash="9ca9486999de387069556bf4777cbfdf"/></dir><dir name="Model"><file name="Config.php" hash="98791c265d914dfc8fa2d3bde5cbbdc1"/><dir name="Method"><file name="Checkout2.php" hash="d68ba56d9de974b77cc23a38df10c5a2"/></dir><file name="Notification.php" hash="7f7466bb8ce9ecdfc84f53a986c040c4"/><file name="Observer.php" hash="d5bc3717b51265d4b7b335debd23395c"/><file name="Order.php" hash="7caf0306a00499dbce2c756eeb7fdbc0"/><file name="Themes.php" hash="30c39fad25db4883bfbed8c79687958f"/><file name="VerificationTypes.php" hash="e8a9bccb0203a2af8140b3858684be56"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="ShipmentController.php" hash="1c8aeb17a1e55816fd1736d26224bb58"/></dir></dir></dir><file name="ExpressController.php" hash="4f7871835f0cdad74455a77a4150d56e"/><file name="NotificationController.php" hash="f3cba6067ac6fe9cc5060f1ce52eca6a"/><file name="PaymentController.php" hash="e70cfe80ef6aed32f6aba51d03a092ee"/></dir><dir name="etc"><file name="config.xml" hash="908d9295cdcdf73d85462f1d09e7eea6"/><file name="system.xml" hash="d2b161347c5c7cd4cf5d22080e141f26"/></dir><dir name="sql"><dir name="payson_checkout2_setup"><file name="mysql4-install-1.0.0.php" hash="c4139a6d4e830aa554b6d7cd106e4e25"/></dir></dir></dir><dir name="Payson"><dir name="Block"><file name="Form.php" hash="74a8967879fbb6af999f0e513bc91323"/><dir name="Invoice"><file name="Form.php" hash="88a008948e1231b135ba8a798eeb1c66"/></dir><dir name="Order"><dir name="Totals"><file name="Fee.php" hash="3e8566e634d68d8df9bb70f597916980"/></dir></dir><dir name="Standard"><file name="Form.php" hash="c715cbec95494a9a26d261992429dff0"/></dir></dir><dir name="Helper"><dir name="Api"><dir name="Response"><file name="Interface.php" hash="51d0ffe7eefaa12eb9b4f2551e9f4259"/><dir name="Standard"><file name="Parameters.php" hash="6965b8259867c23a5e1e682e14491eb2"/></dir><file name="Standard.php" hash="cef827896629364fee49671af879adc3"/><file name="Validate.php" hash="34fb6626af3a6ac06e987c9e10a95796"/></dir></dir><file name="Api.php" hash="3331e8965dfe60b18609a794fbe4c498"/><file name="Data.php" hash="83ff59b1588c0b0ff8d2f7341589ea59"/><file name="FundingConstraint.php" hash="64cb684a5d30dd237e90d5e835ccddd3"/></dir><dir name="Model"><file name="Config.php" hash="7de7a2257df64a5e039de977edbc5492"/><dir name="Method"><file name="Abstract.php" hash="dadd8d3120cd0a187af661f54ecae0f7"/><file name="Invoice.php" hash="d3825c5f72d355d0ac0798c89e2087fa"/><file name="Standard.php" hash="136579912fb4971ebd2279d29a85afc3"/></dir><dir name="Mysql4"><file name="Setup.php" hash="3075fa047af3d56d6eac609004e6e1cc"/></dir><dir name="Order"><dir name="Creditmemo"><dir name="Total"><file name="Invoice.php" hash="19fadd6df40cd03528fb9c211c34a8bc"/></dir></dir><dir name="Invoice"><dir name="Total"><file name="Invoice.php" hash="87899d88d04362bc148eb51a0a9a076e"/></dir></dir></dir><dir name="Quote"><dir name="Address"><dir name="Total"><file name="Invoice.php" hash="44eef552e2dd3869c3181f3f939ac355"/></dir></dir></dir><file name="Standard.php" hash="233cf9d7ebe15137d98a8e1b23125a51"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Paysondirectmethod.php" hash="5f0a8584217204a638d11dbf61891779"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="ShipmentController.php" hash="068143a443700a95395bdb28ae39f170"/></dir></dir></dir><file name="CheckoutController.php" hash="0bdda7fc1e239d2182b51099d777cf2f"/><file name="IpnController.php" hash="e7b092cdd0011a3a1359a084bbaf14ad"/></dir><dir name="etc"><file name="config.xml" hash="c3a06f230d79b12d3d57f4c7404dfef0"/><file name="system.xml" hash="8f0a4d417de513c9f37a5feb993b4c46"/></dir><dir name="sql"><dir name="payson_setup"><file name="mysql4-install-0.1.0.php" hash="21cd9fd3436ba1eb2fc20eaaadb42106"/><file name="mysql4-upgrade-0.1.0-0.1.2.php" hash="5bbcb930748e3a87a220c0e9f8448a15"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="payson_checkout2.xml" hash="22b3bc15951f0c383c5e6f96d7949fad"/></dir><dir name="template"><dir name="payson"><dir name="checkout2"><dir name="elements"><file name="button.phtml" hash="1f63ccf569ff10d35e51616a413955d7"/><file name="minicartbutton.phtml" hash="a575c64a333be672cb8fc6aec89382d8"/></dir><dir name="form"><file name="checkout2.phtml" hash="99419617856e6c5ea93c3cf88ae4d490"/><file name="review.phtml" hash="2908826635a38b1dfd5640a1c6feba54"/><file name="shipping.phtml" hash="abd612bee8e11baf89c8468f76b00615"/></dir><dir name="page"><file name="blank.phtml" hash="509893c584213ad7d78e17a1a53249d1"/></dir><dir name="payment"><file name="confirmation.phtml" hash="d73bb16ae4b6d2b1d333079e84aa9b55"/><file name="express.phtml" hash="6d2757865efe818d2ab213992ffe40f3"/><file name="standard.phtml" hash="0da3b1e0080df8f31d808061939b430e"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Payson_Checkout2.xml" hash="dcbe0d3d1f1cad514c719d0a79f213e0"/></dir></target><target name="magelocale"><dir name="sv_SE"><file name="payson_checkout2.csv" hash="4555f2b2f86dffe56ccbe8e7ad373866"/></dir></target><target name="magelib"><dir name="Payson"><dir name="Checkout2"><dir name="PaysonCheckout2PHP"><file name="README.md" hash="bb8c8d92c7e18353d4d9d5a496a566da"/><file name="cancel_order.php" hash="094352d0bff59f9fed593707b8596679"/><dir name="example"><file name="cancel_order.php" hash="094352d0bff59f9fed593707b8596679"/><file name="config.php" hash="45966251b3cef234834cc1d2dc966e90"/><file name="confirmation.php" hash="7a50c9e9772ccc123c6d84cc8e2fe7f3"/><file name="index.php" hash="1b3081faa0d1835641c7259db5cf3837"/><file name="notification.php" hash="d80a0d41e083fb43cce844c7d23b7338"/><file name="update_order.php" hash="ad2367147e72a88428808dfaab231366"/><file name="validate.php" hash="436f44544aa97ef039e28977ca1f6380"/></dir><dir name="lib"><file name="account.php" hash="22acb8e56a837dfaf200252d99bc023f"/><file name="cancel_order.php" hash="094352d0bff59f9fed593707b8596679"/><file name="confirmation.php" hash="e23740168f2941741ffeb308cfa6aaa9"/><file name="customer.php" hash="34f1f9d76b729938118e72721cacd8af"/><file name="gui.php" hash="e234c46d3a046fd0989ecd535c1d9eb1"/><file name="index.php" hash="eb59320117f2668f615a19ee892fcf09"/><file name="orderitem.php" hash="3081930512e0d0ae705b361a5a5c104b"/><file name="paydata.php" hash="718479d8f056d6393e89c3de85d7526e"/><file name="paysonapi.php" hash="44665885f35c04edf78405159d01a4ff"/><file name="paysonapierror.php" hash="e3712bd19b64c3fbb5b64015ce944563"/><file name="paysonapiexception.php" hash="ee5a2ddad8fc7870b5dc121386ac3ef0"/><file name="paysoncheckout.php" hash="31efedcb1d197b3e230fcea9a9deef93"/><file name="paysonmerchant.php" hash="126ad5956d6efebedf4c2d6b35de1dff"/><file name="update_order.php" hash="500f71b5fb1fb31660626e4e12d113c7"/></dir></dir></dir></dir></target><target name="mage"><dir name="js"><dir name="payson"><dir name="checkout2"><file name="express.js" hash="8185c0ef8c7f4bd006e561df0602e3c2"/></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><dir name="payson_checkout2"><file name="style.css" hash="f70e8d8d166a189383d5795620c162e3"/></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="."><file name="modman" hash=""/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.3.0</min><max>5.6.9</max></php></required></dependencies>
18
+ </package>
skin/frontend/base/default/css/payson_checkout2/style.css ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .minicart-actions .checkout-types li:first-child {
2
+ margin-left: 5px;
3
+ }
4
+
5
+ .payson.button {
6
+ background-color: #ed8d37;
7
+ }
8
+
9
+ .payson.button:hover {
10
+ background-color: #ff9a3f;
11
+ }
12
+
13
+ .payson-express .col-left {
14
+ min-width: 350px;
15
+ }
16
+
17
+ .payson-express .col-main {
18
+ width: calc(100% - 350px);
19
+ }
20
+
21
+ .payson-express .col-main > * {
22
+ max-width: 680px;
23
+ margin: 0 auto;
24
+ }
25
+
26
+ .payson-express .col2-left-layout .main {
27
+ min-height: 565px;
28
+ }
29
+
30
+ .payson-shipping, .payson-review {
31
+ margin-bottom: 3em;
32
+ margin-bottom: 3em;
33
+ }
34
+
35
+ .payson-shipping > h3, .payson-review > h3 {
36
+ border-bottom: 1px solid rgb(237, 237, 237);
37
+ margin-bottom: 1em;
38
+ }
39
+
40
+ @media only screen and (max-width: 770px) {
41
+ .payson-express .col2-left-layout .main {
42
+ display: flex;
43
+ flex-direction: column-reverse;
44
+ }
45
+ }