Skip to content

Instantly share code, notes, and snippets.

@DeveloperWil
Created August 27, 2014 05:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save DeveloperWil/2a380bf7e428cd962084 to your computer and use it in GitHub Desktop.
Save DeveloperWil/2a380bf7e428cd962084 to your computer and use it in GitHub Desktop.
Enables the credit card fields for Gravity Forms and provides a function to get the credit card details which are not available through the filter $form or $entry
//Turn on our credit card field for admin and front end
add_action("gform_enable_credit_card_field", "enable_creditcard");
function enable_creditcard($is_enabled){
return true;
}
//Email encoded card details when the form is submitted.
add_action('gform_after_submission', 'email_encoded_cc', 10, 2);
function email_encoded_cc($entry, $form) {
function get_creditcard_field($form){
$fields = GFCommon::get_fields_by_type($form, array("creditcard"));
return empty($fields) ? false : $fields[0];
}
$card_field = get_creditcard_field($form);
$card_number = rgpost("input_{$card_field["id"]}_1");
$expiration_date = rgpost("input_{$card_field["id"]}_2");
$expire_month = $expiration_date[0];
$expire_year = $expiration_date[1];
$security_code = rgpost("input_{$card_field["id"]}_3");
$card_name = rgpost("input_{$card_field["id"]}_5");
$cc_detail_string = "CCName $card_name CCNum $card_number CCexp $expire_month-$expire_year CCV $security_code " ;
//remember base 64 is not encryption - just encoding!
$encoded_cc_detail_string = base64_encode($cc_detail_string);
//send encoded cc details via email
$to = "whoever@wherever.com"; /*your email here*/
$subject = "For your eyes only";
$body = $cc_detail_string; /*or encoded string*/
$message = "Here are some cc details $body";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
@epagecity
Copy link

Thank you so much for this code! I spent hours trying to figure this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment