Example #1
0
 function _pre_auth_complete($post_data)
 {
     // charge
     $gateway_method = 'xmlauthco';
     // txn
     $post_data['AuthTrxnNumber'] = $this->response['txn_no'];
     // txn_no,auth_code
     // end  point
     $endpoint = $this->_get_endpoint($this->status . '_' . $gateway_method);
     // live_xmlauth, live_xmlauthco etc.
     // filter post data for api
     $post_string = $this->_filter_postdata($gateway_method, $post_data);
     // headers
     $http_headers = $this->_get_http_headers($gateway_method);
     // log
     mgm_log('Request Headers [' . $gateway_method . ']' . mgm_pr($http_headers, true), __FUNCTION__);
     // log
     mgm_log('Request [' . $gateway_method . ']' . $post_string, __FUNCTION__);
     // create curl post
     $http_response = mgm_remote_post($endpoint, $post_string, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
     // log
     mgm_log('Response [' . $gateway_method . ']' . $http_response, __FUNCTION__);
     // parse response
     $this->_process_response($gateway_method, $http_response);
     // log
     mgm_log('Response Parsed [' . $gateway_method . ']' . mgm_pr($this->response, true), __FUNCTION__);
     // testing
     // $this->response['response_status'] = 1;
     // return
     if ($this->response['response_status'] == 1) {
         // track
         $this->response['preauth_complete'] = true;
         // return
         return true;
     }
     // return
     return false;
 }
 /**
  * Specifically check recurring status of each rebill for an expiry date
  * Along with IPN post mechanism for rebills, the module will need to specifically request for the rebill status
  * @param int $user_id
  * @param object $member
  * @return boolean
  * @deprecated as not supported by standard	 
  */
 function query_rebill_status($user_id, $member = NULL)
 {
     // check
     if ($this->setting['rebill_status_query'] == 'disabled') {
         return false;
     }
     // check
     if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) {
         // query data
         $query_data = array();
         // add internal vars
         $secure = array('clientAccnum' => $this->setting['client_acccnum'], 'clientSubacc' => $this->setting['client_subacc'], 'username' => $this->setting['datalink_username'], 'password' => $this->setting['datalink_password']);
         // merge
         $query_data = array_merge($query_data, $secure);
         // overwrite post data array with secure params
         // method
         $query_data['action'] = 'viewSubscriptionStatus';
         $query_data['subscriptionId'] = $member->payment_info->subscr_id;
         // xml response
         $query_data['returnXML'] = 1;
         // post string
         $query_string = _http_build_query($query_data, null, '&');
         // endpoint
         $endpoint = $this->_get_endpoint('datalink_sms');
         // url
         $url = $endpoint . '?' . $query_string;
         // remote get
         $http_response = mgm_remote_get($url, null, null, false);
         // log
         mgm_log($http_response, $this->module . '_' . __FUNCTION__);
         // subs data
         $subsdata = array('subscriptionStatus' => 'Error');
         // xml
         if ($xml = @simplexml_load_string($http_response)) {
             // check
             if (isset($xml->subscriptionStatus)) {
                 // get status
                 switch ((int) $xml->subscriptionStatus) {
                     case 0:
                         // inactive
                         //$subsdata['subscriptionStatus'] = 'Pending';
                         //consider expired - got confirmation from ccbill team
                         $subsdata['subscriptionStatus'] = 'Expired';
                         if ($expirationDate = (string) $xml->expirationDate) {
                             $subsdata['expirationDate'] = strlen($expirationDate) > 8 ? substr($expirationDate, 0, 8) : $expirationDate;
                         }
                         break;
                     case 1:
                         // cancelled
                         $subsdata['subscriptionStatus'] = 'Cancelled';
                         if ($cancelDate = (string) $xml->cancelDate) {
                             $subsdata['cancelDate'] = strlen($cancelDate) > 8 ? substr($cancelDate, 0, 8) : $cancelDate;
                         }
                         if ($expirationDate = (string) $xml->expirationDate) {
                             $subsdata['expirationDate'] = strlen($expirationDate) > 8 ? substr($expirationDate, 0, 8) : $expirationDate;
                         }
                         break;
                     case 2:
                         // active
                         $subsdata['subscriptionStatus'] = 'Active';
                         break;
                     default:
                         // error
                         break;
                 }
             }
             // next pay
             if (isset($xml->nextBillingDate)) {
                 if ($nextBillingDate = (string) $xml->nextBillingDate) {
                     $subsdata['nextBillingDate'] = strlen($nextBillingDate) > 8 ? substr($nextBillingDate, 0, 8) : $nextBillingDate;
                 }
             }
         }
         // check
         if (isset($subsdata['subscriptionStatus'])) {
             // old status
             $old_status = $member->status;
             // date format
             $date_format = mgm_get_date_format('date_format');
             // set status
             switch ($subsdata['subscriptionStatus']) {
                 case 'Active':
                     // set new status
                     $member->status = $new_status = MGM_STATUS_ACTIVE;
                     // status string
                     $member->status_str = __('Last payment cycle processed successfully', 'mgm');
                     //Get pack cycle and less form cc-bill nexbilling date to find last pay date.
                     $pack_cycle_format = mgm_get_pack_cycle_date((int) $member->pack_id, $member);
                     // last pay date
                     if ($pack_cycle_format !== false) {
                         $pack_cycle_less = str_replace('+', '-', $pack_cycle_format);
                         $member->last_pay_date = isset($subsdata['nextBillingDate']) ? date('Y-m-d', strtotime($pack_cycle_less, strtotime($subsdata['nextBillingDate']))) : date('Y-m-d');
                     } else {
                         $member->last_pay_date = isset($subsdata['nextBillingDate']) ? date('Y-m-d', strtotime($subsdata['nextBillingDate'])) : date('Y-m-d');
                     }
                     // expire date
                     if (isset($subsdata['nextBillingDate']) && !empty($member->expire_date)) {
                         // consider next billing date as expire date from cc bill.
                         $member->expire_date = date('Y-m-d', strtotime($subsdata['nextBillingDate']));
                         /*
                         // date to add
                         						 	$date_add = mgm_get_pack_cycle_date((int)$member->pack_id, $member);		
                         // check 
                         if($date_add !== false){
                         	// new expire date should be later than current expire date, #1223
                         	$new_expire_date = date('Y-m-d', strtotime($date_add, strtotime($member->last_pay_date)));
                         	// apply on last pay date so the calc always treat last pay date form gateway
                         	if(strtotime($new_expire_date) > strtotime($member->expire_date)){
                         		$member->expire_date = $new_expire_date;
                         	}
                         }else{
                         // set last pay date if greater than expire date
                         	if(strtotime($member->last_pay_date) > strtotime($member->expire_date)){
                         		$member->expire_date = $member->last_pay_date;
                         	}
                         }
                         */
                     }
                     // save
                     $member->save();
                     // only run in cron, other wise too many tracking will be added
                     // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){
                     // transaction_id
                     $transaction_id = $member->transaction_id;
                     // hook args
                     $args = array('user_id' => $user_id, 'transaction_id' => $transaction_id);
                     // after succesful payment hook
                     do_action('mgm_membership_transaction_success', $args);
                     // backward compatibility
                     do_action('mgm_subscription_purchase_payment_success', $args);
                     // new organized name
                     // }
                     break;
                 case 'Cancelled':
                     // if expire date in future, let as awaiting
                     if (isset($subsdata['expirationDate']) && !empty($subsdata['expirationDate']) && strtotime($subsdata['expirationDate']) > time()) {
                         // status
                         $member->status = $new_status = MGM_STATUS_AWAITING_CANCEL;
                         //taking expire date from ccbill
                         $member->expire_date = date('Y-m-d', strtotime($subsdata['expirationDate']));
                         // status string
                         $member->status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($member->expire_date)));
                         // set reset date
                         $member->status_reset_on = $member->expire_date;
                         // reset as
                         $member->status_reset_as = MGM_STATUS_CANCELLED;
                     } else {
                         // set cancelled
                         // status
                         $member->status = $new_status = MGM_STATUS_CANCELLED;
                         // status string
                         if (isset($subsdata['cancelDate']) && !empty($subsdata['cancelDate'])) {
                             $member->status_str = sprintf(__('Last payment cycle cancelled on %s', 'mgm'), date($date_format, strtotime($subsdata['cancelDate'])));
                         } else {
                             $member->status_str = __('Last payment cycle cancelled', 'mgm');
                         }
                     }
                     //Before this fix users having wrong last pay date so updating here - issue #1520
                     if (isset($subsdata['expirationDate']) && !empty($subsdata['expirationDate'])) {
                         //Get pack cycle and less form cc-bill nexbilling date to find last pay date
                         $pack_cycle_format = mgm_get_pack_cycle_date((int) $member->pack_id, $member);
                         // last pay date
                         if ($pack_cycle_format !== false) {
                             $pack_cycle_less = str_replace('+', '-', $pack_cycle_format);
                             $member->last_pay_date = date('Y-m-d', strtotime($pack_cycle_less, strtotime($subsdata['expirationDate'])));
                         }
                     }
                     // save
                     $member->save();
                     // only run in cron, other wise too many tracking will be added
                     // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){
                     // after cancellation hook
                     do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id));
                     // }
                     break;
                 case 'Expired':
                     // set new status
                     $member->status = $new_status = MGM_STATUS_EXPIRED;
                     // status string
                     if (isset($subsdata['expirationDate']) && !empty($subsdata['expirationDate'])) {
                         $member->status_str = sprintf(__('Last payment cycle expired on %s', 'mgm'), date($date_format, strtotime($subsdata['expirationDate'])));
                     } else {
                         $member->status_str = __('Last payment cycle expired', 'mgm');
                     }
                     //Before this fix users having wrong last pay date so updating here - issue #1520
                     if (isset($subsdata['expirationDate']) && !empty($subsdata['expirationDate'])) {
                         //Get pack cycle and less form cc-bill nexbilling date to find last pay date
                         $pack_cycle_format = mgm_get_pack_cycle_date((int) $member->pack_id, $member);
                         // last pay date
                         if ($pack_cycle_format !== false) {
                             $pack_cycle_less = str_replace('+', '-', $pack_cycle_format);
                             $member->last_pay_date = date('Y-m-d', strtotime($pack_cycle_less, strtotime($subsdata['expirationDate'])));
                         }
                         //taking expire date from ccbill
                         $member->expire_date = date('Y-m-d', strtotime($subsdata['expirationDate']));
                     }
                     // save
                     $member->save();
                     break;
             }
             // action
             if (isset($new_status) && $new_status != $old_status) {
                 // user status change
                 do_action('mgm_user_status_change', $user_id, $new_status, $old_status, 'module_' . $this->module, $member->pack_id);
                 // rebill status change
                 do_action('mgm_rebill_status_change', $user_id, $new_status, $old_status, 'query');
                 // query or notify
             }
             // return as a successful rebill
             return true;
         }
     }
     // return
     return false;
 }
