XF 2.0 VBulletin to Xenforo Subscription Gateway - Help Please

MickkD

Member
Hi All,

I have made a working standalone script that is entering the details of a vBulletin paypal IPN transaction directly into the Xenforo Database.

It works by intercepting the the IPN in another script (this has to be standalone to redirect to the old vbulletin payment_gateway.php or the Xenforo payment_callback.php page).

I would like to integrate it into a plugin but I cannot work out how to do the SQL UPDATES & INSERTS using the MVC Module.
Also how do I use the Xenforo Database instead of a file I made called db_connection.php ($conn).

If I am asking to much maybe some hints on what classes need to be looked at :) i'm quite resourceful lol!

Part of my Procedural Code is like this:

PHP:
// Above this is all the other _POST items (cleaned using mysqli). and the calls to the existing xf_user table to get the username based on the custom POST that vbulletin uses to store the username of the member that subbed.

        $txn_complete = "subscr_payment";
        $txn_expire = "subscr_eot";
        $txn_reversed = "Reversed";
   
        // Variable to pass for the INSERT/UPDATE the Blob into the database
        $blob_a = 'a:4:{s:11:"cost_amount";s:4:"6.99";s:13:"cost_currency";s:3:"GBP";s:13:"length_amount";i:6;s:11:"length_unit";s:5:"month";}';
        $blob_b = 'a:4:{s:11:"cost_amount";s:5:"12.99";s:13:"cost_currency";s:3:"GBP";s:13:"length_amount";i:1;s:11:"length_unit";s:4:"year";}';
  

    // this if is a kind of security to make sure that the receivers email matches our business email address otherwise dont do anything (identical ===)
    if ($receiver_email === $our_email){
     
        //check if the txn types match a Complete (purchase)
        if ($txn_type === $txn_complete){
         
            // check if the amount is equal to the subs amount && (both equal true) the transaction is a Completed transaction (very important) otherwise you could grant access to an end of term.
            if ($payment_amount === "6.99" && $payment_status === "Completed"){
         
                //  This is checking that the user_id of the member matches that of the user_id in the database. Not sure if this is the best way to do this but it will work.
                //  This is the MYSQL UPDATE SEction  it updates the `xf_user_upgrade_active` table if the user_id is already in there.
                //  The user_id column is a unique table,  this means you need to update and not insert or you will get mysql errors - and nothing happening.
                //  What I found was that the subscritption does not normally end / update until after midnight on the actual date that paypal sends the IPN
                //  This means that you will do an update of the table and not an insert
                if ($subID['user_id'] === $userID['user_id']){
             
                    mysqli_query($conn,"UPDATE `xf_user_upgrade_active` SET `purchase_request_key` = '".$purchaseKey_a."'  WHERE `user_id` = '".$subID['user_id']."'");
                    mysqli_query($conn,"UPDATE `xf_user_upgrade_active` SET `start_date` = '".strtotime('now')."'  WHERE `user_id` = '".$subID['user_id']."'");
                    mysqli_query($conn,"UPDATE `xf_user_upgrade_active` SET `end_date` = '".strtotime('6 month')."'  WHERE `user_id` = '".$subID['user_id']."'");
                    mysqli_query($conn,"UPDATE `xf_user_upgrade_active` SET `extra` = '".$blob_a."'  WHERE `user_id` = '".$subID['user_id']."'");
                    $dbcode = "DB xf_user_upgrade_active £6.99 UPDATED";
                    $db_updated = "DB updated (£6.99), trasaction status = " .$txn_complete. "  Details:";
         
                // just incase that the subscrition is not in the `xf_user_upgrade_active` table - we will insert it.
                } else {

//The rest does INSERTS if no upgrade exists,  and also all the other subsriptions based on the IFS.

I am really happy now, We do not get any PAYPAL warning emails anymore and them switching off our IPN - and it automatically is updating our database and the xenforo admin areas. (see pic)

working vbulletin subs.webp

Thank you.
 
Last edited:
Back
Top Bottom