Support

Home Forums Event Espresso Premium Grabbing event and user information after payment has been received

Grabbing event and user information after payment has been received

Posted: September 7, 2023 at 9:09 am


Zoe

September 7, 2023 at 9:09 am

Hi all, I need to create a function that does the following, could I get some guidance on what hook I need and the quickest way to grab the info please?

This needs to fire when a payment has been made (and stripe has confirmed the payment has been received).

Then I need to be able to:
– Loop through all events on the order
– If one of those events appears in a specific event category then get:
– The Event ID
– The delegates/users name
– The delegates/users email address

For this specific type/category of event we are limiting it to one per order, so there would only ever be 1 delegate against the event.

Thank youuuuu!

Zoe


Brent Christensen

  • Support Staff

September 11, 2023 at 12:59 pm

Hi Zoe,

A good hook to use would probably be:

AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed

which gives you access to:

  1. the EE_Checkout object which has access to pretty much every bit of data collected during the registration process, including:
    1. $cart the ‘EE_CART’ object
    2. $transaction the ‘EE_Transaction’ object
    3. $primary_attendee_obj the ‘EE_Attendee’ object for the primary registrant
    4. $payment the ‘EE_Payment’ object
  2. plus an array of details from the transaction, which you likely don’t need

you can check the status of the payment using $payment->status() which you can compare against one of the payment status codes on EEM_Payment.

Then to do the following:

– Loop through all events on the order

you can get the list of registrations from the transaction object:


$registrations = $transaction->registrations();

then get the events from the registrations:


foreach ( $registrations as $registration ) {
    $event = $registration->event();
}

– If one of those events appears in a specific event category then get:

if ( $event->category() === 'my category' ) { ... }

– The Event ID

$event->ID()

– The delegates/users name

$registration->attendee()->full_name()

– The delegates/users email address

$registration->attendee()->email()

Hope that helps!


Zoe

September 12, 2023 at 9:30 am

Thanks Brent this is really helpful! Where can I get a list of payment codes for EEM_Payment? We’ll be using stripe so I’ll just be looking for whatever confirms stripe successfully took payment.

Cheers 🙂

Zoe


Tony

  • Support Staff

September 12, 2023 at 2:42 pm

Where can I get a list of payment codes for EEM_Payment?

As soon as you open up EEM_Payment.model.php you’ll see the payment statuses available, like THIS.

We’ll be using stripe so I’ll just be looking for whatever confirms stripe successfully took payment.

You don’t actually need the Stripe specific payment status as the EE_Payment object will have been updated at that point, you’d be looking to confirm the transaction status is complete and if checking individual EE_Payment objects you ca use something like:

if ($payment->status() === EEM_Payment::status_id_approved) {
    //This payment has a status of Approved.
}

Also, depending on the specifics of what this is for you could also just hook into when a registration is Approved, within EE_Registration.class.php there is a set_status() method, that is used to set the registration status which happens automatically when a payment is made in full (although also can happen at other times).

So this action:

do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context);

Fires when a registration status is set to Approved, $this, will be an EE_Registration object. $old_STS_ID is what thee status was before this recent update, $new_STS_ID is what its just been set to (In this case it will be Approved) and $context gives you more details on what is updating the status.

It really depends on the specifics of what you are using these for, Brents hook also works fine so this is just another option.

You must be logged in to reply to this support post. Sign In or Register for an Account

Event Espresso