Craig_Tco - Version 2.4.0

Version Notes

Better Direct Checkout Integration

Download this release

Release Info

Developer Craig Christenson
Extension Craig_Tco
Version 2.4.0
Comparing to
See all releases


Code changes from version 2.3.3 to 2.4.0

app/{design/frontend/base/default/template/tco/info.phtml → code/local/Craig/Tco/Block/Iframe.php} RENAMED
@@ -19,7 +19,24 @@
19
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
  */
21
 
22
- echo $this->__('2Checkout (Credit Card, Debit Card, PayPal)');
23
- ?>
 
24
 
 
 
 
 
 
25
 
 
 
 
 
 
 
 
 
 
 
 
19
  * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
  */
21
 
22
+ class Craig_Tco_Block_Iframe extends Mage_Core_Block_Template
23
+ {
24
+ protected $_params = array();
25
 
26
+ protected function _construct()
27
+ {
28
+ parent::_construct();
29
+ $this->setTemplate('tco/iframe.phtml');
30
+ }
31
 
32
+ public function setParams($params)
33
+ {
34
+ $this->_params = $params;
35
+ return $this;
36
+ }
37
+
38
+ public function getParams()
39
+ {
40
+ return $this->_params;
41
+ }
42
+ }
app/code/local/Craig/Tco/Block/Redirect.php CHANGED
@@ -29,46 +29,29 @@ class Craig_Tco_Block_Redirect extends Mage_Core_Block_Abstract
29
 
30
  $form = new Varien_Data_Form();
31
  $form->setAction($tco->getUrl())
32
- ->setId('pay')
33
- ->setName('pay')
34
  ->setMethod('POST')
35
  ->setUseContainer(true);
36
  $tco->getFormFields();
37
  foreach ($tco->getFormFields() as $field=>$value) {
38
  $form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value, 'size'=>200));
39
  }
 
40
 
41
- $html = '<style type="text/css">
42
- .col-left { display: none; }
43
- .col-right { display: none; }
44
- </style>';
45
 
46
  if ($tco->getDisplay()) {
47
- //inline mode
48
- $html .= '<p style=text-align:center;><img style=text-align:center;cursor:pointer src="https://www.2checkout.com/upload/images/logo.png" onclick="formSubmit();" /></p><br />'.
49
- '<p style=text-align:center;>'.$tco->getRedirectMessage().'</p><br />'.
50
- '<p style=text-align:center;><img style=text-align:center;cursor:pointer src="https://www.2checkout.com/upload/images/paymentlogoshorizontal.png" onclick="formSubmit();" /></p><br />'.
51
- $form->toHtml();
52
- $html.= '<script type="text/javascript" src="https://www.2checkout.com/static/checkout/javascript/direct.min.js"></script>';
53
- $html.= '
54
- <script type="text/javascript">
55
- function formSubmit(){
56
- document.getElementById("pay").submit();
57
- var elem = document.getElementById("tco_lightbox");
58
- elem.style.display = "block";
59
- }
60
-
61
- window.onload=function(){
62
- formSubmit();
63
- };
64
- </script>';
65
  } else {
66
- //dynamic mode
67
- $html .= '<p style=text-align:center;><img style=text-align:center;cursor:pointer src="https://www.2checkout.com/upload/images/logo.png" onclick="document.location.reload()" /></p><br />'.
68
- '<p style=text-align:center;>'.$tco->getRedirectMessage().'</p><br />'.
69
- '<p style=text-align:center;><img style=text-align:center;cursor:pointer src="https://www.2checkout.com/upload/images/paymentlogoshorizontal.png" onclick="document.location.reload()" /></p><br />'.
70
- $form->toHtml();
71
- $html.= '<script type="text/javascript">function formSubmit(){ document.getElementById("pay").submit();}
72
  window.onload=function(){
73
  formSubmit();
74
  };</script>';
29
 
30
  $form = new Varien_Data_Form();
31
  $form->setAction($tco->getUrl())
32
+ ->setId('tcopay')
33
+ ->setName('tcopay')
34
  ->setMethod('POST')
35
  ->setUseContainer(true);
36
  $tco->getFormFields();
37
  foreach ($tco->getFormFields() as $field=>$value) {
38
  $form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value, 'size'=>200));
39
  }
40
+ $form->addField('tcosubmit', 'submit', array('name'=>'tcosubmit'));
41
 
42
+ $html = '<style> #tcosubmit {display:none;} </style>';
 
 
 
43
 
44
  if ($tco->getDisplay()) {
45
+ //inline mode
46
+ $html .= $form->toHtml();
47
+ $html.= '<script type="text/javascript">function formSubmit(){ document.getElementById("tcopay").submit();}
48
+ window.onload=function(){
49
+ formSubmit();
50
+ };</script>';
 
 
 
 
 
 
 
 
 
 
 
 
51
  } else {
52
+ //dynamic mode
53
+ $html .= $form->toHtml();
54
+ $html.= '<script type="text/javascript">function formSubmit(){ document.getElementById("tcopay").submit();}
 
 
 
55
  window.onload=function(){
56
  formSubmit();
57
  };</script>';
app/code/local/Craig/Tco/Model/Checkout.php CHANGED
@@ -32,23 +32,23 @@ class Craig_Tco_Model_Checkout extends Mage_Payment_Model_Method_Abstract {
32
  return Mage::getUrl('tco/redirect');
33
  }
34
 
35
- //get SID
36
  public function getSid() {
37
- $sid = $this->getConfigData('sid');
38
- return $sid;
39
- }
40
 
41
- //get Demo Setting
42
  public function getDemo() {
43
- if ($this->getConfigData('demo') == '1') {
44
- $demo = 'Y';
45
- } else {
46
- $demo = 'N';
47
- }
48
- return $demo;
49
- }
50
 
51
- //get Checkout Display
52
  public function getDisplay() {
53
  if ($this->getConfigData('inline') == '1') {
54
  $display = true;
@@ -58,34 +58,34 @@ class Craig_Tco_Model_Checkout extends Mage_Payment_Model_Method_Abstract {
58
  return $display;
59
  }
60
 
61
- //get purchase routine URL
62
  public function getUrl() {
63
- $url = "https://www.2checkout.com/checkout/purchase";
64
  return $url;
65
  }
66
 
67
- //get checkout language
68
  public function getLanguage() {
69
  $lang = $this->getConfigData('checkout_language');
70
  return $lang;
71
  }
72
 
73
- //get custom checkout message
74
  public function getRedirectMessage() {
75
  $redirect_message = $this->getConfigData('redirect_message');
76
  return $redirect_message;
77
  }
78
 
79
- //get order
80
  public function getQuote() {
81
  $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
82
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
83
  return $order;
84
  }
85
 
86
- //get product data
87
  public function getProductData() {
88
- $products = array();
89
  $items = $this->getQuote()->getAllItems();
90
  if ($items) {
91
  $i = 1;
@@ -93,17 +93,17 @@ class Craig_Tco_Model_Checkout extends Mage_Payment_Model_Method_Abstract {
93
  if ($item->getParentItem()) {
94
  continue;
95
  }
96
- $products['c_name_'.$i] = $item->getName();
97
- $products['c_description_'.$i] = $item->getSku();
98
- $products['c_price_'.$i] = number_format($item->getPrice(), 2, '.', '');
99
- $products['c_prod_'.$i] = $item->getSku() . ',' . $item->getQtyToInvoice();
100
- $i++;
101
  }
102
  }
103
  return $products;
104
  }
105
 
106
- //get lineitem data
107
  public function getLineitemData() {
108
  $lineitems = array();
109
  $items = $this->getQuote()->getAllItems();
@@ -120,46 +120,46 @@ class Craig_Tco_Model_Checkout extends Mage_Payment_Model_Method_Abstract {
120
  if ($item->getParentItem()) {
121
  continue;
122
  }
123
- $lineitems['li_'.$i.'_type'] = 'product';
124
- $lineitems['li_'.$i.'_product_id'] = $item->getSku();
125
- $lineitems['li_'.$i.'_quantity'] = $item->getQtyToInvoice();
126
- $lineitems['li_'.$i.'_name'] = $item->getName();
127
- $lineitems['li_'.$i.'_description'] = $item->getDescription();
128
- $lineitems['li_'.$i.'_price'] = number_format($item->getPrice(), 2, '.', '');
129
- $lineitem_total += number_format($item->getPrice(), 2, '.', '');
130
- $i++;
131
  }
132
- }
133
- //get taxes
134
- if ($taxFull) {
135
  foreach($taxFull as $rate){
136
- $lineitems['li_'.$i.'_type'] = 'tax';
137
- $lineitems['li_'.$i.'_name'] = $rate['rates']['0']['code'];
138
- $lineitems['li_'.$i.'_price'] = round($rate['amount'], 2);
139
- $lineitem_total += round($rate['amount'], 2);
140
- $i++;
141
- }
142
  }
143
- //get shipping
144
- if ($ship_method) {
145
- $lineitems['li_'.$i.'_type'] = 'shipping';
146
- $lineitems['li_'.$i.'_name'] = $order->getShipping_description();
147
- $lineitems['li_'.$i.'_price'] = round($order->getShippingAmount(), 2);
148
- $lineitem_total += round($order->getShippingAmount(), 2);
149
- $i++;
150
  }
151
- //get coupons
152
- if ($coupon) {
153
- $lineitems['li_'.$i.'_type'] = 'coupon';
154
- $lineitems['li_'.$i.'_name'] = $order->getCoupon_code();
155
- $lineitems['li_'.$i.'_price'] = trim(round($order->getBase_discount_amount(), 2), '-');
156
- $lineitem_total -= trim(round($order->getBase_discount_amount(), 2), '-');
157
- $i++;
158
  }
159
  return $lineitems;
160
  }
161
 
162
- //check total
163
  public function checkTotal() {
164
  $items = $this->getQuote()->getAllItems();
165
  $order_id = $this->getCheckout()->getLastRealOrderId();
@@ -175,27 +175,27 @@ class Craig_Tco_Model_Checkout extends Mage_Payment_Model_Method_Abstract {
175
  if ($item->getParentItem()) {
176
  continue;
177
  }
178
- $lineitem_total += number_format($item->getPrice(), 2, '.', '');
179
  }
180
  }
181
  //get taxes
182
  if ($taxFull) {
183
  foreach($taxFull as $rate){
184
- $lineitem_total += round($rate['amount'], 2);
185
  }
186
  }
187
  //get shipping
188
  if ($ship_method) {
189
- $lineitem_total += round($order->getShippingAmount(), 2);
190
  }
191
  //get coupons
192
  if ($coupon) {
193
- $lineitem_total -= trim(round($order->getBase_discount_amount(), 2), '-');
194
  }
195
  return $lineitem_total;
196
  }
197
 
198
- //get tax data
199
  public function getTaxData() {
200
  $order_id = $this->getCheckout()->getLastRealOrderId();
201
  $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
@@ -204,15 +204,15 @@ class Craig_Tco_Model_Checkout extends Mage_Payment_Model_Method_Abstract {
204
  if ($taxFull) {
205
  $i = 1;
206
  foreach($taxFull as $rate){
207
- $taxes['tax_id_'.$i] = $rate['rates']['0']['code'];
208
- $taxes['tax_amount_'.$i] = round($rate['amount'], 2);
209
- $i++;
210
- }
211
- }
212
  return $taxes;
213
- }
214
 
215
- //get HTML form data
216
  public function getFormFields() {
217
  $order_id = $this->getCheckout()->getLastRealOrderId();
218
  $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
@@ -230,59 +230,60 @@ class Craig_Tco_Model_Checkout extends Mage_Payment_Model_Method_Abstract {
230
  $cart_order_id = $order_id;
231
  $lineitemData = $this->getLineitemData();
232
 
233
- $tcoFields = array();
234
- $tcoFields['sid'] = $this->getSid();
235
  $tcoFields['lang'] = $this->getLanguage();
236
  $tcoFields['purchase_step'] = 'payment-method';
237
- $tcoFields['merchant_order_id'] = $order_id;
238
- $tcoFields['email'] = $order->getData('customer_email');
239
- $tcoFields['first_name'] = $b->getFirstname();
240
- $tcoFields['last_name'] = $b->getLastname();
241
- $tcoFields['phone'] = $b->getTelephone();
242
- $tcoFields['country'] = $b->getCountry();
243
- $tcoFields['street_address'] = $b->getStreet1();
244
- $tcoFields['street_address2'] = $b->getStreet2();
245
- $tcoFields['city'] = $b->getCity();
246
 
247
  if ($country == 'US' || $country == 'CA') {
248
  $tcoFields['state'] = $b->getRegion();
249
  } else {
250
- $tcoFields['state'] = 'XX';
251
- }
252
 
253
  $tcoFields['zip'] = $b->getPostcode();
254
 
255
- if ($a) {
256
- $tcoFields['ship_name'] = $a->getFirstname() . ' ' . $a->getLastname();
257
- $tcoFields['ship_country'] = $a->getCountry();
258
- $tcoFields['ship_street_address'] = $a->getStreet1();
259
- $tcoFields['ship_street_address2'] = $a->getStreet2();
260
- $tcoFields['ship_city'] = $a->getCity();
261
- $tcoFields['ship_state'] = $a->getRegion();
262
- $tcoFields['ship_zip'] = $a->getPostcode();
263
- $tcoFields['sh_cost'] = $shipping;
264
- $tcoFields['sh_weight'] = $weight;
265
- $tcoFields['ship_method'] = $ship_method;
266
  }
267
- $tcoFields['2co_tax'] = $tax;
268
- $tcoFields['2co_cart_type'] = 'magento';
269
- $tcoFields['x_Receipt_Link_URL'] = Mage::getUrl('tco/redirect/success', array('_secure' => true));
270
- $tcoFields['demo'] = $this->getDemo();
 
271
  $tcoFields['currency_code'] = $currency_code;
272
 
273
- //Check Integration mode
274
  $lineitem_total = $this->checkTotal();
275
- if ($lineitem_total != $amount) {
276
  $tcoFields['id_type'] = '1';
277
  $tcoFields['total'] = $amount;
278
  $tcoFields['cart_order_id'] = $order_id;
279
  $result = $productData + $taxData + $tcoFields;
280
- } else {
281
- $tcoFields['mode'] = '2CO';
282
- $result = $tcoFields + $lineitemData;
283
- }
284
 
285
- return $result;
286
- }
287
 
288
  }
32
  return Mage::getUrl('tco/redirect');
33
  }
34
 
35
+ //get SID
36
  public function getSid() {
37
+ $sid = $this->getConfigData('sid');
38
+ return $sid;
39
+ }
40
 
41
+ //get Demo Setting
42
  public function getDemo() {
43
+ if ($this->getConfigData('demo') == '1') {
44
+ $demo = 'Y';
45
+ } else {
46
+ $demo = 'N';
47
+ }
48
+ return $demo;
49
+ }
50
 
51
+ //get Checkout Display
52
  public function getDisplay() {
53
  if ($this->getConfigData('inline') == '1') {
54
  $display = true;
58
  return $display;
59
  }
60
 
61
+ //get purchase routine URL
62
  public function getUrl() {
63
+ $url = "https://www.2checkout.com/checkout/purchase";
64
  return $url;
65
  }
66
 
67
+ //get checkout language
68
  public function getLanguage() {
69
  $lang = $this->getConfigData('checkout_language');
70
  return $lang;
71
  }
72
 
73
+ //get custom checkout message
74
  public function getRedirectMessage() {
75
  $redirect_message = $this->getConfigData('redirect_message');
76
  return $redirect_message;
77
  }
78
 
79
+ //get order
80
  public function getQuote() {
81
  $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
82
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
83
  return $order;
84
  }
85
 
86
+ //get product data
87
  public function getProductData() {
88
+ $products = array();
89
  $items = $this->getQuote()->getAllItems();
90
  if ($items) {
91
  $i = 1;
93
  if ($item->getParentItem()) {
94
  continue;
95
  }
96
+ $products['c_name_'.$i] = $item->getName();
97
+ $products['c_description_'.$i] = $item->getSku();
98
+ $products['c_price_'.$i] = number_format($item->getPrice(), 2, '.', '');
99
+ $products['c_prod_'.$i] = $item->getSku() . ',' . $item->getQtyToInvoice();
100
+ $i++;
101
  }
102
  }
103
  return $products;
104
  }
105
 
106
+ //get lineitem data
107
  public function getLineitemData() {
108
  $lineitems = array();
109
  $items = $this->getQuote()->getAllItems();
120
  if ($item->getParentItem()) {
121
  continue;
122
  }
123
+ $lineitems['li_'.$i.'_type'] = 'product';
124
+ $lineitems['li_'.$i.'_product_id'] = $item->getSku();
125
+ $lineitems['li_'.$i.'_quantity'] = $item->getQtyToInvoice();
126
+ $lineitems['li_'.$i.'_name'] = $item->getName();
127
+ $lineitems['li_'.$i.'_description'] = $item->getDescription();
128
+ $lineitems['li_'.$i.'_price'] = number_format($item->getPrice(), 2, '.', '');
129
+ $lineitem_total += number_format($item->getPrice(), 2, '.', '');
130
+ $i++;
131
  }
132
+ }
133
+ //get taxes
134
+ if ($taxFull) {
135
  foreach($taxFull as $rate){
136
+ $lineitems['li_'.$i.'_type'] = 'tax';
137
+ $lineitems['li_'.$i.'_name'] = $rate['rates']['0']['code'];
138
+ $lineitems['li_'.$i.'_price'] = round($rate['amount'], 2);
139
+ $lineitem_total += round($rate['amount'], 2);
140
+ $i++;
141
+ }
142
  }
