function _get_button_data($pack, $tran_id = NULL) { // system $system_obj = mgm_get_class('system'); // item $item = $this->get_pack_item($pack); //pack currency over rides genral setting currency - issue #1602 if (!isset($pack['currency']) || empty($pack['currency'])) { $pack['currency'] = $this->setting['currency']; } // type $membership_type = md5($pack['membership_type']); $user_id = mgm_get_user_id(); $user = get_userdata($user_id); $member = mgm_get_member($user_id); $amount = mgm_convert_to_cents($pack['cost']); $payment_type = (int) $pack['num_cycles'] == 1 ? 'one-time' : 'subscription'; $s_valid_until = date('Y-m-d\\TG:i:s\\Z', strtotime('+1 hour')); $description = substr($item['name'], 0, 32); // Setup hash string $hash_string = $this->setting['secret_key'] . $this->setting['merchant_id'] . $this->setting['sub_id'] . $amount . $tran_id . $payment_type . $s_valid_until . '1' . $description . '1' . $amount; // Remove HTML Entities $hash_string = html_entity_decode($hash_string); // Remove space characters: "\t", "\n", "\r" and " " $hash_string = str_replace(array("\t", "\n", "\r", " "), '', $hash_string); // Generate hash $hash_string = sha1($hash_string); $enc_trans_id = $this->_encode_id($tran_id); $cancel_url = add_query_arg(array('status' => 'cancel', 'extra' => $enc_trans_id), $this->setting['cancel_url']); $success_url = add_query_arg(array('status' => 'success', 'extra' => $enc_trans_id), $this->setting['return_url']); $error_url = add_query_arg(array('status' => 'error', 'extra' => $enc_trans_id), $this->setting['return_url']); // set data $data = array('merchantID' => $this->setting['merchant_id'], 'subID' => $this->setting['sub_id'], 'language' => $this->setting['language'], 'currency' => $pack['currency'], 'amount' => $amount, 'purchaseID' => $tran_id, 'description' => $description, 'hash' => $hash_string, 'paymentType' => $payment_type, 'validUntil' => $s_valid_until, 'itemNumber1' => '1', 'itemDescription1' => $description, 'itemQuantity1' => '1', 'itemPrice1' => $amount, 'urlCancel' => $cancel_url, 'urlSuccess' => $success_url, 'urlError' => $error_url); // add filter @todo test $data = apply_filters('mgm_payment_button_data', $data, $tran_id, $this->module, $pack); // rabo changes if ($this->setting['aquirer'] == 'rabo_omnikassa') { // convert for rabobank $data = $this->_get_rabobank_data($data, $tran_id); } elseif ($this->setting['aquirer'] == 'sisow') { // convert for rabobank $data = $this->_get_sisow_data($data, $tran_id); } // update pack/transaction mgm_update_transaction(array('data' => json_encode($pack), 'module' => $this->module), $tran_id); // data return $data; }
/** * add * * @param array $data pack data * @param array $options */ public function add($data, $options = NULL) { global $wpdb; // init $columns = $tran_data = array(); // payment type $columns['payment_type'] = isset($data['buypost']) ? 'post_purchase' : 'subscription_purchase'; // user // IMPORTANT: user_id has to be passed alogn with pack details, otherwise logged in user id $tran_data['user_id'] = isset($options['user_id']) ? $options['user_id'] : mgm_get_user_id(); // register and purchase, capture post id if (isset($options['post_id'])) { $tran_data['post_id'] = (int) $options['post_id']; } // register and purchase postpack, capture postpack id & postpack post id if (isset($options['postpack_id'])) { $tran_data['postpack_id'] = (int) $options['postpack_id']; } if (isset($options['postpack_post_id'])) { $tran_data['postpack_post_id'] = (int) $options['postpack_post_id']; } // subscription option : create|upgrade|downgrade|extend if ($columns['payment_type'] == 'subscription_purchase') { // registration flag, @ToDo will use "subscription_option" next onwards // subscription option $tran_data['subscription_option'] = isset($options['subscription_option']) ? $options['subscription_option'] : 'create'; // new registration @todo @depracate $tran_data['is_registration'] = isset($options['is_registration']) ? 'Y' : 'N'; // another subscription purchase flag @todo @depracate $tran_data['is_another_membership_purchase'] = isset($options['is_another_membership_purchase']) ? 'Y' : 'N'; // another subscription purchase - if upgrade from prev pack // value should be reset once upgrade member object is replaced @todo @depracate $tran_data['multiple_upgrade_prev_packid'] = isset($options['multiple_upgrade_prev_packid']) ? $options['multiple_upgrade_prev_packid'] : ''; // registration user email notification flag after user is active - issue #1468 $tran_data['notify_user'] = isset($options['notify_user']) ? $options['notify_user'] : false; } // others // set system currency, will update at module level after module selection //issue #1602 if (!isset($data['currency']) || empty($data['currency'])) { $tran_data['currency'] = mgm_get_class('system')->get_setting('currency'); } else { $tran_data['currency'] = $data['currency']; } // ip $tran_data['client_ip'] = mgm_get_client_ip_address(); // payment email sent flag $tran_data['payment_email'] = 0; // merge with data $tran_data = array_merge($data, $tran_data); // set data $columns['data'] = json_encode($tran_data); // date $columns['transaction_dt'] = date('Y-m-d H:i:s'); // user id if (isset($tran_data['user_id']) && (int) $tran_data['user_id'] > 0) { // add $columns['user_id'] = $tran_data['user_id']; } // insert $wpdb->insert(TBL_MGM_TRANSACTION, $columns); // transaction id $id = $wpdb->insert_id; // run actions do_action('mgm_transaction_item_add', $id, $columns['payment_type']); // global do_action('mgm_transaction_item_add_' . $columns['payment_type'], $id); // individual // return return $id; }
/** * Admin user edit screen unsubscribe option process */ function mgm_admin_user_unsubscribe_process($user_ID = false, $return = false) { // get user if (!$user_ID) { $user_ID = mgm_get_user_id(); } // get form object if (is_object($user_ID)) { $user_ID = $user_ID->ID; } // member $member = mgm_get_member($user_ID); // init $user = new stdClass(); $user->ID = $user_ID; $html = ''; // error if (isset($_GET['unsubscribe_errors']) && !empty($_GET['unsubscribe_errors'])) { $errors = new WP_Error(); $errors->add('unsubscribe_errors', urldecode(strip_tags($_GET['unsubscribe_errors'])), isset($_GET['unsubscribed']) ? 'message' : 'error'); $html .= mgm_set_errors($errors, true); unset($errors); } $html .= mgm_get_admin_user_unsubscribe_status_button($member, $user); if (isset($member->other_membership_types) && is_array($member->other_membership_types) && count($member->other_membership_types) > 0) { foreach ($member->other_membership_types as $key => $memtypes) { $memtypes = mgm_convert_array_to_memberobj($memtypes, $user_ID); $html .= mgm_get_admin_user_unsubscribe_status_button($memtypes, $user); } } echo $html; }
/** * API helper method set payment type, used as wrapper for backward compatibility * * @param array $pack * @param string $currency * @return string $payment_type * @deprecated */ function _set_payment_type($pack, $currency = NULL) { // encript membership_type $membership_type = md5($pack['membership_type']); // user $user_id = mgm_get_user_id(); // currency if (!$currency) { $currency = mgm_get_class('system')->get_setting('currency'); } // ip address $ip_address = mgm_get_client_ip_address(); // custom string if (isset($pack['buypost'])) { // get_the_ID() $payment_type = implode('_', array('buypost', $pack['duration'], $pack['cost'], $currency, $user_id, $pack['post_id'], $ip_address)); // 'buypost_' . $pack['duration'] .'_'. $pack['cost'] .'_'. $currency .'_'. $user_id .'_' . $pack['post_id'] // . '_' . mgm_get_client_ip_address() ; } else { $payment_type = implode('_', array('subscription', $pack['duration'], $pack['cost'], $currency, $user_id, $membership_type, strtoupper($pack['duration_type']), $pack['role'], $ip_address, (int) $pack['hide_old_content'], (int) $pack['id'])); // 'subscription_' . $pack['duration'] .'_'. $pack['cost'] .'_'. $currency .'_'. $user_id .'_'. $membership_type . '_'. strtoupper($pack['duration_type']) // . '_' . $pack['role'] . '_' . mgm_get_client_ip_address() . '_' . (int)$pack['hide_old_content']. '_' . (int)$pack['id']; } // return return $payment_type; }
/** * edit custom fields */ function mgm_edit_custom_fields($user_ID = false, $submit_row = false, $return = false) { // get user if (!$user_ID) { $user_ID = mgm_get_user_id(); } // get form object if (is_object($user_ID)) { $user_ID = $user_ID->ID; } //check logged in user is super admin: $is_admin = is_super_admin() ? true : false; // system $system_obj = mgm_get_class('system'); // get custom_fields $profile_fields = mgm_get_config('default_profile_fields', array()); // get active custom fields on profile page //$cf_profile_page = mgm_get_class('member_custom_fields')->get_fields_where(array('display'=>array('on_profile'=>true))); //issue #844 - get active custom fields for profile page $cf_profile_pg = mgm_get_class('member_custom_fields'); $cf_profile_page = 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['display']['on_profile'] || $is_admin)) { $cf_profile_page[] = $field; } } } $member = mgm_get_member($user_ID); //this is a fix for issue#: 589, see the notes for details: //This is to read saved coupons as array in order to fix the fatal error on some servers. //This will change the object on each users profile view. //Also this will avoid using patch for batch update, $arr_coupon = array('upgrade', 'extend'); $oldcoupon_found = 0; foreach ($arr_coupon as $cpn_type) { if (isset($member->{$cpn_type}['coupon']) && is_object($member->{$cpn_type}['coupon'])) { $member->{$cpn_type}['coupon'] = (array) $member->{$cpn_type}['coupon']; $oldcoupon_found++; } } if ($oldcoupon_found) { $member->save(); } // user $user = get_userdata($user_ID); // init $html = ''; // capture $fields = array(); //default and readonly fields: $default_readonly = array(); $arr_images = array(); //issue #844 $skip_fileds = array('subscription_introduction', 'coupon', 'privacy_policy', 'payment_gateways', 'terms_conditions', 'subscription_options', 'autoresponder', 'captcha', 'show_public_profile'); // loop fields foreach ($cf_profile_page as $field) { // issue#: 255 if (in_array($field['name'], array_keys($profile_fields))) { //if custom field = defualt field, is read only if ($field['attributes']['readonly'] && !$is_admin) { $default_readonly[] = $profile_fields[$field['name']]['id']; //email and url id is different than custom fields: if (in_array($field['name'], array('email', 'url'))) { $default_readonly[] = $field['name']; } } continue; } //issue #844 if (in_array($field['name'], $skip_fileds)) { continue; } // init value $value = ''; //disable readonly for admin user(issue#: 515) $ro = $field['attributes']['readonly'] == true && !$is_admin ? 'readonly="readonly"' : false; // value if (isset($member->custom_fields->{$field}['name'])) { $value = $member->custom_fields->{$field}['name']; } // date if ($field['name'] == 'birthdate') { if ($value) { //convert saved date to input field format $value = mgm_get_datepicker_format('date', $value); } else { $value = ''; } $element = '<input type="text" name="mgm_profile_field[' . $field['name'] . ']" value="' . $value . '" ' . $ro . ' class="text ' . ($ro ? '' : 'mgm_date') . ' mgm_custom_profile_birthdate"/>'; } else { if ($field['name'] == 'country') { $countries = mgm_field_values(TBL_MGM_COUNTRY, 'code', 'name'); if ($ro) { $countries = !empty($value) ? array($value => $countries[$value]) : array(" " => " "); } //issue #1782 $value = !empty($value) ? $value : 'US'; $options = mgm_make_combo_options($countries, $value, MGM_KEY_VALUE); $element = '<select name="mgm_profile_field[' . $field['name'] . ']" > ' . $options . ' </select>'; } else { if ($field['type'] == 'text') { $element = '<input type="text" name="mgm_profile_field[' . $field['name'] . ']" value="' . $value . '" ' . $ro . ' class="text mgm_custom_profile_password"/>'; } else { if ($field['type'] == 'password') { continue; } else { if ($field['type'] == 'textarea') { $element = '<textarea name="mgm_profile_field[' . $field['name'] . ']" cols="40" rows="5" ' . $ro . '>' . $value . '</textarea>'; } else { if ($field['type'] == 'checkbox') { $options = preg_split('/[;,]/', $field['options']); //$values = preg_split('/[;,\s]/', $value); $values = @unserialize($value); // pass " " as value to prevent the default value getting selected, if no option is selected $values = empty($values) ? " " : $values; //Issue # 694 $element = mgm_make_checkbox_group('mgm_profile_field[' . $field['name'] . '][]', $options, $values, MGM_VALUE_ONLY, '', 'div'); } else { if ($field['type'] == 'checkboxg') { $options = preg_split('/[;,]/', $field['options']); if (!is_array($value)) { $values = @unserialize($value); } else { $values = $value; } $values = empty($values) ? " " : $values; $element = mgm_make_checkbox_group('mgm_profile_field[' . $field['name'] . '][]', $options, $values, MGM_VALUE_ONLY, '', 'div'); } else { if ($field['type'] == 'radio') { $options = preg_split('/[;,]/', $field['options']); $element = mgm_make_radio_group('mgm_profile_field[' . $field['name'] . ']', $options, $value, MGM_VALUE_ONLY); } else { if ($field['type'] == 'select') { $element = '<select name="mgm_profile_field[' . $field['name'] . ']" ' . $ro . '>'; $options = preg_split('/[;,]/', $field['options']); if ($ro) { $options = !empty($value) ? array($value => $value) : array(" " => " "); } $element .= mgm_make_combo_options($options, $value, MGM_VALUE_ONLY); $element .= '</select>'; } else { if ($field['type'] == 'selectm') { $element = '<select name="mgm_profile_field[' . $field['name'] . '][]" ' . $ro . ' multiple>'; $options = preg_split('/[;,]/', $field['options']); if ($ro) { $options = !empty($value) ? array($value => $value) : array(" " => " "); } $element .= mgm_make_combo_options($options, $value, MGM_VALUE_ONLY); $element .= '</select>'; } else { if ($field['type'] == 'html') { $element = ''; $element .= '<div class="mgm_custom_subs_introduction">' . html_entity_decode(mgm_stripslashes_deep($field['value'])) . '</div>'; } else { if ($field['type'] == 'image') { $form_fields = new mgm_form_fields(); $element = $form_fields->get_field_element($field, 'mgm_profile_field', $value); if (!in_array($field['name'], $arr_images)) { $arr_images[] = $field['name']; } //issue #1258 } else { if ($field['type'] == 'label') { $form_fields = new mgm_form_fields(); $element = $form_fields->get_field_element($field, 'mgm_profile_field', $value); } } } } } } } } } } } } } // set array if ($element) { $fields[] = array('name' => $field['name'], 'label' => $field['label'], 'field' => $element); } } // if fields - issue #1782 if (count($fields)) { $html .= '<table class="form-table">'; foreach ($fields as $i => $row) { $html .= '<tr><th><label>' . mgm_stripslashes_deep($row['label']) . '</label></th>'; $html .= '<td>' . $row['field'] . '</td></tr>'; } // button if ($submit_row) { $html .= '<tr> <td colspan="2"> <input class="button" type="submit" name="submit" value="' . __('Update your profile', 'mgm') . '"/> <input type="hidden" name="update_mgm_custom_fields_submit" value="1" /> </td></tr>'; } $html .= '</table>'; $html .= mgm_attach_scripts(true, array()); $yearRange = mgm_get_calendar_year_range(); //include scripts for image upload: if (!empty($arr_images)) { $html .= mgm_upload_script_js('your-profile', $arr_images); } $html .= '<script language="javascript">jQuery(document).ready(function(){try{mgm_date_picker(".mgm_date",false,{yearRange:"' . $yearRange . '", dateFormat: "' . mgm_get_datepicker_format() . '"});}catch(x){}});</script>'; } if (!empty($default_readonly)) { $html .= '<script language="javascript">'; $html .= 'jQuery(document).ready(function(){try{'; $html .= 'jQuery.each(' . json_encode($default_readonly) . ', function(){jQuery("#"+this).attr("readonly", true)})'; $html .= '}catch(x){}})'; $html .= '</script>'; } // return if ($return) { return $html; } else { echo $html; } }