コード例 #1
0
 /**
  * Process membership order
  *
  * @param array
  */
 public static function process_membership_order($order_info)
 {
     $file = get_template_directory() . '/includes/forms/step-functions.php';
     if (is_readable($file)) {
         include_once $file;
         /*
          * Abracadabra
          */
         $txn_id = $order_info['txn_id'];
         /*
          * First we retrieve user orders by the transaction id
          * @see https://bitbucket.org/Pronamic/classipress/src/bc1334736c6e/includes/theme-functions.php?at=3.2.1#cl-2488
          */
         $orders = get_user_orders('', $txn_id);
         $order = get_option($orders);
         /*
          * Get the user ID from the orders
          * @see https://bitbucket.org/Pronamic/classipress/src/bc1334736c6e/includes/theme-functions.php?at=3.2.1#cl-2476
          */
         $user_id = get_order_userid($orders);
         /*
          * Get user data
          * @see http://codex.wordpress.org/Function_Reference/get_userdata
          */
         $userdata = get_userdata($user_id);
         // @see https://bitbucket.org/Pronamic/classipress/src/bc1334736c6e/includes/forms/step-functions.php?at=3.2.1#cl-895
         $order_processed = appthemes_process_membership_order($userdata, $order);
         if ($order_processed) {
             // @see https://bitbucket.org/Pronamic/classipress/src/bc1334736c6e/includes/theme-emails.php?at=3.2.1#cl-563
             cp_owner_activated_membership_email($userdata, $order_processed);
         }
     }
 }
