Home › Forums › Payment Gateway › Authorize.Net integration in PHP
Tagged: Authorize.Net integration, PHP, Sql
- This topic has 0 replies, 1 voice, and was last updated 8 years, 6 months ago by Cleonix Technologies.
-
AuthorPosts
-
September 30, 2015 at 3:35 pm #703Cleonix TechnologiesKeymaster
Authorize.Net Advanced Integration Method (AIM):
Start PHP code
$post_url = “https://test.authorize.net/gateway/transact.dll”;
$post_values = array(
// the API Login ID and Transaction Key must be replaced with valid values
“x_login” => “API_LOGIN_ID”,
“x_tran_key” => “TRANSACTION_KEY”,
“x_version” => “3.1”,
“x_delim_data” => “TRUE”,
“x_delim_char” => “|”,
“x_relay_response” => “FALSE”,
“x_type” => “AUTH_CAPTURE”,
“x_method” => “CC”,
“x_card_num” => “4111111111111111”,
“x_exp_date” => “0115”,
“x_amount” => “19.99”,
“x_description” => “Sample Transaction”,
“x_first_name” => “John”,
“x_last_name” => “Doe”,
“x_address” => “1234 Street”,
“x_state” => “WA”,
“x_zip” => “98004”
);
// This section takes the input fields and converts them to the proper format
// for an http post. For example: “x_login=username&x_tran_key=a1B2c3D4”
$post_string = “”;
foreach( $post_values as $key => $value )
{ $post_string .= “$key=” . urlencode( $value ) . “&”; }
$post_string = rtrim( $post_string, “& ” );
$request = curl_init($post_url); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
$post_response = curl_exec($request); // execute curl post and store results in $post_response
curl_close ($request); // close curl object
// This line takes the response and breaks it into an array using the specified delimiting character
$response_array = explode($post_values[“x_delim_char”],$post_response);
The results are output to the screen in the form of an html numbered list.
echo “
- n”;
- ” . $value . ”
foreach ($response_array as $value)
{
echo “
n”;
}
echo “
n”;
End PHP here
-
AuthorPosts
- You must be logged in to reply to this topic.