Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

[SOLVED] Family subscriptions with CBSubs and AutoActions

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
10 years 11 months ago - 10 years 10 months ago #238018 by OldLodgeSkins
Hi,

Me again ;)

I'm still trying to build a family subscriptions feature and I think I'm half-way now.
I have some additional fields showing up on the registration page when the family plan is selected, in order to collect a name & e-mail (I'm working on only one additional account for now, I'll add more once this works). I have an autoaction using the CB API to create the additional account - so far this works OK.

Now I'm trying to handle the cancellation case. If the main account owner cancels his subscription then the sub-account must be disabled.

After looking at the available options I'm guessing the right trigger would be onCPayUserStateChange - is this correct? Then how do I verify the exact state change that happened (i.e. it must be a cancellation or any other case where the user hasn't paid his subscription and the grace period is over). I do not want this to fire on renewals obviously...
And then knowing all I have is the sub-account's e-mail not the ID, is doing a query action the best way to go, or is there a CB function I can call to disable the account based on the e-mail address?

Thanks.

Seb.
Last edit: 10 years 10 months ago by OldLodgeSkins.

Please Log in or Create an account to join the conversation.

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
10 years 11 months ago #238025 by OldLodgeSkins
Replied by OldLodgeSkins on topic Family subscriptions with CBSubs and AutoActions
Quick update, I said the first part (signup) was working, but in fact something strange happens... Both accounts end up with a subscription.
The initial payment is affected to the sub-account and the main account's subscription remains unpaid...
I don't need to have a subscription on the sub-account. Is there a way to change this? Or maybe I could make a free plan that would not be manually selectable at signup and have that affected automatically to the sub-account?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
10 years 11 months ago - 10 years 10 months ago #238034 by krileon

I have an autoaction using the CB API to create the additional account - so far this works OK.

CB Auto Actions comes with a Registration action. You could use it and just substitute in your fields.

After looking at the available options I'm guessing the right trigger would be onCPayUserStateChange - is this correct?

Yes, you'd use it as follows.

Triggers: onCPayUserStateChange
Conditional 1: [var3] Equal To PLAN_ID_HERE
Conditional 2: [var2] Equal To STATUS

With the above STATUS can be as follows.

A = Active
R = Registered Unpaid
X = Expired
C = Unsubscribed
U = Upgraded to other
I = Invalid

And then knowing all I have is the sub-account's e-mail not the ID, is doing a query action the best way to go, or is there a CB function I can call to disable the account based on the e-mail address?

You'll probably want to do a query action based that uses the email address stored to the parent account. So the below for example will block an account.

Code:
UPDATE `#__users` SET `block` = 1 WHERE `email` = '[cb_child1email]'

You can probably just use CBSubs SQL Actions for this instead of a CB Auto Action though as it's already designed to handle various subscription states.

Quick update, I said the first part (signup) was working, but in fact something strange happens... Both accounts end up with a subscription.
The initial payment is affected to the sub-account and the main account's subscription remains unpaid...
I don't need to have a subscription on the sub-account. Is there a way to change this? Or maybe I could make a free plan that would not be manually selectable at signup and have that affected automatically to the sub-account?

CBSubs doesn't have a family subscription feature. So any specific usages on what you implemented I can not help you with.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 10 years 10 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
10 years 11 months ago #238045 by OldLodgeSkins
Replied by OldLodgeSkins on topic Family subscriptions with CBSubs and AutoActions
Hi again,

I know there's no family feature that's why I'm trying to make it manually...

I have partially solved the problem by using a different trigger, "onBeforeFirstLogin" - that way the sub-account isn't created immediately and the subscription is affected to the correct account.
When the user logs in for the first time the sub-account gets created but I get the "Chosen plans combination is not allowed" message and the login fails. I am guessing this is due to the sub-account not having any subscription (?) - I have set "Allow Free Registered Users (without subscriptions)" to Yes in CBSubs settings though...
Is there a way I could affect a subscription to the sub-account just after creating it?

For the record I'm using a code action and not a register action because I need to generate random user names. Here's the code I'm currently using:
Code:
global $_CB_database; if (!function_exists('generateRandomString')) { function generateRandomString($length = 10) { return substr(str_shuffle(implode(array_merge(range(0,9), range('A', 'Z'), range('a', 'z')))), 0, $length); } } /* $testUser = new moscomprofilerUser( $_CB_database ); $foundUser = $testUser->loadByUsername( $usrname ); if ( $foundUser ) { // Username Exists $usrname=''; $usrname=generateRandomString(25); } else { // Username Does Not Exist - nothing to do! } */ if (!function_exists('registerUser')) { function registerUser( $fname, $lname, $email, $username, $password, $approve = 0, $confirm = 2 ) { global $_CB_framework, $_CB_database, $ueConfig, $_PLUGINS; $approval = ( $approve == 2 ? $ueConfig['reg_admin_approval'] : $approve ); $confirmation = ( $confirm == 2 ? $ueConfig['reg_confirmation'] : $confirm ); $usertype = $_CB_framework->getCfg( 'new_usertype' ); $user = new moscomprofilerUser( $_CB_database ); $user->usertype = ( $usertype ? $usertype : 'Registered' ); $user->gid = $_CB_framework->acl->get_group_id( $user->usertype, 'ARO' ); $user->gids = array( $user->gid ); $user->sendEmail = 0; $user->registerDate = date( 'Y-m-d H:i:s', $_CB_framework->now() ); $user->name = $fname . ' ' . $lname; $user->firstname = $fname; $user->lastname = $lname; $user->username = $username; $user->email = $email; $user->password = $user->hashAndSaltPassword( $password ); $user->registeripaddr = cbGetIPlist(); if ( $approval == 0 ) { $user->approved = 1; } else { $user->approved = 0; } if ( $confirmation == 0 ) { $user->confirmed = 1; } else { $user->confirmed = 0; } if ( ( $user->confirmed == 1 ) && ( $user->approved == 1 ) ) { $user->block = 0; } else { $user->block = 1; } $_PLUGINS->trigger( 'onBeforeUserRegistration', array( &$user, &$user ) ); if ( $user->store() ) { if ( ( $user->confirmed == 0 ) && ( $confirmation != 0 ) ) { $user->_setActivationCode(); if ( ! $user->store() ) { return false; } } $_PLUGINS->trigger( 'onAfterUserRegistration', array( &$user, &$user, true ) ); return true; } return false; } } $friend1name = '[cb_friend1name]'; $friend2name = '[cb_friend2name]'; if (!empty($friend1name)) { $usrname = ''; $pass = ''; $usrname=generateRandomString(25); $pass=generateRandomString(8); registerUser('[cb_friend1name]','NA','[cb_family1]',$usrname,$pass); } if (!empty($friend2name)) { $usrname = ''; $pass = ''; $usrname=generateRandomString(25); $pass=generateRandomString(8); registerUser('[cb_friend2name]','NA','[cb_family2]',$usrname,$pass); }

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
10 years 10 months ago - 10 years 10 months ago #238072 by krileon

Is there a way I could affect a subscription to the sub-account just after creating it?

I guess you could set a field in the child account for it to be known as a child account. Then before login use a CB Paid Subscriptions action to give them a free subscription to something. You'd just need to condition for the field that determines they're a child account.

For the record I'm using a code action and not a register action because I need to generate random user names. Here's the code I'm currently using:

Use the after registration trigger in a Code action with Method set to PHP. Next generate your random usernames. Now add them to the post. In your Registration action you can access the randomly generated usernames that you added to post using [post_MYVAR]. Example as follows.

Code:
$_POST['cb_friend1username'] = generateRandomString( 25 );

Now in your action you access the above with [post_cb_friend1username]. Be sure your registration actions are ordered after this one so they fire after the PHP one is done adding to post. This should eliminate your need for a bunch of custom coding.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 10 years 10 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • OldLodgeSkins
  • OldLodgeSkins
  • OFFLINE
  • Posts: 119
  • Thanks: 5
  • Karma: 2
  • Add-ons
10 years 10 months ago #238090 by OldLodgeSkins
Replied by OldLodgeSkins on topic Family subscriptions with CBSubs and AutoActions
You're sure you don't live in a lamp and don't have a blue skin Mr Genius?

If I do as you said on after registration I end up with the same old problem I had at the beginning - the sub is affected to the secondary account, this is visible as soon as you reach the second registration step which shows the subscription you're about to take, it's the secondary account's name that shows up there.
However, if I do exactly the same thing, but with onBeforeFirstLogin trigger... It nearly works, I feel the solution is close! Both accounts are created (with the second one being created when the main user logs in for the first time of course), the main account has its subscription, the sub-account seems to be on a free no-subscription mode... Looks ok. Except I requested a password change for the sub-account (the password wasn't sent by e-mail but I was expecting this), it worked I got the e-mail with the new password, I logged in with it and got the message about the "Chosen plans combination is not allowed" - for the sub-account, the main one works fine.
I feel if I could just automatically affect the sub-account to a free lifetime plan I have created this would solve the problem... In CBSubs settings I have:

Allow Free Registered Users (without subscriptions): YES
Create Subscriptions also for free lifetime plans: YES

And I do have a free lifetime plan, set not to show at signup though as I don't want people to access it on their own... Shouldn't the sub-account have been given that plan? Or did I miss something? Should I put the second setting to NO?

Anyway I think I'm really close to the solution, thanks to you...

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum