Answered Question on Xenforo Payment process handling

Dnyan

New Coder
Jun 4, 2019
12
2
4
Hello to all,

I would like to know more about or need a php file for doing redirection and sending the response for following case.

I saw all payment handling script in xenforo, the pre-configured xenforo payment profiles had almost following in common.

URL for returning after purchase
URL for Returning when purchase is cancel
AND the IPN or server to server call back during callback state.

In my case where i am trying to make an addon for payment profile, My payment server only sends signle response on a single url which i need to handle either it pass or fail or something else.

I wish to make that response a s a return page, this will be just a blank page with loader and message stating like please do not refresh, we are processing your payments........

Mean while i want a php to process the captured response by posting it to payment_callback.php and redirect user to either purchase complete or cancel or dynamic redirect as per error.

I wish to know, how i can make it work on xenforo

Process Chart:
1. User Click on Make payment and get redirected to payment provider page for doing payment (Happens as xF default system)

2. User does payment or cancel, Payment provider sends responce to single call back url with POST method ( I want a PHP file to handle that response)

3. IN PHP file
POST response recieved from the Payment provider will be sent to payment_callback.php for processing and logging the data
Base on Status in post data 'case' i would like to redirect user to purchase complete, cancel or dynamic redirect.

Meanwhile those process by PHP on redirect from payment provider, i would like to show a blank page with loader and message to wait.
any help on this would be much appreciated.

As i am not a coder, i might have express something wrongly in this.
 

Ghost

Active Coder
Moderator
Apr 19, 2019
135
61
28
XenForo has gateways for PayPal, Stripe, etc, so it shouldn't be too hard to build off of what is already there.

I have supplied some information down below to hopefully help you understand what's really going on, but basically you should be using your database to see if things are paid or not & just checking that information when pages are loaded. Ideally you should be building off of the gateways that XF provides instead of trying to change the way they work.
-----

What payment processor are you using?
I have created this exact type of flow with PayPal & Stripe, but it's pretty much the same for all of the various services.
You basically need to set up a PHP file/code that can add a new "pending payment" to the database.
For example, a user can press the button to buy a "shirt". Your database would then have a record that User 23 is purchasing "shirt" and the status_id would = 0, for not purchased.
Then the callback PHP file would update that record to status_id = 1 (for paid) when the service tells you they have paid.

You can check if the payment is made & redirect based on that.
It's incredibly hard for me to tell you exactly how to do it because you didn't say what service you are using, and its obviously even trickier to do it inside of XenForo. However, I know that this can be done relatively easily with PayPal IPN or similar services.

So for PayPal you could have something like this...
yoursite.com/checkout.php (shows the product they buy, amount, etc)
-> they click a product or something
-> generate a new payment & redirect to PayPal checkout page
-> you should have some sort of invoice or payment ID to identify the user's purchase

yoursite.com/callback.php (PayPal tells this page when user has paid)
-> this page will update the pending payment to = PAID in your database

yoursite.com/returnurl.php
-> this page checks to see if the product was paid for, if it was paid then it should say so & also trigger whatever it is you need done (ex: User is buying a VIP Role, or a Forum Shirt)

That's the general idea of what you need to do, but there's hundreds of pages of documentation for all the payment services, so I really can't fully explain it here - there's just too much to type.
 

Dnyan

New Coder
Jun 4, 2019
12
2
4
Thank You for replying, actually i am trying to make an integration Paytm India Payment gateway.

Like Paypal, it is not redirect to different url for success or failure of transaction as it wont take it as parameter to process transaction.

there is a only one url which i can pass to receive a response from paytm server, user will be redirected to that URL after transaction (processed or cancelled or any status)

I manage to take response on my own custom call back file where i am redirecting it base on response to either purchase-process or to upgrade page using router.

initially i was thinking of making file to handle response and sending it to call back via POST method and redirect user to either of 2 possibilities, finally i made a custom call cack php
 

Ghost

Active Coder
Moderator
Apr 19, 2019
135
61
28
Thank You for replying, actually i am trying to make an integration Paytm India Payment gateway.
Like Paypal, it is not redirect to different url for success or failure of transaction as it wont take it as parameter to process transaction.
there is a only one url which i can pass to receive a response from paytm server, user will be redirected to that URL after transaction (processed or cancelled or any status)
I manage to take response on my own custom call back file where i am redirecting it base on response to either purchase-process or to upgrade page using router.
initially i was thinking of making file to handle response and sending it to call back via POST method and redirect user to either of 2 possibilities, finally i made a custom call cack php
Yeah, I would just store the result (paid / unpaid / cancelled) and then when the user is redirected, just look up the status of the transaction.
You can have a separate page for paid/unpaid/etc & just redirect them to that page once you receive the callback.
Your actual callback page that they initially go to can have some sort of 'Loading...' screen on it while your script looks up the status! :)