Gravity Forms Credit Card Field Offline Payment Processing

Gravity Forms is a premium form plugin for WordPress. It is the most robust and up to date form plugin for WP. I have been using this plugin since 3 years and a few days ago i need a “Credit Card Field”. And also our client asked for the offline payment processing with this field. But it is disabled by default in form coding. We may build our own Credit Card Field with various input types but also we then had to very hard working on style files and browser compatibility issues. So we have worked on how to save Credit Card Field data to db and success, we made it:) Below you will learn how to achieve to build this type of form.

1 – First we should enable the hidden “Credit Card Field” on admin panel. You should search the following line inside the wp-content/plugins/gravityforms/form_detail.php file.

 

if(apply_filters(“gform_enable_credit_card_field”, false))

 

when you switch “false” value to “true” you will see the hidden Credit Card Field below the Pricing Field section.

 

 

2 – In this step you should search the following code block inside wp-content/plugins/gravityforms/forms_model.php file;

case "creditcard" :
                //saving last 4 digits of credit card
                list($input_token, $field_id_token, $input_id) = rgexplode("_", $input_name, 3);
                if($input_id == "1"){
                    $value = str_replace(" ", "", $value);
                    $card_number_length = strlen($value);
                    $value = substr($value, -4, 4);
                    $value = str_pad($value, $card_number_length, "X", STR_PAD_LEFT);
                }
                else if($input_id == "4")
                {
                    $card_number = rgpost("input_{$field_id_token}_1");
                    $card_type = GFCommon::get_card_type($card_number);
                    $value = $card_type ? $card_type["name"] : "";
                }
                else{
                    $value = "";
                }

and replace the above code with the following;

 case "creditcard" :
                //saving last 4 digits of credit card
                list($input_token, $field_id_token, $input_id) = rgexplode("_", $input_name, 3);

				//$value = str_replace(" ", "", $value);
				//$card_number_length = strlen($value);

				if($input_id == "1")
				{
					$card_number = rgpost("input_{$field_id_token}_1");
					$card_type  = GFCommon::get_card_type($card_number);

					$carddata   = "<b>Credit Card Number : </b>";
					$carddata  .= $card_number;
					$carddata  .= "<br/>";

					$carddata  .= "<b>Expiration Date : </b>";
					$expressionTarihi = rgpost("input_{$field_id_token}_2");
					if($expressionTarihi[0]<10)
					$carddata  .= "0";
					$carddata  .= $expressionTarihi[0];
					$carddata  .= '-'.$expressionTarihi[1];
					$carddata  .= "<br/>";

					$carddata  .= "<b>Security Number : </b>";
					$carddata  .= rgpost("input_{$field_id_token}_3");
					$carddata  .= "<br/>";

					$carddata  .= "<b>Card Type : </b>";
					$carddata  .= $card_type["name"];
					$carddata  .= "<br/>";

					$carddata  .= "<b>Card Holder Name : </b>";
					$carddata  .= rgpost("input_{$field_id_token}_5");

					$card_number = $carddata;

					$value = $card_number; 
				}
				else if($input_id == "4")
                {

				}
				else{
                    $value = "";
                }

 

After saving the file Credit Card Fields would save to the database and also entries tab. That’s it:)

 

Gravity Forms Credit Card Field Offline Payment Processing” hakkında bir yorum

  1. Hey there! I’m looking to do the same thing but the code has changed substantially in the new version of gravity. Any chance you’ve updated this? Thanks a lot!

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir