function sunshine_paypal_process_ipn() { global $sunshine; if (isset($_GET['sunshine_paypal_ipn']) && $_GET['sunshine_paypal_ipn'] == 'paypal_standard_ipn' && isset($_POST)) { $raw_post_data = file_get_contents('php://input'); $raw_post_array = explode('&', $raw_post_data); $myPost = array(); foreach ($raw_post_array as $keyval) { $keyval = explode('=', $keyval); if (count($keyval) == 2) { $myPost[$keyval[0]] = urldecode($keyval[1]); } } // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' $req = 'cmd=_notify-validate'; if (function_exists('get_magic_quotes_gpc')) { $get_magic_quotes_exists = true; } foreach ($myPost as $key => $value) { if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { $value = urlencode(stripslashes($value)); } else { $value = urlencode($value); } $req .= "&{$key}={$value}"; } $paypal_url = $sunshine->options['paypal_test_mode'] ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr'; $response = wp_remote_post($paypal_url, array('method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.1', 'blocking' => true, 'headers' => array(), 'body' => $req, 'cookies' => array())); if (is_wp_error($response)) { exit; } else { $res = wp_remote_retrieve_body($response); } if (strcmp($res, "VERIFIED") != 0) { exit; } $order_id = intval($_POST['custom']); wp_set_post_terms($order_id, 'new', 'sunshine-order-status'); add_post_meta($order_id, 'txn_id', $myPost['txn_id']); add_post_meta($order_id, 'payment_fee', $myPost['payment_fee']); add_post_meta($order_id, 'ipn_track_id', $myPost['ipn_track_id']); add_post_meta($order_id, 'verify_sign', $myPost['verify_sign']); add_post_meta($order_id, 'payer_id', $myPost['payer_id']); add_post_meta($order_id, 'mode', $sunshine->options['paypal_test_mode'] ? 'test' : 'live'); SunshineOrder::notify($order_id); exit; } }
function sunshine_process_free_order() { global $sunshine; if (isset($_POST['sunshine_checkout']) && $_POST['sunshine_checkout'] == 1 && empty($sunshine->errors) && $sunshine->cart->total <= 0) { SunshineOrder::process_free_payment(); } }