Authorize.Net Advanced Implementation Method (AIM) PHP Example Code This is just a test to: 1) post an HTTP request to the secure Authorize.Net server 2) process feedback from the secure Authorize.Net transaction DLL =$_POST['card_num'];?> |
|||||||||||||||||||||||||||||||||||||||||||||||||||
"your_login_id_from_authorizenet_goes_here",
"x_version" => "3.1",
"x_delim_char" => "|",
"x_delim_data" => "TRUE",
"x_url" => "FALSE",
"x_type" => "AUTH_CAPTURE",
"x_method" => "CC",
"x_tran_key" => "your_transaction_key_from_authorizenet_goes_here",
"x_relay_response" => "FALSE",
"x_card_num" => "4222222222222",
"x_exp_date" => "1209",
"x_description" => "Recycled Toner Cartridges",
"x_amount" => "7.00",
"x_first_name" => "Charles D.",
"x_last_name" => "Gaulle",
"x_address" => "342 N. Main Street #150",
"x_city" => "Ft. Worth",
"x_state" => "TX",
"x_zip" => "12345",
"x_merchant_email" => "your_email_goes_here",
"CustomerBirthMonth" => "Customer Birth Month: 12",
"CustomerBirthDay" => "Customer Birth Day: 1",
"CustomerBirthYear" => "Customer Birth Year: 1959",
"SpecialCode" => "Promotion: Spring Sale",
"x_encap_char" => "",
"x_card_code" => "888",
"x_test_request" => "TRUE",
);
$fields = "";
foreach( $authnet_values as $key => $value ) $fields .= "$key=" . urlencode( $value ) . "&";
echo " "; /////////////////////////////////////////////////////////// echo "01: Post the transaction (see the code for specific information): "; $ch = curl_init("https://test.authorize.net/gateway/transact.dll"); ### Uncomment the line ABOVE for test accounts or BELOW for live merchant accounts ### $ch = curl_init("https://secure.authorize.net/gateway/transact.dll"); curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1) curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " )); // use HTTP POST to send form data ### curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ### $resp = curl_exec($ch); //execute post and get results curl_close ($ch); echo " "; /////////////////////////////////////////////////////////// echo "02: Get post results: "; echo $resp; echo " "; echo " "; /////////////////////////////////////////////////////////// echo "03: Parse post results (simple approach) "; $text = $resp; echo "
"; /////////////////////////////////////////////////////////// echo "04: Parse the results string into individual, meaningful segments: "; echo "
"; echo " "; /////////////////////////////////////////////////////////// echo "04: Done. "; ?> |