コード例 #2
0
ファイル: ipn.php プロジェクト: joaosigno/dazake-job
function cp_handle_ipn_response($_POST)
{
    global $wpdb;
    //step functions required to process orders
    include_once "wp-load.php";
    include_once TEMPLATEPATH . '/includes/forms/step-functions.php';
    // make sure the ad unique trans id (stored in invoice var) is included
    if (!empty($_POST['txn_type']) && !empty($_POST['invoice'])) {
        // process the ad based on the paypal response
        switch (strtolower($_POST['payment_status'])) {
            // payment was made so we can approve the ad
            case 'completed':
                $pid = trim($_POST['invoice']);
                //attempt to process membership order first
                $orders = get_user_orders('', $pid);
                if (!empty($orders)) {
                    $order_id = get_order_id($orders);
                    $storedOrder = get_option($orders);
                    $user_id = get_order_userid($orders);
                    $the_user = get_userdata($user_id);
                    if (get_option('cp_paypal_ipn_debug') == 'true' && !empty($orders)) {
                        wp_mail(get_option('admin_email'), 'PayPal IPN Attempting to Activate Memebership', print_r($orders, true) . PHP_EOL . print_r($order, true) . PHP_EOL . print_r($_REQUEST, true));
                    }
                    $order_processed = appthemes_process_membership_order($the_user, $storedOrder);
                }
                if ($order_processed) {
                    //admin email confirmation
                    //TODO - move into wordpress options panel and allow customization
                    wp_mail(get_option('admin_email'), 'PayPal IPN Activated Memebership', __('A membership order has been completed. Check to make sure this is a valid order by comparing this messages Paypal Transaction ID to the respective ID in the Paypal payment receipt email.', 'appthemes') . PHP_EOL . __('Order ID: ', 'appthemes') . print_r($orders, true) . PHP_EOL . __('User ID: ', 'appthemes') . print_r($user_id, true) . PHP_EOL . __('User Login: '******'appthemes') . print_r($the_user->user_login, true) . PHP_EOL . __('Pack Name: ', 'appthemes') . print_r(stripslashes($storedOrder['pack_name']), true) . PHP_EOL . __('Total Cost: ', 'appthemes') . print_r($storedOrder['total_cost'], true) . PHP_EOL . __('Paypal Transaction ID: ', 'appthemes') . print_r($_POST['txn_id'], true) . PHP_EOL);
                    break;
                }
                $sql = $wpdb->prepare("SELECT p.ID, p.post_status\r\n                            FROM {$wpdb->posts} p, {$wpdb->postmeta} m\r\n                            WHERE p.ID = m.post_id\r\n                            AND p.post_status <> 'publish'\r\n                            AND m.meta_key = 'cp_sys_ad_conf_id'\r\n                            AND m.meta_value = %s\r\n                            ", $pid);
                $newadid = $wpdb->get_row($sql);
                // if the ad is found, then publish it
                if ($newadid) {
                    $the_ad = array();
                    $the_ad['ID'] = $newadid->ID;
                    $the_ad['post_status'] = 'publish';
                    $ad_id = wp_update_post($the_ad);
                    // now we need to update the ad expiration date so they get the full length of time
                    // sometimes they didn't pay for the ad right away or they are renewing
                    // first get the ad duration and first see if ad packs are being used
                    // if so, get the length of time in days otherwise use the default
                    // prune period defined on the CP settings page
                    $ad_length = get_post_meta($ad_id, 'cp_sys_ad_duration', true);
                    if (isset($ad_length)) {
                        $ad_length = $ad_length;
                    } else {
                        $ad_length = get_option('cp_prun_period');
                    }
                    // set the ad listing expiration date
                    $ad_expire_date = date_i18n('m/d/Y H:i:s', strtotime('+' . $ad_length . ' days'));
                    // don't localize the word 'days'
                    //now update the expiration date on the ad
                    update_post_meta($ad_id, 'cp_sys_expire_date', $ad_expire_date);
                }
                break;
            case 'pending':
                // send an email if payment is pending
                wp_mail(get_option('admin_email'), 'PayPal IPN - payment pending', "" . print_r($_POST, true));
                break;
                // payment failed so don't approve the ad
            // payment failed so don't approve the ad
            case 'denied':
            case 'expired':
            case 'failed':
            case 'voided':
                // send an email if payment didn't work
                wp_mail(get_option('admin_email'), 'PayPal IPN - payment failed', "" . print_r($_POST, true));
                break;
        }
        // regardless of what happens, log the transaction
        if (file_exists(TEMPLATEPATH . '/includes/gateways/process.php')) {
            include_once TEMPLATEPATH . '/includes/gateways/process.php';
        }
    }
}
コード例 #3
0
            
                <div class="thankyou">
            
                    <?php 
    // call in the selected payment gateway as long as the price isn't zero
    if (cp_payments_is_enabled() && $order['total_cost'] > 0) {
        $membership_order = appthemes_new_order();
        $membership_order->add_item(CP_ITEM_MEMBERSHIP, $order['total_cost']);
        do_action('appthemes_create_order', $membership_order);
        echo html('h3', __('Payment', APP_TD));
        echo html('p', __('Please wait while we redirect you to our payment page.', APP_TD));
        echo html('p', html('small', __('(Click the button below if you are not automatically redirected within 5 seconds.)', APP_TD)));
        cp_js_redirect($membership_order->get_return_url(), __('Continue to Payment', APP_TD));
        //process the "free" orders on this page
    } else {
        $order_processed = appthemes_process_membership_order($current_user, $order);
        //send email to user
        if ($order_processed) {
            cp_owner_activated_membership_email($current_user, $order_processed);
        }
        ?>
            
                        <h3><?php 
        _e('Your order has been completed and your membership status should now be active.', APP_TD);
        ?>
</h3>
            
                        <p><?php 
        _e('Visit your dashboard to review your membership status details.', APP_TD);
        ?>
</p>
コード例 #4
0
ファイル: admin-options.php プロジェクト: kalushta/darom
function cp_transactions()
{
    global $wpdb, $wp_version;
    include_once TEMPLATEPATH . '/includes/forms/step-functions.php';
    if (isset($_GET['p'])) {
        $page = (int) $_GET['p'];
    } else {
        $page = 1;
    }
    $per_page = 10;
    $start = $per_page * $page - $per_page;
    // check to prevent php "notice: undefined index" msg when php strict warnings is on
    if (isset($_GET['action'])) {
        $theswitch = $_GET['action'];
    } else {
        $theswitch = '';
    }
    switch ($theswitch) {
        // mark transaction as paid
        case 'setPaid':
            $wpdb->update($wpdb->cp_order_info, array('payment_status' => 'Completed'), array('id' => $_GET['id']));
            ?>
			<p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
            _e('Updating transaction entry.....', APP_TD);
            ?>
<br /><br /><img src="<?php 
            bloginfo('template_directory');
            ?>
/images/loader.gif" alt="" /></p>
			<meta http-equiv="refresh" content="0; URL=?page=transactions">

		<?php 
            break;
            // mark transaction as unpaid
        // mark transaction as unpaid
        case 'unsetPaid':
            $wpdb->update($wpdb->cp_order_info, array('payment_status' => 'Pending'), array('id' => $_GET['id']));
            ?>
			<p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
            _e('Updating transaction entry.....', APP_TD);
            ?>
<br /><br /><img src="<?php 
            bloginfo('template_directory');
            ?>
/images/loader.gif" alt="" /></p>
			<meta http-equiv="refresh" content="0; URL=?page=transactions">

		<?php 
            break;
            // delete transaction entry
        // delete transaction entry
        case 'delete':
            if (version_compare($wp_version, '3.4', '>=')) {
                $wpdb->delete($wpdb->cp_order_info, array('id' => $_GET['id']));
            } else {
                $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->cp_order_info} WHERE id = %d", $_GET['id']));
            }
            ?>
			<p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
            _e('Deleting transaction entry.....', APP_TD);
            ?>
<br /><br /><img src="<?php 
            bloginfo('template_directory');
            ?>
/images/loader.gif" alt="" /></p>
			<meta http-equiv="refresh" content="0; URL=?page=transactions">

		<?php 
            break;
            // activate membership, update transaction entry
        // activate membership, update transaction entry
        case 'activateMembership':
            $orders = get_user_orders('', $_GET['oid']);
            if (!empty($orders)) {
                $order_id = get_order_id($orders);
                $storedOrder = get_option($orders);
                $user_id = get_order_userid($orders);
                $the_user = get_userdata($user_id);
                //activate membership
                $order_processed = appthemes_process_membership_order($the_user, $storedOrder);
                //send email to user
                if ($order_processed) {
                    cp_owner_activated_membership_email($the_user, $order_processed);
                }
                //update transaction entry
                $wpdb->update($wpdb->cp_order_info, array('payment_status' => 'Completed'), array('custom' => $_GET['oid']));
            }
            ?>
			<p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
            _e('Activating membership plan.....', APP_TD);
            ?>
<br /><br /><img src="<?php 
            bloginfo('template_directory');
            ?>
/images/loader.gif" alt="" /></p>
			<meta http-equiv="refresh" content="0; URL=?page=transactions">

		<?php 
            break;
            // show the table of all transactions
        // show the table of all transactions
        default:
            ?>
    <div class="wrap">
        <div class="icon32" id="icon-themes"><br /></div>
        <h2><?php 
            _e('Order Transactions', APP_TD);
            ?>
</h2>

        <?php 
            cp_admin_info_box();
            ?>

        <table id="tblspacer" class="widefat fixed">

            <thead>
                <tr>
                    <th scope="col" style="width:35px;">&nbsp;</th>
                    <th scope="col"><?php 
            _e('Payer Name', APP_TD);
            ?>
</th>
                    <th scope="col" style="text-align: center;"><?php 
            _e('Payer Status', APP_TD);
            ?>
</th>
                    <th scope="col"><?php 
            _e('Ad Title', APP_TD);
            ?>
</th>
                    <th scope="col"><?php 
            _e('Item Description', APP_TD);
            ?>
</th>
                    <th scope="col" style="width:125px;"><?php 
            _e('Transaction ID', APP_TD);
            ?>
</th>
                    <th scope="col"><?php 
            _e('Payment Type', APP_TD);
            ?>
</th>
                    <th scope="col"><?php 
            _e('Payment Status', APP_TD);
            ?>
</th>
                    <th scope="col"><?php 
            _e('Total Amount', APP_TD);
            ?>
</th>
                    <th scope="col" style="width:150px;"><?php 
            _e('Date Paid', APP_TD);
            ?>
</th>
                    <th scope="col" style="text-align:center;width:100px;"><?php 
            _e('Actions', APP_TD);
            ?>
</th>
                </tr>
            </thead>

    <?php 
            // must be higher than personal edition so let's query the db
            $sql = "SELECT SQL_CALC_FOUND_ROWS o.*, p.post_title " . "FROM {$wpdb->cp_order_info} o, {$wpdb->posts} p " . "WHERE o.ad_id = p.id " . "ORDER BY o.id DESC LIMIT {$start},{$per_page}";
            $results = $wpdb->get_results($sql);
            $total_pages = $wpdb->get_var("SELECT FOUND_ROWS()");
            $total_pages = ceil($total_pages / $per_page);
            if ($results) {
                $rowclass = '';
                $i = 1;
                ?>

              <tbody id="list">

            <?php 
                foreach ($results as $result) {
                    $rowclass = 'even' == $rowclass ? 'alt' : 'even';
                    if ($result->user_id > 0) {
                        $user = get_user_by('id', $result->user_id);
                        $user_link = $user ? '( <a href="user-edit.php?user_id=' . $user->ID . '" title="' . __('Edit user', APP_TD) . '">' . $user->user_login . '</a> )<br />' : '';
                    } else {
                        $user_link = '';
                    }
                    ?>

                <tr class="<?php 
                    echo $rowclass;
                    ?>
">
                    <td style="padding-left:10px;"><?php 
                    echo $i;
                    ?>
.</td>

                    <td><strong><?php 
                    echo $result->first_name;
                    ?>
 <?php 
                    echo $result->last_name;
                    ?>
</strong><br /><?php 
                    echo $user_link;
                    ?>
<a href="mailto:<?php 
                    echo $result->payer_email;
                    ?>
"><?php 
                    echo $result->payer_email;
                    ?>
</a></td>
                    <td style="text-align: center;">
                        <?php 
                    if ($result->payer_status == 'verified') {
                        ?>
<img src="<?php 
                        bloginfo('template_directory');
                        ?>
/images/paypal_verified.gif" alt="" title="" /><br /><?php 
                    }
                    ?>
                        <?php 
                    echo cp_get_status_i18n($result->payer_status);
                    ?>
                    </td>
                    <td><a href="post.php?action=edit&post=<?php 
                    echo $result->ad_id;
                    ?>
"><?php 
                    echo $result->post_title;
                    ?>
</a></td>
                    <td><?php 
                    echo $result->item_name;
                    ?>
</td>
                    <td><?php 
                    echo $result->txn_id;
                    ?>
</td>
                    <td><?php 
                    echo ucfirst($result->payment_type);
                    ?>
</td>
                    <td><?php 
                    echo cp_get_status_i18n($result->payment_status);
                    ?>
</td>
                    <td><?php 
                    cp_display_price($result->mc_gross, $result->mc_currency);
                    ?>
</td>
                    <td><?php 
                    echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $result->payment_date);
                    ?>
</td>
                    <td style="text-align:center">
                      <?php 
                    echo '<a onclick="return confirmBeforeDelete();" href="?page=transactions&amp;action=delete&amp;id=' . $result->id . '" title="' . __('Delete', APP_TD) . '"><img src="' . get_bloginfo('template_directory') . '/images/cross.png" alt="' . __('Delete', APP_TD) . '" /></a>&nbsp;&nbsp;&nbsp;';
                    if (strtolower($result->payment_status) == 'completed') {
                        echo '<br /><a href="?page=transactions&amp;action=unsetPaid&amp;id=' . $result->id . '" title="' . __('Mark as Unpaid', APP_TD) . '">' . __('Unmark Paid', APP_TD) . '</a>';
                    } else {
                        echo '<br /><a href="?page=transactions&amp;action=setPaid&amp;id=' . $result->id . '" title="' . __('Mark as Paid', APP_TD) . '">' . __('Mark Paid', APP_TD) . '</a>';
                    }
                    ?>
                    </td>
                </tr>

              <?php 
                    $i++;
                }
                // end for each
                ?>

            </tbody>

        <?php 
            } else {
                ?>

            <tr>
                <td>&nbsp;</td><td colspan="10"><?php 
                _e('No transactions found.', APP_TD);
                ?>
</td>
            </tr>

        <?php 
            }
            // end $results
            ?>

        </table> <!-- this is ok -->

				<div class="tablenav">
					<div class="tablenav-pages alignright">
						<?php 
            if ($total_pages > 1) {
                echo paginate_links(array('base' => 'admin.php?page=transactions%_%', 'format' => '&p=%#%', 'prev_text' => __('&laquo; Previous', APP_TD), 'next_text' => __('Next &raquo;', APP_TD), 'total' => $total_pages, 'current' => $page, 'end_size' => 1, 'mid_size' => 5));
            }
            ?>
	
					</div> 
				</div>
				<div class="clear"></div>


        <div class="icon32" id="icon-themes"><br /></div>
        <h2><?php 
            _e('Membership Orders', APP_TD);
            ?>
</h2>
        <table id="tblspacer" class="widefat fixed">

            <thead>
                <tr>
                    <th scope="col" style="width:35px;">&nbsp;</th>
                    <th scope="col"><?php 
            _e('Payer Name', APP_TD);
            ?>
</th>
                    <th scope="col" style="text-align: center;"><?php 
            _e('Payer Status', APP_TD);
            ?>
</th>
                    <th scope="col"><?php 
            _e('Item Description', APP_TD);
            ?>
</th>
                    <th scope="col" style="width:125px;"><?php 
            _e('Transaction ID', APP_TD);
            ?>
</th>
                    <th scope="col"><?php 
            _e('Payment Type', APP_TD);
            ?>
</th>
                    <th scope="col"><?php 
            _e('Payment Status', APP_TD);
            ?>
</th>
                    <th scope="col"><?php 
            _e('Total Amount', APP_TD);
            ?>
</th>
                    <th scope="col" style="width:150px;"><?php 
            _e('Date Paid', APP_TD);
            ?>
</th>
                    <th scope="col" style="text-align:center;width:100px;"><?php 
            _e('Actions', APP_TD);
            ?>
</th>
                </tr>
            </thead>


		<?php 
            // seperate table for membership orders
            $sql = "SELECT SQL_CALC_FOUND_ROWS * " . "FROM {$wpdb->cp_order_info} " . "WHERE ad_id = 0 " . "ORDER BY id DESC LIMIT {$start},{$per_page}";
            $results = $wpdb->get_results($sql);
            $total_pages = $wpdb->get_var("SELECT FOUND_ROWS()");
            $total_pages = ceil($total_pages / $per_page);
            if ($results) {
                $rowclass = '';
                $i = 1;
                ?>

              <tbody id="list">

            <?php 
                foreach ($results as $result) {
                    $rowclass = 'even' == $rowclass ? 'alt' : 'even';
                    if ($result->user_id > 0) {
                        $user = get_user_by('id', $result->user_id);
                        $user_link = $user ? '( <a href="user-edit.php?user_id=' . $user->ID . '" title="' . __('Edit user', APP_TD) . '">' . $user->user_login . '</a> )<br />' : '';
                    } else {
                        $user_link = '';
                    }
                    ?>

                <tr class="<?php 
                    echo $rowclass;
                    ?>
">
                    <td style="padding-left:10px;"><?php 
                    echo $i;
                    ?>
.</td>
					<?php 
                    $payer = get_user_by('email', $result->payer_email);
                    ?>
                    <?php 
                    //TODO - LOOKUP CUSTOMER BY PAYPAL EMAIL CUSTOM PROFILE FIELD
                    ?>
                    <td><strong><?php 
                    echo $result->first_name;
                    ?>
 <?php 
                    echo $result->last_name;
                    ?>
</strong><br /><?php 
                    echo $user_link;
                    ?>
<a href="<?php 
                    if (isset($payer->ID) && $payer) {
                        echo get_bloginfo('url') . '/wp-admin/user-edit.php?user_id=' . $payer->ID;
                    } else {
                        echo 'mailto:' . $result->payer_email;
                    }
                    ?>
"><?php 
                    echo $result->payer_email;
                    ?>
</a></td>
                    <td style="text-align: center;">
                        <?php 
                    if ($result->payer_status == 'verified') {
                        ?>
<img src="<?php 
                        bloginfo('template_directory');
                        ?>
/images/paypal_verified.gif" alt="" title="" /><br /><?php 
                    }
                    ?>
                        <?php 
                    echo cp_get_status_i18n($result->payer_status);
                    ?>
                    </td>
                    <td><?php 
                    echo $result->item_name;
                    ?>
</td>
                    <td><?php 
                    echo $result->txn_id;
                    ?>
</td>
                    <td><?php 
                    echo ucfirst($result->payment_type);
                    ?>
</td>
                    <td><?php 
                    echo cp_get_status_i18n($result->payment_status);
                    ?>
</td>
                    <td><?php 
                    cp_display_price($result->mc_gross, $result->mc_currency);
                    ?>
</td>
                    <td><?php 
                    echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $result->payment_date);
                    ?>
</td>
                    <td style="text-align:center">
											<?php 
                    echo '<a onclick="return confirmBeforeDelete();" href="?page=transactions&amp;action=delete&amp;id=' . $result->id . '" title="' . __('Delete', APP_TD) . '"><img src="' . get_bloginfo('template_directory') . '/images/cross.png" alt="' . __('Delete', APP_TD) . '" /></a>&nbsp;&nbsp;&nbsp;';
                    if (strtolower($result->payment_status) == 'completed') {
                        echo '<br /><a href="?page=transactions&amp;action=unsetPaid&amp;id=' . $result->id . '" title="' . __('Mark as Unpaid', APP_TD) . '">' . __('Unmark Paid', APP_TD) . '</a>';
                    } else {
                        echo '<br /><a href="?page=transactions&amp;action=setPaid&amp;id=' . $result->id . '" title="' . __('Mark as Paid', APP_TD) . '">' . __('Mark Paid', APP_TD) . '</a>';
                        if (!empty($result->custom)) {
                            $orders = get_user_orders('', $result->custom);
                        } else {
                            $orders = '';
                        }
                        if (!empty($orders)) {
                            echo '<br /><a href="?page=transactions&amp;action=activateMembership&amp;oid=' . $result->custom . '" title="' . __('Activate membership', APP_TD) . '">' . __('Activate membership', APP_TD) . '</a>';
                        }
                    }
                    ?>
                    </td>
                </tr>

              <?php 
                    $i++;
                }
                // end for each
                ?>

              </tbody>

            <?php 
            } else {
                ?>

                <tr>
                    <td>&nbsp;</td><td colspan="9"><?php 
                _e('No transactions found.', APP_TD);
                ?>
</td>
                </tr>

            <?php 
            }
            // end $results
            ?>

				</table> <!-- this is ok -->

				<div class="tablenav">
					<div class="tablenav-pages alignright">
						<?php 
            if ($total_pages > 1) {
                echo paginate_links(array('base' => 'admin.php?page=transactions%_%', 'format' => '&p=%#%', 'prev_text' => __('&laquo; Previous', APP_TD), 'next_text' => __('Next &raquo;', APP_TD), 'total' => $total_pages, 'current' => $page, 'end_size' => 1, 'mid_size' => 5));
            }
            ?>
	
					</div> 
				</div>
				<div class="clear"></div>


        </div><!-- end wrap -->

    <?php 
    }
    // endswitch
    ?>



    <script type="text/javascript">
        /* <![CDATA[ */
            function confirmBeforeDelete() { return confirm("<?php 
    _e('WARNING: Are you sure you want to delete this transaction entry?? (This cannot be undone)', APP_TD);
    ?>
"); }
        /* ]]> */
    </script>

<?php 
}
コード例 #5
0
ファイル: ipn.php プロジェクト: kalushta/darom
function cp_handle_ipn_response()
{
    global $wpdb;
    //step functions required to process orders
    include_once "wp-load.php";
    include_once TEMPLATEPATH . '/includes/forms/step-functions.php';
    // make sure the ad unique trans id (stored in invoice var) is included
    if (!empty($_POST['txn_id']) && !empty($_REQUEST['invoice'])) {
        $request_data = stripslashes_deep($_REQUEST);
        // process the ad based on the paypal response
        switch (strtolower($_POST['payment_status'])) {
            // payment was made so we can approve the ad
            case 'completed':
                $pid = trim($_REQUEST['invoice']);
                //attempt to process membership order first
                $orders = get_user_orders('', $pid);
                if (!empty($orders)) {
                    $order_id = get_order_id($orders);
                    $storedOrder = get_option($orders);
                    $user_id = get_order_userid($orders);
                    $the_user = get_userdata($user_id);
                    if (get_option('cp_paypal_ipn_debug') == 'true' && !empty($orders)) {
                        wp_mail(get_option('admin_email'), __('PayPal IPN Attempting to Activate Membership', APP_TD), print_r($orders, true) . PHP_EOL . print_r($order, true) . PHP_EOL . print_r($request_data, true));
                    }
                    $order_processed = appthemes_process_membership_order($the_user, $storedOrder);
                }
                if ($order_processed) {
                    //send email to user
                    cp_owner_activated_membership_email($the_user, $order_processed);
                    //admin email confirmation
                    //TODO - move into wordpress options panel and allow customization
                    wp_mail(get_option('admin_email'), __('PayPal IPN Activated Membership', APP_TD), __('A membership order has been completed. Check to make sure this is a valid order by comparing this messages Paypal Transaction ID to the respective ID in the Paypal payment receipt email.', APP_TD) . PHP_EOL . __('Order ID: ', APP_TD) . print_r($orders, true) . PHP_EOL . __('User ID: ', APP_TD) . print_r($user_id, true) . PHP_EOL . __('User Login: '******'Pack Name: ', APP_TD) . print_r(stripslashes($storedOrder['pack_name']), true) . PHP_EOL . __('Total Cost: ', APP_TD) . print_r($storedOrder['total_cost'], true) . PHP_EOL . __('Paypal Transaction ID: ', APP_TD) . print_r($_POST['txn_id'], true) . PHP_EOL);
                    break;
                }
                $sql = $wpdb->prepare("SELECT p.ID, p.post_status\n\t\t\t\t\tFROM {$wpdb->posts} p, {$wpdb->postmeta} m\n\t\t\t\t\tWHERE p.ID = m.post_id\n\t\t\t\t\tAND p.post_status <> 'publish'\n\t\t\t\t\tAND m.meta_key = 'cp_sys_ad_conf_id'\n\t\t\t\t\tAND m.meta_value = %s\n\t\t\t\t\t", $pid);
                $newadid = $wpdb->get_row($sql);
                // if the ad is found, then publish it
                if ($newadid) {
                    $the_ad = array();
                    $the_ad['ID'] = $newadid->ID;
                    $the_ad['post_status'] = 'publish';
                    $ad_id = wp_update_post($the_ad);
                    // now we need to update the ad expiration date so they get the full length of time
                    // sometimes they didn't pay for the ad right away or they are renewing
                    // first get the ad duration and first see if ad packs are being used
                    // if so, get the length of time in days otherwise use the default
                    // prune period defined on the CP settings page
                    $ad_length = get_post_meta($ad_id, 'cp_sys_ad_duration', true);
                    if (isset($ad_length)) {
                        $ad_length = $ad_length;
                    } else {
                        $ad_length = get_option('cp_prun_period');
                    }
                    // set the ad listing expiration date
                    $ad_expire_date = date_i18n('m/d/Y H:i:s', strtotime('+' . $ad_length . ' days'));
                    // don't localize the word 'days'
                    //now update the expiration date on the ad
                    update_post_meta($ad_id, 'cp_sys_expire_date', $ad_expire_date);
                }
                break;
            case 'pending':
                // send an email if payment is pending
                $mailto = get_option('admin_email');
                $subject = __('PayPal IPN - payment pending', APP_TD);
                $headers = 'From: ' . __('ClassiPress Admin', APP_TD) . ' <' . get_option('admin_email') . '>' . "\r\n";
                $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
                $message = __('Dear Admin,', APP_TD) . "\r\n\r\n";
                $message .= sprintf(__('The following payment is pending on your %s website.', APP_TD), $blogname) . "\r\n\r\n";
                $message .= __('Payment Details', APP_TD) . "\r\n";
                $message .= __('-----------------', APP_TD) . "\r\n";
                $message .= __('Payer PayPal address: ', APP_TD) . $_POST['payer_email'] . "\r\n";
                $message .= __('Transaction ID: ', APP_TD) . $_POST['txn_id'] . "\r\n";
                $message .= __('Payer first name: ', APP_TD) . $_POST['first_name'] . "\r\n";
                $message .= __('Payer last name: ', APP_TD) . $_POST['last_name'] . "\r\n";
                $message .= __('Payment type: ', APP_TD) . $_POST['payment_type'] . "\r\n";
                $message .= __('Amount: ', APP_TD) . html_entity_decode(cp_display_price($_POST['mc_gross'], $_POST['mc_currency'], false), ENT_QUOTES, 'UTF-8') . "\r\n\r\n";
                $message .= __('Full Details', APP_TD) . "\r\n";
                $message .= __('-----------------', APP_TD) . "\r\n";
                $message .= print_r($request_data, true) . "\r\n";
                wp_mail($mailto, $subject, $message, $headers);
                break;
                // payment failed so don't approve the ad
            // payment failed so don't approve the ad
            case 'denied':
            case 'expired':
            case 'failed':
            case 'voided':
                // send an email if payment didn't work
                $mailto = get_option('admin_email');
                $subject = __('PayPal IPN - payment failed', APP_TD);
                $headers = 'From: ' . __('ClassiPress Admin', APP_TD) . ' <' . get_option('admin_email') . '>' . "\r\n";
                $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
                $message = __('Dear Admin,', APP_TD) . "\r\n\r\n";
                $message .= sprintf(__('The following payment has failed on your %s website.', APP_TD), $blogname) . "\r\n\r\n";
                $message .= __('Payment Details', APP_TD) . "\r\n";
                $message .= __('-----------------', APP_TD) . "\r\n";
                $message .= __('Payer PayPal address: ', APP_TD) . $_POST['payer_email'] . "\r\n";
                $message .= __('Transaction ID: ', APP_TD) . $_POST['txn_id'] . "\r\n";
                $message .= __('Payer first name: ', APP_TD) . $_POST['first_name'] . "\r\n";
                $message .= __('Payer last name: ', APP_TD) . $_POST['last_name'] . "\r\n";
                $message .= __('Payment type: ', APP_TD) . $_POST['payment_type'] . "\r\n";
                $message .= __('Amount: ', APP_TD) . html_entity_decode(cp_display_price($_POST['mc_gross'], $_POST['mc_currency'], false), ENT_QUOTES, 'UTF-8') . "\r\n\r\n";
                $message .= __('Full Details', APP_TD) . "\r\n";
                $message .= __('-----------------', APP_TD) . "\r\n";
                $message .= print_r($request_data, true) . "\r\n";
                wp_mail($mailto, $subject, $message, $headers);
                break;
            case 'refunded':
            case 'reversed':
            case 'chargeback':
                // send an email if payment was refunded
                $mailto = get_option('admin_email');
                $subject = __('PayPal IPN - payment refunded/reversed', APP_TD);
                $headers = 'From: ' . __('ClassiPress Admin', APP_TD) . ' <' . get_option('admin_email') . '>' . "\r\n";
                $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
                $message = __('Dear Admin,', APP_TD) . "\r\n\r\n";
                $message .= sprintf(__('The following payment has been marked as refunded on your %s website.', APP_TD), $blogname) . "\r\n\r\n";
                $message .= __('Payment Details', APP_TD) . "\r\n";
                $message .= __('-----------------', APP_TD) . "\r\n";
                $message .= __('Payer PayPal address: ', APP_TD) . $_POST['payer_email'] . "\r\n";
                $message .= __('Transaction ID: ', APP_TD) . $_POST['txn_id'] . "\r\n";
                $message .= __('Payer first name: ', APP_TD) . $_POST['first_name'] . "\r\n";
                $message .= __('Payer last name: ', APP_TD) . $_POST['last_name'] . "\r\n";
                $message .= __('Payment type: ', APP_TD) . $_POST['payment_type'] . "\r\n";
                $message .= __('Reason code: ', APP_TD) . $_POST['reason_code'] . "\r\n";
                $message .= __('Amount: ', APP_TD) . html_entity_decode(cp_display_price($_POST['mc_gross'], $_POST['mc_currency'], false), ENT_QUOTES, 'UTF-8') . "\r\n\r\n";
                $message .= __('Full Details', APP_TD) . "\r\n";
                $message .= __('-----------------', APP_TD) . "\r\n";
                $message .= print_r($request_data, true) . "\r\n";
                wp_mail($mailto, $subject, $message, $headers);
                break;
        }
        // regardless of what happens, log the transaction
        if (file_exists(TEMPLATEPATH . '/includes/gateways/process.php')) {
            include_once TEMPLATEPATH . '/includes/gateways/process.php';
        }
    }
}
コード例 #6
0
/**
 * Processes membership activation on order activation.
 *
 * @param object $order
 */
function cp_payments_handle_membership_activated($order)
{
    // include all the functions needed for this action
    require_once get_template_directory() . '/includes/forms/step-functions.php';
    foreach ($order->get_items(CP_ITEM_MEMBERSHIP) as $item) {
        $user = get_user_by('id', $order->get_author());
        $membership_orders = get_user_orders($user->ID, false);
        if (empty($membership_orders)) {
            continue;
        }
        $order_id = get_order_id($membership_orders[0]);
        $stored_order = get_option($membership_orders[0]);
        $order_processed = appthemes_process_membership_order($user, $stored_order);
        if ($order_processed) {
            cp_owner_activated_membership_email($user, $order_processed);
        }
    }
}
コード例 #7
0
function cp_transactions()
{
    global $wpdb;
    // check to prevent php "notice: undefined index" msg when php strict warnings is on
    if (isset($_GET['action'])) {
        $theswitch = $_GET['action'];
    } else {
        $theswitch = '';
    }
    switch ($theswitch) {
        // mark transaction as paid
        case 'setPaid':
            $update = "UPDATE " . $wpdb->prefix . "cp_order_info SET payment_status = 'Completed' WHERE id = '" . $_GET['id'] . "'";
            $wpdb->query($update);
            ?>
        <p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
            _e('Updating transaction entry.....', 'appthemes');
            ?>
<br /><br /><img src="<?php 
            echo bloginfo('template_directory');
            ?>
/images/loader.gif" alt="" /></p>
        <meta http-equiv="refresh" content="0; URL=?page=transactions">

    <?php 
            break;
            // mark transaction as unpaid
        // mark transaction as unpaid
        case 'unsetPaid':
            $update = "UPDATE " . $wpdb->prefix . "cp_order_info SET payment_status = 'Pending' WHERE id = '" . $_GET['id'] . "'";
            $wpdb->query($update);
            ?>
        <p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
            _e('Updating transaction entry.....', 'appthemes');
            ?>
<br /><br /><img src="<?php 
            echo bloginfo('template_directory');
            ?>
/images/loader.gif" alt="" /></p>
        <meta http-equiv="refresh" content="0; URL=?page=transactions">

    <?php 
            break;
            // delete transaction entry
        // delete transaction entry
        case 'delete':
            $delete = "DELETE FROM " . $wpdb->prefix . "cp_order_info WHERE id = '" . $_GET['id'] . "'";
            $wpdb->query($delete);
            ?>
        <p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
            _e('Deleting transaction entry.....', 'appthemes');
            ?>
<br /><br /><img src="<?php 
            echo bloginfo('template_directory');
            ?>
/images/loader.gif" alt="" /></p>
        <meta http-equiv="refresh" content="0; URL=?page=transactions">

    <?php 
            break;
            // activate membership, update transaction entry
        // activate membership, update transaction entry
        case 'activateMembership':
            include_once TEMPLATEPATH . '/includes/forms/step-functions.php';
            $orders = get_user_orders('', $_GET['oid']);
            if (!empty($orders)) {
                $order_id = get_order_id($orders);
                $storedOrder = get_option($orders);
                $user_id = get_order_userid($orders);
                $the_user = get_userdata($user_id);
                //activate membership
                $order_processed = appthemes_process_membership_order($the_user, $storedOrder);
                //send email to user
                if ($order_processed) {
                    cp_owner_activated_membership_email($the_user, $order_processed);
                }
                //update transaction entry
                $update = "UPDATE " . $wpdb->prefix . "cp_order_info SET payment_status = 'Completed' WHERE custom = '" . $_GET['oid'] . "'";
                $wpdb->query($update);
            }
            ?>
        <p style="text-align:center;padding-top:50px;font-size:22px;"><?php 
            _e('Activating membership plan.....', 'appthemes');
            ?>
<br /><br /><img src="<?php 
            echo bloginfo('template_directory');
            ?>
/images/loader.gif" alt="" /></p>
        <meta http-equiv="refresh" content="0; URL=?page=transactions">

    <?php 
            break;
            // show the table of all transactions
        // show the table of all transactions
        default:
            ?>
    <div class="wrap">
        <div class="icon32" id="icon-themes"><br /></div>
        <h2><?php 
            _e('Order Transactions', 'appthemes');
            ?>
</h2>

        <?php 
            cp_admin_info_box();
            ?>

        <table id="tblspacer" class="widefat fixed">

            <thead>
                <tr>
                    <th scope="col" style="width:35px;">&nbsp;</th>
                    <th scope="col"><?php 
            _e('Payer Name', 'appthemes');
            ?>
</th>
                    <th scope="col" style="text-align: center;"><?php 
            _e('Payer Status', 'appthemes');
            ?>
</th>
                    <th scope="col"><?php 
            _e('Ad Title', 'appthemes');
            ?>
</th>
                    <th scope="col"><?php 
            _e('Item Description', 'appthemes');
            ?>
</th>
                    <th scope="col" style="width:125px;"><?php 
            _e('Transaction ID', 'appthemes');
            ?>
</th>
                    <th scope="col"><?php 
            _e('Payment Type', 'appthemes');
            ?>
</th>
                    <th scope="col"><?php 
            _e('Payment Status', 'appthemes');
            ?>
</th>
                    <th scope="col"><?php 
            _e('Total Amount', 'appthemes');
            ?>
</th>
                    <th scope="col" style="width:150px;"><?php 
            _e('Date Paid', 'appthemes');
            ?>
</th>
                    <th scope="col" style="text-align:center;width:100px;"><?php 
            _e('Actions', 'appthemes');
            ?>
</th>
                </tr>
            </thead>

    <?php 
            // must be higher than personal edition so let's query the db
            $sql = "SELECT o.*, p.post_title " . "FROM " . $wpdb->prefix . "cp_order_info o, {$wpdb->posts} p " . "WHERE o.ad_id = p.id " . "ORDER BY o.id desc";
            $results = $wpdb->get_results($sql);
            if ($results) {
                $rowclass = '';
                $i = 1;
                ?>

              <tbody id="list">

            <?php 
                foreach ($results as $result) {
                    $rowclass = 'even' == $rowclass ? 'alt' : 'even';
                    ?>

                <tr class="<?php 
                    echo $rowclass;
                    ?>
">
                    <td style="padding-left:10px;"><?php 
                    echo $i;
                    ?>
.</td>

                    <td><strong><?php 
                    echo $result->first_name;
                    ?>
 <?php 
                    echo $result->last_name;
                    ?>
</strong><br /><a href="mailto:<?php 
                    echo $result->payer_email;
                    ?>
"><?php 
                    echo $result->payer_email;
                    ?>
</a></td>
                    <td style="text-align: center;">
                        <?php 
                    if ($result->payer_status == 'verified') {
                        ?>
<img src="<?php 
                        bloginfo('template_directory');
                        ?>
/images/paypal_verified.gif" alt="" title="" /><br /><?php 
                    }
                    ?>
                        <?php 
                    echo ucfirst($result->payer_status);
                    ?>
                    </td>
                    <td><a href="post.php?action=edit&post=<?php 
                    echo $result->ad_id;
                    ?>
"><?php 
                    echo $result->post_title;
                    ?>
</a></td>
                    <td><?php 
                    echo $result->item_name;
                    ?>
</td>
                    <td><?php 
                    echo $result->txn_id;
                    ?>
</td>
                    <td><?php 
                    echo ucfirst($result->payment_type);
                    ?>
</td>
                    <td><?php 
                    echo ucfirst($result->payment_status);
                    ?>
</td>
                    <td><?php 
                    echo $result->mc_gross;
                    ?>
 <?php 
                    echo $result->mc_currency;
                    ?>
</td>
                    <td><?php 
                    echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $result->payment_date);
                    ?>
</td>
                    <td style="text-align:center">
                      <?php 
                    echo '<a onclick="return confirmBeforeDelete();" href="?page=transactions&amp;action=delete&amp;id=' . $result->id . '" title="' . __('Delete', 'appthemes') . '"><img src="' . get_bloginfo('template_directory') . '/images/cross.png" alt="' . __('Delete', 'appthemes') . '" /></a>&nbsp;&nbsp;&nbsp;';
                    if (strtolower($result->payment_status) == 'completed') {
                        echo '<br /><a href="?page=transactions&amp;action=unsetPaid&amp;id=' . $result->id . '" title="' . __('Mark as Unpaid', 'appthemes') . '">' . __('Unmark Paid', 'appthemes') . '</a>';
                    } else {
                        echo '<br /><a href="?page=transactions&amp;action=setPaid&amp;id=' . $result->id . '" title="' . __('Mark as Paid', 'appthemes') . '">' . __('Mark Paid', 'appthemes') . '</a>';
                    }
                    ?>
                    </td>
                </tr>

              <?php 
                    $i++;
                }
                // end for each
                ?>

            </tbody>

        <?php 
            } else {
                ?>

            <tr>
                <td>&nbsp;</td><td colspan="10"><?php 
                _e('No transactions found.', 'appthemes');
                ?>
</td>
            </tr>

        <?php 
            }
            // end $results
            ?>

        </table> <!-- this is ok -->


        <div class="icon32" id="icon-themes"><br /></div>
        <h2><?php 
            _e('Membership Orders', 'appthemes');
            ?>
</h2>
        <table id="tblspacer" class="widefat fixed">

            <thead>
                <tr>
                    <th scope="col" style="width:35px;">&nbsp;</th>
                    <th scope="col"><?php 
            _e('Payer Name', 'appthemes');
            ?>
</th>
                    <th scope="col" style="text-align: center;"><?php 
            _e('Payer Status', 'appthemes');
            ?>
</th>
                    <th scope="col"><?php 
            _e('Item Description', 'appthemes');
            ?>
</th>
                    <th scope="col" style="width:125px;"><?php 
            _e('Transaction ID', 'appthemes');
            ?>
</th>
                    <th scope="col"><?php 
            _e('Payment Type', 'appthemes');
            ?>
</th>
                    <th scope="col"><?php 
            _e('Payment Status', 'appthemes');
            ?>
</th>
                    <th scope="col"><?php 
            _e('Total Amount', 'appthemes');
            ?>
</th>
                    <th scope="col" style="width:150px;"><?php 
            _e('Date Paid', 'appthemes');
            ?>
</th>
                    <th scope="col" style="text-align:center;width:100px;"><?php 
            _e('Actions', 'appthemes');
            ?>
</th>
                </tr>
            </thead>


		<?php 
            // seperate table for membership orders
            $sql = "SELECT * " . "FROM " . $wpdb->prefix . "cp_order_info " . "WHERE ad_id = 0 " . "ORDER BY id desc";
            $results = $wpdb->get_results($sql);
            if ($results) {
                $rowclass = '';
                $i = 1;
                ?>

              <tbody id="list">

            <?php 
                foreach ($results as $result) {
                    $rowclass = 'even' == $rowclass ? 'alt' : 'even';
                    ?>

                <tr class="<?php 
                    echo $rowclass;
                    ?>
">
                    <td style="padding-left:10px;"><?php 
                    echo $i;
                    ?>
.</td>
					<?php 
                    $payer = get_user_by('email', $result->payer_email);
                    ?>
                    <?php 
                    //TODO - LOOKUP CUSTOMER BY PAYPAL EMAIL CUSTOM PROFILE FIELD
                    ?>
                    <td><strong><?php 
                    echo $result->first_name;
                    ?>
 <?php 
                    echo $result->last_name;
                    ?>
</strong><br /><a href="<?php 
                    if (isset($payer->ID) && $payer) {
                        echo get_bloginfo('url') . '/wp-admin/user-edit.php?user_id=' . $payer->ID;
                    } else {
                        echo 'mailto:' . $result->payer_email;
                    }
                    ?>
"><?php 
                    echo $result->payer_email;
                    ?>
</a></td>
                    <td style="text-align: center;">
                        <?php 
                    if ($result->payer_status == 'verified') {
                        ?>
<img src="<?php 
                        bloginfo('template_directory');
                        ?>
/images/paypal_verified.gif" alt="" title="" /><br /><?php 
                    }
                    ?>
                        <?php 
                    echo ucfirst($result->payer_status);
                    ?>
                    </td>
                    <td><?php 
                    echo $result->item_name;
                    ?>
</td>
                    <td><?php 
                    echo $result->txn_id;
                    ?>
</td>
                    <td><?php 
                    echo ucfirst($result->payment_type);
                    ?>
</td>
                    <td><?php 
                    echo ucfirst($result->payment_status);
                    ?>
</td>
                    <td><?php 
                    echo $result->mc_gross;
                    ?>
 <?php 
                    echo $result->mc_currency;
                    ?>
</td>
                    <td><?php 
                    echo mysql2date(get_option('date_format') . ' ' . get_option('time_format'), $result->payment_date);
                    ?>
</td>
                    <td style="text-align:center">
                      <?php 
                    echo '<a onclick="return confirmBeforeDelete();" href="?page=transactions&amp;action=delete&amp;id=' . $result->id . '" title="' . __('Delete', 'appthemes') . '"><img src="' . get_bloginfo('template_directory') . '/images/cross.png" alt="' . __('Delete', 'appthemes') . '" /></a>&nbsp;&nbsp;&nbsp;';
                    if (strtolower($result->payment_status) == 'completed') {
                        echo '<br /><a href="?page=transactions&amp;action=unsetPaid&amp;id=' . $result->id . '" title="' . __('Mark as Unpaid', 'appthemes') . '">' . __('Unmark Paid', 'appthemes') . '</a>';
                    } else {
                        echo '<br /><a href="?page=transactions&amp;action=setPaid&amp;id=' . $result->id . '" title="' . __('Mark as Paid', 'appthemes') . '">' . __('Mark Paid', 'appthemes') . '</a>';
                    }
                    ?>
                    </td>
                </tr>

              <?php 
                    $i++;
                }
                // end for each
                ?>

              </tbody>

            <?php 
            } else {
                ?>

                <tr>
                    <td>&nbsp;</td><td colspan="9"><?php 
                _e('No transactions found.', 'appthemes');
                ?>
</td>
                </tr>

            <?php 
            }
            // end $results
            ?>

            </table> <!-- this is ok -->


        </div><!-- end wrap -->

    <?php 
    }
    // endswitch
    ?>



    <script type="text/javascript">
        /* <![CDATA[ */
            function confirmBeforeDelete() { return confirm("<?php 
    _e('WARNING: Are you sure you want to delete this transaction entry?? (This cannot be undone)', 'appthemes');
    ?>
"); }
        /* ]]> */
    </script>

<?php 
}