uc_authorizenet.pages.inc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @file
  4. * Page callback for Authorize.Net's Silent POST feature.
  5. */
  6. /**
  7. * Receives a payment notification and handles it appropriately.
  8. */
  9. function uc_authorizenet_silent_post() {
  10. // Determine if this is an ARB notification or not.
  11. $arb = (isset($_POST['x_subscription_id']) and isset($_POST['x_subscription_paynum']));
  12. // Log ARB payment notification, if enabled.
  13. if (variable_get('uc_authnet_report_arb_post', FALSE)) {
  14. $args = array(
  15. '!arb' => $arb ? 'ARB ' : '',
  16. '@order_id' => $_POST['x_invoice_num'],
  17. '@post' => print_r($_POST, TRUE),
  18. );
  19. watchdog('uc_authorizenet', '!arbSilent POST received for order @order_id: <pre>@post</pre>', $args);
  20. }
  21. // Decrypt the Auth.Net API login data.
  22. $login_data = _uc_authorizenet_login_data();
  23. // TODO: Modify the MD5 hash to accommodate differences from AIM to ARB.
  24. // This is an ARB notification.
  25. if ($arb) {
  26. // Compare our expected MD5 Hash against what was received.
  27. $md5 = strtoupper(md5($login_data['md5_hash'] . $_POST['x_trans_id'] . $_POST['x_amount']));
  28. // Post an error message if the MD5 hash does not validate.
  29. if ($_POST['x_MD5_Hash'] != $md5) {
  30. watchdog('uc_authorizenet', 'Invalid ARB payment notification received.', array(), WATCHDOG_ERROR);
  31. }
  32. // Otherwise, let other modules act on the data.
  33. else {
  34. module_invoke_all('uc_auth_arb_payment', $_POST);
  35. }
  36. }
  37. exit();
  38. }