You are here

function commerce_paypal_wps_paypal_ipn_validate in Commerce PayPal 7

Same name and namespace in other branches
  1. 7.2 modules/wps/commerce_paypal_wps.module \commerce_paypal_wps_paypal_ipn_validate()

Payment method callback: validate an IPN based on receiver e-mail address, price, and other parameters as possible.

File

modules/wps/commerce_paypal_wps.module, line 209
Implements PayPal Website Payments Standard in Drupal Commerce checkout.

Code

function commerce_paypal_wps_paypal_ipn_validate($order, $payment_method, $ipn) {

  // Return FALSE if the receiver e-mail does not match the one specified by
  // the payment method instance.
  if (trim(strtolower($ipn['receiver_email'])) != trim(strtolower($payment_method['settings']['business']))) {
    commerce_payment_redirect_pane_previous_page($order);
    watchdog('commerce_paypal_wps', 'IPN rejected: invalid receiver e-mail specified (@receiver_email); must match the primary e-mail address on the PayPal account.', array(
      '@receiver_email' => $ipn['receiver_email'],
    ), WATCHDOG_NOTICE);
    return FALSE;
  }

  // Prepare the IPN data for inclusion in the watchdog message if enabled.
  $ipn_data = '';
  if (!empty($payment_method['settings']['ipn_logging']) && $payment_method['settings']['ipn_logging'] == 'full_ipn') {
    $ipn_data = '<pre>' . check_plain(print_r($ipn, TRUE)) . '</pre>';
  }

  // Log a message including the PayPal transaction ID if available.
  if (!empty($ipn['txn_id'])) {
    watchdog('commerce_paypal_wps', 'IPN validated for Order @order_number with ID @txn_id.!ipn_data', array(
      '@order_number' => $order->order_number,
      '@txn_id' => $ipn['txn_id'],
      '!ipn_data' => $ipn_data,
    ), WATCHDOG_NOTICE);
  }
  else {
    watchdog('commerce_paypal_wps', 'IPN validated for Order @order_number.!ipn_data', array(
      '@order_number' => $order->order_number,
      '!ipn_data' => $ipn_data,
    ), WATCHDOG_NOTICE);
  }
}