WordPress.org

Forums

myCRED
[resolved] Bonus Credits: Stripe Payment Add-On (14 posts)

  1. PaulMRivera
    Member
    Posted 1 year ago #

    I saw the code to award a user with bonus credits here: http://mycred.me/support/forums/topic/buycred-different-prices/

    How would the code be if I'm using the stripe add-on payment gateway? I would like to award 2 credits to users if they purchase 10 credits, and award 5 credits to users if the purchase 20 credits.

    Thanks for the help

    https://wordpress.org/plugins/mycred/

  2. Gabriel
    Member
    Plugin Author

    Posted 1 year ago #

    Hey!

    That particular code was written for PayPal but you can change it to work with Strip (or any other buyCRED gateway for that matter) by changing:

    buy_creds_with_paypal_standard

    to:

    buy_creds_with_stripe

    on the 6th line.

    Let me know if you require further assistance.

  3. PaulMRivera
    Member
    Posted 1 year ago #

    I have tried replacing that line of code already and it doesn't appear to work. Any other suggestions?

  4. Gabriel
    Member
    Plugin Author

    Posted 1 year ago #

    does the code work with PayPal?

  5. PaulMRivera
    Member
    Posted 1 year ago #

    I have not tried it with paypal because I do not have the account setup for that.

    I have been trying to mess with the code and still nothing seems to work.

  6. PaulMRivera
    Member
    Posted 1 year ago #

    Is there something I could add to the actual "mycred-stripe.php" in the stripe plugin folder that would award 2 credits to users if they purchase 10 credits, and award 5 credits to users if the purchase 20 credits since the code above isn't working?

    Thanks for the help.

  7. Gabriel
    Member
    Plugin Author

    Posted 1 year ago #

    Hey.

    A quick question:

    You are using the code from the support forum and I assume you made the change I suggested earlier. Did you remove the minimum 100 points check in the code?

    In the forum topic the user requested that only users who buy more then 100 points get this bonus. So if you try that code with less then 100 points purchases, it will not award points.

  8. PaulMRivera
    Member
    Posted 1 year ago #

    Yes I changed it to 9 instead of 100 to see if when i purchase 10, it will award 2.

  9. Gabriel
    Member
    Plugin Author

    Posted 1 year ago #

    Could you paste the code you are using in a pastebin so I can have a look?

  10. PaulMRivera
    Member
    Posted 1 year ago #

    add_filter( 'mycred_add', 'add_bonus_points_for_purchase', 10, 3 );
    function add_bonus_points_for_purchase( $reply, $request, $mycred )
    {
    	if ( $reply === false ) return $reply;
    	// For Stripe Payments
    	if ( $request['ref'] != 'buy_creds_with_stripe' ) {
    		$amount = $request['amount'];
    		// Award bonus for purchases over 9 points
    		if ( $amount == 10 ) {
    			// Give extra 2 points
    			// Remember not to use $mycred->add_creds() here or you will
    			// create an endless loop. Instead use update_users_balance()
    			$mycred->update_users_balance( $request['user_id'], 2 );
    			// Log the good news
    			$mycred->add_to_log(
    				'bonus_points',
    				$request['user_id'],
    				2,
    				'Bonus points for %plural% purchase!'
    			);
    		}
    	}
    
    	return $reply;
    }

    I also tried this (switching "==9" to "> 9":

    add_filter( 'mycred_add', 'add_bonus_points_for_purchase', 10, 3 );
    function add_bonus_points_for_purchase( $reply, $request, $mycred )
    {
    	if ( $reply === false ) return $reply;
    	// For Stripe Payments
    	if ( $request['ref'] != 'buy_creds_with_stripe' ) {
    		$amount = $request['amount'];
    		// Award bonus for purchases over 9 points
    		if ( $amount > 9 ) {
    			// Give extra 2 points
    			// Remember not to use $mycred->add_creds() here or you will
    			// create an endless loop. Instead use update_users_balance()
    			$mycred->update_users_balance( $request['user_id'], 2 );
    			// Log the good news
    			$mycred->add_to_log(
    				'bonus_points',
    				$request['user_id'],
    				2,
    				'Bonus points for %plural% purchase!'
    			);
    		}
    	}
    
    	return $reply;
    }
  11. Gabriel
    Member
    Plugin Author

    Posted 1 year ago #

    Change:

    $request['ref'] != 'buy_creds_with_stripe'

    to:

    $request['ref'] == 'buy_creds_with_stripe'
  12. PaulMRivera
    Member
    Posted 1 year ago #

    You are a god. Works perfectly now. Thanks!

  13. Gabriel
    Member
    Plugin Author

    Posted 1 year ago #

    Sometimes it's the smallest things.

  14. PaulMRivera
    Member
    Posted 1 year ago #

    Couldn't agree more. Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • myCRED
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.