0

Im creating a pseudo payment system where the user completes a form then the form redirects him to an external url to complete the checkout process.

When the user submits the order details i want them to be passed along to the external url so i can display them sort of like a receipt.

Question

What's the best way of doing it?

Ethaan
  • 11,291
  • 5
  • 35
  • 45

1 Answers1

1

Instead of loading the page in iframe i would recommend you to do an ajax call to the external url (as you have control over it).

Here is the ajax for your operation

$.ajax({
        type:'POST',
        url:'http://alexanderkap.esy.es/yourprojectfolder/file.php',
        crossDomain: true,
        data:'yourdata=anyofyourdata',
        success: function(data){
            console.log(data);
        },
        error:function(data){
            console.log(data);
        }
    });

Note :

  1. You shall use any click event to call this ajax
  2. To send your entire form data you shall use form serialize
  3. I have just put the success and failure case in the console which you shall do that in a div
Sulthan Allaudeen
  • 11,330
  • 12
  • 48
  • 63
  • thanks a lot i will try that i am confident it will work – Alexander Kapriniotis Apr 05 '15 at 15:30
  • awesome i managed to do this perfectly with your help. I wanted to ask something aditional though, when the payments checks and completes succesfully is there a way to redirect in my project's page get a variable that payment was completed succesfully and then run a query(update the user's info) – Alexander Kapriniotis Apr 05 '15 at 16:45
  • That's great, and yes it is possible by jquery and php. In php you shall do `header("Location: https://sitename.com/login.php");` and in jquery you shall do `$(location).attr('href','http://yourPage.com/');` Together the url you shall pass the variable like ?id=1 like that and get the page to make it done. – Sulthan Allaudeen Apr 05 '15 at 16:50
  • And in the new page loading i will just check for get id if isset and if it is =success right? Thanks a lot by the way much appreciated – Alexander Kapriniotis Apr 05 '15 at 16:57
  • Yes, it is based on what you have done in the previous page. If you pass id in success case and if you dont pass id in fail case you need to check `isset` in the newly loading page. – Sulthan Allaudeen Apr 05 '15 at 16:59
  • awesome i thought it would be more complicated than this, thanks a lot :) – Alexander Kapriniotis Apr 05 '15 at 17:03
  • Thanks, everything is in what we think. Glad to help :) – Sulthan Allaudeen Apr 05 '15 at 17:04
  • Sorry to bother you again but if a user manually writes the id on the header then the query runs without him having to submit the form, so i thought of making an empty page acting as the middleman that received the id runs the query and then redirects to the site with just the sucess message :) – Alexander Kapriniotis Apr 05 '15 at 17:32
  • That's ok. :) Yes, you don't even have to do a middleman page, you can handle it in a function itself. And are you ok with that or you having any issue in it ?? – Sulthan Allaudeen Apr 05 '15 at 17:38
  • yeah i did it with the way i told you how you could you do it in a function while preventing from users manually tampering with it since it is a url variable i am curious – Alexander Kapriniotis Apr 05 '15 at 17:51
  • You can do this in two ways one is by setting a `session` or `cookie` variable in the external page and in the new page you should check whether the session or cookie is set or not , If it is set then it is a success case and if not then it is a failure case. And the second way is to have a have table named as `transaction` or something and you will insert a random number in it for each transaction and whenever you taking the user to new page you should check whether the random number provided by the url and db are same if matches then success else failure – Sulthan Allaudeen Apr 05 '15 at 18:02
  • nice, i didnt knew you could pass session variables amongst external pages, i liked your second solution i will try it thanks a lot – Alexander Kapriniotis Apr 05 '15 at 18:07
  • You are welcome , And yes we can share session among external domains http://stackoverflow.com/a/14611577/3282633 and i have suggested you cookies also, but the second way is more secure :) – Sulthan Allaudeen Apr 05 '15 at 18:09