WordPress.org

Ready to get started?Download WordPress

Forums

myCRED
Bank Groups - possible? (9 posts)

  1. TaylorWestDesign
    Member
    Posted 11 months ago #

    I read your tutorial on setting up a central bank to deduct credits from. Here is the modification I want to develop -- is it possible?

    My site uses WooCommerce, and MyCreds is the currency people use to checkout with our products.

    I'd like a "Company" user account to be the bank, and the "Employees" user accounts of that company to checkout using their company's MyCred balance.

    So we might issue a company account 1000 credits. That company might have 10 employees, who each have accounts (with 0 creds each), but they can all use the company creds balance to make purchases at checkout until the company runs out.

    So essentially this would be setting up multiple banks, each with approved sub-accounts that could checkout using their associated bank -- but could NOT see or use other banks (other companies).

    Thoughts?

    http://wordpress.org/plugins/mycred/

  2. Gabriel
    Member
    Plugin Author

    Posted 11 months ago #

    Hi Taylor.

    Interesting concept. I assume each user would have some sort of meta data that would "link" them to a specific "business". For example each having a custom meta "employer_id" which would hold the User ID of the business account. With this, you could hook into the mycred_add filter and query each users business ID, then retrieve that businesses account balance and deduct / add points from that account instead.

  3. TaylorWestDesign
    Member
    Posted 11 months ago #

    Yes! That sounds about right.

    I'm a bit of a hack when it comes to this type of customization. How long do you think something like this would take to set up?

    Any chance you'd be up for developing it for me? Or writing a tutorial on how to accomplish it with specifics? I'd be willing to pay for the customization of course, but need it pretty soon for a product launch.

  4. fcpro
    Member
    Posted 11 months ago #

    Hi Taylor,
    For your information, we're building up a similar approach localy:
    "Company - Employees" users. We have decided to switch our wp installation for a Multi-Site instead, where Company has it's own subsite (site admin) and buying points for employees to earn them by clicking and visiting. This way, each Company can have their own Purchasing Points Policy.

    * We're using Master Template feature from ... mycred.me/about/features/multisites/

    Hope it helps.

  5. Gabriel
    Member
    Plugin Author

    Posted 11 months ago #

    I have pasted in a code that addresses your request. It's based on the code in the Central Bank Account tutorial. As you can see the difference is that instead of having a pre-defined bank account ID $bank_id = 1; we will attempt to get the users Company ID.

    For this example I assume each user has a custom user meta called 'company_id' which is the user id of the company that the user belongs to.

    add_filter( 'mycred_add', 'charge_bank_account', 10, 3 );
    function charge_bank_account( $reply, $request, $mycred )
    {
    	// Bank ID. Get users company ID (bank)
    	$bank_id = get_user_meta( $request['user_id'], 'company_id', true );
    	$bank_balance = $mycred->get_users_cred( $bank_id );
    
    	// Make sure that the request is not for our bank account
    	if ( $request['user_id'] == $bank_id ) return $reply;
    
    	$amount = $request['amount'];
    	// User is to lose points
    	if ( $amount < 0 ) {
    		// Add the points getting deducted to our bank account
    		// Dont forget to turn our negative value into a positive one!
    		$mycred->update_users_balance( $bank_id, abs( $amount ) );
    		// Log event
    		$mycred->add_to_log( $request['ref'], $bank_id, abs( $amount ), $request['entry'], $request['ref_id'], $request['data'], $request['type'] );
    	}
    	// User is to gain points
    	else {
    		// First make sure the bank is not bust
    		if ( $bank_balance <= 0 ) return false;
    
    		// Second we check if the bank is solvent
    		if ( $bank_balance-$amount <= 0 ) return false;
    
    		// If we have come this far, the bank has sufficient funds so lets deduct
    		$mycred->update_users_balance( $bank_id, 0-$amount );
    		// Log event
    		$mycred->add_to_log( $request['ref'], $bank_id, 0-$amount, $request['entry'], $request['ref_id'], $request['data'], $request['type'] );
    	}
    
    	// Return the result
    	return $reply;
    }
  6. TaylorWestDesign
    Member
    Posted 11 months ago #

    Gabriel,

    Thank you for the code. Here's what happened so far when using it:

    The sub-user had 0 credits and the associated "bank" had 10000 to start.

    When checking out with the sub-user's account, it wouldn't allow me to - giving the error "There is no payment method associated with your state".

    I then manually added 10 credits to the sub-user's account in the user administration area. This deducted 10 credits from the user's associated bank (now 9990).

    I tried to checkout with the sub-user again, and succeeded -- however, the credits used at checkout (1) were transferred back to the associated bank (now 9991).

    I also tried checking out with the bank user, which was successful. The bank user doesn't have a company_id either.

    So in summary:
    When "creating" credits for a user with a linked bank account, it removes those credits from the bank. (this is fine I suppose)

    A user cannot checkout using the bank's balance. -- this is a problem, as I need the bank to be available to the sub-user at checkout.

    A user with his own credits transfers them to their associated bank user after checkout -- this is a problem, as I need credits to disappear (like currency) after checkout.

    Any thoughts?

  7. Gabriel
    Member
    Plugin Author

    Posted 11 months ago #

    Hi Taylor.

    You are describing exactly what the above code does. Points "awarded" to users (poitive balance) is taken from the "bank account" while points lost is given back to that bank account.

    It sounds to me like you are rather looking for only adding points from the bank account but if the user uses these points, they are just deducted and not handed back.

  8. TaylorWestDesign
    Member
    Posted 11 months ago #

    Actually I'm really needing the bank to act as the connected user's "wallet" of sorts.

    In other words -- each user associated with the bank checks out (woocommerce) using the bank's balance instead of their own. They can/will have a ZERO personal balance, but still checkout since the only balance that matters to them is the bank/admin's balance.

    Here is the practical use scenario -- maybe this will help!

    1. A Company buys 100 credits from us, and now has a 100 credit balance
    2. The company signs up 10 sub-accounts for their employees, so that they can each login and purchase lunch from us.
    3. Each employee account retains zero balance -- but sees that the group's account is funded with credits, and so can make a purchase
    4. When an employee checks out with their lunch, it reduces the balance of the shared company account -- and is reflected across the entire group of employees.

    Currently, we're having to distribute credits evenly & manually among many employee accounts so each person can make purchases with us.

    This is a headache on it's own -- but worse is that each employee spends differently... so to get a good report or picture of how many credits a company has spent and has remaining we have to take into account ALL of their employee accounts.

  9. Gabriel
    Member
    Plugin Author

    Posted 11 months ago #

    Ok so we are talking about charging the "Bank" account instead of the current users account.

    In version 1.2 I have added a few new actions and filters to myCRED to give you more control over balances. One of these is the mycred_get_users_cred filter which we could use for your request to instead of returning the current users balance return the "banks" balance.

    Example:

    add_filter( 'mycred_get_users_cred', 'my_custom_balance', 10, 2 );
    function my_custom_balance( $balance, $mycred )
    {
    	$bank_id = 1;
    	$bank_balance = $mycred->get_users_cred( $bank_id );
    	return $bank_balance;
    }

    This hook (in the above example) will always return the banks balance (in this case user with ID 1).

    The 1.2 Beta is currently available from the plugin trunk.

Reply

You must log in to post.

About this Plugin

About this Topic