tribulant

PayPal Pro

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