Recurly accounts consist of a required unique account code

We strongly recommend you use an account code unique to your system, such as the auto-incrementing ID from your users database. Email addresses change and are not guaranteed to be unique, so we discourage using emails for your account code.

a first name and last name, username, company name, accept_language, email and billing info which

if present the account will only be created or updated after the billing information is validated

.

The request is to resolve if an Account page is necessary as a user-facing page as per Add user-facing pages for managing subscriptions. An account page could show the basic information associated with a Recurly account including the state of the account, which could be "active", "closed" or "past_due". If "past_due", meaning the account has at least one uncollected (failing payment) invoice, then this state should be very visible on this page similar to Include a past due status on user-facing subscription page. The account page could offer a way for users to edit/update the information associated with their Recurly account, maybe even set their preferred language. The other option is to use hook_user_update.

CommentFileSizeAuthor
#9 recurly_sync_account.patch11.05 KBquicksketch

Comments

quicksketch’s picture

The account page could offer a way for users to edit/update the information associated with their Recurly account, maybe even set their preferred language. The other option is to use hook_user_update.

I think the ability to edit/update account information is essentially the same as update billing information, is it not? Users can already update their information through #1627930: Introduce RecurlyJS module for updating billing information/subscribing, but of course they also have to update their credit card at the same time. I'm not sure updating contact information independently is really a necessary option, or if we did, we should use hook_user_update() like you suggest.

Setting preferred language seems like it should definitely just be pulled from Locale module.

blasthaus’s picture

Agreed. Just that the email address needs to be taken into account. If a user changes their email in Drupal, I think we have to change it at Recurly due to the dunning process. Billing info will not alter their basic account data and if we force it to, you may end up with account holders that don't match Drupal users. One other thing to note is the idea of tokens that we can use to customize the Recurly emails that go out as described in the Recurly docs, especially when it comes to providing links to their account. I like the idea of hook_user_update to at least deal with the email address to ensure that is correct. The full extent of that would be to allow in recurly_settings, fields on user that you have to map to the first name, last name, company name, but that may be overkill. Also there may be instances of a user who is using a company credit card, a spouse's or vise versa, but again it doesn't seem like such an issue. In fact the only real advantage I can see of having this page is for admin's to be able to act on a user's account, like suspend it or cancel it, but that could also live somewhere else.

quicksketch’s picture

Just that the email address needs to be taken into account. If a user changes their email in Drupal, I think we have to change it at Recurly due to the dunning process.

Good thinking, I hadn't thought of that.

One other thing to note is the idea of tokens that we can use to customize the Recurly emails that go out as described in the Recurly docs, especially when it comes to providing links to their account.

I also hadn't thought of that; glad you're around! :D

This makes me think that my approach of setting the "account_code" to be something like "user-1" could cause problems generating links to Drupal user accounts. In order to work we'd need to provide some redirect URL on the Drupal side (which honestly would probably be a good idea anyway). Something like http://example.com/subscription/account/[account-code], which would load the record from the recurly_account table and redirect to the proper Drupal user URL, http://example.com/user/1/subscription. Then we wouldn't be dependent upon our account codes lining up at all between Recurly and Drupal.

quicksketch’s picture

To handle the syncing of data over to Recurly, I think the best approach would be to pull out text values of fields and send them over to Recurly. I suggest handling this configuration through tokens, with each Recurly field mapping to a particular token. This approach is both more flexible and more likely to fit with most configurations of user accounts than a straight "Recurly field to Drupal field" mapping. The reason being a lot of fields in Drupal potentially contain multiple pieces, such as an addressfield, which would need to be split into address1, address2, city, state/province, zip, etc. Using tokens these could be pulled out easily such as [user:address_field:address1]. Additionally tokens would give an extra power to situations where the "account holder" on Recurly is not the same as the Drupal user account. For example you could have a subscription bound to a node, and then have the author of that node be the source of contact information in Recurly by using a token like [node:author:mail].

I'll look into this syncing business later today and see what this looks like in code.

blasthaus’s picture

