BuddyDev

Search

Donation feature for buddypress

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #39933

    Hello,

    I want to encourage users to tip/donate to other members they like and follow or content creators, so I created a profile group called (BANK DETAILS) which consists of the following profile fields
    1. Bank name
    2. Account number
    3. Stripe address
    4. Paypal

    Now I created a donate page which is meant to display only the Bank details of the receiver and I used the code below to display the button in user profiles

     /**
     * Add custom buttons to profile header
     */
    function np_add_custom_buttons() {
    
    	if ( ! bp_is_my_profile() ) {
    		return;
    	}
    
    	$send_tip_button_args = array(
    		'id'                => 'np_send_tip',
    		'component'         => 'members',
    		'must_be_logged_in' => true,
    		'block_self'        => false,
    		'link_href'         => esc_url( 'https://www.site.com/send-tip/' ),
    		'link_text'         => __( 'Send Tip' ),
    	);
    
    	echo bp_get_button( $send_tip_button_args );
    }
    
    add_action( 'bp_member_header_actions', 'np_add_custom_buttons' ); 

    The problem now is how can I output the Bank details profile information of the recipient in a popup or a shortcode to display the bank details in a page.

    The feature will be similar to Twitter tip jar https://techcrunch.com/2021/05/06/twitter-tip-jar-lets-you-pay-people-for-good-tweetin/

    But only bank details profile info needs to be displayed.

    What do you think about this

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #39934

    The donate button can be displayed in three locations.

    1. Member profile header
    2. Members directory
    3. Blog post as (Send tip to Author)

    The donations would be peer to peer

    • This reply was modified 2 years, 7 months ago by Tosin.
  • Participant
    Level: Guru
    Posts: 885
    Tosin on #39986

    Any feedback sir

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #39988

    Hello Tosin,

    Please check the following code:

    https://github.com/buddydev/bp-shortcodes/blob/master/src/shortcodes/profile/class-profile-shortcode.php

    It allows displaying user data based on profile field group id. Please let me know if it helps or not.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #39992

    Thanks for the feedback
    1. Do I install the code as a plugin
    2. What is the shortcode text to be applied from the text below

     /**
    	 * Create shortcode
    	 */
    	private function setup() {
    		add_shortcode( 'bp-shortcodes-profile', array( $this, 'shortcode' ) );
    	} 
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #40002

    Hello Tosin,

    Yes, You have to install the plugin in order to use this shortcode.

    On single-user screen you can use shortcodes like:

    Replace id with your band detail field group id.

    
    
    [bp-shortcodes-profile context=display group_id=4]
    
    

    On the member directory and post screen, you have to provide shortcode attributes dynamically.

    Regards
    Ravi

    • This reply was modified 2 years, 7 months ago by Ravi.
  • Participant
    Level: Guru
    Posts: 885
    Tosin on #40015

    Making it dynamic is tricky

    Can something similar to this code be used to determine a dynamic url then the username is the url can be picked by the [bp-shortcodes-profile context=display group_id=4] to determine the context of the profile data

     function hibuddy_get_send_public_message_url() {
     
        $user_id = hibuddy_get_context_user_id();
     
        if ( ! $user_id || $user_id == bp_loggedin_user_id() ) {
            return;
        }
     
        if ( bp_is_my_profile() || ! is_user_logged_in() ) {
            return false;
        }
    	
    	$username = bp_core_get_username( $user_id );
     
        return apply_filters( 'hibuddy_get_send_public_message_url', wp_nonce_url( site_url() . '/news-feed/?r=' . $username ) );
    } 

    Maybe $username of the recipient can be picked [bp-shortcodes-profile context=display group_id=4] so context=username from the url

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #40019

    Hello Tosin,

    Thank you for sharing the code. Shortcode does provide an attribute name ‘user_id’. Have you tried this?

    
    do_shortcode( '[bp-shortcodes-profile user_id=' . hibuddy_get_context_user_id() . ' group_id=4]' );
    
    

    Please give it shot and let me know if it helps or not.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #40078

    I could not get anything to work, I just got confused with making the send donation link dynamic.

    WHAT IM TRYING TO ACHIVE

    1. Create a (send-donation) page which contains the shortcode [bp-shortcodes-profile context=display group_id=2]

    2. Clicking send donation link in either blog post or single user profile would redirect to (send-donation) page.

    3. On this page the potential donor/sender would see the bank details of the receiver determined by(username of post author or user profile)

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #40089

    Hello Tosin,

    Check the follwing code I have created for user profile using Nouveau Template pack:

    
    
    add_filter( 'bp_nouveau_get_members_buttons', function ( $buttons ) {
    
    	$user_id = bp_displayed_user_id();
    
    	$donation_page_link = add_query_arg(
    		array(
    			'user_id' => $user_id,
    			'nonce'   => wp_create_nonce( 'donate-' . $user_id ),
    		),
    		get_page_link( 68 ) // Replace by your donation page link.
    	);
    
    	$buttons['donation_link'] = array(
    		'id'                => 'donation_link',
    		'component'         => 'members',
    		'must_be_logged_in' => true,
    		'link_text'         => _x( 'Donate', 'button', 'buddypress' ),
    		'link_href'         => esc_url( $donation_page_link ),
    	);
    
    	return $buttons;
    } );
    
    add_filter( 'the_content', function ( $content ) {
    
    	// Our donation page link.
    	if ( ! is_page( 68 ) || ! isset( $_GET['user_id'] ) || ! $_GET['nonce'] ) {
    		return $content;
    	}
    
    	$user = get_user_by( 'id', absint( $_GET['user_id'] ) );
    
    	if ( ! $user || ! wp_verify_nonce( $_GET['nonce'], 'donate-' . $user->ID ) ) {
    		return $content;
    	}
    
    	ob_start();
    
    	echo do_shortcode( "[bp-shortcodes-profile user_id={$user->ID} group_id=2]" );
    
    	$shortcode_content = ob_get_clean();
    
    	return $content . $shortcode_content;
    } );
    
    

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved