예제 #1
0
 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;
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
 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__);
         }
     }
 }
예제 #4
0
?>

	<form name="frmmgmupgrade" id="frmmgmupgrade" action="admin-ajax.php?action=mgm_admin_ajax_action&page=mgm/admin/tools&method=upgrade" method="post">
	<div class="table form-table width100">
  		<div class="row">
    		<div class="cell">
				<?php 
// _e('No Upgrade available','mgm')
?>

				<div id="update_data">
					<?php 
// load remote data
$upgrade_url = MGM_SERVICE_SITE . 'upgrade_screen' . MGM_INFORMATION;
//.'&new_version='.$_REQUEST['new_version'];
echo mgm_remote_get($upgrade_url, NULL, NULL, 'Could not connect');
?>

				</div>	
			</div>
		</div>
		<!--<div class="row">
    		<div class="cell">
				<p>					
					<input type="button" class="button" onclick="core_setup()" value="<?php 
//_e('UPGRADE','mgm')
?>
" disabled="disabled" />
				</p>
			</div>
		</div>-->	
예제 #5
0
 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;
 }