/**
 * Send Email Notification to Admin on Post Purchase
 *
 * @uses mgm_notify_admin()
 * @param string $blogname
 * @param object $user
 * @param object $post
 * @param string $status
 * @return bool $send
 */
function mgm_notify_admin_post_purchase($blogname, $user, $post, $status)
{
    //post link
    $link = "<a href=" . get_permalink($post->ID) . ">" . $post->post_title . "</a>";
    // not for guest
    if (isset($user->ID)) {
        $subject = sprintf("[%s] Admin Notification - %s purchased post: %s [%d]", $blogname, $user->user_email, $post->post_title, $post->ID);
        $message = sprintf("User display name: %s<br />\n\t\t\t                User email: %s<br />\n\t\t\t                User ID: %s<br />\n\t\t            \t\tStatus: %s<br />\n\t\t            \t\tAction: Purchase post <br/>\n\t\t            \t\tPost Title: %s \n\t\t\t\t\t\t\tPost Link: %s", $user->display_name, $user->user_email, $user->ID, $status, $post->post_title, $link);
    } else {
        $subject = sprintf("[%s] Admin Notification - Guest[IP: %s] purchased post: %s [%d]", $blogname, mgm_get_client_ip_address(), $post->post_title, $post->ID);
        $message = sprintf("Action: Guest Purchase post <br/>\n\t\t            \t\tPost Title: %s \n\t\t\t\t\t\t\tPost Link: %s", $post->post_title, $link);
    }
    // return
    return @mgm_notify_admin(null, $subject, $message);
}
Exemplo n.º 2
0
 function _buy_post()
 {
     global $wpdb;
     // get system settings
     $system_obj = mgm_get_class('system');
     $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
     $dpne = bool_from_yn($system_obj->get_setting('disable_payment_notify_emails'));
     // get passthrough, stop further process if fails to parse
     $custom = $this->_get_transaction_passthrough($_POST['M_custom']);
     // local var
     extract($custom);
     // find user
     //issue #504
     if ($user_id) {
         $user = get_userdata($user_id);
     }
     $blogname = get_option('blogname');
     $tran_success = false;
     //getting purchase post title and & price - issue #981
     $post_obj = mgm_get_post($post_id);
     $purchase_cost = mgm_convert_to_currency($post_obj->purchase_cost);
     $post = get_post($post_id);
     $post_title = $post->post_title;
     // errors
     $errors = array();
     // check
     switch ($_POST['transStatus']) {
         case "Y":
             // status success
             $tran_success = true;
             // status str
             $status_str = __('Last payment was successful', 'mgm');
             //issue #504
             if ($user_id) {
                 // subject
                 $subject = $system_obj->get_template('payment_success_email_template_subject', array('blogname' => $blogname), true);
                 // body
                 $message = $system_obj->get_template('payment_success_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'post_title' => $post_title, 'purchase_cost' => $purchase_cost, 'email' => $user->user_email, 'admin_email' => $system_obj->setting['admin_email']), true);
             }
             // transaction id
             $transaction_id = $this->_get_transaction_id('M_custom');
             // hook args
             $args = array('post_id' => $post_id, 'transaction_id' => $transaction_id);
             // user purchase
             if (isset($user_id) && (int) $user_id > 0) {
                 $args['user_id'] = $user_id;
             } else {
                 // guest purchase
                 $args['guest_token'] = $guest_token;
             }
             // after succesful payment hook
             do_action('mgm_buy_post_transaction_success', $args);
             // backward compatibility
             do_action('mgm_post_purchase_payment_success', $args);
             // new organized name
             break;
         case "C":
             // status
             $status_str = __('Last payment was refunded or denied', 'mgm');
             //issue #504
             if ($user_id) {
                 // subject
                 $subject = $system_obj->get_template('payment_failed_email_template_subject', array('blogname' => $blogname), true);
                 // body
                 $message = $system_obj->get_template('payment_failed_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'post_title' => $post_title, 'purchase_cost' => $purchase_cost, 'email' => $user->user_email, 'payment_type' => 'post purchase payment', 'reason' => $status_str, 'admin_email' => $system_obj->setting['admin_email']), true);
             }
             // error
             $errors[] = $status_str;
             break;
         case "F":
             // reason
             $reason = 'Unknown';
             // status
             $status_str = sprintf(__('Last payment is pending. Reason: %s', 'mgm'), $reason);
             //issue #504
             if ($user_id) {
                 // subject
                 $subject = $system_obj->get_template('payment_pending_email_template_subject', array('blogname' => $blogname), true);
                 // body
                 $message = $system_obj->get_template('payment_pending_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'post_title' => $post_title, 'purchase_cost' => $purchase_cost, 'email' => $user->user_email, 'reason' => $status_str, 'admin_email' => $system_obj->setting['admin_email']), true);
             }
             // error
             $errors[] = $status_str;
             break;
         default:
             // status
             $status_str = sprintf(__('Last payment status: %s', 'mgm'), $_POST['rawAuthMessage']);
             //issue #504
             if ($user_id) {
                 // subject
                 $subject = $system_obj->get_template('payment_unknown_email_template_subject', array('blogname' => $blogname), true);
                 // body
                 $message = $system_obj->get_template('payment_unknown_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'post_title' => $post_title, 'purchase_cost' => $purchase_cost, 'email' => $user->user_email, 'reason' => $status_str, 'admin_email' => $system_obj->setting['admin_email']), true);
             }
             // error
             $errors[] = $status_str;
     }
     // do action
     do_action('mgm_return_post_purchase_payment_' . $this->module, array('post_id' => $post_id));
     // new, individual
     do_action('mgm_return_post_purchase_payment', array('post_id' => $post_id));
     // new, global
     // notify user
     if (!$dpne) {
         if ($user_id && $this->send_payment_email($_POST['M_custom'])) {
             //issue #862
             $subject = mgm_replace_email_tags($subject, $user_id);
             $message = mgm_replace_email_tags($message, $user_id);
             mgm_mail($user->user_email, $subject, $message);
             //send an email to the buyer
             //update as email sent
             $this->update_paymentemail_sent($_POST['M_custom']);
         }
     }
     $status = __('Failed join', 'mgm');
     //overridden on a successful payment
     if ($tran_success) {
         //issue #1421
         if ($user_id) {
             do_action('mgm_update_coupon_usage', array('user_id' => $user_id));
         }
         // mark as purchased
         if (isset($guest_token)) {
             // issue #1421
             if (isset($coupon_id) && isset($coupon_code)) {
                 do_action('mgm_update_coupon_usage', array('guest_token' => $guest_token, 'coupon_id' => $coupon_id));
                 $this->_set_purchased(NULL, $post_id, $guest_token, $_POST['M_custom'], $coupon_code);
             } else {
                 $this->_set_purchased(NULL, $post_id, $guest_token, $_POST['M_custom']);
             }
         } else {
             $this->_set_purchased($user_id, $post_id, NULL, $_POST['M_custom']);
         }
         // status
         $status = __('The post was purchased successfully', 'mgm');
     }
     // transaction status
     mgm_update_transaction_status($_POST['M_custom'], $status, $status_str);
     // notify admin, only if gateway emails on
     if (!$dge) {
         // not for guest
         if ($user_id) {
             $subject = "[" . $blogname . "] Admin Notification: " . $user->user_email . " purchased post " . $post_id;
             $message = "User display name: {$user->display_name}<br />User email: {$user->user_email}<br />User ID: {$user->ID}<br />Status: " . $status . "<br />Action: Purchase post:" . $subject . "<br /><br />" . $message . "<br /><br /><pre>" . print_r($_POST, true) . '</pre>';
         } else {
             $subject = "[" . $blogname . "] Admin Notification: Guest[IP: " . mgm_get_client_ip_address() . "] purchased post " . $post_id;
             $message = "Guest Purchase";
         }
         mgm_mail($system_obj->setting['admin_email'], $subject, $message);
     }
     // error condition redirect
     if (count($errors) > 0) {
         $this->_meta_redirect(add_query_arg(array('status' => 'error', 'errors' => implode('|', $errors)), $this->_get_thankyou_url()));
     }
 }
 private function _log_request($api_key, $authorized)
 {
     global $wpdb;
     // sql data
     $sql_data = array();
     // set
     $sql_data['api_key'] = $api_key;
     $sql_data['uri'] = $this->request->uri_string;
     $sql_data['method'] = $this->request->verb;
     $sql_data['params'] = json_encode($this->request->data['global']);
     $sql_data['ip_address'] = mgm_get_client_ip_address();
     $sql_data['is_authorized'] = $authorized === TRUE ? 'Y' : 'N';
     $sql_data['create_dt'] = date('Y-m-d H:i:s');
     // insert
     $wpdb->insert(TBL_MGM_REST_API_LOG, $sql_data);
 }
Exemplo n.º 4
0
 /**
  * Calls an HTTP POST function to verify if the user's guess was correct
  * @param string $privkey
  * @param string $remoteip
  * @param string $challenge
  * @param string $response
  * @param array $extra_params an array of extra variables to post to the server
  * @return ReCaptchaResponse
  */
 function recaptcha_check_answer($challenge, $response, $extra_params = array())
 {
     //system settings
     $recaptcha_response = new stdClass();
     $recaptcha_response->error = null;
     $setting = mgm_get_class('system')->get_setting();
     $use_ssl = isset($_SERVER['https']) ? true : false;
     $remoteip = mgm_get_client_ip_address();
     if (empty($setting['recaptcha_private_key']) || empty($setting['recaptcha_public_key'])) {
         $recaptcha_response->is_valid = false;
         $recaptcha_response->error = __("reCAPTCHA API keys are blank. ", 'mgm');
         return $recaptcha_response;
     }
     if ($remoteip == null || $remoteip == '') {
         $recaptcha_response->is_valid = false;
         $recaptcha_response->error = __("For security reasons, you must pass the remote IP to reCAPTCHA", 'mgm');
         return $recaptcha_response;
     }
     //discard spam submissions
     if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
         $recaptcha_response->is_valid = false;
         $recaptcha_response->error = __('The Captcha String isn\'t correct', 'mgm');
         return $recaptcha_response;
     }
     $response = $this->_recaptcha_http_post($setting['recaptcha_verify_server'], "/recaptcha/api/verify", array('privatekey' => $setting['recaptcha_private_key'], 'remoteip' => $remoteip, 'challenge' => $challenge, 'response' => $response) + $extra_params);
     $recaptcha_response->is_valid = $response['status'];
     if (isset($response['error'])) {
         $recaptcha_response->error = __('The Captcha String isn\'t correct', 'mgm');
     }
     return $recaptcha_response;
 }
Exemplo n.º 5
0
            $this->_set_purchased(NULL, $post_id, $guest_token, $_POST['custom']);
        }
    } else {
        $this->_set_purchased($user_id, $post_id, NULL, $_POST['custom']);
    }
    // status
    $status = __('The post was purchased successfully', 'mgm');
}
// notify admin, only if gateway emails on
if (!$dge) {
    // not for guest
    if ($user_id) {
        $subject = "[" . $blogname . "] Admin Notification: " . $user->user_email . " purchased post " . $post_id;
        $message = "User display name: {$user->display_name}<br />User email: {$user->user_email}<br />User ID: {$user->ID}<br />\n\t\t           Status: " . $status . "<br />Action: Purchase post:" . $subject . "<br /><br />" . $message . "<br /><br />\n\t\t\t\t   <pre>" . print_r($_POST, true) . '</pre>';
    } else {
        $subject = "[" . $blogname . "] Admin Notification: Guest[IP: " . mgm_get_client_ip_address() . "] purchased post " . $post_id;
        $message = "Guest Purchase";
    }
    mgm_mail($system_obj->setting['admin_email'], $subject, $message);
}
if (!$dge) {
    $message = 'Could not read membership type in the following POST 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($_POST, true) . '</pre>';
    // mail
    mgm_mail($system_obj->setting['admin_email'], 'Error in ' . ucwords($this->module) . ' membership verification', $message);
}
// on status
switch ($member->status) {
    case MGM_STATUS_ACTIVE:
        //Sending notification email to user - issue #1468
        if ($notify_user && $is_registration == 'Y') {
            $user_pass = mgm_decrypt_password($member->user_password, $user_id);
 /**	
  * 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;
 }
 /**
  * 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
 }
 function get_proxy($url)
 {
     // fields
     $fields = $this->postfields;
     // init result
     $result = array();
     // obj
     $jsonrpc = new mgm_jsonrpc_client($url);
     // campaigns
     $campaigns = $jsonrpc->get_campaigns($fields['campaign_ref'], array('name' => array('EQUALS' => $fields['campaign_name'])));
     // validate
     if (is_array($campaigns) && count($campaigns) > 0) {
         // campaign_id
         $campaign_id = array_shift(array_keys($campaigns));
         // check
         if ($campaign_id) {
             // campaign fields
             $campaign_fields = array('campaign' => $campaign_id, 'action' => 'standard', 'email' => $fields['email'], 'cycle_day' => 0, 'ip' => mgm_get_client_ip_address());
             // append extra
             foreach ($this->postfields as $field => $value) {
                 // set, skip already set and base ones
                 if (!isset($campaign_fields[$field]) && !in_array($field, array('campaign_name', 'campaign_ref'))) {
                     $campaign_fields['customs'][] = array('name' => strtolower($field), 'content' => $value);
                 }
             }
             // add to campaign
             return $result = $jsonrpc->add_contact($fields['campaign_ref'], $campaign_fields);
         }
     }
     // return as executed
     return true;
 }
Exemplo n.º 9
0
 /**
  * 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;
 }
Exemplo n.º 10
0
 function _buy_post()
 {
     global $wpdb;
     // system
     $system_obj = mgm_get_class('system');
     $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
     $dpne = bool_from_yn($system_obj->get_setting('disable_payment_notify_emails'));
     // get passthrough, stop further process if fails to parse
     $custom = $this->_get_transaction_passthrough($_REQUEST['custom']);
     // local var
     extract($custom);
     // find user
     if ($user_id) {
         $user = get_userdata($user_id);
     }
     // blog
     $blogname = get_option('blogname');
     //getting purchase post title and & price - issue #981
     $post_obj = mgm_get_post($post_id);
     $purchase_cost = mgm_convert_to_currency($post_obj->purchase_cost);
     $post = get_post($post_id);
     $post_title = $post->post_title;
     // tran
     $tran_success = false;
     // status success
     $tran_success = true;
     // status
     $status_str = __('Last payment was successful', 'mgm');
     // emails not for guest
     if ($user_id) {
         // subject
         $subject = $system_obj->get_template('payment_success_email_template_subject', array('blogname' => $blogname), true);
         // body
         $message = $system_obj->get_template('payment_success_email_template_body', array('blogname' => $blogname, 'name' => $user->display_name, 'post_title' => $post_title, 'purchase_cost' => $purchase_cost, 'email' => $user->user_email, 'admin_email' => $system_obj->setting['admin_email']), true);
         //update coupon usage - issue #1421
         do_action('mgm_update_coupon_usage', array('user_id' => $user_id));
     }
     // transation id
     $transaction_id = $this->_get_transaction_id('custom', $_REQUEST);
     // hook args
     $args = array('post_id' => $post_id, 'transaction_id' => $transaction_id);
     // user purchase
     if (isset($user_id) && (int) $user_id > 0) {
         $args['user_id'] = $user_id;
     } else {
         // guest purchase
         $args['guest_token'] = $guest_token;
     }
     // after succesful payment hook
     do_action('mgm_buy_post_transaction_success', $args);
     // backward compatibility
     do_action('mgm_post_purchase_payment_success', $args);
     // new organized name
     // do action
     do_action('mgm_return_post_purchase_payment_' . $this->module, array('post_id' => $post_id));
     // new, individual
     do_action('mgm_return_post_purchase_payment', array('post_id' => $post_id));
     // new, global
     // notify user
     if (!$dpne) {
         // mail
         if ($user_id && $this->send_payment_email($_REQUEST['custom'])) {
             //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);
             //send an email to the buyer
             //update as email sent
             $this->update_paymentemail_sent($_REQUEST['custom']);
         }
     }
     // mark as purchased
     if (isset($guest_token)) {
         // issue #1421
         if (isset($coupon_id) && isset($coupon_code)) {
             do_action('mgm_update_coupon_usage', array('guest_token' => $guest_token, 'coupon_id' => $coupon_id));
             $this->_set_purchased(NULL, $post_id, $guest_token, $_REQUEST['custom'], $coupon_code);
         } else {
             $this->_set_purchased(NULL, $post_id, $guest_token, $_REQUEST['custom']);
         }
     } else {
         $this->_set_purchased($user_id, $post_id, NULL, $_REQUEST['custom']);
     }
     // status
     $status = __('The post was purchased successfully', 'mgm');
     // transaction status
     mgm_update_transaction_status($_REQUEST['custom'], $status, $status_str);
     // notify admin, only if gateway emails on
     if (!$dge) {
         // not for guest
         if ($user_id) {
             // subject
             $subject = "[" . $blogname . "] Admin Notification: " . $user->user_email . " purchased post " . $post_id;
             // message
             $message = "User display name: {$user->display_name}<br />\r\r\n\t\t\t\t\t\t\tUser email: {$user->user_email}<br />\r\r\n\t\t\t\t\t\t\tUser ID: {$user->ID}<br />Status: " . $status . "<br />\r\r\n\t\t\t\t\t\t\tAction: Purchase post:" . $subject . "<br /><br />" . $message;
         } else {
             $subject = "[" . $blogname . "] Admin Notification: Guest[IP: " . mgm_get_client_ip_address() . "] purchased post " . $post_id;
             $message = "Guest Purchase";
         }
         // mail
         mgm_mail($system_obj->setting['admin_email'], $subject, $message);
     }
 }
Exemplo n.º 11
0
/**
 * record logout at
 *
 * @since 1.8.38 
 */
function mgm_record_logout_at()
{
    //logout pack-user(multiple)
    global $wpdb;
    // ip
    $ip_address = mgm_get_client_ip_address();
    // user
    $user = wp_get_current_user();
    $member = mgm_get_member($user->ID);
    // update at logout time
    $sql = "UPDATE  `" . TBL_MGM_MULTIPLE_LOGIN_RECORDS . "` SET `logout_at` = NOW() \r\r\n\t      WHERE `user_id` = '{$user->ID}' AND `pack_id` = '{$member->pack_id}' \r\r\n\t      AND `ip_address` = '{$ip_address}'";
    $wpdb->query($sql);
}
Exemplo n.º 12
0
 /**
  * verify dataplus post
  */
 function _verify_dataplus_post()
 {
     // ips
     $epoch_ips = $this->_get_epoch_dataplus_ips();
     // test ip
     $request_ip = mgm_get_client_ip_address();
     //'65.17.248.99';//
     // match
     $match = false;
     // matach
     foreach ($epoch_ips as $epoch_ip) {
         // check
         if (preg_match('#^' . preg_quote($epoch_ip) . '#', $request_ip)) {
             $match = true;
             break;
         }
     }
     // log
     mgm_log('request_ip: ' . $request_ip . ' match:' . (int) $match, __FUNCTION__);
     // return
     return $match;
 }
/**
 * verify transaction
 */
function mgm_verify_transaction($transaction)
{
    //check IP
    if (!isset($transaction['data']['client_ip']) || isset($transaction['data']['client_ip']) && $transaction['data']['client_ip'] != mgm_get_client_ip_address()) {
        //treat as fraud if try from different IP
        return false;
    }
    //check datetime:
    if (!isset($transaction['transaction_dt']) || isset($transaction['transaction_dt']) && strtotime(date('Y-m-d H:i:s')) - strtotime($transaction['transaction_dt']) > 60 * 10) {
        //delay is restricted to 10 minutes
        return false;
    }
    if ($transaction['status'] != MGM_STATUS_ACTIVE) {
        return false;
    }
    return true;
}