From e3fb7d925d98978a4346611c0d66cac08d95ed10 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 1 Nov 2016 12:10:48 -0400 Subject: [PATCH] Update the payment form to include reCaptcha Adding reCaptcha from google to the payment form. --- glm-payments.php | 18 +-- includes/payment-display.php | 298 +++++++++++++++++++---------------- 2 files changed, 170 insertions(+), 146 deletions(-) diff --git a/glm-payments.php b/glm-payments.php index 9ba9fc0..e8da2c6 100755 --- a/glm-payments.php +++ b/glm-payments.php @@ -1,10 +1,10 @@ - 'POST', + 'timeout' => 45, + 'redirection' => 5, + 'httpversion' => '1.0', + 'blocking' => true, + 'headers' => array(), + 'body' => array( + 'secret' => '6LfUdwoUAAAAAPIZJ1_ipx0hK2Bl8XMMsmamlRDq', + 'response' => $_REQUEST['g-recaptcha-response'], + 'remoteip' => $_SERVER['REMOTE_ADDR'] + ), + 'cookies' => array() + ) ); + $response_code = wp_remote_retrieve_response_code( $response ); + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); + if ( $api_response['success'] != true ) { + $_SESSION['payment_msg'] = 'Captcha did not verify!'; + header("Location:".site_url().$_SERVER['REQUEST_URI']); + exit; + } $first_name = $_REQUEST['first_name']; $last_name = $_REQUEST['last_name']; $organization = $_REQUEST['organization']; @@ -21,7 +43,7 @@ $state = $_REQUEST['state']; $zip = $_REQUEST['zip']; $phone = $_REQUEST['phone']; - $email = $_REQUEST['email']; + $email = $_REQUEST['email']; $donation_type = $_REQUEST['donation_type']; $r_frequency = $_REQUEST['r_frequency']; $r_times = $_REQUEST['r_times']; @@ -34,7 +56,7 @@ $x_card_code = $_REQUEST['x_card_code']; $comment = $_REQUEST['comment']; $payment_method = $_REQUEST['payment_method']; - + // Adjust this to point to the Authorize.Net PHP SDK include dirname(__FILE__) .'/../anet_php_sdk/AuthorizeNet.php'; @@ -43,13 +65,13 @@ define("AUTHORIZENET_API_LOGIN_ID",$mysetting[0]->api_login); // Add your API LOGIN ID define("AUTHORIZENET_TRANSACTION_KEY",$mysetting[0]->key); // Add your API transaction key if($mysetting[0]->mod==0){ - define("AUTHORIZENET_SANDBOX",true); // Set to false to test against production - define("TEST_REQUEST", true); // You may want to set to true if testing against production + define("AUTHORIZENET_SANDBOX",true); // Set to false to test against production + define("TEST_REQUEST", true); // You may want to set to true if testing against production } else { define("AUTHORIZENET_SANDBOX",false); // Set to false to test against production - define("TEST_REQUEST", false); + define("TEST_REQUEST", false); } // You only need to adjust the two variables below if testing DPM define("AUTHORIZENET_MD5_SETTING",""); // Add your MD5 Setting. @@ -57,24 +79,24 @@ $REQUEST = $_REQUEST; if(authorizepayment($METHOD_TO_USE,$REQUEST,$address1,$city,$state,$country,$zipcode,$emailaddress,$plan)) { - $sql = "INSERT INTO `".$wpdb->prefix."payment` (`first_name`, `last_name`, `organization`, `address`, `city`, `country`, `state`, `zip`, `phone`, `email`, `donation_type`, `amount`, `invoice_num`,`comment`, `status`,`date`) + $sql = "INSERT INTO `".$wpdb->prefix."payment` (`first_name`, `last_name`, `organization`, `address`, `city`, `country`, `state`, `zip`, `phone`, `email`, `donation_type`, `amount`, `invoice_num`,`comment`, `status`,`date`) VALUES ('".$first_name."', '".$last_name."','".$organization."','".$address."','".$city."','".$country."','".$state."','".$zip."','".$phone."','".$email."','".$donation_type."','".$amount."','".$invoice_num."','".$comment."', '1',now());"; $wpdb->query($sql); - + $post = get_post($post->ID); $slug = $post->post_name; - + // verification form submission to billing@gaslightmedia.com ////// $headers = "From: Gaslight Media \r\n" . "Reply-To: noreply@gaslightmedia.com\r\n"; - - $clientInfo = "A payment has been made on the Gaslight Media website. Please review the billing information below\r\n" . + + $clientInfo = "A payment has been made on the Gaslight Media website. Please review the billing information below\r\n" . "First Name: " . $first_name . "\r\n" . "Last Name: " . $last_name . "\r\n" . "Invoice #: " . $invoice_num . "\r\n" . "Payment Amount: $". $amount . "\r\n" . "Organization: " . $organization; - + $message = print_r($clientInfo, true); mail( 'billing@gaslightmedia.com', 'GLM Payment Form', $message, $headers); @@ -88,11 +110,12 @@ header("Location:".site_url().$_SERVER['REQUEST_URI']); exit; } - - } + } +} function glm_payment_form() { + wp_enqueue_script('reCaptcha', 'https://www.google.com/recaptcha/api.js'); ob_start(); global $wpdb; ?> @@ -102,9 +125,9 @@ function glm_payment_form() { -

For your convenience, you can pay your Invoices using our secured - online credit card processing form. If you would like to have your - Invoice automatically paid monthly via credit card, please call +

For your convenience, you can pay your Invoices using our secured + online credit card processing form. If you would like to have your + Invoice automatically paid monthly via credit card, please call the office and we can set that up for you.

@@ -114,38 +137,38 @@ function glm_payment_form() { Billing information - - + + First name* - + Last name* - + Organization - + Address* - - + + City* - - + + Country* - - + + State* - + Zip* - + Phone - - + + Email* - Payment Information + Payment Information - - + + - Amount* + Amount* - $

+ $
- - + + Invoice Number - + Card type* @@ -505,7 +528,7 @@ function glm_payment_form() { - + Credit Card Number* @@ -515,7 +538,7 @@ function glm_payment_form() { Expiration Date* - + / + / @@ -555,6 +578,7 @@ function glm_payment_form() { +
@@ -568,7 +592,7 @@ function glm_payment_form() { recurrings[3] = 1 ; recurrings[4] = 1 ; recurrings[5] = 1 ; - var countryIds = new Array(); + var countryIds = new Array(); countryIds[0] = 1; countryIds[1] = 2; countryIds[2] = 3; @@ -814,7 +838,7 @@ function glm_payment_form() { countryIds[242] = 243; countryIds[243] = 244; countryIds[244] = 245; - var countryNames = new Array(); + var countryNames = new Array(); countryNames[0]= "Afghanistan" countryNames[1]= "Albania" countryNames[2]= "Algeria" @@ -1081,47 +1105,47 @@ function glm_payment_form() { methods.Add(method); var currentCampaign = 0 ; function checkData() { - var form = document.payment_form; + var form = document.payment_form; var minimumAmount = 1 ; var maximumAmount = 100000 ; - + if (form.first_name.value == '') { alert("Please enter your first name"); form.first_name.focus(); return ; - } + } if (form.last_name.value=="") { alert("Please enter your last name"); form.last_name.focus(); return; - } + } if (form.address.value=="") { alert("Please enter your address"); form.address.focus(); - return; - } + return; + } if (form.city.value == "") { alert("Please enter your city"); form.city.focus(); - return; - } + return; + } if (form.state.length > 1) { if (form.state.value =="") { alert("Please enter your state"); form.state.focus(); - return; + return; } - } + } if (form.zip.value == "") { alert("Please enter your zip"); form.zip.focus(); return; - } + } // if (form.country.value == "") { // alert("Please enter your country"); // form.country.focus(); -// return; -// } +// return; +// } // if (form.invoice_num.value == "") { // alert("Please enter an invoice number"); // form.invoice_num.focus(); @@ -1131,22 +1155,22 @@ function glm_payment_form() { // alert("Please enter your phone"); // form.phone.focus(); // return; -// } - +// } + if (form.email.value == '') { alert("Please enter your email"); form.email.focus(); return; } - - + + var emailFilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i var ret = emailFilter.test(form.email.value); if (!ret) { alert("Please enter a valid email"); form.email.focus(); return; - } + } var amountValid = false ; var amount = 0 ; if (form.rd_amount) { @@ -1155,29 +1179,29 @@ function glm_payment_form() { if(form.rd_amount[i].checked == true) { amountValid = true ; amount = form.rd_amount[i].value ; - } - } + } + } } else if (form.rd_amount.checked == true) { amountValid = true ; amount = form.rd_amount.value ; } - + } - if (!amountValid) { + if (!amountValid) { if (parseFloat(form.amount.value)) { amountValid = true; - amount = form.amount.value ; - } - } - - + amount = form.amount.value ; + } + } + + if (!amountValid) { var msg; msg = "Please choose from pre-defined amounts or enter your own amount in the textbox"; alert(msg); - return; - } + return; + } if (parseFloat(amount) < minimumAmount) { @@ -1193,22 +1217,22 @@ function glm_payment_form() { return ; } - - - - - + + + + + var paymentMethod = ""; paymentMethod = "os_authnet"; - - method = methods.Find(paymentMethod); + + method = methods.Find(paymentMethod); //Check payment method page if (method.getCreditCard()) { if (form.x_card_num.value == "") { alert("Please enter creditcard number"); form.x_card_num.focus(); - return; - } + return; + } if (form.x_card_code.value == "") { alert("Please enter card code"); form.x_card_code.focus(); @@ -1221,51 +1245,51 @@ function glm_payment_form() { form.card_holde_name.focus(); return ; } - } + } //This check is only used for echeck payment gateway if (paymentMethod == 'os_echeck') { if (form.x_bank_aba_code.value == '') { alert("Please enter Bank ABA Routing Number"); form.x_bank_aba_code.focus(); return ; - } + } if (form.x_bank_acct_num.value == '') { alert("Please enter Bank Account Number"); form.x_bank_aba_code.focus(); return ; - } + } if (form.x_bank_name.value == '') { alert("Please enter Bank Name"); form.x_bank_name.focus(); - return ; - } + return ; + } if (form.x_bank_acct_name.value == '') { alert("Please enter Account Holder Name"); form.x_bank_acct_name.focus(); return ; - } - } - + } + } + form.submit(); - - } - + + } + function checkNumber(txtName) - { - var num = txtName.value - if(isNaN(num)) - { - alert("Only number is accepted"); - txtName.value = ""; - txtName.focus(); - } + { + var num = txtName.value + if(isNaN(num)) + { + alert("Only number is accepted"); + txtName.value = ""; + txtName.focus(); + } } function changeDonationType() { var form = document.payment_form ; var trFrequecy = document.getElementById('tr_frequency'); - var trNumberDonatons = document.getElementById('tr_number_donations'); + var trNumberDonatons = document.getElementById('tr_number_donations'); if (form.donation_type[0].checked == true) { trFrequecy.style.display = 'none' ; if (trNumberDonatons) @@ -1274,8 +1298,8 @@ function glm_payment_form() { trFrequecy.style.display = '' ; if (trNumberDonatons) trNumberDonatons.style.display = '' ; - } - } + } + } function deSelectRadio() { var form = document.payment_form ; @@ -1288,9 +1312,9 @@ function glm_payment_form() { } } else { form.rd_amount.checked = false ; - } - - } + } + + } } else { form.amount.value = ''; } @@ -1299,14 +1323,14 @@ function glm_payment_form() { function clearTextbox() { var form = document.payment_form ; if (form.amount) - form.amount.value = ''; - } - - function displayRecurring(show) { - var form = document.payment_form ; + form.amount.value = ''; + } + + function displayRecurring(show) { + var form = document.payment_form ; var trDonationType = document.getElementById('donation_type') ; - if (!trDonationType) - return ; + if (!trDonationType) + return ; var trFrequency = document.getElementById('tr_frequency'); var trNumberDonations = document.getElementById('tr_number_donations') ; if (show) { @@ -1316,33 +1340,33 @@ function glm_payment_form() { if (trNumberDonations) { trNumberDonations.style.display = ''; } - } + } } else { trDonationType.style.display = 'none'; trFrequency.style.display = 'none'; if (trNumberDonations) { trNumberDonations.style.display = 'none'; } - } + } } - function checkCampaignRecurring() { + function checkCampaignRecurring() { var form = document.payment_form ; var show = 1 ; var paymentMethod = ""; paymentMethod = "os_authnet"; - + method = methods.Find(paymentMethod); if (!method.getEnableRecurring()) { show = 0 ; } else { if (form.campaign_id.value > 0) show = recurrings [form.campaign_id.value] ; - } + } displayRecurring(show); } - + function updateAmount() { var form = document.payment_form ; var campaignId = form.campaign_id.value ; @@ -1350,9 +1374,9 @@ function glm_payment_form() { //Check to enable and disable recurring var show = 1 ; if (campaignId) - show = recurrings [campaignId] ; - displayRecurring(show); - + show = recurrings [campaignId] ; + displayRecurring(show); + } function updateStateList() { var form = document.payment_form ; @@ -1366,16 +1390,16 @@ function glm_payment_form() { list.length = 1 ; var i = 0; //Get the country index - var country = form.country.value ; + var country = form.country.value ; if (country != '') { //Find index of the country for (var i = 0 ; i < countryNames.length ; i++) { - if (countryNames[i] == country) { + if (countryNames[i] == country) { break ; } } //We will find the states - var countryId = countryIds[i] ; + var countryId = countryIds[i] ; var stateNames = stateList[countryId]; ; if (stateNames) { var arrStates = stateNames.split(','); @@ -1391,12 +1415,12 @@ function glm_payment_form() { list.options[i++] = opt; } list.lenght = i ; - } - } + } + } } - - + +