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; }
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'); ?> </p>
function single_free_button($pricing, $subscription, $user_id, $norepeat = false) { global $M_options; if (empty($M_options['paymentcurrency'])) { $M_options['paymentcurrency'] = 'USD'; } $form = ''; $coupon = membership_get_current_coupon(); $form .= '<form action="' . M_get_returnurl_permalink() . '" method="post" id="signup-form">'; $form .= wp_nonce_field('free-sub_' . $subscription->sub_id(), "_wpnonce", true, false); $form .= "<input type='hidden' name='gateway' value='" . $this->gateway . "' id='subscription_gateway' />"; $form .= '<input type="hidden" name="action" value="subscriptionsignup" />'; $form .= '<input type="hidden" name="custom" value="' . $this->build_custom($user_id, $subscription->id, '0') . '">'; $form .= '<input type="hidden" name="subscription" id="subscription_id" value="' . $subscription->id . '" />'; $form .= '<input type="hidden" name="user" id="subscription_user_id" value="' . $user_id . '" />'; $button = get_option($this->gateway . "_payment_button", ''); if (empty($button)) { $form .= '<input type="submit" class="button ' . apply_filters('membership_subscription_button_color', '') . '" value="' . __('Sign Up', 'membership') . '" />'; } else { $form .= '<input type="image" name="submit" border="0" src="' . $button . '" alt="PayPal - The safer, easier way to pay online">'; } $form .= '<input type="hidden" name="coupon_code" id="subscription_coupon_code" value="' . (!empty($coupon) ? $coupon->get_coupon_code() : '') . '" />'; $form .= '</form>'; return $form; }
<div id='membership-wrapper'> <div class="alert"> <?php echo __('You have already a subscription'); ?> </div> <a class="logoutbutton" href="<?php echo wp_logout_url(); ?> " title="Logout">Logout</a> </div> <?php } else { $sub = new M_Subscription($subscription); // Get the coupon $coupon = membership_get_current_coupon(); // Build the pricing array $pricing = $sub->get_pricingarray(); if (!empty($pricing) && !empty($coupon) && method_exists($coupon, 'valid_for_subscription') && $coupon->valid_for_subscription($sub->id)) { $pricing = $coupon->apply_coupon_pricing($pricing); } ?> <style type="text/css"> .pricescolumn { float: left; width: 100%; } .radio-outerbox { margin: 0 auto; width: 80%; }
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; }
/** * Purchase button * * @see http://plugins.trac.wordpress.org/browser/membership/tags/3.4.4.1/membershipincludes/includes/payment.form.php#L78 * * @param M_Subscription $subscription * @see http://plugins.trac.wordpress.org/browser/membership/tags/3.4.4.1/membershipincludes/classes/class.subscription.php * * @param array $pricing * @see http://plugins.trac.wordpress.org/browser/membership/tags/3.4.4.1/membershipincludes/classes/class.subscription.php#L110 * * array( * array( * 'period' => '1', * 'amount' => '50.00', * 'type' => 'indefinite', * 'unit' => 'm' * ) * ) * * @param int $user_id WordPress user/member ID */ public function purchase_button($subscription, $pricing, $user_id) { if (Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_Membership::is_pricing_free($pricing)) { // @todo what todo? return; } else { $membership = Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_Membership::get_membership($user_id); $config_id = get_option(Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_Extension::OPTION_CONFIG_ID); $data = new Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_PaymentData($subscription, $membership); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); $gateway->set_payment_method($this->payment_method); if ($gateway) { // @see http://plugins.trac.wordpress.org/browser/membership/tags/3.4.4.1/membershipincludes/classes/membershipadmin.php#K2908 if ('new' === strtolower(Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_Membership::get_option('formtype'))) { $action = add_query_arg(array('action' => 'buynow', 'subscription' => $data->get_subscription_id()), admin_url('admin-ajax.php')); } else { $action = '#pronamic-pay-form'; } printf('<form id="pronamic-pay-form" method="post" action="%s">', $action); printf('<img src="%s" alt="%s" />', esc_attr(plugins_url('images/ideal-logo-pay-off-2-lines.png', Pronamic_WP_Pay_Plugin::$file)), esc_attr__('iDEAL - Online payment through your own bank', 'pronamic_ideal')); echo '<div style="margin-top: 1em;">'; echo $gateway->get_input_html(); // Data $fields = array('subscription_id' => $data->get_subscription_id(), 'user_id' => $user_id); // Coupon if (function_exists('membership_get_current_coupon')) { $coupon = membership_get_current_coupon(); if ($coupon) { $fields['coupon_code'] = $coupon->get_coupon_code(); } } echo Pronamic_IDeal_IDeal::htmlHiddenFields($fields); // Submit button printf('<input type="submit" name="pronamic_pay_membership_%s" value="%s" />', esc_attr($this->gateway), esc_attr__('Pay', 'pronamic_ideal')); echo '</div>'; if (isset($this->error) && is_wp_error($this->error)) { foreach ($this->error->get_error_messages() as $message) { echo $message, '<br />'; } } printf('</form>'); } } }
/** * 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; }