コード例 #1
0
 function process_return()
 {
     // record POST/GET data
     do_action('mgm_print_module_data', $this->module, __FUNCTION__);
     // check and show message
     if (isset($_POST['custom']) && !empty($_POST['custom']) || isset($_POST['subscription_id']) && !empty($_POST['subscription_id']) || isset($_GET['status']) && $_GET['status'] != 'error') {
         // caller
         $this->set_webhook_called_by('self');
         // process notify, internally called
         $this->process_notify();
         // query arg
         $query_arg = array('status' => 'success');
         // ref
         if (isset($_POST['custom'])) {
             $query_arg['trans_ref'] = mgm_encode_id($_POST['custom']);
         }
         // is a post redirect?
         $post_redirect = isset($_POST['custom']) ? $this->_get_post_redirect($_POST['custom']) : false;
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = isset($_POST['custom']) ? $this->_auto_login($_POST['custom']) : false;
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         mgm_redirect(add_query_arg(array('status' => 'error'), $this->_get_thankyou_url()));
     }
 }
コード例 #2
0
    /**
     * process request when returns from PAYPAL
     *
     */
    function process_return()
    {
        if (!isset($this->response)) {
            $this->response = array();
        }
        if (isset($_GET['token']) && !empty($_GET['token'])) {
            $this->response = array();
            $end_point = $this->_get_endpoint();
            $secure = array('USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'SIGNATURE' => $this->setting['signature'], 'VERSION' => '65.1');
            //REQUEST AND SHOW PAYMENT DETAILS:
            if (!isset($_POST['confirm_payment'])) {
                // security
                $post_data = array_merge($secure, array('TOKEN' => strip_tags($_GET['token']), 'METHOD' => 'GetExpressCheckoutDetails'));
                //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__);
                // $fields = mgm_http_build_query($data);
                // post
                // $this->_curl_post($end_point, $fields);
                //remove:
                if (isset($this->response['ACK']) && strtoupper($this->response['ACK']) == 'SUCCESS') {
                    if ($this->response['TOKEN'] == $_GET['token']) {
                        //verified:
                        //$this->response['INVNUM']: mgm transaction id;
                        //SHOW PAYMENT DETAILS:
                        $html = '<form action="" method="post" class="mgm_form" name="' . $this->code . '_payment_return_form" id="' . $this->code . '_payment_return_form">
						   		<input type="hidden" name="custom" value="' . $this->response['INVNUM'] . '">
						   		<input type="hidden" name="payer_id" value="' . $this->response['PAYERID'] . '">
						   		<input type="hidden" name="token" value="' . $this->response['TOKEN'] . '">
						   		<input type="hidden" name="confirm_payment" value="1">';
                        //show response fields:
                        $html .= $this->_get_payment_fields($this->response);
                        $html .= '</form>';
                        // return
                        echo $html;
                    } else {
                        //treat as error:
                        $errors = __('Invalid Token', 'mgm');
                    }
                } else {
                    //treat as error:
                    $errors = __('Unable to find transaction details', 'mgm');
                }
            } elseif (!empty($_POST['confirm_payment']) && is_numeric($_POST['custom'])) {
                //PROCESS PAYMENT:
                //$_POST['custom']: mgm transaction id
                $transdata = $this->_get_transaction_passthrough($_POST['custom']);
                $user = get_userdata($transdata['user_id']);
                $pack = mgm_get_class('subscription_packs')->get_pack($transdata['pack_id']);
                $bp_types = array('d' => 'Day', 'w' => 'Week', 'm' => 'Month', 'y' => 'Year');
                $system_obj = mgm_get_class('system');
                $is_onetime = true;
                $data = array();
                $data['TOKEN'] = urlencode($_POST['token']);
                $data['IPADDRESS'] = mgm_get_client_ip_address();
                $data['PAYMENTREQUEST_0_INVNUM'] = $_POST['custom'];
                //transaction ref id
                //issue #974
                if (is_numeric($this->setting['max_failed_payments'])) {
                    $max_failed_payments = round($this->setting['max_failed_payments']);
                } else {
                    $max_failed_payments = 3;
                }
                //mgm_log('max_failed_payments '.$max_failed_payments);
                //pack currency over rides genral setting currency - issue #1602
                if (!isset($pack['currency']) || empty($pack['currency'])) {
                    $pack['currency'] = $this->setting['currency'];
                }
                //recurring:
                if ($transdata['payment_type'] == 'subscription_purchase' && isset($transdata['num_cycles']) && $transdata['num_cycles'] != 1) {
                    $data['METHOD'] = 'CreateRecurringPaymentsProfile';
                    $data['PAYMENTACTION'] = 'Sale';
                    $data['SUBSCRIBERNAME'] = $user->display_name;
                    $data['EMAIL'] = $user->email;
                    $data['PROFILEREFERENCE'] = $_POST['custom'];
                    $data['MAXFAILEDPAYMENTS'] = 1;
                    $data['PROFILESTARTDATE'] = date(DATE_ATOM);
                    // Mon, 15 Aug 2005 15:12:46 UTC
                    $data['DESC'] = isset($transdata['item_name']) ? $transdata['item_name'] : $system_obj->get_subscription_name($transdata);
                    $data['CURRENCYCODE'] = $pack['currency'];
                    $data['AMT'] = $transdata['cost'];
                    $data['BILLINGPERIOD'] = $bp_types[$transdata['duration_type']];
                    $data['BILLINGFREQUENCY'] = $transdata['duration'];
                    $data['TOTALBILLINGCYCLES'] = $transdata['num_cycles'];
                    if ($transdata['trial_on']) {
                        $data['TRIALBILLINGPERIOD'] = $bp_types[$transdata['trial_duration_type']];
                        $data['TRIALBILLINGFREQUENCY'] = $transdata['trial_duration'];
                        $data['TRIALAMT'] = $transdata['trial_cost'];
                        $data['TRIALTOTALBILLINGCYCLES'] = $transdata['trial_num_cycles'];
                    }
                    $data['NOTIFYURL'] = $this->setting['notify_url'];
                    $data['PAYMENTREQUEST_0_NOTIFYURL'] = $this->setting['notify_url'];
                    //issue #974
                    $data['MAXFAILEDPAYMENTS'] = $max_failed_payments;
                    $data['INVNUM'] = $_POST['custom'];
                    //address fields:
                    $this->_set_address_fields($user, $data);
                    $is_onetime = false;
                    //one-time payment/post purchase
                } else {
                    $data['METHOD'] = 'DoExpressCheckoutPayment';
                    $data['PAYERID'] = $_POST['payer_id'];
                    $data['PAYMENTREQUEST_0_CURRENCYCODE'] = $pack['currency'];
                    $data['PAYMENTREQUEST_0_AMT'] = $transdata['cost'];
                    $data['PAYMENTREQUEST_0_DESC'] = isset($transdata['item_name']) ? $transdata['item_name'] : $system_obj->get_subscription_name($transdata);
                    $data['PAYMENTREQUEST_0_NOTIFYURL'] = $this->setting['notify_url'];
                    $data['PAYMENTREQUEST_0_INVNUM'] = $_POST['custom'];
                    //transaction ref id
                    $data['PAYMENTREQUEST_0_CUSTOM'] = $_POST['custom'];
                    //transaction ref id
                    $data['PAYMENTRREQUEST_0_PAYMENTACTION'] = 'Sale';
                    //transaction ref id
                }
                //attach api credentials
                $post_data = array_merge($secure, $data);
                //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__);
                // $fields = mgm_http_build_query($data);
                // reset response
                // $this->response = array();
                // make request:
                // $this->_curl_post($end_point, $fields);
                // check
                if (isset($this->response['ACK']) && strtoupper($this->response['ACK']) == 'SUCCESS') {
                    // process
                    $this->process_notify(true);
                    // query arg
                    $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_POST['custom']));
                    // is a post redirect?
                    $post_redirect = $this->_get_post_redirect($_POST['custom']);
                    // set post redirect
                    if ($post_redirect !== false) {
                        $query_arg['post_redirect'] = $post_redirect;
                    }
                    // is a register redirect?
                    $register_redirect = $this->_auto_login($_POST['custom']);
                    // set register redirect
                    if ($register_redirect !== false) {
                        $query_arg['register_redirect'] = $register_redirect;
                    }
                    // redirect
                    mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
                } else {
                    // teat as error
                    $errors = urlencode($this->response['L_ERRORCODE0'] . ': ' . $this->response['L_SHORTMESSAGE0'] . ' - ' . $this->response['L_LONGMESSAGE0']);
                }
            }
        } else {
            $errors = __('Invalid Token', 'mgm');
        }
        // redirect	if error occured:
        if (isset($errors)) {
            mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => $errors), $this->_get_thankyou_url()));
        }
    }
