Example #1
0
 public function check_for_post()
 {
     if (isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
         // Validate all the datas
         self::validate_and_clean_post_array();
         // If data validation fails then exit early
         if (is_array(self::$validation)) {
             // Validations errors are handled in `function show_donate_form()`
             return;
             // Otherwise the data is clean! Huzzah
         } else {
             // 0 | Set up ready for sagepay
             require_once 'lib/SagePay.php';
             $sagePay = new SagePay();
             self::$input_data['sage_vendortx'] = $sagePay->getVendorTxCode();
             $sage_description = get_option('sd_payment_description');
             // 1 | Save to database
             self::save_donation_to_db();
             // 2 | Format for SagePay
             $amount = floatval(str_replace(array('€', '£', '$'), '', self::$input_data['amount']));
             $currency = get_option('sd_currency', 'GBP');
             $sagePay->setCurrency($currency);
             $sagePay->setAmount($amount);
             $sagePay->setDescription($sage_description);
             $sagePay->setBillingFirstnames(self::$input_data['name_first']);
             $sagePay->setBillingSurname(self::$input_data['name_last']);
             $sagePay->setBillingCity(self::$input_data['city']);
             $sagePay->setBillingPostCode(self::$input_data['postcode']);
             $sagePay->setBillingAddress1(self::$input_data['address1']);
             $sagePay->setBillingCountry(self::$input_data['country']);
             $sagePay->setAllowGiftAid(self::$input_data['giftaid']);
             $sagePay->setDeliverySameAsBilling();
             $sagePay->setWebsite(site_url());
             $sagePay->setSuccessURL(get_option('sd_success_url'));
             $sagePay->setFailureURL(get_option('sd_failure_url'));
             $crypt = $sagePay->getCrypt();
             // 3 | Tell the user that we're going to redirect them to SagePay
             include sprintf("%s/templates/tpl_sage_redirect.php", dirname(__FILE__));
             return TRUE;
         }
     }
 }