Created
September 2, 2012 05:01
-
-
Save zvineyard/3594939 to your computer and use it in GitHub Desktop.
PHP: Barfy Old Authorize.net Procedural PHP Gross
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$required_fields = array( | |
'page_id' => 'page_id', | |
'Amount' => 'cc_amount', | |
'Credit Card Number' => 'cc_card_num', | |
'Credit Card Expiration Date' => 'cc_exp_date', | |
'Description' => 'cc_description' | |
); | |
function verify_data_present($required_fields) { | |
$errors = array(); | |
if(empty($_POST)) { // Ensure we have some data | |
die("<strong>No Post! Nothing to send to Authorize.net</strong>"); | |
} | |
// Make sure that all of the required fields exist as keys in the post array | |
foreach($required_fields as $key => $value) { | |
if(!in_array($value, array_keys($_POST))) { | |
$errors[] = $value . " does not exist in post data and is required!"; | |
} else { | |
if(empty($_POST[$value])) { | |
$errors[] = $key . " is a required field."; | |
} | |
} | |
} | |
if(!is_numeric($_POST['cc_card_num'])) $errors[] = "Card number must be numeric!"; | |
if(!is_numeric($_POST['cc_amount'])) $errors[] = "Amount must be a decimal of form x.xx without the dollar sign!"; | |
if(!empty($errors)) { | |
echo "<div><ul>"; | |
foreach($errors as $value) { | |
echo "<li>" . $value . "</li>"; | |
} | |
echo "</ul></div>"; | |
return false; | |
} else { | |
return true; | |
} | |
if(!verify_data_present($required_fields)) { | |
die(); | |
} else { | |
include('gateway.php'); | |
echo "<div class='approved'>Your transaction has been approved.</div>"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment