function process_credit_card()
 {
     // read tran id
     if (!($tran_id = $this->_read_transaction_id())) {
         return $this->throw_cc_error(__('Transaction Id invalid', 'mgm'));
     }
     // get trans
     if (!($tran = mgm_get_transaction($tran_id))) {
         return $this->throw_cc_error(__('Transaction invalid', 'mgm'));
     }
     // Check user id is set if subscription_purchase. issue #1049
     if ($tran['payment_type'] == 'subscription_purchase' && (!isset($tran['data']['user_id']) || isset($tran['data']['user_id']) && (int) $tran['data']['user_id'] < 1)) {
         return $this->throw_cc_error(__('Transaction invalid . User id field is empty', 'mgm'));
     }
     // system
     $system_obj = mgm_get_class('system');
     // get data
     $data = $this->_get_button_data($tran['data'], $tran_id);
     // merge
     $post_data = array_merge($_POST, $data);
     // set email
     $this->_set_default_email($post_data, 'x_email');
     // issue#: 581 changes ----------------------------------
     // adjust $post_data for recurring: which is(AIM+ARB)
     $bypass_aim = false;
     $temp_data = array();
     $recurring = false;
     if ($post_data['x_recurring_billing'] == 'TRUE') {
         $recurring = true;
         //if valid trial amount found
         if (isset($post_data['x_trial_amount'])) {
             // consider trial amount for AIM transaction
             // store in  temp array: This will be reverted before ARB transaction
             $temp_data['x_amount'] = $post_data['x_amount'];
             $post_data['x_amount'] = $post_data['x_trial_amount'];
             // bypass AIM
             if ($post_data['x_amount'] == 0) {
                 $bypass_aim = true;
             }
             // reduce one trial cycle as nextStart date will be ajjusted for the first transaction
             $post_data['x_trial_occurrences']--;
             if ($post_data['x_trial_occurrences'] <= 0) {
                 //if no remaining trials, reset trial
                 unset($post_data['x_trial_occurrences']);
                 unset($post_data['x_trial_amount']);
             }
         } elseif ($post_data['x_total_occurrences'] != 9999) {
             //if not infinite
             // reduce number of cycles by one as first cycle will be charged through AIM
             $post_data['x_total_occurrences']--;
         }
     }
     // gateway
     // issue#: 581 changes: treat first payment as AIM as first cycle will be billed through AIM if recurring
     $gateway_method = 'aim';
     // add internal vars
     $secure = array('x_login' => $this->setting['loginid'], 'x_tran_key' => $this->setting['tran_key']);
     // merge
     $post_data = array_merge($post_data, $secure);
     // overwrite post data array with secure params
     // store x_custom
     $_POST['x_custom'] = $post_data['x_custom'];
     // filter post data
     $post_data_aim = $this->_filter_postdata($gateway_method, $post_data, 'array');
     // ok, aim array
     // headers
     $http_headers = $gateway_method == 'arb' ? array('Content-Type' => 'text/xml') : array();
     // end  point
     $endpoint = $this->_get_endpoint($this->status . '_' . $gateway_method);
     // test_arb, live_aim etc.
     //if to be charged
     if (!$bypass_aim) {
         // log
         // create curl post
         $http_response = mgm_remote_post($endpoint, $post_data_aim, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
         // parse response
         $this->_process_response($gateway_method, $http_response);
     } else {
         // log
         // mark as success if amount is for trial
         $this->_process_response('bypass', null);
     }
     // log
     mgm_log('AIM: ' . mgm_pr($this->response, true), $this->module . __FUNCTION__);
     // if recurring CREATE ARB subscription:
     // issue#: 581 changes:
     // if AIM is success
     if (isset($this->response['response_status']) && (int) $this->response['response_status'] == 1 || $bypass_aim === true) {
         // cancel previous subscription:
         // no need of passing previous pack id here as ARB creation happens after AIM transaction
         $this->cancel_recurring_subscription(isset($post_data['x_custom']) ? $post_data['x_custom'] : NULL);
         sleep(1);
         // log
         mgm_log('recurring: ' . $recurring, $this->module . __FUNCTION__);
         // if recurring
         if ($recurring) {
             // reset amount if taken from trial:
             // otherwise trial amount will be treated as actual amount for all the transactions
             if (isset($temp_data['x_amount'])) {
                 $post_data['x_amount'] = $temp_data['x_amount'];
             }
             // method
             $gateway_method = 'arb';
             // headers
             $http_headers = array('Content-Type' => 'text/xml');
             // end  point
             $endpoint = $this->_get_endpoint($this->status . '_' . $gateway_method);
             // test_arb, live_aim etc.
             // filter post data
             $post_data_arb = $this->_filter_postdata($gateway_method, $post_data, 'string');
             // ok, xml string
             // create curl post
             $http_response = mgm_remote_post($endpoint, $post_data_arb, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
             // $this->_curl_post($endpoint, $post_string, $http_header);
             // parse response
             $arb_response = $this->_process_response($gateway_method, $http_response, false);
             // log
             mgm_log('ARB:' . mgm_pr($arb_response, true), $this->module . __FUNCTION__);
             // check
             if ((int) $arb_response['response_status'] == 1) {
                 //add recurring subscription id to the response
                 $this->response['subscription_id'] = $arb_response['subscription_id'];
                 //created ARB
             } else {
                 //ARB creation failed.
                 // notify admin:
                 $blogname = get_option('blogname');
                 // mail
                 @mgm_notify_admin_arb_creation_failed($blogname, $post_data, $arb_response);
             }
         }
         // treat as return
         $this->process_return();
     } else {
         // return to credit card form
         return $this->throw_cc_error();
     }
     // important: issue#: 871
     // treat as return
     // update: only if payment is true
     // $this->process_return();
 }
}
// notify admin, only if gateway emails on
if (!$dge) {
    // not for guest
    if ($user_id) {
        $subject = "[" . $blogname . "] Admin Notification: " . $user->user_email . " purchased post " . $post_id;
        $message = "User display name: {$user->display_name}<br />User email: {$user->user_email}<br />User ID: {$user->ID}<br />Status: " . $status . "<br />Action: Purchase post:" . $subject . "<br /><br />" . $message . "<br /><br /><pre>" . print_r($_POST, true) . '</pre>';
    } else {
        $subject = "[" . $blogname . "] Admin Notification: Guest[IP: " . mgm_get_client_ip_address() . "] purchased post " . $post_id;
        $message = "Guest Purchase";
    }
    mgm_mail($system_obj->setting['admin_email'], $subject, $message);
}
if (!$dge) {
    $message = sprintf('Could not read membership type in the following POST data. Please debug or contact magic members to fix the problem making 
	            sure to pass on the following data. <br /><br />%s', mgm_pr($_POST, true));
    mgm_mail($system_obj->setting['admin_email'], 'Error in ABN-AMRO membership verification', $message);
}
// status
switch ($member->status) {
    case MGM_STATUS_ACTIVE:
        //Sending notification email to user - issue #1468
        if ($notify_user && $is_registration == 'Y') {
            $user_pass = mgm_decrypt_password($member->user_password, $user_id);
            do_action('mgm_register_user_notification', $user_id, $user_pass);
        }
        //sending upgrade notifaction email to admin
        if (isset($subscription_option) && $subscription_option == 'upgrade') {
            do_action('mgm_user_upgrade_notification', $user_id);
        }
        // init
 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;
 }
 function _notify2post()
 {
     // parse
     if ($notify_response = $this->_get_notify()) {
         // log
         mgm_log($notify_response, $this->module . __FUNCTION__);
         // only if canceled
         if ($notify_response->type == 'customer.subscription.deleted') {
             // get email
             $customer_id = $notify_response->data->object->customer;
             // get transaction
             if ($tran = mgm_get_transaction_by_option('stripe_customer_id', $customer_id)) {
                 // check
                 if ($member = mgm_get_member($transaction['data']['user_id'])) {
                     // proces only when not canceled
                     if (!in_array($member->status, array(MGM_STATUS_AWAITING_CANCEL, MGM_STATUS_CANCELLED))) {
                         // set post fields
                         $_POST['custom'] = $tran['id'];
                         $_POST['notify_type'] = 'subscr_canceled';
                         //$_POST['notify_type'] = 'subscr_expired'
                         // set notify
                         $this->response = $notify_response;
                         // log
                         mgm_log('Cancelling from Notify Post' . mgm_pr($tran, true), __FUNCTION__);
                     }
                 }
             }
         }
     }
 }
    // not for guest
    if ($user_id) {
        $subject = "[" . $blogname . "] Admin Notification: " . $user->user_email . " purchased post " . $post_id;
        $message = "User display name: {$user->display_name}<br />User email: {$user->user_email}<br />User ID: {$user->ID}<br />Status: " . $status . "<br />Action: Purchase post:" . $subject . "<br /><br />" . $message . "<br /><br /><pre>" . print_r($_POST, true) . '</pre>';
    } else {
        $subject = "[" . $blogname . "] Admin Notification: Guest[IP: " . mgm_get_client_ip_address() . "] purchased post " . $post_id;
        $message = "Guest Purchase";
    }
    // mail
    mgm_mail($system_obj->setting['admin_email'], $subject, $message);
}
if (!$dge) {
    // message
    $message = sprintf('Could not read membership type in the following POST data. Please debug or contact magic members 
	            to fix the problem making sure to pass on the following data. <br /><br />
				%s', mgm_pr($_POST, true));
    // mail
    mgm_mail($system_obj->setting['admin_email'], 'Error in 1ShoppingCart membership verification', $message);
}
// on status
switch ($member->status) {
    case MGM_STATUS_ACTIVE:
        //Sending notification email to user - issue #1468
        if ($notify_user && $is_registration == 'Y') {
            $user_pass = mgm_decrypt_password($member->user_password, $user_id);
            do_action('mgm_register_user_notification', $user_id, $user_pass);
        }
        //sending upgrade notifaction email to admin
        if (isset($subscription_option) && $subscription_option == 'upgrade') {
            do_action('mgm_user_upgrade_notification', $user_id);
        }