Beispiel #1
0
 public function get_items()
 {
     $pricing_array = $this->subscription->get_pricingarray();
     // Coupon
     if (function_exists('membership_get_current_coupon')) {
         $coupon = membership_get_current_coupon();
         if (!empty($pricing_array) && !empty($coupon)) {
             $pricing_array = $coupon->apply_coupon_pricing($pricing_array);
         }
     }
     $items = new Pronamic_IDeal_Items();
     $item = new Pronamic_IDeal_Item();
     $item->setNumber($this->get_order_id());
     $item->setDescription($this->get_description());
     $item->setPrice($pricing_array[0]['amount']);
     $item->setQuantity(1);
     $items->addItem($item);
     return $items;
 }
 public function get_items()
 {
     if (Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_Extension::is_membership2()) {
         $invoice = $this->subscription->get_current_invoice();
         $pricing_array = array(array('amount' => $invoice->total));
     } else {
         $pricing_array = $this->subscription->get_pricingarray();
         // Coupon
         if (function_exists('membership_get_current_coupon')) {
             $coupon = membership_get_current_coupon();
             if (!empty($pricing_array) && !empty($coupon)) {
                 $pricing_array = $coupon->apply_coupon_pricing($pricing_array);
             }
         }
     }
     $items = new Pronamic_IDeal_Items();
     $item = new Pronamic_IDeal_Item();
     $item->setNumber($this->get_order_id());
     $item->setDescription($this->get_description());
     $item->setPrice($pricing_array[0]['amount']);
     $item->setQuantity(1);
     $items->addItem($item);
     return $items;
 }
Beispiel #3
0
    /**
     * Render buy subscription plan box.
     *
     * @since 3.5
     *
     * @access private
     * @global array $M_options The settings array.
     * @param Membership_Model_Subscription $subscription
     */
    private function _render_buy_subscription(Membership_Model_Subscription $subscription)
    {
        global $M_options;
        $pricing = $subscription->get_pricingarray();
        ?>
<div class="pricebox subscriptionbox" id="subscriptionbox-<?php 
        echo $subscription->id;
        ?>
">
			<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">
				<?php 
        if (!empty($pricing)) {
            ?>
					<div class="link" style="float:right;margin-right:10px">
						<?php 
            $class = '';
            if (isset($M_options['formtype']) && $M_options['formtype'] == 'new') {
                // pop up form
                $link = add_query_arg(array('action' => 'buynow', 'subscription' => $subscription->id), admin_url('admin-ajax.php'));
                $class = 'popover';
            } else {
                // original form
                $link = add_query_arg(array('action' => 'registeruser', 'subscription' => $subscription->id), get_permalink($M_options['registration_page']));
            }
            ?>
<a href="<?php 
            echo esc_url($link);
            ?>
" class="button button-primary <?php 
            echo $class;
            ?>
 <?php 
            echo esc_attr(apply_filters('membership_subscription_button_color', ''));
            ?>
">
						<?php 
            echo esc_html(apply_filters('membership_subscription_signup_text', __('Sign Up', 'membership')));
            ?>
						</a>
					</div>
				<?php 
        }
        ?>
				<span class="price"><?php 
        echo $subscription->sub_pricetext();
        ?>
</span>
			</div>
		</div><?php 
    }
