Support

Home Forums Event Espresso Premium REST API Payment amount credit/deduct points

REST API Payment amount credit/deduct points

Posted: May 2, 2022 at 2:47 am


He Zhengrui

May 2, 2022 at 2:47 am

Hi there team,

I hope you guys are doing well!

As there is no addons currently available for this, I am trying to create a way for me to credit user accounts with gamification points based on the final amount paid with a certain scale ($1 = 100 points).

The gamification system (myCred) has an API layer to credit the points and deduct points but I am unsure of which function/action/filter/endpoint that I can use for this scenario.

My apologies for the lack of understanding of the REST API on my end;

I hope you guys can point me in the right direction. Thank you!


Tony

  • Support Staff

May 3, 2022 at 4:39 am

Hi there,

If you are running the function on the site that EE runs on, you don’t need to use the EE REST API for this and can hook in to send a request to myCred from there.

With regards to payments made within Event Espresso, how are you expecting this to work?

Do you only want to credit myCred when the total amount is paid in full, meaning the EE Transaction status switches to ‘complete’ and the registration status switches to ‘Approved’?


He Zhengrui

May 5, 2022 at 6:54 am

Hi Tony!

Great to hear from you, thank you for your reply.

I want to credit myCred when the registration status switches to ‘approved’ and deduct points when it switches to ‘cancelled’

Thank you!


Tony

  • Support Staff

May 5, 2022 at 8:54 am

Ok, so you have a couple of options and the way I would start is to look into this hook:

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

That is ‘fired’ whenever a registration’s status is changed to approved.

After that you can look into:

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

Which is fired whenever a registration’s status is change FROM approved to something else, the $new_STS_ID variable will give you the new status so you can add your condition from there.

Does that help?


He Zhengrui

May 19, 2022 at 6:29 am

Hi Tony,

That was a really great start for me, I’ve been experimenting but to no avail and I will have to trouble you again.

Using your example of status to approved,

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

-May I know where do I add my code for the API
-How can I retrieve the transaction amount of the specific registration to send to my REST API endpoint?

Thanks!


Tony

  • Support Staff

May 19, 2022 at 9:21 am

-May I know where do I add my code for the API

I assume you are aware of how to use WordPress hooks?

https://www.smashingmagazine.com/2011/10/definitive-guide-wordpress-hooks/

Add your function to the above action.

-How can I retrieve the transaction amount of the specific registration to send to my REST API endpoint?

Ok, my recommendation is to take a read of our model system documentation:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

It allows you to relatively easily pull in all of the information you might need once you get used to it.

Combine that with Kint: https://wordpress.org/plugins/kint-debugger/

Wrap your objects in d(); and get a nice output of the object in question which then allows you to dig in an see what it has available to you.

The support post ‘REST API Payment amount credit/deduct points’ 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