You are here

public static function PayPalPaymentIPNController::acknowledge in PayPal for Payment 7

Acknowledges an IPN.

Parameters

array $ipn_variables: IPN message variables in the order they were received in from PayPal.

Return value

bool Whether the IPN was valid and successfully acknowledged.

2 calls to PayPalPaymentIPNController::acknowledge()
PayPalPaymentIPNControllerTest::testAcknowledge in paypal_payment_ipn/tests/PayPalPaymentIPNControllerTest.test
Tests acknowledge().
paypal_payment_ipn_post in paypal_payment_ipn/paypal_payment_ipn.module
Processes an IPN request based on POST data.

File

paypal_payment_ipn/includes/PayPalPaymentIPNController.inc, line 94

Class

PayPalPaymentIPNController
Provides IPN functionality.

Code

public static function acknowledge(array $ipn_variables) {

  // Prepare the request data.
  $ipn_variables['cmd'] = '_notify-validate';
  $data = [];
  foreach ($ipn_variables as $variable => $value) {
    $data[] = $variable . '=' . rawurlencode($value);
  }
  $data = implode('&', $data);

  // Execute the request.
  $url = empty($ipn_variables['test_ipn']) ? self::PAYPAL_IPN_SERVER_URL : self::PAYPAL_IPN_SANDBOX_SERVER_URL;

  // Use url() so we can alter the request using hook_url_outbound_alter().
  $url = url($url, array(
    'external' => TRUE,
  ));
  $response = chr_curl_http_request($url, array(
    'method' => 'POST',
    'data' => $data,
    'curl_opts' => [
      CURLOPT_SSL_VERIFYPEER => TRUE,
      CURLOPT_SSL_VERIFYHOST => 2,
    ],
  ));

  // Process the response.
  if (isset($response->error)) {
    watchdog('paypal_payment_ipn', 'An IPN acknowledgement failed with error @code: %error.', array(
      '@code' => $response->code,
      '%error' => $response->error,
    ), WATCHDOG_ERROR);
    return FALSE;
  }
  elseif ($response->data == 'VERIFIED') {
    return TRUE;
  }
  else {
    watchdog('paypal_payment_ipn', 'PayPal did not verify an IPN acknowledgement.', array(), WATCHDOG_ERROR);
    return FALSE;
  }
}