Posted: 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: 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 |
|
September 11, 2023 at 12:59 pm Hi Zoe, A good hook to use would probably be:
which gives you access to:
you can check the status of the payment using Then to do the following:
you can get the list of registrations from the transaction object:
then get the events from the registrations:
Hope that helps! |
|
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 |
|
As soon as you open up EEM_Payment.model.php you’ll see the payment statuses available, like THIS.
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:
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:
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. |
|
Thanks both, we’ve written this function but it’s causing console errors on the checkout! I’m sure we’re doing something daft wrong… The payment->status if statement is commented out at the moment but we will be needing it, so confirmation on whether that is correct would be appreciated too 🙂
Zoe |
|
Can you post the errors you are getting in the console? Also, if you check your server’s PHP error logs when testing the above code, does that show any errors there? The fact that you’ve commented out:
Leads me to believe the code now works without that check? If so and you getting errors when that code is in use, my guess right now is that Output the contents of |
|
Hi Tony, thanks for helping – we’ve commented in the if statement and tested again, but it still errors. It errors once we enter stripe (test) payment details and press “Pay Now” – the cog appears and it just remains on screen indefinitley. This is the console error:
The only thing appearing in the debug log is The server error logs are also clear. Thanks, Zoe |
|
But it works as expected if you completely remove the above function? For example if you comment this out:
So that the code doesn’t run there’s no more console error? |
|
Hi Tony, that’s correct! We’ve made it as an mu-plugin for now and if we delete the file and follow the same steps to register it works fine with no console errors and takes us to the thank you page… |
|
It’s working for me but I’ve commented out all of the code with the category check as I don’t have the same setup. Add this function to that file:
Then use You should get some more details on what that object is. Or just |
|
Actually… that’s why! Where are you getting
|
|
Beautiful! Thanks Tony, it’s now working 😀 Thanks for your help today, I really needed to get this boxed off and we’ve managed it 🙂 |
|
Just an additional note as I had a fatal on my test site running the above code. This: Will fatal if the registration is on a free ticket, as there is no payment so
Get rid of this Change the conditional to check for a EE_Payment object:
Confirm the |
|
Good spot, thanks Tony, we’ll change this and test it 🙂 |
|
The support post ‘Grabbing event and user information after payment has been received’ 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.