Beispiel #1
0
 /**
  * Update lead status of the specified payment
  *
  * @param Pronamic_Pay_Payment $payment
  */
 public static function status_update(Pronamic_Pay_Payment $payment, $can_redirect = false)
 {
     $status = $payment->get_status();
     $url = M_get_returnurl_permalink();
     switch ($status) {
         case Pronamic_WP_Pay_Statuses::SUCCESS:
             $url = M_get_registrationcompleted_permalink();
             break;
     }
     if ($url && $can_redirect) {
         wp_redirect($url, 303);
         exit;
     }
 }
 function process_payment_form()
 {
     global $M_options, $M_membership_url;
     $return = array();
     if (!is_ssl()) {
         wp_die(__('You must use HTTPS in order to do this', 'membership'));
         exit;
     }
     $popup = isset($M_options['formtype']) && $M_options['formtype'] == 'new' ? true : false;
     $coupon = membership_get_current_coupon();
     if (empty($M_options['paymentcurrency'])) {
         $M_options['paymentcurrency'] = 'USD';
     }
     $factory = Membership_Plugin::factory();
     $subscription = $factory->get_subscription($_POST['subscription_id']);
     $pricing = $subscription->get_pricingarray();
     if (!empty($pricing) && !empty($coupon) && method_exists($coupon, 'valid_for_subscription') && $coupon->valid_for_subscription($subscription->id)) {
         $pricing = $coupon->apply_coupon_pricing($pricing);
     }
     $user_id = is_user_logged_in() ? get_current_user_id() : $_POST['user_id'];
     $user = get_userdata($user_id);
     $sub_id = $subscription->id;
     if (!empty($pricing)) {
         $free = true;
         foreach ($pricing as $key => $price) {
             if (!empty($price['amount']) && $price['amount'] > 0) {
                 $free = false;
             }
         }
         if (!$free) {
             if (count($pricing) == 1) {
                 // A basic price or a single subscription
                 if (in_array($pricing[0]['type'], array('indefinite', 'finite'))) {
                     // one-off payment - so we just use AIM instead
                     $return = $this->process_aim_payment($pricing[0]['amount'], $user, $subscription);
                     if (!empty($return) && $return['status'] == 'success') {
                         // The payment went through ok
                         $member = $factory->get_member($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);
                             }
                         }
                         if ($popup && !empty($M_options['registrationcompleted_message'])) {
                             $return['redirect'] = 'no';
                             $registrationcompletedmessage = $this->get_completed_message($subscription);
                             $return['message'] = $registrationcompletedmessage;
                         } else {
                             $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                             $return['message'] = '';
                         }
                     } else {
                         // The payment didn't go through, so leave the return array holding the error
                     }
                     // Encode the return, echo it and exit so no more processing occurs
                     echo json_encode($return);
                     exit;
                 } elseif ($pricing[0]['type'] == 'serial') {
                     // Single serial subscription - we want to charge the first amount using AIM so we can validate the payment, then setup the subscription to start one period later
                     $return = $this->process_aim_payment($pricing[0]['amount'], $user, $subscription);
                     if (!empty($return) && $return['status'] == 'success') {
                         // The payment went through ok
                         $arbsubscription = new M_Gateway_Worker_AuthorizeNet_ARB(get_option($this->gateway . "_api_user", ''), get_option($this->gateway . "_api_key", ''), get_option($this->gateway . "_mode", 'sandbox') == 'sandbox');
                         $arbsubscription->setParameter('subscrName', $subscription->sub_name() . ' ' . __('subscription', 'membership'));
                         switch ($pricing[0]['unit']) {
                             case 'd':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                 $arbsubscription->setParameter('interval_unit', "days");
                                 $trialperiod = '+' . $pricing[0]['period'] . ' days';
                                 break;
                             case 'w':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 7);
                                 $arbsubscription->setParameter('interval_unit', "days");
                                 $trialperiod = '+' . $pricing[0]['period'] . ' weeks';
                                 break;
                             case 'm':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                 $arbsubscription->setParameter('interval_unit', "months");
                                 $trialperiod = '+' . $pricing[0]['period'] . ' months';
                                 break;
                             case 'y':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 12);
                                 $arbsubscription->setParameter('interval_unit', "months");
                                 $trialperiod = '+' . $pricing[0]['period'] . ' years';
                                 break;
                         }
                         // Add a period to the start date
                         $arbsubscription->setParameter('startDate', date("Y-m-d", strtotime($trialperiod)));
                         // Next period
                         $arbsubscription->setParameter('totalOccurrences', "9999");
                         // 9999 = ongoing subscription in ARB docs
                         $arbsubscription->setParameter('amount', number_format($pricing[0]['amount'], 2, '.', ''));
                         $arbsubscription->setParameter('cardNumber', $_POST['card_num']);
                         $arbsubscription->setParameter('expirationDate', $_POST['exp_year'] . '-' . $_POST['exp_month']);
                         $arbsubscription->setParameter('cardCode', $_POST['card_code']);
                         $arbsubscription->setParameter('firstName', $_POST['first_name']);
                         $arbsubscription->setParameter('lastName', $_POST['last_name']);
                         $arbsubscription->setParameter('address', $_POST['address']);
                         $arbsubscription->setParameter('zip', $_POST['zip']);
                         $arbsubscription->setParameter('customerId', $user->ID);
                         $arbsubscription->setParameter('customerEmail', is_email($user->user_email) != false ? $user->user_email : '');
                         $arbsubscription->createAccount();
                         if ($arbsubscription->isSuccessful()) {
                             // Get the subscription ID
                             $subscription_id = $arbsubscription->getSubscriberID();
                             $member = Membership_Plugin::factory()->get_member($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);
                                 }
                                 // Store the subscription id in the user meta for later use
                                 update_user_meta($member->ID, 'membership_' . $this->gateway . '_subscription_' . $sub_id, $subscription_id);
                             }
                             if ($popup && !empty($M_options['registrationcompleted_message'])) {
                                 $return['redirect'] = 'no';
                                 $registrationcompletedmessage = $this->get_completed_message($subscription);
                                 $return['message'] = $registrationcompletedmessage;
                             } else {
                                 $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                                 $return['message'] = '';
                             }
                         } else {
                             // The subscription was not created!
                             $return['status'] = 'error';
                             $return['errors'][] = __('Sorry, your subscription could not be created.', 'membership');
                         }
                     } else {
                         // The payment didn't go through so return the error passed through from the aim processing
                     }
                     // Encode the return, echo it and exit so no more processing occurs
                     echo json_encode($return);
                     exit;
                 }
             } else {
                 // something much more complex
                 $processsecond = true;
                 $arbsubscription = new M_Gateway_Worker_AuthorizeNet_ARB(get_option($this->gateway . "_api_user", ''), get_option($this->gateway . "_api_key", ''), get_option($this->gateway . "_mode", 'sandbox') == 'sandbox');
                 $arbsubscription->setParameter('subscrName', $subscription->sub_name() . ' ' . __('subscription', 'membership'));
                 switch ($pricing[0]['type']) {
                     case 'finite':
                         // This is the one we are expecting here as anything else would be silly
                         // Set the trial period up
                         switch ($pricing[0]['unit']) {
                             case 'd':
                                 $trialperiod = '+' . $pricing[0]['period'] . ' days';
                                 break;
                             case 'w':
                                 $trialperiod = '+' . $pricing[0]['period'] . ' weeks';
                                 break;
                             case 'm':
                                 $trialperiod = '+' . $pricing[0]['period'] . ' months';
                                 break;
                             case 'y':
                                 $trialperiod = '+' . $pricing[0]['period'] . ' years';
                                 break;
                         }
                         break;
                     case 'indefinite':
                         // Hmmm - ok
                         $processsecond = false;
                         $return = $this->process_aim_payment($pricing[0]['amount'], $user, $subscription);
                         if (!empty($return) && $return['status'] == 'success') {
                             // The payment went through ok
                             $member = Membership_Plugin::factory()->get_member($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);
                                 }
                             }
                             if ($popup && !empty($M_options['registrationcompleted_message'])) {
                                 $return['redirect'] = 'no';
                                 $registrationcompletedmessage = $this->get_completed_message($subscription);
                                 $return['message'] = $registrationcompletedmessage;
                             } else {
                                 $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                                 $return['message'] = '';
                             }
                         } else {
                             // The payment didn't go through, so leave the return array holding the error
                         }
                         // Encode the return, echo it and exit so no more processing occurs
                         echo json_encode($return);
                         exit;
                         break;
                     case 'serial':
                         // Hmmm - ok par deux
                         $processsecond = false;
                         $return = $this->process_aim_payment($pricing[0]['amount'], $user, $subscription);
                         if (!empty($return) && $return['status'] == 'success') {
                             // The payment went through ok
                             $arbsubscription = new M_Gateway_Worker_AuthorizeNet_ARB(get_option($this->gateway . "_api_user", ''), get_option($this->gateway . "_api_key", ''), get_option($this->gateway . "_mode", 'sandbox') == 'sandbox');
                             $arbsubscription->setParameter('subscrName', $subscription->sub_name() . ' ' . __('subscription', 'membership'));
                             switch ($pricing[0]['unit']) {
                                 case 'd':
                                     $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                     $arbsubscription->setParameter('interval_unit', "days");
                                     break;
                                 case 'w':
                                     $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 7);
                                     $arbsubscription->setParameter('interval_unit', "days");
                                     break;
                                 case 'm':
                                     $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                     $arbsubscription->setParameter('interval_unit', "months");
                                     break;
                                 case 'y':
                                     $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 12);
                                     $arbsubscription->setParameter('interval_unit', "months");
                                     break;
                             }
                             // Add a period to the start date
                             $arbsubscription->setParameter('startDate', date("Y-m-d", strtotime('+' . $arbsubscription->intervalLength . ' ' . $arbsubscription->intervalUnit)));
                             // Next period
                             $arbsubscription->setParameter('totalOccurrences', "9999");
                             // 9999 = ongoing subscription in ARB docs
                             $arbsubscription->setParameter('amount', number_format($pricing[0]['amount'], 2, '.', ''));
                             $arbsubscription->setParameter('cardNumber', $_POST['card_num']);
                             $arbsubscription->setParameter('expirationDate', $_POST['exp_year'] . '-' . $_POST['exp_month']);
                             $arbsubscription->setParameter('cardCode', $_POST['card_code']);
                             $arbsubscription->setParameter('firstName', $_POST['first_name']);
                             $arbsubscription->setParameter('lastName', $_POST['last_name']);
                             $arbsubscription->setParameter('address', $_POST['address']);
                             $arbsubscription->setParameter('zip', $_POST['zip']);
                             $arbsubscription->setParameter('customerId', $user->ID);
                             $arbsubscription->setParameter('customerEmail', is_email($user->user_email) != false ? $user->user_email : '');
                             $arbsubscription->createAccount();
                             if ($arbsubscription->isSuccessful()) {
                                 // Get the subscription ID
                                 $subscription_id = $arbsubscription->getSubscriberID();
                                 $member = Membership_Plugin::factory()->get_member($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);
                                     }
                                     // Store the subscription id in the user meta for later use
                                     update_user_meta($member->ID, 'membership_' . $this->gateway . '_subscription_' . $sub_id, $subscription_id);
                                 }
                                 if ($popup && !empty($M_options['registrationcompleted_message'])) {
                                     $return['redirect'] = 'no';
                                     $registrationcompletedmessage = $this->get_completed_message($subscription);
                                     $return['message'] = $registrationcompletedmessage;
                                 } else {
                                     $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                                     $return['message'] = '';
                                 }
                             } else {
                                 // The subscription was not created!
                                 $return['status'] = 'error';
                                 $return['errors'][] = __('Sorry, your subscription could not be created.', 'membership');
                             }
                         } else {
                             // The payment didn't go through so return the error passed through from the aim processing
                         }
                         // Encode the return, echo it and exit so no more processing occurs
                         echo json_encode($return);
                         exit;
                         break;
                 }
                 if ($processsecond == true) {
                     // We had an initial finite period so we need to see if we need to charge for it initially
                     if ($pricing[0]['amount'] >= 1) {
                         // The first period is not free so we have to charge for it
                         $return = $this->process_aim_payment($pricing[0]['amount'], $user, $subscription);
                     } else {
                         $return = array();
                         $return['status'] = 'success';
                     }
                     if (!empty($return) && $return['status'] == 'success') {
                         // The payment went through ok
                         $arbsubscription = new M_Gateway_Worker_AuthorizeNet_ARB(get_option($this->gateway . "_api_user", ''), get_option($this->gateway . "_api_key", ''), get_option($this->gateway . "_mode", 'sandbox') == 'sandbox');
                         $arbsubscription->setParameter('subscrName', $subscription->sub_name() . ' ' . __('subscription', 'membership'));
                         switch ($pricing[0]['unit']) {
                             case 'd':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                 $arbsubscription->setParameter('interval_unit', "days");
                                 break;
                             case 'w':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 7);
                                 $arbsubscription->setParameter('interval_unit', "days");
                                 break;
                             case 'm':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                 $arbsubscription->setParameter('interval_unit', "months");
                                 break;
                             case 'y':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 12);
                                 $arbsubscription->setParameter('interval_unit', "months");
                                 break;
                         }
                         // Add a period to the start date
                         $arbsubscription->setParameter('startDate', date("Y-m-d", strtotime($trialperiod)));
                         // Next period
                         switch ($pricing[1]['type']) {
                             case 'finite':
                                 // For finite and indefinite we set up a subscription and only charge the once
                             // For finite and indefinite we set up a subscription and only charge the once
                             case 'indefinite':
                                 $arbsubscription->setParameter('totalOccurrences', "1");
                                 // 1 = a single future charge
                                 break;
                             case 'serial':
                                 // For serial we set up the subscription to keep being charged
                                 $arbsubscription->setParameter('totalOccurrences', "9999");
                                 // 9999 = ongoing subscription in ARB docs
                                 break;
                         }
                         $arbsubscription->setParameter('amount', number_format($pricing[1]['amount'], 2, '.', ''));
                         $arbsubscription->setParameter('cardNumber', $_POST['card_num']);
                         $arbsubscription->setParameter('expirationDate', $_POST['exp_year'] . '-' . $_POST['exp_month']);
                         $arbsubscription->setParameter('cardCode', $_POST['card_code']);
                         $arbsubscription->setParameter('firstName', $_POST['first_name']);
                         $arbsubscription->setParameter('lastName', $_POST['last_name']);
                         $arbsubscription->setParameter('address', $_POST['address']);
                         $arbsubscription->setParameter('zip', $_POST['zip']);
                         $arbsubscription->setParameter('customerId', $user->ID);
                         $arbsubscription->setParameter('customerEmail', is_email($user->user_email) != false ? $user->user_email : '');
                         $arbsubscription->createAccount();
                         if ($arbsubscription->isSuccessful()) {
                             // Get the subscription ID
                             $subscription_id = $arbsubscription->getSubscriberID();
                             $member = Membership_Plugin::factory()->get_member($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);
                                 }
                                 // Store the subscription id in the user meta for later use
                                 update_user_meta($member->ID, 'membership_' . $this->gateway . '_subscription_' . $sub_id, $subscription_id);
                             }
                             if ($popup && !empty($M_options['registrationcompleted_message'])) {
                                 $return['redirect'] = 'no';
                                 $registrationcompletedmessage = $this->get_completed_message($subscription);
                                 $return['message'] = $registrationcompletedmessage;
                             } else {
                                 $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                                 $return['message'] = '';
                             }
                         } else {
                             // The subscription was not created!
                             $return['status'] = 'error';
                             $return['errors'][] = __('Sorry, your subscription could not be created.', 'membership');
                         }
                     } else {
                         // The payment didn't go through so return the error passed through from the aim processing
                     }
                     // Encode the return, echo it and exit so no more processing occurs
                     echo json_encode($return);
                     exit;
                 }
             }
         }
     }
 }
 public function get_success_url()
 {
     if (Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_Extension::is_membership2()) {
         return esc_url_raw(add_query_arg(array('ms_relationship_id' => $this->subscription->id), MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_REG_COMPLETE, false)));
     }
     return M_get_registrationcompleted_permalink();
 }
 function popover_sendpayment_form($user_id = false)
 {
     global $M_options;
     $sub = $to_sub_id = false;
     $logged_in = is_user_logged_in();
     $subscription = isset($_REQUEST['subscription']) ? $_REQUEST['subscription'] : 0;
     // free subscription processing
     if ($logged_in && $subscription) {
         $sub = Membership_Plugin::factory()->get_subscription($subscription);
         if ($sub->is_free()) {
             $to_sub_id = $subscription;
         }
     }
     // coupon processing
     $coupon = filter_input(INPUT_POST, 'coupon_code');
     if ($logged_in && $coupon && $subscription) {
         $coupon = new M_Coupon($coupon);
         $coupon_obj = $coupon->get_coupon();
         if ($coupon->valid_coupon() && $coupon_obj->discount >= 100 && $coupon_obj->discount_type == 'pct') {
             $to_sub_id = $subscription;
             $coupon->increment_coupon_used();
         }
     }
     if ($to_sub_id) {
         $membership = Membership_Plugin::factory()->get_member(get_current_user_id());
         $membership->create_subscription($to_sub_id);
         if (!empty($M_options['registrationcompleted_message'])) {
             $html = '<div class="header"><h1>';
             $html .= sprintf(__('Subscription %s has been added.', 'membership'), $sub ? $sub->sub_name() : '');
             $html .= '</h1></div><div class="fullwidth">';
             $html .= stripslashes(wpautop($M_options['registrationcompleted_message']));
             $html .= '<a class="button button-primary ' . esc_attr(apply_filters('membership_subscription_button_color', '')) . '" href="' . M_get_account_permalink() . '">' . __('Go to your account', 'membership') . '</a>';
             $html .= '</div>';
             echo $html;
         } else {
             wp_send_json(array('redirect' => strpos(home_url(), 'https://') === 0 ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink()));
         }
         exit;
     }
     // render template
     ob_start();
     echo apply_filters('membership_popover_sendpayment_form_before_content', '');
     if (defined('MEMBERSHIP_POPOVER_SENDPAYMENT_FORM') && is_readable(MEMBERSHIP_POPOVER_SENDPAYMENT_FORM)) {
         include MEMBERSHIP_POPOVER_SENDPAYMENT_FORM;
     } else {
         $filename = apply_filters('membership_override_popover_sendpayment_form', membership_dir('membershipincludes/includes/popover_payment.form.php'));
         if (is_readable($filename)) {
             include $filename;
         }
     }
     echo apply_filters('membership_popover_sendpayment_form_after_content', ob_get_clean());
     exit;
 }
 function process_payment_form()
 {
     global $M_options, $M_membership_url;
     $return = array();
     if (!is_ssl()) {
         wp_die(__('You must use HTTPS in order to do this', 'membership'));
         exit;
     }
     $popup = isset($M_options['formtype']) && $M_options['formtype'] == 'new' ? true : false;
     $coupon = membership_get_current_coupon();
     if (empty($M_options['paymentcurrency'])) {
         $M_options['paymentcurrency'] = 'USD';
     }
     $subscription = Membership_Plugin::factory()->get_subscription($_POST['subscription_id']);
     $pricing = $subscription->get_pricingarray();
     if (!empty($pricing) && !empty($coupon) && method_exists($coupon, 'valid_for_subscription') && $coupon->valid_for_subscription($subscription->id)) {
         $pricing = $coupon->apply_coupon_pricing($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 = Membership_Plugin::factory()->get_member($user_id);
             if ($member) {
                 if ($member->has_subscription() && $member->on_sub($sub_id)) {
                     remove_action('membership_expire_subscription', 'membership_record_user_expire', 10, 3);
                     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';
             if ($popup && !empty($M_options['registrationcompleted_message'])) {
                 $return['redirect'] = 'no';
                 $registrationcompletedmessage = $this->get_completed_message($subscription);
                 $return['message'] = $registrationcompletedmessage;
             } else {
                 $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                 $return['message'] = '';
             }
         } 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;
 }
Beispiel #6
0
 public function get_success_url()
 {
     return M_get_registrationcompleted_permalink();
 }
 function handle_2checkout_return()
 {
     global $M_options;
     // Return handling code
     $timestamp = time();
     if (isset($_REQUEST['key'])) {
         $total = $_REQUEST['total'];
         $sub_id = false;
         $user_id = false;
         list($sub_id, $user_id) = explode(':', $_REQUEST['merchant_order_id']);
         if (esc_attr(get_option($this->gateway . "_twocheckout_status")) == 'test') {
             $hash = strtoupper(md5(esc_attr(get_option($this->gateway . "_twocheckout_secret_word")) . esc_attr(get_option($this->gateway . "_twocheckout_sid")) . $_REQUEST['order_number'] . $total));
         } else {
             $hash = strtoupper(md5(esc_attr(get_option($this->gateway . "_twocheckout_secret_word")) . esc_attr(get_option($this->gateway . "_twocheckout_sid")) . $_REQUEST['order_number'] . $total));
         }
         if ($sub_id && $user_id && $_REQUEST['key'] == $hash && $_REQUEST['credit_card_processed'] == 'Y') {
             $this->_record_transaction($user_id, $sub_id, $_REQUEST['total'], $_REQUEST['currency'], $timestamp, $_REQUEST['order_number'], 'Credit Card Verified', '');
             // Added for affiliate system link
             do_action('membership_payment_processed', $user_id, $sub_id, $_REQUEST['total'], $_REQUEST['currency'], $_REQUEST['order_number']);
             $member = Membership_Plugin::factory()->get_member($user_id);
             if ($member) {
                 $member->create_subscription($sub_id, $this->gateway);
                 membership_debug_log(sprintf(__('Order complete for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
             }
             do_action('membership_payment_subscr_signup', $user_id, $sub_id);
             if (!isset($M_options['registrationcompleted_page']) || 0 >= $M_options['registrationcompleted_page']) {
                 wp_redirect(get_option('home'));
             } else {
                 wp_redirect(M_get_registrationcompleted_permalink());
             }
             exit;
         }
     } else {
         if (isset($_REQUEST['message_type'])) {
             $md5_hash = strtoupper(md5("{$_REQUEST['sale_id']}" . esc_attr(get_option($this->gateway . "_twocheckout_sid")) . "{$_REQUEST['invoice_id']}" . esc_attr(get_option($this->gateway . "_twocheckout_secret_word"))));
             $sub_id = false;
             $user_id = false;
             //$product_id = $_REQUEST['item_id_1'];
             list($sub_id, $user_id, $from_sub_id) = explode(':', $_REQUEST['vendor_order_id']);
             if ($md5_hash == $_REQUEST['md5_hash']) {
                 switch ($_REQUEST['message_type']) {
                     case 'RECURRING_INSTALLMENT_SUCCESS':
                         if (!$this->_check_duplicate_transaction($user_id, $sub_id, $timestamp, $_POST['invoice_id'])) {
                             $this->_record_transaction($user_id, $sub_id, $_REQUEST['item_rec_list_amount_1'], $_REQUEST['list_currency'], $timestamp, $_POST['invoice_id'], 'Processed', '');
                             $member = Membership_Plugin::factory()->get_member($user_id);
                             if ($member) {
                                 remove_action('membership_expire_subscription', 'membership_record_user_expire', 10, 3);
                                 remove_action('membership_add_subscription', 'membership_record_user_subscribe', 10, 4);
                                 if ($from_sub_id) {
                                     $member->drop_subscription($from_sub_id);
                                 }
                                 $member->expire_subscription($sub_id);
                                 $member->create_subscription($sub_id, $this->gateway);
                                 membership_debug_log(sprintf(__('Recurring installment for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
                             }
                             // Added for affiliate system link
                             do_action('membership_payment_processed', $user_id, $sub_id, $_REQUEST['item_rec_list_amount_1'], $_REQUEST['list_currency'], $_POST['invoice_id']);
                         }
                         break;
                     case 'FRAUD_STATUS_CHANGED':
                     case 'INVOICE_STATUS_CHANGED':
                         // We don't really want to do anything here without pulling out more information
                         break;
                     case 'ORDER_CREATED':
                     case 'RECURRING_RESTARTED':
                         $transaction_amount = !empty($_REQUEST['item_rec_list_amount_1']) ? $_REQUEST['item_rec_list_amount_1'] : $_REQUEST['item_list_amount_1'];
                         $this->_record_transaction($user_id, $sub_id, $transaction_amount, $_REQUEST['list_currency'], $timestamp, $_POST['invoice_id'], 'Processed', '');
                         $member = Membership_Plugin::factory()->get_member($user_id);
                         if ($member) {
                             if ($from_sub_id) {
                                 $member->drop_subscription($from_sub_id);
                             }
                             $member->create_subscription($sub_id, $this->gateway);
                             membership_debug_log(sprintf(__('Recurring restarted for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
                         }
                         break;
                     case 'RECURRING_STOPPED':
                     case 'RECURRING_COMPLETE':
                     case 'RECURRING_INSTALLMENT_FAILED':
                     default:
                         $member = Membership_Plugin::factory()->get_member($user_id);
                         if ($member) {
                             $member->mark_for_expire($sub_id);
                             membership_debug_log(sprintf(__('Recurring failed for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
                         }
                         do_action('membership_payment_subscr_cancel', $user_id, $sub_id);
                         break;
                 }
             } else {
                 // MD5 Hash Failed
                 header('Status: 403 Forbidden');
                 echo 'Error: Unexpected Security Value. Verification is not possible.';
                 membership_debug_log('Error: Unexpected Security Value. Verification is not possible.');
                 exit;
             }
             echo "OK";
             membership_debug_log('OK');
             exit;
         } else {
             // Did not find expected POST variables. Possible access attempt from a non PayPal site.
             header('Status: 400 Bad Request');
             echo 'Error: Missing POST variables. Identification is not possible.';
             membership_debug_log('Error: Missing POST variables. Identification is not possible.');
             exit;
         }
     }
 }
 /**
  * Payment redirect URL filter.
  *
  * @param string                  $url
  * @param Pronamic_WP_Pay_Payment $payment
  * @return string
  */
 public static function redirect_url($url, $payment)
 {
     // @see https://github.com/wp-plugins/membership/blob/4.0.0.2/app/model/class-ms-model-pages.php#L492-L530
     if (Pronamic_WP_Pay_Class::method_exists('MS_Model_Pages', 'get_page_url')) {
         // @see https://github.com/wp-plugins/membership/blob/4.0.0.2/app/model/class-ms-model-pages.php#L44-L55
         $url = MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_REGISTER);
     } elseif (function_exists('M_get_returnurl_permalink')) {
         // @see https://github.com/wp-plugins/membership/blob/3.4.4.3/membershipincludes/includes/functions.php#L598-L622
         $url = M_get_returnurl_permalink();
     }
     switch ($payment->get_status()) {
         case Pronamic_WP_Pay_Statuses::SUCCESS:
             // @see https://github.com/wp-plugins/membership/blob/4.0.0.2/app/model/class-ms-model-pages.php#L492-L530
             if (Pronamic_WP_Pay_Class::method_exists('MS_Model_Pages', 'get_page_url')) {
                 $invoice_id = get_post_meta($payment->get_id(), '_pronamic_payment_membership_invoice_id', true);
                 $invoice = MS_Factory::load('MS_Model_Invoice', $invoice_id);
                 $subscription = $invoice->get_subscription();
                 // @see https://github.com/wp-plugins/membership/blob/4.0.0.2/app/model/class-ms-model-pages.php#L44-L55
                 $url = add_query_arg('ms_relationship_id', $subscription->id, MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_REG_COMPLETE));
             } elseif (function_exists('M_get_registrationcompleted_permalink')) {
                 // @see https://github.com/wp-plugins/membership/blob/3.4.4.3/membershipincludes/includes/functions.php#L576-L598
                 $url = M_get_registrationcompleted_permalink();
             }
             break;
     }
     return $url;
 }
Beispiel #9
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;
 }