Support

Home Forums Event Espresso Premium Surcharge for payment gateway

Surcharge for payment gateway

Posted: May 7, 2017 at 12:08 pm

Viewing 3 reply threads


TKT

May 7, 2017 at 12:08 pm

Hi,

We have a situation where we require the buyers of certain events to pay for choosing the payment method(gateway). I found the following set of code very useful to start with

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

Can this code be further modified to select only certain events that the surcharge applies? I’m thinking maybe you could hard-code event_id’s somewhere that can do the job but I’m not so sure.


Josh

  • Support Staff

May 8, 2017 at 9:55 am

The code can be modified to include some checks for event ID’s. Before you do that though, you’ll need to get the event information from the transaction object. You’ll note that on line 31 of the example code it has the transaction object set as $transaction:

$transaction = $payment_options_reg_step->checkout->transaction;

You can get the event object by adding the following:

if ( $transaction instanceof EE_Transaction ) {
  foreach ( $transaction->registrations() as $registration ) {
    if ( $registration instanceof EE_Registration ) {
     $event = $registration->event();
     // you have the $event object now, so you can compare your array of event ID's to $event-ID();
    }
  }
}


TKT

May 8, 2017 at 7:56 pm

I have a question about adding a new payment method and how the code generates a payment method slug.

We’re adding a couple new payment methods and wondering how to find out what the payment slug for each is so that we could refer to in this code

$payment_methods_with_surcharges = array( ‘invoice’ );

Here, ‘invoice’ obviously is the slug for method Invoice
Lets say we are adding a method called ‘123’, what would be the slug for it to use in this particular code?


Josh

  • Support Staff

May 9, 2017 at 8:05 am

You can look in the database with a tool like phpMyAdmin to get this information. You go to the _esp_payment_method table and look at the
PMD_slug column in your custom payment method’s row.

Viewing 3 reply threads

The support post ‘Surcharge for payment gateway’ 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