Beispiel #4
0
 /**
  * Processes purchase action.
  *
  * @since  3.5
  * @action wp_ajax_nopriv_processpurchase_authorize
  * @action wp_ajax_processpurchase_authorize
  *
  * @access public
  */
 public function process_purchase()
 {
     global $M_options;
     if (empty($M_options['paymentcurrency'])) {
         $M_options['paymentcurrency'] = 'USD';
     }
     if (!is_ssl()) {
         wp_die(__('You must use HTTPS in order to do this', 'membership'));
         exit;
     }
     // fetch subscription and pricing
     $sub_id = filter_input(INPUT_POST, 'subscription_id', FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)));
     $this->_subscription = Membership_Plugin::factory()->get_subscription($sub_id);
     $pricing = $this->_subscription->get_pricingarray();
     if (!$pricing) {
         status_header(404);
         exit;
     }
     // apply a coupon
     $coupon = membership_get_current_coupon();
     if ($coupon && $coupon->valid_for_subscription($this->_subscription->id)) {
         $pricing = $coupon->apply_coupon_pricing($pricing);
     }
     // fetch member
     $user_id = is_user_logged_in() ? get_current_user_id() : $_POST['user_id'];
     $this->_member = Membership_Plugin::factory()->get_member($user_id);
     // fetch CIM user and payment profiles info
     // pay attention that CIM can't handle recurring transaction, so we need
     // to use standard ARB aproach and full cards details
     $has_serial = in_array('serial', wp_list_pluck($pricing, 'type'));
     if (!$has_serial) {
         $this->_cim_payment_profile_id = trim(filter_input(INPUT_POST, 'profile'));
         if (!empty($this->_cim_payment_profile_id)) {
             $this->_cim_profile_id = get_user_meta($this->_member->ID, 'authorize_cim_id', true);
             if ($this->_cim_profile_id) {
                 $response = $this->_get_cim()->getCustomerPaymentProfile($this->_cim_profile_id, $this->_cim_payment_profile_id);
                 if ($response->isError()) {
                     $this->_cim_payment_profile_id = false;
                 }
             }
         }
     }
     // process payments
     $first_payment = false;
     $started = new DateTime();
     $this->_payment_result = array('status' => '', 'errors' => array());
     $this->_transactions = array();
     for ($i = 0, $count = count($pricing); $i < $count; $i++) {
         if ($first_payment === false && $pricing[$i]['amount'] > 0) {
             $first_payment = $pricing[$i]['amount'];
         }
         switch ($pricing[$i]['type']) {
             case 'finite':
                 //Using AIM for onetime payment
                 $this->_transactions[] = $this->_process_nonserial_purchase($pricing[$i], $started);
                 /*//Call ARB with only one recurrency for each subscription level.
                 		$this->_transactions[] = $this->_process_serial_purchase( $pricing[$i], $started, 1, $unit = 'months', 12 );
                 		$interval              = self::_get_period_interval_in_date_format( $pricing[$i]['unit'] );
                 		$started->modify( sprintf( '+%d %s', $pricing[$i]['period'], $interval ) );*/
                 break;
             case 'indefinite':
                 $this->_transactions[] = $this->_process_nonserial_purchase($pricing[$i], $started);
                 break 2;
             case 'serial':
                 //Call ARB with no end date (an ongoing subscription).
                 $this->_transactions[] = $this->_process_serial_purchase($pricing[$i], $started, 9999);
                 break 2;
         }
         if ($this->_payment_result['status'] == 'error') {
             $this->_rollback_transactions();
             break;
         }
     }
     if ($this->_payment_result['status'] == 'success') {
         // create member subscription
         if ($this->_member->has_subscription()) {
             $from_sub_id = filter_input(INPUT_POST, 'from_subscription', FILTER_VALIDATE_INT, array('options' => array('min_range' => 1)));
             if ($this->_member->on_sub($from_sub_id)) {
                 $this->_member->drop_subscription($from_sub_id);
             }
             if ($this->_member->on_sub($sub_id)) {
                 $this->_member->drop_subscription($sub_id);
             }
         }
         $this->_member->create_subscription($sub_id, $this->gateway);
         // create CIM profile it is not exists, otherwise update it if new card was added
         $this->_cim_profile_id = get_user_meta($this->_member->ID, 'authorize_cim_id', true);
         if (!$this->_cim_profile_id) {
             $this->_create_cim_profile();
         } elseif (!$has_serial && empty($this->_cim_payment_profile_id)) {
             $this->_update_cim_profile();
         }
         // process transactions
         $this->_commit_transactions();
         if ($first_payment) {
             do_action('membership_authorizenet_payment_processed', $this->_member->ID, $sub_id);
             do_action('membership_payment_processed', $this->_member->ID, $sub_id, $first_payment, $M_options['paymentcurrency'], $this->_transactions[0]['transaction']);
         }
         // process response message and redirect
         if (self::is_popup() && !empty($M_options['registrationcompleted_message'])) {
             $html = '<div class="header" style="width: 750px"><h1>';
             $html .= sprintf(__('Sign up for %s completed', 'membership'), $this->_subscription->sub_name());
             $html .= '</h1></div><div class="fullwidth">';
             $html .= stripslashes(wpautop($M_options['registrationcompleted_message']));
             $html .= '</div>';
             $this->_payment_result['redirect'] = 'no';
             $this->_payment_result['message'] = $html;
         } else {
             $this->_payment_result['message'] = '';
             $this->_payment_result['redirect'] = strpos(home_url(), 'https://') === 0 ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
         }
     }
     echo json_encode($this->_payment_result);
     exit;
 }