Authorize.Net is my favorite payment mode for using in web development. It is simple, easy and secure payment connection. I use authorize.Net in my codeigniter based projects and here is the code and downloads.
This is helper for payment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
function do_payment ($post_values) { $post_url = "https://test.authorize.net/gateway/transact.dll"; // This section takes the input fields and converts them to the proper format $post_string = ""; foreach( $post_values as $key => $value ) { $post_string .= "$key=" . urlencode( $value ) . "&"; } $post_string = rtrim( $post_string, "& " ); // This sample code uses the CURL library for php to establish a connection, // submit the post, and record the response. // If you receive an error, you may want to ensure that you have the curl // library enabled in your php configuration $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 http://www.php.net/curl_setopt 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. if($response_array) { return $response_array; } else { return ''; } } |
And here is your controller function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
function do_user_payment() { $this->load->library('auth_payment'); $card_expiration = $_POST['crMonth'].$_POST['crYear']; $x_login = "login_key"; $x_tran_key = "trans_key"; $card_number = $_POST['ccn']; $invoice_num = ''; $x_card_code = $_POST['CSV']; $post_values['x_invoice_num'] = $invoice_num; $post_values['x_login'] = $x_login; $post_values['x_tran_key'] = $x_tran_key; $post_values['x_card_code'] = $x_card_code; $post_values['x_version'] = "3.1"; $post_values['x_delim_data'] = "TRUE"; $post_values['x_delim_char'] = "|"; $post_values['x_relay_response'] = "FALSE"; $post_values['x_type'] = "AUTH_CAPTURE"; //Optional $post_values['x_method'] = "CC"; $post_values['x_card_num'] = $card_number; $post_values['x_exp_date'] = $card_expiration; $post_values['x_amount'] = 'Your Charges'; $post_values['x_first_name'] = $user_first_name; //Optional (From Client) $post_values['x_last_name'] = $user_last_name; //Optional (From Client) $post_values['x_address'] = $user_address1; //Optional (From Client) $post_values['x_state'] = $user_state; //Optional (From Client) $post_values['x_zip'] = $user_zip; //Optional (From Client) //Calling Payment function $paymentResponse = $this->auth_payment->do_payment($post_values); if($paymentResponse[0]==1 && $paymentResponse[1]==1 && $paymentResponse[2]==1) { // payment is successful. Do your action here } else { // payment failed. return $paymentResponse[3]; // return error } } |
Idea is good but just publishing some piece of code will not help anyone. There is no explanation of how to implement it and most of the files are also missing. Where is the description for that?
Hello
Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => (TESTMODE) This transaction has been approved.
[4] => 000000
[5] => P
[6] => 0
……….
Currently i am getting this responses but i want
Array
(
[x_response_code] => 3
[x_response_reason_code] => 5
[x_response_reason_text] => (TESTMODE) A valid amount is required.
[x_avs_code] => P
[x_auth_code] => 000000
[x_trans_id] => 0
[x_method] => CC
This type of responses can you help me how i can get this?
I have implemented this code and its working fine but I have requirment to save the token after every transaction. Can any body help me out.
kindly explain how to use these above 2 code plz
Can you please provide library ?
$this->load->library(‘auth_payment’);
Can you please provide library ?