Support

Home Forums Event Espresso Premium Filter hooks for service fee

Filter hooks for service fee

Posted: March 2, 2016 at 12:20 pm


Railpromo

March 2, 2016 at 12:20 pm

Dear support team,

In this topic, you show a workaround for adding a service fee to PayPal standard transactions.

Would you be willing to tell me how to add the same fee to PayPal Pro and iDeal (Mollie) transactions? Unfortunately, I seem to be unable to grasp the concept of the hooks within Event Espresso completely and get stuck on this matter.

Thank you for helping me out.

Best,
Luc


Josh

  • Support Staff

March 2, 2016 at 12:41 pm

Hi Luc,

Here’s another example that can work with any gateway. You’ll plug in the payment methods into line 14 of the example:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/checkout/bc_add_cart_modifier.php


Railpromo

March 2, 2016 at 12:59 pm

Dear Josh,

Thanks, but:
– Where to put that file?
– How to plug in other payment methods? What is the identifier/name for the other payment methods? Is it “Paypal Pro”, “PayPalPro”, “PayPal-pro”?

Best,
Luc


Railpromo

March 2, 2016 at 1:02 pm

Sorry, I forgot: I prefered the other options because it lets me add a fixed fee instead of a percentage.
I didn’t manage to recode your example. πŸ™

Regarding the payment method identifiers I reckon I should use the name as specified in the name field in the payment settings panel.

Luc


Josh

  • Support Staff

March 2, 2016 at 4:09 pm

Hi Luc,

You should be able to use the add_unrelated_item() method instead of the add_percentage_based_item() method to add a fixed fee.


Railpromo

March 3, 2016 at 3:15 am

Dear Josh,

Thank you. The other questions remain:
Where to put the file and which identifiers to use for the payment methods?


Josh

  • Support Staff

March 3, 2016 at 7:37 am

You can add the code to a functions plugin or into your WordPress theme’s functions.php file. Each payment method has its own unique slug.


Railpromo

March 3, 2016 at 7:53 am

Dear Josh,

I changed these two lines when copying the code to the child theme’s functions.php:

$payment_methods_with_surcharges = array( ‘iDeal, Paypal Standard, Paypal Pro, Stripe’ );

$success = EEH_Line_Item::add_unrelated_item(

Unfortunately, no service fee is added upon paying the transaction?

Best,
Luc


Josh

  • Support Staff

March 3, 2016 at 8:37 am

Luc, you’re going to need to actually look at the method you’re trying to use and set the parameters in the way it expects. eg, You can’t pass in a percentage amount to the add_unrelated_item method. Do you have a PHP developer on your team that you can work with on this?


Railpromo

March 3, 2016 at 8:54 am

Dear Josh,

Would you be so kind to provide me with a reference to the relevant documentation about the function?
This is something I come across more often on your support desk: solutions are referred to, but documentation or clear context information is lacking. I think it would boost your already good service to even higher standards. πŸ™‚


Josh

  • Support Staff

March 3, 2016 at 9:19 am

The PHP doc block inside the Event Espresso plugin code itself has the documentation. Since you’ve asked though here’s a direct link:

https://github.com/eventespresso/event-espresso-core/blob/master/core/helpers/EEH_Line_Item.helper.php#L26

documentation or clear context information is lacking

Do you think support is lacking because we’re not providing one-off customizations for every possible customization request? Support staff is here to provide support and documentation for how to use Event Espresso. While we’ll try to work with developers to help assist with customizations, we are not qualified to provide in-depth one-off customizations, which are best handled by experienced PHP developers. If you need assistance from an experienced PHP developer I can recommend one of the developers listed here:

https://eventespresso.com/developers/event-espresso-pros/


Railpromo

March 3, 2016 at 9:22 am

Dear Josh,

I explicitly wrote your support is great, but that a clearer structure between general documentation and support provided would make it even more easier to get the best results with Event Espresso.

I’ll start with the code reference you sent now. Thanks!

Cheers!


Railpromo

March 3, 2016 at 10:06 am

Dear Josh,

I found the parameters, thank you for the link.

A remaining question is about the payment method’s slug. Is it the name you specify in the settings panel in Event Espresso?

I included this piece of code in the child theme’s functions.php, but without result – I suspect the payment method’s slug because I could not find a clear reference to that one.

function bc_add_cart_modifier( EE_SPCO_Reg_Step $payment_options_reg_step ) {
	// CHANGE THESE TO YOUR LIKING
	$name = 'Booking fee';
	$unit_price = 2.50;
	$description = 'Booking fee';
	$quantity = 1;
	$taxable = TRUE;
	$code = null;
	$payment_methods_with_surcharges = array( 'Paypal Standard, iDeal, Paypal Pro, Stripe' );
	// get what the user selected for payment method
	$selected_method_of_payment = $payment_options_reg_step->checkout->selected_method_of_payment;
	if ( ! in_array( $selected_method_of_payment, $payment_methods_with_surcharges ) ) {
		// does not require surcharge
		return;
	}
	$cart = $payment_options_reg_step->checkout->cart;
	if ( ! $cart instanceof EE_Cart ) {
		// ERROR
		return;
	}
	$total_line_item = $cart->get_grand_total();
	if ( ! $total_line_item instanceof EE_Line_Item && ! $total_line_item->is_total() ) {
		// ERROR
		return;
	}
	EE_Registry::instance()->load_helper( 'Line_Item' );
	$success = EEH_Line_Item::add_unrelated_item(
		$total_line_item,
		$name,
		$unit_price,
		$description,
		$quantity,
		$taxable,
		$code
	);
	if ( $success ) {
		$new_total   = $total_line_item->total();
		$transaction = $payment_options_reg_step->checkout->transaction;
		if ( $transaction instanceof EE_Transaction ) {
			$transaction->set_total( $new_total );
			$success = $transaction->save();
			if ( $success ) {
				/** @type EE_Registration_Processor $registration_processor */
				$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
				$registration_processor->update_registration_final_prices( $transaction );
			}
		}
	}
}
add_action( "AHEE__Single_Page_Checkout__before_payment_options__process_reg_step", 'bc_add_cart_modifier', 10, 1 );


Josh

  • Support Staff

March 3, 2016 at 10:22 am

No it’s actually your syntax in the array is incorrect. Here’s an example of a reference that shows how to write an array:

http://php.net/manual/en/language.types.array.php#example-99


Railpromo

March 3, 2016 at 10:27 am

Dear Josh,

Of course you’re right. Dumb. I copied it 1:1 from another example on the site, but apparently slept while checking it. πŸ™

Still:

	$payment_methods_with_surcharges = array( 'Paypal Standard', 'iDeal', 'Paypal Pro', 'Stripe' );

… doesn’t do the trick either. It still won’t add the fee.

Really appreciate your help!

Luc


Josh

  • Support Staff

March 3, 2016 at 10:30 am

Hi Luc,

I’m going to suggest teaming up with a PHP developer on this one. This is really outside the scope of support.

The support post ‘Filter hooks for service fee’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso