'eProcessingNetwork Gateway', 'api_version' => 2.0, 'class_name' => 'wpsc_merchant_epngateway', 'has_recurring_billing' => true, 'display_name' => 'eProcessing CC Payment', 'wp_admin_cannot_cancel' => false, 'requirements' => array( /// so that you can restrict merchant modules to PHP 5, if you use PHP 5 features ///'php_version' => 5.0, ), 'form' => 'form_epngateway', 'submit_function' => 'submit_epngateway', // this may be legacy, not yet decided 'internalname' => 'wpsc_merchant_epngateway', ); class wpsc_merchant_epngateway extends wpsc_merchant { // Build an array we can send to eProcessing Network function construct_value_array(){ $data = array( ); //ePN account data entered in settings in admin area $data['ePNAccount'] = get_option( 'ePNAccountNum' ); $data['RestrictKey'] = get_option( 'RestrictKey' ); //Make sure that the URL to Logo field contains an image link. //DBE will give a vague error message and not allow the processing page to load if the URL doesn't point to an image. if (preg_match('/([^\s]+(?=\.(jpg|gif|png))\.\2)/i', get_option('epn_logo'))) { $data['LogoURL'] = get_option('epn_logo'); } $data['HTML'] = "No"; // CC data $data['CardType'] = $_POST['cctype']; $data['CardNo'] = $_POST['card_number']; $data['ExpMonth'] = $_POST['expiry']['month']; $data['ExpYear'] = substr($_POST['expiry']['year'],2,2); $data['CVV2'] = $_POST['card_code']; $data['CVV2Type'] = 1; // Billing Data $data['FirstName'] = $this->cart_data['billing_address']['first_name']; $data['LastName'] = $this->cart_data['billing_address']['last_name']; $data['EMail'] = $this->cart_data['email_address']; $data['Address'] = $this->cart_data['billing_address']['address']; $data['City'] = $this->cart_data['billing_address']['city']; $data['State'] = $this->cart_data['billing_address']['state']; $data['Country'] = $this->cart_data['billing_address']['country']; $data['Zip'] = $this->cart_data['billing_address']['post_code']; //Order $data['Total'] = $this->cart_data['total_price']; $data['SessID'] = $this->cart_data['session_id']; $data['PurchID'] = $this->purchase_id; $this->collected_gateway_data = $data; } function submit() { //Set purchase state as "Processing" $this->set_purchase_processed_by_purchid(2); if (get_option('epn_debug') == "Yes") { //Debug mode $data = $this->collected_gateway_data; $data['email'] = get_option('epn_debug_email'); $data['PostURL'] = "https://www.eProcessingNetwork.com/cgi-bin/dbe/order.pl"; $this->collected_gateway_data = $data; // initiate cURL w/ protocol & URL of remote host $ch=curl_init("https://www.eprocessingnetwork.com/cgi-bin/Reflect/transact.pl "); // normal POST request curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$this->collected_gateway_data); // set response to return as variable curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); // trap response into $response var $response=curl_exec($ch); // close cURL transfer curl_close($ch); $this->set_transaction_details("Test Transaction", 1 ); echo($response); } elseif (get_option('epn_mode') == "0") { //Actions performed if DBE mode // Create Form to POST $output = "

If you are not automatically forwarded to the payment site, you can click the \"Continue\" button below.

\n "; foreach($this->collected_gateway_data as $n=>$v) { $output .= "\n"; } $output .= "
"; echo($output); echo(""); exit(); } else { //Actions performed if TDBE mode // initiate cURL w/ protocol & URL of remote host $ch=curl_init("https://www.eProcessingNetwork.Com/cgi-bin/tdbe/transact.pl"); // normal POST request curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$this->collected_gateway_data); // set response to return as variable curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); // trap response into $response var $response=curl_exec($ch); // close cURL transfer curl_close($ch); $auth=substr($response,1,1); if ($auth=="Y") { //Set transaction detail to "accepted payment" $this->set_transaction_details(substr($response,11,6), 3 ); $this->go_to_transaction_results($this->cart_data['session_id']); }else{ //Set detail to "payment declined" and show error message $this->set_transaction_details("N/A", 6 ); $endofmessage = strpos($response,'","'); $errMess = substr($response,2,($endofmessage-2)); //$errMess = $response; $this->set_error_message($errMess); $this->return_to_checkout(); } exit(); } } } function form_epngateway() { if (get_option("epn_visa")=="1") { $epn_visaY="checked='checked'"; }elseif (get_option("enp_visa")=="0") { $epn_visaN="checked='checked'"; } if (get_option("epn_discover")=="1") { $epn_discoverY="checked='checked'"; }elseif (get_option("enp_discover")=="0") { $epn_discoverN="checked='checked'"; } if (get_option("epn_mastercard")=="1") { $epn_mastercardY="checked='checked'"; }elseif (get_option("enp_mastercard")=="0") { $epn_mastercardN="checked='checked'"; } if (get_option("epn_amex")=="1") { $epn_amexY="checked='checked'"; }elseif (get_option("enp_amex")=="0") { $epn_amexN="checked='checked'"; } if (get_option("epn_mode")=="1") { $epn_modeY="checked='checked'";//TDBE }elseif (get_option("enp_mode")=="0") { $epn_modeN="checked='checked'";//DBE } if (get_option("epn_debug")=="Yes") { $epn_debugY="checked='checked'"; } $output = " \n"; $output .= " \n"; $output .= " Payment Mode TDBE DBE(offsite processing) "; $output .= "

Accept Visa Yes No \n

Accept Discover Yes No \n

Accept MasterCard Yes No \n

Accept American Express Yes No \n \n \n "; return $output; } function submit_epngateway() { if ( isset( $_POST['ePNAccount'] ) ) update_option( 'ePNAccountNum', $_POST['ePNAccount'] ); if ( isset( $_POST['RestrictKey'] ) ) update_option( 'RestrictKey', $_POST['RestrictKey'] ); if ( isset( $_POST['epn_logo'] ) ) update_option( 'epn_logo', $_POST['epn_logo'] ); if ( isset( $_POST['epn_visa'] ) ) update_option( 'epn_visa', $_POST['epn_visa'] ); if ( isset( $_POST['epn_discover'] ) ) update_option( 'epn_discover', $_POST['epn_discover'] ); if ( isset( $_POST['epn_mastercard'] ) ) update_option( 'epn_mastercard', $_POST['epn_mastercard'] ); if ( isset( $_POST['epn_amex'] ) ) update_option( 'epn_amex', $_POST['epn_amex'] ); if ( isset( $_POST['epn_mode'] ) ) update_option( 'epn_mode', $_POST['epn_mode'] ); if ( isset( $_POST['epn_debug'] ) ) update_option( 'epn_debug', $_POST['epn_debug'] ); if ( isset( $_POST['epn_debug_email'] ) ) update_option( 'epn_debug_email', $_POST['epn_debug_email'] ); return true; } function nzshpcrt_epngateway_callback() { if (($_GET['eProcessing_return']=="yes") && ($_POST['approved']=="Y")) { //Perform this action when being sent from eProcessing DBE page with approval //$transid = $_POST['ID']; $merchantTransaction = new wpsc_merchant_epngateway(); $merchantTransaction->session_id = $_POST['SessID']; $merchantTransaction->purchase_id = $_POST['PurchID']; //Set transaction detail to "accepted payment" $merchantTransaction->set_transaction_details($merchantTransaction->purchase_id , 3 ); $merchantTransaction->go_to_transaction_results($merchantTransaction->session_id); unset($merchantTransaction); } elseif (($_GET['eProcessing_return']=="yes") && ($_POST['approved']=="N")) { //Perform this when denied $merchantTransaction = new wpsc_merchant_epngateway(); $merchantTransaction->session_id = $_POST['SessID']; $merchantTransaction->purchase_id = $_POST['PurchID']; //Set transaction detail to "Payment Denied" $merchantTransaction->set_transaction_details($merchantTransaction->purchase_id, 6 ); //Set error message and forward the user to the checkout page displaying the error $errMess = "Sorry, there was an error processing your payment."; $merchantTransaction->set_error_message($errMess); $merchantTransaction->return_to_checkout(); } } /* Adds CC form to checkout page */ $years = $months = $CCs = ''; if ( in_array( 'wpsc_merchant_epngateway', (array)get_option( 'custom_gateway_options' ) ) && (get_option('epn_mode') == "1")) { $curryear = date( 'Y' ); //generate year options for ( $i = 0; $i < 10; $i++ ) { $years .= "\r\n"; $curryear++; } //Populate the Credit Card options $availableCC = array(); if (get_option("epn_visa")=="1") { array_push($availableCC,"Visa"); } if (get_option("epn_discover")=="1") { array_push($availableCC,"Discover"); } if (get_option("epn_mastercard")=="1") { array_push($availableCC,"MasterCard"); } if (get_option("epn_amex")=="1") { array_push($availableCC,"American Express"); } foreach($availableCC as &$CCName) { $CCs .= "\r\n"; } $gateway_checkout_form_fields[$nzshpcrt_gateways[$num]['class_name']] = " " . __( 'Card Type', 'wpsc' ) . " * " . __( 'Credit Card Number', 'wpsc' ) . " * " . __( 'Credit Card Expiration', 'wpsc' ) . " * " . __( 'CVV', 'wpsc' ) . " * "; } add_action('init', 'nzshpcrt_epngateway_callback'); ?>