Posted: May 2, 2018 at 7:20 am
I am using the AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful hook in order to do some custom coding with regards to events.
What I ultimately need to do is to get the event id that the transaction/registration was done for; as I want to update the access list for the specific event page when a registration is done and paid for (there is already a page associated with the event, which is already coded and working fine).
I can see in the source code for EE_Payment_Processor.core.php that it passes the payment and transaction objects to the hook.
What I have so far:
I have also tried using the passed parameters directly, which didn’t work:
Please let me know if the data is structured differently, and if I should adapt my code in order to get the ID (or if there is an easier way to get the id).
You’re passing the payment_object to wp_mail, not the event_id.
Would be an email containing the event id.
If for some reason $payment wasn’t an instance of EE_Payment, your going to get fatal errors as your function then runs methods on null below…
So rather than setting the var as null, return instead:
Thanks, but I only added that so that I can debug as I can’t use logs or the console to generate output. There is a lot of code after this section, but if it isn’t finding the data from the event, then the other code can’t work, so no point in including it really (it is custom code that doesn’t really have anything to do with the event espresso code, don’t expect you guys to help out with that 🙂 ) I just need the event id in order to proceed.
I opened a ticket earlier, in which someone told me that the format of the object data has changed from an example that I was working from (custom shortcode in the messages).
The example below is a snippet from a different function and a different hook, but perhaps the same happened here, that the format has changed and I thus cannot access the data.
Sure you can, you can use a little function like this: http://www.stumiller.me/sending-output-to-the-wordpress-debug-log/
Add this snippet to your
The write_log function then writes whatever you pass it to
That’s was me and it only applied to the messages system and my example code, to provide more context, the
I’m using your code in WP console and replicating it by pulling in an EE Transaction, then pulling a payment from that transaction so I have the same objects you should have – http://take.ms/ljJNB
That works and emails me the object and event_id – http://take.ms/ZXTzV
I then hooked into
So the code you are using above seems to be working fine?
Which payment method are you using to complete the payment?
When you say it doesn’t work, what is happening? What emails do you receive?
Ah okay, you learn something new every day, thanks 🙂
I’ve now inspected the $payment and $transaction objects that is passed to the hook (AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful), and I can see all the data that I need there. But it is protected, So I’ve tried using get_first_event public method located in the EE_Payment class in order to get the data:
But this still isn’t working, even though it is a public method.
The thing is I want this to happen every time there is a successful payment applied to the transaction, either VIA bank transfer (applied from the backend) or from a payment gateway. So I wouldn’t necessarily know the ID of the transaction.
What isn’t working? Are you getting a blank email or nothing at all?
Are you applying a payment from within the admin now or using an online payment method?
I’m not sure why you would need to know the transaction ID, but if you have the transaction object you have the transaction ID.
Not getting anything at all in the first point, it isn’t sending a mail.
I am currently using a payment gateway, not from the admin itself (but the hook still gets called, as tested from my previous code).
I saw in your code that you called the transaction via its ID in line 6.
Thank you very much for your input and patience with this (as well as the previous ticket), I’m just struggling to understand why I can’t use the public method as designated by the class if I have the object.
I’m pulling a Transaction by ID so that I have a Transaction in the console, I’m replicating the object you have available on that hook, this was my previous reply:
You don’t need to know the ID, you already have the transaction object passed to the hook.
Which payment gateway?
Add the write_log function I gave you above to either, enable WP_Debug using the snippet I gave you and then add:
before the email is sent, retest and check the debug.log file to see if you have the objects written to the log.
There are too many unknowns in your code right now, you don’t know if
In short, break down your code and check each variable as you run through to find what is actually being run and what they contain before you use them, right now you don’t know if the email is sent or not and just that it doesn’t work, you need to narrow that down to the specific area that fails because the above is working for me.
Okay, got it.
The get_first_event method failed.
After I saw the debug messages I realised that I am not on the latest version of Event Espresso, and that this method didn’t exist in my code ( I was looking at the EE_Payment class on GitHub).
Thank you very much for your assistance, especially with teaching me how to debug properly! Never working with mails again, thank goodness.
You can close the ticket now.
Great! I’m glad it’s working for you 🙂
I’d recommend always using the latest version of EE, we update with new features and bug fixes etc little and often.
The support post ‘Getting payment and transaction objects from hook after payment is applied’ 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.