[BuyCred] Item Name Variable

front page Forums Community [BuyCred] Item Name Variable

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #5749
    Avatarmendie

    Hello! I need the Item Name for the Payment Gateways to be set on the front end, depending on what someone “donates.” For example, right now you can only set up the Item Name in the Payment Gateways section. What I am planning on doing is a sort of “crowdfunding,” where users can choose what to “donate” on, and in return they get points. The easiest way I can see, is if the item name can be changed in the shortcode.

    For example [mycred_buy gateway="paypal-standard" amount="100" "Donation for X"][mycred_buy gateway="paypal-standard" amount="100" "Donation for Y"]

    Any help on this would be appreciated!! Thanks!

    #5764
    AvatarWPExperts

    Hi.

    I am not sure if this is what you looking for but you can wrap the mycred_buy shortcode around text to set the button title:

    [mycred_buy amount="100" gateway="paypal-standard"]Donation for X[/mycred_buy]
    

    Let me know if this is not what you are looking for.

    #5768
    Avatarmendie

    Sorry no.. I need it for the actual data I get back from Paypal and Stripe… It needs to be in the order summary so that I know what the money will be for.

    #5784
    AvatarWPExperts

    Ah! I see! Thats is possible but is a bit more complicated.

    We would first need to create our own “buy button” which will then indicate that his is a “donation”. Then we would need to to hook into the gateway processor and pass along this info to the gateway and in when the payment is confirmed by the gateway, add this marker to the log entry.

    Once you have this marker saved in the log, we can add a custom column for the log page where this marker is shown (if set) showing you what are donations and what are points purchases.

    You can find the code here and Ill go though it below.

    1. Create the shortcode
    Ok so this is the easy part. We can mimic the mycred_buy shortcode and add an extra shortcode attribute where you can set this marker that will be shown in the log. In this example Ill use “Donation”.

    Example usage:

    [mycred_custom_buy gateway="" amount="" marker="Donation"]
    

    2. Inject marker into gateway call.
    Each gateway has the option to pass along extra data to the gateway that gets sent back on confirmed payments.

    In this example we will use the paypal gateway but the same can be applied to all gateways.

    3. Display Marker.
    Finally I add a custom column to the payments log in your admin area. This requires you to have the custom log page enabled for buyCRED. Go to myCRED > Settings > buyCRED and select show logs on a separate page.

    Requires version 1.4 or higher!
    If the column is not showing up in the admin area, try and download a fresh copy of 1.4 and replace your current version. There was a bug with relation to the columns I fixed.

    #5805
    Avatarmendie

    Thank you so much for this! I tried it out but I’m getting “myCRED is not installed”…
    This is the code that I put into functions.php :

    /** Step 1 - Create custom Shortcode
     * Creates a custom buyCRED shortcode that includes
     * the marker attribute that is passed on to the gateway.
     * @version 1.0
     */
    add_shortcode( 'mycred_custom_buy', 'mycred_render_custom_buy_shortcode' );
    function mycred_render_custom_buy_shortcode( $atts, $title = 'Buy Points' ) {
    	if ( ! function_exists( 'mycred' ) ) return 'myCRED is not installed';
     
    	extract( shortcode_atts( array(
    		'gateway' => '',
    		'amount'  => '',
    		'gift_to' => false,
    		'marker'  => '',
    		'class'   => 'mycred-buy-link button large custom',
    		'login'   => 'Please login to buy points'
    	), $atts ) );
     
    	// Load myCRED
    	$mycred = mycred();
     
    	// If we are not logged in
    	if ( ! is_user_logged_in() ) return '<div class="mycred-buy login">' . $mycred->template_tags_general( $login ) . '</div>';
     
    	$url = get_bloginfo( 'url' ) . '/';
    	$args = array(
    		'mycred_buy' => $gateway,
    		'amount'     => $mycred->number( $amount ),
    		'token'      => wp_create_nonce( 'mycred-buy-creds' ),
    		'marker'     => $marker
    	);
     
    	// Classes
    	$classes = explode( ' ', $class );
    	if ( empty( $classes ) )
    		$classes = array( 'mycred-buy-link', 'button large', 'custom' );
    	$classes[] = $gateway;
     
    	$title = $mycred->template_tags_general( $title );
     
    	// Element to return
    	$element = '<a href="' . add_query_arg( $args, $url ) . '" class="' . implode( ' ', $classes ) . '" title="' . $title . '">' . $title . '</a>';
     
    	return $element;
    }
     
    /**
     * Step 2 - Inject Marker
     * Next we inject our marker into the data sent to the gateway.
     * You would need to add a filter for each gateway you want this to support.
     * filter: mycred_{gateway id}_extra. Replace gateway with the gateway name.
     * Replace - with _ and remember to always return a result!
     * @version 1.0
     */
    add_filter( 'mycred_paypal_standard_extra', 'mycred_inject_marker_for_paypal', 10, 6 );
    function mycred_inject_marker_for_paypal( $extra, $cost, $from, $to, $gateway_prefs, $mycred ) {
    	// Only add marker if it is set and not empty
    	if ( isset( $_REQUEST['marker'] ) && ! empty( $_REQUEST['marker'] ) )
    		return sanitize_text_field( $_REQUEST['marker'] );
     
    	return $extra;
    }
    add_filter( 'mycred_stripe_extra', 'mycred_inject_marker_for_stripe', 10, 6 );
    function mycred_inject_marker_for_stripe( $extra, $cost, $from, $to, $gateway_prefs, $mycred ) {
    	// Only add marker if it is set and not empty
    	if ( isset( $_REQUEST['marker'] ) && ! empty( $_REQUEST['marker'] ) )
    		return sanitize_text_field( $_REQUEST['marker'] );
     
    	return $extra;
    }
     
    /**
     * Step 3 - Insert a custom payment column
     * Finally we will insert a custom column on the payment log to
     * show if a marker has been used for this payment.
     * @version 1.0
     */
    add_filter( 'mycred_buycred_log_columns', 'mycred_adjust_purchase_log_columns' );
    function mycred_adjust_purchase_log_columns( $columns ) {
    	$columns['column-marker'] = 'Marker';
    	return $columns;
    }
    add_action( 'mycred_payment_log_column-marker', 'mycred_payment_column_marker' );
    function mycred_payment_column_marker( $log_entry ) {
    	$data = maybe_unserialize( $log_entry->data );
    	if ( isset( $data['sales_data'] ) ) {
    		list ( $buyer_id, $payer_id, $amount, $cost, $currency, $token, $other ) = explode( '|', $data['sales_data'] );
    		
    		// Marker is saved under "other" last in the array.
    		echo $other;
    	}
    	else {
    		echo 'n/a';
    	}
    }

    Sorry I’m so noob when it comes to programming :/ I think I did something wrong in step 2 I’m not so sure what “Replace – with _” meant …

    #5827
    AvatarWPExperts

    If you are getting the “myCRED is not installed” error, then you either not using version 1.4 or the code is pasted in the wrong location or myCRED is disabled.

    Can you tell me what version you are currently using?

    #5844
    Avatarmendie

    Oh you’re right I wasn’t upgraded… but now it works! Thank you sooo much!!

    #5936
    Avatarmendie

    Hey, I thought it was all working, but my Stripe payments don’t seem to be making it to the Payment Log :/

    #5937
    AvatarWPExperts

    If you go to myCRED > Payment Gateways, do you have a “Last Payment Notifications”?

    #5938
    AvatarWPExperts

    Also, have you updated the Stripe gateway to the latest version (version 1.0.2)?

    I can see that you have not entered your license key here on the myCRED site so you are not getting any update notices.

    #5955
    Avatarmendie

    I do have a last payment notifications and I just updated to the newest update. I had no idea I was supposed to enter my license key! I was wondering why I wasn’t being notified of updates 😛

    So I updated and I still am not getting Stripe in the Payment logs :/ Neither in last payment notifications

    #5972
    AvatarWPExperts

    Hi!

    You should have a notice in your order email that licenses needs to be setup. I will make an effort to be more clear in the future. Apologies.

    Is Sandbox mode enabled?

    #6004
    Avatarmendie

    Sandbox mode is not enabled, it’s on live mode

    #6046
    AvatarWPExperts

    If you login to your Strip account, and check under “Events & Webhooks” in your Stripe account, does the purchases get registered?
    Do you have any errors or callbacks under the “Log” in your Stripe account? Stripe will record every incoming request and every outgoing confirmations and myCRED purchases will show up here as well.

    #6063
    Avatarmendie

    I can see it on my Events & Webhooks ok and under the log there are no errors and it correctly saves the customer and charges them. Are your stripe charges showing up on your mycred log?

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic.

11