Payment Getway in php

Authorize.Net payment gateway in php

Quick steps to implement payments in your site using PHP and the Authorize.Net APIs

Authorize.Net is a payment gateway service provider allowing merchants to accept credit card and electronic check payments through their Web site and over an IP (Internet Protocol) connection.

1. AIM Capture + ARB: users will be charged the first amount of payment immediately when they subscribe on your website, then the recurring billing (created in ARB) will start after the first membership period. There is one transaction + one authorization made on the date.

2. AIM Authorize + ARB: user’s credit card will be authorized for the first amount of payment when they subscribe on your website, then the recurring billing (created in ARB) will start the next date of the subscription. There is one authorization on the date + one transaction made on the other date.

3. ARB ONLY: users will be charged the first amount of payment the next day after they subscribe on your website, then the recurring billing will start after the first membership period. There is only one transaction made on the date.

The first two options are safer, as they ensure that you can charge the user’s credit card at the first day, this is especially important if you sell downloadable products. If you do not care about the user’s access, the third one would be easier.



<table width="50%" border="1" bordercolor="#CCCCFF" bgcolor="#CCCCFF">
  <form action="payment.php" method="post" name="payform" id="payform">
    <td colspan="4" align="center"> Payment Getway</td>
    <td>First Name</td>
    <td> <input name="firstname" type="text" /></td>
    <td>Last Name</td>
    <td><input name="lastname" type="text" /></td>
    <td><input name="email" type="text" /></td>
    <td><input name="address" type="text" /></td>
    <td> <input name="city" type="text" /></td>
    <td><input name="state" type="text" maxlengtd="2" style="width:30px;" /> <span style="font:8pt arial;">eg. NY</span>
          <input name="zip" type="text" style="width:75px;" /></td>
    <td>Card Type</td>
    <td><select name="cardtype" >
            <option value="visa">Visa</option>
            <option value="MasterCard">Master Card</option>
            <option value="AmericanExpress">American Express</option>
    <td>Cardholder Name</td>
    <td><input name="cardholder" type="text" /></td>
    <td>Card Number</td>
    <td> <input name="cardnumber" type="text" /></td>
    <td>Expiration <span style=" font:7pt arial; color:gray;">[ mm / yyyy ]</span></td>
        <input name="cardmontd" class="sel" type="text" style="width:40px;" />
        <input type="text" name="cardyear" class="sel" style=" width:98px;" />
    <td>CVV Number</td>
    <td> <input name="cardcvv" type="text" /></td>
       <input name="submit" type="submit" style="border:1px outset gray; widtd:100px;" value="Pay Now" />


$loginkey = '7X9ST39nq8';////////////api login
$transkey = '4yC65cJM44f8aD95';////////////api key

$fname =urlencode( $_POST['firstname']);
$lname =urlencode($_POST['lastname']);
$creditCardType =urlencode( $_POST['cardtype']);
$creditCardNumber = urlencode($_POST['cardnumber']);
$expDateMonth =urlencode( $_POST['cardmonth']);
// Month must be padded with leading zero
$padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
$expDateYear =urlencode( $_POST['cardyear']);
$cvv2Number = urlencode($_POST['cardcvv']);
$address1 = urlencode($_POST['address']);
$city = urlencode($_POST['city']);
$state =urlencode( $_POST['state']);
$zip = urlencode($_POST['zip']);
//give the actual amount below
$amount = "1";
$date = $expDateMonth.$expDateYear;

$post_values = array(
"x_login"            => "$loginkey",
"x_tran_key"        => "$transkey",
"x_version"            => "3.1",
"x_delim_data"        => "TRUE",
"x_delim_char"        => "|",
"x_relay_response"    => "FALSE",
//"x_market_type"        => "2",
"x_device_type"        => "1",
"x_type"            => "AUTH_CAPTURE",
"x_method"            => "CC",
"x_card_num"        => $creditCardNumber,
//"x_exp_date"        => "0115",
"x_exp_date"        => $date,
"x_amount"            => $amount,
//"x_description"        => "Sample Transaction",
"x_first_name"        => $fname,
"x_last_name"        => $lname,
"x_address"            => $address1,
"x_state"            => $state,
"x_response_format"    => "1",
"x_zip"                => $zip
// Additional fields can be added here as outlined in the AIM integration
// guide at:

echo '<pre>'; echo 'Request values'; print_r($post_values);
//comment the above line. i have given this just for testing purpose.

$post_string = "";
foreach( $post_values as $key => $value )$post_string .= "$key=" . urlencode( $value ) . "&";
$post_string = rtrim($post_string,"& ");

//for test mode use the followin url
$post_url = "";
//for live use this url
//$post_url = "";

$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
// additional options may be required depending upon your server configuration
// you can find documentation on curl options at
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);

echo '<br><br> Response Array'; print_r($response_array);
//remove this line. i have used this just print the response array

echo '<b>Payment Unsuccessful</b>. <br>';
echo '<b>Error </b>: '.$response_array[3];
echo '<br><br>Click hare to go back to the previous page';
$ptid = $response_array[6];
$ptidmd5 = $response_array[7];
echo "Payment Successfull";

Share Button

About admin

Leave a Reply

Your email address will not be published. Required fields are marked *


Author: pramod kumar kumawat Mob: 9269727062
Free WordPress Themes - Download High-quality Templates