You are here

function _uc_recurring_hosted_paypal_ipn_payment in UC Recurring Payments and Subscriptions 7.2

Same name and namespace in other branches
  1. 6.2 modules/uc_recurring_hosted/uc_recurring_hosted.paypal_ipn.inc \_uc_recurring_hosted_paypal_ipn_payment()

Handles payment information from IPN message.

3 calls to _uc_recurring_hosted_paypal_ipn_payment()
uc_recurring_hosted_paypal_ipn in modules/uc_recurring_hosted/uc_recurring_hosted.paypal_ipn.inc
Handle IPN callbacks for PayPal recurring payments
uc_recurring_hosted_paypal_wpp_renew in modules/uc_recurring_hosted/uc_recurring_hosted.module
Setup a mock renew handler to process through UC Recurring.
uc_recurring_hosted_paypal_wps_renew in modules/uc_recurring_hosted/uc_recurring_hosted.module
Setup a mock renew handler to process through UC Recurring.

File

modules/uc_recurring_hosted/uc_recurring_hosted.paypal_ipn.inc, line 133
Handle paypal IPN callbacks for recurring payments

Code

function _uc_recurring_hosted_paypal_ipn_payment($ipn) {
  global $user;
  $context = array(
    'revision' => 'formatted-original',
    'type' => 'amount',
  );
  $options = array(
    'sign' => FALSE,
  );
  switch ($ipn->payment_status) {
    case 'Canceled_Reversal':
      uc_order_comment_save($ipn->order_id, 0, t('PayPal has cancelled the reversal and returned !amount !currency to your account.', array(
        '!amount' => uc_currency_format($ipn->mc_gross, $options['sign']),
        '!currency' => $ipn->mc_currency,
      )), 'admin');
      break;
    case 'Completed':
      $comment = t('PayPal transaction ID: @txn_id', array(
        '@txn_id' => $ipn->txn_id,
      ));

      // save the transaction in the order log
      uc_order_comment_save($ipn->order_id, 0, t('Payment of @amount @currency submitted through PayPal.', array(
        '@amount' => uc_currency_format($ipn->mc_gross, $options['sign']),
        '@currency' => $ipn->mc_currency,
      )), 'order', 'payment_received');
      uc_order_comment_save($ipn->order_id, 0, t('PayPal IPN reported a payment of @amount @currency.', array(
        '@amount' => uc_currency_format($ipn->mc_gross, $options['sign']),
        '@currency' => $ipn->mc_currency,
      )));
      uc_payment_enter($ipn->order_id, 'paypal_wps', $ipn->mc_gross, $user->uid, NULL, $comment);
      break;
    case 'Denied':
      uc_order_comment_save($ipn->order_id, 0, t("You have denied the customer's payment."), 'admin');
      break;
    case 'Expired':
      uc_order_comment_save($ipn->order_id, 0, t('The authorization has failed and cannot be captured.'), 'admin');
      break;
    case 'Failed':
      uc_order_comment_save($ipn->order_id, 0, t("The customer's attempted payment from a bank account failed."), 'admin');
      break;
    case 'Pending':
      uc_order_update_status($ipn->order_id, 'paypal_pending');
      uc_order_comment_save($ipn->order_id, 0, t('Payment is pending at PayPal: @reason', array(
        '@reason' => _uc_paypal_pending_message(check_plain($ipn->pending_reason)),
      )), 'admin');
      break;

    // You, the merchant, refunded the payment.
    case 'Refunded':
      $comment = t('PayPal transaction ID: @txn_id', array(
        '@txn_id' => $ipn->txn_id,
      ));
      uc_payment_enter($ipn->order_id, 'paypal_wps', $ipn->mc_gross, $ipn->uid, NULL, $comment);
      break;
    case 'Reversed':
      watchdog('uc_recurring_hosted', 'PayPal has reversed a payment!', array(), WATCHDOG_ERROR);
      uc_order_comment_save($ipn->order_id, 0, t('Payment has been reversed by PayPal: @reason', array(
        '@reason' => _uc_paypal_reversal_message($ipn->reason_code),
      )), 'admin');
      break;
    case 'Processed':
      uc_order_comment_save($ipn->order_id, 0, t('A payment has been accepted.'), 'admin');
      break;
    case 'Voided':
      uc_order_comment_save($ipn->order_id, 0, t('The authorization has been voided.'), 'admin');
      break;
    default:
      watchdog('uc_recurring_hosted', 'Payment status @status not recognized.  Nothing to do. !debug', array(
        '@status' => $ipn->payment_status,
        '!debug' => variable_get('uc_paypal_wps_debug_ipn', FALSE) ? '<pre>' . check_plain(print_r($_POST, TRUE)) . '</pre>' : '',
      ));
      break;
  }
}