コード例 #3
0
 function process_return($external_data = array())
 {
     // no redirect for schedular
     $redirect = true;
     // check
     /*if(isset($external_data['from']) && $external_data['from'] == 'scheduler') {
     			$redirect = false;
     		}*/
     // response
     if (!isset($this->response)) {
         $this->response = array();
     }
     // check and show message
     if (isset($this->response['response_status']) && $this->response['response_status'] != 3) {
         // 3 == Error
         // process notify, internally called
         $this->process_notify($external_data);
         // redirct
         if ($redirect) {
             // redirect as success if not already redirected
             $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_POST['Option1']));
             // is a post redirect?
             $post_redirect = $this->_get_post_redirect($_POST['Option1']);
             // set post redirect
             if ($post_redirect !== false) {
                 $query_arg['post_redirect'] = $post_redirect;
             }
             // is a register redirect?
             $register_redirect = $this->_auto_login($_POST['Option1']);
             // set register redirect
             if ($register_redirect !== false) {
                 $query_arg['register_redirect'] = $register_redirect;
             }
             // redirect
             mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
         }
     } else {
         // error redirct
         if ($redirect) {
             mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => urlencode($this->response['message_text'])), $this->_get_thankyou_url()));
         }
     }
 }
コード例 #4
0
 function process_return()
 {
     // passthrough
     $alt_tran_id = $this->_get_alternate_transaction_id();
     // check and show message
     if (isset($alt_tran_id) && !empty($alt_tran_id)) {
         // process notify, internally called for demo
         // the below line is not required as IPN will be called seperately:
         // caller
         $this->set_webhook_called_by('self');
         // issue #: 527
         $this->process_notify();
         // this records the order_number/sale_id for the user in transaction log
         // redirect as success if not already redirected
         // query arg
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($alt_tran_id));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($alt_tran_id);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($alt_tran_id);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // meta redirect, needed to change url from 2checkout
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()), 302, 'meta');
     } else {
         // needed to change url from 2checkout
         mgm_redirect(add_query_arg(array('status' => 'error'), $this->_get_thankyou_url()), 302, 'meta');
     }
 }
