Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //require the bootstrap include
- require_once './includes/bootstrap.inc';
- //load Drupal API
- drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
- // create a new user with posted username,password,email
- $newUser = array(
- 'name' => $_POST['username'],
- 'pass' => $_POST['password'],
- 'mail' => $_POST['email'],
- 'status' => 1,
- 'init' => $_POST['email']
- );
- $user = user_save(null,$newUser);
- // hard coded product id for testing
- $productID = 56;
- $error_msg = FALSE;
- $node = node_load($productID);
- $product = uc_product_load($node);
- if (!$product)
- $error_msg = 'There was an error finding the requested product. Please contact an administrator.';
- // 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?)
- $product->nid = $node->nid;
- $product->qty = 1;
- $product->price = $node->cost;
- $product->title = $node->title;
- // create order object for this user
- $order = uc_order_new($user->uid, 'completed');
- $order_id = $order->order_id;
- $last_name = $_POST['lastName'];
- $first_names = $_POST['firstName'];
- $email = $_POST['email'];
- $street = $_POST['address'];
- $company = '';
- $city = $_POST['city'];
- $zone = $_POST['state'];
- $country = $_POST['country'];
- $postalcode = $_POST['postalcode'];
- // create payment object from posted info (hardcoded to visa for testing for now)
- $payment = array();
- $payment['cc_number'] = $_POST['cc_number'];
- $payment['cc_exp_month'] = $_POST['cc_exp_month'];
- $payment['cc_exp_year'] = $_POST['cc_exp_year'];
- $payment['cc_cvv'] = $_POST['cc_cvv'];
- $payment['cc_type'] = "Visa";
- $payment['cc_owner'] = $first_names . " " . $last_name;
- // fill out the order with the product,payment, and billing information
- $order->products[] = $product;
- $order->payment_details[] = $payment;
- $order->payment_method = 'credit';
- $order->primary_email = $email;
- $order->billing_first_name = $first_names;
- $order->billing_last_name = $last_name;
- $order->billing_company = $company;
- $order->billing_street1 = $street;
- $order->billing_postal_code = $postalcode;
- $order->billing_city = $city;
- $order->billing_zone = $zone;
- $order->billing_country = $country;
- // calculate order total
- $order->order_total = uc_order_get_total($order,TRUE);
- // save and complete order
- uc_order_save($order);
- uc_cart_complete_sale($order, TRUE);
- // process payment?
- uc_payment_enter($order->order_id, 'credit',$order->order_total, $user->uid, NULL, t('Checkout completed'));
- // check order status to see if payment was successful
- $order = uc_order_load($order->order_id);
- if ($order->order_status == 'payment_received'){
- echo "success";
- } else {
- echo "failure";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement