function get_batch_transactions($batches)
    {
        // xml request
        $post_data_s = '
		<getTransactionListRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
		    <merchantAuthentication>
		        <name>' . $this->setting['loginid'] . '</name>
		        <transactionKey>' . $this->setting['tran_key'] . '</transactionKey>
		    </merchantAuthentication>
		    <batchId>{batch_id}</batchId>
		</getTransactionListRequest>';
        // end  point
        $endpoint = $this->_get_endpoint($this->status . '_arb');
        // test_arb, live_aim etc.
        // headers
        $http_headers = array('Content-Type' => 'text/xml');
        // transactions
        $transactions = array();
        // loop
        foreach ($batches as $batchId) {
            // id replace
            $post_data = str_replace('{batch_id}', $batchId, $post_data_s);
            // create curl post
            $http_response = mgm_remote_post($endpoint, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
            // object
            if ($xml_o = @simplexml_load_string($http_response)) {
                // log
                // mgm_log('batch transactions response:' . mgm_pr($xml_o, true), __FUNCTION__);
                // check
                if (isset($xml_o->transactions->transaction)) {
                    // array
                    if (count($xml_o->transactions->transaction)) {
                        // loop
                        foreach ($xml_o->transactions->transaction as $transaction) {
                            // set
                            $transactions[(string) $transaction->invoiceNumber] = (string) $transaction->transId;
                        }
                    } elseif (isset($xml_o->transactions->transaction->transId)) {
                        // set
                        $transactions[(string) $xml_o->transactions->transaction->invoiceNumber] = (string) $xml_o->transactions->transaction->transId;
                    }
                }
                // log
                // mgm_log('batch transactions: '. mgm_pr($transactions, true), __FUNCTION__);
            }
        }
        // return
        return $transactions;
    }
 /**
  * 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
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @param int $pack_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $subscr_id = 0;
                     }
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         if ($this->setting['aquirer'] != 'sisow') {
             // skip sisow
             return false;
             //skip as trans reff will need to be passed always
         }
     }
     //only for subscription_purchase
     if ($this->setting['aquirer'] == 'sisow') {
         if (!isset($member)) {
             $member = mgm_get_member($user_id);
         }
         $txn_id = $member->payment_info->txn_id;
         //mgm_pr($member);
         // endpoint
         $endpoint = $this->_get_endpoint();
         // set
         $endpoint = str_replace('[action]', 'CancelReservationRequest', $endpoint);
         // keys
         $compute_keys = array($txn_id, $this->setting['merchant_id'], $this->setting['secret_key']);
         $compute_sha1 = sha1(implode('', $compute_keys));
         $post_data = array('trxid' => $txn_id, 'merchantid' => $this->setting['merchant_id'], 'sha1' => $compute_sha1);
         // headers
         $http_headers = array();
         //array('Content-Type' => 'text/xml');
         //mgm_pr($post_data); die;
         // create curl post
         $http_response = mgm_remote_post($endpoint, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         mgm_log($http_response, __FUNCTION__);
         // parse
         if ($xml = @simplexml_load_string($http_response)) {
             mgm_log($xml, __FUNCTION__);
             // redirect to issuer
             if (isset($xml->reservation->status)) {
                 return (string) $xml->reservation->status == 'Cancelled' ? true : false;
             } else {
                 return false;
             }
         }
     }
     //send email only if setting enabled
     if (!empty($subscr_id) || $subscr_id === 0) {
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         //send email only if setting enabled
         if (!$dge) {
             // blog
             $blogname = get_option('blogname');
             // user
             $user = get_userdata($user_id);
             // notify admin
             mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member);
         }
         return true;
     }
     return false;
 }
示例#4
0
 function _pre_auth_complete($post_data)
 {
     // charge
     $gateway_method = 'xmlauthco';
     // txn
     $post_data['AuthTrxnNumber'] = $this->response['txn_no'];
     // txn_no,auth_code
     // end  point
     $endpoint = $this->_get_endpoint($this->status . '_' . $gateway_method);
     // live_xmlauth, live_xmlauthco etc.
     // filter post data for api
     $post_string = $this->_filter_postdata($gateway_method, $post_data);
     // headers
     $http_headers = $this->_get_http_headers($gateway_method);
     // log
     mgm_log('Request Headers [' . $gateway_method . ']' . mgm_pr($http_headers, true), __FUNCTION__);
     // log
     mgm_log('Request [' . $gateway_method . ']' . $post_string, __FUNCTION__);
     // create curl post
     $http_response = mgm_remote_post($endpoint, $post_string, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
     // log
     mgm_log('Response [' . $gateway_method . ']' . $http_response, __FUNCTION__);
     // parse response
     $this->_process_response($gateway_method, $http_response);
     // log
     mgm_log('Response Parsed [' . $gateway_method . ']' . mgm_pr($this->response, true), __FUNCTION__);
     // testing
     // $this->response['response_status'] = 1;
     // return
     if ($this->response['response_status'] == 1) {
         // track
         $this->response['preauth_complete'] = true;
         // return
         return true;
     }
     // return
     return false;
 }
 /**
  * fetch sales/transaction details
  * @param int $sale_id
  * @return multitype:string NULL |multitype:
  */
 function getSaleDetails($sale_id)
 {
     // url
     $saledetail_url = $this->_get_endpoint('saledetail');
     // url
     $url = add_query_arg(array('sale_id' => $sale_id), $saledetail_url);
     // auth string
     $auth = $this->setting['apiusername'] . ':' . $this->setting['apipassword'];
     // post
     $post_data = array();
     // headers
     $http_headers = array('Accept' => 'application/json', 'Authorization' => 'Basic ' . base64_encode($auth));
     // fetch
     $http_response = mgm_remote_post($url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
     // log
     // mgm_log($http_response, __FUNCTION__);
     // post
     // $response = $this->_curl_post($url, NULL, $auth, array("Accept: application/json") );
     // mgm_log('$response:=' . $response);
     // decode
     $response = json_decode($http_response);
     // mgm_log(mgm_array_dump($response, true), '2checkout1');
     if (isset($response->sale->invoices) && is_array($response->sale->invoices)) {
         $invoices = $response->sale->invoices;
         $inv_count = count($invoices);
         if ($inv_count > 0) {
             if (1) {
                 return array('status' => 'active', 'expire_date' => $invoices[$inv_count - 1]->lineitems[0]->billing->date_next, 'sale_id' => $response->sale->sale_id, 'email' => $response->sale->customer->email_address, 'last_pay' => date('Y-m-d', strtotime($invoices[$inv_count - 1]->date_placed)), 'recurring_status' => $invoices[$inv_count - 1]->lineitems[0]->billing->recurring_status, 'status_type' => $invoices[$inv_count - 1]->lineitems[0]->billing->status);
             }
         }
     } else {
         $mssg = isset($response->errors->message) ? $response->errors->message : 'No Invoice details found';
         return array('status' => 'error', 'message' => $mssg);
     }
     return array();
     //mgm_log($invoices[$inv_count-1]->lineitems[0]->billing->date_next);
     //mgm_log($invoices[$inv_count-1]->lineitems[0]->billing->recurring_status);
 }
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             if (isset($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } else {
                 //check pack is recurring:
                 $pid = $pack_id ? $pack_id : $member->pack_id;
                 if ($pid) {
                     $s_packs = mgm_get_class('subscription_packs');
                     $sel_pack = $s_packs->get_pack($pid);
                     if ($sel_pack['num_cycles'] != 1) {
                         $subscr_id = 0;
                     }
                     // 0 stands for a lost subscription id
                 }
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 // mgm_log('RECALLing '. $member->payment_info->module .': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     }
     //ony for subscription_purchase
     if ($subscr_id) {
         // end  point
         $endpoint = $this->_get_endpoint('unsubscribe');
         // base
         // add query
         $url = add_query_arg(array('SUBSCRIPTION_ID' => urlencode($subscr_id), 'MERCHANT_ID' => urlencode($this->setting['merchant_id']), 'ZombaioGWPass' => urlencode($this->setting['gw_pass']), 'ReasonCode' => urlencode(11)), $endpoint);
         // create curl post
         //$buffer = $this->_curl_post($url);
         // headers
         $http_headers = array();
         // fetch
         $http_response = mgm_remote_post($url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // verify
         if ($http_response == 1) {
             return true;
         } else {
             // message
             return $this->_get_cancel_error($http_response);
         }
     } elseif ($subscr_id === 0) {
         //send email to admin if subscription Id is absent
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         //send email only if setting enabled
         if (!$dge) {
             $user = get_userdata($user_id);
             //send notification email to admin:
             $message = __('The User: '******'mgm') . $user->user_email . ' (' . $user_id . ') ' . __('has upgraded/cancelled subscription.', 'mgm');
             $message .= "<br/>" . __('Please unsubscribe the user subscription from Gateway Merchant panel.', 'mgm');
             if (!empty($member->transaction_id)) {
                 $message .= "<br/>" . __('MGM Transaction Id:', 'mgm') . $member->transaction_id;
             }
             //admin email:
             if (!empty($system_obj->setting['admin_email'])) {
                 @mgm_mail($system_obj->setting['admin_email'], sprintf(__('[%s] User Subscription Cancellation', 'mgm'), get_option('blogname')), $message);
             }
         }
         return true;
     }
     return false;
 }
    function read_orders()
    {
        // endpoint
        $endpoint = sprintf('https://www.mcssl.com/API/%d/Orders/LIST', $this->setting['merchant_id']);
        // start date
        $start_dt = date('m/d/Y H:i:s', strtotime('-1 DAY'));
        // content
        $post_data = '<Request>
						<Key>' . $this->setting['merchant_api_key'] . '</Key>
						<LimitCount>10</LimitCount>
						<LimitOffset>0</LimitOffset>
						<LimitStartDate>' . $start_dt . '</LimitStartDate>
						<LimitEndDate>' . date('m/d/Y H:i:s') . '</LimitEndDate>						
						<SortOrder>DESC</SortOrder>
					  </Request>';
        // headers
        $http_headers = array('Content-Type' => 'text/xml');
        // fetch
        $http_response = mgm_remote_post($endpoint, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
        // $buffer = $this->_curl_post($endpoint, $content, array("Content-Type: text/xml") );
        // simple xml
        $xml = @simplexml_load_string($http_response);
        // check
        if ($xml) {
            // success
            if ($this->is_api_success($xml)) {
                $orders = array();
            }
        }
    }
    function get_transaction_details($member)
    {
        // array
        $response = array();
        // verify txn id exists
        $this->_fetch_merchant_txn_id($member);
        // check
        if (isset($member->payment_info->txn_id) && !empty($member->payment_info->txn_id)) {
            // set xml content
            $post_data = '<getTransactionDetailsRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">

							<merchantAuthentication>

								<name>' . $this->setting['loginid'] . '</name>

								<transactionKey>' . $this->setting['tran_key'] . '</transactionKey>

							</merchantAuthentication>

							<transId>' . $member->payment_info->txn_id . '</transId>

						</getTransactionDetailsRequest>';
            // 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
            $response = $this->_process_response('transaction_details', $http_response, false);
        }
        // return
        return $response;
    }
 /**
  * Cancel Recurring Subscription
  * This is not a private function
  * @param int/string $trans_ref	
  * @param int $user_id	
  * @param int/string $subscr_id	
  * @return boolean
  */
 function cancel_recurring_subscription($trans_ref = null, $user_id = null, $subscr_id = null, $pack_id = null)
 {
     //if coming form process return after a subscription payment
     if (!empty($trans_ref)) {
         $transdata = $this->_get_transaction_passthrough($trans_ref);
         if ($transdata['payment_type'] != 'subscription_purchase') {
             return false;
         }
         $user_id = $transdata['user_id'];
         if (isset($transdata['is_another_membership_purchase']) && $transdata['is_another_membership_purchase'] == 'Y') {
             $member = mgm_get_member_another_purchase($user_id, $transdata['membership_type']);
         } else {
             $member = mgm_get_member($user_id);
         }
         if (isset($member->payment_info->module) && !empty($member->payment_info->module)) {
             $subscr_id = null;
             if (!empty($member->payment_info->subscr_id)) {
                 $subscr_id = $member->payment_info->subscr_id;
             } elseif (!empty($member->pack_id)) {
                 //check the pack is recurring
                 $s_packs = mgm_get_class('subscription_packs');
                 $sel_pack = $s_packs->get_pack($member->pack_id);
                 if ($sel_pack['num_cycles'] != 1) {
                     $subscr_id = 0;
                 }
                 // 0 stands for a lost subscription id
             }
             //check for same module: if not call the same function of the applicale module.
             if (str_replace('mgm_', '', $member->payment_info->module) != str_replace('mgm_', '', $this->code)) {
                 // mgm_log('RECALLing '. $member->payment_info->module .': cancel_recurring_subscription FROM: ' . $this->code);
                 return mgm_get_module($member->payment_info->module, 'payment')->cancel_recurring_subscription($trans_ref, null, null, $pack_id);
             }
             //skip if same pack is updated
             if (empty($member->pack_id) || is_numeric($pack_id) && $pack_id == $member->pack_id) {
                 return false;
             }
         } else {
             return false;
         }
     }
     // when a subscription found
     if ($subscr_id) {
         $user = get_userdata($user_id);
         $date_format = mgm_get_date_format('date_format');
         // post data
         $post_data = array('USER' => $this->setting['ap_merchant'], 'PASSWORD' => $this->setting['ap_apipassword'], 'SUBSCRIPTIONREFERENCE' => $subscr_id, 'NOTE' => sprintf('Cancellation selected by member: "%s", ID: %d on: %s', $user->user_email, $user->ID, date($date_format)), 'TESTMODE' => $this->status == 'test' ? '1' : '0');
         // url
         $unsubscribe_url = $this->_get_endpoint('unsubscribe');
         // headers
         $http_headers = array();
         // create curl post
         $http_response = mgm_remote_post($unsubscribe_url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // parse
         @parse_str($http_response, $data);
         // verify
         if (isset($data['REFERENCENUMBER']) && $data['RETURNCODE'] == 100) {
             return true;
         } elseif (isset($data['DESCRIPTION'])) {
             //error string
             return $data['DESCRIPTION'];
         }
     } elseif (is_null($subscr_id) || $subscr_id === 0) {
         //send email to admin if subscription Id is absent
         $system_obj = mgm_get_class('system');
         $dge = bool_from_yn($system_obj->get_setting('disable_gateway_emails'));
         // check
         if (!$dge) {
             // blog
             $blogname = get_option('blogname');
             // user
             $user = get_userdata($user_id);
             // notify admin
             mgm_notify_admin_membership_cancellation_manual_removal_required($blogname, $user, $member);
         }
         // return
         return true;
     }
     // return
     return false;
 }
 /**
  * create recurring profile
  */
 function _create_paypal_profile()
 {
     // double check
     if ($_POST['RESULT'] != 0) {
         return;
     }
     // @todo
     // void the auth
     // $this->_void_auth();
     // tran
     $tran = mgm_get_transaction($_POST['M_CUSTOM']);
     // pack
     $pack = $tran['data'];
     // log
     // mgm_log($pack, $this->module . __FUNCTION__);
     // one time billing cycle
     if (isset($pack['num_cycles']) && (int) $pack['num_cycles'] == 1) {
         // log
         mgm_log('Exit Flag for One time billing', $this->module . __FUNCTION__);
         // exit
         return;
     }
     // log
     mgm_log('Process flag to Create Profile', $this->module . __FUNCTION__);
     // user data
     $user_id = $pack['user_id'];
     $user = get_userdata($user_id);
     // item
     $item = $this->get_pack_item($pack);
     // periods
     $pay_periods = array('d' => 'DAYS', 'w' => 'WEEK', 'm' => 'MONT', 'y' => 'YEAR');
     // day not supported by Paypal
     $pay_terms = array('d' => 365, 'w' => 52, 'm' => 12, 'y' => 1);
     // secured
     $secured = array('PARTNER' => $this->setting['partner'], 'VENDOR' => $this->setting['vendor'], 'USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'MAXFAILPAYMENTS' => (int) $this->setting['max_failed_payments']);
     // greater than 0, set term to ongoing
     if ((int) $pack['num_cycles'] > 1) {
         $term = $pay_terms[$pack['duration_type']] * ($pack['num_cycles'] - 1);
         // reduce 1 since auth captures first payment right away
     } else {
         $term = 0;
     }
     // exprs
     $duration_exprs = mgm_get_class('subscription_packs')->get_duration_exprs();
     //array('d'=>'DAY','w' => 'WEEK', 'm'=>'MONTH', 'y'=>'YEAR' );
     // start date should be next billing cycle date, //date('mdY', strtotime('+1 DAY')),//MMDDYYYY
     $start_date = date('mdY', strtotime('+' . 1 * (int) $pack['duration'] . ' ' . $duration_exprs[$pack['duration_type']]));
     // method
     switch ($_POST['METHOD']) {
         case 'CC':
             // Credit Card DCC
             // comment
             $comment = sprintf('%s By %s', $item['name'], $user->user_email);
             # code...
             $data = array('TRXTYPE' => 'R', 'TENDER' => 'C', 'ACTION' => 'A', 'PROFILENAME' => $item['name'], 'ORIGID' => $_POST['PNREF'], 'START' => $start_date, 'PAYPERIOD' => $pay_periods[$pack['duration_type']], 'TERM' => $term, 'AMT' => $pack['cost'], 'EMAIL' => $user->user_email, 'DESC' => $item['name'], 'COMMENT1' => $this->_remove_special_chars($comment));
             break;
         case 'P':
             // PayPal, EC
         // PayPal, EC
         default:
             // comment
             $comment = sprintf('%s By %s', $item['name'], $user->user_email);
             # code...
             $data = array('TRXTYPE' => 'R', 'TENDER' => 'P', 'ACTION' => 'A', 'PROFILENAME' => $item['name'], 'BAID' => isset($_POST['BAID']) && !empty($_POST['BAID']) ? $_POST['BAID'] : $_POST['PNREF'], 'START' => $start_date, 'PAYPERIOD' => $pay_periods[$pack['duration_type']], 'TERM' => $term, 'AMT' => $pack['cost'], 'EMAIL' => $user->user_email, 'DESC' => $item['name'], 'COMMENT1' => $this->_remove_special_chars($comment));
             // check, notify admin
             if (!isset($_POST['BAID']) || empty($_POST['BAID'])) {
                 // subject
                 $subject = 'BAID missing in PayPal Payflow Profile Creation';
                 // message
                 $message = sprintf('BAID missing in PayPal Payflow Profile Creation, Please contact PayPal, POST DATA: %s', print_r($_POST, true));
                 // send
                 mgm_notify_admin(null, $subject, $message);
                 // log
                 mgm_log($message, $this->module . __FUNCTION__);
             }
             break;
     }
     // additional fields
     $this->_set_address_fields($user, $data);
     // merge
     $data = array_merge($secured, $data);
     // log
     mgm_log($data, $this->module . __FUNCTION__);
     // data
     $data_post = _http_build_query($data, null, '&', '', false);
     // do not encode
     // link
     $post_url = $this->_get_endpoint();
     //issue #1508
     $url_parsed = parse_url($post_url);
     // domain/host
     $domain = $url_parsed['host'];
     // headers
     $http_headers = array('POST /cgi-bin/webscr HTTP/1.1\\r\\n', 'Content-Type: application/x-www-form-urlencoded\\r\\n', 'Host: ' . $domain . '\\r\\n', 'Connection: close\\r\\n\\r\\n');
     // post
     $http_response = mgm_remote_post($post_url, $data_post, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
     // parse
     $response = array();
     // parse
     parse_str($http_response, $response);
     // log
     mgm_log($response, $this->module . __FUNCTION__);
     // profile id
     if ($response['RESULT'] == 0) {
         // set in post
         $_POST['PROFILEID'] = $response['PROFILEID'];
         // set in option
         mgm_add_transaction_option(array('transaction_id' => $_POST['M_CUSTOM'], 'option_name' => strtolower($this->module . '_PROFILEID'), 'option_value' => isset($_POST['PROFILEID']) ? $_POST['PROFILEID'] : ''));
     }
 }