tribulant

Untitled

Jun 14th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global $errors, $wpcoDb, $Product, $Order, $Item, $Country, $wpcoHtml, $Discount;
  2.                                 require_once(dirname(__FILE__) . DS . 'includes' . DS . 'constants.php');
  3.  
  4.                                 $order_id = $Order -> current_order_id();
  5.                                 $wpcoDb -> model = $Order -> model;
  6.                                 $order = $wpcoDb -> find(array('id' => $order_id));
  7.                                 $wpcoDb -> model = $Item -> model;
  8.                                 $items = $wpcoDb -> find_all(array('order_id' => $order_id));
  9.                                 $user = $this -> userdata($order -> user_id);
  10.                                 $pmethod = "pp_pro";
  11.                                
  12.                                 $success = false;
  13.                                 $errors = null;
  14.                                 if (empty($_POST['creditCardNumber'])) { $errors['creditCardNumber'] = __('Please fill in a credit card number.', $this -> plugin_name); }
  15.                                 elseif (!is_numeric($_POST['creditCardNumber'])) { $errors['creditCardNumber'] = __('Only numbers are allowed in the credit card number.', $this -> plugin_name); }
  16.                                 if (empty($_POST['expDateMonth']) || empty($_POST['expDateYear'])) { $errors['expDate'] = __('Please choose an expiry date.', $this -> plugin_name); }
  17.                                 if (empty($_POST['cvv2Number'])) { $errors['cvv2Number'] = __('Please fill in a security code.', $this -> plugin_name); }
  18.                                 elseif (!is_numeric($_POST['cvv2Number'])) { $errors['cvv2Number'] = __('Only numbers are allowed for the security code.', $this -> plugin_name); }
  19.  
  20.                                 if (empty($errors)) {                                  
  21.                                     require_once $this -> plugin_base() . DS . 'vendors' . DS . 'gateways' . DS . 'class.pp_pro.php';
  22.                                    
  23.                                     $api_username = $this -> get_option('pp_pro_api_username');
  24.                                     $api_password = $this -> get_option('pp_pro_api_password');
  25.                                     $api_signature = $this -> get_option('pp_pro_api_signature');
  26.                                     $api_endpoint = $this -> get_option('pp_pro_api_endpoint');
  27.                                    
  28.                                     $email = urlencode($user -> user_email);
  29.                                     $firstName = urlencode($order -> bill_fname);
  30.                                     $lastName = urlencode($order -> bill_lname);
  31.                                     $creditCardType = urlencode($_POST['creditCardType']);
  32.                                     $creditCardNumber = urlencode($_POST['creditCardNumber']);
  33.                                     $expDateMonth = urlencode($_POST['expDateMonth']);
  34.                                     $expDateYear = urlencode($_POST['expDateYear']);
  35.                                     $cvv2Number = urlencode($_POST['cvv2Number']);
  36.                                     $address1 = urlencode($order -> bill_address);
  37.                                     $address2 = urlencode($order -> bill_address2);
  38.                                     $city = urlencode($order -> bill_city);
  39.                                     $state = urlencode($order -> bill_state);
  40.                                     $zip = urlencode($order -> bill_zipcode);
  41.                                     $amount = urlencode($order -> total);
  42.                                     $currencyCode = urlencode($this -> get_option('currency'));
  43.                                     $shiptophonenum = urlencode($order -> ship_phone);
  44.                                     $SHIPTONAME = urlencode($order -> ship_fname . ' ' . $order -> ship_lname);
  45.                                     $SHIPTOSTREET = urlencode($order -> ship_address);
  46.                                     $SHIPTOSTREET2 = urlencode($order -> ship_address2);
  47.                                     $shiptocity = urlencode($order -> ship_city);
  48.                                     $shiptostate = urlencode($order -> ship_state);
  49.                                     $shiptozip = urlencode($order -> ship_zipcode);
  50.                                     $wpcoDb -> model = $Country -> model;
  51.                                     $shiptocountry = $wpcoDb -> field('code', array('id' => $user -> ship_country));
  52.                                     $paymentAction = urlencode("Sale");
  53.                                     $IPADDRESS = urlencode($_SERVER['REMOTE_ADDR']);
  54.                                     $nvpRecurring = '';
  55.                                     $methodToCall = 'DoDirectPayment'; 
  56.                                    
  57.                                     $wpcoDb -> model = $Country -> model;
  58.                                     $countrycode = $wpcoDb -> field('code', array('id' => $user -> bill_country)); 
  59.                                    
  60.                                     if ($countrycode == "UK") { $countrycode = "GB"; }
  61.                                     if ($shiptocountry == "UK") { $shiptocountry = "GB"; }                 
  62.                                    
  63.                                     $nvpstr =
  64.                                     '&PAYMENTACTION=' . $paymentAction .
  65.                                     '&CUSTOM=' . $shipmethod_name .
  66.                                     '&IPADDRESS=' . $IPADDRESS .
  67.                                     '&AMT=' . $amount .
  68.                                     '&CREDITCARDTYPE=' . $creditCardType .
  69.                                     '&ACCT=' . $creditCardNumber .
  70.                                     '&EXPDATE=' . $expDateMonth . $expDateYear .
  71.                                     '&CVV2=' . $cvv2Number .
  72.                                     '&EMAIL=' . $email .
  73.                                     '&FIRSTNAME=' . $firstName .
  74.                                     '&LASTNAME=' . $lastName .
  75.                                     '&STREET=' . $address1 .
  76.                                     '&STREET2=' . $address2 .                                  
  77.                                     '&CITY=' . $city .
  78.                                     '&STATE=' . $state .
  79.                                     '&ZIP=' . $zip .
  80.                                     '&COUNTRYCODE=' . $countrycode .
  81.                                     '&CURRENCYCODE=' . $currencyCode .
  82.                                     '&SHIPTOPHONENUM=' . $shiptophonenum .
  83.                                     '&SHIPTONAME=' . $SHIPTONAME .
  84.                                     '&SHIPTOSTREET=' . $SHIPTOSTREET .
  85.                                     '&SHIPTOSTREET2=' . $SHIPTOSTREET2 .
  86.                                     '&SHIPTOCITY=' . $shiptocity .
  87.                                     '&SHIPTOSTATE=' . $shiptostate .
  88.                                     '&SHIPTOZIP=' . $shiptozip .
  89.                                     '&SHIPTOCOUNTRY=' . $shiptocountry;
  90.                                    
  91.                                     if ($Order -> do_shipping($order_id)) {
  92.                                         $shipmethod_name = $wpcoHtml -> shipmethod_name($order -> shipmethod_id);
  93.                                         $nvpstr .= '&CUSTOM=' . urlencode($shipmethod_name);
  94.                                        
  95.                                         if (!empty($order -> cu_shipmethod)) {
  96.                                             $nvpstr .= urlencode(' - ' . html_entity_decode($order -> cu_shipmethod));
  97.                                         }
  98.                                     }
  99.                                    
  100.                                     $subtotal = $Order -> total($order_id, false, false, true, true, false);
  101.                                     $shipping = $Order -> shipping_total($subtotal, $order_id);
  102.                                     $tax = $Order -> tax_total($order_id);
  103.                                    
  104.                                     $discount = $Discount -> total($order_id);
  105.                                     if ($this -> get_option('enablecoupons') == "Y" && $discount > 0) {
  106.                                        
  107.                                     } else {
  108.                                         $n = 0;
  109.                                         $itemamt = 0;
  110.    
  111.                                         if (!empty($items)) {                                  
  112.                                             foreach ($items as $item) {
  113.                                                 $itemamount = ($Product -> unit_price($item -> product -> id, $item -> count, $item -> id, false, true, false, false));
  114.                                                 $nvpstr .= '&L_NAME' . $n . '=' . urlencode($item -> product -> title);
  115.                                                 $nvpstr .= '&L_DESC' . $n . '=' . urlencode(substr(strip_tags($item -> product -> description), 0, 125));
  116.                                                 $nvpstr .= '&L_AMT' . $n . '=' . urlencode(number_format($itemamount, 2, '.', ''));
  117.                                                 $nvpstr .= '&L_NUMBER' . $n . '=' . urlencode($item -> product -> code);
  118.                                                 $nvpstr .= '&L_QTY' . $n . '=' . urlencode($item -> count);
  119.                                                
  120.                                                 $n++;
  121.                                                 $itemamt += ($itemamount * $item -> count);
  122.                                                 $itemamount = 0;
  123.                                             }
  124.                                            
  125.                                             $nvpstr .= '&ITEMAMT=' . urlencode(number_format($itemamt, 2, '.', ''));
  126.                                             $nvpstr .= '&SHIPPINGAMT=' . urlencode(number_format($shipping, 2, '.', ''));
  127.                                             $nvpstr .= '&TAXAMT=' . urlencode(number_format($tax, 2, '.', ''));
  128.                                         }
  129.                                     }
  130.                                    
  131.                                     $nvpstr .= $nvpRecurring;
  132.                                    
  133.                                     $paypalPro = new wpcopp_pro($api_username, $api_password, $api_signature, '', '', false, false, '57.0', $api_endpoint);
  134.                                     $resArray = $paypalPro -> hash_call($methodToCall, $nvpstr);
  135.                                     $ack = strtoupper($resArray["ACK"]);
  136.  
  137.                                     $ack = strtoupper($resArray["ACK"]);
  138.                                     if($ack != "SUCCESS")  {
  139.                                         $success = false;
  140.                                         $message = __('The transaction has been declined. Please try again.', $this -> plugin_name);                                           
  141.                                     } else {                                           
  142.                                         $success = true;
  143.                                         $message = __('The transaction was successful.', $this -> plugin_name);
  144.                                         $user_id = $user -> ID;    
  145.                                        
  146.                                         $this -> finalize_order($order_id, 'pp_pro', false, "Y");                                  
  147.                                     }
  148.                                    
  149.                                     $paypalPro -> message = $message;
  150.                                 } else {
  151.                                     $title = __('Processing Order', $this -> plugin_name);
  152.                                     $this -> process_order($title, $order, $user, $pmethod);   
  153.                                 }
  154.                                 break;
Advertisement
Add Comment
Please, Sign In to add comment