function _uc_recurring_hosted_paypal_ipn_validate in UC Recurring Payments and Subscriptions 7.2
Same name and namespace in other branches
- 6.2 modules/uc_recurring_hosted/uc_recurring_hosted.paypal_ipn.inc \_uc_recurring_hosted_paypal_ipn_validate()
Validate Paypal IPN.
1 call to _uc_recurring_hosted_paypal_ipn_validate()
- uc_recurring_hosted_paypal_ipn in modules/
uc_recurring_hosted/ uc_recurring_hosted.paypal_ipn.inc - Handle IPN callbacks for PayPal recurring payments
File
- modules/
uc_recurring_hosted/ uc_recurring_hosted.paypal_ipn.inc, line 238 - Handle paypal IPN callbacks for recurring payments
Code
function _uc_recurring_hosted_paypal_ipn_validate($ipn) {
if (_uc_recurring_hosted_paypal_ipn_is_duplicate($ipn)) {
return FALSE;
}
// @todo: any reason we can't use http_build_query() here?
$req = '';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= $key . '=' . $value . '&';
}
$req .= 'cmd=_notify-validate';
if (variable_get('uc_paypal_wpp_server', '') == 'https://api-3t.paypal.com/nvp') {
$host = 'https://www.paypal.com/cgi-bin/webscr';
}
else {
$host = variable_get('uc_paypal_wps_server', 'https://www.sandbox.paypal.com/cgi-bin/webscr');
}
$response = drupal_http_request($host, array(
'headers' => array(),
'method' => 'POST',
'data' => $req,
));
// @todo: Change this to property_exists when we have a PHP requirement >= 5.1.
if (array_key_exists('error', $response)) {
watchdog('uc_recurring_hosted', 'IPN failed with HTTP error @error, code @code.', array(
'@error' => $response->error,
'@code' => $response->code,
), WATCHDOG_ERROR);
return FALSE;
}
if (strcmp($response->data, 'VERIFIED') == 0) {
watchdog('uc_recurring_hosted', 'PayPal Recurring IPN Transaction Verified.');
return TRUE;
}
elseif (strcmp($response->data, 'INVALID') == 0) {
watchdog('uc_recurring_hosted', 'IPN transaction failed verification.', array(), WATCHDOG_ERROR);
uc_order_comment_save($ipn->order_id, 0, t('An IPN transaction failed verification for this order.'), 'admin');
}
return FALSE;
}