示例#1
0
            if ($pricing) {
                do_action('membership_purchase_button', $sub, $pricing, $member->ID);
            }
            ?>
									</td>
								</tr>
							<?php 
        }
        ?>
			</table>
		</div>

	<?php 
    } else {
        $sub = new M_Subscription($subscription);
        $pricing = $sub->get_pricingarray();
        $coupon_code = membership_get_current_coupon();
        if (!empty($pricing) && !empty($coupon_code)) {
            $pricing = $sub->apply_coupon_pricing($coupon_code, $pricing);
        }
        ?>
		<div class='header' style='width: 750px'>
		<h1><?php 
        echo __('Sign up for', 'membership') . " " . $sub->sub_name();
        ?>
</h1>
		</div>
		<div class='fullwidth'>
			<p><?php 
        echo __('Please check the details of your subscription below and click on the relevant button to complete the subscription.', 'membership');
        ?>
    ?>
'>
					<div class="topbar"><span class='title'><?php 
    echo $subscription->sub_name();
    ?>
</span></div>
					<div class="pricedetails"><?php 
    echo $subscription->sub_description();
    ?>
</div>
					<div class="bottombar"><span class='price'><?php 
    echo $subscription->sub_pricetext();
    ?>
</span>
					<?php 
    $pricing = $subscription->get_pricingarray();
    if ($pricing) {
        ?>
							<span class='link'>
								<?php 
        if (isset($M_options['formtype']) && $M_options['formtype'] == 'new') {
            // pop up form
            $link = admin_url('admin-ajax.php');
            $link .= '?action=buynow&amp;subscription=' . (int) $sub->id;
            $class = 'popover';
        } else {
            // original form
            $link = '?action=registeruser&amp;subscription=' . (int) $sub->id;
            $class = '';
        }
        if (empty($linktext)) {
        function handle_profile_member_page()
        {
            ?>
			<div class='wrap'>
				<div class="icon32" id="icon-users"><br></div>
				<h2><?php 
            _e('Membership details', 'membership');
            ?>
</h2>

				<?php 
            if (isset($_GET['msg'])) {
                echo '<div id="message" class="updated fade"><p>' . $messages[(int) $_GET['msg']] . '</p></div>';
                $_SERVER['REQUEST_URI'] = remove_query_arg(array('message'), $_SERVER['REQUEST_URI']);
            }
            if (!current_user_is_member()) {
                // Not a member so show the message and signup forms
                ?>
						<div class='nonmembermessage'>
						<h3><?php 
                _e('Not called yet', 'membership');
                ?>
</h3>
						<?php 
                _e('Not called yet', 'membership');
                ?>
						</div>
						<div class='signups'>
						<h3><?php 
                _e('Select a subscription', 'membership');
                ?>
</h3>
						<p>
							<?php 
                _e('Please select a subscription from the options below.', 'membership');
                ?>
						</p>
						<?php 
                do_action('membership_subscription_form_before_subscriptions', $user_id);
                $subs = $this->get_subscriptions();
                do_action('membership_subscription_form_before_paid_subscriptions', $user_id);
                foreach ((array) $subs as $key => $sub) {
                    $subscription = new M_Subscription($sub->id);
                    ?>
								<div class="subscription">
									<div class="description">
										<h3><?php 
                    echo $subscription->sub_name();
                    ?>
</h3>
										<p><?php 
                    echo $subscription->sub_description();
                    ?>
</p>
									</div>

								<?php 
                    $pricing = $subscription->get_pricingarray();
                    if ($pricing) {
                        ?>
										<div class='priceforms'>
											<?php 
                        do_action('membership_purchase_button', $subscription, $pricing, $user_id);
                        ?>
										</div>
										<?php 
                    }
                    ?>
								</div>
								<?php 
                }
                do_action('membership_subscription_form_after_paid_subscriptions', $user_id);
                do_action('membership_subscription_form_after_subscriptions', $user_id);
                ?>
						</div>
					<?php 
            } else {
                if (current_user_has_subscription()) {
                    // User has a subscription already. Display the details - and an action to enable upgrading / not upgrading to take place.
                    ?>
							<div class='nonmembermessage'>
							<h3><?php 
                    _e('Not called yet', 'membership');
                    ?>
</h3>
							<?php 
                    _e('Not called yet', 'membership');
                    ?>
							</div>
						<?php 
                }
            }
            ?>
			</div> <!-- wrap -->
			<?php 
        }
 function handle_payment_return()
 {
     global $M_options, $M_membership_url;
     $return = array();
     if ($_SERVER['HTTPS'] != 'on') {
         wp_die(__('You must use HTTPS in order to do this', 'membership'));
         exit;
     }
     $coupon_code = isset($_REQUEST['remove_coupon']) ? '' : $_REQUEST['coupon_code'];
     if (empty($M_options['paymentcurrency'])) {
         $M_options['paymentcurrency'] = 'USD';
     }
     $subscription = new M_Subscription($_POST['subscription_id']);
     $pricing = $subscription->get_pricingarray();
     if (!empty($coupon_code)) {
         $pricing = $subscription->apply_coupon_pricing($coupon_code, $pricing);
     }
     $user_id = is_user_logged_in() ? get_current_user_id() : $_POST['user_id'];
     $user = get_userdata($user_id);
     $sub_id = $subscription->id;
     // A basic price or a single subscription
     if ($pricing) {
         $timestamp = time();
         if (get_option($this->gateway . "_mode", 'sandbox') == 'sandbox') {
             $endpoint = "https://test.authorize.net/gateway/transact.dll";
         } else {
             $endpoint = "https://secure.authorize.net/gateway/transact.dll";
         }
         $payment = new M_Gateway_Worker_AuthorizeNet_AIM($endpoint, get_option($this->gateway . "_delim_data", 'yes'), get_option($this->gateway . "_delim_char", ','), get_option($this->gateway . "_encap_char", ''), get_option($this->gateway . "_api_user", ''), get_option($this->gateway . "_api_key", ''), get_option($this->gateway . "_mode", 'sandbox') == 'sandbox');
         $payment->transaction($_POST['card_num']);
         $amount = number_format($pricing[0]['amount'], 2);
         // Billing Info
         $payment->setParameter("x_card_code", $_POST['card_code']);
         $payment->setParameter("x_exp_date ", $_POST['exp_month'] . $_POST['exp_year']);
         $payment->setParameter("x_amount", $amount);
         // Payment billing information passed to authorize, thanks to Kevin L. for spotting this.
         $payment->setParameter("x_first_name", $_POST['first_name']);
         $payment->setParameter("x_last_name", $_POST['last_name']);
         $payment->setParameter("x_address", $_POST['address']);
         $payment->setParameter("x_zip", $_POST['zip']);
         $payment->setParameter("x_email", is_email($user->user_email) != false ? is_email($user->user_email) : '');
         // Order Info
         $payment->setParameter("x_description", $subscription->sub_name());
         $payment->setParameter("x_duplicate_window", 30);
         // E-mail
         $payment->setParameter("x_header_email_receipt", get_option($this->gateway . "_header_email_receipt", ''));
         $payment->setParameter("x_footer_email_receipt", get_option($this->gateway . "_footer_email_receipt", ''));
         $payment->setParameter("x_email_customer", strtoupper(get_option($this->gateway . "_email_customer", '')));
         $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']);
         $payment->process();
         if ($payment->isApproved()) {
             $status = __('Processed', 'membership');
             $note = '';
             $member = new M_Membership($user_id);
             if ($member) {
                 if ($member->has_subscription() && $member->on_sub($sub_id)) {
                     remove_action('membership_expire_subscription', 'membership_record_user_expire', 10, 2);
                     remove_action('membership_add_subscription', 'membership_record_user_subscribe', 10, 4);
                     $member->expire_subscription($sub_id);
                     $member->create_subscription($sub_id, $this->gateway);
                 } else {
                     $member->create_subscription($sub_id, $this->gateway);
                 }
             }
             // TODO: create switch for handling different authorize aim respone codes
             $this->record_transaction($user_id, $sub_id, $amount, $M_options['paymentcurrency'], time(), $payment->results[6] == 0 ? 'TESTMODE' : $payment->results[6], $status, $note);
             do_action('membership_payment_subscr_signup', $user_id, $sub_id);
             $return['status'] = 'success';
             $return['redirect'] = !strpos(home_url, 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
         } else {
             $return['status'] = 'error';
             $return['errors'][] = __('Your payment was declined.  Please check all your details or use a different card.', 'membership');
         }
     } else {
         $return['status'] = 'error';
         $return['errors'][] = __('There was an issue determining the price.', 'membership');
     }
     echo json_encode($return);
     exit;
 }