Results 1 to 1 of 1

Thread: Registering User While Posting And Ad Combined With Pay By Mobile Integration

  1. #1
    Thread Starter
    stephenoconnor's Avatar
    Join Date
    Mar 2012
    Location
    Ireland
    Posts
    27
    Thanks
    11
    Thanked 7 Times in 5 Posts

    Registering User While Posting And Ad Combined With Pay By Mobile Integration

    step3.php gets used when an ad is placed using paypal. We customised this so WP creates new user based on email field for username for wordpress if unregistered user created the ad and to assign the new ad to his account. It also checks if the email address already has an account, and if so, it doesn't create a new account but assigns the ad to the account already existing.

    Now we added pay by mobile and the equivalent of step3.php is a file called tpl-thanks_post_ad.php - this uses notification function and private key to communicate the mobile solution provider and auto-approve the ad.

    I wonder if I could put the notification function in the step3.php instead so i can avail of the user creation bit but only use it when paying by mobile.

    the first step in the form has this:

    Code:
     <script type='text/javascript'>
            // <![CDATA[
              jQuery(document).ready(function() {
               ******.Widget(****, {
             CtrlId: 'paymentBoxLaunchControlId',
            ServiceId: '****',
           CountryCode: 'IE',
           LanguageCode: 'en',
           ItemCode: 'HM001',
           Mode: 'SIMULATION',
           ReturnUrl: '<?php echo get_site_url(); ?>/thank-you-ad-posting/',
           ShowCloseButton: true,
           WidgetLoadedCallbackUrl: '<?php echo get_site_url(); ?>/mobile-notify/',
           OnWidgetLoadAttempt: function() { /*alert('function called prior to lanuching payment box');*/ },
           CustomString: '<?php echo $post->ID;?>'
           // CssUrl: 'http://your-domain/custom-widget.css', // default to use ******'s CSS
         });
         });
          </script>
    I am guessing I change this thank-you-ad-posting bit to the step3.php page but inside the step3.php I am not sure how to insert the function so that it only runs if it's mobile payment. This is the notification function that I have currently:

    Code:
       function notification($privateKey)
           {
           $iv = base64_decode($_REQUEST["bpi"]);
             $enc = $_REQUEST["bpe"];
              $sig = $_REQUEST["bps"];
              $sig2 = hash_hmac("sha256", utf8_encode($iv . '.' . $enc), utf8_encode($privateKey));
    
              if ($sig == strtolower($sig2)) {
              return str_replace(chr(0), '', 
            mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $privateKey, 
                base64_decode($enc), MCRYPT_MODE_CBC, $iv));
    
             // The return value should then be parsed to retrieve each notification parameter
            }
              else {
              return null;
            }
              }
          ?>
             <?php
         $query = notification('********************************');
        $trans_array = explode('&',$query);
          list($psdi, $msisdn, $custom, $status) = explode('&',$query);
            ?>
    It needs to go somewhere in to the step3 file here:

    Code:
        <?php
                    /**
                     * This is step 3 of 3 for the ad submission form
                     * 
                     * @package ClassiPress
                     * @subpackage New Ad
                     * @author AppThemes
                     *
                     *
                     */
    
    
                    global $current_user, $wpdb;
    
                    // now get all the ad values which we stored in an associative array in the db
                    // first we do a check to make sure this db session still exists and then we'll
                    // use this option array to create the new ad below
                    $advals = get_option( 'cp_'.$_POST['oid'] );
    
                    if ( isset( $_POST['cp_payment_method'] ) ) 
                        $advals['cp_payment_method'] = $_POST['cp_payment_method'];
                    else 
                        $advals['cp_payment_method'] = '';
    
                    // check and make sure the form was submitted from step 2 and the hidden oid matches the oid in the db
                    // we don't want to create duplicate ad submissions if someone reloads their browser
                    if ( isset( $_POST['step2'] ) && isset( $advals['oid'] ) && ( strcasecmp( $_POST['oid'], $advals['oid'] ) == 0 ) ) {
                    ?>
    
    
                       <div id="step3"></div>
    
                       <h2 class="dotted">
                           <?php 
                            if ( get_option('cp_charge_ads') == 'yes' ) 
                                _e('Final Step', 'appthemes'); 
                            else 
                                _e('Ad Listing Received', 'appthemes'); 
                            ?>
                       </h2>
    
                       <img src="<?php bloginfo('template_url'); ?>/images/step3.gif" alt="" class="stepimg" />
    
                        <div class="processlog">
                        <?php 
                            // insert the ad and get back the post id
                            $post_id = cp_add_new_listing( $advals );
    
                            // Changes to register user or link the ad to user AFTER posting the ad.
                    // if the ad is found, then link it to user or create user
    
                    // Get user name and email from the ad
                        $new_ad_email = get_post_meta($post_id, 'cp_email', true);
                        $user_name = get_post_meta($post_id, 'cp_name', true);
    
                    // Check if a user with the same email already exists
                       if($new_ad_email) {
    
                            $sql = $wpdb->prepare("SELECT u.ID FROM $wpdb->users u
                                   WHERE u.user_email = '$new_ad_email'
                                   ");
    
                            $user_id = $wpdb->get_row($sql);
                    // If yes, update the ad to link it to the found user
                           if($user_id) {
                             $the_post = array();
                             $the_post['ID'] = $post_id;
                             $the_post['post_author'] = $user_id->ID;
                             $post = wp_update_post($the_post);
    
                    // If not, create user, set nicename and displayname to name and link ad to him         
                          } else {
                             $user_pass = wp_generate_password();
                             $new_user_id = wp_create_user( $new_ad_email, $user_pass, $new_ad_email );
    
                             $the_user = array();
                             $the_user['ID'] = $new_user_id;
                             $the_user['user_nicename'] = $user_name;
                             $the_user['display_name'] =  $user_name;
                             $post = wp_update_user($the_user);
    
                             $the_post = array();
                             $the_post['ID'] = $post_id;
                             $the_post['post_author'] = $new_user_id;
                             $post = wp_update_post($the_post);
    
                             wp_new_user_notification($new_user_id, $user_pass);   
    
                          }
                       }
                    // END OF CHANGES
    
                        ?>
                        </div>
                        <div class="thankyou">
    
    
                        <?php
    
                        //incriment coupon code count only if total ad price was not zero
                        if (isset($advals['cp_coupon_code']) && cp_check_coupon_discount($advals['cp_coupon_code']) )
                            cp_use_coupon($advals['cp_coupon_code']);
    
                        // call in the selected payment gateway as long as the price isn't zero
                        if ( (get_option('cp_charge_ads') == 'yes') && ($advals['cp_sys_total_ad_cost'] != 0) ) {
    
                            //load payment gateway page to process checkout
                            include_once ( TEMPLATEPATH . '/includes/gateways/gateway.php' );
    
                        } else {
    
                        // otherwise the ad was free and show the thank you page.
                            // get the post status
                            $the_post = get_post( $post_id ); 
    
                            // check to see what the ad status is set to
                            if ( $the_post->post_status == 'pending' ) {
    
                                // send ad owner an email
                                cp_owner_new_ad_email( $post_id );
    
                            ?>
    
                                <h3><?php _e('Thank you! Your ad listing has been submitted for review.','appthemes') ?></h3>
                                <p><?php _e('You can check the status by viewing your dashboard.','appthemes') ?></p>
    
                            <?php } else { ?>
    
                                <h3><?php _e('Thank you! Your ad listing has been submitted and is now live.','appthemes') ?></h3>
                                <p><?php _e('Visit your dashboard to make any changes to your ad listing or profile.','appthemes') ?></p>
                                <a href="<?php echo get_permalink($post_id); ?>"><?php _e('View your new ad listing.','appthemes') ?></a>
    
                            <?php } ?>
    
    
                        </div> <!-- /thankyou -->
    
                        <?php
                        }
    
    
                        // send new ad notification email to admin
                        if ( get_option('cp_new_ad_email') == 'yes' || $advals['cp_payment_method'] == 'banktransfer' )
                            cp_new_ad_email( $post_id );
    
    
                        // remove the temp session option from the database
                        delete_option( 'cp_'.$_POST['oid'] );
    
    
                    } else {
    
                    ?>
    
                        <h2 class="dotted"><?php _e('An Error Has Occurred','appthemes') ?></h2>
    
                        <div class="thankyou">
                            <p><?php _e('Your session has expired or you are trying to submit a duplicate ad. Please start over.','appthemes') ?></p>
                        </div>
    
                    <?php
    
                    }
    
                    ?>
    
                        <div class="pad100"></div>
    Any help with this issue will be greatly appreciated.

    Thanks from Steve

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. CapthCHa Error ! when registering new user!
    By madiw in forum ClassiPress General Discussion
    Replies: 3
    Last Post: October 14th, 2014, 05:26 AM
  2. Registering NEw user - > Usernames with: Ö - Ä - Ü not allowed
    By optagon66 in forum Report JobRoller Bugs
    Replies: 10
    Last Post: September 1st, 2012, 02:37 PM
  3. Registering/ new user
    By sellyourskill in forum Report Vantage Bugs (Legacy)
    Replies: 1
    Last Post: May 16th, 2012, 10:33 PM