/**
     * 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)) {
            $post_data = '<ARBGetSubscriptionStatusRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
							<merchantAuthentication>
								<name>' . $this->setting['loginid'] . '</name>
								<transactionKey>' . $this->setting['tran_key'] . '</transactionKey>
							</merchantAuthentication>
							<subscriptionId>' . $member->payment_info->subscr_id . '</subscriptionId>
						</ARBGetSubscriptionStatusRequest>';
            // end  point
            $endpoint = $this->_get_endpoint($this->status . '_arb');
            // test_arb, live_aim etc.
            // headers
            $http_headers = array('Content-Type' => 'text/xml');
            // create curl post
            $http_response = mgm_remote_post($endpoint, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
            // $this->_curl_post($endpoint, $content, array("Content-Type: text/xml") );
            // parse response
            $this->_process_response('subscription_status', $http_response);
            // check
            if (isset($this->response['subscription_status'])) {
                // old status
                $old_status = $member->status;
                // set status
                switch (strtolower($this->response['subscription_status'])) {
                    case 'active':
                        // set new status
                        $member->status = $new_status = MGM_STATUS_ACTIVE;
                        // status string
                        $member->status_str = __('Last payment cycle processed successfully', 'mgm');
                        // get transaction
                        $tran_response = $this->get_transaction_details($member);
                        // last pay date
                        $member->last_pay_date = isset($tran_response['transDate']) && !empty($tran_response['transDate']) ? date('Y-m-d', strtotime($tran_response['transDate'])) : date('Y-m-d');
                        // expire date
                        if (isset($tran_response['transDate']) && !empty($tran_response['transDate']) && !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;
                                }
                                //issue #1678 & 1736 - some times proccessing Authorize.net declined transactions so added check here, based on last pay date form gateway
                                $temp_new_expire_date = date('Y-m-d', strtotime($new_expire_date));
                                $temp_expire_date = date('Y-m-d', strtotime($member->expire_date));
                                // date mistmatch
                                if (strtotime($temp_new_expire_date) < strtotime($temp_expire_date) || strtotime($temp_new_expire_date) == strtotime($temp_expire_date) && time() > strtotime($member->expire_date)) {
                                    /*// set new status
                                    		$member->status = $new_status = MGM_STATUS_EXPIRED;
                                    		// status string
                                    		$member->status_str = __('Last payment cycle expired','mgm');
                                    		//expire date
                                    		$member->expire_date = $new_expire_date;*/
                                    // #1736 final fix
                                    // verify txn id exists again
                                    $this->_fetch_merchant_txn_id($member, true);
                                }
                            } 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;
                                }
                            }
                        }
                        // expire on error
                        if (isset($tran_response['response_status']) && (int) $tran_response['response_status'] == 5) {
                            // set as expired
                            $member->status = $new_status = MGM_STATUS_EXPIRED;
                            // status string
                            $member->status_str = sprintf(__('Last payment cycle expired. %s', 'mgm'), $tran_response['message_text']);
                            //expire date
                            $member->expire_date = $member->last_pay_date;
                        }
                        // set eway txn no
                        if (isset($tran_response['transId'])) {
                            $member->payment_info->authorizenet_txn_id = $tran_response['transId'];
                        }
                        // set eway txn no
                        if (isset($tran_response['batchId'])) {
                            $member->payment_info->authorizenet_batch_id = $tran_response['batchId'];
                        }
                        // 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 'canceled':
                        // 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 'suspended':
                    case 'terminated':
                    case 'expired':
                        // set new statis
                        $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
    }
 /**
  * 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
 }
예제 #3
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
  */
 function query_rebill_status($user_id, $member = NULL)
 {
     // check
     if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) {
         // id
         $subscr_id = $member->payment_info->subscr_id;
         // check
         if ($this->response = $this->_get_api_notify('get_customer', null, $subscr_id)) {
             // log
             mgm_log($this->response, $this->module . '_' . __FUNCTION__);
             // old status
             $old_status = $member->status;
             // check
             $subscription_status = 'not found';
             if (isset($this->response->subscription->status) && !empty($this->response->subscription->status)) {
                 $subscription_status = strtolower($this->response->subscription->status);
             }
             // log
             mgm_log('subscription_status: ' . $subscription_status, $this->module . '_' . __FUNCTION__);
             // set status
             switch ($subscription_status) {
                 case 'active':
                 case 'trialing':
                     // set new status
                     $member->status = $new_status = MGM_STATUS_ACTIVE;
                     // status string
                     $member->status_str = __('Last payment cycle processed successfully', 'mgm');
                     // start date
                     $current_period_start = $this->response->subscription->current_period_start;
                     // trial fix
                     if ('trialing' == $subscription_status) {
                         // expire
                         if (empty($member->expire_date)) {
                             $member->expire_date = date('Y-m-d', $this->response->subscription->trial_end);
                         }
                         // start date
                         $current_period_start = $this->response->subscription->trial_start;
                         // status string
                         $member->status_str = __('Last trial cycle processed successfully', 'mgm');
                     }
                     // last pay date
                     $member->last_pay_date = isset($current_period_start) && !empty($current_period_start) ? date('Y-m-d', $current_period_start) : date('Y-m-d');
                     // expire date
                     if (isset($current_period_start) && !empty($current_period_start) && !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 'canceled':
                     // 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;
                         // set reset date
                         $member->cancel_date = date('Y-m-d', $this->response->subscription->canceled_at);
                         // $member->expire_date;
                         // 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 'suspended':
                 case 'terminated':
                 case 'expired':
                 case 'error':
                 case 'not found':
                 case 'past_due':
                 default:
                     // set new statis
                     $member->status = $new_status = MGM_STATUS_EXPIRED;
                     // status string
                     $member->status_str = sprintf(__('Last payment cycle expired, subscription: %s.', 'mgm'), $subscription_status);
                     // save
                     $member->save();
                     break;
             }
             // action
             if (isset($new_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
 }
예제 #4
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;
 }
예제 #5
0
 /**
  * Specifically check recurring status of each rebill for an expiry date
  * As Eway doesn't have an 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->rebill_customerid) && !empty($member->payment_info->rebill_customerid) && isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) {
         //if settings are blank
         if (empty($this->setting['username']) || empty($this->setting['password']) || empty($this->setting['customer_id'])) {
             return false;
         }
         // eway time
         $eway_time = $this->_datetime_to_eway_serverdatetime(date('Y-m-d H:i:s'));
         // check rebill start date
         if (!isset($member->payment_info->rebill_start_date) || isset($member->payment_info->rebill_start_date) && strtotime($eway_time) <= strtotime($member->payment_info->rebill_start_date)) {
             // log
             mgm_log(sprintf('Exit flag since rebill start date not reached Eway Time Today: %s, Rebill Start Date: %s', $eway_time, $member->payment_info->rebill_start_date), $this->module . '_' . __FUNCTION__);
             // return
             return false;
         }
         // setup
         $gateway_method = 'webservice';
         $secure = array('CustomerID' => $this->setting['customer_id'], 'Username' => $this->setting['username'], 'Password' => $this->setting['password']);
         // packs
         $s_packs = mgm_get_class('subscription_packs');
         // pack
         $pack = $s_packs->get_pack((int) $member->pack_id);
         // durations
         $duration_exprs = $s_packs->get_duration_exprs();
         // time
         $time = time();
         // start date is last pay date as per pack
         $start_date = date('Y-m-d', strtotime(sprintf('- %d %s', $pack['duration'], $duration_exprs[$pack['duration_type']]), $time));
         // end date is today
         $end_date = date('Y-m-d', $time);
         //data to post
         $post_data = array('Option1' => $member->payment_info->txn_id, 'webservice_action' => 'QueryTransactions', 'RebillCustomerID' => $member->payment_info->rebill_customerid, 'RebillID' => $member->payment_info->subscr_id, 'startDate' => $start_date, 'endDate' => $end_date);
         // merge
         $post_data = array_merge($post_data, $secure);
         // filter post data and create soap xml
         $post_string = $this->_filter_postdata($gateway_method, $post_data);
         // endpoint
         $endpoint = $this->_get_endpoint($this->status . '_' . $gateway_method);
         // test_webservice / live_webservice
         // headers
         $http_headers = $this->_get_http_headers($gateway_method, $post_data['webservice_action']);
         // log
         mgm_log('Request Headers [' . $post_data['webservice_action'] . ']' . mgm_pr($http_headers, true), __FUNCTION__);
         // log
         mgm_log('Request [' . $post_data['webservice_action'] . ']' . $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 [' . $post_data['webservice_action'] . ']' . $http_response, __FUNCTION__);
         /*// header
         		$http_header = array('User-Agent: NuSOAP/0.9.5 (1.123)', 'Content-Type: text/xml; charset=ISO-8859-1', 
         		                     sprintf('SOAPAction: "http://www.eway.com.au/gateway/rebill/manageRebill/%s"', $post_data['webservice_action']));*/
         // post soap data
         // $buffer = $this->_curl_post($endpoint, $post_string, $http_header);
         // parse response
         $this->_process_response($gateway_method, $http_response, $post_data['webservice_action']);
         // log
         mgm_log('Response Parsed [' . $post_data['webservice_action'] . ']' . mgm_pr($this->response, true), __FUNCTION__);
         // check
         if (isset($this->response['response_status'])) {
             // old status
             $old_status = $member->status;
             // get response code
             $response_code = $this->_get_response_code($this->response['response_status'], 'status');
             // log
             mgm_log('Response Code' . $response_code, __FUNCTION__);
             // process on response code
             switch ($response_code) {
                 case 'Approved':
                     // 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['transactiondate']) ? date('Y-m-d', strtotime($this->response['transactiondate'])) : date('Y-m-d');
                     // expire date
                     if (isset($this->response['transactiondate']) && !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;
                             }
                         }
                     }
                     // set eway txn no
                     if (isset($this->response['transactionnumber'])) {
                         $member->payment_info->eway_txn_id = $this->response['transactionnumber'];
                     }
                     // 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 (!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
 }
예제 #6
0
 function process_rebill_status($user_id, $member = NULL)
 {
     // record POST/GET data
     do_action('mgm_print_module_data', $this->module, __FUNCTION__);
     // member
     if (!$member) {
         $member = mgm_get_member($user_id);
     }
     // set
     if (isset($_REQUEST['Success']) && $_REQUEST['Success'] == 1) {
         // old status
         $old_status = $member->status;
         // 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 = date('Y-m-d');
         // expire date
         if (isset($member->last_pay_date) && !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();
         // 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, 'notify');
             // query or notify
         }
     }
     // log
     // mgm_log($member, ($this->module . '_' . __FUNCTION__));
     // 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
  */
 function query_rebill_status($user_id, $member = NULL)
 {
     // check
     if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) {
         // check pack
         if (isset($member->pack_id)) {
             if ($pack = mgm_get_subscription_package($member->pack_id)) {
                 // 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 false;
                 }
             }
         }
         // add internal vars
         $data = array('PARTNER' => $this->setting['partner'], 'VENDOR' => $this->setting['vendor'], 'USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'TRXTYPE' => 'R', 'TENDER' => 'C', 'ACTION' => 'I', 'ORIGPROFILEID' => $member->payment_info->subscr_id);
         // log
         mgm_log($data, $this->module . '_' . __FUNCTION__);
         // data
         $data_str = _http_build_query($data, null, '&', '', false);
         // do not urlencode
         // post url
         $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_str, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // respomse
         $response = array();
         // parse
         parse_str($http_response, $response);
         // log
         mgm_log($response, $this->module . '_' . __FUNCTION__);
         // check
         if (isset($response['STATUS'])) {
             // old status
             $old_status = $member->status;
             // set status
             switch ($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
                     $last_pay_date = date('Y-m-d');
                     // today
                     // date to add
                     $date_add = mgm_get_pack_cycle_date((int) $member->pack_id, $member);
                     // date to add
                     if (isset($response['NEXTPAYMENT']) && !empty($response['NEXTPAYMENT'])) {
                         // convert to date
                         $response['NEXTPAYMENT'] = $this->_maketime($response['NEXTPAYMENT']);
                         // make time
                         // check
                         if ($date_add !== false) {
                             // new expire date should be later than current expire date, #1223
                             $last_pay_date = strtotime(str_replace('+', '-', $date_add), $response['NEXTPAYMENT']);
                             // start date
                             // $response['START'] = $this->_maketime($response['START']); // mmddyyyy
                             // check before start date
                             if ($last_pay_date < $member->join_date) {
                                 $last_pay_date = $member->join_date;
                             }
                             // format
                             $last_pay_date = date('Y-m-d', $last_pay_date);
                         }
                     }
                     // last pay date
                     $member->last_pay_date = $last_pay_date;
                     //date('Y-m-d', strtotime($last_pay_date));
                     // last pay date
                     // $member->last_pay_date = (isset($response['LASTPAYMENTDATE'])) ? date('Y-m-d', strtotime($response['LASTPAYMENTDATE'])) : date('Y-m-d');
                     // expire date
                     if (isset($response['NEXTPAYMENT']) && !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 'VENDOR INACTIVE':
                 case 'DEACTIVATED BY MERCHANT':
                     // 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');
                         // set new 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
                         // set new 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;
                 case 'TOO MANY FAILURES':
                     // set new status
                     $member->status = $new_status = MGM_STATUS_NULL;
                     // status string
                     $member->status_str = __('Last payment cycle failed, too many failed transactions.', '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
 }
예제 #8
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
  */
 function query_rebill_status($user_id, $member = NULL)
 {
     // check
     if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id) && !empty($this->setting['searchapi_auth_user']) && !empty($this->setting['searchapi_auth_pass'])) {
         // end  point
         $endpoint = $this->_get_endpoint('search');
         // search
         // headers
         $http_headers = array();
         //array('Content-Type' => 'text/xml');
         // data
         $query = array('auth_user' => $this->setting['searchapi_auth_user'], 'auth_pass' => $this->setting['searchapi_auth_pass'], 'member_id' => $member->payment_info->subscr_id, 'trans_id' => $member->payment_info->txn_id, 'api_action' => 'search');
         //prevcanc	//
         // url
         $post_url = add_query_arg($query, $endpoint);
         // create curl post
         $http_response = mgm_remote_get($post_url, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // init
         $response = array();
         // parse
         if ($xml = @simplexml_load_string($http_response)) {
             // dump
             mgm_log($xml, __FUNCTION__);
             $response = array();
             // status
             if (isset($xml->Record->Customer->Status)) {
                 $response['status'] = (string) $xml->Record->Customer->Status;
             }
             // tarsn date
             if (isset($xml->Record->Customer->LastTransDate)) {
                 $response['last_trans_date'] = date('Y-m-d', strtotime((string) $xml->Record->Customer->LastTransDate));
             }
             // trans id
             if (isset($xml->Record->Transactions->Transaction->TransID)) {
                 $response['trans_id'] = (string) $xml->Record->Transactions->Transaction->TransID;
             }
             // event type
             if (isset($xml->Record->Events->Event->EventType)) {
                 $response['event_type'] = (string) $xml->Record->Events->Event->EventType;
             }
             // event date
             if (isset($xml->Record->Events->Event->EventInitdate)) {
                 $response['event_date'] = (string) $xml->Record->Events->Event->EventInitdate;
             }
         }
         // dump
         mgm_log($response, __FUNCTION__);
         //return false;
         // check
         if (isset($response['status'])) {
             // old status
             $old_status = $member->status;
             // set status
             switch ($response['status']) {
                 case 'Active Trial':
                 case 'Active Recurring':
                 case 'Active Preview':
                 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($response['last_trans_date']) && !empty($response['last_trans_date']) ? $response['last_trans_date'] : date('Y-m-d');
                     // expire date
                     if (isset($response['last_trans_date']) && !empty($response['last_trans_date']) && !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;
                             }
                         }
                     }
                     // set eway txn no
                     if (isset($response['trans_id'])) {
                         $member->payment_info->epoch_txn_id = $response['trans_id'];
                     }
                     // 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 'Canceled':
                 case 'Cancelled Recurring':
                 case 'Cancelled Trial':
                 case 'Cancelled Preview':
                     // 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 'Suspended':
                 case 'Terminated':
                 case 'Expired':
                     // set new statis
                     $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
 }