Advertisement
craygo

chout.php

Jul 18th, 2011
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.33 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Chout extends CI_Controller
  4. {
  5.  
  6.   function Chout()
  7.   {
  8.     parent::__construct();
  9.     $this->load->model('cart_model');
  10.   }
  11.  
  12.   function page_data()
  13.   {
  14.     $data['title'] = 'Prep N\' Pop';
  15.     $data['header'] = '
  16.      <div id="header" /></div>';
  17.     $data['css'] = "
  18.      <link href=\"".$this->config->item('base_url').$this->config->item('css')."\" rel=\"stylesheet\" type=\"text/css\" />
  19.      <script type=\"text/javascript\" src=\"".$this->config->item('base_url')."assets/js/jquery-1.6.2.min.js\"></script>
  20.      <script type=\"text/javascript\" src=\"".$this->config->item('base_url')."assets/js/ch_core.js\"></script>";
  21.     $data['heading'] = '
  22.      <div id="heading" />Prep N\' Pop</div>';
  23.  
  24.     return $data;
  25.  
  26.   }
  27.  
  28.     function index()
  29.     {
  30.         $this->load->view('checkout', $this->page_data());
  31.     }
  32.  
  33.     function show_cart(){
  34.         $this->load->view('chcart');
  35.     }
  36.  
  37.     function update_cart(){
  38.         $this->cart_model->validate_update_cart();
  39.         redirect('chout');
  40.     }
  41.  
  42.     function empty_cart(){
  43.         $this->cart->destroy();
  44.         redirect('pnp');
  45.     }
  46.  
  47.   function process_sale(){
  48.     $root = realpath($_SERVER["DOCUMENT_ROOT"]);
  49.     require_once("$root/newsite/assets/anet_php_sdk/config.php");
  50.  
  51.   if ($METHOD_TO_USE == "AIM") {
  52.     $transaction = new AuthorizeNetAIM;
  53.     $transaction->setSandbox(AUTHORIZENET_SANDBOX);
  54.     $transaction->setFields(
  55.         array(
  56.         'amount' => $amount,
  57.         'card_num' => $_POST['x_card_num'],
  58.         'exp_date' => $_POST['x_exp_date'],
  59.         'first_name' => $_POST['x_first_name'],
  60.         'last_name' => $_POST['x_last_name'],
  61.         'address' => $_POST['x_address'],
  62.         'city' => $_POST['x_city'],
  63.         'state' => $_POST['x_state'],
  64.         'country' => $_POST['x_country'],
  65.         'zip' => $_POST['x_zip'],
  66.         'email' => $_POST['x_email'],
  67.         'card_code' => $_POST['x_card_code'],
  68.         )
  69.     );
  70.     $response = $transaction->authorizeAndCapture();
  71.     if ($response->approved) {
  72.         // Transaction approved! Do your logic here.
  73.         header('Location: thank_you_page.php?transaction_id=' . $response->transaction_id);
  74.     } else {
  75.         header('Location: error_page.php?response_reason_code='.$response->response_reason_code.'&response_code='.$response->response_code.'&response_reason_text=' .$response->response_reason_text);
  76.     }
  77.   } elseif (count($_POST)) {
  78.     $response = new AuthorizeNetSIM;
  79.     if ($response->isAuthorizeNet()) {
  80.         if ($response->approved) {
  81.             // Transaction approved! Do your logic here.
  82.             // Redirect the user back to your site.
  83.             $return_url = $site_root . 'thank_you_page.php?transaction_id=' .$response->transaction_id;
  84.         } else {
  85.             // There was a problem. Do your logic here.
  86.             // Redirect the user back to your site.
  87.             $return_url = $site_root . 'error_page.php?response_reason_code='.$response->response_reason_code.'&response_code='.$response->response_code.'&response_reason_text=' .$response->response_reason_text;
  88.         }
  89.         echo AuthorizeNetDPM::getRelayResponseSnippet($return_url);
  90.     } else {
  91.         echo "MD5 Hash failed. Check to make sure your MD5 Setting matches the one in config.php";
  92.     }
  93.   }
  94.   }
  95.  
  96.   function thank_you(){
  97.  
  98.   }
  99.  
  100. }
  101.  
  102. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement