/** * Handle a call to our IPN listener. * * @return string * @access public * @static * @since 1.0.0 */ public static function process_ipn() { /* We only accept POST requests */ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { return false; } $gateway = new Charitable_Gateway_Paypal(); $data = $gateway->get_encoded_ipn_data(); if (empty($data)) { return false; } if (!$gateway->paypal_ipn_verification($data)) { return false; } $defaults = array('txn_type' => '', 'payment_status' => ''); $data = wp_parse_args($data, $defaults); $donation_id = isset($data['custom']) ? absint($data['custom']) : 0; if (!$donation_id) { return false; } /** * By default, all transactions are handled by the web_accept handler. * To handle other transaction types in a different way, use the * 'charitable_paypal_{transaction_type}' hook. * * @see Charitable_Gateway_Paypal::process_web_accept() */ $txn_type = strlen($data['txn_type']) ? $data['txn_type'] : 'web_accept'; if (has_action('charitable_paypal_' . $txn_type)) { do_action('charitable_paypal_' . $txn_type, $data, $donation_id); } else { do_action('charitable_paypal_web_accept', $data, $donation_id); } exit; }
/** * Handle a call to our IPN listener. * * @return string * @access public * @static * @since 1.0.0 */ public static function process_ipn() { /* We only accept POST requests */ if (isset($_SERVER['REQUEST_METHOD']) && 'POST' != $_SERVER['REQUEST_METHOD']) { die(__('Invalid Request', 'charitable')); } $gateway = new Charitable_Gateway_Paypal(); $data = $gateway->get_encoded_ipn_data(); if (defined('CHARITABLE_DEBUG') && CHARITABLE_DEBUG) { error_log(json_encode($data)); } if (empty($data)) { die(__('Empty Data', 'charitable')); } if (!$gateway->get_value('disable_ipn_verification') && !$gateway->paypal_ipn_verification($data)) { die(__('IPN Verification Failure', 'charitable')); } $defaults = array('txn_type' => '', 'payment_status' => '', 'custom' => 0); $data = wp_parse_args($data, $defaults); $custom = json_decode($data['custom'], true); $donation_id = is_array($custom) && array_key_exists('donation_id', $custom) ? absint($custom['donation_id']) : absint($custom); if (!$donation_id) { die(__('Missing Donation ID', 'charitable')); } /** * By default, all transactions are handled by the web_accept handler. * To handle other transaction types in a different way, use the * 'charitable_paypal_{transaction_type}' hook. * * @see Charitable_Gateway_Paypal::process_web_accept() */ $txn_type = strlen($data['txn_type']) ? $data['txn_type'] : 'web_accept'; if (has_action('charitable_paypal_' . $txn_type)) { do_action('charitable_paypal_' . $txn_type, $data, $donation_id); } else { do_action('charitable_paypal_web_accept', $data, $donation_id); } exit; }