Function Reference: geodir_payment_form_authorizenet

Summary

This function has not been documented yet.

Filters

‘geodir_authorizenet_item_name’ [Line: 81]

Source Code

function geodir_payment_form_authorizenet( $invoice_id ) {
	global $current_user, $gd_session;
	
	$invoice_info = geodir_get_invoice( $invoice_id );
	$paymentmethod = get_payment_options( $invoice_info->paymentmethod );
	
	$currency_code = geodir_get_currency_type();
	
	$user_id = $invoice_info->user_id;
	$post_id = $invoice_info->post_id;
	$item_name = $invoice_info->post_title;
	$item_name = apply_filters( 'geodir_authorizenet_item_name', $item_name, $invoice_id );
	
	$payable_amount = $invoice_info->paied_amount;

	$sandbox = $paymentmethod['payment_mode'] == 'sandbox' ? true : false;
	$loginid = $paymentmethod['loginid'];
	$transkey = $paymentmethod['transkey'];
	
	$display_name = geodir_get_client_name($user_id);
	$user_email = $current_user->data->user_email;
	$user_phone = isset($current_user->data->user_phone) ? $current_user->data->user_phone : '';
	
	$cc_number = isset($_REQUEST['cc_number']) ? sanitize_text_field($_REQUEST['cc_number']) : '';
	$cc_month = isset($_REQUEST['cc_month']) ? sanitize_text_field($_REQUEST['cc_month']) : '';
	$cc_year = isset($_REQUEST['cc_year']) ? sanitize_text_field($_REQUEST['cc_year']) : '';
	$cv2 = isset($_REQUEST['cv2']) ? sanitize_text_field($_REQUEST['cv2']) : '';
	
	$x_card_num = $cc_number;
	$x_exp_date = $cc_month . substr( $cc_year, 2, strlen( $cc_year ) );
	$x_card_code = $cv2;
		
	require_once('authorizenet/authorizenet.class.php');
	
	$a = new authorizenet_class;
	if ($sandbox) {
		$a->is_sandbox(); // put api in sandbox mode
	}
	
	/*You login using your login, login and tran_key, or login and password.  It
	varies depending on how your account is setup.
	I believe the currently recommended method is to use a tran_key and not
	your account password.  See the AIM documentation for additional information.*/	
	$a->add_field('x_login', $loginid);
	$a->add_field('x_tran_key', $transkey);
	//$a->add_field('x_password', 'CHANGE THIS TO YOUR PASSWORD');
	
	$a->add_field('x_version', '3.1');
	$a->add_field('x_type', 'AUTH_CAPTURE');
	//$a->add_field('x_test_request', 'TRUE');     Just a test transaction
	$a->add_field('x_relay_response', 'FALSE');
	
	/*
	You *MUST* specify '|' as the delim char due to the way I wrote the class.
	I will change this in future versions should I have time.  But for now, just
	 make sure you include the following 3 lines of code when using this class.
	*/	
	$a->add_field('x_delim_data', 'TRUE');
	$a->add_field('x_delim_char', '|');     
	$a->add_field('x_encap_char', '');
	
	/*
	Setup fields for customer information.  This would typically come from an
	array of POST values from a secure HTTPS form.
	*/	
	$a->add_field('x_first_name', $display_name);
	$a->add_field('x_last_name', '');
	/*
	$a->add_field('x_address', $address);
	$a->add_field('x_city', $userInfo['user_city']);
	$a->add_field('x_state', $userInfo['user_state']);
	$a->add_field('x_zip', $userInfo['user_postalcode']);
	$a->add_field('x_country', 'US');
	$a->add_field('x_country',  $userInfo['user_country']);
	*/
	$a->add_field('x_email', $user_email);
	$a->add_field('x_phone', $user_phone);
	
	/* Using credit card number '4007000000027' performs a successful test.  This
	 allows you to test the behavior of your script should the transaction be
	 successful.  If you want to test various failures, use '4222222222222' as
	 the credit card number and set the x_amount field to the value of the
	 Response Reason Code you want to test. 
	
	 For example, if you are checking for an invalid expiration date on the
	 card, you would have a condition such as:
	 if ($a->response['Response Reason Code'] == 7) ... (do something)
	
	 Now, in order to cause the gateway to induce that error, you would have to
	 set x_card_num = '4222222222222' and x_amount = '7.00'
	
	  Setup fields for payment information*/
	//$a->add_field('x_method', $_REQUEST['cc_type']);
	$a->add_field('x_method', 'CC');
	$a->add_field('x_card_num', $x_card_num);
	/*
	$a->add_field('x_card_num', '4007000000027');   // test successful visa
	$a->add_field('x_card_num', '370000000000002');   // test successful american express
	$a->add_field('x_card_num', '6011000000000012');  // test successful discover
	$a->add_field('x_card_num', '5424000000000015');  // test successful mastercard
	$a->add_field('x_card_num', '4222222222222');    // test failure card number
	*/
	$a->add_field('x_amount', $payable_amount);
	$a->add_field('x_exp_date', $x_exp_date);    /* march of 2008*/
	$a->add_field('x_card_code', $x_card_code);    // Card CAVV Security code
	
	/* Process the payment and output the results */
	$success = false;
	$message = '';
	$response_code = $a->process();

	switch ($response_code) {
		case 1:  /* Success */
			$success = true;

			$transaction_details = '';
			$transaction_details .= "--------------------------------------------------
"; $transaction_details .= sprintf(__("Payment Details for Invoice ID #%s", 'geodir_payments'), geodir_payment_invoice_id_formatted($invoice_id) ) ."
"; $transaction_details .= "--------------------------------------------------
"; $transaction_details .= sprintf(__("Item Name: %s", 'geodir_payments'), $item_name)."
"; $transaction_details .= "--------------------------------------------------
"; $transaction_details .= sprintf(__("Trans ID: %s", 'geodir_payments'), $a->response['Transaction ID'])."
"; $transaction_details .= sprintf(__("Status: %s", 'geodir_payments'), $a->response['Response Code'])."
"; $transaction_details .= sprintf(__("Amount: %s", 'geodir_payments'),$a->response['Amount'])."
"; $transaction_details .= sprintf(__("Type: %s", 'geodir_payments'),$a->response['Transaction Type'])."
"; $transaction_details .= sprintf(__("Date: %s", 'geodir_payments'), date_i18n("F j, Y, g:i a", current_time( 'timestamp' )))."
"; $transaction_details .= sprintf(__("Method: %s", 'geodir_payments'), 'Authorize.net')."
"; $transaction_details .= "--------------------------------------------------
"; /*############ SET THE INVOICE STATUS START ############*/ // update invoice status and transaction details geodir_update_invoice_status( $invoice_id, 'confirmed' ); geodir_update_invoice_transaction_details( $invoice_id, $transaction_details ); /*############ SET THE INVOICE STATUS END ############*/ // send notification to admin geodir_payment_adminEmail( $post_id, $user_id, 'payment_success', $transaction_details ); // send notification to client geodir_payment_clientEmail( $post_id, $user_id, 'payment_success', $transaction_details ); $redirect_url =geodir_info_url( array( 'pay_action' => 'success', 'inv' => $invoice_id, 'pid' => $post_id ) ); wp_redirect( $redirect_url ); exit; break; case 2: /* Declined */ $message = $a->get_response_reason_text(); // update invoice status geodir_update_invoice_status( $invoice_id, 'cancelled' ); break; case 3: /* Error */ $message = $a->get_response_reason_text(); // update invoice status geodir_update_invoice_status( $invoice_id, 'failed' ); break; } if ( !$success ) { $gd_session->set('display_message', $message); $redirect_url = geodir_info_url( array( 'pay_action' => 'cancel', 'inv' => $invoice_id, 'pmethod' => 'authorizenet', 'err_msg' => urlencode( $message ) )); wp_redirect( $redirect_url ); } exit; }