コード例 #5
0
 function _get_button_data($pack, $tran_id = NULL)
 {
     // system setting
     $system_obj = mgm_get_class('system');
     $user_id = $pack['user_id'];
     $user = get_userdata($user_id);
     // item
     $item = $this->get_pack_item($pack);
     //pack currency over rides genral setting currency - issue #1602
     if (!isset($pack['currency']) || empty($pack['currency'])) {
         $pack['currency'] = $this->setting['currency'];
     }
     // set data
     $data = array('instId' => $this->setting['inst_id'], 'cartId' => $tran_id, 'currency' => $pack['currency'], 'lang' => $this->setting['lang'], 'email' => $user->user_email, 'desc' => $item['name'], 'hideContact' => 0);
     // hideCurrency = 0
     // address fields
     $this->_set_address_fields($user, $data);
     // unit types
     $unit_types = array('d' => 1, 'w' => 2, 'm' => 3, 'y' => 4);
     // unit types
     // subscription purchase with ongoing/limited
     if (!isset($pack['buypost']) && isset($pack['duration_type']) && $pack['num_cycles'] != 1) {
         // does not support one-time recurring
         // worldpay does not allow 1 time subscription @see #1278 issue notes
         // if ($pack['num_cycles'] != 1 && $pack['duration_type']) {// old style
         // type
         $data['M_payment_type'] = 'subscription';
         $data['option'] = 0;
         // check http://www.rbsworldpay.com/support/kb/bg/recurringpayments/rpfp.html -> Regular Agrrements -> Options
         $data['futurePayType'] = 'regular';
         // $data['startDate']   = date('Y-m-d', strtotime('+1 DAY'));@deprecated in favor of trial delay
         $data['startDelayMult'] = 1;
         // 1
         $data['startDelayUnit'] = 1;
         // day	To start the agreement 1 day after the agreement is setup
         // interval
         $data['intervalMult'] = $pack['duration'];
         $data['intervalUnit'] = $unit_types[$pack['duration_type']];
         // 1|3|4 = day|month|year
         // regular charge
         $data['normalAmount'] = $pack['cost'];
         // no of payments, limited
         if ((int) $pack['num_cycles'] > 0) {
             $data['noOfPayments'] = $pack['num_cycles'];
         }
         // trial
         if ($pack['trial_on']) {
             // set initialAmount as trial and normalAmount as recurring
             // #1223
             if ((double) $pack['trial_cost'] > 0.0) {
                 $data['amount'] = $pack['trial_cost'];
                 // instant payment
             }
             /*else{
             			$data['initialAmount'] = $pack['trial_cost'];// first payment
             		}*/
             $data['startDelayMult'] = $pack['trial_duration'];
             // to start the actual after trial settings
             $data['startDelayUnit'] = $unit_types[$pack['trial_duration_type']];
         }
         // signature field
         $amount_field = 'normalAmount';
     } else {
         // type of payment
         $data['M_payment_type'] = 'one-time';
         // signature field
         $amount_field = 'amount';
         // set amount
         $data['amount'] = $pack['cost'];
     }
     // signature
     if ($this->setting['md5_sig']) {
         $data['signatureFields'] = implode(':', array($amount_field, 'currency'));
         $data['signature'] = md5(implode(':', array($this->setting['md5_sig'], $pack['cost'], $pack['currency'])));
     }
     // custom
     $data['M_custom'] = $tran_id;
     // custom parameters:
     $trans_url = mgm_get_custom_url('transactions');
     // args
     $qry_args = array('module' => $this->code, 'method' => 'payment_return', 'transtatus' => 'success', 'transid' => mgm_encode_id($tran_id));
     // include success url to be parsed on Worldpay Gateway resultY.html(success) page
     // success thank you page
     $data['MC_success'] = add_query_arg($qry_args, $trans_url);
     //error page
     $qry_args['transtatus'] = 'error';
     // include error url to be parsed on Worldpay Gateway resultC.html(error/cancel) page
     $data['MC_error'] = add_query_arg($qry_args, $trans_url);
     $data['MC_redirectin'] = 7;
     //redirection in seconds
     $data['MC_sitename'] = get_option('blogname');
     //site name
     // test mode
     if ($this->status == 'test') {
         $data['testMode'] = 100;
     }
     // update currency - issue #1602
     /*		if($pack['currency'] != $this->setting['currency']){
     			$pack['currency'] = $this->setting['currency'];
     		}*/
     // add filter @todo test
     $data = apply_filters('mgm_payment_button_data', $data, $tran_id, $this->module, $pack);
     // update pack/transaction
     mgm_update_transaction(array('data' => json_encode($pack), 'module' => $this->module), $tran_id);
     // data
     return $data;
 }
コード例 #6
0
 function process_return()
 {
     // NOTE: as of ISSUE ID 152, no post data is sent back to server even if rm =2 is set
     // this works ok on paypal sandbox but not on live, treat success always for now
     $alt_tran_id = $this->_get_alternate_transaction_id();
     // check and show message
     // if((isset($_POST['custom']) && !empty($_POST['custom'])) || (isset($_POST['auth']) && !empty($_POST['auth']))){
     if (isset($alt_tran_id) && !empty($alt_tran_id)) {
         // query arg
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($alt_tran_id));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($alt_tran_id);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($alt_tran_id);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         mgm_redirect(add_query_arg(array('status' => 'error'), $this->_get_thankyou_url()));
     }
 }
コード例 #7
0
 function process_return()
 {
     // record POST/GET data
     do_action('mgm_print_module_data', $this->module, __FUNCTION__);
     // auto return page data - issue #1519
     if (count($_REQUEST) > 3) {
         //results
         $result = $this->_get_autoreturn_notification_post();
         //check
         if ($result == "VERIFICADO") {
             /*	
             	Return transaction status
             	Full (Completo): Full payment
             	Payroll Waiting(Aguardando Pagto): Waiting for customer payment
             	Approved(Aprovado): Payment approved, awaiting compensation
             	Analysis(Em Análise): Payment approved, under review by PagSeguro
             	Cancelled(Cancelado): Payment canceled by PagSeguro				
             */
             $status_transacao_arr = array('Completo', 'Aguardando Pagto', 'Aprovado', 'Em Análise');
             // update auto return response log
             update_option('mgm_' . $_REQUEST['TransacaoID'], serialize($_REQUEST));
             //transaction status check
             if (in_array($_REQUEST['StatusTransacao'], $status_transacao_arr)) {
                 //custom val
                 update_option($_REQUEST['TransacaoID'], $_REQUEST['Referencia']);
             }
             //O post foi validado pelo PagSeguro.
         } else {
             if ($result == "FALSO") {
                 //O post não foi validado pelo PagSeguro.
             } else {
                 //Erro na integração com o PagSeguro.
             }
         }
     } else {
         //check
         if (isset($_REQUEST['transaction_id'])) {
             //transaction id
             $pagseguro_tran_id = str_replace('-', '', $_REQUEST['transaction_id']);
             //custom
             $custom_val = get_option($pagseguro_tran_id);
             $_REQUEST['custom'] = $custom_val;
             //mgm_log('_pagseguro custom val : '.$custom_val,$this->module.'_'.__FUNCTION__);
             //fetch auto return response log data
             //$pagseguro_data = get_option('mgm_'.$pagseguro_tran_id);
             //$pagseguro_data = unserialize($pagseguro_data);
             //mgm_log('_pagseguro_data : '.mgm_array_dump($pagseguro_data,true),$this->module.'_'.__FUNCTION__);
         }
     }
     // check and show message
     if (isset($_REQUEST['custom']) && !empty($_REQUEST['custom'])) {
         // query arg
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_REQUEST['custom']));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_REQUEST['custom']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($_REQUEST['custom']);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         mgm_redirect(add_query_arg(array('status' => 'error'), $this->_get_thankyou_url()));
     }
 }
コード例 #8
0
 function process_return()
 {
     // record POST/GET data
     do_action('mgm_print_module_data', $this->module, __FUNCTION__);
     // check and show message
     if (isset($_REQUEST['cbreceipt']) && !empty($_REQUEST['cbreceipt']) || isset($_REQUEST['custom']) && !empty($_REQUEST['custom'])) {
         // redirect as success if not already redirected
         // query arg
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_REQUEST['custom']));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_REQUEST['custom']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($_REQUEST['custom']);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // error
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => urlencode('clickbank receipt error')), $this->_get_thankyou_url()));
     }
 }
コード例 #9
0
 function process_return()
 {
     // read input stream
     $this->_inputstream_post();
     // record POST/GET data
     do_action('mgm_print_module_data', $this->module, __FUNCTION__);
     // check and show message
     if (isset($_POST['order_id']) && !empty($_POST['order_id']) || isset($_GET['status'])) {
         // tran
         $_POST['custom'] = '';
         // check
         if ($user_tran_id = mgm_cookie_var('CK_USER_LAST_TRANSACTION_ID')) {
             // set tran
             $_POST['custom'] = $user_tran_id;
             // delete it
             mgm_delete_cookie_var('CK_USER_LAST_TRANSACTION_ID');
         }
         // redirect as success if not already redirected
         $query_arg = array('status' => 'success');
         // set
         if (!empty($query_arg)) {
             $query_arg = array_merge($query_arg, array('trans_ref' => mgm_encode_id($_POST['custom'])));
         }
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_POST['custom']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($_POST['custom']);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // error
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => urlencode('1ShoppingCart Order Reference Error')), $this->_get_thankyou_url()));
     }
 }
コード例 #10
0
 function process_return()
 {
     // only save once success, there may be multiple try
     if (isset($_POST['custom']) && !empty($_POST['custom'])) {
         // process
         $this->process_notify();
         // query arg
         //trans_ref: mgm trans reference
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_POST['custom']));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_POST['custom']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($_POST['custom']);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // teat as error
         $errors = 'error in processing your request';
         // redirect
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => $errors), $this->_get_thankyou_url()));
     }
 }
コード例 #11
0
 function process_return()
 {
     if (!isset($this->response)) {
         $this->response = array();
     }
     // check and show message
     if ($this->process_payment() === true) {
         // redirect as success if not already redirected
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_POST['tran_id']));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_POST['tran_id']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($_POST['tran_id']);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // error
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => urlencode($this->process_payment())), $this->_get_thankyou_url()));
     }
 }
コード例 #12
0
/**
 * register post process
 *
 * @param int $user_id 
 * @return void or int $user_id
 */
function mgm_register($user_id)
{
    global $wpdb, $post;
    // check import in action and skip, tools->import calls mgm_register via "user_register" hook, this will help skip
    if (defined('MGM_DOING_USERS_IMPORT') && MGM_DOING_USERS_IMPORT == TRUE) {
        // return
        return $user_id;
    }
    // get mgm_system
    $system_obj = mgm_get_class('system');
    // hide
    $hide_custom_fields = $system_obj->get_setting('hide_custom_fields');
    // packs
    $packs = mgm_get_class('subscription_packs');
    // members object
    $member = mgm_get_member($user_id);
    // set status
    $member->set_field('status', MGM_STATUS_NULL);
    // get custom fields
    $cf_register_page = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true)));
    // mgm_subscription
    $mgm_subscription = mgm_post_var('mgm_subscription');
    // get subs
    $subs_pack = mgm_decode_package($mgm_subscription);
    // extract
    extract($subs_pack);
    // payment_gateways if set:
    $mgm_payment_gateways = mgm_post_var('mgm_payment_gateways');
    // Eg: $_POST['mgm_payment_gateways'] = mgm_paypal
    $cf_payment_gateways = !empty($mgm_payment_gateways) ? $mgm_payment_gateways : NULL;
    // init
    $member_custom_fields = array();
    // wordpress register
    $wordpres_form = mgm_check_wordpress_login();
    // system - issue #1237
    $short_format = !empty($system_obj->setting['date_format_short']) ? $system_obj->setting['date_format_short'] : MGM_DATE_FORMAT_SHORT;
    // loop
    foreach ($cf_register_page as $field) {
        // skip custom fields by settings call
        if ($hide_custom_fields == 'Y' || $hide_custom_fields == 'W' && $wordpres_form || $hide_custom_fields == 'C' && !$wordpres_form) {
            // if($hide_custom_fields && $field['name'] != 'subscription_options') continue;
            if (!in_array($field['name'], array('subscription_options', 'payment_gateways'))) {
                continue;
            }
        }
        //skip if payment_gateways custom field
        if ($field['name'] == 'payment_gateways') {
            continue;
        }
        //
        // do not save html
        if ($field['type'] == 'html' || $field['type'] == 'label') {
            continue;
        }
        // save
        switch ($field['name']) {
            case 'username':
                // #739
                if (isset($_POST[$field['attributes']['capture_field_alias']])) {
                    $member_custom_fields[$field['name']] = @$_POST[$field['attributes']['capture_field_alias']];
                } else {
                    $member_custom_fields[$field['name']] = @$_POST['user_login'];
                }
                break;
            case 'email':
                // #739
                if (isset($_POST[$field['attributes']['capture_field_alias']])) {
                    $member_custom_fields[$field['name']] = @$_POST[$field['attributes']['capture_field_alias']];
                } else {
                    $member_custom_fields[$field['name']] = @$_POST['user_email'];
                }
                break;
            case 'password':
                // #739
                // check
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    if (!empty($_POST[$field['attributes']['capture_field_alias']])) {
                        $user_password = @$_POST[$field['attributes']['capture_field_alias']];
                        $member_custom_fields[$field['name']] = mgm_encrypt_password($user_password, $user_id);
                    }
                } else {
                    if (!empty($_POST['user_password'])) {
                        $user_password = $_POST['user_password'];
                        $member_custom_fields[$field['name']] = mgm_encrypt_password($user_password, $user_id);
                    }
                }
                break;
            case 'autoresponder':
                // #739
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    // checked issue #839
                    // if(in_array(strtolower($_POST[$field['attributes']['capture_field_alias']]), array('y','yes'))){
                    if (!empty($_POST[$field['attributes']['capture_field_alias']]) && $_POST['mgm_register_field'][$field['name']] == $field['value']) {
                        $member->subscribed = 'Y';
                        $member->autoresponder = $system_obj->active_modules['autoresponder'];
                    }
                } else {
                    // checked issue #839
                    // if(in_array(strtolower($_POST['mgm_register_field'][$field['name']]), array('y','yes'))){
                    if (!empty($_POST['mgm_register_field'][$field['name']]) && $_POST['mgm_register_field'][$field['name']] == $field['value']) {
                        // set to member, to be used on payment
                        $member->subscribed = 'Y';
                        $member->autoresponder = $system_obj->active_modules['autoresponder'];
                    }
                }
                break;
            case 'coupon':
                // #739
                // check alias
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    // check
                    if (!empty($_POST[$field['attributes']['capture_field_alias']])) {
                        // validate
                        if ($coupon = mgm_validate_coupon($_POST[$field['attributes']['capture_field_alias']], $cost)) {
                            // set
                            $member->coupon = $coupon;
                            // update coupon usage
                            mgm_update_coupon_usage($coupon['id'], 'register');
                        }
                    }
                } else {
                    // check primary
                    if (isset($_POST['mgm_register_field'][$field['name']]) && !empty($_POST['mgm_register_field'][$field['name']])) {
                        // validate
                        if ($coupon = mgm_validate_coupon($_POST['mgm_register_field'][$field['name']], $cost)) {
                            // set
                            $member->coupon = $coupon;
                            // update coupon usage
                            mgm_update_coupon_usage($coupon['id'], 'register');
                        }
                    }
                }
                break;
            case 'birthdate':
                // #739
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    //issue #1237
                    $member_custom_fields[$field['name']] = mgm_format_inputdate_to_mysql($_POST[$field['attributes']['capture_field_alias']], $short_format);
                } else {
                    //convert from short date format to mysql format - issue #1237
                    $member_custom_fields[$field['name']] = mgm_format_inputdate_to_mysql($_POST['mgm_register_field'][$field['name']], $short_format);
                }
                break;
            default:
                // #739
                if (isset($field['attributes']['capture_field_alias']) && isset($_POST[$field['attributes']['capture_field_alias']])) {
                    $member_custom_fields[$field['name']] = @$_POST[$field['attributes']['capture_field_alias']];
                } elseif ($field['type'] == 'checkbox' && is_array(@$_POST['mgm_register_field'][$field['name']])) {
                    //$member_custom_fields[$field['name']] = implode(" ", @$_POST['mgm_register_field'][$field['name']]);
                    //issue #1070
                    $val = @$_POST['mgm_register_field'][$field['name']];
                    $member_custom_fields[$field['name']] = serialize($val);
                } else {
                    $member_custom_fields[$field['name']] = @$_POST['mgm_register_field'][$field['name']];
                }
                break;
        }
    }
    // end fields save
    // user password not provided
    /*
    	if (!isset( $user_password )){
    		$user_password = (isset($_POST['pass1']) && !empty($_POST['pass1'])) ? trim($_POST['pass1']) : substr(md5(uniqid(microtime())), 0, 7);		
    	}*/
    // user password not provided
    if (!isset($user_password)) {
        // take custom password fields, iss#717, consider BP custom password field
        $password_fields = array('pass1', 'signup_password');
        // loop
        foreach ($password_fields as $password_field) {
            // check if set
            if (isset($_POST[$password_field]) && !empty($_POST[$password_field])) {
                $user_password = trim($_POST[$password_field]);
                break;
            }
        }
    }
    // auto generate if still missing
    if (!isset($user_password)) {
        $user_password = substr(md5(uniqid(microtime())), 0, 7);
    }
    //encrypt password and save in
    $member->user_password = mgm_encrypt_password($user_password, $user_id);
    // md5
    $user_password_hash = wp_hash_password($user_password);
    // db update
    $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->users}` SET `user_pass` = %s WHERE ID = %d", $user_password_hash, $user_id));
    // unset label fields
    if (isset($member_custom_fields['password_conf'])) {
        unset($member_custom_fields['password_conf']);
    }
    // set custom
    $member->set_custom_fields($member_custom_fields);
    // set pack
    if ($pack_id) {
        // pack
        $pack = $packs->get_pack($pack_id);
        // set
        $member->amount = $pack['cost'];
        $member->duration = $pack['duration'];
        $member->duration_type = $pack['duration_type'];
        $member->active_num_cycles = $pack['num_cycles'];
        // set membership type
        $member->membership_type = $membership_type;
        // from mgm_subscription
        // set in member
        $member->pack_id = $pack_id;
        // from mgm_subscription
    }
    // set status
    $member->status = MGM_STATUS_NULL;
    // update option
    $member->save();
    // update user firstname/last name
    mgm_update_default_userdata($user_id);
    // admin check
    $is_admin = is_admin();
    //&& current_user_can('manage_options');
    // send
    $notify_user = true;
    // Block registration emails if Buddypress is enabled and disable_registration_email_bp value is Yes
    $block_reg_email = bool_from_yn(mgm_get_class('system')->get_setting('disable_registration_email_bp'));
    // send notification, bp active, do not send password, #739
    if (!isset($_POST['send_password']) && $is_admin || mgm_is_plugin_active('buddypress/bp-loader.php') && $block_reg_email) {
        $notify_user = false;
    }
    // send notification - issue #1468
    if ($system_obj->setting['enable_new_user_email_notifiction_after_user_active'] == 'N') {
        if ($notify_user) {
            mgm_new_user_notification($user_id, $user_password, $is_admin ? false : true);
        }
        $notify_user = false;
    }
    // hook for other plugin who wishes to use default "user_register"
    do_action('mgm_user_register', $user_id);
    // process payment only when registered from site, not when user added by admin
    if ($is_admin) {
        // unset
        unset($_POST['send_password']);
        //prevent sending user email again
        // assign default pack
        do_action('mgm_admin_user_register', $user_id, $notify_user);
        // return id
        return $user_id;
    }
    // if on wordpress page or custompage
    $post_id = get_the_ID();
    // post custom register
    if ($post_id > 0 && $post->post_type == 'post') {
        $redirect = get_permalink($post_id);
    } else {
        $redirect = mgm_get_custom_url('transactions');
    }
    // if buddypress url replace by register url : issue#: 791
    $redirect = apply_filters('mgm_bp_register_url', $redirect);
    // userdata
    $userdata = get_userdata($user_id);
    // note this fix VERY IMPORTANT, needed for PAYPAL PRO CC POST
    $redirect = add_query_arg(array('username' => urlencode($userdata->user_login)), $redirect);
    // add redirect
    if ($redirector = mgm_request_var('mgm_redirector', mgm_request_var('redirect_to', '', true), true)) {
        $redirect = add_query_arg(array('redirector' => $redirector), $redirect);
    }
    // with subscription
    if ($mgm_subscription) {
        $redirect = add_query_arg(array('subs' => $mgm_subscription, 'method' => 'payment_subscribe'), $redirect);
    }
    // bypass step2 if payment gateway is submitted: issue #: 469
    if (!is_null($cf_payment_gateways)) {
        // pack
        $packs_obj = mgm_get_class('subscription_packs');
        // validate
        $pack = $packs_obj->validate_pack($cost, $duration, $duration_type, $membership_type, $pack_id);
        // error
        if ($pack != false) {
            // get pack
            mgm_get_register_coupon_pack($member, $pack);
            // cost
            if ((double) $pack['cost'] > 0) {
                //get an object of the payment gateway:
                $mod_obj = mgm_get_module($cf_payment_gateways, 'payment');
                // tran options
                $tran_options = array('is_registration' => true, 'user_id' => $user_id, 'notify_user' => $notify_user);
                // is register & purchase
                if (isset($_POST['post_id'])) {
                    $tran_options['post_id'] = (int) $_POST['post_id'];
                }
                // is register & purchase postpack
                if (isset($_POST['postpack_post_id']) && isset($_POST['postpack_id'])) {
                    $tran_options['postpack_post_id'] = (int) $_POST['postpack_post_id'];
                    $tran_options['postpack_id'] = (int) $_POST['postpack_id'];
                }
                // create transaction
                // $tran_id = $mod_obj->_create_transaction($pack, $tran_options);
                $tran_id = mgm_add_transaction($pack, $tran_options);
                //bypass directly to process return if manual payment:
                if ($cf_payment_gateways == 'mgm_manualpay') {
                    // set
                    $_POST['custom'] = $tran_id;
                    // direct call to module return function:
                    $mod_obj->process_return();
                    // exit
                    exit;
                }
                // encode id:
                $tran_id = mgm_encode_id($tran_id);
                // redirect - if on wordpress page or custompage - issue #1648
                if ($post_id > 0 && $post->post_type == 'post') {
                    $redirect = $mod_obj->_get_endpoint('html_redirect', true);
                } else {
                    $redirect = $mod_obj->_get_endpoint('html_redirect', false);
                }
                // if buddypress url replace by register url : issue#: 791
                $redirect = add_query_arg(array('tran_id' => $tran_id), apply_filters('mgm_bp_register_url', $redirect));
            } else {
                // issue #1468
                $redirect = add_query_arg(array('notify_user' => $notify_user), $redirect);
            }
        }
    }
    // ends custom payment gateway bypassing
    // is register & purchase
    if (isset($_POST['post_id'])) {
        $redirect = add_query_arg(array('post_id' => (int) $_POST['post_id']), $redirect);
    }
    // is register & purchase postpack
    if (isset($_POST['postpack_post_id']) && isset($_POST['postpack_id'])) {
        $redirect = add_query_arg(array('postpack_id' => (int) $_POST['postpack_id'], 'postpack_post_id' => (int) $_POST['postpack_post_id']), $redirect);
    }
    // redirect filter, returing a false can stop the redirect
    $redirect = apply_filters('mgm_after_regiter_redirect', mgm_site_url($redirect));
    // redirect
    if ($redirect !== FALSE) {
        // do the redirect to payment
        mgm_redirect($redirect);
        // this goes to subscribe, mgm_functions.php/mgm_get_subscription_buttons
        // exit
        exit;
    }
    // default
    return $user_id;
}
コード例 #13
0
 function process_return()
 {
     // check and show message
     if (isset($_REQUEST['apc_1'])) {
         // query arg
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_REQUEST['apc_1']));
         // is a post redirect?
         if (isset($_REQUEST['apc_1'])) {
             // is a post redirect?
             $post_redirect = $this->_get_post_redirect($_REQUEST['apc_1']);
             // set post redirect
             if ($post_redirect !== false) {
                 $query_arg['post_redirect'] = $post_redirect;
             }
             // is a register redirect?
             $register_redirect = $this->_auto_login($_REQUEST['apc_1']);
             // set register redirect
             if ($register_redirect !== false) {
                 $query_arg['register_redirect'] = $register_redirect;
             }
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         mgm_redirect(add_query_arg(array('status' => 'error'), $this->_get_thankyou_url()));
     }
 }
コード例 #14
0
 function process_return()
 {
     // check and show message
     if (isset($this->response->id)) {
         // id
         // caller
         $this->webhook_called_by = 'self';
         // process notify, internally called
         $this->process_notify();
         // redirect as success if not already redirected
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_POST['custom']));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_POST['custom']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($_POST['custom']);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // error
         $error = isset($this->response->error->message) ? $this->response->error->message : 'Unknown error';
         // error
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => urlencode($error)), $this->_get_thankyou_url()));
     }
 }
コード例 #15
0
 function process_return()
 {
     if (!isset($this->response)) {
         $this->response = array();
     }
     // only save once success, there may be multiple try
     if ($this->response['ACK'] == 'Success' || $this->response['ACK'] == 'SuccessWithWarning') {
         // process
         $this->process_notify();
         // query arg
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_POST['custom']));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_POST['custom']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($_POST['custom']);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // teat as error
         $errors = urlencode($this->response['L_ERRORCODE0'] . ': ' . $this->response['L_SHORTMESSAGE0'] . ' - ' . $this->response['L_LONGMESSAGE0']);
         // redirect
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => $errors), $this->_get_thankyou_url()));
     }
 }
コード例 #16
0
 function process_return()
 {
     // check and show message
     if (isset($_REQUEST['crypt'])) {
         // parse crypt
         $_POST = $this->_crypt($_REQUEST['crypt']);
         // custom
         $alt_tran_id = $this->_get_alternate_transaction_id();
         // process notify, internally called
         $this->process_notify();
         // query arg
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($alt_tran_id));
         // is a post redirect?
         if (isset($alt_tran_id) && !empty($alt_tran_id)) {
             // is a post redirect?
             $post_redirect = $this->_get_post_redirect($alt_tran_id);
             // set post redirect
             if ($post_redirect !== false) {
                 $query_arg['post_redirect'] = $post_redirect;
             }
             // is a register redirect?
             $register_redirect = $this->_auto_login($alt_tran_id);
             // set register redirect
             if ($register_redirect !== false) {
                 $query_arg['register_redirect'] = $register_redirect;
             }
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         mgm_redirect(add_query_arg(array('status' => 'error'), $this->_get_thankyou_url()));
     }
 }
コード例 #17
0
/**
 * get post purchase buttons
 * final step for post purchase
 *
 * @param void
 * @return $html
 */
function mgm_get_post_purchase_buttons()
{
    // get current user data - issue #1421
    $user = wp_get_current_user();
    // pack
    $pack = NULL;
    // addon options
    if ($addon_option_ids = mgm_post_var('addon_options')) {
        $addon_options = mgm_get_addon_options_only($addon_option_ids);
        // mgm_pr($addon_options);
    }
    // post purchase
    if (isset($_POST['post_id'])) {
        //issue #1250
        if (isset($_POST['mgm_postpurchase_field']['coupon']) && !empty($_POST['mgm_postpurchase_field']['coupon'])) {
            //issue #1250 - Coupon validation
            if (!empty($_POST['form_action'])) {
                // check if its a valid coupon
                if (!($coupon = mgm_get_coupon_data($_POST['mgm_postpurchase_field']['coupon']))) {
                    //redirect back to the form
                    $q_arg = array('error_field' => 'Coupon', 'error_type' => 'invalid', 'error_field_value' => $_POST['mgm_postpurchase_field']['coupon']);
                    $redirect = add_query_arg($q_arg, $_POST['form_action']);
                    mgm_redirect($redirect);
                    exit;
                }
            }
        }
        // post id
        $post_id = $_POST['post_id'];
        // gete mgm data
        $post_obj = mgm_get_post($post_id);
        $cost = mgm_convert_to_currency($post_obj->purchase_cost);
        $product = $post_obj->product;
        $allowed_modules = $post_obj->allowed_modules;
        // post data
        $post = get_post($post_id);
        $title = $post->post_title;
        // item name -issue #1380
        $item_name = apply_filters('mgm_post_purchase_itemname', sprintf(__('Purchase Post - %s', 'mgm'), $title));
        // set pack
        $pack = array('duration' => 1, 'item_name' => $item_name, 'buypost' => 1, 'cost' => $cost, 'title' => $title, 'product' => $product, 'post_id' => $post_id, 'allowed_modules' => $allowed_modules);
    } else {
        if (isset($_POST['postpack_id'])) {
            // post pack purchase
            //issue #1250
            if (isset($_POST['mgm_postpurchase_field']['coupon']) && !empty($_POST['mgm_postpurchase_field']['coupon'])) {
                //issue #1250 - Coupon validation
                if (!empty($_POST['form_action'])) {
                    // check if its a valid coupon
                    if (!($coupon = mgm_get_coupon_data($_POST['mgm_postpurchase_field']['coupon']))) {
                        //redirect back to the form
                        $q_arg = array('error_field' => 'Coupon', 'error_type' => 'invalid', 'error_field_value' => $_POST['mgm_postpurchase_field']['coupon']);
                        $redirect = add_query_arg($q_arg, $_POST['form_action']);
                        mgm_redirect($redirect);
                        exit;
                    }
                }
            }
            // post pack purchase
            $postpack_id = $_POST['postpack_id'];
            // pcak id
            $postpack_post_id = $_POST['postpack_post_id'];
            // post id where pack is listed, redirect here
            // get pack
            $postpack = mgm_get_postpack($postpack_id);
            $cost = mgm_convert_to_currency($postpack->cost);
            $product = json_decode($postpack->product, true);
            $modules = json_decode($postpack->modules, true);
            //mgm_pr($postpack);
            // item name -issue #1380
            $item_name = apply_filters('mgm_postpack_purchase_itemname', sprintf(__('Purchase Post Pack - %s', 'mgm'), $postpack->name));
            // post id
            $post_id = mgm_get_postpack_posts_csv($postpack_id);
            // set pack
            $pack = array('duration' => 1, 'item_name' => $item_name, 'buypost' => 1, 'cost' => $cost, 'title' => $postpack->name, 'product' => $product, 'post_id' => $post_id, 'postpack_id' => $postpack_id, 'postpack_post_id' => $postpack_post_id, 'allowed_modules' => $modules);
        }
    }
    // check
    if (!$pack) {
        return __('Error in Payment! No data available ');
        exit;
    }
    // guest token	-issue #1421
    if (isset($_POST['guest_purchase']) && $_POST['guest_purchase'] == TRUE && $user->ID <= 0) {
        $pack['guest_token'] = sanitize_title_for_query(mgm_create_token());
    }
    // addon options
    if (isset($addon_options) && !empty($addon_options)) {
        $pack['addon_options'] = $addon_options;
    }
    // get coupon
    $post_purchase_coupon = mgm_save_partial_fields(array('on_postpurchase' => true), 'mgm_postpurchase_field', $pack['cost'], false, 'postpurchase');
    // alter
    mgm_get_post_purchase_coupon_pack($post_purchase_coupon, $pack);
    // Eg: $_POST['mgm_payment_gateways'] = mgm_paypal
    $cf_payment_gateways = isset($_POST['mgm_payment_gateways']) && !empty($_POST['mgm_payment_gateways']) ? $_POST['mgm_payment_gateways'] : null;
    // bypass step2 if payment gateway is submitted: issue #: 469
    if (!is_null($cf_payment_gateways)) {
        // get pack
        // mgm_get_upgrade_coupon_pack($member, $selected_pack);
        // cost
        if ((double) $pack['cost'] > 0) {
            //get an object of the payment gateway:
            $mod_obj = mgm_get_module($cf_payment_gateways, 'payment');
            // tran options
            $tran_options = array('user_id' => $user->ID);
            // is register & purchase
            if (isset($_POST['post_id'])) {
                $tran_options['post_id'] = (int) $_POST['post_id'];
            }
            // postpack id
            if (isset($_POST['postpack_id'])) {
                $tran_options['postpack_id'] = (int) $_POST['postpack_id'];
            }
            // is register & purchase postpack
            if (isset($_POST['postpack_post_id']) && isset($_POST['postpack_id'])) {
                $tran_options['postpack_post_id'] = (int) $_POST['postpack_post_id'];
                $tran_options['postpack_id'] = (int) $_POST['postpack_id'];
            }
            // create transaction
            $tran_id = mgm_add_transaction($pack, $tran_options);
            // bypass directly to process return if manual payment:
            if ($cf_payment_gateways == 'mgm_manualpay') {
                // set
                $_POST['custom'] = $tran_id;
                // direct call to module return function:
                $mod_obj->process_return();
                // exit
                exit;
            }
            // encode id:
            $tran_id = mgm_encode_id($tran_id);
            $redirect = $mod_obj->_get_endpoint('html_redirect', true);
            $redirect = add_query_arg(array('tran_id' => $tran_id), $redirect);
            // redirect
            mgm_redirect($redirect);
            // this goes to subscribe, mgm_functions.php/mgm_get_subscription_buttons
            // exit
            exit;
        }
    }
    // get payment modules
    $a_payment_modules = mgm_get_class('system')->get_active_modules('payment');
    // init
    $payment_modules = array();
    // when active
    if ($a_payment_modules) {
        // loop
        foreach ($a_payment_modules as $payment_module) {
            // not trial
            if (in_array($payment_module, array('mgm_free', 'mgm_trial'))) {
                continue;
            }
            // store
            $payment_modules[] = $payment_module;
        }
    }
    // init
    $button = '';
    // transaction
    $tran_id = NULL;
    $button_printed = 0;
    // loop modules
    foreach ($payment_modules as $module) {
        // object
        $mod_obj = mgm_get_module($module, 'payment');
        // check buypost support
        if (in_array('buypost', $mod_obj->supported_buttons)) {
            // create transaction
            if (!$tran_id) {
                $tran_id = mgm_add_transaction($pack);
            }
            // button code
            if (isset($pack['allowed_modules'])) {
                // Issue #1562: If no payment module is selected, display all supported modules
                if (!empty($pack['allowed_modules']) && FALSE === in_array($module, $pack['allowed_modules'])) {
                    continue;
                }
            }
            $button_code = $mod_obj->get_button_buypost(array('pack' => $pack, 'tran_id' => $tran_id), true);
            $button_printed++;
            // get button
            $button .= "<div class='mgm_custom_filed_table'>" . $button_code . "</div>";
        }
    }
    // none active
    if ($button_printed == 0) {
        $button .= sprintf('<p class="mgm-no-module"> %s </p>', __('No Payment module active for this Content Purchase.', 'mgm'));
    }
    // if Cost is zero, then process using free module.: issue#: 883
    if ($tran_id && $pack['cost'] == 0 && in_array('mgm_free', $a_payment_modules) && mgm_get_module('mgm_free')->is_enabled()) {
        // module
        $module = 'mgm_free';
        // payments url
        $payments_url = mgm_get_custom_url('transactions');
        // query_args
        $query_args = array('method' => 'payment_return', 'module' => $module, 'custom' => $tran_id);
        // redirector
        if (isset($_REQUEST['redirector'])) {
            // set
            $query_args['redirector'] = $_REQUEST['redirector'];
        }
        // redirect to module to mark the payment as complete
        $redirect = add_query_arg($query_args, $payments_url);
        // redirect
        mgm_redirect($redirect);
    }
    // html
    $return = '<div class="post_purchase_select_gateway">' . __('Please Select a Payment Gateway.', 'mgm') . '</div>' . $button;
    // return
    return $return;
}
コード例 #18
0
 function _encode_id($trans_id)
 {
     return mgm_encode_id($trans_id);
 }
コード例 #19
0
 function process_return()
 {
     // check and show message
     // if(isset($_REQUEST['status']) && $_REQUEST['status']=='success'){
     // issue#: 360:
     $payment_status = $this->_parse_payment_status($_REQUEST['STATUS']);
     // check
     if ($payment_status == 'Authorized' || $payment_status == 'Payment requested') {
         // query arg
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_REQUEST['COMPLUS']));
         // is a post redirect?
         if (isset($_REQUEST['COMPLUS'])) {
             // is a post redirect?
             $post_redirect = $this->_get_post_redirect($_REQUEST['COMPLUS']);
             // set post redirect
             if ($post_redirect !== false) {
                 $query_arg['post_redirect'] = $post_redirect;
             }
             // is a register redirect?
             $register_redirect = $this->_auto_login($_REQUEST['COMPLUS']);
             // set register redirect
             if ($register_redirect !== false) {
                 $query_arg['register_redirect'] = $register_redirect;
             }
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         mgm_redirect(add_query_arg(array('status' => 'error'), $this->_get_thankyou_url()));
     }
 }
コード例 #20
0
 function process_return()
 {
     // init
     if (!isset($this->response)) {
         $this->response = array();
     }
     // check and show message
     if (isset($this->response['response_status']) && $this->response['response_status'] != 3) {
         // 3 == Error
         // caller
         $this->set_webhook_called_by('self');
         // process notify, internally called
         $this->process_notify();
         // redirect as success if not already redirected
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_POST['x_custom']));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_POST['x_custom']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($_POST['x_custom']);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // error
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => urlencode($this->response['message_text'])), $this->_get_thankyou_url()));
     }
 }
コード例 #21
0
 function process_return()
 {
     // record POST/GET data
     do_action('mgm_print_module_data', $this->module, __FUNCTION__);
     // populate transaction
     if (!isset($_POST['M_CUSTOM'])) {
         // recompose
         $this->_populate_transaction();
     }
     // only save once success, there may be multiple try
     if (isset($_POST['RESULT']) && (int) $_POST['RESULT'] == 0 && isset($_POST['RESPMSG']) && $_POST['RESPMSG'] == 'Approved') {
         // query arg
         $query_arg = array('status' => 'success', 'trans_ref' => mgm_encode_id($_POST['M_CUSTOM']));
         // is a post redirect?
         $post_redirect = $this->_get_post_redirect($_POST['M_CUSTOM']);
         // set post redirect
         if ($post_redirect !== false) {
             $query_arg['post_redirect'] = $post_redirect;
         }
         // is a register redirect?
         $register_redirect = $this->_auto_login($_POST['M_CUSTOM']);
         // set register redirect
         if ($register_redirect !== false) {
             $query_arg['register_redirect'] = $register_redirect;
         }
         // redirect
         mgm_redirect(add_query_arg($query_arg, $this->_get_thankyou_url()));
     } else {
         // teat as error
         $errors = urlencode($_POST['L_ERRORCODE0'] . ': ' . $_POST['L_SHORTMESSAGE0'] . ' - ' . $_POST['L_LONGMESSAGE0']);
         // redirect
         mgm_redirect(add_query_arg(array('status' => 'error', 'errors' => $errors), $this->_get_thankyou_url()));
     }
 }