'inetsecure/form', 'title' => t('Credit Card Payment'), 'callback' => 'inetsecure_page', 'access' => true, 'type' => MENU_CALLBACK); $items[] = array('path' => 'inetsecure/script', 'title' => t('Return Script Page'), 'callback' => 'inetsecure_script', 'access' => true, 'type' => MENU_CALLBACK); } return $items; } /** * Implementation of hook_help(). */ function inetsecure_help($section = 'admin/help#inetsecure') { switch ($section) { case 'admin/modules#description': return t('Process payments using internetsecure.com.'); case 'admin/settings/inetsecure': return t("You need to have an Internet Secure merchant account in order to use this module. See here for more information."); case 'inetsecure/form_submit_guidlines': return t("After entering your credit card information, please be sure to click the complete payment button to return to the site."); } } function inetsecure_ec_settings() { $output = ''; $form['settings'] = array( '#type' => 'fieldset', '#title' => t('Main settings'), '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['settings']['inetsecure_help'] = array( '#type' => 'textarea', '#title' => t('Explanation or submission guidelines'), '#default_value' => variable_get('inetsecure_help', inetsecure_help('inetsecure/form_submit_guidlines')), '#cols' => 70, '#rows' => 5, '#description' => t('This text will be displayed at the top of the credit card submission form.'), ); $form['settings']['inetsecure_login'] = array( '#type' => 'textfield', '#title' => t('Login ID'), '#default_value' => variable_get('inetsecure_login', ''), '#size' => 70, '#maxlength' => 180, '#description' => t("Enter your merchant login ID."), ); $form['settings']['inetsecure_url'] = array( '#type' => 'textfield', '#title' => t('Internet Secure processing URL'), '#default_value' => variable_get('inetsecure_url', 'https://secure.internetsecure.com/process.cgi'), '#size' => 70, '#maxlength' => 180, '#description' => t('URL of the secure payment processing page.'), ); $form['settings']['inetsecure_success_url'] = array( '#type' => 'textfield', '#title' => t('Successful payment URL'), '#default_value' => variable_get('inetsecure_success_url', '/'), '#size' => 70, '#maxlength' => 180, '#description' => t("This is the destination to which you would like to send your customers when their payment has been successfully completed. The URL must be a Drupal system path. If you are not using clean URLs, specify the part after '?q='. If unsure, specify '/'."), ); $form['settings']['inetsecure_debug'] = array( '#type' => 'radios', '#title' => t('Internet Secure test mode'), '#default_value' => variable_get('inetsecure_debug', 0), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('If enabled, transactions will be sent in test mode and cards will not be charged.'), ); $form['settings']['inetsecure_debug_decline'] = array( '#type' => 'radios', '#title' => t('Internet Secure test mode (decline)'), '#default_value' => variable_get('inetsecure_debug_decline', 0), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('If enabled, transactions will be sent in test mode and cards will not be charged. Will force a processor decline. Overrides test mode (above).'), ); $form['settings']['inetsecure_email_customer'] = array( '#type' => 'radios', '#title' => t('Email Internet Secure Reciept'), '#default_value' => variable_get('inetsecure_email_customer', 1), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('If enabled, the customer will recieve a payment confirmation email from Internet Secure. Keep in mind the ecommerce package sends its own transaction summary as well. Enabling this option is recommended because it provides the customer with an accurate confirmation of the amount you have charged.'), ); $form['settings']['inetsecure_shipping'] = array( '#type' => 'radios', '#title' => t('Shipping Option'), '#default_value' => variable_get('inetsecure_shipping', 2), '#options' => array(t('No shipping calculations'), t('Pass shipping calculation as product')), '#description' => t("If pass is chosen, an additional product is added on called 'Shipping' with a sku of 'shp', the cost is taken from the shipping cost in transaction array at txn->misc."), ); $form['settings']['inetsecure_tax'] = array( '#type' => 'radios', '#title' => t('Tax Option'), '#default_value' => variable_get('inetsecure_tax', 2), '#options' => array(t('No tax calculations'), t('Pass tax calculation as product')), '#description' => t("If pass is chosen, an additional product is added on called 'tax' with a sku of 'tax', the cost is taken from the tax cost in transaction array at txn->misc."), ); $form['settings']['inetsecure_confusr'] = array( '#type' => 'textfield', '#title' => t('Username for Return (Export) Script'), '#default_value' => variable_get('inetsecure_confusr', ''), '#size' => 70, '#maxlength' => 180, '#description' => t("If you are using an export script, this is the username that you specify at InternetSecure.

Export scripts are set up by default, set the web page in the merchant area to /inetsecure/script."), ); $form['settings']['inetsecure_confpwd'] = array( '#type' => 'textfield', '#title' => t('Password for Return (Export) Script'), '#default_value' => variable_get('inetsecure_confpwd', ''), '#size' => 70, '#maxlength' => 180, ); $form['settings']['inetsecure_confstr'] = array( '#type' => 'textfield', '#title' => t('Confirmation String for Return (Export) Script'), '#default_value' => variable_get('inetsecure_confstr', ''), '#size' => 70, '#maxlength' => 180, '#description' => t("If you are using an export script, this is the confirmation string that you specify at InternetSecure.

Export scripts are set up by default, set the web page in the merchant area to /inetsecure/script."), ); return $form; } /** * Implementation of hook_paymentapi(). */ function inetsecure_paymentapi(&$txn, $op) { switch ($op) { case 'display name': return t('Pay with credit card'); case 'payment page': return inetsecure_goto($txn); } } /** * Implementation of hook_ec_transactionapi(). */ function inetsecure_ec_transactionapi(&$txn, $op, $a3 = NULL, $a4 = NULL) { if ($txn->payment_method != 'inetsecure') return NULL; switch ($op) { case 'load': $txn->payment = db_fetch_object(db_query("SELECT * FROM {ec_inetsecure} WHERE txnid = %d", $txn->txnid)); break; case 'insert': case 'update': inetsecure_save($txn); break; case 'delete': inetsecure_delete($txn); break; } } function inetsecure_delete($txn) { db_query('DELETE FROM {ec_inetsecure} WHERE txnid = %d', $txn->txnid); } /** * Called immediately after the user has clicked the checkout button. * * Redirect the user to the secure server to collect credit card information. */ function inetsecure_goto($txn) { global $base_url; $payment_url = str_replace('https://', 'http://', $base_url). '/'. url("inetsecure/form/". $txn->txnid); /* * Switch to https at internet secure */ header("Location: $payment_url"); exit(); } /** * Controller for collecting and processing credit card data. */ function inetsecure_page($txnid = null) { $edit = $_POST['edit']; $op = $_POST['op']; if(isset($_POST['xxxName'])){ //this is a ReturnCGI from Internet Secure $output = inetsecure_returncgi(); // We want to go to a http, not https. $base = str_replace('https://', 'http://', $base_url); header("Location: ".$base. "/". variable_get('inetsecure_success_url', 'node')."?status=".$output['status']); exit(); } else { $output = inetsecure_form($txnid); } print theme('page', $output, $title); } /** * Build the credit card transaction. */ function inetsecure_form($txnid) { global $user, $base_url; $t = store_transaction_load($txnid); //Make sure the user owns the transaction or is admin. if ($user->uid != $t->uid && $user->uid != 1) { drupal_access_denied(); } //Make sure the user is connected via SSL //if (!$_SERVER['HTTPS']) { // drupal_access_denied(); //} $output = t('
%inetsecure_help
', array('%inetsecure_help' => variable_get('inetsecure_help', inetsecure_help('inetsecure/form_submit_guidlines')))); $output .= '
'; $output .= ' '; $output .= ' '; $output .= ' '; $output .= ' '; $products=''; if ($t->items) { foreach ($t->items as $p) { $product = product_load($p); $subtotal += $p->qty * $p->price; $items[] = t('%order of %title at %price each', array('%order' => format_plural($p->qty, '1 order', '%count orders'), '%title' => $p->title, '%price' => payment_format(product_adjust_price($product)))). "\n"; $products .= $p->price.'::'.$p->qty.'::'.$product->sku.'::'.$p->title; if(variable_get('inetsecure_debug_decline',0) != 0) { $products .= '::{TESTD}'; $test = 'debug_decline'; drupal_set_message(t('TEST MODE (FORCE DECLINE)')); } else if(variable_get('inetsecure_debug',0) != 0) { $products .= '::{TEST}'; $test = 'debug'; drupal_set_message(t('TEST MODE')); } $products .= '|'; } } if ($t->misc) { foreach ( $t->misc as $misc){ if ($misc->type=="shipping") {$shipping = $misc->price;} elseif ($misc->type=="tax") {$tax = $misc->price;} } } $total = $subtotal; if (variable_get('inetsecure_shipping',0) == 1 && $shipping != "") { $products .= $shipping.'::1::shp::Shipping Costs'; if ($test == 'debug') $products .= '::{TEST}'; if ($test == 'debug_decline') $products .= '::{TESTD}'; $products .= '|'; $shiptext = t('
Shipping: '.payment_format($shipping)). "\n"; $total += $shipping; } if (variable_get('inetsecure_tax',0) == 1 && $tax != "") { $products .= $tax.'::1::tax::Tax Costs'; if ($test == 'debug') $products .= '::{TEST}'; if ($test == 'debug_decline') $products .= '::{TESTD}'; $products .= '|'; $taxtext = t('
Tax: '.payment_format($tax)). "\n"; $total += $tax; } $output .= ' '; $output .= '

'. theme('item_list', $items, t('Your items')). '

'; $output .= '

Subtotal: '. payment_format($subtotal).'
'.$shiptext.$taxtext.'

Total cost: '. payment_format($total). ' (US Dollar)

'; $output .= ''; $output .= "
"; return $output; } function inetsecure_save($txn) { if (is_numeric($txn->txnid) && is_numeric($txn->anid)) { if (db_result(db_query("SELECT COUNT(txnid) FROM {ec_inetsecure} WHERE txnid = '%s'", $txn->txnid))) { db_query("UPDATE {ec_inetsecure} SET anid = '%s', amount = '%f' WHERE txnid = %d", $txn->anid, $txn->amount, $txn->txnid); } else { db_query("INSERT INTO {ec_inetsecure} (txnid, anid, amount) VALUES (%d, '%s', '%f')", $txn->txnid, $txn->anid, $txn->amount); } } } /* ReturnCGI processing from Internet Secure gets called after successful transaction Possible values: Variable Name Description xxxName Customer's full name xxxCompany Customer company xxxAddress Customer's street address xxxCity Customer's city xxxProvince Customer's province xxxCountry Customer's country xxxPostal Customer's postal code xxxEmail Customer's email address xxxPhone Customer's phone number xxxcard_name Cardholder's name on credit card xxxCCType Customer's credit card type (Visa, MasterCard, Amex, Discover) xxxAmount Dollar amount of the transaction Amount Dollar amount of the transaction SalesOrderNumber Sales order number of transaction. Numbers are unique to each merchant and increment by one for each transaction. receiptnumber InternetSecure receipt number. Unique to each transaction. ApprovalCode Bank approval code for this transaction Verbage Verbiage sent back by the processor Currency The currency used to process the transactions Products The Products string, as passed by the merchant DateTimeAction a 15 digit code returned by the processing system in the following format yy/mm/dd/hr/min/sec Live Indicated whether the transaction was real (1) or a test (0) ReturnCGI The address on your site to which the Return CGI results were posted xxxVar1 Hidden variable specific to your site xxxVar2 Hidden variable specific to your site xxxVar3 Hidden variable specific to your site xxxVar4 Hidden variable specific to your site xxxVar5 Hidden variable specific to your site xxxVar1 is being used to pass the txnid from drupal->inetsecure->drupal */ function inetsecure_returncgi() { global $base_url; $txnid = $_POST['xxxVar1']; $status = $_POST['NiceVerbage']; if ($status == "Approved" || $status == "Test+Approved" || $status == "Test Approved") {$status = "completed";} elseif ($status == "Refunded") {$status = "refunded";} else {$status = "failed";} $billing['firstname'] = substr($_POST['xxxName'],0,strpos($_POST['xxxName']," ")); $billing['lastname'] = substr($_POST['xxxName'],strpos($_POST['xxxName']," ")); $billing['street1'] = $_POST['xxxAddress']; $billing['street2'] = " "; $billing['city'] = $_POST['xxxCity']; $billing['state'] = $_POST['xxxProvince']; $billing['country'] = strtolower($_POST['xxxCountry']); $billing['zip'] = $_POST['xxxPostal']; $billing['txnid'] = $txnid; $address = store_transaction_address_save($billing, 'billing'); $edit = store_transaction_load($txnid); $edit->anid = $_POST['receiptnumber']; // ***FIXME*** what is supposed to go in anid??? $edit->amount = $_POST['Amount']; $edit->payment_status = payment_get_status_id($status); $edit->payment_method = 'inetsecure'; $is_new = (db_result(db_query('SELECT COUNT(txnid) FROM {ec_inetsecure} WHERE txnid = %d', $txnid))) ? false : true; $txnid = store_transaction_save($edit); if ($is_new && $txnid) { // Compose and send confirmation email to the user store_send_invoice_email($txnid); } $returnarr['txnid'] = $billing['txnid']; $returnarr['status'] = $status; return $returnarr; } /** * The page for internetsecure to send back its info. */ function inetsecure_script(){ $output = inetsecure_returncgi(); print variable_get('inetsecure_confstr', ''); /*if ($_POST[username] == variable_get('inetsecure_confusr', '') && $_POST[password] == variable_get('inetsecure_confpwd', '')) { $output = inetsecure_returncgi(); print variable_get('inetsecure_confstr', ''); } else { //ask for authentication here } */ }