143
+ //get shipping
144
+ if ($ship_method) {
145
+ $lineitems['li_'.$i.'_type'] = 'shipping';
146
+ $lineitems['li_'.$i.'_name'] = $order->getShipping_description();
147
+ $lineitems['li_'.$i.'_price'] = round($order->getShippingAmount(), 2);
148
+ $lineitem_total += round($order->getShippingAmount(), 2);
149
+ $i++;
150
  }
151
+ //get coupons
152
+ if ($coupon) {
153
+ $lineitems['li_'.$i.'_type'] = 'coupon';
154
+ $lineitems['li_'.$i.'_name'] = $order->getCoupon_code();
155
+ $lineitems['li_'.$i.'_price'] = trim(round($order->getBase_discount_amount(), 2), '-');
156
+ $lineitem_total -= trim(round($order->getBase_discount_amount(), 2), '-');
157
+ $i++;
158
  }
159
  return $lineitems;
160
  }
161
 
162
+ //check total
163
  public function checkTotal() {
164
  $items = $this->getQuote()->getAllItems();
165
  $order_id = $this->getCheckout()->getLastRealOrderId();
175
  if ($item->getParentItem()) {
176
  continue;
177
  }
178
+ $lineitem_total += number_format($item->getPrice(), 2, '.', '');
179
  }
180
  }
181
  //get taxes
182
  if ($taxFull) {
183
  foreach($taxFull as $rate){
184
+ $lineitem_total += round($rate['amount'], 2);
185
  }
186
  }
187
  //get shipping
188
  if ($ship_method) {
189
+ $lineitem_total += round($order->getShippingAmount(), 2);
190
  }
191
  //get coupons
192
  if ($coupon) {
193
+ $lineitem_total -= trim(round($order->getBase_discount_amount(), 2), '-');
194
  }
195
  return $lineitem_total;
196
  }
197
 
198
+ //get tax data
199
  public function getTaxData() {
200
  $order_id = $this->getCheckout()->getLastRealOrderId();
201
  $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
204
  if ($taxFull) {
205
  $i = 1;
206
  foreach($taxFull as $rate){
207
+ $taxes['tax_id_'.$i] = $rate['rates']['0']['code'];
208
+ $taxes['tax_amount_'.$i] = round($rate['amount'], 2);
209
+ $i++;
210
+ }
211
+ }
212
  return $taxes;
213
+ }
214
 
215
+ //get HTML form data
216
  public function getFormFields() {
217
  $order_id = $this->getCheckout()->getLastRealOrderId();
218
  $order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
230
  $cart_order_id = $order_id;
231
  $lineitemData = $this->getLineitemData();
232
 
233
+ $tcoFields = array();
234
+ $tcoFields['sid'] = $this->getSid();
235
  $tcoFields['lang'] = $this->getLanguage();
236
  $tcoFields['purchase_step'] = 'payment-method';
237
+ $tcoFields['merchant_order_id'] = $order_id;
238
+ $tcoFields['email'] = $order->getData('customer_email');
239
+ $tcoFields['first_name'] = $b->getFirstname();
240
+ $tcoFields['last_name'] = $b->getLastname();
241
+ $tcoFields['phone'] = $b->getTelephone();
242
+ $tcoFields['country'] = $b->getCountry();
243
+ $tcoFields['street_address'] = $b->getStreet1();
244
+ $tcoFields['street_address2'] = $b->getStreet2();
245
+ $tcoFields['city'] = $b->getCity();
246
 
247
  if ($country == 'US' || $country == 'CA') {
248
  $tcoFields['state'] = $b->getRegion();
249
  } else {
250
+ $tcoFields['state'] = 'XX';
251
+ }
252
 
253
  $tcoFields['zip'] = $b->getPostcode();
254
 
255
+ if ($a) {
256
+ $tcoFields['ship_name'] = $a->getFirstname() . ' ' . $a->getLastname();
257
+ $tcoFields['ship_country'] = $a->getCountry();
258
+ $tcoFields['ship_street_address'] = $a->getStreet1();
259
+ $tcoFields['ship_street_address2'] = $a->getStreet2();
260
+ $tcoFields['ship_city'] = $a->getCity();
261
+ $tcoFields['ship_state'] = $a->getRegion();
262
+ $tcoFields['ship_zip'] = $a->getPostcode();
263
+ $tcoFields['sh_cost'] = $shipping;
264
+ $tcoFields['sh_weight'] = $weight;
265
+ $tcoFields['ship_method'] = $ship_method;
266
  }
267
+ $tcoFields['2co_tax'] = $tax;
268
+ $tcoFields['2co_cart_type'] = 'magento';
269
+ $tcoFields['x_Receipt_Link_URL'] = Mage::getUrl('tco/redirect/success', array('_secure' => true));
270
+ $tcoFields['return_url'] = Mage::getUrl('tco/redirect/cart', array('_secure' => true));
271
+ $tcoFields['demo'] = $this->getDemo();
272
  $tcoFields['currency_code'] = $currency_code;
273
 
274
+ //Check Integration mode
275
  $lineitem_total = $this->checkTotal();
276
+ if ($lineitem_total != $amount) {
277
  $tcoFields['id_type'] = '1';
278
  $tcoFields['total'] = $amount;
279
  $tcoFields['cart_order_id'] = $order_id;
280
  $result = $productData + $taxData + $tcoFields;
281
+ } else {
282
+ $tcoFields['mode'] = '2CO';
283
+ $result = $tcoFields + $lineitemData;
284
+ }
285
 
286
+ return $result;
287
+ }
288
 
