WordPress.org

Ready to get started?Download WordPress

Forums

Custom WooCommerce payment gateway redirection issue (8 posts)

  1. SirCharo
    Member
    Posted 9 months ago #

    Hello,
    I'm developing a custom payment gateway for WooCommerce to process payments through NetCommerce (a local visa and credit card gateway).
    1- Collecting customer information is Working fine
    2- Sending the information to the gateway website is Working fine
    3- Transactions are being made successfully on the gateway website and they successfully send us a message back with the transaction status if accepted or rejected.
    The problem i'm facing is that whenever i receive the message from them i'm having errors changing the order status to "Processing" if the transaction was successful, and an error displaying the message received in the signature whenever the transaction is failing to go through.
    The redirection is right i assume since I always get back to checkout whenever i'm done from the payment gateway website with a message saying "Thank you for Shopping".
    I'm not sure whats wrong with the final step of the file, i checked many other gateways and i think i did the same.
    Does anyone have idea about this issue?
    The php file can be found here: http://goldeneagleadv.com/NetCommerce_Gateway.php (Right click + Save target as)
    Thank you.

  2. bcworkz
    Member
    Posted 9 months ago #

    I'm not sure I can help, but I cannot even see you code. Servers typically will never send the contents of PHP files, This is a good thing and appears to be happening here. Try copying it into a .txt file or just use pastebin.com. Post the new link here and I'll see if I can offer any advice.

  3. SirCharo
    Member
    Posted 9 months ago #

    Hello bcworkz,

    thank you for following up i pasted the code on pastebin.com here is the link http://pastebin.com/GW4MuigY

  4. bcworkz
    Member
    Posted 9 months ago #

    I don't know what a lot of the methods used do, so if any of them initiate a redirect, I would not know it. Still, it appears there is no redirect upon successful payment. AFAICT, the successful payment portion of the code starts at line 1128 of the pastebin code and runs until line 1136. Most of the remaining code relates to various failure conditions.

    Within that block I would expect to see a redirect code such as there is at line 1188. The problem is though at line 1130 there is an echo statement which will cause any subsequent PHP redirects to fail. PHP redirects must be called before any output is sent because the redirect is caused by sending a "Location:" header. No headers can be sent after output to the browser. If you want a redirect after output is sent, you must use javascript, it cannot be done with PHP.

  5. SirCharo
    Member
    Posted 9 months ago #

    Well i couldn't figure it out how to do it inside the same file, but i changed the redirection to My Account page and i'm trying to add the get_response code inside that page so it displays a message once they respond, however i tried to do so which supposed to be easier but still not working... here is the my account code http://pastebin.com/4rAkm9A9
    It should ring a bell if you take a look at it i think. thank you.

  6. bcworkz
    Member
    Posted 9 months ago #

    I've never tried passing data through a redirect, so I'm speculating here. I believe that after a redirect, the values in $_POST are gone. $_POST values should only be valid for the page specified as the action attribute of the form.

    I'm not sure you can pass POST data through a redirect, you should be able to pass data through $_GET though. You would need to append URL parameters to the redirect URL. A truncated example, just add in the rest of the data:
    wp_redirect( $get_checkout_url.'?txtMerchNum='.$_POST['txtMerchNum'].'&txtIndex='.$_POST['txtIndex']);

  7. SirCharo
    Member
    Posted 9 months ago #

    Im sorry i didn't quite get you, im not advanced with php could you edit it the way you think its good?

  8. bcworkz
    Member
    Posted 9 months ago #

    I'll try. When the form is submitted via POST to the page that interfaces with the payment gateway, as you know, the form data is all available in $_POST. After the payment is processed and you redirect to My Account, it is seen as a new GET page request. Whatever data that was in $_POST dies with the interface page.

    Thus you need to take measures on the interface page to pass data you need on My Account from $_POST while still on the interface page. That is where the suggested (my previous post) redirect line comes in. That line is just an example though, it is incomplete, you need to add parameters for all data needed on My Account.

    When data is passed as suggested, it can be accessed with $_GET in the same way that $_POST was used. For example, the 'txtIndex' value is contained in $_GET['txtIndex'].

    I hope this makes more sense. If there is any part you do not still understand, explain how you are confused and I will try to explain further.

Reply

You must log in to post.

About this Topic