function seamless_donations_generate_donation_form() { $form_action = plugins_url('/seamless-donations-payment.php', __FILE__); //$session_id = $GLOBALS['seamless_donations_session_id']; //$session_id = 'dgxdonate_' . substr ( session_id (), 0, 10 ) . '_' . time (); $session_id = seamless_donations_get_guid('sd'); dgx_donate_debug_log('----------------------------------------'); dgx_donate_debug_log('PREPARING DONATION FORM'); dgx_donate_debug_log("Seamless Donations Version: " . dgx_donate_get_version()); dgx_donate_debug_log("User browser: " . seamless_donations_get_browser_name()); dgx_donate_debug_log("Assigning hidden field session ID to {$session_id}"); dgx_donate_debug_log("Form action: {$form_action}"); $form = array('id' => 'seamless-donations-form', 'name' => 'seamless-donations-form', 'action' => $form_action, 'method' => 'post', 'elements' => array('session_id_element' => array('type' => 'hidden', 'group' => '_dgx_donate_session_id', 'value' => $session_id), 'redirect_url_element' => array('type' => 'hidden', 'group' => '_dgx_donate_redirect_url', 'value' => $form_action), 'success_url_element' => array('type' => 'hidden', 'group' => '_dgx_donate_success_url', 'value' => dgx_donate_paypalstd_get_current_url()))); // Start the outermost container $form['outermost_container'] = array('id' => 'dgx-donate-container'); // Pick and choose the built in sections this gateway supports $warning_section = seamless_donations_donation_form_warning_section(); if (is_array($warning_section)) { $form['outermost_container']['warning_section'] = $warning_section; } $form['outermost_container']['donation_section'] = seamless_donations_get_donation_section(); $form['outermost_container']['tribute_section'] = seamless_donations_get_tribute_section(); $form['outermost_container']['donor_section'] = seamless_donations_get_donor_section(); $form['outermost_container']['billing_section'] = seamless_donations_get_billing_section(); $form['outermost_container']['paypal_section'] = seamless_donations_get_paypal_section(); $form['outermost_container']['submit_section'] = seamless_donations_get_submit_section(); $form = apply_filters('seamless_donations_form_section_order', $form); // build and display the form $html = seamless_donations_forms_engine($form); return $html; }
function seamless_donations_generate_donation_form() { $process_form_via = get_option('dgx_donate_form_via_action'); // if the option isn't defined, returns false, if defined = '1' // this option exists for host compatibility, where some hosts won't send a form // to another .php file for processing if ($process_form_via == '1') { $form_action = get_permalink(); $process_form_via_status = 'initiating page'; } else { // redirect to seamless-donations-payment.php, which may cause some hosting errors // but is the default behavior since early 4.0.x releases $form_action = plugins_url('/seamless-donations-payment.php', __FILE__); $process_form_via_status = 'external php file'; } $browser_based_ids = get_option('dgx_donate_browser_uuid'); if ($browser_based_ids == '1') { $session_id = 'browser-uuid'; // generate UUID in JavaScript } else { $session_id = seamless_donations_get_guid('sd'); // UUID on server } dgx_donate_debug_log('----------------------------------------'); dgx_donate_debug_log('PREPARING DONATION FORM'); dgx_donate_debug_log("Seamless Donations Version: " . dgx_donate_get_version()); dgx_donate_debug_log("User browser: " . seamless_donations_get_browser_name()); dgx_donate_debug_log("Assigning hidden field session ID to {$session_id}"); dgx_donate_debug_log("Form action via: {$process_form_via_status}"); dgx_donate_debug_log("Form action: {$form_action}"); $form = array('id' => 'seamless-donations-form', 'name' => 'seamless-donations-form', 'action' => $form_action, 'method' => 'post', 'elements' => array('session_id_element' => array('type' => 'hidden', 'group' => '_dgx_donate_session_id', 'value' => $session_id), 'redirect_url_element' => array('type' => 'hidden', 'group' => '_dgx_donate_redirect_url', 'value' => $form_action), 'success_url_element' => array('type' => 'hidden', 'group' => '_dgx_donate_success_url', 'value' => dgx_donate_paypalstd_get_current_url()), 'process_via' => array('type' => 'hidden', 'group' => '_dgx_donate_form_via', 'value' => $process_form_via))); // Start the outermost container $form['outermost_container'] = array('id' => 'dgx-donate-container'); // Pick and choose the built in sections this gateway supports $warning_section = seamless_donations_donation_form_warning_section(); if (is_array($warning_section)) { $form['outermost_container']['warning_section'] = $warning_section; } $form['outermost_container']['donation_section'] = seamless_donations_get_donation_section(); $form['outermost_container']['tribute_section'] = seamless_donations_get_tribute_section(); $form['outermost_container']['donor_section'] = seamless_donations_get_donor_section(); $form['outermost_container']['billing_section'] = seamless_donations_get_billing_section(); $form['outermost_container']['paypal_section'] = seamless_donations_get_paypal_section(); $form['outermost_container']['submit_section'] = seamless_donations_get_submit_section(); $form = apply_filters('seamless_donations_form_section_order', $form); // build and display the form $html = seamless_donations_forms_engine($form); return $html; }
require_once './inc/utilities.php'; require_once './inc/legacy.php'; require_once './inc/donations.php'; require_once './legacy/dgx-donate.php'; require_once './legacy/dgx-donate-admin.php'; require_once './seamless-donations-admin.php'; require_once './seamless-donations-form.php'; require_once './dgx-donate-paypalstd.php'; // Log dgx_donate_debug_log('----------------------------------------'); dgx_donate_debug_log('DONATION TRANSACTION STARTED'); dgx_donate_debug_log('Test mode: A'); $php_version = phpversion(); dgx_donate_debug_log("PHP Version: {$php_version}"); dgx_donate_debug_log("Seamless Donations Version: " . dgx_donate_get_version()); dgx_donate_debug_log("User browser: " . seamless_donations_get_browser_name()); dgx_donate_debug_log('IPN: ' . plugins_url('/dgx-donate-paypalstd-ipn.php', __FILE__)); $nonce = $_POST['nonce']; if (!wp_verify_nonce($nonce, 'dgx-donate-nonce')) { dgx_donate_debug_log('Payment process nonce validation failure.'); die('Access Denied.'); } else { dgx_donate_debug_log("Payment process nonce {$nonce} validated."); } // todo: not getting session ID *************************************************** // todo: reattach the javascript verification code $sd4_mode = get_option('dgx_donate_start_in_sd4_mode'); $session_id = $_POST['_dgx_donate_session_id']; dgx_donate_debug_log("Session ID retrieved from _POST: {$session_id}"); // now attempt to retrieve session data to see if it already exists (which would trigger an error) if ($sd4_mode == false) {
function dgx_donate_paypalstd_ajax_checkout() { // Log dgx_donate_debug_log('----------------------------------------'); dgx_donate_debug_log('DONATION TRANSACTION STARTED'); dgx_donate_debug_log('Test mode: B'); $php_version = phpversion(); dgx_donate_debug_log("PHP Version: {$php_version}"); dgx_donate_debug_log("Seamless Donations Version: " . dgx_donate_get_version()); dgx_donate_debug_log("User browser: " . seamless_donations_get_browser_name()); dgx_donate_debug_log('IPN: ' . plugins_url('/dgx-donate-paypalstd-ipn.php', __FILE__)); $nonce = $_POST['nonce']; if (!wp_verify_nonce($nonce, 'dgx-donate-nonce')) { dgx_donate_debug_log('Payment process nonce validation failure.'); die('Access Denied.'); } else { dgx_donate_debug_log("Payment process nonce {$nonce} validated."); } $sd4_mode = get_option('dgx_donate_start_in_sd4_mode'); $session_id = $_POST['sessionID']; dgx_donate_debug_log("Session ID retrieved from _POST: {$session_id}"); // now attempt to retrieve session data to see if it already exists (which would trigger an error) if ($sd4_mode == false) { // use the old transient system $session_data = get_transient($session_id); dgx_donate_debug_log('Looking for pre-existing session data (legacy transient mode): ' . $session_id); } else { // use the new guid/audit db system $session_data = seamless_donations_get_audit_option($session_id); dgx_donate_debug_log('Looking for pre-existing session data (guid/audit db mode): ' . $session_id); } if ($session_data !== false) { dgx_donate_debug_log('Session data already exists, returning false'); die; } else { dgx_donate_debug_log('Duplicate session data not found. Payment process data assembly can proceed.'); if ($_POST['honoreeCountry'] == 'US') { $_POST['honoreeProvince'] = ''; } else { if ($_POST['honoreeCountry'] == 'CA') { $_POST['honoreeState'] = ''; } else { if ($_POST['honoreeCountry'] == '') { //default to US if country blank $_POST['honoreeCountry'] = 'US'; } else { $_POST['honoreeState'] = ''; $_POST['honoreeProvince'] = ''; } } } if ($_POST['country'] == 'US') { $_POST['province'] = ''; } else { if ('CA' == $_POST['country']) { $_POST['state'] = ''; } else { if ($_POST['country'] == '') { $_POST['country'] = 'US'; } else { $_POST['state'] = ''; $_POST['province'] = ''; } } } // Resolve the donation amount if (strcasecmp($_POST['donationAmount'], "OTHER") == 0) { $_POST['amount'] = floatval($_POST['userAmount']); } else { $_POST['amount'] = floatval($_POST['donationAmount']); } if ($_POST['amount'] < 1.0) { $_POST['amount'] = 1.0; } // Repack the POST $acceptedFields = apply_filters('seamless_donations_accepted_fields', array('referringUrl', 'sessionID', 'amount', 'repeating', 'designated', 'designatedFund', 'tributeGift', 'memorialGift', 'honoreeName', 'honoreeEmail', 'honoreeAddress', 'honoreeCity', 'honoreeState', 'honoreeProvince', 'honoreeCountry', 'honoreeZip', 'honoreeEmailName', 'honoreePostName', 'firstName', 'lastName', 'phone', 'email', 'addToMailingList', 'address', 'address2', 'city', 'state', 'province', 'country', 'zip', 'increaseToCover', 'anonymous', 'paymentMethod', 'employerMatch', 'employerName', 'occupation', 'ukGiftAid')); foreach ($acceptedFields as $key => $value) { $upper = strtoupper($value); $post_data[$upper] = $_POST[$value]; } $post_data['PAYMENTMETHOD'] = 'PayPal'; // Sanitize the data (remove leading, trailing spaces quotes, brackets) foreach ($post_data as $key => $value) { $temp = trim($value); $temp = str_replace("\"", "", $temp); $temp = strip_tags($temp); $post_data[$key] = $temp; } if ($sd4_mode == false) { // Save it all in a transient $transient_token = $post_data['SESSIONID']; // Capture the result of the transient update call $transient_status = set_transient($transient_token, $post_data, 7 * 24 * 60 * 60); // 7 days // if transient could not be set, fail and die if ($transient_status === false) { $returnMessage = '1|Failed to save transient'; echo $returnMessage; wp_die(); } dgx_donate_debug_log('Saving transaction data using legacy mode'); } else { seamless_donations_update_audit_option($session_id, $post_data); dgx_donate_debug_log('Saving transaction data using guid/audit db mode'); } // more log data dgx_donate_debug_log('Name: ' . $post_data['FIRSTNAME'] . ' ' . $post_data['LASTNAME']); dgx_donate_debug_log('Amount: ' . $post_data['AMOUNT']); dgx_donate_debug_log("Preparation complete. It is now up to PayPal to return data via IPN."); // Return success to AJAX caller as " code | message " // A return code of 0 indicates success, and the returnMessage is ignored // A return code of 1 indicates failure, and the returnMessage contains the error message $returnMessage = "0|SUCCESS"; echo $returnMessage; wp_die(); // this is required to return a proper result } }
function seamless_donations_process_payment() { // Log $paypal_server = get_option('dgx_donate_paypal_server'); dgx_donate_debug_log('----------------------------------------'); dgx_donate_debug_log('DONATION TRANSACTION STARTED'); dgx_donate_debug_log('Processing mode: ' . $paypal_server); $php_version = phpversion(); dgx_donate_debug_log("PHP Version: {$php_version}"); dgx_donate_debug_log("Seamless Donations Version: " . dgx_donate_get_version()); dgx_donate_debug_log("User browser: " . seamless_donations_get_browser_name()); $http_ipn_url = plugins_url('/dgx-donate-paypalstd-ipn.php', dirname(__FILE__)); $https_ipn_url = plugins_url('/pay/paypalstd/ipn.php', dirname(__FILE__)); $https_ipn_url = str_ireplace('http://', 'https://', $https_ipn_url); // force https check dgx_donate_debug_log('IPN (http): ' . $http_ipn_url); dgx_donate_debug_log('IPN (https): ' . $https_ipn_url); $nonce_bypass = get_option('dgx_donate_ignore_form_nonce'); if ($nonce_bypass != '1') { $nonce = $_POST['nonce']; if (!wp_verify_nonce($nonce, 'dgx-donate-nonce')) { $nonce_error = 'Payment process nonce validation failure. '; $nonce_error .= 'Consider turning on Ignore Form Nonce Value in the Seamless Donations '; $nonce_error .= 'Settings tab under Host Compatibility Options.'; dgx_donate_debug_log($nonce_error); die('Access Denied. See Seamless Donations log for details.'); } else { dgx_donate_debug_log("Payment process nonce {$nonce} validated."); } } // todo: not getting session ID *************************************************** // todo: reattach the javascript verification code $sd4_mode = get_option('dgx_donate_start_in_sd4_mode'); $session_id = $_POST['_dgx_donate_session_id']; dgx_donate_debug_log("Session ID retrieved from _POST: {$session_id}"); // now attempt to retrieve session data to see if it already exists (which would trigger an error) if ($sd4_mode == false) { // use the old transient system $session_data = get_transient($session_id); dgx_donate_debug_log('Looking for pre-existing session data (legacy transient mode): ' . $session_id); } else { // use the new guid/audit db system $session_data = seamless_donations_get_audit_option($session_id); dgx_donate_debug_log('Looking for pre-existing session data (guid/audit db mode): ' . $session_id); } if ($session_data !== false) { dgx_donate_debug_log('Session data already exists, returning false'); die; } else { dgx_donate_debug_log('Duplicate session data not found. Payment process data assembly can proceed.'); // Repack the POST $post_data = array(); if (isset($_POST['_dgx_donate_redirect_url'])) { $post_data['REFERRINGURL'] = $_POST['_dgx_donate_redirect_url']; } else { $post_data['REFERRINGURL'] = ''; } if (isset($_POST['_dgx_donate_success_url'])) { $post_data['SUCCESSURL'] = $_POST['_dgx_donate_success_url']; } else { $post_data['SUCCESSURL'] = ''; } if (isset($_POST['_dgx_donate_session_id'])) { $post_data['SESSIONID'] = $_POST['_dgx_donate_session_id']; } else { $post_data['SESSIONID'] = ''; } if (isset($_POST['_dgx_donate_repeating'])) { $post_data['REPEATING'] = $_POST['_dgx_donate_repeating']; } else { $post_data['REPEATING'] = ''; } if (isset($_POST['_dgx_donate_designated'])) { $post_data['DESIGNATED'] = $_POST['_dgx_donate_designated']; } else { $post_data['DESIGNATED'] = ''; } if (isset($_POST['_dgx_donate_designated_fund'])) { $post_data['DESIGNATEDFUND'] = $_POST['_dgx_donate_designated_fund']; } else { $post_data['DESIGNATEDFUND'] = ''; } if (isset($_POST['_dgx_donate_tribute_gift'])) { $post_data['TRIBUTEGIFT'] = $_POST['_dgx_donate_tribute_gift']; } else { $post_data['TRIBUTEGIFT'] = ''; } if (isset($_POST['_dgx_donate_memorial_gift'])) { $post_data['MEMORIALGIFT'] = $_POST['_dgx_donate_memorial_gift']; } else { $post_data['MEMORIALGIFT'] = ''; } if (isset($_POST['_dgx_donate_honoree_name'])) { $post_data['HONOREENAME'] = $_POST['_dgx_donate_honoree_name']; } else { $post_data['HONOREENAME'] = ''; } if (isset($_POST['_dgx_donate_honor_by_email'])) { $post_data['HONORBYEMAIL'] = $_POST['_dgx_donate_honor_by_email']; } else { $post_data['HONORBYEMAIL'] = ''; } if (isset($_POST['_dgx_donate_honoree_email'])) { $post_data['HONOREEEMAIL'] = $_POST['_dgx_donate_honoree_email']; } else { $post_data['HONOREEEMAIL'] = ''; } if (isset($_POST['_dgx_donate_honoree_address'])) { $post_data['HONOREEADDRESS'] = $_POST['_dgx_donate_honoree_address']; } else { $post_data['HONOREEADDRESS'] = ''; } if (isset($_POST['_dgx_donate_honoree_city'])) { $post_data['HONOREECITY'] = $_POST['_dgx_donate_honoree_city']; } else { $post_data['HONOREECITY'] = ''; } if (isset($_POST['_dgx_donate_honoree_state'])) { $post_data['HONOREESTATE'] = $_POST['_dgx_donate_honoree_state']; } else { $post_data['HONOREESTATE'] = ''; } if (isset($_POST['_dgx_donate_honoree_province'])) { $post_data['HONOREEPROVINCE'] = $_POST['_dgx_donate_honoree_province']; } else { $post_data['HONOREEPROVINCE'] = ''; } if (isset($_POST['_dgx_donate_honoree_country'])) { $post_data['HONOREECOUNTRY'] = $_POST['_dgx_donate_honoree_country']; } else { $post_data['HONOREECOUNTRY'] = ''; } if (isset($_POST['_dgx_donate_honoree_zip'])) { $post_data['HONOREEZIP'] = $_POST['_dgx_donate_honoree_zip']; } else { $post_data['HONOREEZIP'] = ''; } if (isset($_POST['_dgx_donate_honoree_email_name'])) { $post_data['HONOREEEMAILNAME'] = $_POST['_dgx_donate_honoree_email_name']; } else { $post_data['HONOREEEMAILNAME'] = ''; } if (isset($_POST['_dgx_donate_honoree_post_name'])) { $post_data['HONOREEPOSTNAME'] = $_POST['_dgx_donate_honoree_post_name']; } else { $post_data['HONOREEPOSTNAME'] = ''; } if (isset($_POST['_dgx_donate_donor_first_name'])) { $post_data['FIRSTNAME'] = $_POST['_dgx_donate_donor_first_name']; } else { $post_data['FIRSTNAME'] = ''; } if (isset($_POST['_dgx_donate_donor_last_name'])) { $post_data['LASTNAME'] = $_POST['_dgx_donate_donor_last_name']; } else { $post_data['LASTNAME'] = ''; } if (isset($_POST['_dgx_donate_donor_phone'])) { $post_data['PHONE'] = $_POST['_dgx_donate_donor_phone']; } else { $post_data['PHONE'] = ''; } if (isset($_POST['_dgx_donate_donor_email'])) { $post_data['EMAIL'] = $_POST['_dgx_donate_donor_email']; } else { $post_data['EMAIL'] = ''; } if (isset($_POST['_dgx_donate_add_to_mailing_list'])) { $post_data['ADDTOMAILINGLIST'] = $_POST['_dgx_donate_add_to_mailing_list']; } else { $post_data['ADDTOMAILINGLIST'] = ''; } if (isset($_POST['_dgx_donate_donor_address'])) { $post_data['ADDRESS'] = $_POST['_dgx_donate_donor_address']; } else { $post_data['ADDRESS'] = ''; } if (isset($_POST['_dgx_donate_donor_address2'])) { $post_data['ADDRESS2'] = $_POST['_dgx_donate_donor_address2']; } else { $post_data['ADDRESS2'] = ''; } if (isset($_POST['_dgx_donate_donor_city'])) { $post_data['CITY'] = $_POST['_dgx_donate_donor_city']; } else { $post_data['CITY'] = ''; } if (isset($_POST['_dgx_donate_donor_state'])) { $post_data['STATE'] = $_POST['_dgx_donate_donor_state']; } else { $post_data['STATE'] = ''; } if (isset($_POST['_dgx_donate_donor_province'])) { $post_data['PROVINCE'] = $_POST['_dgx_donate_donor_province']; } else { $post_data['PROVINCE'] = ''; } if (isset($_POST['_dgx_donate_donor_country'])) { $post_data['COUNTRY'] = $_POST['_dgx_donate_donor_country']; } else { $post_data['COUNTRY'] = ''; } if (isset($_POST['_dgx_donate_donor_zip'])) { $post_data['ZIP'] = $_POST['_dgx_donate_donor_zip']; } else { $post_data['ZIP'] = ''; } if (isset($_POST['_dgx_donate_increase_to_cover'])) { $post_data['INCREASETOCOVER'] = $_POST['_dgx_donate_increase_to_cover']; } else { $post_data['INCREASETOCOVER'] = ''; } if (isset($_POST['_dgx_donate_anonymous'])) { $post_data['ANONYMOUS'] = $_POST['_dgx_donate_anonymous']; } else { $post_data['ANONYMOUS'] = ''; } if (isset($_POST['_dgx_donate_employer_match'])) { $post_data['EMPLOYERMATCH'] = $_POST['_dgx_donate_employer_match']; } else { $post_data['EMPLOYERMATCH'] = ''; } if (isset($_POST['_dgx_donate_employer_name'])) { $post_data['EMPLOYERNAME'] = $_POST['_dgx_donate_employer_name']; } else { $post_data['EMPLOYERNAME'] = ''; } if (isset($_POST['_dgx_donate_occupation'])) { $post_data['OCCUPATION'] = $_POST['_dgx_donate_occupation']; } else { $post_data['OCCUPATION'] = ''; } if (isset($_POST['_dgx_donate_uk_gift_aid'])) { $post_data['UKGIFTAID'] = $_POST['_dgx_donate_uk_gift_aid']; } else { $post_data['UKGIFTAID'] = ''; } if (isset($_POST['nonce'])) { $post_data['NONCE'] = $_POST['nonce']; } else { $post_data['NONCE'] = ''; } // pull override data from hidden form (might be modified by users with callbacks) if (isset($_POST['business'])) { $post_data['BUSINESS'] = $_POST['business']; } else { $post_data['BUSINESS'] = ''; } if (isset($_POST['return'])) { $post_data['RETURN'] = $_POST['return']; } else { $post_data['RETURN'] = ''; } if (isset($_POST['notify_url'])) { $post_data['NOTIFY_URL'] = $_POST['notify_url']; } else { $post_data['NOTIFY_URL'] = ''; } if (isset($_POST['item_name'])) { $post_data['ITEM_NAME'] = $_POST['item_name']; } else { $post_data['ITEM_NAME'] = ''; } if (isset($_POST['cmd'])) { $post_data['CMD'] = $_POST['cmd']; } else { $post_data['CMD'] = ''; } if (isset($_POST['p3'])) { $post_data['P3'] = $_POST['p3']; } else { $post_data['P3'] = ''; } if (isset($_POST['t3'])) { $post_data['T3'] = $_POST['t3']; } else { $post_data['T3'] = ''; } if (isset($_POST['a3'])) { $post_data['A3'] = $_POST['a3']; } else { $post_data['A3'] = ''; } // Resolve the donation amount if (strcasecmp($_POST['_dgx_donate_amount'], "OTHER") == 0) { $post_data['AMOUNT'] = floatval($_POST['_dgx_donate_user_amount']); } else { $post_data['AMOUNT'] = floatval($_POST['_dgx_donate_amount']); } if ($post_data['AMOUNT'] < 1.0) { $post_data['AMOUNT'] = 1.0; } if ('US' == $post_data['HONOREECOUNTRY']) { $post_data['PROVINCE'] = ''; } else { if ('CA' == $post_data['HONOREECOUNTRY']) { $post_data['HONOREESTATE'] = ''; } else { $post_data['HONOREESTATE'] = ''; $post_data['HONOREEPROVINCE'] = ''; } } // If no country entered, pull in the default if ($post_data['COUNTRY'] == '') { $post_data['COUNTRY'] = get_option('dgx_donate_default_country'); } if ('US' == $post_data['COUNTRY']) { $post_data['PROVINCE'] = ''; } else { if ('CA' == $post_data['COUNTRY']) { $post_data['STATE'] = ''; } else { $post_data['STATE'] = ''; $post_data['PROVINCE'] = ''; } } $post_data['PAYMENTMETHOD'] = "PayPal"; // $_POST['dgx_donate_payment_method'] $post_data['SDVERSION'] = dgx_donate_get_version(); // Sanitize the data (remove leading, trailing spaces quotes, brackets) foreach ($post_data as $key => $value) { $temp = trim($value); $temp = str_replace("\"", "", $temp); $temp = strip_tags($temp); $post_data[$key] = $temp; } // account for different permalink styles $success_url = $post_data['SUCCESSURL']; $qmark = strpos($success_url, '?'); if ($qmark === false) { $success_url .= "?thanks=true"; } else { $success_url .= "&thanks=true"; } $post_data['RETURN'] = $success_url; dgx_donate_debug_log("Success URL: {$success_url}"); $post_data = apply_filters('seamless_donations_payment_post_data', $post_data); // insert extra validation for GoodByeCaptcha and any other validation $challenge_response_passed = apply_filters('seamless_donations_challenge_response_request', true, $post_data); if (true !== $challenge_response_passed) { if (is_wp_error($challenge_response_passed)) { $error_message = $challenge_response_passed->get_error_message(); } else { $error_message = (string) $challenge_response_passed; } dgx_donate_debug_log('Form challenge-response failed:' . $error_message); die(esc_html__('Invalid response to challenge. Are you human?')); } if ($sd4_mode == false) { // Save it all in a transient $transient_token = $post_data['SESSIONID']; set_transient($transient_token, $post_data, 7 * 24 * 60 * 60); // 7 days dgx_donate_debug_log('Saving transaction data using legacy mode'); } else { seamless_donations_update_audit_option($session_id, $post_data); dgx_donate_debug_log('Saving transaction data using guid/audit db mode'); } // more log data $obscurify = get_option('dgx_donate_log_obscure_name'); // false if not set if ($obscurify == '1') { // obscurify for privacy $donor_name = strtolower($post_data['FIRSTNAME'] . $post_data['LASTNAME']); $donor_name = seamless_donations_obscurify_string($donor_name, '*', false); } else { $donor_name = $post_data['FIRSTNAME'] . ' ' . $post_data['LASTNAME']; } dgx_donate_debug_log('Name: ' . $donor_name); dgx_donate_debug_log('Amount: ' . $post_data['AMOUNT']); dgx_donate_debug_log("Preparation complete. Entering PHP post code."); // new posting code // Build the PayPal query string $post_args = "?"; $post_args .= "first_name=" . urlencode($post_data['FIRSTNAME']) . "&"; $post_args .= "last_name=" . urlencode($post_data['LASTNAME']) . "&"; $post_args .= "address1=" . urlencode($post_data['ADDRESS']) . "&"; $post_args .= "address2=" . urlencode($post_data['ADDRESS2']) . "&"; $post_args .= "city=" . urlencode($post_data['CITY']) . "&"; $post_args .= "zip=" . urlencode($post_data['ZIP']) . "&"; if ('US' == $post_data['COUNTRY']) { $post_args .= "state=" . urlencode($post_data['STATE']) . "&"; } else { if ('CA' == $post_data['COUNTRY']) { $post_args .= "state=" . urlencode($post_data['PROVINCE']) . "&"; } } $post_args .= "country=" . urlencode($post_data['COUNTRY']) . "&"; $post_args .= "email=" . urlencode($post_data['EMAIL']) . "&"; $post_args .= "custom=" . urlencode($post_data['SESSIONID']) . "&"; // fill in repeating data, overriding if necessary dgx_donate_debug_log("Checking for repeat. REPEAT value is [" . $post_data['REPEATING'] . "]."); if ($post_data['REPEATING'] == '') { if ($post_data['CMD'] == '') { $post_data['CMD'] = '_donations'; } $post_args .= "amount=" . urlencode($post_data['AMOUNT']) . "&"; $post_args .= "cmd=" . urlencode($post_data['CMD']) . "&"; } else { if ($post_data['CMD'] == '') { $post_data['CMD'] = '_xclick-subscriptions'; } if ($post_data['P3'] == '') { $post_data['P3'] = '1'; } if ($post_data['T3'] == '') { $post_data['T3'] = 'M'; } $post_args .= "cmd=" . urlencode($post_data['CMD']) . "&"; $post_args .= "p3=" . urlencode($post_data['P3']) . "&"; // 1, M = monthly $post_args .= "t3=" . urlencode($post_data['T3']) . "&"; $post_args .= "src=1&sra=1&"; // repeat until cancelled, retry on failure $post_args .= "a3=" . urlencode($post_data['AMOUNT']) . "&"; $log_msg = "Enabling repeating donation, cmd=" . $post_data['CMD']; $log_msg .= ", p3=" . $post_data['P3'] . ", t3=" . $post_data['T3']; $log_msg .= ", a3=" . $post_data['AMOUNT']; dgx_donate_debug_log($log_msg); } $notify_url = plugins_url('/dgx-donate-paypalstd-ipn.php', __FILE__); $paypal_email = get_option('dgx_donate_paypal_email'); $currency_code = get_option('dgx_donate_currency'); // fill in the rest of the form data, overriding if necessary if ($post_data['BUSINESS'] == '') { $post_data['BUSINESS'] = $paypal_email; } if ($post_data['NOTIFY_URL'] == '') { $post_data['NOTIFY_URL'] = $notify_url; } dgx_donate_debug_log("Computed RETURN value: '" . $post_data['RETURN'] . "'"); $post_args .= "business=" . urlencode($post_data['BUSINESS']) . "&"; $post_args .= "return=" . urlencode($post_data['RETURN']) . "&"; $post_args .= "notify_url=" . urlencode($post_data['NOTIFY_URL']) . "&"; $post_args .= "item_name=" . urlencode($post_data['ITEM_NAME']) . "&"; $post_args .= "quantity=" . urlencode('1') . "&"; $post_args .= "currency_code=" . urlencode($currency_code) . "&"; $post_args .= "no_note=" . urlencode('1') . "&"; if ($paypal_server == "SANDBOX") { $form_action = "https://www.sandbox.paypal.com/cgi-bin/webscr"; } else { $form_action = "https://www.paypal.com/cgi-bin/webscr"; } // var_dump ( $post_args ); // // die(); // dgx_donate_debug_log ( "Post args: " . $post_args ); dgx_donate_debug_log("Redirecting to PayPal... now!"); wp_redirect($form_action . $post_args); exit; } }
function dgx_donate_paypalstd_ajax_checkout() { // Log dgx_donate_debug_log('----------------------------------------'); dgx_donate_debug_log('DONATION TRANSACTION STARTED'); dgx_donate_debug_log('Test mode: B'); $php_version = phpversion(); dgx_donate_debug_log("PHP Version: {$php_version}"); dgx_donate_debug_log("Seamless Donations Version: " . dgx_donate_get_version()); dgx_donate_debug_log("User browser: " . seamless_donations_get_browser_name()); dgx_donate_debug_log('IPN: ' . plugins_url('/dgx-donate-paypalstd-ipn.php', __FILE__)); $nonce = $_POST['nonce']; if (!wp_verify_nonce($nonce, 'dgx-donate-nonce')) { dgx_donate_debug_log('Payment process nonce validation failure.'); die('Access Denied.'); } else { dgx_donate_debug_log("Payment process nonce {$nonce} validated."); } $sd4_mode = get_option('dgx_donate_start_in_sd4_mode'); $session_id = $_POST['sessionID']; dgx_donate_debug_log("Session ID retrieved from _POST: {$session_id}"); // now attempt to retrieve session data to see if it already exists (which would trigger an error) if ($sd4_mode == false) { // use the old transient system $session_data = get_transient($session_id); dgx_donate_debug_log('Looking for pre-existing session data (legacy transient mode): ' . $session_id); } else { // use the new guid/audit db system $session_data = seamless_donations_get_audit_option($session_id); dgx_donate_debug_log('Looking for pre-existing session data (guid/audit db mode): ' . $session_id); } if ($session_data !== false) { dgx_donate_debug_log('Session data already exists, returning false'); die; } else { dgx_donate_debug_log('Duplicate session data not found. Payment process data assembly can proceed.'); // all of this no longer necessary for transfer to PayPal, just for storage in local audit table $referringUrl = $_POST['referringUrl']; $donationAmount = $_POST['donationAmount']; $userAmount = $_POST['userAmount']; $repeating = $_POST['repeating']; $designated = $_POST['designated']; $designatedFund = $_POST['designatedFund']; $tributeGift = $_POST['tributeGift']; $memorialGift = $_POST['memorialGift']; $honoreeName = $_POST['honoreeName']; $honorByEmail = $_POST['honorByEmail']; $honoreeEmail = $_POST['honoreeEmail']; $honoreeAddress = $_POST['honoreeAddress']; $honoreeCity = $_POST['honoreeCity']; $honoreeState = $_POST['honoreeState']; $honoreeProvince = $_POST['honoreeProvince']; $honoreeCountry = $_POST['honoreeCountry']; if ('US' == $honoreeCountry) { $honoreeProvince = ''; } else { if ('CA' == $honoreeCountry) { $honoreeState = ''; } else { $honoreeState = ''; $honoreeProvince = ''; } } $honoreeZip = $_POST['honoreeZip']; $honoreeEmailName = $_POST['honoreeEmailName']; $honoreePostName = $_POST['honoreePostName']; $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $phone = $_POST['phone']; $email = $_POST['email']; $addToMailingList = $_POST['addToMailingList']; $address = $_POST['address']; $address2 = $_POST['address2']; $city = $_POST['city']; $state = $_POST['state']; $province = $_POST['province']; $country = $_POST['country']; if ('US' == $country) { $province = ''; } else { if ('CA' == $country) { $state = ''; } else { $state = ''; $province = ''; } } $zip = $_POST['zip']; $increaseToCover = $_POST['increaseToCover']; $anonymous = $_POST['anonymous']; $employerMatch = $_POST['employerMatch']; $employerName = $_POST['employerName']; $occupation = $_POST['occupation']; $ukGiftAid = $_POST['ukGiftAid']; // Resolve the donation amount if (strcasecmp($donationAmount, "OTHER") == 0) { $amount = floatval($userAmount); } else { $amount = floatval($donationAmount); } if ($amount < 1.0) { $amount = 1.0; } // Repack the POST $post_data = array(); $post_data['REFERRINGURL'] = $referringUrl; $post_data['SESSIONID'] = $session_id; $post_data['AMOUNT'] = $amount; $post_data['REPEATING'] = $repeating; $post_data['DESIGNATED'] = $designated; $post_data['DESIGNATEDFUND'] = $designatedFund; $post_data['TRIBUTEGIFT'] = $tributeGift; $post_data['MEMORIALGIFT'] = $memorialGift; $post_data['HONOREENAME'] = $honoreeName; $post_data['HONORBYEMAIL'] = $honorByEmail; $post_data['HONOREEEMAIL'] = $honoreeEmail; $post_data['HONOREEADDRESS'] = $honoreeAddress; $post_data['HONOREECITY'] = $honoreeCity; $post_data['HONOREESTATE'] = $honoreeState; $post_data['HONOREEPROVINCE'] = $honoreeProvince; $post_data['HONOREECOUNTRY'] = $honoreeCountry; $post_data['HONOREEZIP'] = $honoreeZip; $post_data['HONOREEEMAILNAME'] = $honoreeEmailName; $post_data['HONOREEPOSTNAME'] = $honoreePostName; $post_data['FIRSTNAME'] = $firstName; $post_data['LASTNAME'] = $lastName; $post_data['PHONE'] = $phone; $post_data['EMAIL'] = $email; $post_data['ADDTOMAILINGLIST'] = $addToMailingList; $post_data['ADDRESS'] = $address; $post_data['ADDRESS2'] = $address2; $post_data['CITY'] = $city; $post_data['STATE'] = $state; $post_data['PROVINCE'] = $province; $post_data['COUNTRY'] = $country; $post_data['ZIP'] = $zip; $post_data['INCREASETOCOVER'] = $increaseToCover; $post_data['ANONYMOUS'] = $anonymous; $post_data['PAYMENTMETHOD'] = "PayPal"; $post_data['EMPLOYERMATCH'] = $employerMatch; $post_data['EMPLOYERNAME'] = $employerName; $post_data['OCCUPATION'] = $occupation; $post_data['UKGIFTAID'] = $ukGiftAid; $post_data['SDVERSION'] = dgx_donate_get_version(); // Sanitize the data (remove leading, trailing spaces quotes, brackets) foreach ($post_data as $key => $value) { $temp = trim($value); $temp = str_replace("\"", "", $temp); $temp = strip_tags($temp); $post_data[$key] = $temp; } if ($sd4_mode == false) { // Save it all in a transient $transient_token = $post_data['SESSIONID']; set_transient($transient_token, $post_data, 7 * 24 * 60 * 60); // 7 days dgx_donate_debug_log('Saving transaction data using legacy mode'); } else { seamless_donations_update_audit_option($session_id, $post_data); dgx_donate_debug_log('Saving transaction data using guid/audit db mode'); } // more log data dgx_donate_debug_log('Name: ' . $post_data['FIRSTNAME'] . ' ' . $post_data['LASTNAME']); dgx_donate_debug_log('Amount: ' . $post_data['AMOUNT']); dgx_donate_debug_log("Preparation complete. It is now up to PayPal to return data via IPN."); // Return success to AJAX caller as " code | message " // A return code of 0 indicates success, and the returnMessage is ignored // A return code of 1 indicates failure, and the returnMessage contains the error message $returnMessage = "0|SUCCESS"; echo $returnMessage; die; // this is required to return a proper result } }