/**
 * find members with two dates  critera
 *
 * @param string $field
 * @param string $value
 * @param array $params
 * @param string $return ( results|count)
 * @return mixed array|int  
 */
function mgm_get_members_between_two_dates($field, $value_one, $value_two)
{
    global $wpdb;
    $start = 0;
    $limit = 1000;
    //user meta fields
    $fields = array('user_id', 'meta_value');
    // sql
    $sql = "SELECT count(*) FROM `{$wpdb->usermeta}` WHERE `meta_key` = 'mgm_member_options' AND `user_id` <> 1";
    $count = $wpdb->get_var($sql);
    // init
    $members = array();
    //count
    if ($count) {
        for ($i = $start; $i < $count; $i = $i + $limit) {
            $users = mgm_patch_partial_user_member_options($i, $limit, $fields);
            foreach ($users as $user) {
                $user_id = $user->user_id;
                $member = unserialize($user->meta_value);
                // convert member object
                $member = mgm_convert_array_to_memberobj($member, $user_id);
                // vlid
                $valid = false;
                // matrch field
                switch ($field) {
                    case 'last_pay_date':
                    case 'expire_date':
                    case 'join_date':
                        // take only date part #1023 related
                        if ($field == 'join_date') {
                            $field_ts = strtotime(date('Y-m-d', $member->{$field}));
                        } else {
                            $field_ts = strtotime(date('Y-m-d', strtotime($member->{$field})));
                        }
                        mgm_log("User id: " . $member->id . "User Exp : " . $member->{$field} . " User Start : " . $value_one . " User End : " . $value_two);
                        // check between
                        if ($field_ts >= strtotime($value_one) && $field_ts <= strtotime($value_two)) {
                            // valid
                            $valid = true;
                        }
                        // check other - issue #1483
                        if (!$valid && isset($member->other_membership_types) && is_object($member->other_membership_types) && !empty($member->other_membership_types)) {
                            // loop
                            foreach ($member->other_membership_types as $key => $memtypes) {
                                // convet
                                if (is_array($memtypes)) {
                                    $memtypes = mgm_convert_array_to_memberobj($memtypes, $user_id);
                                }
                                // skip default values:
                                if (strtolower($memtypes->membership_type) == 'guest' || $memtypes->status == MGM_STATUS_NULL) {
                                    continue;
                                }
                                // take only date part #1023 related
                                $field_ts = strtotime(date('Y-m-d', strtotime($memtypes->{$field})));
                                // match
                                if ($field_ts >= strtotime($value_one) && $field_ts <= strtotime($value_two)) {
                                    // valid
                                    $valid = true;
                                    break;
                                }
                            }
                        }
                        break;
                }
                // store
                if ($valid) {
                    $members[] = $user_id;
                }
                // unset object
                unset($member);
            }
            //a small delay of 0.01 second
            usleep(10000);
        }
    }
    // return
    return $return == 'count' ? count($members) : $members;
}
    function _cancel_membership($user_id = NULL, $redirect = false)
    {
        // system
        $system_obj = mgm_get_class('system');
        $s_packs = mgm_get_class('subscription_packs');
        $duration_str = $s_packs->duration_str;
        $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
        $dpne = bool_from_yn($system_obj->get_setting('disable_payment_notify_emails'));
        //issue #1521
        $is_admin = is_super_admin() ? true : false;
        // if passthrough provided
        if (isset($_REQUEST['extra'])) {
            // get passthrough, stop further process if fails to parse
            $custom = $this->_get_transaction_passthrough($_REQUEST['extra']);
            // local var
            extract($custom);
        } elseif (isset($_REQUEST['SUBSCRIPTION_ID']) || isset($_REQUEST['SubscriptionID'])) {
            // get tran
            $tran = mgm_get_transaction_by_option('zombaio_subscription_id', isset($_REQUEST['SUBSCRIPTION_ID']) ? $_REQUEST['SUBSCRIPTION_ID'] : $_REQUEST['SubscriptionID']);
            // local var
            extract($tran['data']);
        } elseif (isset($_REQUEST['TRANSACTION_ID'])) {
            // get tran
            $tran = mgm_get_transaction_by_option('zombaio_transaction_id', $_REQUEST['TRANSACTION_ID']);
            // local var
            extract($tran['data']);
        } elseif (isset($_REQUEST['username'])) {
            // get user
            if ($user = get_user_by('login', $_REQUEST['username'])) {
                $user_id = $user->ID;
            }
        }
        // log
        // mgm_log($user_id, ($this->module . '_' . __FUNCTION__));
        // no user id
        if (!$user_id) {
            // message
            $message = 'Could not read member in the following REQUEST data. 
			            Please debug or contact magic members to fix the problem making sure to pass 
						on the following data. <br /><br /><pre>' . "\n\n" . print_r($_REQUEST, true) . '</pre>';
            // notify admin, only if gateway emails on
            if (!$dge) {
                // mail
                mgm_mail($system_obj->get_setting('admin_email'), 'Error in Zombaio membership cancellation', $message);
            } else {
                // log
                mgm_log($message, $this->module . '_' . __FUNCTION__);
            }
            // exit
            exit;
        }
        // find user
        $user = get_userdata($user_id);
        $member = mgm_get_member($user_id);
        // multiple membesrhip level update:
        $multiple_update = false;
        // check
        if (isset($_POST['membership_type']) && $member->membership_type != $_POST['membership_type'] || isset($membership_type) && $member->membership_type != $membership_type) {
            $multiple_update = true;
            $member = mgm_get_member_another_purchase($user_id, $_POST['membership_type']);
        }
        // get pack
        if ($member->pack_id) {
            $subs_pack = $s_packs->get_pack($member->pack_id);
        } else {
            $subs_pack = $s_packs->validate_pack($member->amount, $member->duration, $member->duration_type, $member->membership_type);
        }
        // tracking fields module_field => post_field
        $tracking_fields = array('txn_type' => 'Action', 'subscr_id' => array('SUBSCRIPTION_ID', 'SubscriptionID'), 'txn_id' => 'TRANSACTION_ID');
        // save tracking fields
        $this->_save_tracking_fields($tracking_fields, $member, $_REQUEST);
        // types
        $duration_exprs = $s_packs->get_duration_exprs();
        // default expire date
        $expire_date = $member->expire_date;
        // if lifetime:
        if ($member->duration_type == 'l') {
            $expire_date = date('Y-m-d');
        }
        // if trial on
        if ($subs_pack['trial_on'] && isset($duration_exprs[$subs_pack['trial_duration_type']])) {
            // if cancel data is before trial end, set cancel on trial expire_date
            $trial_expire_date = strtotime("+{$subs_pack['trial_duration']} {$duration_exprs[$subs_pack['trial_duration_type']]}", $member->join_date);
            // if lower
            if (time() < $trial_expire_date) {
                $expire_date = date('Y-m-d', $trial_expire_date);
            }
        }
        // transaction_id
        $trans_id = $member->transaction_id;
        // log
        // mgm_log($member, ($this->module . '_' . __FUNCTION__));
        // mgm_log($expire_date . ' ' . date('Y-m-d H:i:s'), ($this->module . '_' . __FUNCTION__));
        // if today
        if (time() >= strtotime($expire_date)) {
            // status
            $new_status = MGM_STATUS_CANCELLED;
            $new_status_str = __('Subscription cancelled', 'mgm');
            // set
            $member->status = $new_status;
            $member->status_str = $new_status_str;
            $member->expire_date = date('Y-m-d H:i:s');
            // reassign expiry membership pack if exists: issue#: 535
            $member = apply_filters('mgm_reassign_member_subscription', $user_id, $member, 'CANCEL', true);
        } else {
            // date
            $date_format = mgm_get_date_format('date_format');
            // status
            $new_status = MGM_STATUS_AWAITING_CANCEL;
            $new_status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($expire_date)));
            // set
            $member->status = $new_status;
            $member->status_str = $new_status_str;
            // set reset date
            $member->status_reset_on = $expire_date;
            $member->status_reset_as = MGM_STATUS_CANCELLED;
        }
        // log
        // mgm_log($member, ($this->module . '_' . __FUNCTION__));
        // update user
        // multiple membesrhip level update:
        if ($multiple_update) {
            mgm_save_another_membership_fields($member, $user_id);
        } else {
            $member->save();
        }
        // transaction status
        mgm_update_transaction_status($trans_id, $new_status, $new_status_str);
        // send email notification to client
        $blogname = get_option('blogname');
        // subject
        $subject = $system_obj->get_template('subscription_cancelled_email_template_subject', array('blogname' => $blogname), true);
        // body
        $message = $system_obj->get_template('subscription_cancelled_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'email' => $user->user_email, 'admin_email' => $system_obj->setting['admin_email']), true);
        // send email notification to user
        if (!$dpne) {
            //issue #862
            $subject = mgm_replace_email_tags($subject, $user_id);
            $message = mgm_replace_email_tags($message, $user_id);
            // mail
            mgm_mail($user->user_email, $subject, $message);
        }
        // notify admin, only if gateway emails on
        if (!$dge) {
            $subject = "[{$blogname}] {$user->user_email} - {$new_status}";
            $message = "\tUser display name: {$user->display_name}\n\n<br />\r\r\n\t\t\t\t\tUser email: {$user->user_email}\n\n<br />\r\r\n\t\t\t\t\tUser ID: {$user->ID}\n\n<br />\r\r\n\t\t\t\t\tMembership Type: {$membership_type}\n\n<br />\r\r\n\t\t\t\t\tNew status: {$new_status}\n\n<br />\r\r\n\t\t\t\t\tStatus message: {$member->status_str}\n\n<br />\t\t\t\t\t\r\r\n\t\t\t\t\tPayment Mode: Cancelled\n\n<br />\r\r\n\t\t\t\t\tPOST Data was: \n\n<br /><br /><pre>" . print_r($_POST, true) . '</pre>';
            mgm_mail($system_obj->setting['admin_email'], $subject, $message);
        }
        // after cancellation hook
        do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id));
        // redirect
        if ($redirect) {
            // message
            $lformat = mgm_get_date_format('date_format_long');
            $message = sprintf(__("You have successfully unsubscribed. Your account has been marked for cancellation on %s", "mgm"), $expire_date == date('Y-m-d') ? 'Today' : date($lformat, strtotime($expire_date)));
            //issue #1521
            if ($is_admin) {
                mgm_redirect(add_query_arg(array('user_id' => $user_id, 'unsubscribe_errors' => urlencode($message)), admin_url('user-edit.php')));
            }
            // redirect
            mgm_redirect(mgm_get_custom_url('membership_details', false, array('unsubscribed' => 'true', 'unsubscribe_errors' => urlencode($message))));
        }
    }
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @param int $pack_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $subscr_id = 0;
                     }
                     // 0 stands for a lost subscription id
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     }
     $system_obj = mgm_get_class('system');
     $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
     //send email only if setting enabled
     if ((!empty($subscr_id) || $subscr_id === 0) && !$dge) {
         $user = get_userdata($user_id);
         //send notification email to admin:
         $message = __('The User: '******'mgm') . $user->user_email . ' (' . $user_id . ') ' . __('has upgraded/cancelled subscription.', 'mgm');
         $message .= "<br/>" . __('Please unsubscribe the user from Gateway Merchant panel.', 'mgm');
         if ($subscr_id) {
             $message .= "<br/><br/>" . __('Pay Id: ', 'mgm') . $subscr_id;
         }
         if (isset($member->transaction_id)) {
             $message .= "<br/>" . __('MGM Transaction Id:', 'mgm') . $member->transaction_id;
         }
         //admin email:
         if (!empty($system_obj->setting['admin_email'])) {
             @mgm_mail($system_obj->setting['admin_email'], sprintf(__('[%s] User Subscription Cancellation', 'mgm'), get_option('blogname')), $message);
         }
     }
     return true;
 }
 function _get_epoch_dataplus_ips()
 {
     // ips
     if (!($epoch_dataplus_ips = get_transient('mgm_epoch_dataplus_ips'))) {
         // init
         $epoch_dataplus_ips = array();
         // check
         if ($ip_list = mgm_remote_get('https://epoch.com/ip_list.php', null, null, 'CONNECT_ERROR')) {
             // check
             if ($ip_list != 'CONNECT_ERROR') {
                 $epoch_dataplus_ips = explode('|', $ip_list);
             }
         }
         // known
         if (empty($epoch_dataplus_ips)) {
             $epoch_dataplus_ips = explode('|', '174.129.249.162|65.17.248.|68.71.103.|184.73.155.222|184.72.56.152|184.72.56.199|184.73.192.230');
         }
         // set cache
         set_transient('mgm_epoch_dataplus_ips', $epoch_dataplus_ips, mgm_time2second('1 DAY'));
         // log
         mgm_log($epoch_dataplus_ips, __FUNCTION__);
     }
     // return
     return $epoch_dataplus_ips;
 }
 function _get_notification_data()
 {
     // notificationCode
     $notification_code = mgm_post_var('notificationCode');
     // code
     $notification_type = mgm_post_var('notificationType');
     // transaction
     // check
     if ($notification_code) {
         // parse the pagseguro URL
         $notification_url = $this->_get_endpoint('notification');
         // build
         $notification_url = add_query_arg(array('email' => $this->setting['receiver_email'], 'token' => $this->setting['token']), trailingslashit($notification_url . $notification_code));
         // headers
         $http_headers = array('Content-Type' => 'application/x-www-form-urlencoded');
         // just in case
         // get
         $http_response = mgm_remote_get($notification_url, null, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // log xml as came
         mgm_log('http_response: ' . $http_response, $this->module . '_' . __FUNCTION__);
         // parse as xml
         if ($xml = @simplexml_load_string($http_response)) {
             // parse
             $_POST['code'] = (string) $xml->code;
             $_POST['custom'] = (string) $xml->reference;
             $_POST['type'] = (string) $xml->type;
             $_POST['status'] = (string) $xml->status;
             // code
             $_POST['status_code'] = $this->_get_status_code($_POST['status']);
             // log
             mgm_log('PagSeguro IPN : processed :' . print_r($_POST, true), $this->module . '_' . __FUNCTION__);
         }
     }
 }
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @param int $pack_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $subscr_id = 0;
                     }
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     }
     //send email only if setting enabled
     if (!empty($subscr_id) || $subscr_id === 0) {
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         //send email only if setting enabled
         if (!$dge) {
             // blog
             $blogname = get_option('blogname');
             // user
             $user = get_userdata($user_id);
             // notify admin
             mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member);
         }
         return true;
     }
     return false;
 }
/**
 * Hook to print POST/GET data in modules
 *
 * @param string $module
 * @param string $action
 */
function mgm_print_module_data($module, $action)
{
    // skip credit card details submitted from credit card form:
    if (isset($_POST['mgm_card_number'])) {
        return;
    }
    // log file
    $log_filename = $module . '_' . $action;
    // post
    if (isset($_POST)) {
        mgm_log($module . ' ' . $action . ' POST DATA:' . mgm_array_dump($_POST, true), $log_filename);
    }
    // get
    if (isset($_GET)) {
        mgm_log($module . ' ' . $action . ' GET DATA:' . mgm_array_dump($_GET, true), $log_filename);
    }
}
 function _inputstream_post()
 {
     // access raw HTTP POST data
     $post_body = file_get_contents('php://input');
     // log
     mgm_log($post_body, __FUNCTION__);
     // load
     if ($xml = @simplexml_load_string($post_body)) {
         // log
         mgm_log($xml, __FUNCTION__);
         // token
         if (isset($xml->Token)) {
             // set
             $_POST['token'] = (string) $xml->Token;
             // read order token
             $this->read_order($_POST['token']);
             // get user by email
             if (isset($_POST['email'])) {
                 // fetch
                 $user = get_user_by('email', $_POST['email']);
                 // log
                 // mgm_log($user, __FUNCTION__);
                 // tran id/ custom
                 if ($user->ID > 0) {
                     // custom
                     $_POST['custom'] = get_user_option('mgm_1shoppingcart_tran_id', $user->ID);
                     // remove temp meta
                     if (isset($_POST['custom']) && !empty($_POST['custom'])) {
                         delete_user_option($user->ID, 'mgm_1shoppingcart_tran_id', true);
                     }
                 }
             }
         }
     }
 }
 function _verify_postback()
 {
     // system
     $system_obj = mgm_get_class('system');
     $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
     // parse the paypal URL
     $url_parsed = parse_url($this->_get_endpoint());
     // domain/host
     $domain = $url_parsed['host'];
     // str_replace('https://', '', $this->_get_endpoint());
     // post vars
     $request = 'cmd=_notify-validate';
     // loop post
     foreach ($_POST as $key => $value) {
         // strip
         //issue#: 552(verification fails if get_magic_quotes_gpc() turned off and doesn't strip slashes )
         /*if (get_magic_quotes_gpc()) {
         			$value = stripslashes($value);
         		}*/
         $value = mgm_stripslashes_deep($value);
         // request
         $request .= '&' . $key . '=' . urlencode($value);
     }
     // get conn
     @set_time_limit(60);
     // fosockopen
     if ($conn = @fsockopen("ssl://" . $domain, 443, $errno, $errstr, 60)) {
         fputs($conn, "POST /cgi-bin/webscr HTTP/1.1\r\n");
         fputs($conn, "Host: " . $domain . "\r\n");
         fputs($conn, "Content-type: application/x-www-form-urlencoded\r\n");
         fputs($conn, "Content-length: " . strlen($request) . "\r\n");
         fputs($conn, "Connection: close\r\n\r\n");
         fputs($conn, $request . "\r\n\r\n");
         // get response
         $response = '';
         while (!feof($conn)) {
             $response .= fgets($conn, 1024);
         }
         // close
         fclose($conn);
         // close connection
         // check
         if (!preg_match('/VERIFIED/i', $response)) {
             // notify admin, only if gateway emails on
             if (!$dge) {
                 $message = sprintf("sent a request to host: '%s'. \n\n <br />response was: \n\n <br />\r\r\n\t\t\t\t\t\t                %s \n\n <br />post vars: <pre>%s</pre><br />\n", $domain, $response, print_r($_POST, true));
                 mgm_notify_admin('callback failed', $message);
             } else {
                 // log
                 mgm_log('PAYPAL verification failed(fsockopen): paypal', $this->module);
             }
             // error
             return false;
         }
         // valid
         return true;
     } elseif (extension_loaded('curl')) {
         // open
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $this->_get_endpoint());
         curl_setopt($ch, CURLOPT_USERAGENT, 'Magic Members Membership Software');
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
         curl_setopt($ch, CURLOPT_VERBOSE, 1);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
         curl_setopt($ch, CURLOPT_REFERER, get_option('siteurl'));
         curl_setopt($ch, CURLOPT_HEADER, 0);
         $response = curl_exec($ch);
         // check
         if (!preg_match('/VERIFIED/i', $response)) {
             // notify admin, only if gateway emails on
             if (!$dge) {
                 $message = sprintf("sent a request to host: '%s'. \n\n <br />response was: \n\n <br />\r\r\n\t\t\t\t\t\t               %s\n\n <br />post vars: <pre>%s</pre>", $domain, $response, print_r($_POST, true));
                 mgm_notify_admin('callback failed', $message);
             } else {
                 // log
                 mgm_log('PAYPAL verification failed(curl): paypal', $this->module);
             }
             // error
             return false;
         }
         // valid
         return true;
     } else {
         // notify admin, only if gateway emails on
         if (!$dge) {
             mgm_admin_mail('callback failed', sprintf('fsockopen/curl to %s failed. Would have sent: %s', $domain, $request));
         } else {
             // log
             mgm_log('PAYPAL verification failed(NOT SENT): paypal', $this->module);
         }
         // error
         return false;
     }
 }
 /**
  * create recurring profile
  */
 function _create_paypal_profile()
 {
     // double check
     if ($_POST['RESULT'] != 0) {
         return;
     }
     // @todo
     // void the auth
     // $this->_void_auth();
     // tran
     $tran = mgm_get_transaction($_POST['M_CUSTOM']);
     // pack
     $pack = $tran['data'];
     // log
     // mgm_log($pack, $this->module . __FUNCTION__);
     // one time billing cycle
     if (isset($pack['num_cycles']) && (int) $pack['num_cycles'] == 1) {
         // log
         mgm_log('Exit Flag for One time billing', $this->module . __FUNCTION__);
         // exit
         return;
     }
     // log
     mgm_log('Process flag to Create Profile', $this->module . __FUNCTION__);
     // user data
     $user_id = $pack['user_id'];
     $user = get_userdata($user_id);
     // item
     $item = $this->get_pack_item($pack);
     // periods
     $pay_periods = array('d' => 'DAYS', 'w' => 'WEEK', 'm' => 'MONT', 'y' => 'YEAR');
     // day not supported by Paypal
     $pay_terms = array('d' => 365, 'w' => 52, 'm' => 12, 'y' => 1);
     // secured
     $secured = array('PARTNER' => $this->setting['partner'], 'VENDOR' => $this->setting['vendor'], 'USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'MAXFAILPAYMENTS' => (int) $this->setting['max_failed_payments']);
     // greater than 0, set term to ongoing
     if ((int) $pack['num_cycles'] > 1) {
         $term = $pay_terms[$pack['duration_type']] * ($pack['num_cycles'] - 1);
         // reduce 1 since auth captures first payment right away
     } else {
         $term = 0;
     }
     // exprs
     $duration_exprs = mgm_get_class('subscription_packs')->get_duration_exprs();
     //array('d'=>'DAY','w' => 'WEEK', 'm'=>'MONTH', 'y'=>'YEAR' );
     // start date should be next billing cycle date, //date('mdY', strtotime('+1 DAY')),//MMDDYYYY
     $start_date = date('mdY', strtotime('+' . 1 * (int) $pack['duration'] . ' ' . $duration_exprs[$pack['duration_type']]));
     // method
     switch ($_POST['METHOD']) {
         case 'CC':
             // Credit Card DCC
             // comment
             $comment = sprintf('%s By %s', $item['name'], $user->user_email);
             # code...
             $data = array('TRXTYPE' => 'R', 'TENDER' => 'C', 'ACTION' => 'A', 'PROFILENAME' => $item['name'], 'ORIGID' => $_POST['PNREF'], 'START' => $start_date, 'PAYPERIOD' => $pay_periods[$pack['duration_type']], 'TERM' => $term, 'AMT' => $pack['cost'], 'EMAIL' => $user->user_email, 'DESC' => $item['name'], 'COMMENT1' => $this->_remove_special_chars($comment));
             break;
         case 'P':
             // PayPal, EC
         // PayPal, EC
         default:
             // comment
             $comment = sprintf('%s By %s', $item['name'], $user->user_email);
             # code...
             $data = array('TRXTYPE' => 'R', 'TENDER' => 'P', 'ACTION' => 'A', 'PROFILENAME' => $item['name'], 'BAID' => isset($_POST['BAID']) && !empty($_POST['BAID']) ? $_POST['BAID'] : $_POST['PNREF'], 'START' => $start_date, 'PAYPERIOD' => $pay_periods[$pack['duration_type']], 'TERM' => $term, 'AMT' => $pack['cost'], 'EMAIL' => $user->user_email, 'DESC' => $item['name'], 'COMMENT1' => $this->_remove_special_chars($comment));
             // check, notify admin
             if (!isset($_POST['BAID']) || empty($_POST['BAID'])) {
                 // subject
                 $subject = 'BAID missing in PayPal Payflow Profile Creation';
                 // message
                 $message = sprintf('BAID missing in PayPal Payflow Profile Creation, Please contact PayPal, POST DATA: %s', print_r($_POST, true));
                 // send
                 mgm_notify_admin(null, $subject, $message);
                 // log
                 mgm_log($message, $this->module . __FUNCTION__);
             }
             break;
     }
     // additional fields
     $this->_set_address_fields($user, $data);
     // merge
     $data = array_merge($secured, $data);
     // log
     mgm_log($data, $this->module . __FUNCTION__);
     // data
     $data_post = _http_build_query($data, null, '&', '', false);
     // do not encode
     // link
     $post_url = $this->_get_endpoint();
     //issue #1508
     $url_parsed = parse_url($post_url);
     // domain/host
     $domain = $url_parsed['host'];
     // headers
     $http_headers = array('POST /cgi-bin/webscr HTTP/1.1\\r\\n', 'Content-Type: application/x-www-form-urlencoded\\r\\n', 'Host: ' . $domain . '\\r\\n', 'Connection: close\\r\\n\\r\\n');
     // post
     $http_response = mgm_remote_post($post_url, $data_post, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
     // parse
     $response = array();
     // parse
     parse_str($http_response, $response);
     // log
     mgm_log($response, $this->module . __FUNCTION__);
     // profile id
     if ($response['RESULT'] == 0) {
         // set in post
         $_POST['PROFILEID'] = $response['PROFILEID'];
         // set in option
         mgm_add_transaction_option(array('transaction_id' => $_POST['M_CUSTOM'], 'option_name' => strtolower($this->module . '_PROFILEID'), 'option_value' => isset($_POST['PROFILEID']) ? $_POST['PROFILEID'] : ''));
     }
 }
    function member_export()
    {
        global $wpdb;
        // error -- use WP_DEBUG with WP_DEBUG_LOG
        // if(!WP_DEBUG) error_reporting(0);
        // extract
        extract($_POST);
        // log
        // mgm_log($_POST, __FUNCTION__);
        // get format
        $sformat = mgm_get_date_format('date_format_short');
        // process
        if (isset($export_member_info)) {
            // init
            $success = 0;
            // type
            $membership_type = isset($bk_membership_type) ? $bk_membership_type : 'all';
            // status
            $membership_status = isset($bk_membership_status) ? $bk_membership_status : 'all';
            // date
            $date_start = isset($bk_date_start) ? $bk_date_start : '';
            $date_end = isset($bk_date_end) ? $bk_date_end : '';
            // query inut
            $query = '';
            // selected only
            if (isset($bk_only_selected)) {
                // check
                if (isset($bk_selected_members) && is_array($bk_selected_members)) {
                    $query = " AND `id` IN(" . mgm_map_for_in($bk_selected_members) . ")";
                }
            }
            // start date
            if ($date_start) {
                // Issue #700
                // convert to mysql date
                $date_start = strtotime(mgm_format_inputdate_to_mysql($date_start, $sformat));
                // end date
                if ($date_end) {
                    // Issue #700
                    // convert to mysql date
                    $date_end = mgm_format_inputdate_to_mysql($date_end, $sformat);
                    $date_end = strtotime($date_end);
                    // issue#" 492
                    $query .= " AND UNIX_TIMESTAMP(user_registered) >= '{$date_start}' \r\r\n\t\t\t\t\t            AND UNIX_TIMESTAMP(DATE_FORMAT(user_registered, '%Y-%m-%d')) <= '{$date_end}'";
                } else {
                    $query .= " AND UNIX_TIMESTAMP(user_registered) >= '{$date_start}'";
                }
            } else {
                if ($date_end) {
                    // Issue #700
                    // convert to mysql date
                    $date_end = strtotime(mgm_format_inputdate_to_mysql($date_end, $sformat));
                    // query
                    $query .= " AND UNIX_TIMESTAMP(DATE_FORMAT(user_registered, '%Y-%m-%d')) <= '{$date_end}' ";
                }
            }
            // all users
            $sql = 'SELECT ID, user_login, user_email, user_registered, display_name FROM `' . $wpdb->users . '` 
			        WHERE ID <> 1 ' . $query . ' ORDER BY `user_registered` ASC';
            // users
            $users = $wpdb->get_results($sql);
            // filter
            $export_users = array();
            // date
            $current_date = time();
            //issue #844
            $skip_fileds = array('subscription_introduction', 'coupon', 'privacy_policy', 'payment_gateways', 'terms_conditions', 'subscription_options', 'autoresponder', 'captcha');
            // check - issue #1382
            if (isset($bk_users_to_import)) {
                $custom_fields = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true, 'on_profile' => true)));
                $import_user_fileds = array('user_login', 'user_email', 'pack_id', 'membership_type');
                foreach ($custom_fields as $field) {
                    if (!in_array($field['name'], $skip_fileds)) {
                        $import_user_fileds[] = $field['name'];
                    }
                }
            }
            // Custom fields
            $cf_profile_pg = mgm_get_class('member_custom_fields');
            $to_unserialize = array();
            foreach (array_unique($cf_profile_pg->sort_orders) as $id) {
                foreach ($cf_profile_pg->custom_fields as $field) {
                    // issue #954: show the field only if it is enabled for profile page
                    if ($field['id'] == $id && $field['type'] == 'checkbox') {
                        $to_unserialize[] = $field['name'];
                    }
                }
            }
            // loop
            foreach ($users as $user) {
                // user cloned
                $user_obj = clone $user;
                // member
                $member = mgm_get_member($user->ID);
                // check
                if (!isset($bk_inactive)) {
                    $bk_inactive = false;
                }
                // check search parameters:
                if ($this->_get_membership_details($member, $bk_msexp_dur_unit, $bk_msexp_dur, $membership_type, $current_date, $bk_inactive, $membership_status)) {
                    // merge
                    if (method_exists($member, 'merge_fields')) {
                        $user = $member->merge_fields($user);
                    }
                    // log
                    // mgm_log($user, __FUNCTION__);
                    // issue #844
                    foreach ($skip_fileds as $skip_filed) {
                        unset($user->{$skip_filed});
                    }
                    // format dates
                    $user->user_registered = date($sformat, strtotime($user->user_registered));
                    $user->last_pay_date = (int) $user->last_pay_date > 0 ? date($sformat, strtotime($user->last_pay_date)) : 'N/A';
                    $user->expire_date = !empty($user->expire_date) ? date($sformat, strtotime($user->expire_date)) : 'N/A';
                    $user->join_date = (int) $user->join_date > 0 ? date($sformat, $user->join_date) : 'N/A';
                    // issue#: 672
                    // DO not show actual password: #1002
                    // $user->user_password = mgm_decrypt_password($member->user_password, $user->ID);
                    $user->rss_token = $member->rss_token;
                    // unset password
                    unset($user->password, $user->password_conf);
                    // unserialize checkbox values
                    if (count($to_unserialize)) {
                        foreach ($to_unserialize as $chkname) {
                            if (isset($user->{$chkname}) && !empty($user->{$chkname})) {
                                $chk_val = @unserialize($user->{$chkname});
                                if (is_array($chk_val)) {
                                    $user->{$chkname} = implode("|", $chk_val);
                                }
                            }
                        }
                    }
                    // check - issue #1382
                    if (isset($bk_users_to_import)) {
                        $importuser = new stdClass();
                        foreach ($import_user_fileds as $import_user_filed) {
                            if (isset($user->{$import_user_filed})) {
                                $importuser->{$import_user_filed} = $user->{$import_user_filed};
                            }
                            if ($import_user_filed == 'pack_id') {
                                $importuser->{$import_user_filed} = $member->pack_id;
                            }
                        }
                        $export_users[] = $importuser;
                        unset($importuser);
                    } else {
                        $export_users[] = $user;
                    }
                }
                // consider multiple memberships as well:
                if (isset($member->other_membership_types) && is_array($member->other_membership_types) && count($member->other_membership_types) > 0) {
                    // loop
                    foreach ($member->other_membership_types as $key => $memtypes) {
                        // types
                        if (is_array($memtypes)) {
                            $memtypes = mgm_convert_array_to_memberobj($memtypes, $user->ID);
                        }
                        // check search parameters:
                        if ($this->_get_membership_details($memtypes, $bk_msexp_dur_unit, $bk_msexp_dur, $membership_type, $current_date, $bk_inactive, $membership_status)) {
                            // copy
                            $user_mem = clone $user_obj;
                            // add custom fields as well:
                            if (!empty($member->custom_fields)) {
                                // loop
                                foreach ($member->custom_fields as $index => $val) {
                                    // custom field
                                    if ($index == 'birthdate' && !empty($val)) {
                                        // convert saved date to input field format
                                        $val = mgm_get_datepicker_format('date', $val);
                                    }
                                    // set
                                    $user_mem->{$index} = $val;
                                }
                            }
                            // check types
                            if (is_object($memtypes) && method_exists($memtypes, 'merge_fields')) {
                                // merge
                                $user_mem = $memtypes->merge_fields($user_mem);
                            } else {
                                // convert to array
                                $data = mgm_object2array($memtypes);
                                // check payment
                                if (isset($memtypes->payment_info) && count($memtypes->payment_info) > 0) {
                                    // loop payments
                                    foreach ($memtypes->payment_info as $index => $val) {
                                        // set
                                        $data['payment_info_' . $index] = str_replace('mgm_', '', $val);
                                    }
                                }
                                // loop data
                                foreach ($data as $index => $val) {
                                    $user_mem->{$index} = $val;
                                }
                            }
                            //issue #844
                            foreach ($skip_fileds as $skip_filed) {
                                unset($user->{$skip_filed});
                            }
                            // format dates
                            $user_mem->user_registered = date($sformat, strtotime($user_mem->user_registered));
                            $user_mem->last_pay_date = (int) $memtypes->last_pay_date > 0 ? date($sformat, strtotime($memtypes->last_pay_date)) : 'N/A';
                            $user_mem->expire_date = !empty($memtypes->expire_date) ? date($sformat, strtotime($memtypes->expire_date)) : 'N/A';
                            $user_mem->join_date = (int) $memtypes->join_date > 0 ? date($sformat, $memtypes->join_date) : 'N/A';
                            // check - issue #1382
                            if (isset($bk_users_to_import)) {
                                $importuser = new stdClass();
                                foreach ($import_user_fileds as $import_user_filed) {
                                    if ($user_mem->{$import_user_filed}) {
                                        $importuser->{$import_user_filed} = $user_mem->{$import_user_filed};
                                    }
                                    if ($import_user_filed == 'pack_id') {
                                        $importuser->{$import_user_filed} = $memtypes->pack_id;
                                    }
                                }
                                $export_users[] = $importuser;
                                unset($importuser);
                            } else {
                                $export_users[] = $user_mem;
                            }
                            // unset
                            unset($user_mem);
                        }
                    }
                }
            }
            // end for
            mgm_log('export_users : ' . mgm_array_dump($export_users, true));
            // default response
            $response = array('status' => 'error', 'message' => __('Error while exporting members. Could not find any member with requested search parameters.', 'mgm'));
            // check
            if (($expcount = count($export_users)) > 0) {
                // Issue #1559: standardization of Membership type
                for ($k = 0; $k < $expcount; $k++) {
                    if (isset($export_users[$k]->membership_type)) {
                        $export_users[$k]->membership_type = strtolower($export_users[$k]->membership_type);
                    }
                }
                // success
                $success = count($export_users);
                // create
                if ($bk_export_format == 'csv') {
                    $filename = mgm_create_csv_file($export_users, 'export_users');
                } else {
                    $filename = mgm_create_xls_file($export_users, 'export_users');
                }
                // src
                $file_src = MGM_FILES_EXPORT_URL . $filename;
                // message
                $response['message'] = sprintf(__('Successfully exported %d %s.', 'mgm'), $success, $success > 1 ? 'users' : 'user');
                $response['status'] = 'success';
                $response['src'] = $file_src;
                // for download iframe
            }
            // return response
            echo json_encode($response);
            exit;
        }
        // data
        $data = array();
        // load template view
        $this->load->template('members/member/export', array('data' => $data));
    }
 /**
  * Specifically check recurring status of each rebill for an expiry date
  * ALong with IPN post mechanism for rebills, the module will need to specifically request for the rebill status
  * @param int $user_id
  * @param object $member
  * @return boolean
  */
 function query_rebill_status($user_id, $member = NULL)
 {
     // check
     if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) {
         //issue #1602
         $pack_id = (int) $member->pack_id;
         if ($pack_id) {
             $currency = mgm_get_pack_currency($pack_id);
         }
         // post data
         $post_data = array();
         // add internal vars
         $secure = array('USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'SIGNATURE' => $this->setting['signature'], 'VERSION' => '64.0', 'IPADDRESS' => mgm_get_client_ip_address(), 'CURRENCYCODE' => $currency ? $currency : $this->setting['currency']);
         // merge
         $post_data = array_merge($post_data, $secure);
         // overwrite post data array with secure params
         // method
         $post_data['METHOD'] = 'GetRecurringPaymentsProfileDetails';
         $post_data['PROFILEID'] = $member->payment_info->subscr_id;
         // endpoint	url
         $end_point = $this->_get_endpoint();
         //issue #1508
         $url_parsed = parse_url($end_point);
         // domain/host
         $domain = $url_parsed['host'];
         // headers
         $http_headers = array('POST /cgi-bin/webscr HTTP/1.1\\r\\n', 'Content-Type: application/x-www-form-urlencoded\\r\\n', 'Host: ' . $domain . '\\r\\n', 'Connection: close\\r\\n\\r\\n');
         // post
         $http_response = mgm_remote_post($end_point, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // log
         mgm_log($http_response, __FUNCTION__);
         // reset
         $this->response = array();
         // parse to array
         parse_str($http_response, $this->response);
         // log
         mgm_log($this->response, __FUNCTION__);
         // post string
         // $post_string = mgm_http_build_query($post_data);
         // create curl post
         // $buffer = $this->_curl_post($endpoint, $post_string);
         // parse to array
         // parse_str($http_response, $this->response);
         // check
         if (isset($this->response['STATUS'])) {
             // old status
             $old_status = $member->status;
             // set status
             switch ($this->response['STATUS']) {
                 case 'Active':
                     // set new status
                     $member->status = $new_status = MGM_STATUS_ACTIVE;
                     // status string
                     $member->status_str = __('Last payment cycle processed successfully', 'mgm');
                     // last pay date
                     $member->last_pay_date = isset($this->response['LASTPAYMENTDATE']) ? date('Y-m-d', strtotime($this->response['LASTPAYMENTDATE'])) : date('Y-m-d');
                     // expire date
                     if (isset($this->response['LASTPAYMENTDATE']) && !empty($member->expire_date)) {
                         // date to add
                         $date_add = mgm_get_pack_cycle_date((int) $member->pack_id, $member);
                         // check
                         if ($date_add !== false) {
                             // new expire date should be later than current expire date, #1223
                             $new_expire_date = date('Y-m-d', strtotime($date_add, strtotime($member->last_pay_date)));
                             // apply on last pay date so the calc always treat last pay date form gateway
                             if (strtotime($new_expire_date) > strtotime($member->expire_date)) {
                                 $member->expire_date = $new_expire_date;
                             }
                         } else {
                             // set last pay date if greater than expire date
                             if (strtotime($member->last_pay_date) > strtotime($member->expire_date)) {
                                 $member->expire_date = $member->last_pay_date;
                             }
                         }
                     }
                     // save
                     $member->save();
                     // only run in cron, other wise too many tracking will be added
                     // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){
                     // transaction_id
                     $transaction_id = $member->transaction_id;
                     // hook args
                     $args = array('user_id' => $user_id, 'transaction_id' => $transaction_id);
                     // after succesful payment hook
                     do_action('mgm_membership_transaction_success', $args);
                     // backward compatibility
                     do_action('mgm_subscription_purchase_payment_success', $args);
                     // new organized name
                     // }
                     break;
                 case 'Cancelled':
                 case 'Suspended':
                     // if expire date in future, let as awaiting
                     if (!empty($member->expire_date) && strtotime($member->expire_date) > time()) {
                         // date format
                         $date_format = mgm_get_date_format('date_format');
                         // status
                         $member->status = $new_status = MGM_STATUS_AWAITING_CANCEL;
                         // status string
                         $member->status_str = sprintf(__('Subscription awaiting cancellation on %s', 'mgm'), date($date_format, strtotime($member->expire_date)));
                         // set reset date
                         $member->status_reset_on = $member->expire_date;
                         // reset as
                         $member->status_reset_as = MGM_STATUS_CANCELLED;
                     } else {
                         // set cancelled
                         // status
                         $member->status = $new_status = MGM_STATUS_CANCELLED;
                         // status string
                         $member->status_str = __('Last payment cycle cancelled', 'mgm');
                     }
                     // save
                     $member->save();
                     // only run in cron, other wise too many tracking will be added
                     // if( defined('DOING_QUERY_REBILL_STATUS') && DOING_QUERY_REBILL_STATUS != 'manual' ){
                     // after cancellation hook
                     do_action('mgm_membership_subscription_cancelled', array('user_id' => $user_id));
                     // }
                     break;
                 case 'Expired':
                     // set new status
                     $member->status = $new_status = MGM_STATUS_EXPIRED;
                     // status string
                     $member->status_str = __('Last payment cycle expired', 'mgm');
                     // save
                     $member->save();
                     break;
             }
             // action
             if (isset($new_status) && $new_status != $old_status) {
                 // user status change
                 do_action('mgm_user_status_change', $user_id, $new_status, $old_status, 'module_' . $this->module, $member->pack_id);
                 // rebill status change
                 do_action('mgm_rebill_status_change', $user_id, $new_status, $old_status, 'query');
                 // query or notify
             }
             // return as a successful rebill
             return true;
         }
     }
     // return
     return false;
     //default to false to skip normal modules
 }
/**
 * fetch authorizenet missing txn id
 *
 * @param object $authorizenet
 * @param array $user_ids 
 * @return void
 * @since 2.7 
 */
function mgm_fetch_authorizenet_missing_txn_id($authorizenet, $user_ids = null)
{
    // db
    global $wpdb;
    // for
    $where = "AND B.option_value = ''";
    // users
    if (is_null($user_ids)) {
        // fetch first 10
        $and_where = $where . " ORDER BY transaction_dt DESC LIMIT 0, 10";
    } elseif (is_array($user_ids) && !empty($user_ids)) {
        // fetch as requested
        $and_where = $where . " AND `user_id` IN(" . mgm_map_for_in($user_ids) . ")";
    } elseif ((int) $user_ids > 0) {
        // fetch one
        $and_where = "AND `user_id` = '" . (int) $user_ids . "'";
    }
    // sql
    $sql = "SELECT `A`.`id`,user_id,data,transaction_dt,`B`.`id` AS `option_id`,`B`.`option_name`,`B`.`option_value` \r\r\n\t\t\tFROM `" . TBL_MGM_TRANSACTION . "` A JOIN `" . TBL_MGM_TRANSACTION_OPTION . "` B ON(A.id=B.transaction_id)\r\r\n\t        WHERE 1 AND `user_id` IS NOT NULL AND module ='authorizenet' \r\r\n\t        AND B.option_name ='authorizenet_transaction_id' {$and_where}";
    // log
    mgm_log($sql, __FUNCTION__);
    // return
    $authorizenet_transaction_id = false;
    //  check missing user_id
    if ($an_transactions = $wpdb->get_results($sql)) {
        // jus use the settings
        // authorize.net specific
        $an_loginid = $authorizenet->setting['loginid'];
        $an_tran_key = $authorizenet->setting['tran_key'];
        // types
        $duration2days = array('d' => 'DAY', 'm' => 'MONTH', 'w' => 'WEEK', 'y' => 'YEAR');
        // log
        mgm_log($an_transactions, __FUNCTION__);
        // this will only miss when pack with trial cost 0.00
        // loop
        foreach ($an_transactions as $transaction) {
            // pack
            $pack = json_decode($transaction->data, true);
            // log
            mgm_log($pack, __FUNCTION__);
            // check
            if (isset($pack['trial_on']) && (int) $pack['trial_on'] == 1 && (double) $pack['trial_cost'] == 0.0) {
                $trial_duration_type = $pack['trial_duration_type'];
                $trial_duration = (int) $pack['trial_duration'];
                $trial_num_cycles = (int) $pack['trial_num_cycles'];
                // calc
                $trial_length = $trial_num_cycles * $trial_duration;
                // 1 * 10
                $trial_days = $duration2days[$trial_duration_type];
                // DAY,MONTH
                // first transaction
                $an_transaction_dt = $transaction->transaction_dt;
                // billing start date
                $an_billing_start_dt = date('Y-m-d H:i:s', strtotime("+{$trial_length} {$trial_days}", strtotime($transaction->transaction_dt)));
            } else {
                $duration_type = $pack['duration_type'];
                $duration = (int) $pack['duration'];
                $num_cycles = (int) $pack['num_cycles'];
                // calc
                $length = $num_cycles == 0 ? $duration : $num_cycles * $duration;
                // 1 * 10
                $days = $duration2days[$duration_type];
                // DAY,MONTH
                // first transaction
                $an_transaction_dt = $transaction->transaction_dt;
                // billing start date
                $an_billing_start_dt = date('Y-m-d H:i:s', strtotime("+{$length} {$days}", strtotime($an_transaction_dt)));
                // log
                mgm_log("+{$length} {$days}", __FUNCTION__);
                // test
                if (strtotime($an_billing_start_dt) < time()) {
                    // temp
                    $temp_an_billing_start_dt = $an_billing_start_dt;
                    // loop
                    while (strtotime($temp_an_billing_start_dt) < time()) {
                        $temp_an_billing_start_dt = date('Y-m-d H:i:s', strtotime("+{$length} {$days}", strtotime($temp_an_billing_start_dt)));
                    }
                    // reduce one unit if next date fetched
                    if (strtotime($temp_an_billing_start_dt) > time()) {
                        $temp_an_billing_start_dt = date('Y-m-d H:i:s', strtotime("-{$length} {$days}", strtotime($temp_an_billing_start_dt)));
                    }
                    // log
                    mgm_log('temp_an_billing_start_dt: ' . $temp_an_billing_start_dt, __FUNCTION__);
                    // copy
                    $an_billing_start_dt = $temp_an_billing_start_dt;
                }
            }
            // log
            mgm_log($an_transaction_dt . ' ' . $an_billing_start_dt, __FUNCTION__);
            // fetch
            $transactions = $authorizenet->get_settled_transactions($an_billing_start_dt);
            // log
            // mgm_log('transactions: '. mgm_pr($transactions, true), __FUNCTION__);
            // check
            if (in_array($transaction->id, array_keys($transactions))) {
                // log
                mgm_log($transaction->id . ' => ' . $transactions[$transaction->id], __FUNCTION__);
                // update
                $wpdb->update(TBL_MGM_TRANSACTION_OPTION, array('option_value' => $transactions[$transaction->id]), array('id' => $transaction->option_id));
                // log
                mgm_log($wpdb->last_query, __FUNCTION__);
                // return
                $authorizenet_transaction_id = $transactions[$transaction->id];
            }
        }
    }
    // return
    return $authorizenet_transaction_id;
}
 function _get_api_notify($action, $post_data = null, $id = null)
 {
     // headers
     $http_headers = array('Authorization' => 'Basic ' . base64_encode($this->setting['secretkey'] . ':'));
     // just in case
     // base
     $api_url = trailingslashit($this->_get_endpoint('api'));
     // action
     switch ($action) {
         case 'create_customer':
         case 'create_charge':
             // endpoint
             $api_url .= $action == 'create_customer' ? 'customers' : 'charges';
             // post
             $http_response = $this->_remote_post($api_url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
             // log
             mgm_log($http_response, __FUNCTION__);
             // return
             if ($notify = json_decode($http_response)) {
                 return $notify;
             }
             break;
         case 'upgrade_subscription':
             // endpoint
             $api_url .= sprintf('customers/%s/subscription', $id);
             // return
             $http_response = $this->_remote_post($api_url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
             // log
             mgm_log($http_response, __FUNCTION__);
             // return
             if ($notify = json_decode($http_response)) {
                 return $notify;
             }
             break;
         case 'cancel_subscription':
             // endpoint
             $api_url .= sprintf('customers/%s/subscription', $id);
             // return
             $http_response = $this->_remote_delete($api_url, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
             // log
             mgm_log($http_response, __FUNCTION__);
             // return
             if ($notify = json_decode($http_response)) {
                 return $notify;
             }
             break;
         case 'get_customer':
             // endpoint
             $api_url .= sprintf('customers/%s', $id);
             // return
             $http_response = mgm_remote_get($api_url, null, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
             // log
             mgm_log($http_response, __FUNCTION__);
             // return
             if ($notify = json_decode($http_response)) {
                 return $notify;
             }
             break;
         case 'get_invoice':
             // endpoint
             $api_url .= sprintf('invoices/%s', $id);
             // return
             $http_response = mgm_remote_get($api_url, null, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
             // log
             mgm_log($http_response, __FUNCTION__);
             // return
             if ($notify = json_decode($http_response)) {
                 return $notify;
             }
             break;
     }
     // return
     return false;
 }
 function process_credit_card()
 {
     // read tran id
     if (!($tran_id = $this->_read_transaction_id())) {
         return __('Transaction Id invalid', 'mgm');
     }
     // get trans
     if (!($tran = mgm_get_transaction($tran_id))) {
         return __('Transaction invalid', 'mgm');
     }
     // update pack/transaction: this is to confirm the module code if it is different
     mgm_update_transaction(array('module' => $this->module), $tran_id);
     // Check user id is set if subscription_purchase. issue #1049
     if ($tran['payment_type'] == 'subscription_purchase' && (!isset($tran['data']['user_id']) || isset($tran['data']['user_id']) && (int) $tran['data']['user_id'] < 1)) {
         return $this->throw_cc_error(__('Transaction invalid . User id field is empty', 'mgm'));
     }
     // get data
     $data = $this->_get_button_data($tran['data'], $tran_id);
     // merge
     $post_data = array_merge($_POST, $data);
     // set email
     $this->_set_default_email($post_data, 'email');
     //issue #1062
     if (isset($tran['data']['currency']) && !empty($tran['data']['currency'])) {
         $currency = $tran['data']['currency'];
     } else {
         $currency = $this->setting['currency'];
     }
     // add internal vars
     $secure = array('USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'SIGNATURE' => $this->setting['signature'], 'VERSION' => '64.0', 'IPADDRESS' => $_SERVER["REMOTE_ADDR"], 'CURRENCYCODE' => $currency);
     // merge
     $post_data = $this->_filter_postdata(array_merge($post_data, $secure));
     // overwrite post data array with secure params
     // TODO
     $endpoint = $this->_get_endpoint();
     //issue #1508
     $url_parsed = parse_url($endpoint);
     // domain/host
     $domain = $url_parsed['host'];
     // headers
     $http_headers = array('POST /cgi-bin/webscr HTTP/1.1\\r\\n', 'Content-Type: application/x-www-form-urlencoded\\r\\n', 'Host: ' . $domain . '\\r\\n', 'Connection: close\\r\\n\\r\\n');
     // log
     mgm_log($post_data, __FUNCTION__);
     // post
     $http_response = mgm_remote_post($endpoint, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
     // log
     mgm_log($http_response, __FUNCTION__);
     // parse
     $this->response = array();
     // parse response
     parse_str($http_response, $this->response);
     // store custom
     $_POST['custom'] = !empty($post_data['custom']) ? $post_data['custom'] : $tran_id;
     // check
     if (empty($this->response['ACK']) || $this->response['ACK'] == 'Failure' && !empty($this->response['L_LONGMESSAGE0'])) {
         // return to credit card form
         $error_string = sprintf('Paypal Error %s: %s - %s', $this->response['L_ERRORCODE0'], $this->response['L_SHORTMESSAGE0'], $this->response['L_LONGMESSAGE0']);
         // return
         return $this->throw_cc_error($error_string);
     }
     // treat as return
     $this->process_return();
 }
Example #18
0
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @param int $pack_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $subscr_id = 0;
                     }
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         if ($this->setting['aquirer'] != 'sisow') {
             // skip sisow
             return false;
             //skip as trans reff will need to be passed always
         }
     }
     //only for subscription_purchase
     if ($this->setting['aquirer'] == 'sisow') {
         if (!isset($member)) {
             $member = mgm_get_member($user_id);
         }
         $txn_id = $member->payment_info->txn_id;
         //mgm_pr($member);
         // endpoint
         $endpoint = $this->_get_endpoint();
         // set
         $endpoint = str_replace('[action]', 'CancelReservationRequest', $endpoint);
         // keys
         $compute_keys = array($txn_id, $this->setting['merchant_id'], $this->setting['secret_key']);
         $compute_sha1 = sha1(implode('', $compute_keys));
         $post_data = array('trxid' => $txn_id, 'merchantid' => $this->setting['merchant_id'], 'sha1' => $compute_sha1);
         // headers
         $http_headers = array();
         //array('Content-Type' => 'text/xml');
         //mgm_pr($post_data); die;
         // create curl post
         $http_response = mgm_remote_post($endpoint, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         mgm_log($http_response, __FUNCTION__);
         // parse
         if ($xml = @simplexml_load_string($http_response)) {
             mgm_log($xml, __FUNCTION__);
             // redirect to issuer
             if (isset($xml->reservation->status)) {
                 return (string) $xml->reservation->status == 'Cancelled' ? true : false;
             } else {
                 return false;
             }
         }
     }
     //send email only if setting enabled
     if (!empty($subscr_id) || $subscr_id === 0) {
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         //send email only if setting enabled
         if (!$dge) {
             // blog
             $blogname = get_option('blogname');
             // user
             $user = get_userdata($user_id);
             // notify admin
             mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member);
         }
         return true;
     }
     return false;
 }
Example #19
0
 function process_return()
 {
     // log
     // mgm_log('process_return free REQUEST : '.print_r($_REQUEST,true));
     //mgm_pr($_REQUEST); die;
     // only save once success, there may be multiple try
     if (isset($_REQUEST['custom']) && !empty($_REQUEST['custom'])) {
         // id
         $transid = mgm_decode_id(mgm_get_var('transid', '', true));
         // process
         $this->process_notify($transid);
         // query arg
         $query_arg = array('status' => 'success');
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_REQUEST['custom']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // log
         mgm_log($query_arg, __FUNCTION__);
         // login autoredirection
         if (is_numeric($transid)) {
             // update transaction
             mgm_update_transaction_status($transid, MGM_STATUS_ACTIVE, '');
             // is a register redirect?
             $register_redirect = $this->_auto_login($transid);
             // set register redirect
             if ($register_redirect !== false) {
                 $query_arg['register_redirect'] = $register_redirect;
             }
         }
         // log
         mgm_log($query_arg, __FUNCTION__);
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // teat as error
         $errors = 'error in processing your request';
         // redirect
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => $errors), $this->_get_thankyou_url()));
     }
 }
 function get_positional_fields($content)
 {
     // test mode
     $fields = array(0 => "x_response_code", 1 => "x_response_subcode", 2 => "x_response_reason_code", 3 => "x_response_reason_text", 4 => "x_authorization_code", 5 => "x_avs_response", 6 => "x_transaction_id", 9 => "x_amount", 10 => "x_method", 11 => "x_transaction_type", 37 => "x_md5_hash", 38 => "x_card_code_response");
     // split
     $response = explode($this->delim_char, $content);
     // log
     mgm_log($response, __FUNCTION__);
     // data
     $temp = $data = array();
     $ind = 0;
     // explode and store
     foreach ($response as $r) {
         // check
         if (!empty($r)) {
             $temp[$ind] = urldecode($r);
         }
         $ind++;
     }
     // log
     mgm_log($temp, __FUNCTION__);
     foreach ($fields as $i => $field) {
         if (isset($temp[$i])) {
             $data[$field] = $temp[$i];
         }
     }
     // log
     mgm_log($data, __FUNCTION__);
     return $data;
 }
Example #21
0
 function print_role($user_id)
 {
     $roles = $this->get_user_role($user_id);
     // mgm_log('PRINTING USER ROLES:');
     if (!empty($roles)) {
         mgm_log(mgm_array_dump($roles, true));
     }
 }