/** * Success page */ public function post_donation() { if (!isset($_GET['crypt'])) { return; } // 0 | Set up require_once 'lib/SagePay.php'; $sagePay = new SagePay(); // 1 | Decode crypt from SagePay $crypt = $_GET['crypt']; $decoded = $sagePay->decode($crypt); // 2 | Update record with donation amount, success/fail & `VPSTxId` self::update_donation_detail($decoded['VendorTxCode'], $decoded); // 3 | Look up donation details $donation = self::select_donation_detail($decoded['VendorTxCode']); $show_allocation_field = get_option('sd_show_allocate'); // 4 | Send notification email to admin $headers = array('Content-Type: text/html; charset=UTF-8'); if ($notification_address = get_option('sd_notify_email')) { include sprintf("%s/templates/tpl_admin_notification_email.php", dirname(__FILE__)); $mail = wp_mail($notification_address, 'Online donation', $email_content, $headers); } // 5 | Send a thank you email if the donation goes through if (get_option('sd_confirmation') && ($message = get_option('sd_confirmation_body'))) { if (strpos($donation->status, 'Successful')) { $headers = array(); $reply_to = get_option('sd_reply_to_email'); if ($reply_to != "") { $headers['Reply-To'] = $reply_to; add_filter('wp_mail_from', function ($email) { return $reply_to; }); add_filter('wp_mail_from_name', function ($name) { return get_bloginfo('name'); }); } add_filter('wp_mail_content_type', array(&$this, 'set_html_content_type')); $mail = wp_mail($donation->email, 'Thank you', apply_filters('the_content', $message), $headers); remove_filter('wp_mail_content_type', array(&$this, 'set_html_content_type')); } } }