289
  }
app/code/local/Craig/Tco/Model/Observer.php CHANGED
@@ -1,12 +1,13 @@
1
  <?php
2
 
3
- class Craig_Tco_Model_Observer extends Mage_Adminhtml_Block_Template{
4
 
5
  public function issue_creditmemo_refund(Varien_Object $payment) {
6
 
7
  $refund = Mage::getStoreConfig('payment/tco/refund');
8
 
9
  if ($refund == '1') {
 
10
  $creditmemo = $payment->getCreditmemo()->getOrder()->getData();
11
  $creditmemo_amount = $payment->getCreditmemo()->getData();
12
  $creditmemo_comment = $payment->getCreditmemo()->getCommentsCollection()->toArray();
@@ -44,10 +45,84 @@ class Craig_Tco_Model_Observer extends Mage_Adminhtml_Block_Template{
44
  $http->setConfig($config);
45
  $http->write(Zend_Http_Client::POST, $url, '1.1', $headers, $data);
46
  $response = $http->read();
 
 
47
  } catch (Exception $e) {
48
- die($e->getMessage());
49
  }
50
  }
51
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  }
53
  ?>
1
  <?php
2
 
3
+ class Craig_Tco_Model_Observer extends Mage_Core_Block_Abstract {
4
 
5
  public function issue_creditmemo_refund(Varien_Object $payment) {
6
 
7
  $refund = Mage::getStoreConfig('payment/tco/refund');
8
 
9
  if ($refund == '1') {
10
+ $order = $payment->getCreditmemo()->getOrder();
11
  $creditmemo = $payment->getCreditmemo()->getOrder()->getData();
12
  $creditmemo_amount = $payment->getCreditmemo()->getData();
13
  $creditmemo_comment = $payment->getCreditmemo()->getCommentsCollection()->toArray();
45
  $http->setConfig($config);
46
  $http->write(Zend_Http_Client::POST, $url, '1.1', $headers, $data);
47
  $response = $http->read();
48
+ $order->addStatusHistoryComment($response);
49
+ $order->save();
50
  } catch (Exception $e) {
51
+ Mage::throwException(Mage::helper('core')->__($e->getMessage()));
52
  }
53
  }
54
  }
55
+
56
+
57
+ public function output_tco_redirect(Varien_Object $observer) {
58
+ if (isset($_POST['payment']['method']) && $_POST['payment']['method'] == "tco") {
59
+ $controller = $observer->getEvent()->getData('controller_action');
60
+ $result = Mage::helper('core')->jsonDecode(
61
+ $controller->getResponse()->getBody('default'),
62
+ Zend_Json::TYPE_ARRAY
63
+ );
64
+
65
+ if (Mage::getStoreConfig('payment/tco/inline') == '1') {
66
+ $js = '<script>
67
+ document.getElementById("review-please-wait").style["display"] = "block";
68
+ if ($$("a.top-link-cart")) {
69
+ $$("a.top-link-cart")[0].href = "'.Mage::getUrl('tco/redirect/cart', array('_secure' => true)).'";
70
+ }
71
+ if ($$("p.f-left").length !== 0) {
72
+ $$("p.f-left")[0].style["display"] = "none";
73
+ }
74
+ function formSubmit() {
75
+ $("tcosubmit").click();
76
+ }
77
+ var tcohead = $$("head")[0];
78
+ var tcoscript = new Element("script", { type: "text/javascript", src: "https://www.2checkout.com/static/checkout/javascript/direct.min.js" });
79
+ tcohead.appendChild(tcoscript);
80
+ var checkoutOrderBtn = $$("button.btn-checkout");
81
+ checkoutOrderBtn[0].removeAttribute("onclick");
82
+ checkoutOrderBtn[0].addEventListener("click", formSubmit, false);
83
+ new PeriodicalExecuter(function(pe) {
84
+ if (typeof window["inline_2Checkout"] != "undefined")
85
+ {
86
+ formSubmit();
87
+ pe.stop();
88
+ }
89
+ }, 0.50);
90
+ </script>';
91
+ } else {
92
+ $js = '<script>
93
+ document.getElementById("review-please-wait").style["display"] = "block";
94
+ if ($$("a.top-link-cart")) {
95
+ $$("a.top-link-cart")[0].href = "'.Mage::getUrl('tco/redirect/cart', array('_secure' => true)).'";
96
+ }
97
+ if ($$("p.f-left").length !== 0) {
98
+ $$("p.f-left")[0].style["display"] = "none";
99
+ }
100
+ function formSubmit() {
101
+ $("tcosubmit").click();
102
+ }
103
+ var checkoutOrderBtn = $$("button.btn-checkout");
104
+ checkoutOrderBtn[0].removeAttribute("onclick");
105
+ checkoutOrderBtn[0].addEventListener("click", formSubmit, false);
106
+ formSubmit();
107
+ </script>';
108
+ }
109
+
110
+ if (empty($result['error'])) {
111
+ $controller->loadLayout('checkout_onepage_review');
112
+ $html = $controller->getLayout()->createBlock('tco/redirect')->toHtml();
113
+ $html .= $js;
114
+ $result['update_section'] = array(
115
+ 'name' => 'tcoiframe',
116
+ 'html' => $html
117
+ );
118
+ $result['redirect'] = false;
119
+ $result['success'] = false;
120
+ $controller->getResponse()->clearHeader('Location');
121
+ $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
122
+ }
123
+ }
124
+ return $this;
125
+ }
126
+
127
  }
128
  ?>
app/code/local/Craig/Tco/controllers/RedirectController.php CHANGED
@@ -80,4 +80,17 @@ class Craig_Tco_RedirectController extends Mage_Core_Controller_Front_Action {
80
  }
81
  }
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  }
80
  }
81
  }
82
 
83
+ public function cartAction() {
84
+ $session = Mage::getSingleton('checkout/session');
85
+ if ($session->getLastRealOrderId()) {
86
+ $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
87
+ if ($order->getId()) {
88
+ $order->cancel()->save();
89
+ }
90
+ $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
91
+ $quote->setIsActive(true)->save();
92
+ }
93
+ $this->_redirect('checkout/cart');
94
+ }
95
+
96
  }
app/code/local/Craig/Tco/etc/config.xml CHANGED
@@ -24,7 +24,7 @@
24
  <config>
25
  <modules>
26
  <Craig_Tco>
27
- <version>2.3.3</version>
28
  </Craig_Tco>
29
  </modules>
30
  <global>
@@ -64,6 +64,15 @@
64
  </tco_read>
65
  </resources>
66
  <events>
 
 
 
 
 
 
 
 
 
67
  <sales_order_creditmemo_refund>
68
  <observers>
69
  <issue_creditmemo_refund>
@@ -73,10 +82,16 @@
73
  </issue_creditmemo_refund>
74
  </observers>
75
  </sales_order_creditmemo_refund>
76
-
77
  </events>
78
  </global>
79
  <frontend>
 
 
 
 
 
 
 
80
  <routers>
81
  <tco>
82
  <use>standard</use>
24
  <config>
25
  <modules>
26
  <Craig_Tco>
27
+ <version>2.4.0</version>
28
  </Craig_Tco>
29
  </modules>
30
  <global>
64
  </tco_read>
65
  </resources>
66
  <events>
67
+ <controller_action_postdispatch_checkout_onepage_saveOrder>
68
+ <observers>
69
+ <output_tco_redirect>
70
+ <type>singleton</type>
71
+ <class>Craig_Tco_Model_Observer</class>
72
+ <method>output_tco_redirect</method>
73
+ </output_tco_redirect>
74
+ </observers>
75
+ </controller_action_postdispatch_checkout_onepage_saveOrder>
76
  <sales_order_creditmemo_refund>
77
  <observers>
78
  <issue_creditmemo_refund>
82
  </issue_creditmemo_refund>
83
  </observers>
84
  </sales_order_creditmemo_refund>
 
85
  </events>
86
  </global>
87
  <frontend>
88
+ <layout>
89
+ <updates>
90
+ <tco>
91
+ <file>tco.xml</file>
92
+ </tco>
93
+ </updates>
94
+ </layout>
95
  <routers>
