I need help please?

Hi, there I have a question and need your help, I can make payment through custom api connect to my app but when button pay with chapa is clicked it will automatically add the course into currentuserclassespurchased add parent group course but what I need is to add this course to for a user who paid for it, but it automatically added even if i complete the transaction it also added how to fix this,?
please help me