Drupal Commerce: Set Order as Paid in Full I am trying to import records from a CSV file (from another non-drupal database) for a membership site I am porting to Drupal 7. I have Drupal Commerce, Commerce Recurring Framework set up. Everything works as it should when you go through the proper work flow. However, I have 2000+ records that need to be added to the site and going through that process doesn't make sense. In other words, I am writing a script to set up the order and then recurring entity for each user. 

I have code that creates my order, the issue is that Commerce is looking for a payment to be made before it creates the recurring entity for the order. Again, that doesn't make sense from a time perspective, not to mention all of these members have already paid as these are being ported. So my question is how to I trigger the order paid in full event that will trigger the creation of the recurring entity being created? Or is there a way to just create the recurring entity?

Here is my code:

&lt;?php
foreach ($records as $record) {
$product_sku = $record['sku'];

$order = commerce_order_new($user-&gt;uid, 'completed');

commerce_order_save($order);

$product = commerce_product_load_by_sku($product_sku);
$line_item = commerce_product_line_item_new($product, 1, $order-&gt;order_id); 

commerce_line_item_save($line_item);

$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper-&gt;commerce_line_items[] = $line_item;

commerce_order_save($order);
}
?&gt;


Thanks,
Aaron
If you want to trigger the paid in full event you just need to make the order balance 0. You can do that by adding a payment transaction for the full amount to the order. The event is then triggered when that new successful transaction is saved.

The relevant Commerce function is

commerce_payment_commerce_payment_transaction_insert

/**
 * Implements hook_commerce_payment_transaction_insert().
 *
 * When a new payment transaction is inserted that is already completed, check
 * the order balance and invoke a Rules event if the order is paid in full.
 */
function commerce_payment_commerce_payment_transaction_insert($transaction) {
  // If the inserted transaction was marked as a success and placed against a
  // valid order...
  if ($transaction-&gt;status == COMMERCE_PAYMENT_STATUS_SUCCESS &amp;&amp;
    $order = commerce_order_load($transaction-&gt;order_id)) {
    // Then check to make sure the event hasn't been invoked for this order.
    if (empty($order-&gt;data['commerce_payment_order_paid_in_full_invoked'])) {
      // Check the order balance and invoke the event.
      $balance = commerce_payment_order_balance($order);

      if ($balance['amount'] &lt;= 0) {
        // Invoke the event including a hook of the same name.
        rules_invoke_all('commerce_payment_order_paid_in_full', $order, $transaction);

        // Update the order's data array to indicate this just happened.
        $order-&gt;data['commerce_payment_order_paid_in_full_invoked'] = TRUE;

        // Save the updated order.
        commerce_order_save($order);
      }
    }
  }
}


The key part is here:

// Invoke the event including a hook of the same name.
rules_invoke_all('commerce_payment_order_paid_in_full', $order, $transaction);
// Update the order's data array to indicate this just happened.
$order-&gt;data['commerce_payment_order_paid_in_full_invoked'] = TRUE;

// Save the updated order.
commerce_order_save($order);


In any case, you'll need to create a valid transaction for the order to trigger the commerce_payment_order_paid_in_full event. Rules reacting to that event will expect the transaction object as an assumed parameter.