Managing donations in Drupal Commerce
This question has come up quite a bit in IRC, e-mails, and the forum / issue queue. I want to just kickstart in this post a discussion that can result in one or more usable contributed modules for managing donations in Drupal Commerce.
When I think of a donation, I understand it as either a variable amount or some recommended amount of money given to an organization's general fund or dedicated to a specific initiative within that organization. On any given donation, then, you need to determine the amount from the customer, possibly get their designation, and then keep a nice tidy record of donations for end of year reports for both the donor and organization.
Often donations are the sole purpose of an e-commerce website, but they can also be collected on a site that sells other merchandise in a more traditional manner. This means a donation might be tacked onto another order, but donations might also all be handled through a standalone form that on one page allows the donor to designate an amount, fill in an address, provide payment details, and be done with a single click of the mouse.
The questions in integrating with Commerce revolve around how to get the designated amount, especially in cases where it's a free-form variable amount text field, and how to represent the donation on the order. I think these issues are connected, and I see two basic solutions off the top of my head:
- We can do like I did with UC Variable Price and create a donation "product" on the back end whose Add to Cart form includes an amount textfield. Upon submission, this amount would be stored in the product line item's data array. On subsequent loads of the shopping cart, this line item's unit price would always be set to the price value stored in the data array.
- Alternately we could create a donation line item type whose unit price isn't affected by the normal product pricing rules. In this case, the unit price would be set when the Add to Cart form is submitted, the line item would be added to the cart order, and its price wouldn't be changed (unless you built that ability into the cart form somehow or an administrator did it).
Either one of these things would be easily achievable in contrib.
Additionally, we'd want the ability to skip the cart and/or shorten the checkout process. If you are solely a donation site, you might get away with just creating a very simple form that accepts a donation amount, payment details, and submits by creating the order, adding the donation (or producT) line item, and being done. It really depends on your payment process... i.e. can you integrate the CC form into the donation form or do you have to redirect to PayPal and come back? I think most people will continue to need the Checkout form for payment reasons (and for combined donation / purchase orders), but that doesn't mean it can't be shortened / embedded on a donation specific page. The form isn't dependent on the checkout URLs, and it could be possible through some altering to change the checkout workflow to a single step submission when the form is embedded on a donation page.
The next question I'd have would be how to know where to embed the donation form. Any form ought to be standalone, able to function regardless of the display context. This is how Commerce entity forms work - the core order add / edit form makes no assumptions about URLs, redirects, etc. but is instantiated by the Order UI module to appear at a specific URL and redirect to another URL upon submission. If a custom donation form is treated the same way, it can then be made into a display formatter for the product reference field if you're using the product line item approach. It could be made into its own field if you're using the donation line item type approach and want to create a content type for unique donation pages. For either approach it might be enabled through some sort of Token that is replaced using a custom text format filter.
Really, this could go any number of ways, and ultimately it's going to depend on the various other business rules I've pointed out above:
- Does the site just need to accept donations?
- Does the site sell other products (i.e. swag, event registrations)? If so, does it support combined orders or would it still use a standalone donation form?
- What payment method will be used and can its payment form be included inline in a standalone donation form?
- How will the site report donations?
- Where will donation pages fit in the IA for the site?
Ultimately, I think we'll want multiple solutions. Recreating UC Variable Price for DC wouldn't be that difficult, and I don't think creating a donation line item type would be that difficult but may come with unexpected side effects due to some dependence on product line items in the cart / checkout workflow (those can be addressed). The bigger question will likely be how exactly you want the donation form to be displayed, and anything is possible... using the cart / checkout form as is, embedding a trimmed down checkout form on the donation page, or creating a custom donation form that simply creates a new order upon successful payment completion.
What other ideas do we have? And who's up for developing some of this? ; )