The MU forums have moved to WordPress.org

Paypal API Subscriptions (16 posts)

  1. AndyCharrington
    Member
    Posted 13 years ago #

    Hello all and happy christmas!

    I have been scouring the forums both here and on premium.wpmudev.org for quite a while now looking for a plugin that allowed me to charge users to get a blog and continued to charge them with paypal subscriptions. (Yes i know all the arguments against charging people for a service they can get elsewhere for free so there's no need to voice them here.. ;-) )

    Anyway, the closest i could get was the premium "pay to blog" plugin but this had one major downfall. The plugin would only charge the user once they had logged in and would not disable the blog if the user had not paid. This was not really good enough for me as i wanted users to have to subscribe to the site with paypal subscriptions.

    Another posibility was the premium "upgrades" plugin. But alas this did not fullfill my needs either.

    I was at my wits end when i came accross the following plugin -

    http://wordpress.org/extend/plugins/paypal-api-subscriptions/

    It was entered into the WordPress Plugin Competition Blog on weblogtoolscollection.com and appears on first glance to not only do everything i need it to do but also to be wpmu compatible!!

    Woo!

    However.....

    Upon installing it in my mu i found that the wordpress compatability statement was a bit far fetched.

    Updating the options page is impossible as i get the old "are you sure you want to do this?" error.

    Also i can produce subscribe buttons and clicking on them takes me through to my wp-signup.php page, which is good, but at no point am i taken to paypal.....

    So i looked through the code....

    The only built in mu compatibility reference i could find was

    // MU Compatibility
    if (function_exists('get_current_site'))
        define('PPSA_URLPATH', get_option('siteurl').'/wp-content/mu-plugins/' . PPSAFOLDER.'/');
    else
        define('PPSA_URLPATH', get_option('siteurl').'/wp-content/plugins/' . PPSAFOLDER.'/');

    Now i am not really up on converting wp plugins to wpmu but i am sure that more is needed than just defining the path..... Intrestingly it does not work in the mu-plgins folder and yet you have to put the images in there anyway....

    What i am wondering is... is there anyone out there who fancies coding this to work in wpmu????

    I would do it myself but i have no idea where to start!

    If we can get this to work in wpmu it would be (as far as i know) the first one of its kind to work in wpmu.... Wouldn't that be great!

    Here is the download link-

    http://downloads.wordpress.org/plugin/paypal-api-subscriptions.1.0.zip

  2. AndyCharrington
    Member
    Posted 13 years ago #

    ++++UPDATE++++

    Wow sitting at a computer can really make me stupid.

    Thus plugin does indeed work in the mu-plugins folder. You just have to put the files in the root of mu-plugins and not in their own folder.

    So there's that one solved.

    HOWEVER....

    Now the credit/debit card form is showing up at the top of every page on my mu install followed by the following error-

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/****/public_html/wp-content/mu-plugins/form.php:4) in /home/****/public_html/wp-content/mu-plugins/subscriptions.php on line 17

    I have checked for whitespace: None.

    I have heard that the session_start(); needs to be on line 1 of the file: Doesn't help.

    what i dont understand is why the form is showing on every page.....

    I will post each of the pages here so you can see what i'm going on about.

  3. AndyCharrington
    Member
    Posted 13 years ago #

    subscriptions.php-

    <?php
    /*
    Plugin Name: Paypal API Subscriptions
    Plugin URI: http://zackdesign.biz
    Description: This plugin creates the ability for users to register on Wordpress and subscribe using the Paypal API at the same time
    Author: Isaac Rowntree
    Version: 1.0
    Author URI: http://zackdesign.biz
    
    	Copyright (c) 2005, 2006 Isaac Rowntree (http://zackdesign.biz)
    	QuickShop is released under the GNU General Public
    	License (GPL) http://www.gnu.org/licenses/gpl.txt
    
    	This is a WordPress plugin (http://wordpress.org).
    
    */
    session_start();
    
    // define URL
    define('PPSAFOLDER', dirname(plugin_basename(__FILE__)));
    // MU Compatibility
    if (function_exists('get_current_site'))
        define('PPSA_URLPATH', get_option('siteurl').'/wp-content/mu-plugins/' . PPSAFOLDER.'/');
    else
        define('PPSA_URLPATH', get_option('siteurl').'/wp-content/plugins/' . PPSAFOLDER.'/');
    
    // Show the Form
    function paypal_api_subscription_form()
    {
        // Output the hidden fields and the form
        if ($_SESSION['subscribe'] == 1)
        {
            // All very self-explanatory: this form has all the HTML needed
            require_once('form.php');
    
        }
    }
    
    // Error checking and Transactions
    //
    // @errors = the WP_Error object
    //
    function paypal_api_subscription_post_and_error($errors)
    {
        // Form field validation
        if ($_SESSION['subscribe'] == 1)
        {
            if ( empty( $_POST['first_name'] ) )
        	    	$errors->add('first_name',"<strong>ERROR: </strong> Please enter your first name.");
    
            if ( empty( $_POST['last_name'] ) )
        	    	$errors->add('l_name',"<strong>ERROR: </strong> Please enter your last name.");
    
            if ( empty( $_POST['credit_card_type'] ) || ($_POST['credit_card_type'] == ' ') )
         	    	$errors->add('cctype',"<strong>ERROR: </strong> You need to provide your credit card type.");
    
            if ( empty( $_POST['cc_number']) && empty($_POST['cc_number1']) )
         	    	$errors->add('ccnum',"<strong>ERROR: </strong> You need to provide your credit card number.");
    
            if ( empty( $_POST['cvv2_number'] ))
         	    	$errors->add('cvv2',"<strong>ERROR: </strong> You need to provide your credit card verification code.");
    
            if ( empty( $_POST['address1'] ))
         	    	$errors->add('cvv2',"<strong>ERROR: </strong> You need to provide a street address.");
    
            if ( empty( $_POST['city'] ))
         	    	$errors->add('cvv2',"<strong>ERROR: </strong> You need to provide your city.");
    
            if ( empty( $_POST['state'] ))
         	    	$errors->add('cvv2',"<strong>ERROR: </strong> You need to provide your state.");
    
            if ( empty( $_POST['zip'] ))
         	    	$errors->add('cvv2',"<strong>ERROR: </strong> You need to provide your zip/postal code.");
    
            if ( empty( $_POST['country_code'] ))
         	    	$errors->add('cvv2',"<strong>ERROR: </strong> You need to provide your country.");
    
            // Only run the transaction if there are no form field errors
            $count = 0;
            foreach ($errors as $error)
            {
                foreach ($error as $e)
                    $count++;
            }
    
            if ( !$count && ($_SESSION['subscribe'] == 1) )
            {
                // Paypal API class - it just works! :D
                require_once 'paypal_api.php';
    
                $p=new paypal();
    
                // Generate current date for profile start date.
                $start_time = strtotime(date('m/d/Y'));
                $start_date = date('Y-m-d\T00:00:00\Z',$start_time);
    
                // Create ALL the values to be sent via CURL
                $p->addvalue('METHOD', 'CreateRecurringPaymentsProfile');
                $p->addvalue('CREDITCARDTYPE', $_POST['credit_card_type']);
                if (empty($_POST['cc_number']) && !empty($_POST['cc_number1']))
                    $p->addvalue('ACCT', $_POST['cc_number1']);
                else
                    $p->addvalue('ACCT', $_POST['cc_number']);
                $p->addvalue('EXPDATE',str_pad( $_POST['expdate_month'], 2, '0', STR_PAD_LEFT).$_POST['expdate_year']);
                $p->addvalue('CVV2', $_POST['cvv2_number']);
                $p->addvalue('FIRSTNAME', $_POST['first_name']);
                $p->addvalue('LASTNAME', $_POST['last_name']);
                $p->addvalue('PROFILESTARTDATE', $start_date);
                $p->addvalue('BILLINGFREQUENCY', $_SESSION['frequency']);
                $p->addvalue('BILLINGPERIOD', $_SESSION['period']);
                $p->addvalue('SUBSCRIBERNAME', $_POST['user_login']);
                $p->addvalue('AMT', $_SESSION['price']);
                $p->addvalue('DESC', $_SESSION['name']);
                $p->addvalue('CURRENCYCODE', $p->currency);
                $p->addvalue('STREET', $_POST['address1']);
                if (!empty($_POST['address2']))
                    $p->addvalue('STREET2', $_POST['address2']);
                $p->addvalue('CITY', $_POST['city']);
                $p->addvalue('STATE', $_POST['state']);
                $p->addvalue('ZIP', $_POST['zip']);
                $p->addvalue('COUNTRYCODE', $_POST['country_code']);
    
                // Run it!
                // Use 'true' to display the string sent to Paypal if you're unsure what's going on.
                // $data = $p->call_paypal(true);
                $data = $p->call_paypal();
    
    		        // If successful we can go to step 2!
                if (strcasecmp($data['ACK'],'SUCCESS') == 0)
                    $_SESSION['subscribe'] = 2;
                else // Bounce back to the register form with error info. Probably a result of poorly-entered credit card info...
                    $errors->add('failed',"<strong>ERROR: </strong> The transaction failed. ".$data['L_LONGMESSAGE0'].' '.$p->show_error());
            }
        }
        else if ( $_POST['subscribe'] == 3 )
        {
            // We're using the error checking of Wordpress to help with the first step
            SetExpressCheckout($errors);
        }
        return $errors;
    }
    
    // Step 1 messages
    //
    // @msg = the string containing all the messages
    //
    function paypal_api_subscription_message_step1($msg)
    {
        // Do some house-keeping.
        // I've set it so that the session is over-written if a new subscription button is pressed on the site
    
        if ($_GET['subscribe'] == 'canceled')
            session_destroy();
    
        if (!empty($_GET['subscribe']) || !isset($_SESSION['subscribe']))
        {
            $_SESSION['subscribe'] = $_GET['subscribe'];
            if (!empty($_GET['frequency']))
                $_SESSION['frequency'] = $_GET['frequency'];
            if (!empty($_GET['period']))
                $_SESSION['period'] = $_GET['period'];
            if (!empty($_GET['name']))
                $_SESSION['name'] = $_GET['name'];
            if (!empty($_GET['price']))
                $_SESSION['price'] = $_GET['price'];
        }
        if ($_SESSION['subscribe'] == 1)
        {
            // Add an 's' to the end of day, month, year, semi-month...
            if ($_SESSION['frequency'] > 1)
                $plural = 's';
            else
                $plural = '';
    
            // Currency by default is USD.
            $currency = get_option('ppsa_cc');
            if (empty($currency))
                $currency = 'USD';
    
            $sub = $_SESSION['frequency'] . ' ' . $_SESSION['period'].$plural . ' of ' . $_SESSION['name'] . ' for $' . $_SESSION['price'] . ' ' . $currency;
    
            // Completely clear any previous messages with this one. You're not missing anything!
            $msg = '<div class="message register">
                    <h2>'.get_bloginfo('name').' Subscription</h2><br />
    
            <p>You are subscribing to the following:</p><br />
            <p style="text-decoration: underline; font-weight: bold;">'.$sub.'</p><br />
            <p>Please note that this is a recurring billing cycle. You are also registering on '.get_bloginfo('name').'.</p><br />
            <p><strong><a href="?action=register&subscribe=canceled">Cancel this subscription process.</a></strong></p>
            </div>';
        }
        else if ($_SESSION['subscribe'] == 5) // second-last step in Express Checkout
        {
            // Completely clear any previous messages with this one. You're not missing anything!
             $msg = '<p class="message">You have successfully paid your subscription and will be billed on a recurring basis. Please continue by registering.</p>';
        }
    
        return $msg;
    }
    
    // Step 2 messages
    //
    // @msg = the string containing all the messages
    //
    function paypal_api_subscription_message_step2($msg)
    {
        if ($_SESSION['subscribe'] == 2)
        {
            // Append a new message to the 'successful registration' one. We're now ready to direct the user
            $step2 = get_option('ppsa_step2');
            if (!empty($step2))
                $msg .= '<p class="message">'.$step2.'</p>';
            else
                $msg .= '<p class="message">You have successfully paid your subscription and will be billed on a recurring basis.</p>';   
    
            // Time to say bye-bye to the session
            session_destroy();
        }
        else if ($_SESSION['subscribe'] == 5) // Express checkout version!
        {
            // Append a new message to the 'successful registration' one. We're now ready to direct the user
            $step4 = get_option('ppsa_step4');
            if (!empty($step4))
                $msg .= '<p class="message">'.$step4.'</p>';
    
            // Time to say bye-bye to the session
            session_destroy();
        }
    
        return $msg;
    }
    
    // Add options page
    function paypal_api_subscriptions_options_page()
    {
         add_options_page('Paypal API Subscriptions', 'Paypal API Subscriptions', 8, __FILE__, 'paypal_api_subscriptions_options');
    }
    
    // Options page form
    function paypal_api_subscriptions_options()
    {
        $sb = get_option('ppsa_sandbox');
        $user = get_option('ppsa_username');
    
        if (!empty($sb) || empty($user))
            $sb = 'checked="checked"';
    
        echo '
        <div class="wrap"><h2>Subscription Options</h2>
    
        <form method="post" action="options.php">
    
        '.wp_nonce_field('update-options').'
    
        <h3>Paypal API</h3>
        <p><a href="http://www.paypal.com/">Login to PayPal</a> (to set up API or manage users)</p>
        <p><a href="https://developer.paypal.com/">Paypal Developer Central</a></p>
        <p><strong>HIGHLY IMPORTANT:</strong> You require SSL when using your API credentials and
        when you take your user\'s credit card details. Please use the following plugin for Wordpress SSL:
        <a href="http://www.kerrins.co.uk/blog/admin-ssl/">Admin SSL</a></p>
        <p>Please do not use your API credentials until SSL is working.</p>
        <table class="form-table">
    
            <tr valign="top">
                <th scope="row">Sandbox Mode?</th>
                <td><input type="checkbox" name="ppsa_sandbox" '.$sb.' /></td>
            </tr>
            <tr valign="top">
                <th scope="row">Username</th>
                <td><input type="text" name="ppsa_username" style="width: 40%" value="'.$user.'"  /></td>
            </tr>
            <tr valign="top">
                <th scope="row">Password</th>
                <td><input type="text" name="ppsa_password" value="'.get_option('ppsa_password').'"  /></td>
            </tr>
            <tr valign="top">
                <th scope="row">Signature</th>
                <td><input type="text" name="ppsa_signature" style="width: 60%" value="'.get_option('ppsa_signature').'"  /></td>
            </tr>
            <tr valign="top">
                <th scope="row">Currency Code</th>
                <td><input type="text" name="ppsa_cc" value="'.get_option('ppsa_cc').'"  />  - defaults to USD</td>
            </tr>
    
        </table>
    
        <h3>Thank you Message (Direct Payment)</h3>
        <p>May include HTML. Needs to include verification that the transaction process has completed. Can also send your users elsewhere via HTML link. One is already provided by default but you can put your own down here.</p>
    
        <textarea name="ppsa_step2" id="ppsa_step2" style="width: 30%;" rows="10" cols="50">'.get_option('ppsa_step2').'</textarea>
    
        <h3>Thank you Message (Express Checkout)</h3>
        <p>May include HTML. Needs to include verification that the transaction process has completed. Can also send your users elsewhere via HTML link. One is already provided by default but you can put your own down here.</p>
    
        <textarea name="ppsa_step4" id="ppsa_step4" style="width: 30%;" rows="10" cols="50">'.get_option('ppsa_step4').'</textarea>
    
        <p class="submit">
    <input type="submit" name="Submit" value="Update Options &raquo;" />
    <input type="hidden" name="action" value="update" />
    <input type="hidden" name="page_options" value="ppsa_username,ppsa_password,ppsa_signature,ppsa_step2,ppsa_step4,ppsa_cc,ppsa_sandbox" />
    </p>
        </div>
        ';
    }
    
    // This function is called to display the subscribe button on the page
    //
    // @content = the content to replace
    //
    function paypal_api_subscriptions_button($content)
    {
            $pattern = '/\[ppsa\].+\[\/ppsa\]/';
            preg_match_all ($pattern, $content, $matches);
    
            foreach ($matches[0] as $match)
            {
                // Get rid of the surrounding shortcodes
                $pattern = '/\[ppsa\]/';
                $m = preg_replace ($pattern, '', $match);
                $content = preg_replace ($pattern, '', $content);
    
                $pattern = '/\[\/ppsa\]/';
                $m = preg_replace ($pattern, '', $m);
                $content = preg_replace ($pattern, '', $content);
    
                // Only show subscription button if user is logged out. No point otherwise
                if (!is_user_logged_in())
                {
                    // If the pieces aren't in the right order this won't work
                    // Error checking is done by the transaction so will probably
                    // leave this until a later version unless it's a huge problem...
                    $pieces = explode('|',$m);
    
                    $options = '<input type="hidden" name="frequency" value="'.$pieces[2].'">
                                <input type="hidden" name="period" value="'.$pieces[3].'">
                                <input type="hidden" name="name" value="'.$pieces[0].'">
                                <input type="hidden" name="price" value="'.$pieces[1].'">';
    
                    $replacement = '<div class="ppsa_subscription_form"><form class="subscription_form_1" action="'.get_bloginfo('wpurl').'/wp-login.php" method="get">
                                    <input type="image" src="'.PPSA_URLPATH.'images/subscribe.gif" border="0" name="submit" alt="'.get_bloginfo('name').'">
                                    '.$options.'<input type="hidden" name="subscribe" value="1"><input type="hidden" name="action" value="register"></form>
                                    <span class="ppsa_or">OR</span>
                                    <form class="subscription_form_2" style="margin: 0; border: 0; padding: 0; background: none;" action="'.get_bloginfo('wpurl').'/wp-login.php" method="post">
                                    <input alt="Make payments with PayPal - it\'s fast, free and secure!" name="submit" src="'. PPSA_URLPATH.'images/xpress.gif" type="image" />
                                    <input type="hidden" name="subscribe" value="3"><input type="hidden" name="action" value="register">'.$options.'</form></div>';
                }
                else
                    $replacement = '';
    
                // Replace using the original match as the template.
                $m = preg_replace ('/\|/', '\|', $m);
                $content = preg_replace('/'.$m.'/', $replacement, $content);
            }
            return $content;
    }
    
    // While processing the API call tell the user to wait and clear the register button
    function paypal_api_subscriptions_processing()
    {
        // At the moment this is the best I can do as wp_enqueue_script doesn't seem to want to work here
        ?>
    
        <script type='text/javascript' src='<?php echo PPSA_URLPATH; ?>js/jquery-1.2.6.min.js'></script>
    
        <script type="text/javascript">
    		$(document).ready(function(){
    
            <?php
    
                // Further Javascript to remove all doubt of where they're registering
                if (!empty($_SESSION['subscribe']))
                {
            ?>
    
            $(".submit input").click(function () {
                $(this).attr({disabled : "disabled"});
                $(this).val("Please wait... processing transaction.");
                $(this).css("color","red");
            });
    
            $("#registerform p label:first").prepend('Your New <?php bloginfo("name"); ?> ');
    
            <?php
    
                }
    
            ?>
    
        });
    	  </script>
    
        <?php
    }
    
    // ExpressCheckout function step 1
    //
    // @errors = the errors we will clear and substitute with our own if this transaction fails
    //
    function SetExpressCheckout($errors)
    {
        $_SESSION['name'] = $_POST['name'];
        $_SESSION['price'] = $_POST['price'];
        $_SESSION['period'] = $_POST['period'];
        $_SESSION['frequency'] = $_POST['frequency'];
    
        // Paypal API class - it just works! :D
        require_once 'paypal_api.php';
    
        $p=new paypal();
    
        // Create ALL the values to be sent via CURL
        $p->addvalue('METHOD', 'SetExpressCheckout');
        $p->addvalue('L_BILLINGTYPE0', 'RecurringPayments');
        $p->addvalue('L_BILLINGAGREEMENTDESCRIPTION0', $_SESSION['name']);
        $p->addvalue('AMT', $_SESSION['price']);
        $p->addvalue('RETURNURL',get_bloginfo('url'));
        $p->addvalue('CANCELURL',get_bloginfo('url'));
    
        // Run it!
        // Use 'true' to display the string sent to Paypal if you're unsure what's going on.
        // $data = $p->call_paypal(true);
        $data = $p->call_paypal();
    
    		// If successful we can go to step 2!
        if (strcasecmp($data['ACK'],'SUCCESS') == 0)
        {
            $_SESSION['subscribe'] = 4;
    
            if ($p->sandbox)
                $url = $p->express_sandbox_url;
            else
                $url = $p->express_url;
    
            $redirect_to = $url.'?cmd=_express-checkout&token='.$data['TOKEN'];
    	      wp_redirect($redirect_to);
    
    	      exit();
        }
        else // Bounce back to the register form with error info. Probably a result of poorly-entered credit card info...
        {
            unset($errors->errors);
    
            $errors->add('failed',"<strong>ERROR: </strong> The transaction failed. ".$data['L_LONGMESSAGE0'].' '.$p->show_error().
            '<br /><br /><strong><a href="'.get_bloginfo('url').'" >&laquo; Back to '. get_bloginfo('title', 'display' ).'</a></strong>');
    
        }
        return $errors;
    }
    
    // Load the subscription stuff before Wordpress pulls up the headers.
    function ppsa_init()
    {
        if ($_SESSION['subscribe'] == 4)
            CreateRecurringPaymentsProfile(); // ExpressCheckout function step 2
    }
    
    // ExpressCheckout function step 2
    function CreateRecurringPaymentsProfile()
    {
        $token = $_GET['token'];
        $ID = $_GET['PayerID'];
    
        // Paypal API class - it just works! :D
        require_once 'paypal_api.php';
    
        $p=new paypal();
    
        // Generate current date for profile start date.
        $start_time = strtotime(date('m/d/Y'));
        $start_date = date('Y-m-d\T00:00:00\Z',$start_time);
    
        // Create ALL the values to be sent via CURL
        $p->addvalue('METHOD', 'CreateRecurringPaymentsProfile');
        $p->addvalue('PROFILESTARTDATE', $start_date);
        $p->addvalue('BILLINGFREQUENCY', $_SESSION['frequency']);
        $p->addvalue('BILLINGPERIOD', $_SESSION['period']);
        $p->addvalue('AMT', $_SESSION['price']);
        $p->addvalue('DESC',$_SESSION['name']);
        $p->addvalue('CURRENCYCODE', $p->currency);
        $p->addvalue('TOKEN', $token);
        $p->addvalue('PayerID', $ID);
    
        // Run it!
        // Use 'true' to display the string sent to Paypal if you're unsure what's going on.
        // $data = $p->call_paypal(true);
        $data = $p->call_paypal();
    
    		// If successful we can go to step 3!
        if (strcasecmp($data['ACK'],'SUCCESS') == 0)
        {
            $_SESSION['subscribe'] = 5;
            $redirect_to = get_bloginfo('wpurl').'/wp-login.php?action=register';
    	      wp_redirect($redirect_to);
    
    	      exit();
        }
        else // Bounce back to the register form with error info. Probably a result of timed-out-edness
        {
            echo "<strong>ERROR: </strong> The transaction failed. ".$data['L_LONGMESSAGE0'].' '.$p->show_error().
            '<br /><br /><strong><a href="'.get_bloginfo('url').'" >&laquo; Back to '. get_bloginfo('title', 'display' ).'</a></strong>';
            session_destroy();
            die();
        }
    }
    
    // Displays the form inside the register form
    add_action('register_form', 'paypal_api_subscription_form');
    
    // Runs (very minimal as of right now) error checking and transaction posting via CURL
    add_filter('registration_errors','paypal_api_subscription_post_and_error');
    
    // Shows information about what the user is registering for in the first message
    add_filter('login_message','paypal_api_subscription_message_step1');
    
    // Shows the user a success message and invites them to proceed further if necessary
    add_filter('login_messages','paypal_api_subscription_message_step2');
    
    // An options page for the API information and other details
    add_action('admin_menu','paypal_api_subscriptions_options_page');
    
    // Convert shortcode into subscription buttons
    add_filter('the_content', 'paypal_api_subscriptions_button');
    
    // Ensure that the 'Register' button can't be clicked twice during API call
    add_action('login_head', 'paypal_api_subscriptions_processing');
    
    // Make sure the second step for Express Checkout works!
    add_action('init', 'ppsa_init');
    
    ?>
  4. AndyCharrington
    Member
    Posted 13 years ago #

    form.php-

    <div id="credit"><h2>Credit or Debit Card Information</h2><br />
    <p>
    		<label>First Name<br />
    <input tabindex="25" type="text" id="first_name" maxlength="32" style="width: 200px;" class="input" name="first_name" value="<?php echo $_POST['first_name']; ?>"><br /><span class="small">(as it appears on card)</span>
    </p>
    <p>
    		<label>Last Name<br />
    <input tabindex="30" type="text" id="last_name" maxlength="32" style="width: 200px;" name="last_name" value="<?php echo $_POST['last_name']; ?>"><br /><span class="small">(as it appears on card)</span>
    </p>
    <p>
    		<label>Card Type<br />
    <select tabindex="35" id="credit_card_type" name="credit_card_type" ><option value=" ">Select Card</option>
    <?php
    $options = array(
    array('value'=>'MasterCard','name'=>'MasterCard'),
    array('value'=>'Visa','name'=>'Visa'),
    array('value'=>'Discover','name'=>'Discover'),
    array('value'=>'Amex','name'=>'American Express'));
    
    foreach ($options as $c)
    {
        $selected = '';
        if ($_POST['credit_card_type'] == $c['value'])
            $selected = 'selected="selected"';
    
        echo '<option value="'.$c['value'].'" '.$selected.'>'.$c['name'].'</option>';
    }
    ?>
    </select>
    </p>
    <p>
    		<label>Card Number<br />
    
    <?php 
    
        if (empty($_POST['cc_number']) && !empty($_POST['cc_number1']))
            $_POST['cc_number'] = $_POST['cc_number1'];
    
        if (!empty($_POST['cc_number']))
        {
            $num = str_split($_POST['cc_number']);
    
            for ($i = 0; $i < sizeof($num); $i++)
            {
                if ($i < (sizeof($num) - 4))
                    $num[$i] = x;
                 echo $num[$i];
            }
        }
    
    ?>
    <input tabindex="40" type="text" id="cc_number" maxlength="19" style="width: 200px;" name="cc_number" value="">
    <input type="hidden" id="cc_number1" name="cc_number1" value="<?php echo $_POST['cc_number']; ?>">
    </p>
    <p>
    		<label>Expiration Date: </label>
    <select tabindex="45" id="expdate_month" name="expdate_month">
    <?php
    
    for ($i = 1; $i < 13; $i++)
    {
        $selected = '';
        if ($_POST['expdate_month'] == $i)
            $selected = 'selected="selected"';
    
        if ($i < 10)
            $m = str_pad($i,2,'0',STR_PAD_LEFT);
        else
            $m = $i;
    
        echo '<option '.$selected.'>'.$m.'</option>';
    }
    
    ?></select> &nbsp;<select tabindex="50" id="expdate_year" name="expdate_year">
    
    <?php
    
    $options = years(20,array());
    
    foreach ($options as $o)
    {
        $selected = '';
        if ($_POST['expdate_year'] == $o)
            $selected = 'selected="selected"';
    
        echo '<option '.$selected.'>'.$o.'</option>';
    }
    
    // Recursively make a list of years to a certain value...
    //
    // @count - the amount of times to return
    // @values - requires an array
    //
    function years($count,$values)
    {
        if ($count > 0)
            $count--;
    
        $date = date('Y');
    
        $values[] = $date+$count;
        if ($count)
            $values = years($count,$values);
        else
            sort($values);
    
        return $values;
    }
    
    ?>
    </select>
    </p>
    <p>
    		<label>Card Security Code<br />
    <input tabindex="55" type="text" id="cvv2_number" size="3" maxlength="4" name="cvv2_number" value="<?php echo $_POST['cvv2_number']; ?>">
    <a target="_blank" href="https://www.paypal.com/us/cgi-bin/webscr?cmd=p/acc/cvv_info_pop-outside" ><span class="small">What's this?</span></a>
    </p>
    </div><div id="billing">
    <h2>Billing Details</h2>
    
    <p>
    <label>Address Line 1<br />
    <input tabindex="60" type="text" id="address1" size="25" maxlength="100" class="smallInputWidth" name="address1" value="<?php echo $_POST['address1']; ?>">
    </label>
    </p>
    <p>
    <label>Address Line 2<br />
    <input tabindex="65" type="text" id="address2" size="25" maxlength="100" class="smallInputWidth" name="address2" value="<?php echo $_POST['address2']; ?>">
    </label>
    </p>
    <p>
    <label>City<br />
    <input tabindex="70" type="text" id="city" size="25" maxlength="40" class="smallInputWidth" name="city" value="<?php echo $_POST['city']; ?>">
    </label>
    </p>
    <p>
    <label>State<br />
    <input tabindex="75" type="text" id="state" size="25" maxlength="40" class="smallInputWidth" name="state" value="<?php echo $_POST['state']; ?>">
    </label>
    </p>
    
    <p>
    <label>Country<br />
    <select tabindex="80" id="country_code" name="country_code" class="" >
    <option value="">-- Choose a Country --</option>
    <?php 
    
    $options = array(
    array('value'=>'US','name'=>'United States'),
    array('value'=>'AL','name'=>'Albania'),
    array('value'=>'DZ','name'=>'Algeria'),
    array('value'=>'AD','name'=>'Andorra'),
    array('value'=>'AO','name'=>'Angola'),
    array('value'=>'AI','name'=>'Anguilla'),
    array('value'=>'AG','name'=>'Antigua and Barbuda'),
    array('value'=>'AR','name'=>'Argentina'),
    array('value'=>'AM','name'=>'Armenia'),
    array('value'=>'AW','name'=>'Aruba'),
    array('value'=>'AU','name'=>'Australia'),
    array('value'=>'AT','name'=>'Austria'),
    array('value'=>'AZ','name'=>'Azerbaijan Republic'),
    array('value'=>'BS','name'=>'Bahamas'),
    array('value'=>'BH','name'=>'Bahrain'),
    array('value'=>'BB','name'=>'Barbados'),
    array('value'=>'BE','name'=>'Belgium'),
    array('value'=>'BZ','name'=>'Belize'),
    array('value'=>'BJ','name'=>'Benin'),
    array('value'=>'BM','name'=>'Bermuda'),
    array('value'=>'BT','name'=>'Bhutan'),
    array('value'=>'BO','name'=>'Bolivia'),
    array('value'=>'BA','name'=>'Bosnia and Herzegovina'),
    array('value'=>'BW','name'=>'Botswana'),
    array('value'=>'BR','name'=>'Brazil'),
    array('value'=>'VG','name'=>'British Virgin Islands'),
    array('value'=>'BN','name'=>'Brunei'),
    array('value'=>'BG','name'=>'Bulgaria'),
    array('value'=>'BF','name'=>'Burkina Faso'),
    array('value'=>'BI','name'=>'Burundi'),
    array('value'=>'KH','name'=>'Cambodia'),
    array('value'=>'CA','name'=>'Canada'),
    array('value'=>'CV','name'=>'Cape Verde'),
    array('value'=>'KY','name'=>'Cayman Islands'),
    array('value'=>'TD','name'=>'Chad'),
    array('value'=>'CL','name'=>'Chile'),
    array('value'=>'C2','name'=>'China'),
    array('value'=>'CO','name'=>'Colombia'),
    array('value'=>'KM','name'=>'Comoros'),
    array('value'=>'CK','name'=>'Cook Islands'),
    array('value'=>'CR','name'=>'Costa Rica'),
    array('value'=>'HR','name'=>'Croatia'),
    array('value'=>'CY','name'=>'Cyprus'),
    array('value'=>'CZ','name'=>'Czech Republic'),
    array('value'=>'CD','name'=>'Democratic Republic of the Congo'),
    array('value'=>'DK','name'=>'Denmark'),
    array('value'=>'DJ','name'=>'Djibouti'),
    array('value'=>'DM','name'=>'Dominica'),
    array('value'=>'DO','name'=>'Dominican Republic'),
    array('value'=>'EC','name'=>'Ecuador'),
    array('value'=>'SV','name'=>'El Salvador'),
    array('value'=>'ER','name'=>'Eritrea'),
    array('value'=>'EE','name'=>'Estonia'),
    array('value'=>'ET','name'=>'Ethiopia'),
    array('value'=>'FK','name'=>'Falkland Islands'),
    array('value'=>'FO','name'=>'Faroe Islands'),
    array('value'=>'FM','name'=>'Federated States of Micronesia'),
    array('value'=>'FJ','name'=>'Fiji'),
    array('value'=>'FI','name'=>'Finland'),
    array('value'=>'FR','name'=>'France'),
    array('value'=>'GF','name'=>'French Guiana'),
    array('value'=>'PF','name'=>'French Polynesia'),
    array('value'=>'GA','name'=>'Gabon Republic'),
    array('value'=>'GM','name'=>'Gambia'),
    array('value'=>'DE','name'=>'Germany'),
    array('value'=>'GI','name'=>'Gibraltar'),
    array('value'=>'GR','name'=>'Greece'),
    array('value'=>'GL','name'=>'Greenland'),
    array('value'=>'GD','name'=>'Grenada'),
    array('value'=>'GP','name'=>'Guadeloupe'),
    array('value'=>'GT','name'=>'Guatemala'),
    array('value'=>'GN','name'=>'Guinea'),
    array('value'=>'GW','name'=>'Guinea Bissau'),
    array('value'=>'GY','name'=>'Guyana'),
    array('value'=>'HN','name'=>'Honduras'),
    array('value'=>'HK','name'=>'Hong Kong'),
    array('value'=>'HU','name'=>'Hungary'),
    array('value'=>'IS','name'=>'Iceland'),
    array('value'=>'IN','name'=>'India'),
    array('value'=>'ID','name'=>'Indonesia'),
    array('value'=>'IE','name'=>'Ireland'),
    array('value'=>'IL','name'=>'Israel'),
    array('value'=>'IT','name'=>'Italy'),
    array('value'=>'JM','name'=>'Jamaica'),
    array('value'=>'JP','name'=>'Japan'),
    array('value'=>'JO','name'=>'Jordan'),
    array('value'=>'KZ','name'=>'Kazakhstan'),
    array('value'=>'KE','name'=>'Kenya'),
    array('value'=>'KI','name'=>'Kiribati'),
    array('value'=>'KW','name'=>'Kuwait'),
    array('value'=>'KG','name'=>'Kyrgyzstan'),
    array('value'=>'LA','name'=>'Laos'),
    array('value'=>'LV','name'=>'Latvia'),
    array('value'=>'LS','name'=>'Lesotho'),
    array('value'=>'LI','name'=>'Liechtenstein'),
    array('value'=>'LT','name'=>'Lithuania'),
    array('value'=>'LU','name'=>'Luxembourg'),
    array('value'=>'MG','name'=>'Madagascar'),
    array('value'=>'MW','name'=>'Malawi'),
    array('value'=>'MY','name'=>'Malaysia'),
    array('value'=>'MV','name'=>'Maldives'),
    array('value'=>'ML','name'=>'Mali'),
    array('value'=>'MT','name'=>'Malta'),
    array('value'=>'MH','name'=>'Marshall Islands'),
    array('value'=>'MQ','name'=>'Martinique'),
    array('value'=>'MR','name'=>'Mauritania'),
    array('value'=>'MU','name'=>'Mauritius'),
    array('value'=>'YT','name'=>'Mayotte'),
    array('value'=>'MX','name'=>'Mexico'),
    array('value'=>'MN','name'=>'Mongolia'),
    array('value'=>'MS','name'=>'Montserrat'),
    array('value'=>'MA','name'=>'Morocco'),
    array('value'=>'MZ','name'=>'Mozambique'),
    array('value'=>'NA','name'=>'Namibia'),
    array('value'=>'NR','name'=>'Nauru'),
    array('value'=>'NP','name'=>'Nepal'),
    array('value'=>'NL','name'=>'Netherlands'),
    array('value'=>'AN','name'=>'Netherlands Antilles'),
    array('value'=>'NC','name'=>'New Caledonia'),
    array('value'=>'NZ','name'=>'New Zealand'),
    array('value'=>'NI','name'=>'Nicaragua'),
    array('value'=>'NE','name'=>'Niger'),
    array('value'=>'NU','name'=>'Niue'),
    array('value'=>'NF','name'=>'Norfolk Island'),
    array('value'=>'NO','name'=>'Norway'),
    array('value'=>'OM','name'=>'Oman'),
    array('value'=>'PW','name'=>'Palau'),
    array('value'=>'PA','name'=>'Panama'),
    array('value'=>'PG','name'=>'Papua New Guinea'),
    array('value'=>'PE','name'=>'Peru'),
    array('value'=>'PH','name'=>'Philippines'),
    array('value'=>'PN','name'=>'Pitcairn Islands'),
    array('value'=>'PL','name'=>'Poland'),
    array('value'=>'PT','name'=>'Portugal'),
    array('value'=>'QA','name'=>'Qatar'),
    array('value'=>'CG','name'=>'Republic of the Congo'),
    array('value'=>'RE','name'=>'Reunion'),
    array('value'=>'RO','name'=>'Romania'),
    array('value'=>'RU','name'=>'Russia'),
    array('value'=>'RW','name'=>'Rwanda'),
    array('value'=>'VC','name'=>'Saint Vincent and the Grenadines'),
    array('value'=>'WS','name'=>'Samoa'),
    array('value'=>'SM','name'=>'San Marino'),
    array('value'=>'ST','name'=>'Sao Tome and Principe'),
    array('value'=>'SA','name'=>'Saudi Arabia'),
    array('value'=>'SN','name'=>'Senegal'),
    array('value'=>'SC','name'=>'Seychelles'),
    array('value'=>'SL','name'=>'Sierra Leone'),
    array('value'=>'SG','name'=>'Singapore'),
    array('value'=>'SK','name'=>'Slovakia'),
    array('value'=>'SI','name'=>'Slovenia'),
    array('value'=>'SB','name'=>'Solomon Islands'),
    array('value'=>'SO','name'=>'Somalia'),
    array('value'=>'ZA','name'=>'South Africa'),
    array('value'=>'KR','name'=>'South Korea'),
    array('value'=>'ES','name'=>'Spain'),
    array('value'=>'LK','name'=>'Sri Lanka'),
    array('value'=>'SH','name'=>'St. Helena'),
    array('value'=>'KN','name'=>'St. Kitts and Nevis'),
    array('value'=>'LC','name'=>'St. Lucia'),
    array('value'=>'PM','name'=>'St. Pierre and Miquelon'),
    array('value'=>'SR','name'=>'Suriname'),
    array('value'=>'SJ','name'=>'Svalbard and Jan Mayen Islands'),
    array('value'=>'SZ','name'=>'Swaziland'),
    array('value'=>'SE','name'=>'Sweden'),
    array('value'=>'CH','name'=>'Switzerland'),
    array('value'=>'TW','name'=>'Taiwan'),
    array('value'=>'TJ','name'=>'Tajikistan'),
    array('value'=>'TZ','name'=>'Tanzania'),
    array('value'=>'TH','name'=>'Thailand'),
    array('value'=>'TG','name'=>'Togo'),
    array('value'=>'TO','name'=>'Tonga'),
    array('value'=>'TT','name'=>'Trinidad and Tobago'),
    array('value'=>'TN','name'=>'Tunisia'),
    array('value'=>'TR','name'=>'Turkey'),
    array('value'=>'TM','name'=>'Turkmenistan'),
    array('value'=>'TC','name'=>'Turks and Caicos Islands'),
    array('value'=>'TV','name'=>'Tuvalu'),
    array('value'=>'UG','name'=>'Uganda'),
    array('value'=>'UA','name'=>'Ukraine'),
    array('value'=>'AE','name'=>'United Arab Emirates'),
    array('value'=>'GB','name'=>'United Kingdom'),
    array('value'=>'UY','name'=>'Uruguay'),
    array('value'=>'VU','name'=>'Vanuatu'),
    array('value'=>'VA','name'=>'Vatican City State'),
    array('value'=>'VE','name'=>'Venezuela'),
    array('value'=>'VN','name'=>'Vietnam'),
    array('value'=>'WF','name'=>'Wallis and Futuna Islands'),
    array('value'=>'YE','name'=>'Yemen'),
    array('value'=>'ZM','name'=>'Zambia'));
    
    foreach ($options as $c)
    {
        $selected = '';
        if ($_POST['country_code'] == $c['value'])
            $selected = 'selected="selected"';
    
        echo '<option value="'.$c['value'].'" '.$selected.'>'.$c['name'].'</option>';
    }
    
    ?>
    </select>
    </label>
    </p>
    
    <p>
    <label>ZIP/Postal Code<br />
    <input tabindex="85"  type="text" id="zip" size="10" maxlength="10" name="zip" value="<?php echo $_POST['zip']; ?>">
    </label>
    </p></div>
  5. AndyCharrington
    Member
    Posted 13 years ago #

    paypal_api.php-

    <?php 
    
    /* 
    
       This class is lifted directly from the Paypal Developer forum.
       http://www.paypaldeveloper.com/pdn/board/message?board.id=nvp&thread.id=1952
       Thanks to the incredible user 'Boanerges' who released this class
       I have been able to modify it slightly to suit myself!
    
    */
    
    class paypal
    {
        var $postdata=array();
        var $response=array();
        var $username;
        var $password;
        var $signature=NULL;
        var $certfile=NULL;
        var $proxy=NULL;
        var $currency;
        var $sandbox;
        var $error;
        var $version="52.0";
        var $sandbox_url="https://api-3t.sandbox.paypal.com/nvp";
        var $live_url="https://api-aa-3t.paypal.com/nvp";
        var $express_sandbox_url="https://www.sandbox.paypal.com/webscr";
        var $express_url="https://www.paypal.com/cgi-bin/webscr";
    
        //initialize
    	  function __construct($proxy=NULL)
     	  {
    	      // SandBox info set here automatically for testing purposes
            $this->username = get_option('ppsa_username');
            $this->password = get_option('ppsa_password');
            $this->signature = get_option('ppsa_signature');
            $this->sandbox = get_option('ppsa_sandbox');
    
            if (empty($this->username))
            {
                $this->username = 'sdk-three_api1.sdk.com';
                $this->password = 'QFZCWN5HZM8VBG7Q';
                $this->signature = 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU';
                $this->sandbox = true;
            }
    
            // Currency by default is USD.
            $currency = get_option('ppsa_cc');
            if (empty($currency))
                $this->currency = 'USD';
    
    	      if(is_file($cert))
                $this->certfile=$cert;
    
    	      if($proxy) $this->proxy=$proxy;
    	}
    	//add values to the array
    	function addvalue($key, $val, $limit=NULL)
    	{
    	    $v=$val;
    	    if(is_numeric($limit)) $v=substr($v,0,$limit);
    	    $this->postdata[$key]=urlencode($v);
    	}
    	//clear the array for a new call
    	function resetdata()
    	{
    	    $this->postdata=array();
    	}
    
    	function call_paypal($showurl=false)
    	{
    	    $this->postdata['USER']=urlencode($this->username);
    	    $this->postdata['PWD']=urlencode($this->password);
    	    if($this->signature) $this->postdata['SIGNATURE']=urlencode($this->signature);
    	    if(!isset($this->postdata['VERSION'])) $this->postdata['VERSION']=$this->version;
    
    	    $url=($this->sandbox) ? $this->sandbox_url : $this->live_url;
    	    $nvp=NULL;
    	    foreach($this->postdata as $k => $v):
    	        $nvp.="$k=$v&";
    	    endforeach;
    	    if(!$nvp) return false;
    	    //strip out the last character, which is a &
    	    $nvp=substr($nvp, 0, -1);
    	    if($showurl) echo $nvp;
    	    //curl request
    	    $ch = curl_init();
    	    curl_setopt($ch, CURLOPT_URL, $url);
    	    if($this->certfile) curl_setopt($ch, CURLOPT_SSLCERT, $this->certfile);
    	    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    	    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    	    if($this->proxy)
    		  {
    		    curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
    		    curl_setopt ($ch, CURLOPT_PROXY,$this->proxy);
    		  }
    	    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp);
    	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	    $mydata = curl_exec ($ch);
    	    if(curl_error($ch))
    		  {
    		      $this->error = (curl_error($ch));
    		      echo $this->error;
    		      return false;
    		  }
    	    curl_close ($ch);
    
    	    return $this->process_response($mydata);
    	}
    
    	function process_response($str)
    	{
    	    $data=array();
    	    $x=explode("&", $str);
    	    foreach($x as $val):
    		      $y=explode("=", $val);
    		      $data[$y[0]]=urldecode($y[1]);
    	    endforeach;
    	    return $data;
    	}
    
    	function show_error()
    	{
    	    return $error;
    	}
    }
    
    ?>
  6. AndyCharrington
    Member
    Posted 13 years ago #

    I hope someone can make something of this. It would be so great to have this plugin working for wpmu.

  7. andrea_r
    Moderator
    Posted 13 years ago #

    Two things:

    - please don't paste long pieces of code. It's better to use pastebin.com and link to it. Easier to read, too.

    - there's a premium plugin that does this already.
    http://premium.wpmudev.org/project/pay-to-blog

    The other thread you posted in was for a slightly different plugin that has since been renamed. :)

  8. AndyCharrington
    Member
    Posted 13 years ago #

    Sorry about the long posts......

    As I said already the pay to blog plugin does not do this. The pay to blog plugin required the user to log in before being prompted to pay. It does not include pay pal subscriptions and this makes it totally different to the paypal api subscriptions plugin.

    Again sorry about the long posts. I will know for next time.

    I posted in two other threads. Which plugin are you reffering to?

    Thanks for your help.

    Did you get a chance to look at the code? Any ideas why it doesn't work?

  9. andrewbillits
    Member
    Posted 13 years ago #

    Hiya,

    The next version of the Pay to Blog plugin will allow for subscription payments. Also, regarding this bit:

    The plugin would only charge the user once they had logged in and would not disable the blog if the user had not paid.

    The bit in bold isn't true. What would be the point of a "Pay to Blog" plugin that didn't do anything if the user doesn't pay ;)

    As for the code you posted, I think you're going to need to pay a developer to help you with it.

    Thanks,
    Andrew

  10. AndyCharrington
    Member
    Posted 13 years ago #

    Hi Andrew.

    Happy Christmas!

    Thanks for your response. I had read that intergrating subscriptions was high on your agenda. Can't wait.

    When I said didn't disable the blog I meant the front end. Sorry I wasn't clear about that. My project will be charging the user effectively for storage so the front end needs to disable if they don't pay. Your plugin only disables the back end.

    I think you're right about paying someone to do it...... Oh well. Maybe I'll give it a go myself... ;)

    I'll keep you updated!

  11. AndyCharrington
    Member
    Posted 13 years ago #

    Ok it seems that having the form.php in mu-plugins root causes wordpress to call the form on every page. Not ideal. However I cannot get it to work still. I will update soon.

  12. xenon2050
    Member
    Posted 13 years ago #

    Maybe you can put it in the plugin folder and have plugin commander force it to be activated on every blog, or just the main site. Not sure how it works, but I don't see why it should go in the mu-plugin folder.

  13. AndyCharrington
    Member
    Posted 13 years ago #

    That's a good point. I'm away for a couple of days but will give that a go when I get back. Although thinking about it I'm sure I put it in plugins to begin with. And I don't think it worked. I will have a another look though. Thanks for your reply.

  14. AndyCharrington
    Member
    Posted 13 years ago #

    hello,

    I have tried everything i can think of.

    I have contacted the original developer of this plugin but he is too busy to help.

    So i am asking for help.....

    Can anybody help me convert this plugin to work in MU?

    If money is a problem i will consider paying for it...

    Thanks for your help.

    Andy

    ps. If you would like to contact me directly please do so on andycharrington [at] gmail [dot] com

  15. jtmudge
    Member
    Posted 13 years ago #

    Andy,

    So to summarize where you are at, the plugin works but in the mu-plugin folder it is causing it to appear on every page of every blog, is that correct?

    There are several things you could do. Not sure how you are running your themes, but you should be able to alter them such that they will only show the form where required.

  16. ScottSanders
    Member
    Posted 13 years ago #

    I found a plugin that uses paypal subscriptions and gives users an affiliate link, go check it out its pretty amazing stuff!

    http://summitmediaconcepts.com/wordpress_plugins/subscriber

About this Topic

  • Started 13 years ago by AndyCharrington
  • Latest reply from ScottSanders