96
  <tco>
97
  <use>standard</use>
app/design/frontend/base/default/layout/tco.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <layout version="0.1.0">
2
+ <checkout_onepage_review>
3
+ <reference name="checkout.onepage.review.info.items.after">
4
+ <block type="tco/iframe" name="tco.iframe" as="tco_iframe">
5
+ <action method="setBlockId"><block_id>tcoiframe</block_id></action>
6
+ </block>
7
+ </reference>
8
+ </checkout_onepage_review>
9
+ </layout>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Craig_Tco</name>
4
- <version>2.3.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>2Checkout Payment Extension</summary>
10
- <description>2Checkout Payment Extension</description>
11
- <notes>Updated image urls</notes>
12
- <authors><author><name>Craig Christenson</name><user>Craig2Checkout</user><email>cchristenson@2co.com</email></author></authors>
13
- <date>2013-10-01</date>
14
- <time>16:41:39</time>
15
- <contents><target name="mageetc"><dir name="modules"><file name="Craig_Tco.xml" hash="4a6e92678d9b2a310af880d35a4c355f"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="tco"><file name="form.phtml" hash="08ae585e158550d0a5dccbed3d37758d"/><file name="info.phtml" hash="b714a7398773adc71ea086024dfc96b1"/></dir></dir></dir></dir></dir></target><target name="magelocal"><dir name="Craig"><dir name="Tco"><dir name="Block"><file name="Form.php" hash="b552018543f57090c42784d939004dd4"/><file name="Info.php" hash="ceb4ec03e4de3e4f1dafaf5d7da9b982"/><file name="Redirect.php" hash="1b98352eef4b85d367512cbe9b14fcca"/></dir><dir name="controllers"><file name="NotificationController.php" hash="5bf12db9cfc0719deea1f82dfe3fe1a2"/><file name="RedirectController.php" hash="234c09971716a837f84e459a7d15199f"/></dir><dir name="Model"><file name="Checkout.php" hash="abc306412071808aaa015f0198efc4fb"/><file name="Observer.php" hash="c24b10be82be173a91cd6b53a0cbbd18"/></dir><dir name="Helper"><file name="Data.php" hash="de7680011db7d6821c1f68d70a8fa684"/></dir><dir name="etc"><file name="config.xml" hash="1a8c3472752aebf282b31e991e46d004"/><file name="system.xml" hash="8b8a49a75cd220f0ae7597d70c55f156"/></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Craig_Tco</name>
4
+ <version>2.4.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>2Checkout Payment Extension</summary>
10
+ <description>2Checkout Payment Module</description>
11
+ <notes>Better Direct Checkout Integration</notes>
12
+ <authors><author><name>Craig Christenson</name><user>Craig2Checkout</user><email>cchristenson@2checkout.com</email></author></authors>
13
+ <date>2014-03-02</date>
14
+ <time>03:13:48</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Craig_Tco.xml" hash="4a6e92678d9b2a310af880d35a4c355f"/></dir></target><target name="magelocal"><dir name="Craig"><dir name="Tco"><dir name="Block"><file name="Form.php" hash="b552018543f57090c42784d939004dd4"/><file name="Iframe.php" hash="c8a410448492f2722d8f9891d8470ef7"/><file name="Info.php" hash="ceb4ec03e4de3e4f1dafaf5d7da9b982"/><file name="Redirect.php" hash="3f74b079cdaa46bb2077ef23c4117e6f"/></dir><dir name="controllers"><file name="NotificationController.php" hash="5bf12db9cfc0719deea1f82dfe3fe1a2"/><file name="RedirectController.php" hash="116f9d6b3a5bf6386a00486ccfabdb63"/></dir><dir name="etc"><file name="config.xml" hash="6dd85feeb9f21bbb23fc051c21dfdddb"/><file name="system.xml" hash="8b8a49a75cd220f0ae7597d70c55f156"/></dir><dir name="Helper"><file name="Data.php" hash="de7680011db7d6821c1f68d70a8fa684"/></dir><dir name="Model"><file name="Checkout.php" hash="9471947098baeba75bc1a6c285e2842d"/><file name="Observer.php" hash="3e290d36a1623a768f6228ffad2d8fe3"/></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="tco"><file name="iframe.phtml" hash=""/><file name="info.phtml" hash=""/></dir></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="tco.xml" hash="674ab3912206c33400cefc358f07579f"/></dir><dir name="template"><dir name="tco"><file name="form.phtml" hash="08ae585e158550d0a5dccbed3d37758d"/></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>