Post by Gilmore » Sat Nov 13, 2010 4:17 am

Here is the fix I use for 2Checkout. It also has the new checkout page for 2Checkout. Now you get a simplified 1 page checkout instead of the multi page old style.

Open catalog/controller/payment/twocheckout.php
Select ALL.
Replace with:

Code: Select all

<?php
class ControllerPaymentTwoCheckout extends Controller {
	protected function index() {
    	$this->data['button_confirm'] = $this->language->get('button_confirm');
		$this->data['button_back'] = $this->language->get('button_back');

		$this->load->model('checkout/order');
		
		$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
		
		/* $this->data['action'] = 'https://www.2checkout.com/2co/buyer/purchase'; */		
		$this->data['action'] = 'https://www.2checkout.com/checkout/spurchase';  // New single page checkout

		$this->data['sid'] = $this->config->get('twocheckout_account');
		$this->data['total'] = $this->currency->format($order_info['total'], $order_info['currency'], $order_info['value'], FALSE);
		$this->data['cart_order_id'] = $this->session->data['order_id'];
		$this->data['card_holder_name'] = $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'];
		$this->data['street_address'] = $order_info['payment_address_1'];
		$this->data['city'] = $order_info['payment_city'];
		if ($order_info['payment_country'] == "United States" || $order_info['payment_country'] == "Canada") {
			$this->data['state'] = $order_info['payment_zone'];
		} else {
			$this->data['state'] = "XX";
		}
		$this->data['zip'] = $order_info['payment_postcode'];
		$this->data['country'] = $order_info['payment_country'];
		$this->data['email'] = $order_info['email'];
		$this->data['phone'] = $order_info['telephone'];
		
		if ($this->cart->hasShipping()) {
			$this->data['ship_street_address'] = $order_info['shipping_address_1'];
			$this->data['ship_city'] = $order_info['shipping_city'];
			$this->data['ship_state'] = $order_info['shipping_zone'];
			$this->data['ship_zip'] = $order_info['shipping_postcode'];
			$this->data['ship_country'] = $order_info['shipping_country'];
		} else {
			$this->data['ship_street_address'] = $order_info['payment_address_1'];
			$this->data['ship_city'] = $order_info['payment_city'];
			$this->data['ship_state'] = $order_info['payment_zone']; // was: $this->data['ship_state'] = $order_info['payment_zone'];
			$this->data['ship_zip'] = $order_info['payment_postcode'];
			$this->data['ship_country'] = $order_info['payment_country'];			
		}
		
		$this->data['products'] = array();
		
		$products = $this->cart->getProducts();

		foreach ($products as $product) {
			$this->data['products'][] = array(
				'product_id'  => $product['product_id'],
				'name'        => $product['name'],
				'description' => $product['name'],
				'quantity'    => $product['quantity'],
				'price'		  => $this->currency->format($product['price'], $order_info['currency'], $order_info['value'], FALSE)
			);
		}

		if ($this->config->get('twocheckout_test')) {
			$this->data['demo'] = 'Y';
		}	
		
		$this->data['lang'] = $this->session->data['language'];

		if ($this->request->get['route'] != 'checkout/guest_step_3') {
			$this->data['return_url'] = HTTPS_SERVER . 'index.php?route=checkout/confirm';
		} else {
			$this->data['return_url'] = HTTPS_SERVER . 'index.php?route=checkout/guest_step_3';
		}
		
		if ($this->request->get['route'] != 'checkout/guest_step_3') {
			$this->data['back'] = HTTPS_SERVER . 'index.php?route=checkout/payment';
		} else {
			$this->data['back'] = HTTPS_SERVER . 'index.php?route=checkout/guest_step_2';
		}

		$this->data['payment_callback'] = HTTPS_SERVER . 'index.php?route=payment/twocheckout/callback';
		
		$this->id = 'payment';

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/twocheckout.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/payment/twocheckout.tpl';
		} else {
			$this->template = 'default/template/payment/twocheckout.tpl';
		}	
		