Just to pull this into scope a bit, is the intent still to enable all entities to be referenced when setting the account_code and do the prefix of [entity_name]-[id]? Looking at my code, I have a subscription object and an account_code field. Could I use the account_code field (note this is not a unique field as user's can have multiple subscriptions)? My account_code field will auto increment only if we're setting up a new subscription for a new account.

Also do you see any sense in doing a module_invoke_all on the creation of the account code or does that break everything? My original thinking as you may have noticed was to have an admin setting for a prefix for cases where several different sites are using the same Recurly account and you need to distinguish between them. So setting the prefix you may end up with for example site1-subscription-1 and site2-subscription-1.

quicksketch’s picture

Also do you see any sense in doing a module_invoke_all on the creation of the account code or does that break everything? My original thinking as you may have noticed was to have an admin setting for a prefix for cases where several different sites are using the same Recurly account and you need to distinguish between them. So setting the prefix you may end up with for example site1-subscription-1 and site2-subscription-1.

How about we simply make a settings.php "hidden variable" for setting the "recurly_prefix", similar to a database table prefix? I wouldn't want to make it a UI option, considering if you ever changed your recurly prefix, it'd have far-reaching effects (you'd need to update all your newly created Recurly accounts for example). As with any setting, you could define it in settings.php as such:

$conf['recurly_prefix'] = 'sitename';

I think having a hook for the creation of the account code would be fine, since it doesn't really matter what the account code is, just as long as Drupal can map the account code to a user/entity. Alternatively you could insert the row into the recurly_account table directly to provide the mapping manually, that might actually be a cleaner approach than some kind of hook.

I'm not quite sure what you mean by account code not being unique (because users can have more than one subscription). That seems confusing to me because users can already have more than one subscription per account (but not two of the same one).

blasthaus’s picture

I'm with you. The prefix in settings.php is a good call. What I said was confusing. I have a subscription table with a subscription_id, account_code, etc. The account_code is not unique to that column in the db. (locally it's not unique since it can be attached to several subscriptions) But what is unique is the subscription_id (and Recurly's unique id uuid for the subscription). Like you said it doesn't really matter what the account code is, as long as some other field is present on the entity type to link it to a user/entity. I was always thinking that of the account_code as a token, that could be parsed to get relevant information. i.e. $user->uid . ':' . $order->order_id . ':' . time(); or some such.

One other non-issue for me but I thought about is what if users who already have Recurly subscriptions (and their own account codes) want to migrate to Drupal use this module. It's kind of a far-reaching task to provide this but something that may come up.

quicksketch’s picture

One other non-issue for me but I thought about is what if users who already have Recurly subscriptions (and their own account codes) want to migrate to Drupal use this module. It's kind of a far-reaching task to provide this but something that may come up.

I think the convention of using "$entity_type-$entity_id" as the account code is really only relevant for the creation of new Recurly accounts, and really only applies to using the "managed_pages" module, since that's the only situation where you don't have any idea what Drupal user account was associated with the Recurly account_code. Once the record is made in the "recurly_account" database table, the format or contents of the account_code become largely irrelevant. So a user moving to this module after having used Recurly beforehand could simply query Recurly for all accounts, and do whatever mapping made sense to get them into the Drupal "recurly_account" database table. There's no need to update the account_code in Recurly, the only thing we need is the mapping.

quicksketch’s picture

Status: Active » Fixed
StatusFileSize
new11.05 KB

This patch adds the basics of account management through tokens. So far it only concerns itself with Contact information on the account and not with billing information. I couldn't rationalize pushing billing information to Recurly, since the billing information is likely bound to the credit card information.

In any case it's a good start and solves the basics of the problem in an easy way. Patch contains a little cleanup to RecurlyJS module that I encountered while updating recurlyjs_menu().

quicksketch’s picture

Title: Include an Account page for managing accounts » Push account updates to Recurly contact information

In order to work we'd need to provide some redirect URL on the Drupal side (which honestly would probably be a good idea anyway). Something like http://example.com/subscription/account/[account-code], which would load the record from the recurly_account table and redirect to the proper Drupal user URL, http://example.com/user/1/subscription. Then we wouldn't be dependent upon our account codes lining up at all between Recurly and Drupal.

I opened an issue for this: #1643720: Provide an account_code to Entity redirect URL

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.