serveit-ca / curastreamPlugin

Curastream
https://www.curastream.com
0 stars 0 forks source link

Group Management #74

Open SideonDeaka opened 5 years ago

SideonDeaka commented 5 years ago
SideonDeaka commented 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

SideonDeaka commented 5 years ago

Groups Development - Create Git Issue and Briefing

serveit-ca commented 5 years ago

this is looking great!

SideonDeaka commented 5 years ago

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);

SideonDeaka commented 5 years ago

We might want to add some defaults in there, but this db structure will work for creating functions

SideonDeaka commented 5 years ago

Groups Development - Create Database Structure

SideonDeaka commented 5 years ago

Groups Development - Create Functions as Per Git Issue

SideonDeaka commented 5 years ago

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.

SideonDeaka commented 5 years ago

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.

serveit-ca commented 5 years ago

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.

serveit-ca commented 5 years ago

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.

serveit-ca commented 5 years ago

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

screen shot 2019-02-13 at 10 29 02 am

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)

SideonDeaka commented 5 years ago

Groups Development - Memberpress Web Hooks

serveit-ca commented 5 years ago

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?    

serveit-ca commented 5 years ago

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.

  1. Create a Custom Field for the Company Name screen shot 2019-02-15 at 4 40 18 pm

  2. Edit the membership to ensure it has the company field active (Member Press -> Memberships) screen shot 2019-02-15 at 4 41 33 pm

  3. Ensure the database is in MemberPress Test Mode screen shot 2019-02-15 at 4 42 54 pm

  4. Complete a purchase of the membership entering the company name Use Test Card 4242 4242 4242 4242 with a future date

  5. Confirm the company field is present in the get Member REST API Route

  6. 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.

This should get you started on this project.

SideonDeaka commented 5 years ago

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.

SideonDeaka commented 5 years ago

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

SideonDeaka commented 5 years ago

@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.

SideonDeaka commented 5 years ago

Groups Development - Refactor to New Object

SideonDeaka commented 5 years ago

Refactor is done, Some things may break, make sure we are testing before pushing live.