$value) { $params = $params . '&' . $key . '=' . urlencode(stripslashes($value)); if ($msg != '') { $msg = $msg . ', '; } $msg = $msg . $key . '=' . $value; } $payment_gross = $_REQUEST['mc_gross']; if (!isset($payment_gross) || $payment_gross == '') { $payment_gross = $_REQUEST['payment_gross']; } $cc = yak_get_option(SELECTED_CURRENCY, ''); $payment_currency = $_REQUEST['mc_currency']; if (!empty($payment_currency) && $payment_currency != $cc) { echo "ERROR: paypal currency mismatch: $payment_currency doesn't match expected value"; yak_log("paypal currency mismatch: $payment_currency doesn't match $cc"); yak_insert_orderlog($order_id, "currency '$payment_currency' does not match [ $cc ]"); return; } $sql = $wpdb->prepare("select funds_received from $order_table where id = %d", $order_id); $row = $wpdb->get_row($sql); if ($row->funds_received > 0) { echo "INFO: IPN notification has already been processed for this order"; // we've already processed this return; } $paypal_account = strtolower(yak_get_option(PAYPAL_ACCOUNT, '')); $business = strtolower($_REQUEST['business']); if ($business != $paypal_account) { echo "ERROR: paypal business mismatch: $business or $receiver_email doesn't match expected value"; yak_log("paypal business mismatch: $business or $receiver_email doesn't match $msg"); yak_insert_orderlog($order_id, "business '$business' or receiver_email '$receiver_email' does not match [ $msg ]"); return; } $payment_types = yak_get_option(PAYMENT_TYPES_CASE_INSENSITIVE, null); // choose the right paypal url based on what's set in the payment types array if (in_array(PAYPAL_SANDBOX, $payment_types)) { $url = parse_url(PAYPAL_SANDBOX_URL); } else { $url = parse_url(PAYPAL_URL); } // call paypal to verify $response = yak_do_http($url['scheme'] . '://' . $url['host'], $url['path'], $params); yak_log("IPN order_id=$order_id payment_gross=$payment_gross -- params=$params -- response=$response"); if (!(strpos($response, 'VERIFIED') === false)) { $sql = $wpdb->prepare("update $order_table set funds_received = %f where id = %d", $payment_gross, $order_id); $wpdb->query($sql); yak_send_confirmation_email($order_id); yak_insert_orderlog($order_id, "PayPal verified order $order_id. response: [$response]"); } else { yak_insert_orderlog($order_id, "PayPal response *NOT* verified for order $order_id. response: [$response] data: [ $msg ]"); } yak_check_order($order_id); } } if (!function_exists('yak_paypal_pdt')) { /** * Function to handle a PayPal Payment Data Transfer */ function yak_paypal_pdt() { global $order_table, $order_log_table, $wpdb; // only process if payment notification is set to PDT (otherwise just return true) // this means the pdt function can be used on the success page whether or not pdt is actually // used for payment notification if (yak_get_option(PAYPAL_PAYMENT_NOTIFICATION, '') == PAYPAL_PDT && !empty($_GET['tx'])) { $params = 'cmd=_notify-synch&tx=' . $_GET['tx'] . '&at=' . yak_get_option(PAYPAL_IDENTITY_TOKEN, ''); $payment_types = yak_get_option(PAYMENT_TYPES_CASE_INSENSITIVE, null); // choose the right paypal url based on what's set in the payment types array if (in_array(PAYPAL_SANDBOX, $payment_types)) { $url = parse_url(PAYPAL_SANDBOX_URL); } else { $url = parse_url(PAYPAL_URL); } $submit_url = $url['scheme'] . '://' . $url['host']; yak_log("YAK PDT url " . $submit_url); yak_log("YAK PARAMS " . $params); $response = yak_do_http($submit_url, $url['path'], $params, null, 'GET'); if (!(strpos($response, 'SUCCESS') === false)) { $payment_gross = yak_get_tag_value($response, 'mc_gross=', "\n"); $order_id = yak_get_tag_value($response, 'custom=', "\n"); yak_cleanup_after_order(); $cc = yak_get_option(SELECTED_CURRENCY, ''); $payment_currency = $_REQUEST['mc_currency']; if (!empty($payment_currency) && $payment_currency != $cc) { echo "ERROR: paypal currency mismatch: $payment_currency doesn't match expected value"; yak_log("paypal currency mismatch: $payment_currency doesn't match $cc"); yak_insert_orderlog($order_id, "currency '$payment_currency' does not match [ $cc ]"); return false; } $sql = $wpdb->prepare("update $order_table set funds_received = %f where id = %d", $payment_gross, $order_id); $wpdb->query($sql); yak_check_order($order_id); yak_send_confirmation_email($order_id); yak_insert_orderlog($order_id, "PayPal response successful for id $order_id [ $response ]"); return true; } else { $order_id = null; if (isset($_GET['order_id'])) { $order_id = $_GET['order_id']; } else if (isset($_GET['cm'])) { $order_id = $_GET['cm']; } if (isset($order_id)) { yak_insert_orderlog($order_id, "PayPal response not successful for id $order_id [ $response ]"); } return false; } } else { return true; } } } if (!function_exists('yak_paypal_pdt_success_tag')) { /** * [yak_paypal_pdt_success]message to display on success[/yak_paypal_pdt_success] */ function yak_paypal_pdt_success_tag($attrs, $content = null) { $pdt = yak_paypal_pdt(); $_REQUEST['yak_paypal_pdt'] = $pdt; if ($pdt) { return $content; } else { return ""; } } } if (!function_exists('yak_paypal_pdt_failure_tag')) { /** * [yak_paypal_pdt_failure]message to display on failure[/yak_paypal_pdt_failure] * * NOTE: Must be used in conjunction with the success tag (which must also be used first) */ function yak_paypal_pdt_failure_tag($attrs, $content = null) { $pdt = $_REQUEST['yak_paypal_pdt']; if ($pdt) { return ""; } else { return $content; } } } if (!function_exists('yak_paypal_head_wp')) { /** * Stuff to do at the head of the page. */ function yak_paypal_head_wp() { // Fix a problem with Paypal landing back at the root page of the blog, rather // than the proper page -- so cleanup the order if we find some common // paypal params in the POST if (!empty($_GET['custom']) && !empty($_GET['txn_id'])) { yak_paypal_ipn(); yak_cleanup_after_order(); } if (!empty($_GET['merchant_return_link'])) { yak_cleanup_after_order(); } } } if (!function_exists('yak_paypal_settings')) { function yak_paypal_settings() { global $model; $model[PAYPAL_ACCOUNT] = yak_get_option(PAYPAL_ACCOUNT, ''); $model[PAYPAL_RETURN_URL] = yak_get_option(PAYPAL_RETURN_URL, ''); $model[PAYPAL_CANCEL_RETURN_URL] = yak_get_option(PAYPAL_CANCEL_RETURN_URL, ''); $model[PAYPAL_IDENTITY_TOKEN] = yak_get_option(PAYPAL_IDENTITY_TOKEN, ''); $model[PAYPAL_PAYMENT_NOTIFICATION] = yak_get_option(PAYPAL_PAYMENT_NOTIFICATION, ''); $model[PAYPAL_INCLUDE_SHIPPING_ADDRESS] = yak_get_option(PAYPAL_INCLUDE_SHIPPING_ADDRESS, ''); ?>
| PAYPAL_RETURN_URL, 'selected'=>$model[PAYPAL_RETURN_URL], 'values'=>$model[PAGES])) ?> |
|
| PAYPAL_CANCEL_RETURN_URL, 'selected'=>$model[PAYPAL_CANCEL_RETURN_URL], 'values'=>$model[PAGES])) ?> |
|
| PAYPAL_PAYMENT_NOTIFICATION, 'selected'=>$model[PAYPAL_PAYMENT_NOTIFICATION], 'values'=>array(PAYPAL_IPN=>PAYPAL_IPN_TEXT, PAYPAL_PDT=>PAYPAL_PDT_TEXT))); ?> | |
| /> |