/** * 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; }
/** * 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; } } } //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)) { // log // mgm_log('RECALLing '. $member->payment_info->module .': cancel_recurring_subscription FROM: ' . $this->code); // return 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; } } //only for subscription_purchase if ($subscr_id) { // set xml content $post_data = '<ARBCancelSubscriptionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name>' . $this->setting['loginid'] . '</name> <transactionKey>' . $this->setting['tran_key'] . '</transactionKey> </merchantAuthentication> <refId>' . $user_id . '</refId> <subscriptionId>' . $subscr_id . '</subscriptionId> </ARBCancelSubscriptionRequest>'; // 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)); // parse response and store into a different array: // do not use $this->response here as this will overwrite previous theprevious values in one scenario $arb_response = $this->_process_response('arb', $http_response, false); // check if (isset($arb_response['response_status']) && $arb_response['response_status'] == 1) { return true; } } 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')); //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 return true; } // return return false; }
/** * Cancel Recurring Subscription * * @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; } } //ony for subscription_purchase if ($subscr_id) { $user = get_userdata($user_id); $format = mgm_get_date_format('date_format'); // compose post body $post_data = array('USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'SIGNATURE' => $this->setting['signature'], 'VERSION' => '64.0', 'METHOD' => 'ManageRecurringPaymentsProfileStatus', 'PROFILEID' => $subscr_id, 'ACTION' => 'Cancel', 'NOTE' => sprintf('Cancellation selected by member on UPGRADE: "%s", ID: %d on: %s', $user->user_email, $user->ID, date($format))); // end point 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__); // fields // $fields = mgm_http_build_query($post_data); // post // $response = $this->_curl_post($endpoint, $fields, '', false); // sleep sleep(1); // parse $this->response = array(); // parse to array parse_str($http_response, $this->response); // log mgm_log($this->response, __FUNCTION__); // cancel return isset($this->response['ACK']) && $this->response['ACK'] == 'Success' ? true : false; } 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) { // 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; }
/** * 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)) { 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; } } //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; }
/** * 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; } } // when a subscription found if ($subscr_id) { // @todo add api call // 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'] = 'cancelSubscription'; //check if (isset($member)) { $query_data['subscriptionId'] = $member->payment_info->subscr_id; } else { $query_data['subscriptionId'] = $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; // log mgm_log($url, $this->module . '_' . __FUNCTION__); // remote get $http_response = mgm_remote_get($url, null, null, false); // log mgm_log($http_response, $this->module . '_' . __FUNCTION__); // xml if ($xml = @simplexml_load_string($http_response)) { // log mgm_log($xml, $this->module . '_' . __FUNCTION__); // return return (int) $xml == 1; // success } // end api call } elseif (is_null($subscr_id) || $subscr_id === 0) { $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; }
/** * Cancel Recurring Subscription * * @param int/string $trans_ref * @param int $user_id * @param int/string $subscr_id * @return boolean/string message */ function cancel_recurring_subscription($trans_ref = null, $user_id = null, $sale_id = null, $pack_id = null) { // if coming form process return after a subscription payment if (!empty($trans_ref)) { // transaction data $transdata = $this->_get_transaction_passthrough($trans_ref); // validate if ($transdata['payment_type'] != 'subscription_purchase') { return false; } // user $user_id = $transdata['user_id']; // multiple purchase 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); } // subscription exists if (isset($member->payment_info->module) && !empty($member->payment_info->module)) { // sale id if (isset($member->payment_info->txn_id)) { $sale_id = $member->payment_info->txn_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) { $sale_id = 0; } //not found } } // module info // 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)) { // recur 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 { // error return false; } } // only for subscription_purchase if ($sale_id) { // sale id, returned order_number on approval url post back // saledetail_url $saledetail_url = add_query_arg(array('sale_id' => $sale_id), $this->_get_endpoint('saledetail')); // auth string $auth = $this->setting['apiusername'] . ':' . $this->setting['apipassword']; // post data $post_data = array(); // headers $http_headers = array('Accept' => 'application/json', 'Authorization' => 'Basic ' . base64_encode($auth)); // fetch $http_response = mgm_remote_post($saledetail_url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // decode $response = json_decode($http_response); // ind $lineitem_id = ''; // validate if ((string) $response->response_code == 'OK') { $lineitem_id = (string) $response->sale->invoices[0]->lineitems[0]->billing->lineitem_id; } // set post $post_data = array('vendor_id' => $this->setting['sid'], 'lineitem_id' => $lineitem_id); // unsubscribe_url $unsubscribe_url = $this->_get_endpoint('unsubscribe'); // fetch $http_response = mgm_remote_post($unsubscribe_url, $post_data, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // decode $response = json_decode($http_response); // return status if ((string) $response->response_code == 'OK') { return true; } else { return $response->errors[0]->message; } } elseif ($sale_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) { // 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; } // default return false; }
/** * 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; }
/** * Cancel Recurring Subscription * This is not a private function * @param int/string $trans_ref * @param int $user_id * @param int/string $subscr_id // if -1, it will treated as a lost subscription 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; } } //ony for subscription_purchase if (!is_null($subscr_id)) { $user = get_userdata($user_id); $date_format = mgm_get_date_format('date_format'); $comment = sprintf('Cancellation selected by member on UPGRADE: "%s", ID: %d on: %s', $user->user_email, $user->ID, date($date_format)); // compose post body $data = array('PARTNER' => $this->setting['partner'], 'VENDOR' => $this->setting['vendor'], 'USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'TENDER' => 'C', 'TRXTYPE' => 'R', 'ACTION' => 'C', 'ORIGPROFILEID' => $subscr_id, 'COMMENT1' => $this->_remove_special_chars($comment)); // 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'); // log mgm_log($data, $this->module . '_' . __FUNCTION__); // data $data_post = _http_build_query($data, null, '&', '', false); // do not encode // post $http_response = mgm_remote_post($post_url, $data_post, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // sleep sleep(1); // parse $response = array(); // parse parse_str($http_response, $response); // log mgm_log($response, $this->module . '_' . __FUNCTION__); // cancel return isset($response['RESULT']) && $response['RESULT'] == 0 ? true : $response; } 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')); //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; }
/** * 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)) { 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)) { // log mgm_log('RECALLing ' . $member->payment_info->module . ': cancel_recurring_subscription FROM: ' . $this->code); // return 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) { // call api // 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' => $subscr_id, 'trans_id' => $member->payment_info->txn_id, 'api_action' => 'search'); //prevcanc // // url $post_url = add_query_arg($query, $endpoint); // log mgm_log($post_url, __FUNCTION__); // create curl post $http_response = mgm_remote_get($post_url, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // log mgm_log($http_response, __FUNCTION__); // parse if ($xml = @simplexml_load_string($http_response)) { // log mgm_log($xml, __FUNCTION__); // has status if (isset($xml->Record->Customer->MemberId)) { // get actions $actions = (array) $xml->Record->AvailableActions; // check if (isset($actions['Action']) && in_array('cancel', $actions['Action'])) { // 2nd call $query = array_merge($query, array('api_action' => 'cancel', 'cancel_reason' => 'wmapprvd')); // post url $post_url = add_query_arg($query, $endpoint); // log mgm_log($post_url, __FUNCTION__); // cancel $http_response = mgm_remote_get($post_url, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false)); // log mgm_log($http_response, __FUNCTION__); // flag. @todo fetch exact response status // log mgm_log($xml, __FUNCTION__); // flag. @todo fetch response status if (isset($xml->Cancel->Response) && (string) $xml->Cancel->Response == 'Success') { return true; } } else { return __('Member already cancelled', 'mgm'); } } else { // error if (isset($xml->Error->Response)) { return (string) $xml->Error->Response; } else { //mgm_pr((array)$xml); $xml_a = (array) $xml; return isset($xml_a[0]) ? $xml_a[0] : __('Unknown', 'mgm'); } } } // end } elseif (is_null($subscr_id) || $subscr_id === 0) { $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; }