Advertisement
Guest User

Untitled

a guest
Mar 25th, 2011
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.79 KB | None | 0 0
  1. <?php
  2.  
  3.     //require the bootstrap include
  4.     require_once './includes/bootstrap.inc';
  5.  
  6.     //load Drupal API
  7.     drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  8.  
  9.     // create a new user with posted username,password,email
  10.     $newUser = array(
  11.         'name' => $_POST['username'],
  12.         'pass' => $_POST['password'],
  13.         'mail' => $_POST['email'],
  14.         'status' => 1,
  15.         'init' => $_POST['email']
  16.  
  17.     );
  18.  
  19.     $user = user_save(null,$newUser);
  20.  
  21.     // hard coded product id for testing
  22.     $productID = 56;
  23.  
  24.     $error_msg = FALSE;
  25.        
  26.     $node = node_load($productID);
  27.     $product = uc_product_load($node);
  28.    
  29.     if (!$product)
  30.         $error_msg = 'There was an error finding the requested product. Please contact an administrator.';
  31.        
  32.     // build a product object from the node (saw this in an example, don't get why uc_product_load($node) doesn't do this already?)
  33.  
  34.     $product->nid = $node->nid;
  35.     $product->qty = 1;
  36.     $product->price = $node->cost;
  37.     $product->title = $node->title;
  38.      
  39.         // create order object for this user
  40.     $order = uc_order_new($user->uid, 'completed');
  41.     $order_id = $order->order_id;
  42.    
  43.     $last_name = $_POST['lastName'];
  44.     $first_names = $_POST['firstName'];
  45.     $email = $_POST['email'];
  46.     $street = $_POST['address'];
  47.     $company = '';
  48.     $city = $_POST['city'];
  49.     $zone = $_POST['state'];
  50.     $country = $_POST['country'];
  51.     $postalcode = $_POST['postalcode'];
  52.    
  53.         // create payment object from posted info (hardcoded to visa for testing for now)
  54.     $payment = array();
  55.     $payment['cc_number'] = $_POST['cc_number'];
  56.     $payment['cc_exp_month'] = $_POST['cc_exp_month'];
  57.     $payment['cc_exp_year'] = $_POST['cc_exp_year'];
  58.     $payment['cc_cvv'] = $_POST['cc_cvv'];
  59.     $payment['cc_type'] = "Visa";
  60.     $payment['cc_owner'] = $first_names . " " . $last_name;
  61.    
  62.         // fill out the order with the product,payment, and billing information
  63.     $order->products[] = $product;
  64.     $order->payment_details[] = $payment;
  65.     $order->payment_method = 'credit';
  66.     $order->primary_email = $email;
  67.     $order->billing_first_name = $first_names;
  68.     $order->billing_last_name = $last_name;
  69.     $order->billing_company = $company;
  70.     $order->billing_street1 = $street;
  71.     $order->billing_postal_code = $postalcode;
  72.     $order->billing_city = $city;
  73.     $order->billing_zone = $zone;
  74.     $order->billing_country = $country;
  75.    
  76.         // calculate order total
  77.     $order->order_total = uc_order_get_total($order,TRUE);
  78.    
  79.         // save and complete order
  80.     uc_order_save($order);
  81.     uc_cart_complete_sale($order, TRUE);
  82.  
  83.         // process payment?
  84.     uc_payment_enter($order->order_id, 'credit',$order->order_total, $user->uid, NULL, t('Checkout completed'));
  85.    
  86.         // check order status to see if payment was successful
  87.     $order = uc_order_load($order->order_id);
  88.     if ($order->order_status == 'payment_received'){
  89.         echo "success";
  90.     } else {
  91.         echo "failure";
  92.     }
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement