Open SideonDeaka opened 5 years ago
cura_groups id: Int(11) PK name: custom name for user groups, business name for corp groups. type: int(1): 0 - Not Assigned (Hidden??) 1- Corp 2- Custom/User
cura_group_users id: int(11) PK user_id FK - One User Assigned to 1 Group group_id FK - The Group User is Assigned privilege_level int(1) - 0 Group User / 1 - Group Admin / 2 - Group Owner
cura_group_programs id: int(11) pk group_id FK program_id FK
cura_corps id: int(11) PK mempr_id FK owner_id FK
cura_corps_groups id: int(11) PK group_id FK
this is looking great!
CREATE TABLE dev_cura_corps( id int(11) AUTO_INCREMENT, mempr_id int(11), name varchar(55) NOT NULL, PRIMARY KEY (id));
CREATE TABLE dev_cura_corp_groups( id int(11) AUTO_INCREMENT, group_id int(11) NOT NULL, corp_id int(11) NOT NULL, PRIMARY KEY(id));
CREATE TABLE dev_cura_groups( id int(11) AUTO_INCREMENT, name varchar(55) NOT NULL, type int(1) NOT NULL, PRIMARY KEY(id));
CREATE TABLE dev_cura_group_users( id int(11) AUTO_INCREMENT, user_id int(11) NOT NULL, group_id int(11) NOT NULL, privilege_level int(1) NOT NULL, PRIMARY KEY(id));
CREATE TABLE dev_cura_group_programs( id int(11) AUTO_INCREMENT, group_id int(11) NOT NULL, program_id int(11) NOT NULL, PRIMARY KEY(id));
ALTER TABLE dev_cura_user_programs ADD group_id int(11);
We might want to add some defaults in there, but this db structure will work for creating functions
Use Case Issue for both remove program from group and remove user from group functions. We have no way currently of knowing if a user had any specific program assigned from either another group or personally. This will cause a problem if their group admin removes them or a program they are/were working on individually it will be removed from their programs as a result.
Most of the functions I can think we will need have been created today, I will be moving forward with locally testing them tomorrow, after creating some test data both for myself and for the travis environment.
Can we create a page with not so beautiful output to start to see the groups in the Curastream Backend. i will make it beautiful but i am thinking we want to do have two tables. Custom Groups and Corporate groups.
[x] The Custom Group will have the group name, Number of users, User List, Program Assigned,
[x] The corpoarte groups will have the group name, Number of users, User List, Program Assigned, Corporate Account?
Adding Users to Corporate Groups Automatically, we can leverage the web hooks located here: https://curastream.com/wp-admin/admin.php?page=memberpress-developer-tools
The Web hooks page tells us which URL we want to talk to and the Events page shows us the JSON we should be receiving. I think MemberPress will automatically authenticate against themselves. Their support is really great and will provide more details.
hey @SideonDeaka,
here is an example of a webhook we create on this page https://curastream.com/wp-admin/admin.php?page=memberpress-developer-tools http:www.curastream.test/wp-json/curastream/v2/subAccountAdded
Then if we go look at the events tab we can see the event test button for the selected Web hook https://curastream.com/wp-admin/admin.php?page=memberpress-developer-tools
it will send the following code to the url setup in the web hook { "event": "sub-account-added", "type": "transaction", "data": { "membership": { "id": 6951, "title": "Corporate Membership 14", "content": "", "excerpt": "", "date": "2019-02-07 07:06:28", "status": "publish", "author": "7", "date_gmt": "2019-02-07 15:06:28", "modified": "2019-02-07 07:08:49", "modified_gmt": "2019-02-07 15:08:49", "group": "0", "price": "70.00", "period": "1", "period_type": "months", "signup_button_text": "Sign Up", "limit_cycles": false, "limit_cycles_num": "2", "limit_cycles_action": "expire", "trial": false, "trial_days": "0", "trial_amount": "0.00", "trial_once": "1", "group_order": "0", "is_highlighted": false, "plan_code": "", "pricing_title": "Corporate Membership 14", "pricing_show_price": true, "pricing_display": "auto", "custom_price": "", "pricing_heading_txt": "", "pricing_footer_txt": "", "pricing_button_txt": "Sign Up", "pricing_button_position": "footer", "pricing_benefits": [ "" ], "register_price_action": "default", "register_price": "", "thank_you_page_enabled": false, "thank_you_page_type": "message", "thank_you_message": "", "thank_you_page_id": "0", "custom_login_urls_enabled": false, "custom_login_urls_default": "", "custom_login_urls": [], "expire_type": "none", "expire_after": "1", "expire_unit": "days", "expire_fixed": "2019-02-07", "tax_exempt": false, "allow_renewal": false, "access_url": "", "disable_address_fields": false, "simultaneous_subscriptions": false, "use_custom_template": false, "custom_template": "blog-masonry-full-width.php", "customize_payment_methods": "1", "custom_payment_methods": [ "owxoan-254" ], "customize_profile_fields": false, "custom_profile_fields": [], "cannot_purchase_message": "You don't have access to purchase this item." }, "member": { "id": 200, "email": "fcibookkeeping@gmail.com", "username": "afaulkner2019", "nicename": "afaulkner2019", "url": "", "message": "", "registered_at": "2019-02-07 16:36:45", "first_name": "Ashley", "last_name": "Faulkner", "display_name": "Ashley Faulkner", "address": { "mepr-address-one": "", "mepr-address-two": "", "mepr-address-city": "", "mepr-address-state": "", "mepr-address-zip": "", "mepr-address-country": "" }, "profile": {} }, "coupon": "0", "subscription": "0", "id": "306", "amount": "0.00", "total": "0.00", "tax_amount": "0.00", "tax_rate": "0.000", "tax_desc": "", "tax_class": "standard", "trans_num": "mp-txn-5c5c5e9dd4162", "status": "complete", "txn_type": "sub_account", "gateway": "manual", "prorated": "0", "created_at": "2019-02-07 16:36:45", "expires_at": "2019-03-07 23:59:59", "corporate_account_id": "12", "parent_transaction_id": "293", "tax_compound": "0", "tax_shipping": "1", "response": null, "parent": { "id": 187, "email": "caroline.peters@sunlife.com", "username": "CPeters2019", "nicename": "cpeters2019", "url": "", "message": "", "registered_at": "2019-02-07 15:16:35", "first_name": "Caroline", "last_name": "Peters", "display_name": "CPeters2019", "address": { "mepr-address-one": "9519 100 Ave", "mepr-address-two": "", "mepr-address-city": "Fort St. John", "mepr-address-state": "BC", "mepr-address-zip": "V1J 1Y1", "mepr-address-country": "CA" }, "profile": {} }, "rebill": false, "subscription_payment_index": false } }
you would then listen for the event and detect if it is a valid request grab the member Id "member": { "id": 200, and use that to add it to the corporate account group based on the membership id or the parent id (Not sure how we are going to keep these accounts in sync yet but please play and see what we can do)
Cliff repliedFeb 13, 5:24pmHi Nathan,Subscription Created would be the webhook to use. Then you would just need to check the data > membership > id is an ID that is for a corporate membership level. I hope that helps point you in the right direction.--CliffWas I pleasant to deal with?
So we need 3 API endpoints to handle different activities
Here is a bit of info which may be helpful https://www.w3schools.com/php/func_error_log.asp --> This should help you with Debugging the logs you may need to use a echo phpinfo() to determine which log file is in use
Each of these three events will be triggered by a Web Hook which we will need to create on this page.
Create a Custom Field for the Company Name
Edit the membership to ensure it has the company field active (Member Press -> Memberships)
Ensure the database is in MemberPress Test Mode
Complete a purchase of the membership entering the company name Use Test Card 4242 4242 4242 4242 with a future date
Confirm the company field is present in the get Member REST API Route
You may have an issue where the new subscription does not pass the company name but if you do it manually you will be able to trigger it.
[ ] Add Sub Account to Corporate Account Group --> Sub Account Added
[ ] Remove Sub Account from Corporate Account Group -->Sub Account Removed
This should get you started on this project.
We are waiting on memberpress support in regards to the custom company name field, as well as the remove sub account not firing, will also wait the 24 hours as they have instructed.
Waiting on correspondence from member-press support, staging server is currently setup with access for them. Handing this off to you for now @serveit-ca
@serveit-ca Before Starting with pricing, I am going to refactor groups into its own object, and the group management page to work with said change, trello task to follow.
Refactor is done, Some things may break, make sure we are testing before pushing live.
[x] newCustomGroup - This Function will create a group and set a group type column to 2 in the groups table of the db
[x] newCorpGroup - This Function will create a group and set a group type column to 1 in the groups table of the db
[x] assignUserToGroup - This Function will take an already existing user and assign them to a group
[x] removeUserFromGroup - This Function will remove a user from an existing group
[x] assignProgramToGroup - This Function Assigns a Program to the Group and all of its members.
[x] removeProgramFromGroup - This Function Removes a Program from a Group and all of its members UNLESS a user has it personally assigned.
[x] getProgramsByGroupId - This Function Returns an array of ids of programs for a given group id.
[x] getUsersByGroupId - This Function Returns an array of user ids for a given group id.
[x] changeGroupUserPrivilege - This function takes a user id and a group id and changes their privilege level
[x] checkUserPrivilege - checks the user privilege level in the specified group
[x] checkGroupAssigned - This function checks to see if a user program is assigned by a group or not