Friday, May 9, 2014

PHP - Authorize.net use in php

create a new test account in authorize.net. Automatically Generate API Login ID and Transaction key of create new account.

In this API Login ID and Transaction key used in files than directly access athorize.net account.
The Authorize.Net PHP SDK gives you access to the full suite of APIs.
Download SDK of authorize.net.

You’ll need to include the file “anet_php_sdk/AuthorizeNet.php” in your project so make sure you save the SDK into a folder that your web server can access such as your var/www folder or your htdocs folder.
Mainly three method used in authorize.net.

1)Direct Post Method
<?php
          require_once ‘anet_php_sdk/AuthorizeNet.php’; // The SDK
          $url = “http://YOUR_DOMAIN.com/direct_post.php”;
          $api_login_id = ‘YOUR_API_LOGIN_ID’;
          $transaction_key = ‘YOUR_TRANSACTION_KEY’;
         $md5_setting = ‘YOUR_API_LOGIN_ID’; // Your MD5 Setting
         $amount = “5.99″;
        AuthorizeNetDPM::directPostDemo($url, $api_login_id, $transaction_key, $amount, $md5_setting);
?>

2)Server Integration Method
<?php
         require_once ‘anet_php_sdk/AuthorizeNet.php’; // Include the SDK you downloaded in Step 2
         $api_login_id = ‘YOUR_API_LOGIN_ID’;
         $transaction_key = ‘YOUR_TRANSACTION_KEY’;
         $amount = “5.99″;
         $fp_timestamp = time();
         $fp_sequence = “123″ . time(); // Enter an invoice or other unique number.
         $fingerprint = AuthorizeNetSIM_Form::getFingerprint($api_login_id,
         $transaction_key, $amount, $fp_sequence, $fp_timestamp)
?>

<form method=’post’ action=”https://test.authorize.net/gateway/transact.dll”>
<input type=’hidden’ name=”x_login” value=”<?php echo $api_login_id?>” />
<input type=’hidden’ name=”x_fp_hash” value=”<?php echo $fingerprint?>” />
<input type=’hidden’ name=”x_amount” value=”<?php echo $amount?>” />
<input type=’hidden’ name=”x_fp_timestamp” value=”<?php echo $fp_timestamp?>” />
<input type=’hidden’ name=”x_fp_sequence” value=”<?php echo $fp_sequence?>” />
<input type=’hidden’ name=”x_version” value=”3.1″>
<input type=’hidden’ name=”x_show_form” value=”payment_form”>
<input type=’hidden’ name=”x_test_request” value=”false” />
<input type=’hidden’ name=”x_method” value=”cc”>
<input type=’submit’ value=”Click here for the secure payment form”>
</form>

3)Advanced Integration Method
 <?php
           require_once ‘anet_php_sdk/AuthorizeNet.php’; // Make sure this path is correct.
           $transaction = new AuthorizeNetAIM(‘YOUR_API_LOGIN_ID’, ‘YOUR_TRANSACTION_KEY’);
           $transaction->amount = ’9.99′;
           $transaction->card_num = ’4007000000027′;
           $transaction->exp_date = ’10/16′;
          $response = $transaction->authorizeAndCapture();

          if ($response->approved){
      echo “<h1>Success! The test credit card has been charged!</h1>”;
      echo “Transaction ID: ” . $response->transaction_id;
         }
        else{
      echo $response->error_message;
       }
?>

No comments:

Post a Comment