Version 2 for Commerce recurring framework is a module that closely resembles a "feature" and heavily relies on Fields & Rules for all the processes.

Structure

The module provides a new product type for basic recurring usage, but virtually any product type could be recurring.

Five fields are provided in the default product type.

  • Initial price - Sets the initial price of the product, this might be used to do trial periods. (Commerce price).
  • Initial period - Period or offset of after which the recurring price and period will be effective. (Interval field).
  • Recurring price - Price used for recurring the product. (Commerce price).
  • Recurring period - Periodicity to apply the recurring price. (Interval field)
  • End period - Period after wich end the recurring. (Interval field)

A new Recurring entity is provided with these fields and properties

  • Id.
  • User assigned to the recurring process.
  • Bundle (Product / Order).
  • Recurring reference - Entity reference field to the bundle (product or order).
  • Status property.
  • Price at the moment of creation.
  • Start date (Created date). Date property.
  • Due date. Calculation is based on start date + initial/recurring date.
  • End date (optional), it might be empty or created date + expiration period, or a given timestamp on cancelling the recurring. Date property.
  • Order reference (multiple), to all the orders associated with the recurring process, being 0 the initial one.

Recurring process

When an order containing a Recurring product is purchased for the first time for the current user, by default the module reacts on "Order is paid in full" event, a Recurring entity will be created associated with that product for the current order.

On a cron event, the recurring entities with past due dates are retrieved and an order is created for each recurring entity associated with the recurring product and customer.

Note: When this cron event runs it's the time to trigger the payments or use another technique to build a queue of payments.

All this process is driven through Rules so most of it is modifiable

How do I transform a "normal" product type into a recurring one

If a product has value on any of these fields, it will be considered as a recurring product.

  • commerce_recurring_ini_price
  • commerce_recurring_rec_price
  • commerce_recurring_ini_period
  • commerce_recurring_rec_period
  • commerce_recurring_end_period

There's room to improve this (i.e. with a hook).

Basic UI support through Entity API UI & Views

There's a Commerce Recurring UI submodule providing basic administration and user interface for the module, based in Views and Entity API so it's highly customizable.

Patches and notes

Extras

Roadmap

  • What happens if the payment fails? Take into account completed orders and assume a default behavior.
  • Initial period on recurring entity must be configurable by rules so you can override the initial period order.
  • Complete test coverage
  • Recurring Orders support

Comments

earthday47’s picture

Something that may not be obvious - If a "normal" product has a value for any recurring fields, it will be considered recurring. But the inverse is also true - If a product does NOT have a value for ALL of the recurring fields it will NOT recur and it will NOT appear under Recurring entities admin view.

So if you want to MIX recurring and non-recurring products in the same type, just add the 6 recurring fields to the product type, and then leave those fields blank for the non-recurring products.

This is most helpful if you have product types with extra fields and you don't want to create a duplicate product type just for recurring.

-Wes

83steps’s picture

I have been attempting this same thing Wes described but am not getting the same results. To attempt to add a non-recurring product of the same product type as some recurring ones, I created a new product of that type but left all the recurring fields blank (5 fields, not 6 ... 2 recurring price fields, 3 recurring period fields). I did enter 0 for the standard/regular commerce price field, because with that field empty the Add to Cart button is disabled on the product display node.

When I add the non-recurring product to the cart and check out, a recurring entity is created even though all 5 of the recurring fields are blank in the product. The recurring entity that is created has a price of $0 and due date of "0 sec". Consequentially, for as long as this recurring entity remains, a new order for $0 of type "Pending (Recurring order)" is created *every time* cron is run.

If anyone reading this knows how to make it so that a product with unused (blank) recurring fields can avoid triggering the creation of a recurring entity, please let me know!

83steps’s picture

I found the answer to the discrepancy I had run into. The code checks to see if the product type = 'recurring'. (This is the product type that the Commerce Recurring module creates by default for you). If so, it just automatically treats the product as recurring, without bothering to check the fields. If the product type != 'recurring', only then does it go ahead and look at the fields to see if they are set.

Since I had set up my products using the 'recurring' type, but wanted some of them to not recur if I left recurring fields blank, the solution is either to comment out line 472 of commerce_recurring.module or else set my products back up under a different product type.