		$this->render();
	}
	
	public function callback() {
		$this->load->model('checkout/order');

		$order_info = $this->model_checkout_order->getOrder($this->request->post['cart_order_id']);
		$our_total = $this->currency->format($order_info['total'], $order_info['currency'], $order_info['value'], FALSE);

		$hash_order_number = $this->request->post['order_number'];
		if ($this->config->get('twocheckout_test')) {
			// Checl "MD5 Hash in Demo Mode" section here:
			// https://www.2checkout.com/documentation/UsersGuide2/chapter6/md5-hash.html
			$hash_order_number = "1";
		}

		$hash = md5($this->config->get('twocheckout_secret') . $this->config->get('twocheckout_account') . $hash_order_number . $this->request->post['total']);
		$hash = strtoupper($hash);
		if ($hash == $this->request->post['key']) {

			if ($our_total != $this->request->post['total']) {
				// Ugh. Some one've faked the sum. What should we do? Probably drop a mail to the shop owner?
				// As a first step we block the order.
				$this->model_checkout_order->confirm($this->request->post['cart_order_id'], 8 /*Denied*/);
			} else {
				$this->model_checkout_order->confirm($this->request->post['cart_order_id'], $this->config->get('twocheckout_order_status_id'));
			}

			// We can't use $this->redirect() here, because of 2CO behavior. It fetches this page
			// on behalf of the user and thus user (and his browser) see this as located at 2checkout.com
			// domain. So user's cookies are not here and he will see empty basket and probably other
			// weird things.
//			$this->redirect(HTTP_SERVER . 'index.php?route=checkout/success');
			echo "<html><head>\n";
			echo "  <meta http-equiv=\"Refresh\" content=\"0; url=".HTTP_SERVER.'index.php?route=checkout/success'."\">\n";
			echo "</head><body>\n";
			echo "  <p>Please follow <a href=\"".HTTP_SERVER.'index.php?route=checkout/success'."\">link</a>!</p>\n";
			echo "</body></html>\n";
			exit();
		} else {
			echo "We response from 2checkout.com can't be parsed. Contact site adimistrator, please!";
//			$this->redirect(HTTP_SERVER . 'index.php?route=checkout/failure');

//OLD (before patch)
//		$order_info = $this->model_checkout_order->getOrder($this->request->post['order_number']);
//
//		if (md5($this->config->get('twocheckout_secret') . $this->config->get('twocheckout_account') . $this->request->post['order_number'] . $this->request->post['total']) == $this->request->post['key']) {
//			$this->model_checkout_order->confirm($this->request->post['order_number'], $this->config->get('twocheckout_order_status_id'));
//	
//			$this->redirect(HTTP_SERVER . 'index.php?route=checkout/success');	
		}
	}
}
?>
And in catalog/view/theme/default/template/payment/twocheckout.tpl

Select all and replace with below

Code: Select all

