Programmatically creating an order in Drupal Commerce for anonymous users redirecting to payment page
You may try to test a new module called Commerce Drush which has the following syntax:

drush commerce-order-add 1
drush --user=admin commerce-order-add MY_SKU123




Manual solution

For creating an order programatically in Commerce, you can use the following code (it works with drush as well, e.g. drush -vd -u "$1" scr order_code-7.php).
Please note that commerce_payment_example module is required.

&lt;?php

  if (!function_exists('drush_print')) {
    function drush_print ($text) {
      print $text . "\n";
    }
  }

  $is_cli = php_sapi_name() === 'cli';

  global $user;

  // Add the product to the cart
  $product_id = 5;
  $quantity = 1;

  if ($is_cli) {
    drush_print('Creating new order for ' . $quantity . ' item(s) of product ' . $product_id . '...');
  }

  // Create the new order in checkout; you might also check first to
  // see if your user already has an order to use instead of a new one.
  $order = commerce_order_new($user-&gt;uid, 'checkout_checkout');

  // Save the order to get its ID.
  commerce_order_save($order);

  if ($is_cli) {
    drush_print('Order created. Commerce order id is now ' . $order-&gt;order_id);
    drush_print('Searching product ' . $product_id . ' in a Commerce system...');
  }

  // Load whatever product represents the item the customer will be
  // paying for and create a line item for it.
  $product = commerce_product_load((int)$product_id);

  if((empty($product-&gt;product_id)) || (!$product-&gt;status)){
    if ($is_cli) {
      drush_print('  Cannot match given product id with a Commerce product id.');
    }

    drupal_set_message(t('Invalid product id'));
    drupal_goto(); // frontpage
    return FALSE;
  }

  if ($is_cli) {
    drush_print('  Found a Commerce product ' . $product-&gt;product_id . '.');
  }

  // Create new line item based on selected product
  $line_item = commerce_product_line_item_new($product, 1, $order-&gt;order_id);

  if ($is_cli) {
    drush_print('  Added product to the cart.');
  }

  // Save the line item to get its ID.
  commerce_line_item_save($line_item);

  // Add the line item to the order using fago's rockin' wrapper.
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $order_wrapper-&gt;commerce_line_items[] = $line_item;

  if ($is_cli) {
    drush_print('Saving order...');
  }

  // Save the order again to update its line item reference field.
  commerce_order_save($order);

  // Redirect to the order's checkout form. Obviously, if this were a
  // form submit handler, you'd just set $form_state['redirect'].

  if ($is_cli) {
    drush_print('Checking out the order...');
  }

  commerce_checkout_complete($order);

  if ($is_cli) {
    drush_print('Marking order as fully paid...');
  }

  $payment_method = commerce_payment_method_instance_load('commerce_payment_example|commerce_payment_commerce_payment_example');

  if (!$payment_method) {
    if ($is_cli) {
      drush_print("  No example payment method found, we can't mark order as fully paid. Please enable commerce_payment_example module to use this feature.");
    }
  }
  else {
    if ($is_cli) {
      drush_print("  Creating example transaction...");
    }

    // Creating new transaction via commerce_payment_example module.
    $charge      = $order-&gt;commerce_order_total['und'][0];

    $transaction = commerce_payment_transaction_new('commerce_payment_example', $order-&gt;order_id);
    $transaction-&gt;instance_id = $payment_method['instance_id'];
    $transaction-&gt;amount = $charge['amount'];
    $transaction-&gt;currency_code = $charge['currency_code'];
    $transaction-&gt;status = COMMERCE_PAYMENT_STATUS_SUCCESS;
    $transaction-&gt;message = 'Name: @name';
    $transaction-&gt;message_variables = array('@name' =&gt; 'Example payment');

    if ($is_cli) {
      drush_print("  Notifying Commerce about new transaction...");
    }

    commerce_payment_transaction_save($transaction);

    commerce_payment_commerce_payment_transaction_insert($transaction);
  }

  if ($is_cli) {
    drush_print("Marking order as completed...");
  }

  commerce_order_status_update($order, 'completed');

  if ($is_cli) {
    drush_print("\nDone.");
  }




Note: As suggested in the comment, if you got error about payment method is unknown while saving the order, make sure you've specified it, e.g.

$order-&gt;data['payment_method'] = 'commerce_payment_example|commerce_payment_commerce_payment_‌​example';
commerce_order_save($order);