Popup authroize.net link

Discussion in 'PHP' started by aGig, Sep 20, 2006.

  1. #1
    Greetings,

    I am using the authorize.net API to pass my users to their site to pay. My script calls a file to get the authorize.net code. I want to have it popup a new little window for payment and I am looking for some help. Here is the code in the functions for authorize.net.
    
    [LEFT]## BEGIN of Authorize.Net related functions
    function hmac ($key, $data) {
       // RFC 2104 HMAC implementation for php.
       // Creates an md5 HMAC.
       // Eliminates the need to install mhash to compute a HMAC
       // Hacked by Lance Rushing
    
       $b = 64; // byte length for md5
       if (strlen($key) > $b) {
           $key = pack("H*",md5($key));
       }
       $key  = str_pad($key, $b, chr(0x00));
       $ipad = str_pad('', $b, chr(0x36));
       $opad = str_pad('', $b, chr(0x5c));
       $k_ipad = $key ^ $ipad ;
       $k_opad = $key ^ $opad;
    
       return md5($k_opad  . pack("H*",md5($k_ipad . $data)));
    }
    
    // Inserts the hidden variables in the HTML FORM required for SIM
    // Invokes hmac function to calculate fingerprint.
    function InsertFP ($loginid, $x_tran_key, $amount, $sequence, $currency = "") {
    	$tstamp = time();
    	$fingerprint = hmac ($x_tran_key, $loginid . "^" . $sequence . "^" . $tstamp . "^" . $amount . "^");
    	echo ('<input type="hidden" name="x_fp_sequence" value="' . $sequence . '">');
    	echo ('<input type="hidden" name="x_fp_timestamp" value="' . $tstamp . '">');
    	echo ('<input type="hidden" name="x_fp_hash" value="' . $fingerprint . '">');
    	return (0);
    }
    
    function authorizeNetForm($transactionId, $paymentAmount, $mTable,$directPayment=FALSE,$postUrl='https://secure.authorize.net/gateway/transact.dll') {
    	global $lang, $setts;
    
    	$TESTMODE = 0;
    	## UnComment this line out to enter Testing Mode!
    	## $TESTMODE = 1;
    
    	### this will be the new payment form design
    	echo "<table width=\"100%\" border=\"0\" cellspacing=\"4\" cellpadding=\"4\" class=\"paymenttable\">\n";
      	echo "	<tr>\n";
    	### the PG image will go below
    	echo " 		<td width=\"160\" class=\"paytable1\"><img src=\"themes/".$setts[default_theme]."/img/system/authorize_logo.gif\"></td>\n";
    	if ($TESTMODE) { 
    		echo "<form action=\"https://certification.authorize.net/gateway/transact.dll\" method=\"POST\">";
    	} else { 
    		echo "<form action=\"".$postUrl."\" method=\"POST\" id=\"payform\">";
    	}
    	### the description will go below
       echo "		<td class=\"paytable2\" width=\"100%\">".$lang[authorize_net_description_new]."<br>".displayAmount($paymentAmount,'USD')."\n";;
    	if ($directPayment) {
    		echo "<br><strong>".$lang[add_insurance].":</strong> USD <input type=\"text\" name=\"insurance\" value=\"\" size=\"7\">\n";
    	} 
    	echo "  		</td>\n";
    	### the payment gateway from will go below
    	echo "		<td class=\"paytable3\">							\n";
    	
       if($mTable == 100){
          $userId = getSqlField("SELECT sellerid FROM probid_winners WHERE id='".$transactionId."'",'sellerid');
    		$userDetails = getSqlRow ("SELECT authnetid, authnettranskey FROM probid_users WHERE id='".$userId."'");
          $authid = $userDetails['authnetid'];
          $authkey = $userDetails['authnettranskey'];
       }else{
          $authid = $setts['authnetid'];
          $authkey = $setts['authnettranskey'];
       }
    
    	$amount = $paymentAmount;
    	if (substr($amount, 0,1) == "$") {
    		$amount = substr($amount,1);
    	}
    	srand(time());
    	$sequence = rand(1, 1000);
    	$ret = InsertFP($authid, $authkey, $amount, $sequence);
    	echo "<input type=\"hidden\" name=\"x_description\" value=\"".$lang[serv_act_fee]."\">\n";
    	echo "<input type=\"hidden\" name=\"x_login\" value=\"" . $authid . "\">\n";
    	echo "<input type=\"hidden\" name=\"x_amount\" value=\"" . $amount . "\">\n";
    	echo "<input type=\"hidden\" name=\"x_show_form\" value=\"PAYMENT_FORM\">\n";
    	echo "<input type=\"hidden\" name=\"x_relay_response\" value=\"TRUE\">\n";
    	echo "<input type=\"hidden\" name=\"ProBidID\" value=\"".$transactionId."TBL".$mTable."\">\n";
    	if ($TESTMODE) { 
    		echo "<input type=\"hidden\" name=\"x_test_request\" value=\"TRUE\">";
    	}
    	echo "		<input name=\"submit\" type=\"image\" src=\"themes/".$setts[default_theme]."/img/system/but_pay.gif\" border=\"0\"> \n";
    	echo "		</td></form>\n";
      	echo "	</tr>\n";
    	echo "</table>";
    }
    
    ## END of Authorize.Net related functions 
    Code (markup):
    I'm not sure how or where to place the code to have this link it outputs popup.

    Thank you for your time in advance.

    Mark[/LEFT]
     
    aGig, Sep 20, 2006 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Where are you having the problem?

    I'm just unclear on where you are hung up. Are you trying to post to a popup window? or, are you opening a popup, and then using the popup window to have your user process their payment?
     
    jestep, Sep 21, 2006 IP
  3. aGig

    aGig Well-Known Member

    Messages:
    428
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    118
    #3
    Yes I want a popup to open and have the user enter payment details in there. Right the authroize.net payment page is very plain so making it a popup would look better.

    Thank you.

    Mark
     
    aGig, Sep 21, 2006 IP