send visitor to paypal but my site performs script when they go

Discussion in 'PHP' started by SixDeep, Dec 24, 2005.

  1. #1
    Hopefully the title of this thread isnt too confusing. Heres the scenario;

    I have scripted up a way for a new webhosting client to create their own hosting account after filling in form data. For anyone who does hosting, they know how long it takes for the account to actually create. So, what I would like to do is this; They fill out the form, after submit they get sent to Paypal immediately. While they are at Paypal paying for their hosting, my account creation script kicks in and does its work. By the time they are finished with paypal, they are brought back to my site and they never had to sit through that wait. Make sense?

    I am trying this with a header redirect at the top, but it still makes me sit through the account creation process, then sends me over to paypal afterwards.

    This is my current code

    header ("location: http://www.paypal.com");
    require '/usr/local/cpanel/Cpanel/Accounting.php.inc';
        $host = "localhost";
        $user = "WHM Username";
        $accesshash =  "WHM Access Key";    
    
    $usessl = "0"; 
    //this section takes the info from the form, putting it into variables for the below section
    $acctdomain = $_POST['domain'];
    $acctuser = $_POST['username'];
    $acctpass = $_POST['password'];
    $email = $_POST['email'];
    $acctplan = "HOSTING PLAN GOES HERE";
    $do = createacct($host,$user,$accesshash,$usessl,$acctdomain,$acctuser,$acctpass,$acctplan,$email);
    $objFile = fopen("dump/contactemail_". $acctuser .".txt", "w+");
    fwrite($objFile, $email);
    fclose($objFile);
    $conn_id = ftp_connect("nn.nnn.nn.nn");
    $login_result = ftp_login($conn_id, $acctuser, $acctpass);
    $upload = ftp_put($conn_id, ".contactemail", "dump/contactemail_". $acctuser .".txt", FTP_BINARY); 
    if (!eregi("wwwacct creation finished",$do)){
    echo "There has been a problem with your account creation!<br>Please contact support for help!";
    }
    else
    {
    }
    ?> 
    PHP:
     
    SixDeep, Dec 24, 2005 IP
  2. blissallstar

    blissallstar Peon

    Messages:
    176
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Anyway you can create a cron event right after they hit submit, because I doubt that it will be possible as you want to do it.
     
    blissallstar, Dec 28, 2005 IP
  3. MaxPowers

    MaxPowers Well-Known Member

    Messages:
    264
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    120
    #3
    Use PayPal IPN to create the account and send an email when created. This method works asynchronously with the payment process flow which allows it to function at the same time as the purchase process, but doesnt interfere with the payment process.

    This also allows you to ensure that funds have cleared through to your account before actually creating the users account, reducing fraud and hassle from accidentally NSF incidents or payment delays that affect when or if the funds are actually available to you.
     
    MaxPowers, Dec 28, 2005 IP
  4. SixDeep

    SixDeep Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Good point, thanks guys.

    I grabbed the PayPal php developers kit they offer to look further into the integration process. If anyone is interested in a paypal gateway for their hosting site, let me know and I will pass a link for beta testing in the upcoming weeks.
     
    SixDeep, Dec 28, 2005 IP
  5. jimrthy

    jimrthy Guest

    Messages:
    283
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    One alternative suggestion (though I'd personally not do this myself for most sites):

    Add an
    onclick='SendToPayPal()'
    Code (markup):
    attribute to your link.

    The SendToPayPal() function does an AJAX call to your website to start the process. Your hosting service receives this call and does the preliminaries, setting up their site and such, in a "Pending" state.

    Then the SendToPayPal() redirects the page to the "Pay Me" PayPal site.

    Another service you have monitors your PayPal account. When their payment goes through, it changes the status on their account from "Pending" to "Approved."

    Alternatively, and more complicated, when you receive a payment, your site initiates the transfer to your bank account. Yeah, they have to wait 2-3 days. Isn't that better than you don't get paid? Tough argument, depending on your situation. Dealing with PP can be a PITA. Anyway, if you choose this course, you wait until the cash lands in your bank, and you have some sort of app monitoring things to verify this has happened. Once it does, you click on "Create Account," and their account magically appears.

    Even better, you have something that ties everything together, and you don't have to click the "Create Account" button. It monitors your personal account, notices that a deposit has happened, and then creates the account for you.

    Hmm. This could turn into something fairly technical. Anyone interested in this sort of thing? (No, I'm not advertising anything. I'm just curious about the response. This would represent a large investment of time I don't have just now, but I'm curious).
     
    jimrthy, Dec 28, 2005 IP