WordPress.org

Ready to get started?Download WordPress

Forums

eWAY Payment Gateway
[resolved] Events Manager Integration (12 posts)

  1. coreyharrison79
    Member
    Posted 6 months ago #

    Hi ,
    I'm using your plugin with events manager. It's working perfectly to process event payments, however I'm trying to get events manager to add an additional items check box that will then pass the additional cost through to eway as they register for an event.

    I'm using this code

    function my_em_add_paypal_surcharge($paypal_vars, $EM_Booking, $EM_Gateway_Paypal){
    
    	$EM_Tickets_Bookings = $EM_Booking->get_tickets_bookings();
    	$attendee_datas = EM_Attendees_Form::get_booking_attendees($EM_Booking);
    	$attendee_list = "";
    	$count = 1;
    	foreach( $EM_Tickets_Bookings->tickets_bookings as $EM_Ticket_Booking ){
    
    		$price = $EM_Ticket_Booking->get_price() / $EM_Ticket_Booking->get_spaces();
    		if( $price > 0 ){
    			$paypal_vars['item_name_'.$count] = wp_kses_data($EM_Ticket_Booking->get_ticket()->name);
    			$paypal_vars['quantity_'.$count] = $EM_Ticket_Booking->get_spaces();
    			$paypal_vars['amount_'.$count] = round($price,2);
    		}
    
    		$subitem_count = ($count + 1);
    		for( $i = 0; $i < $EM_Ticket_Booking->ticket_booking_spaces; $i++ ){
    			$fields = $EM_Booking->booking_meta['attendees'][$EM_Ticket_Booking->ticket_id][$i];
    
    			$amount = $fields['tshirt_amount'];
    
    			$paypal_vars['item_name_'.$subitem_count] = wp_kses_data( 'Tshirt' );
    			$paypal_vars['quantity_'.$subitem_count] = 1;
    			$paypal_vars['amount_'.$subitem_count] = round($amount,2);
    			$count = $subitem_count;
    			$subitem_count++;
    		}
    
    		$count++;
    	}	
    
    	return $paypal_vars;
    }
    add_filter('em_gateway_paypal_get_paypal_vars','my_em_add_paypal_surcharge',1,3);
    

    which is from a thread on the EM pro forum. I have modified it here:

    function my_em_add_eway_surcharge($eway_vars, $EM_Booking, $EwayPaymentsEventsManager){
    
    	$EM_Tickets_Bookings = $EM_Booking->get_tickets_bookings();
    	$attendee_datas = EM_Attendees_Form::get_booking_attendees($EM_Booking);
    	$attendee_list = "";
    	$count = 1;
    	foreach( $EM_Tickets_Bookings->tickets_bookings as $EM_Ticket_Booking ){
    
    		$price = $EM_Ticket_Booking->get_price() / $EM_Ticket_Booking->get_spaces();
    		if( $price > 0 ){
    			$eway_vars['item_name_'.$count] = wp_kses_data($EM_Ticket_Booking->get_ticket()->name);
    			$eway_vars['quantity_'.$count] = $EM_Ticket_Booking->get_spaces();
    			$eway_vars['amount_'.$count] = round($price,2);
    		}
    
    		$subitem_count = ($count + 1);
    		for( $i = 0; $i < $EM_Ticket_Booking->ticket_booking_spaces; $i++ ){
    			$fields = $EM_Booking->booking_meta['attendees'][$EM_Ticket_Booking->ticket_id][$i];
    
    			$amount = $fields['tshirt_amount'];
    
    			$eway_vars['item_name_'.$subitem_count] = wp_kses_data( 'Tshirt' );
    			$eway_vars['quantity_'.$subitem_count] = 1;
    			$eway_vars['amount_'.$subitem_count] = round($amount,2);
    			$count = $subitem_count;
    			$subitem_count++;
    		}
    
    		$count++;
    	}	
    
    	return $eway_vars;
    }
    add_filter('em_gateway_eway_get_eway_vars','my_em_add_eway_surcharge',1,3);

    to try and get it to pass the payment on to eway but it isn't working.

    I'm not sure if I have it right so I thought I'd see if you could see any glaring issues.
    Any help you could give me would be brilliant.

    Thanks

    http://wordpress.org/plugins/eway-payment-gateway/

  2. webaware
    Member
    Plugin Author

    Posted 6 months ago #

    G'day Corey,

    I looked at using one of the standard filters to change the price, but it keeps getting reset to the pre-filtered price just before calling the payment process, so I've added a new filter to the eWAY plugin. Please update to v3.1.2 to get the new filter.

    Here's an example of how to use it, based on a checkbox field called extra_fee.

    /**
    * add a fee to the Events Manager booking price for eWAY
    * @param float $price
    * @param EM_Booking $booking
    * @return float
    */
    function my_em_eway_added_fee($price, $EM_Booking) {
        // define your additional fee
        $extra_fee = 2.0;
    
        if (!empty($EM_Booking->booking_meta['booking']['extra_fee'])) {
            $price += $extra_fee;
        }
    
        return $price;
    }
    
    add_filter('em_eway_amount', 'my_em_eway_added_fee', 10, 2);

    cheers,
    Ross

  3. coreyharrison79
    Member
    Posted 6 months ago #

    Hi Ross,
    Thanks so much for this!
    Would I add this code to my theme functions.php or somewhere in the eway gateway plugin?

    Cheers

  4. webaware
    Member
    Plugin Author

    Posted 6 months ago #

    easiest to add it to you theme functions.php file.

  5. coreyharrison79
    Member
    Posted 6 months ago #

    Ok...
    I have tried and tried again, but cannot get this to work!
    I'm sure it's something I'm doing wrong but can't work it out.
    I'll tell you exactly what I'm doing to see if you can spot anything obvious that I've missed.

    1. I've pasted your code into my theme function.php file.
    2. Created a field in Events Manager Attendees Form with an ID of extra_fee
    (I wasn't sure if it being in the attendee form was causing it not to pass on but I tried it in the main booking form with no joy.)
    3. Registered for an event and made payment with eWay (sandbox).

    The results were that the ticket price was processed as normal, but the extra fee was not added on.

    I'm just really stuck with this so if you have any thoughts on how I could debug this that would be great.

    Thanks again

  6. webaware
    Member
    Plugin Author

    Posted 6 months ago #

    When you say the extra fee wasn't added on, do you mean:

    1. it wasn't added on at eWAY
    2. the recorded ticket total didn't include it

    I ask because the code you showed for PayPal adds the charge to PayPal but not to the ticket price, and this filter does the same. If you look at a booking in the admin, it should have just the ticket prices recorded for the booking itself, but the transaction below should show the price including extras.

    Also: didn't realise you wanted extra fees charged per attendee, here's an updated filter function for that.

    /**
    * add a fee to the Events Manager booking price for eWAY
    * @param float $price
    * @param EM_Booking $booking
    * @return float
    */
    function my_em_eway_added_fee($price, $EM_Booking) {
        // define your additional fee
        $extra_fee = 2.0;
    
        // extra fee on booking
        if (!empty($EM_Booking->booking_meta['booking']['extra_fee'])) {
            $price += $extra_fee;
        }
    
        // extra fee on attendees
        $EM_Ticket_Bookings = $EM_Booking->get_tickets_bookings();
        foreach ($EM_Ticket_Bookings->tickets_bookings as $EM_Ticket_Booking) {
            foreach ($EM_Booking->booking_meta['attendees'][$EM_Ticket_Booking->ticket_id] as $attendee) {
                if (!empty($attendee['extra_fee'])) {
                    $price += $extra_fee;
                }
            }
        }
    
        return $price;
    }
    
    add_filter('em_eway_amount', 'my_em_eway_added_fee', 10, 2);

    cheers,
    Ross

  7. coreyharrison79
    Member
    Posted 6 months ago #

    Hi Ross
    Thanks for getting back to me so quickly.
    No the extra fee wasn't recorded in eWay either in the EM admin for the transaction or in the eWay admin. I'll give this a try (hopefully it work).
    If I can't get it happening I might get quote off you to get it up and running for me if you'd be interested.

    Thanks again
    Corey

  8. webaware
    Member
    Plugin Author

    Posted 6 months ago #

    No worries, hit me via my contact page if you run into problems.

    cheers,
    Ross

  9. coreyharrison79
    Member
    Posted 6 months ago #

    It worked!! Thank you so much.
    I'm just thinking, how complicated would it be if I wanted to add multiple check boxes?
    I'm assuming that I can't just duplicate this block of code.

    I'm trying to learn a bit of PHP at the moment via codecademy.com, but I'm still yet to fully grasp how to actually do anything.

    Thanks again.

  10. webaware
    Member
    Plugin Author

    Posted 6 months ago #

    Good stuff!

    To add more checkboxes, duplicate this bit of code and change the field name (and fee, if required).

    if (!empty($attendee['extra_fee'])) {
        $price += $extra_fee;
    }

    cheers,
    Ross

  11. coreyharrison79
    Member
    Posted 6 months ago #

    Perfect!
    Thank you so much, You're a saint!

  12. coreyharrison79
    Member
    Posted 6 months ago #

    :)

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.