twocheckout.php (4829B)
1 <?php 2 class ControllerExtensionPaymentTwoCheckout extends Controller { 3 public function index() { 4 $data['button_confirm'] = $this->language->get('button_confirm'); 5 6 $this->load->model('checkout/order'); 7 8 $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); 9 10 $data['action'] = 'https://www.2checkout.com/checkout/purchase'; 11 12 $data['sid'] = $this->config->get('payment_twocheckout_account'); 13 $data['currency_code'] = $order_info['currency_code']; 14 $data['total'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false); 15 $data['cart_order_id'] = $this->session->data['order_id']; 16 $data['card_holder_name'] = $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname']; 17 $data['street_address'] = $order_info['payment_address_1']; 18 $data['city'] = $order_info['payment_city']; 19 20 if ($order_info['payment_iso_code_2'] == 'US' || $order_info['payment_iso_code_2'] == 'CA') { 21 $data['state'] = $order_info['payment_zone']; 22 } else { 23 $data['state'] = 'XX'; 24 } 25 26 $data['zip'] = $order_info['payment_postcode']; 27 $data['country'] = $order_info['payment_country']; 28 $data['email'] = $order_info['email']; 29 $data['phone'] = $order_info['telephone']; 30 31 if ($this->cart->hasShipping()) { 32 $data['ship_street_address'] = $order_info['shipping_address_1']; 33 $data['ship_city'] = $order_info['shipping_city']; 34 $data['ship_state'] = $order_info['shipping_zone']; 35 $data['ship_zip'] = $order_info['shipping_postcode']; 36 $data['ship_country'] = $order_info['shipping_country']; 37 } else { 38 $data['ship_street_address'] = $order_info['payment_address_1']; 39 $data['ship_city'] = $order_info['payment_city']; 40 $data['ship_state'] = $order_info['payment_zone']; 41 $data['ship_zip'] = $order_info['payment_postcode']; 42 $data['ship_country'] = $order_info['payment_country']; 43 } 44 45 $data['products'] = array(); 46 47 $products = $this->cart->getProducts(); 48 49 foreach ($products as $product) { 50 $data['products'][] = array( 51 'product_id' => $product['product_id'], 52 'name' => $product['name'], 53 'description' => $product['name'], 54 'quantity' => $product['quantity'], 55 'price' => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value'], false) 56 ); 57 } 58 59 if ($this->config->get('payment_twocheckout_test')) { 60 $data['demo'] = 'Y'; 61 } else { 62 $data['demo'] = ''; 63 } 64 65 if ($this->config->get('payment_twocheckout_display')) { 66 $data['display'] = 'Y'; 67 } else { 68 $data['display'] = ''; 69 } 70 71 $data['lang'] = $this->session->data['language']; 72 73 $data['return_url'] = $this->url->link('extension/payment/twocheckout/callback', '', true); 74 75 return $this->load->view('extension/payment/twocheckout', $data); 76 } 77 78 public function callback() { 79 $this->load->model('checkout/order'); 80 81 $order_info = $this->model_checkout_order->getOrder($this->request->post['cart_order_id']); 82 83 if (!$this->config->get('payment_twocheckout_test')) { 84 $order_number = $this->request->post['order_number']; 85 } else { 86 $order_number = '1'; 87 } 88 89 if (strtoupper(md5($this->config->get('payment_twocheckout_secret') . $this->config->get('payment_twocheckout_account') . $order_number . $this->request->post['total'])) == $this->request->post['key']) { 90 if ($this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false) == $this->request->post['total']) { 91 $this->model_checkout_order->addOrderHistory($this->request->post['cart_order_id'], $this->config->get('payment_twocheckout_order_status_id')); 92 } else { 93 $this->model_checkout_order->addOrderHistory($this->request->post['cart_order_id'], $this->config->get('config_order_status_id'));// Ugh. Some one've faked the sum. What should we do? Probably drop a mail to the shop owner? 94 } 95 96 // We can't use $this->response->redirect() here, because of 2CO behavior. It fetches this page 97 // on behalf of the user and thus user (and his browser) see this as located at 2checkout.com 98 // domain. So user's cookies are not here and he will see empty basket and probably other 99 // weird things. 100 101 echo '<html>' . "\n"; 102 echo '<head>' . "\n"; 103 echo ' <meta http-equiv="Refresh" content="0; url=' . $this->url->link('checkout/success') . '">' . "\n"; 104 echo '</head>' . "\n"; 105 echo '<body>' . "\n"; 106 echo ' <p>Please follow <a href="' . $this->url->link('checkout/success') . '">link</a>!</p>' . "\n"; 107 echo '</body>' . "\n"; 108 echo '</html>' . "\n"; 109 exit(); 110 } else { 111 echo 'The response from 2checkout.com can\'t be parsed. Contact site administrator, please!'; 112 } 113 } 114 }