Can someone help me out please. I can't get my module to work. The goal of the module is to award points to a user after she makes a payment. The number of points to be awarded is based on the value of the item_number field from lm_paypal module. Currently no points is awarded when a payment is made and I'm not sure how to fix it. Thanks.

<?php
define('USERPOINTS_LM_PAYPAL_CREDIT_MODERATE', 'userpoints_lm_paypal_credit_moderate');
define('USERPOINTS_LM_PAYPAL_CREDIT_TID', 'userpoints_lm_paypal_credit_tid');

/**
 * Implements hook_permission().
 */
function userpoints_lm_paypal_credit_permission() {
  return array(
    'userpoints lm paypal credit' => array(
      'title' => t('Userpoints Paypal Credit'),
      'description' => t('Award bought credit to users with points'),
     ),
  );
}

/*
 * Function: Implementation of hook_userpoints
 */
function userpoints_lm_paypal_credit_userpoints($op, $params = array()) {
  switch ($op) {
    case 'setting':
      $group = 'userpoints_lm_paypal_credit';
      $form[$group] = array(
        '#type'        => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed'   => TRUE,
        '#title'       => t('!Points for buying credit', userpoints_translation()),
      );

      $form[$group][USERPOINTS_LM_PAYPAL_CREDIT_MODERATE] = array(
        '#type'          => 'radios',
        '#title'         => t('Moderate points for buying credit', userpoints_translation()),
        '#default_value' => variable_get(USERPOINTS_LM_PAYPAL_CREDIT_MODERATE, 0),
        '#options' => array(t('No'), t('Yes')),
      );

      $form[$group][USERPOINTS_LM_PAYPAL_CREDIT_TID] = array(
      '#type'          => 'select',
      '#title'         => t('Category'),
      '#default_value' => variable_get(USERPOINTS_LM_PAYPAL_CREDIT_TID, 0),
      '#options'       => userpoints_get_categories(),
      '#description'   => t('User Credits points will be assigned to this category. You can modify what categories are available by modifying the <a href="!url">Userpoints taxonomy</a>.',
        array('!url' => url('admin/structure/taxonomy/userpoints'))),
      );
      return $form;
  }
}

/*
 * Assign the value of item_number as points (credit).
 */
function userpoints_lm_paypal_credit_order($payment_status) {
  global $user;
  $curUserId = $uid; //$user->uid; // $user->uid means nothing when the IPN call comes in...
//  $result 		= db_query("select d.mc_gross from {lm_paypal_donations}, d {m_paypal_ipns} p where d.txn_id=p.txn_id and d.uid = %d", $curUserId);
//  $total		= db_result($result, $row = 0);

  if (module_exists('lm_paypal' and 'lm_paypal_donations')) {
    // Look up payment if we have one
    $result = db_query("SELECT p.item_number, p.txn_id, p.payment_status FROM {lm_paypal_ipns} p JOIN {lm_paypal_donations} d ON p.txn_id = d.txn_id WHERE d.uid = :uid", array(':uid' => $curUserId));
      if(!empty($result)){
        $pay = db_fetch_object($result);
        $payUserId = $pay->uid;
        $credit = $pay->item_number;
        $paytxn = $pay->txn_id;
        $paystatus = $pay->payment_status;
      }
    }

	// Award points to buyer, if appropriate
	if ($payUserId != 0 && $paystatus = 'Completed') {
		// User id from the transaction

			$params = array (
				'tid' => variable_get(USERPOINTS_LM_PAYPAL_CREDIT_TID, 0),
				'uid' => $payUserId,
				'points' => 6,
				'operation' => 'insert',
				'description' => 'User made a credit purchase, awarding points (Transaction ID ' . $paytxn . ')',
				'entity_id' => $paytxn,
//				'entity_type' => 'Ubercart Transaction',
			);
			userpoints_userpointsapi($params);

			// save data into database
      db_insert('lm_paypal_credit_log')
        ->fields(array(
          'uid' => $payUserId,
          'creditdate' => REQUEST_TIME,
          'txn_id' => $paytxn,
          'credit' => $credit,
          'points' => $points
       ))
       ->execute();
		}
	}
?>

Comments

manuel.adan’s picture

Status: Active » Closed (outdated)

Closing old issues as outdated. Feel free to reopen if needed.