I am trying to use Authorize.Net in a kohana 3.0 project. I have set up the module in the bootstrap.php file.
I want to best understand the process before I focus on the code. In their sample code, it is written.
<?php
require_once 'anet_php_sdk/AuthorizeNet.php'; // Include the SDK you downloaded in Step 2
$api_login_id = 'I_put_my_login_id_here';
$transaction_key = 'and_my_transaction_key_here;
$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>
So, I suppose a user accesses my website and tries to buy a product. I handle the process into the controller. I will use the php_curl.
public function action_authorize(){
$url = 'https://test.authorize.net/gateway/transact.dll';
$post_string = '';
$request = curl_init($url);
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);
$response_array = explode($post_values["x_delim_char"],$post_response);
}
Here my problem is how can I know the server response to my query result in *$response_array*. How to identify error codes ?
Another thing, I enable the Authorize module. How can I access the *’api_login’* and the
*’transaction_key’* from my controller ?
When I do this in the controller, I get an error
*
$authorize = new Authorize;
$authorize->api_login;
- gives an error.
In fact I want to be able to implement Authorize.NET module in Kohana3.0
Store your Authorize.Net SDK classes in application/vendor/anet_php_sdk/
Demo Controller Method:
Since you asked, accessing the POST variables from the controller:
View file (views/payment/page.php):