<form action="<?php echo str_replace('&', '&', $action); ?>" method="post" id="checkout">
  <input type="hidden" name="sid" value="<?php echo $sid; ?>" />
  <input type="hidden" name="total" value="<?php echo $total; ?>" />
  <input type="hidden" name="cart_order_id" value="<?php echo $cart_order_id; ?>" />
  <input type="hidden" name="card_holder_name" value="<?php echo $card_holder_name; ?>" />
  <input type="hidden" name="street_address" value="<?php echo $street_address; ?>" />
  <input type="hidden" name="city" value="<?php echo $city; ?>" />
  <input type="hidden" name="state" value="<?php echo $state; ?>" />
  <input type="hidden" name="zip" value="<?php echo $zip; ?>" />
  <input type="hidden" name="country" value="<?php echo $country; ?>" />
  <input type="hidden" name="email" value="<?php echo $email; ?>" />
  <input type="hidden" name="phone" value="<?php echo $phone; ?>" />
  <input type="hidden" name="ship_street_address" value="<?php echo $ship_street_address; ?>" />
  <input type="hidden" name="ship_city" value="<?php echo $ship_city; ?>" />
  <input type="hidden" name="ship_state" value="<?php echo $ship_state; ?>" />
  <input type="hidden" name="ship_zip" value="<?php echo $ship_zip; ?>" />
  <input type="hidden" name="ship_country" value="<?php echo $ship_country; ?>" />
  <?php $i = 0; ?>
  <?php foreach ($products as $product) { ?>
  <input type="hidden" name="c_prod_<?php echo $i; ?>" value="<?php echo $product['product_id']; ?>,<?php echo $product['quantity']; ?>" />
  <input type="hidden" name="c_name_<?php echo $i; ?>" value="<?php echo $product['name']; ?>" />
  <input type="hidden" name="c_description_<?php echo $i; ?>" value="<?php echo $product['description']; ?>" />
  <input type="hidden" name="c_price_<?php echo $i; ?>" value="<?php echo $product['price']; ?>" />
  <?php $i++; ?>
  <?php } ?>
  <input type="hidden" name="id_type" value="1" />
  <?php if (isset($demo)) { ?>
  <input type="hidden" name="demo" value="<?php echo $demo; ?>" />
  <?php } ?>
  <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
  <input type="hidden" name="return_url" value="<?php echo $return_url; ?>" />
</form>
<div class="buttons">
  <table>
    <tr>
      <td align="left"><a onclick="location = '<?php echo str_replace('&', '&', $back); ?>'" class="button"><span><?php echo $button_back; ?></span></a></td>
      <td align="right"><a onclick="$('#checkout').submit();" class="button"><span><?php echo $button_confirm; ?></span></a></td>
    </tr>
  </table>
</div>
Don't forget to add in your return URL in your 2Checkout account too.

Approved URL
Input a url for your customers to be sent to on a successful purchase.

[url]http://your_domain_name_here.com/index.php?route=payment/twocheckout/callback[/url]

That's it!

Enjoy!

Gilmore
Last edited by Gilmore on Sat Nov 20, 2010 2:46 pm, edited 2 times in total.

User avatar
Active Member

Posts

Joined
Thu Aug 12, 2010 7:33 am

Post by bafaraj » Sat Nov 13, 2010 6:18 am

Can we know what has been changed ?

متجر إنـشــاد | نختصر المسافات
http://www.inshadstore.com


New member

Posts

Joined
Fri Nov 12, 2010 12:32 am
Location - UAE

Post by bafaraj » Sat Nov 13, 2010 6:19 am

Also if the currency issue has been resolved ?

متجر إنـشــاد | نختصر المسافات
http://www.inshadstore.com


New member

Posts

Joined
Fri Nov 12, 2010 12:32 am
Location - UAE

Post by Gilmore » Sat Nov 13, 2010 12:56 pm

I don't know about the currency issue, but if you read the code, you will see where the changes are noted.

User avatar
Active Member

Posts

Joined
Thu Aug 12, 2010 7:33 am

Post by foldingbikela » Tue Dec 14, 2010 4:45 am

Does this fix OpenCart so that it records transactions processed with 2Checkout?

Newbie

Posts

Joined
Thu Dec 09, 2010 10:53 am


Post by Gilmore » Tue Dec 14, 2010 5:58 am

I'm not sure what you mean about recording transactions, but I know it makes the 2Checkout process work. On mine, the transactions are recorded in the Customers Order History and on 2Checkout's admin panel.

User avatar
Active Member

Posts

Joined
Thu Aug 12, 2010 7:33 am

Post by Qphoria » Tue Dec 14, 2010 10:11 am

This was added back in 1.4.9 I believe already

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by silvermarbles » Wed Dec 22, 2010 4:27 am

this update has improved the single checkout which makes the checkout procedure a lot better.

however my only problem is that when i get a successful transaction it DOES NOT update the order status.

any ideas why?

I am using 1.4.9.1

Thanks
Anthony

User avatar
New member

Posts

Joined
Thu Jun 17, 2010 4:06 am
Location - Telford, Shropshire
Who is online

Users browsing this forum: No registered users and 7 guests